Results 1 to 2 of 2

Thread: QSortFilterProxyModel

  1. #1
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default QSortFilterProxyModel

    Qt Code:
    1. ProxyModel::ProxyModel( ItemModel* s )
    2. : QSortFilterProxyModel(s), mSource( s ), mFilterOn(false)
    3. {
    4. setSourceModel( mSource );
    5. }
    6. //
    7. ItemModel* ProxyModel::source() const
    8. {
    9. return mSource;
    10. }
    11. //
    12. bool ProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent) const
    13. {
    14. if (!mFilterOn)
    15. return true;
    16.  
    17. QModelIndex index;
    18. index = sourceModel()->index(sourceRow, 0, sourceParent);
    19. return index.data(Item::FilterRole).toBool();
    20. }
    21. //
    22. void ProxyModel::setFilter(int on)
    23. {
    24. if (!on)
    25. mFilterOn = false;
    26. else
    27. mFilterOn = true;
    28.  
    29. if (mFilterOn)
    30. {
    31. setSortRole(Item::SortRole);
    32. sort(0);
    33. filterChanged ();
    34. }
    35. else
    36. {
    37. clear();
    38. //reset();
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    now problem:
    when i appling filter (setFilter(true)) my source model get filter and sorting - it's ok
    when i remove filter (setFilter(false)) my source model loose filter but not sorting

    how to remove sorting from proxy model?
    Last edited by evgenM; 13th March 2007 at 17:35.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSortFilterProxyModel

    Try:
    Qt Code:
    1. ...
    2. else
    3. {
    4. clear();
    5. sort(-1); // <---
    6. //reset();
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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.