From df909d8b1fb1ba12de890f140ce2a873a4799bd2 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 10 Mar 2016 18:32:48 +0300 Subject: QItemSelectionModel: refactoring of internal functions Introduce template helper function qSelectionIndexes(). Template argument is container. Now we have the same code for QVector and QList. Also it's needed for a follow-up change in this file: add method QModelIndex QItemSelection::index(). Change-Id: I7f86a9b96e5feac9873cf0df7a1cbca74f9191ec Reviewed-by: Marc Mutz --- src/corelib/itemmodels/qitemselectionmodel.cpp | 28 +++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index dd913f957b..b2aacfa5aa 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -327,6 +327,15 @@ static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContain } } +template +static ModelIndexContainer qSelectionIndexes(const QItemSelection &selection) +{ + ModelIndexContainer result; + for (const auto &range : selection) + indexesFromRange(range, result); + return result; +} + /*! Returns \c true if the selection range contains no selectable item \since 4.7 @@ -469,20 +478,7 @@ bool QItemSelection::contains(const QModelIndex &index) const QModelIndexList QItemSelection::indexes() const { - QModelIndexList result; - QList::const_iterator it = begin(); - for (; it != end(); ++it) - indexesFromRange(*it, result); - return result; -} - -static QVector qSelectionPersistentindexes(const QItemSelection &sel) -{ - QVector result; - QList::const_iterator it = sel.constBegin(); - for (; it != sel.constEnd(); ++it) - indexesFromRange(*it, result); - return result; + return qSelectionIndexes(*this); } static QVector > qSelectionPersistentRowLengths(const QItemSelection &sel) @@ -892,8 +888,8 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList>(ranges); + savedPersistentCurrentIndexes = qSelectionIndexes>(currentSelection); } } /*! -- cgit v1.2.3