[Qt-interest] Question about Models, Roles and data

Arnold Krille arnold at arnoldarts.de
Sat Aug 29 19:05:03 CEST 2009


On Saturday 29 August 2009 18:48:40 Stephen Kelly wrote:
> > And stay away from custom roles unless you really have to use them.
> > The main advantage of model-view is that you can plug (almost) any view
> > on any model and it makes sense, preferable without using custom
> > delegates. If you need custom roles, you loose all that...
> This isn't true. Custom roles allow you to use proxies transparently. You
> can do someIndex.data(MyCustomRole).value<MyCustomObject>(); and it doesn't
> matter if 'someIndex' came from the 'core model' or one of the proxies.
> This doesn't really have anything to do with views.
> Regarding having different representations with different numbers of
> columns, I'd say rather than creating a 'core' model with 20 columns and
> then hiding the ones you don't want, make it have only one column, and
> implement proxies to have different numbers of columns, and fetch the data
> from the core model using custom roles. That way you don't have to instruct
> the view to hide things, because there's nothing extra there in the first
> place.
> I did roughly that for Akonadi, and it's quite flexible. A possible problem
> point is that you'll have to make the headerData come from the proxies
> instead of the core model. I solved that using a custom role hack because I
> needed full flexibility, but if you really only have foos and bars, it's
> probably not a big deal to have that in two proxies.

Interesting how your explanation against my reasoning just proves my point...
In akonadi you can not simply attach a view and get all the info. I tried. You 
need your special proxies and special views. (And then special conversions and 
data-types, which was where I didn't go on yet.) So why did you even use 
standard-models? You could have done that with your own model-proxy-view 
classes, no need to use the ones from qt.

Using custom roles to show the additional columns is just bad. If it is a fixed 
number of say 20 columns, it means 20(!) custom roles. If its a variable 
number of columns, you are lost...

Using a proxy to hide unneeded columns is way easier. And stays compatible 
with just attaching standard views without special proxies.

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090829/87658fa0/attachment.bin 


More information about the Qt-interest-old mailing list