Avoid looping over the indexes multiple times to create a persistent list.

Change-Id: I089d272254eb531cd27c7b23fbab4d7183ba01d4
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-09-26 18:30:38 +02:00 committed by The Qt Project
parent 2d97c6a474
commit edec823c00

View File

@ -291,7 +291,8 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &
it avoid concatenating list and works on one
*/
static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &result)
template<typename ModelIndexContainer>
static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContainer &result)
{
if (range.isValid() && range.model()) {
const QModelIndex topLeft = range.topLeft();
@ -303,7 +304,7 @@ static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &
QModelIndex index = columnLeader.sibling(row, column);
Qt::ItemFlags flags = range.model()->flags(index);
if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
result.append(index);
result.push_back(index);
}
}
}
@ -458,6 +459,15 @@ QModelIndexList QItemSelection::indexes() const
return result;
}
static QList<QPersistentModelIndex> qSelectionPersistentindexes(const QItemSelection &sel)
{
QList<QPersistentModelIndex> result;
QList<QItemSelectionRange>::const_iterator it = sel.constBegin();
for (; it != sel.constEnd(); ++it)
indexesFromRange(*it, result);
return result;
}
/*!
Merges the \a other selection with this QItemSelection using the
\a command given. This method guarantees that no ranges are overlapping.
@ -826,13 +836,8 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged()
}
tableSelected = false;
QModelIndexList indexes = ranges.indexes();
QModelIndexList::const_iterator it;
for (it = indexes.constBegin(); it != indexes.constEnd(); ++it)
savedPersistentIndexes.append(QPersistentModelIndex(*it));
indexes = currentSelection.indexes();
for (it = indexes.constBegin(); it != indexes.constEnd(); ++it)
savedPersistentCurrentIndexes.append(QPersistentModelIndex(*it));
savedPersistentIndexes = qSelectionPersistentindexes(ranges);
savedPersistentCurrentIndexes = qSelectionPersistentindexes(currentSelection);
}
/*!