Results 1 to 2 of 2

Thread: Custom Multi-Filter QSortFilterProxyModel

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Custom Multi-Filter QSortFilterProxyModel

    Hi,
    I'm trying to develop a custom QSortFilterProxyModel (i.e. MyFilterProxyModel) supporting two kind of filters:
    1. row filter based on "Parameter Type" throught the value returned by filterRegExp()
    2. data filter based on "Parameter Settings Id" thorught another value returned by mySettingFilterRegExp


    Following an extract of my code:

    Qt Code:
    1. void MyFilterProxyModel::setFilteringEnabled(bool enable)
    2. {
    3. myFilteringEnabled = enable;
    4. invalidateFilter();
    5. }
    6.  
    7. bool MyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &index) const
    8. {
    9. if (!myFilteringEnabled)
    10. return true;
    11.  
    12. QModelIndex sidx = sourceModel()->index(sourceRow, 0, index);
    13. return containsParameter(sourceModel()->data(sidx, ParameterRole));
    14. }
    15.  
    16. bool MyFilterProxyModel::containsParameter(const QVariant & variant) const
    17. {
    18. bool res = false;
    19. if ( qVariantCanConvert< Parameter* >(variant) )
    20. {
    21. Parameter * par = qVariantValue< Parameter* >(variant);
    22. if (par)
    23. res = par->getType().contains(filterRegExp());
    24. }
    25.  
    26. return res;
    27. }
    28.  
    29. QVariant MyFilterProxyModel::data( const QModelIndex& index, int role) const
    30. {
    31. QVariant variant = sourceModel()->data(mapToSource(index), role);
    32.  
    33. if (role == SettingsRole)
    34. {
    35. if ( qVariantCanConvert< QList<Setting *> >(variant) )
    36. {
    37. QList<Setting *> newList;
    38. QList<Setting *> list = qVariantValue< QList<Setting *> >(variant);
    39. foreach(Setting * st, list)
    40. {
    41. bool res = st->getID().contains(mySettingFilterRegExp); //N.B. mySettingFilterRegExp value is different from the one returned by filterRegExp()
    42. if (res)
    43. newList.append(ev);
    44. }
    45.  
    46. variant = qVariantFromValue(newList);
    47. }
    48. }
    49.  
    50. return variant;
    51. }
    To copy to clipboard, switch view to plain text mode 

    The row filtering works fine but I've some problems regarding the data filtering...after I've setted mySettingFilterRegExp, the data(...) function is called only for the standard role...it isn't called for my custom roles (i.e. ParameterRole and SettingsRole). Why?

  2. #2
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom Multi-Filter QSortFilterProxyModel

    any idea about this problem?

Similar Threads

  1. Filter a Filtered QSortFilterProxyModel !?
    By solook in forum Qt Programming
    Replies: 4
    Last Post: 25th October 2011, 19:22
  2. Qt Assistant for custom help and multi-language
    By bec in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2011, 08:54
  3. Replies: 3
    Last Post: 21st January 2011, 16:18
  4. Replies: 19
    Last Post: 25th November 2010, 08:52
  5. QDirModel (filter files, custom Icon, look)
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2009, 09:39

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.