diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-09-26 17:26:21 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-27 18:35:55 +0200 |
commit | 2d97c6a4748a6a94ce28f86b69c03bf1a56536aa (patch) | |
tree | 4a4c26b0c1cb185866b5c2e616e597b53c6bd19f /src | |
parent | a7b2c43dfb25f1c6a1dc357bc353e210725c15d0 (diff) |
Use the sibling method to make iteration over a range potentially faster.
The implementation of QAIM can implement an efficient version of sibling.
Task-number: QTBUG-17732
Change-Id: I474dbc11e52b3ccc42e2165bc9336882fab13d03
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 98afaa3b48..254e952b8c 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -294,10 +294,13 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange & static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &result) { if (range.isValid() && range.model()) { - const QModelIndex parent = range.parent(); - for (int column = range.left(); column <= range.right(); ++column) { - for (int row = range.top(); row <= range.bottom(); ++row) { - QModelIndex index = range.model()->index(row, column, parent); + const QModelIndex topLeft = range.topLeft(); + const int bottom = range.bottom(); + const int right = range.right(); + for (int row = topLeft.row(); row <= bottom; ++row) { + const QModelIndex columnLeader = topLeft.sibling(row, topLeft.column()); + for (int column = topLeft.column(); column <= right; ++column) { + QModelIndex index = columnLeader.sibling(row, column); Qt::ItemFlags flags = range.model()->flags(index); if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) result.append(index); |