[Qt-interest] ModelView - how to use proxies to filter this data?
Daniel Price
daniel.price at fxhome.com
Wed Dec 16 11:14:04 CET 2009
Thanks. That seems kinda complex to me though.
Let me know how it goes. An running example of your more generic solution when you implement it would be awesome!
The biggest problem I've had is keeping everything in-sync; if I edit a branch of data via a proxy I want that change to propagate to all other proxies and views. I've not been able to get this working 100%. It seems that with *some* proxies, you have to transmit the signals yourself. For signals like dataChanged() this is easy, but for others like rowsInserted(), the signal is private to QAbstractItemModel so you can't emit it. I've been using the code for the QSortFilterProxyModel as a guide but it's so complex it's hard to follow.
My solution so far has to been to abandon proxies and instead nest sub-model adaptors in the hierarchy (itself maintained by a single tree of data nodes with a conventional tree adaptor).
Each 'row' has two columns - an data type enumeration and a shared pointer to a table-model. The model contains a pointer to the relevant data structure. In my prototype I have a treeview with the major branch nodes - selecting these switches the data source of a single tableview to the relevant sub-model. This has the advantage that model-adaptors can be lazy-loaded and destroyed when not needed.
It works, for the most part, but it's a little convoluted. It might be easier to build my own custom graph-based MVC framework because the strict concept 'rows' and 'columns' isn't a good match for my graphical app.
> -----Original Message-----
> From: Stephen Kelly [mailto:steveire at gmail.com]
> Sent: 14 December 2009 11:17
> To: Daniel Price; qt-interest at trolltech.com
> Subject: Re: [Qt-interest] ModelView - how to use proxies to filter
> this data?
>
> On Wed, Dec 2, 2009 at 2:18 PM, Daniel Price <daniel.price at fxhome.com>
> wrote:
> > Can I see the source code for DescendantEntitiesProxyModel? I'm not
> familiar with KDE underpinnings.
> >
> > From my experimentation so far, proxy models can only remove items
> from the model. They cannot change the fundamental structure so if the
> source is a tree, they will still display a tree.
>
> Hey, sorry for the very late reply. The LGPL code is now here:
>
> http://websvn.kde.org/trunk/KDE/kdepimlibs/akonadi/kdescendantsproxymod
> el_p.h?view=markup
> http://websvn.kde.org/trunk/KDE/kdepimlibs/akonadi/kdescendantsproxymod
> el.cpp?view=markup
>
> Note that it is also broken in a subtle way because it uses the
> internalPointer() of source model indexes. My intention is to replace
> it with the even more generic KReparentingProxyModel
>
> http://websvn.kde.org/trunk/KDE/kdepim/akonadi/akonadi_next/kreparentin
> gproxymodel.h?view=markup
>
> It can turn a list into a tree (for email threading for example), a
> tree into a list, or a tree into a different tree. So yes, you can
> change the fundamental structure of the model, but it's not trivial if
> you want to keep up to date with source model changes.
>
> All the best,
>
> Steve.
>
> >
> >> -----Original Message-----
> >> From: Stephen Kelly [mailto:steveire at gmail.com]
> >> Sent: 02 December 2009 13:14
> >> To: Daniel Price
> >> Subject: Re: [Qt-interest] ModelView - how to use proxies to filter
> >> this data?
> >>
> >> 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.
> >>
> >>
> >> No virus found in this incoming message.
> >> Checked by AVG - www.avg.com
> >> Version: 9.0.709 / Virus Database: 270.14.88/2537 - Release Date:
> >> 12/01/09 19:32:00
> >
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.709 / Virus Database: 270.14.102/2556 - Release Date:
> 12/10/09 07:36: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 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.
More information about the Qt-interest-old
mailing list