Results 1 to 14 of 14

Thread: Custom proxy model issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Custom proxy model issue

    Yes, it does, so here it is:


    Qt Code:
    1. bool AdvancedSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
    2. {
    3. bool accept = true;
    4. const QList<Filter>& andList = m_currentFilter.andList();
    5. const QList<Filter>& orList = m_currentFilter.orList();
    6. QList<Filter>::const_iterator it;
    7. QModelIndex index;
    8.  
    9. for (it = andList.begin(); it != andList.end(); it++)
    10. {
    11. index = sourceModel()->index(sourceRow, (*it).m_column, sourceParent);
    12. switch ((*it).m_action)
    13. {
    14. case FilterAction_Has:
    15. if (sourceModel()->data(index).toString().contains((*it).m_value) == false)
    16. accept = false;
    17. break;
    18. case FilterAction_Is:
    19. if ((sourceModel()->data(index).toString() == (*it).m_value.pattern()) == false)
    20. accept = false;
    21. break;
    22. case FilterAction_LessThan:
    23. if ((sourceModel()->data(index).toDouble() < (*it).m_value.pattern().toDouble()) == false)
    24. accept = false;
    25. break;
    26. case FilterAction_MoreThan:
    27. if ((sourceModel()->data(index).toDouble() > (*it).m_value.pattern().toDouble()) == false)
    28. accept = false;
    29. break;
    30. default:
    31. break;
    32. }
    33. }
    34.  
    35. for (it = orList.begin(); it != orList.end(); it++)
    36. {
    37. index = sourceModel()->index(sourceRow, (*it).m_column, sourceParent);
    38. switch ((*it).m_action)
    39. {
    40. case FilterAction_Has:
    41. if (sourceModel()->data(index).toString().contains((*it).m_value))
    42. accept = true;
    43. break;
    44. case FilterAction_Is:
    45. if ((sourceModel()->data(index).toString() == (*it).m_value.pattern()))
    46. accept = true;
    47. break;
    48. case FilterAction_LessThan:
    49. if ((sourceModel()->data(index).toDouble() < (*it).m_value.pattern().toDouble()))
    50. accept = true;
    51. break;
    52. case FilterAction_MoreThan:
    53. if ((sourceModel()->data(index).toDouble() > (*it).m_value.pattern().toDouble()))
    54. accept = true;
    55. break;
    56. default:
    57. break;
    58. }
    59. }
    60. return accept;
    61. }
    To copy to clipboard, switch view to plain text mode 

    I know it could be better, i.e. to use QString in the filter and convert it to QRegExp if needed, not the other way around, also, the if's themselves are not quite needed.
    But i don't really see, what can cause that behaviour that i described previously...

  2. #2
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Custom proxy model issue

    Any ideas fresh in the morning perhaps?

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

    Default Re: Custom proxy model issue

    The code seems ok, provided those two for loops work as you expect them to work. Which version of Qt are you using? I remember there were some issues about missing items related to the proxy back around Qt 4.2.

    BTW. Your and-or mechanism is a bit ambigous. Does X and Y or Z mean (X and Y) or Z or X and (Y or Z)? Because you can only represent the first one using your approach. Storing everything in a tree-like structure would be more flexible. You could then even mix ands and ors - (A and (B or C)) or (D and E).

  4. #4
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Custom proxy model issue

    I am using 4.3.2.

    ( About the implementation, you are absolutely right. Using a tree with and/or as nodes and the filters themselves as leaves, then using inorder traversing to interpret the advanced filter would be a much better approach, and one i will definitely consider.

    However, sadly, i dont think this influences the problem which i described. )

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

    Default Re: Custom proxy model issue

    I suggest you insert some qDebug() statements here and there and use them to pinpoint what exactly happens. If you know what happens, it'll be easier to find a solution.

  6. #6
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Custom proxy model issue

    I will most certainly try Wysota, though i dont really know what to watch out for.

    Thanks for your assistance, i appreciate it.

Similar Threads

  1. Custom Model Help PLz
    By Simz in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2007, 16:28
  2. Help with getting my custom model working
    By thomaspu in forum Qt Programming
    Replies: 19
    Last Post: 29th July 2007, 19:35
  3. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 14:54
  4. Model and Proxy
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 22:05
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03

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.