[Qt-interest] FW: QAbstractItemModel: Hiding rows
Eric Clark
eclark at ara.com
Fri Jul 10 23:52:53 CEST 2009
I am not real sure why Brad said you were wrong, but I can see how it would work with a Proxy model. And I do believe that for most cases the proxy model is probably the correct solution. However, for my case, we have come up with some other solutions due to the speed we need to have. I cannot call insert or remove rows during certain circumstances in my application because we need to be as fast as possible.
What Brad suggested is based on my view using the data internally. I could easily add a data role called VisibleRole or something and return a Boolean flag, true if visible, and false if hidden. Then the view could just hide the item or not create it at all. This is a great solution and probably the easiest solution as it only requires my model to return an extra role in its data function. No need for mapping of reordered indexes or anything.
Thanks,
Eric
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Arnold Krille
Sent: Friday, July 10, 2009 12:27 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] FW: QAbstractItemModel: Hiding rows
Hi,
On Friday 10 July 2009 17:52:30 Brad Howes wrote:
> On Jul 10, 2009, at 4:32 AM, Arnold Krille wrote:
> > So actually your model is already a proxy to the real data:-) And
> > all you want to know is what method of hiding some data from the
> > proxies is least costly.
> > As I said, either 1) hide it directly in your model (yes, that
> > involves index-
> > reordering) or 2) do it via a proxymodel (yes, that involves index-
> > reordering)...
> There is no reason at all to do it this way.
> > The model-view concept is actualy working like this: The views show
> > everything exported by the model. And its the models responsibility
> > to hide what is not to be shown.
> Wrong.
> > If you try to introduce a new role, you also have to implement your
> > own views/delegates to be used with your model.
> Wrong.
> > And that is counter-productive. The advantage of the model-view-
> > pattern is that (almost) all views can display the data given in the
> > model. Some my not look interesting (imagine a
> > chart-
> > view coupled to a QDirModel:), but all work without modifications or
> > big specializations.
> There are so many mischaracterizations of MVC and of how Qt does
> things here.
I don't mind telling me when I am wrong. But could you _please_ explain why?
(Trying to learn.)
What do you propose? Introducing a new flag/role in the model? And then modify all views to respect the flag? Somehow this still seems to be counter- productive to the fact that with the standard-interface you can just connect a view to a model (without special things) and get something useful as intended.
Take for example a simple table that contains the results of some experiments.
Regardless whether you connect a TableView, a ChartView or a OpenGL3DChartView, if (like the original poster) you want a row of data to be hidden in all views, you have (to the best of my knowledge) no other possibilities then either not publish/expose that row in the model in the first place or plug a proxy between model and view to hide the row there. And both involve reordering the indizes.
Please tell me where I mis-understand the model-view-pattern!
Arnold
More information about the Qt-interest-old
mailing list