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>
This commit is contained in:
Stephen Kelly 2012-09-27 11:22:25 +02:00 committed by The Qt Project
parent 978d3d01cf
commit cea7a87d5f

View File

@ -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));
}