Results 1 to 2 of 2

Thread: QSortFilterProxyModel very slow when moving a lot of rows

  1. #1
    Join Date
    Dec 2020
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Angry QSortFilterProxyModel very slow when moving a lot of rows

    Hi All,

    I have a QSortFilterProxyModel connected to a QAbstractItemModel that implements a tree.

    I need to move ~8000 rows around which should be fine.

    However, for each one of those moves (done with individual pairs of beginMoveRows / endMoveRows) the QSortFilterProxyModel clears all the internal index mappings and then tries to update all persistent indexes right after (that's all in QSortFilterProxyModelPrivate::_q_sourceLayoutChang ed). The problem is that updating the persistent indexes re-creates the mappings again and forces everything to sort, even when dynamic sorting is disabled (this is done in QSortFilterProxyModelPrivate::create_mapping). This is done for each row that is moved, and since I am using QStrings sorting is VERY slow.

    I'm considering storing my data already sorted so I avoid all the string comparisons, but before I go that route I wanted to ask. Does the QSortFilterProxyModel need to do all this creating/destroying/sorting of the mappings, is there a way to avoid it? Am I using this wrong?

    Thanks a lot!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,122
    Thanks
    291
    Thanked 847 Times in 834 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSortFilterProxyModel very slow when moving a lot of rows

    If you are doing a pairwise move of 8000 rows, then this will be slow, because each move will cause the proxy model to update itself as you have seen.

    It seems to me that instead of doing it pairwise, you might simply modify your model "behind the curtain" all at once, and use the QAbstractItemModel::beginResetModel() / QAbstractItemModel::endResetModel() notifications instead. The proxy will do the same work of recreating the mappings, but will do it only once.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. (PyQt) QSortFilterProxyModel very slow when sorting
    By TheGrudge in forum Qt Programming
    Replies: 0
    Last Post: 17th January 2021, 12:44
  2. Moving up and down the selected rows in a QTableview
    By Raghaw in forum Qt Programming
    Replies: 0
    Last Post: 28th January 2013, 11:04
  3. QSortFilterProxyModel::insertRows always adds rows to the end
    By Agnostic Pope in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2012, 23:23
  4. QAbstactItemView selection after moving rows
    By craig_d in forum Qt Programming
    Replies: 4
    Last Post: 16th April 2012, 08:43
  5. Moving Items in QTableView with QSortFilterProxyModel
    By Rudolf Rendier in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2012, 15:07

Tags for this Thread

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.