Results 1 to 12 of 12

Thread: filtering a TreeView from buttom to top

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: filtering a TreeView from buttom to top

    Hmmm this is driving me nuts.... here are my attempts at "prefiltering"

    I have a member
    QMap <qint64, bool> visibleTable;
    that saves internalPointer<->visiblity;

    This is the extra function
    Qt Code:
    1. bool QBrowseViewFilterModel::myFilterAcceptsRow(int sourceRow,
    2. const QModelIndex &sourceParent)
    3. {
    4.  
    5. QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
    6. bool show = false;
    7.  
    8. if (sourceModel()->hasChildren(index0))
    9. {
    10. for (int i = 0; i < sourceModel()->rowCount(index0); ++i)
    11. if (myFilterAcceptsRow(i, index0))
    12. show = true; /// if any child is visible keep this visible
    13. } else
    14. {
    15. QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
    16. QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
    17.  
    18. show = true;
    19.  
    20. if (!sourceModel()->data(index0).toString().contains(filterRegExp()))
    21. show = false;
    22.  
    23. }
    24.  
    25. visibleTable.insert(index0.internalId(), show);
    26.  
    27. return show;
    28. }
    To copy to clipboard, switch view to plain text mode 
    the original filterAcceptsRow :
    Qt Code:
    1. bool QBrowseViewFilterModel::filterAcceptsRow(int sourceRow,
    2. const QModelIndex &sourceParent) const
    3. {
    4. QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
    5. return visibleTable[index0.internalId()];
    6. }
    To copy to clipboard, switch view to plain text mode 

    And I also overwrote invalidate and reset to actually start the recursion on the top-level-items:
    Qt Code:
    1. void QBrowseViewFilterModel::reset()
    2. {
    3. visibleTable.clear();
    4.  
    5. for (int i = 0; i < sourceModel()->rowCount(); ++i)
    6. myFilterAcceptsRow(i);
    7.  
    8. this->QSortFilterProxyModel::reset();
    9. }
    10.  
    11. void QBrowseViewFilterModel::invalidate()
    12. {
    13. visibleTable.clear();
    14.  
    15. for (int i = 0; i < sourceModel()->rowCount(); ++i)
    16. myFilterAcceptsRow(i);
    17.  
    18. this->QSortFilterProxyModel::invalidate();
    19. }
    To copy to clipboard, switch view to plain text mode 

    But now the table¹ is empty

    ... I hope I am not doing anything stupid there right now.... it is getting kind of late....

    Thanks for not giving up

    edit: ¹ I meant the view.
    Last edited by soul_rebel; 22nd April 2008 at 00:57.
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

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
  •  
Qt is a trademark of The Qt Company.