Results 1 to 2 of 2

Thread: Subclassing QSortFilterProxyModel with lazy population of items

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Subclassing QSortFilterProxyModel with lazy population of items

    I'm creating a sortable/filterable tree model displaying DBus services/nodes.
    My code is based on the code used in qdbusviewer, and everything worked fine, until I started implementing lazy population of items (using hasChildren, canFetchMore and fetchMore).
    My base model (DBusModel) works like a charm, but the accompanying proxy model (DBusSortFilterModel) started behaving very strange.
    Sorting seems to work fine, Filtering seems to work fine, but when I expand any item, the whole view gets messed up (items just disappear!!).
    See attached screenshots...

    At the moment my implementation does something like this:
    Qt Code:
    1. bool DBusSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
    2. {
    3. // ...
    4. }
    5. bool DBusSortFilterProxyModel::hasChildren(const QModelIndex& parent) const
    6. {
    7. return sourceModel()->hasChildren(mapToSource(parent));
    8. }
    9. bool DBusSortFilterProxyModel::canFetchMore(const QModelIndex& parent) const
    10. {
    11. return sourceModel()->canFetchMore(mapToSource(parent));
    12. }
    13. void DBusSortFilterProxyModel::fetchMore(const QModelIndex& parent)
    14. {
    15. return sourceModel()->fetchMore(mapToSource(parent));
    16. }
    To copy to clipboard, switch view to plain text mode 

    Probably I'm just overlooking something, or didn't implement some required functionality for this to work. But what?
    Anybody has some experience with this?
    Attached Images Attached Images
    Last edited by sokopok; 4th August 2009 at 14:08. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing QSortFilterProxyModel with lazy population of items

    Why are you reimplementing the sort filter proxy model? Why isn't implementing lazy population in the source model enough?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Lazy population of QAbstractModel
    By bastien in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.