Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QItemSelection::merge() is really slow
QtWS25 Last Chance

QItemSelection::merge() is really slow

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
treeviewquick controlsselectionmodel
1 Posts 1 Posters 559 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andreh
    wrote on 28 Jan 2019, 11:52 last edited by
    #1

    Hi!

    I need to select all indexes of a Controls 1 TreeView. To do this, I've written a method which traverses the tree, makes a QItemSelection at each level and merge it with the QItemSelection returned by the method :

    QItemSelection LocationModel::treeSelection() const
    {
        QModelIndex root;
        QModelIndexList treeList;
        QItemSelection selection;
    
        for (int row = 0; row < rowCount(root); row++)
            treeList.push_back(index(row, 0, root));
        QItemSelection rootSelection(index(0, 0, root), index(rowCount() - 1, 0, root));
        selection.merge(rootSelection, QItemSelectionModel::Select);
    
        for (int i = 0; i < treeList.length(); i++) {
            QModelIndex parent = treeList[i];
            QItemSelection sel(index(0, 0, parent), index(rowCount(parent) - 1, 0, parent));
            selection.merge(sel, QItemSelectionModel::Select);
            for (int row = 0; row < rowCount(parent); row++)
                treeList.push_back(index(row, 0, parent));
        }
    
        return selection;
    }
    

    Then i pass this QItemSelection to the ItemSelectionModel of the TreeView.

    It works, but the performance is bad: for a 1000-items tree, it takes 2030ms!
    The bottleneck seems to be the QItemSelection::merge() method... Is it possible to optimize it? Or to use a faster method to make a selection?

    1 Reply Last reply
    1

    1/1

    28 Jan 2019, 11:52

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved