summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qitemselectionmodel.cpp
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-09-27 11:22:25 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-27 18:35:55 +0200
commitcea7a87d5fe482afa83a8b610b5b39ce83ab27c9 (patch)
tree4aaf577a449a5e29079e870f4325d46902939b40 /src/corelib/itemmodels/qitemselectionmodel.cpp
parent978d3d01cfa063017fdce1391b60efb7a4fc8df2 (diff)
Take a QPersistentIndex out of the container instead of casting it.
These indexes are later used as the boundary points of a QItemSelectionRange anyway, which means that they're going to become QPersistentModelIndexes again soon. Because QPersistentModelIndex::row and ::column API are not inline, we cache the resulting values in the loop. Change-Id: Ib5099148269a8ccbb7ff2d8819a347e429c55dd1 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels/qitemselectionmodel.cpp')
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index d55cbe9d97..74bc0e6a9d 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -852,16 +852,26 @@ static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes
// merge columns
int i = 0;
while (i < indexes.count()) {
- QModelIndex tl = indexes.at(i);
- QModelIndex br = tl;
+ const QPersistentModelIndex &tl = indexes.at(i);
+ QPersistentModelIndex br = tl;
+ QModelIndex brParent = br.parent();
+ int brRow = br.row();
+ int brColumn = br.column();
while (++i < indexes.count()) {
- QModelIndex next = indexes.at(i);
- if ((next.parent() == br.parent())
- && (next.row() == br.row())
- && (next.column() == br.column() + 1))
+ const QPersistentModelIndex &next = indexes.at(i);
+ const QModelIndex nextParent = next.parent();
+ const int nextRow = next.row();
+ const int nextColumn = next.column();
+ if ((nextParent == brParent)
+ && (nextRow == brRow)
+ && (nextColumn == brColumn + 1)) {
br = next;
- else
+ brParent = nextParent;
+ brRow = nextRow;
+ brColumn = nextColumn;
+ } else {
break;
+ }
}
colSpans.append(QItemSelectionRange(tl, br));
}