Results 1 to 7 of 7

Thread: design help: proxying for filtering, sorting, and structure modifications

  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Question design help: proxying for filtering, sorting, and structure modifications

    Greetings,

    In my QSortFilterProxy model I have implemented the filterAcceptsRow and lessThan methods. A new requirement has creep'd in which requires that the view needs to display/move some of the indexes as child indexes of other nodes. Basically there is meta-data with each index's data that indicates which other node it needs to be a displayed as a child of.

    Without going into a trial and error mode I am wondering: What is the correct chain of proxy's in which I would have to implement to do this correctly?

    * note: the model is only sorted on instantiation, sorting is otherwise disabled.

    From what I understand this is about the design I would need to implement:
    view <- AbstractProxy(mapTo, mapFrom) <- SortFilterProxy(lessThan, filterAccepts) <- AbstractItemModel

    Any suggestions or alternatives?

    tyvm!

    -BB
    Last edited by BreakBad; 14th June 2012 at 19:48.

  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: design help: proxying for filtering, sorting, and structure modifications

    An alternative is to use just one proxy that will do both filtering and mapping. Sorting can be done in the base model using QAbstractItemModel::sort() so a sorting proxy is not required in your situation.
    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. The following user says thank you to wysota for this useful post:

    BreakBad (14th June 2012)

  4. #3
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: design help: proxying for filtering, sorting, and structure modifications

    Simple is better than complex, thanks.


    Added after 27 minutes:


    Well, it appears sort() won't accommodate the method for sorting that I require (a 'hard' coded list for the sort order). So it appears I'll have to use the previously mentioned proxy stack.
    Last edited by BreakBad; 14th June 2012 at 20:51.

  5. #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: design help: proxying for filtering, sorting, and structure modifications

    sort() is a virtual method. You can implement it any way you want. Using a sort proxy just to sort once doesn't make much sense as QSortFilterProxyModel is rather an expensive object to use.
    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.


  6. #5
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: design help: proxying for filtering, sorting, and structure modifications

    Follow up question:

    Decided to use both the abstract and proxy layer, as I needed to filter and map. Now I'm running into difficulty passing the correct index from the views to other views.

    Here is the hierarchy:
    TreeView -> AbstractProxyModel -> SortFilterProxy -> AbstractItemModel <- SortFilterProxy <- TableView

    I'm trying to set the root index of the tableview by passing the current index of the treeview, resulting in "index from wrong model passed to mapFromSource"

    What is the correct method for achieving this?

    Currently I'm trying:
    tree_proxy_index = treeview.sourceModel().mapToSource(treeview.curren tIndex())
    item_model_index = tree_proxy_model.sourceModel().mapToSource(proxy_i ndex())
    table_proxy_index = table_proxy_model.mapFromSource(item_model_index) # warning occurs here
    table_view.setRootIndex(table_proxy_index)


    TYVM

  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: design help: proxying for filtering, sorting, and structure modifications

    What warning?
    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
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: design help: proxying for filtering, sorting, and structure modifications

    Quote Originally Posted by wysota View Post
    What warning?
    "index from wrong model passed to mapFromSource"

    Problem solved. I noticed the address in memory of my AbstractItemModel was different for each view. I had two entirely separate instantiations of the model because of the way my init()'s were setup.

Similar Threads

  1. QGraphicsScene Z Ordering
    By bruceariggs in forum Newbie
    Replies: 0
    Last Post: 27th September 2011, 15:41
  2. modifications of decimal separator
    By 21did21 in forum Qwt
    Replies: 2
    Last Post: 2nd August 2011, 21:41
  3. Replies: 12
    Last Post: 26th June 2011, 11:26
  4. Static Linking Ordering Issues
    By SneakyPeterson in forum Newbie
    Replies: 1
    Last Post: 11th June 2010, 11:51
  5. Documenting modifications in LGPL QT
    By jupi32000 in forum Newbie
    Replies: 1
    Last Post: 25th July 2009, 11:58

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.