[Qt-interest] QAbstractProxyModel methods index, parent, rowCount, columnCount not implemented?

Stephen Kelly steveire at gmail.com
Wed May 18 13:59:26 CEST 2011


Bo Thorsen wrote:

> Den 18-05-2011 12:09, Andre Somers skrev:
>> Op Wo, 18 mei, 2011 11:59 am, schreef Stephen Kelly:
>>
>>>>> It would still be nice if there was a basic
>>>>> QAbstractDecoratorProxyModel
>>>>> base class that didn't have all the overhead of the
>>>>> QSortFilterProxyModel.
>>>> Not a bad idea, actually. A proxy model that is geared towards giving a
>>>> 1:1 representation of the underlying data structure, but that allows
>>>> you to just decorate...
>>>> I am not sure if it makes much of a difference though. Is the overhead
>>>> of
>>>> QSFPM so big?
>>>>
>>>> André
>>>
>>> It's called QIdentityProxyModel and it's in Qt 4.8.
>>>
>>> http://doc.trolltech.com/4.8-snapshot/qidentityproxymodel.html
>>>
>>> http://steveire.wordpress.com/2010/08/25/kidentityproxymodel-does-
nothing-
>>> fast/
>>>
>> Great, I will port my CheckableProxyModel to use it as soon as Qt 4.8 is
>> out.

I had a quick look at your CheckableProxyModel, and it does a bunch of 
things wrong, such as storing QModelIndexes instead of 
QPersistentModelIndexes, and not listening to the source model for changes 
and keeping up to date. QItemSelectionModel does both of those things, which 
is what I use in KCheckableProxyModel. You should probably write some tests 
with a changing source model and see what happens.

> 
> Nice timing. I was about to write my own class doing pretty much this.
> Also for decorations, where the icons are downloaded from the net.
> Perfect case for this class.
> 
> Yes, I could store it directly in the model, but it doesn't belong there
> for this model, and the code was a bit annoying. And delegates don't
> really offer per-row storage. This proxy class is exactly what's needed.

If you store data in a proxy, beware of reset()s of the source and the 
proxy. QIdentityProxyModel does not give you any API to handle them properly 
because the trolls don't want the fix in QAIM. That means everyone has to 
figure out the fix and apply it to each concrete proxy model. The fix is 
also not documented, so good look finding it :). It's described in a unit 
test in one of my old merge requests though.






More information about the Qt-interest-old mailing list