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

Daniel Price daniel.price at fxhome.com
Mon Nov 30 12:15:24 CET 2009


I need to use modelView in an advanced way.

I have data like this (contrived example):

People{}
---person1{first name, last name,address1,address2,phone, email}
---person2{first name, last name,address1,address2,phone, email}
---person3{first name, last name,address1,address2,phone, email}
Companies{}
---company1{name, address1, address2,phone,website}
------product1{name,type,price}
------product2{name,type,price}
---company2{name, address1, address2,phone,website}
------product1{name,type,price}
------product2{name,type,price}

The data is hierarchical but sub-categories of data have different columns and different data for each column. In the above example, 'person' records have 6 columns, but 'product' records have 3. The actual data I'm dealing with is a lot more complex.

Now an QAbstractItemModel-derived class can be used as an adaptor for this but the data cannot (practically) by displayed within a QTreeView. So my idea is to use QAbstractItemProxy-derived classes to wrap the model. The primary single-column TreeView will display the following as headers:

People
---person1
---person2
---person3
Companies
---Company1
---Company2

When a Person or Company row is selected, a secondary TableView with display the data, stored as child indexes of that item in the original model.

So I would need four models - the original (invisible) model with all the data, an Overview proxy model for the primary tree, a Person proxy model, and  Company proxy model.

I'm having trouble implementing this due to the lack of examples/information available. Here is what I have discovered:

1)      It looks like QAbstractProxyModel-derived classes must propagate all signals emitted by the source model or it will do nothing (the examples I've seen work only on static data created before the model is hooked up so it does not matter).

2)      From studying the QSortFilterProxyModel implementation, it seems that proxies cannot share indexes from the source model - they must create their own.

I just need to be able to pick out the data from the primary model for each view. Does anyone have examples on how to proceed? No-one seems to have done this publically outside of Nokia so information is rare!

I can think of discrete ways of doing the same thing without proxies but having everything in a primary model has certain advantages (simplified undo for example).


Daniel Price
Software Engineer
FXhome Limited


________________________________
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 deliberately. 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091130/1aa5cff4/attachment.html 


More information about the Qt-interest-old mailing list