Results 1 to 2 of 2

Thread: Synchronize sorting between tables

  1. #1
    Join Date
    Feb 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Synchronize sorting between tables

    Hello.

    I'm currently working on a Qt Project with QTableViews and QAbstractTableModel subclasses.

    There are 2 synchronized tables (same number of row, synchronized scrollbar, etc.) and we are working on adding sorting on tables.

    I use a customer QSortFilterProxyModel implementation to filter rows and sort model elements.

    Here is an example/demo:
    Sort.jpg

    I wish to automatically arrange rows position in the right table when the left table is sorted by column (and vice-versa).

    Is there any signal/slot mechanism to modify mapping tables of QSortFilterModel?

    We try to implement something like :
    Qt Code:
    1. bool SortFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
    2. {
    3. if(m_b_isSortedFromOtherModel)
    4. {
    5. return otherInstance->lessThanFromOther(left, right);
    6. }
    7. else
    8. {
    9. return QSortFilterProxyModel::lessThan(left, right);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    But the result is not really conclusive, I think we could find something more simple...


    Thanks for the help.
    Bye.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Synchronize sorting between tables

    If a model is sorted, essentially you move rows here and there. The mapping is kept in QSortFilterModel implementation. Now if you want some other model to know of this change of rows, it should point to the proxy model rather than the main model. For the rows were moved in proxy model not the main model. In you case, I think there are two models.
    There can be two way I can think of. One is to make one big model. Let it include all the columns, if one is to one mapping is possible(must be right). Then add a QSFPM on top of that which gives the rows. The model has the view which only looks at columns it is interested in, while on the right, the view sees what it is interested in. Or write two additional QSFPM for the two views. filter acts on the main QSFPM.
    In the other way, you need to track the mappings yourself. Basically which row in left model points to which row in right. Calling less than of left with right modelindex won't help. To create mapping, you need to write the index and parent functions and introduce you struct Map* as a void* into modelindex. So suppose you have mapping in the right model. All you'll do in the right qsfpm is to get void* internalPointer, cast it to map*, use mapFromSource to get left QSFPM index and THEN call the lessthan function on left model.
    Hope I was able to get my point through.

Similar Threads

  1. synchronize QWebPage
    By januszmk in forum Newbie
    Replies: 0
    Last Post: 4th August 2012, 11:45
  2. Replies: 4
    Last Post: 13th July 2010, 05:17
  3. Replies: 1
    Last Post: 16th May 2010, 19:25
  4. synchronize two QSplitters
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2007, 17:14

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.