[Qt-interest] ModelView - how to use proxies to filter this data?

Stephen Kelly steveire at gmail.com
Wed Dec 2 14:15:20 CET 2009


Daniel Price wrote:

> I've been playing with this sortfilter approach and it works fine if the
> layout of the source matches the output. However, what if my source items
> are buried away?
> 
> Eg:
> 
> --Companies
> ----Company1
> ------Product1
> ------Product2
> ------Product3
> ----Company2
> ------Product4
> 
> The above is stored within a QAbstractItemModel and I want to use a proxy
> to just pull out all the products to give me this in a table:
> 
> --Product1
> --Product2
> --Product3
> --Product4
> 
> How could I do this using a proxy? If I store a unique identifier in each
> of the product rows identifying it as a Product record, could I somehow
> use the built-in filtering to get just those rows?


You could do this using a proxy. The way I've done it is to flatten the tree 
into a list, then filter out Company* from the list.

Some screenshots here: 

http://api.kde.org/playground-api/pim-
apidocs/akonadi/akonadi_next/html/index.html

(Look for DescendantEntitiesProxyModel)

All the best,

Steve.

> 
> 
>> -----Original Message-----
>> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
>> bounces at trolltech.com] On Behalf Of Sean Harmer
>> Sent: 01 December 2009 15:54
>> To: qt-interest at trolltech.com
>> Subject: Re: [Qt-interest] ModelView - how to use proxies to filter
>> this data?
>>
>> Hi,
>>
>> On Tuesday 01 December 2009 15:36:18 Daniel Price wrote:
>> > Thanks for the info. I hadn't considered using a proxy filter and
>> just
>> >  accepting/rejecting rows. Does that work with hierarchical data
>> though?
>>
>> Yes it works absolutely fine with hierarchical data as that is what I
>> am using.
>>
>> > I actually QAbstractProxyModel and implemented the mapTo/mapFrom
>> functions.
>> >  But sorting doesn't seem to work.
>>
>> Yeah I thought about doing it that way, but then decided that
>> QSortFilterProxyModel fitted my needs with a little subclassing.
>>
>> > BTW it looks like you're storing pointers to your structures in your
>> >  variants as integers and casting them back.
>>
>> No I am storing them as void* in the QModelIndex's internal pointer so
>> that is
>> why I am casting them back to my specific types. My model's index
>> function
>> looks like this:
>>
>> QModelIndex MapsData1DTreeModel::index( int row, int col, const
>> QModelIndex&
>> parent ) const
>> {
>>     MapsData1DTreeModelGroupNode* parentItem;
>>     if ( !parent.isValid() )
>>         parentItem = m_root;
>>     else
>>         parentItem = static_cast<MapsData1DTreeModelGroupNode*>(
>> parent.internalPointer() );
>>
>>     MapsData1DTreeModelNode* childItem = parentItem->child( row );
>>     if ( childItem )
>>         return createIndex( row, col, childItem );
>>     else
>>         return QModelIndex();
>> }
>>
>> Good luck.
>>
>> Sean
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com
>> Version: 9.0.709 / Virus Database: 270.14.87/2535 - Release Date:
>> 11/30/09 21:05:00
> 
> This email is confidential. It may also be privileged or otherwise
> protected by work product immunity or other legal rules. If you are not
> the intended recipient please notify the sender. Please delete the message
> from all places in your computer where it is stored. You should not copy
> the email or use it for any purpose or disclose its contents to any other
> person.To do so may be unlawful. Email is an informal means of
> communicating and may be subject to data corruption accidentally or
> delibera tely. For this reason it is inappropriate to rely on advice
> contained in an email without obtaining written confirmation of it first.
> 
> FXhome Limited is a limited company registered in England and Wales.
> Registered number: 04172812. Registered office: The Henderson Business
> Centre, Ivy Road, Norwich, Norfolk, NR5 8BF, U.K.




More information about the Qt-interest-old mailing list