Results 1 to 7 of 7

Thread: How to filter model from QStandardItemModel for uniqe values

  1. #1
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1

    Default How to filter model from QStandardItemModel for uniqe values

    Hi folks,
    I'm trying to find out, which class and how should I reimplement, to get duplicate values filter.
    Exactly what I want to do, is just to put uniqe values from one of QStandardItemModel columns (that contains duplicates).

    Best regards,
    Kris

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

    Default Re: How to filter model from QStandardItemModel for uniqe values

    QSortFilterProxyModel -- you'll need to subclass it and reimplement filterAcceptsRow()
    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.


  3. #3
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1

    Default Re: How to filter model from QStandardItemModel for uniqe values

    Thank you. I'm examining Custom Sort/Filter example, what I believe should help me.
    But I'm just wondering how filter is beeing applyed to elements. Row by row?

    I plan to put all unique values into QSet, and check it they exist there. Good track?

    My only concideration is, to keep original order and remove elements following after first occurance.

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

    Default Re: How to filter model from QStandardItemModel for uniqe values

    Quote Originally Posted by Mad Bekon View Post
    Row by row?
    Yes.

    I plan to put all unique values into QSet, and check it they exist there. Good track?
    Sounds fine for a first try.
    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.


  5. The following user says thank you to wysota for this useful post:

    Mad Bekon (15th April 2013)

  6. #5
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1

    Default Re: How to filter model from QStandardItemModel for uniqe values

    Qt Code:
    1. bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
    2. const QModelIndex &sourceParent) const
    3. {
    4. QModelIndex index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent);
    5.  
    6. if(!(mySet.contains(index.data().toString()))) {
    7.  
    8. const_cast<MySortFilterProxyModel *>(this)->mySet.insert(index.data().toString());
    9. return true;
    10. }
    11. else
    12. return false;
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    Did the job... Dzięki wielkie

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

    Default Re: How to filter model from QStandardItemModel for uniqe values

    Remember to clear the set when the filter is invalidated.
    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.


  8. #7
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1

    Default Re: How to filter model from QStandardItemModel for uniqe values

    True, true...
    I cannot edit, so I will add here:
    Qt Code:
    1. void MySortFilterProxyModel::invalidateFilter()
    2. {
    3. mySet.clear();
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to filter duplicates from a proxy model.
    By kaushal_gaurav in forum Qt Programming
    Replies: 6
    Last Post: 14th October 2016, 11:21
  2. Replies: 2
    Last Post: 18th March 2013, 23:31
  3. Model/view, apply a filter on model
    By remy_david in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2011, 18:13
  4. Set a filter on a model/view
    By graciano in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2010, 18:07
  5. Filter Proxy Model to Autoupdate View
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2006, 21:32

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.