Use the sibling method to make iteration over a range potentially faster.
authorStephen Kelly <stephen.kelly@kdab.com>
Wed, 26 Sep 2012 15:26:21 +0000 (17:26 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 27 Sep 2012 16:35:55 +0000 (18:35 +0200)
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>
src/corelib/itemmodels/qitemselectionmodel.cpp

index 98afaa3..254e952 100644 (file)
@@ -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);