diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index a558a0aa2fe..70063a10bff 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -238,7 +238,7 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange & */ -static void rowLengthsFromRange(const QItemSelectionRange &range, QList> &result) +static void rowLengthsFromRange(const QItemSelectionRange &range, QList> &result) { if (range.isValid() && range.model()) { const QModelIndex topLeft = range.topLeft(); @@ -249,7 +249,7 @@ static void rowLengthsFromRange(const QItemSelectionRange &range, QList(*this); } -static QList> qSelectionPersistentRowLengths(const QItemSelection &sel) +static QList> qSelectionPersistentRowLengths(const QItemSelection &sel) { - QList> result; + QList> result; for (const QItemSelectionRange &range : sel) rowLengthsFromRange(range, result); return result; @@ -875,7 +875,7 @@ void QItemSelectionModelPrivate::layoutAboutToBeChanged(const QList> &rowLengths) +static QItemSelection mergeRowLengths(const QList> &rowLengths) { if (rowLengths.isEmpty()) return QItemSelection(); diff --git a/src/corelib/itemmodels/qitemselectionmodel_p.h b/src/corelib/itemmodels/qitemselectionmodel_p.h index d3138971d61..689cd26bd28 100644 --- a/src/corelib/itemmodels/qitemselectionmodel_p.h +++ b/src/corelib/itemmodels/qitemselectionmodel_p.h @@ -82,8 +82,8 @@ public: QItemSelectionModel::SelectionFlags currentCommand; QList savedPersistentIndexes; QList savedPersistentCurrentIndexes; - QList> savedPersistentRowLengths; - QList> savedPersistentCurrentRowLengths; + QList> savedPersistentRowLengths; + QList> savedPersistentCurrentRowLengths; // optimization when all indexes are selected bool tableSelected; QPersistentModelIndex tableParent; diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index c02fb7619b6..a9ead2e1ebb 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -16,7 +15,7 @@ QT_BEGIN_NAMESPACE -typedef QList> QModelIndexPairList; +using QModelIndexPairList = QList>; struct QSortFilterProxyModelDataChanged { @@ -333,10 +332,10 @@ public: int find_source_sort_column() const; void sort_source_rows(QList &source_rows, const QModelIndex &source_parent) const; - QList>> proxy_intervals_for_source_items_to_add( + QList>> proxy_intervals_for_source_items_to_add( const QList &proxy_to_source, const QList &source_items, const QModelIndex &source_parent, Qt::Orientation orient) const; - QList> proxy_intervals_for_source_items( + QList> proxy_intervals_for_source_items( const QList &source_to_proxy, const QList &source_items) const; void insert_source_items( QList &source_to_proxy, QList &proxy_to_source, @@ -705,10 +704,10 @@ void QSortFilterProxyModelPrivate::sort_source_rows( The result is a vector of pairs, where each pair represents a (start, end) tuple, sorted in ascending order. */ -QList> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( +QList> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( const QList &source_to_proxy, const QList &source_items) const { - QList> proxy_intervals; + QList> proxy_intervals; if (source_items.isEmpty()) return proxy_intervals; @@ -725,19 +724,19 @@ QList> QSortFilterProxyModelPrivate::proxy_intervals_for_source_ ++source_items_index; } // Add interval to result - proxy_intervals.append(QPair(first_proxy_item, last_proxy_item)); + proxy_intervals.emplace_back(first_proxy_item, last_proxy_item); } std::stable_sort(proxy_intervals.begin(), proxy_intervals.end()); // Consolidate adjacent intervals for (int i = proxy_intervals.size()-1; i > 0; --i) { - QPair &interval = proxy_intervals[i]; - QPair &preceeding_interval = proxy_intervals[i - 1]; + std::pair &interval = proxy_intervals[i]; + std::pair &preceeding_interval = proxy_intervals[i - 1]; if (interval.first == preceeding_interval.second + 1) { preceeding_interval.second = interval.second; interval.first = interval.second = -1; } } - proxy_intervals.removeIf([](QPair interval) { return interval.first < 0; }); + proxy_intervals.removeIf([](std::pair interval) { return interval.first < 0; }); return proxy_intervals; } @@ -766,7 +765,7 @@ void QSortFilterProxyModelPrivate::remove_source_items( const auto end = proxy_intervals.rend(); for (auto it = proxy_intervals.rbegin(); it != end; ++it) { - const QPair &interval = *it; + const std::pair &interval = *it; const int proxy_start = interval.first; const int proxy_end = interval.second; remove_proxy_interval(source_to_proxy, proxy_to_source, proxy_start, proxy_end, @@ -820,12 +819,12 @@ void QSortFilterProxyModelPrivate::remove_proxy_interval( items), where items is a vector containing the (sorted) source items that should be inserted at that proxy model location. */ -QList>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( +QList>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( const QList &proxy_to_source, const QList &source_items, const QModelIndex &source_parent, Qt::Orientation orient) const { Q_Q(const QSortFilterProxyModel); - QList>> proxy_intervals; + QList>> proxy_intervals; if (source_items.isEmpty()) return proxy_intervals; @@ -880,7 +879,7 @@ QList>> QSortFilterProxyModelPrivate::proxy_intervals_for_ } // Add interval to result - proxy_intervals.append(QPair>(proxy_item, source_items_in_interval)); + proxy_intervals.emplace_back(proxy_item, std::move(source_items_in_interval)); } return proxy_intervals; } @@ -908,7 +907,7 @@ void QSortFilterProxyModelPrivate::insert_source_items( const auto end = proxy_intervals.rend(); for (auto it = proxy_intervals.rbegin(); it != end; ++it) { - const QPair> &interval = *it; + const std::pair> &interval = *it; const int proxy_start = interval.first; const QList &source_items = interval.second; const int proxy_end = proxy_start + source_items.size() - 1; @@ -1137,7 +1136,7 @@ void QSortFilterProxyModelPrivate::updateChildrenMapping(const QModelIndex &sour Qt::Orientation orient, int start, int end, int delta_item_count, bool remove) { // see if any mapped children should be (re)moved - QList> moved_source_index_mappings; + QList> moved_source_index_mappings; auto it2 = parent_mapping->mapped_children.begin(); for ( ; it2 != parent_mapping->mapped_children.end();) { const QModelIndex source_child_index = *it2; @@ -1171,7 +1170,7 @@ void QSortFilterProxyModelPrivate::updateChildrenMapping(const QModelIndex &sour Mapping *cm = source_index_mapping.take(source_child_index); Q_ASSERT(cm); // we do not reinsert right away, because the new index might be identical with another, old index - moved_source_index_mappings.append(QPair(new_index, cm)); + moved_source_index_mappings.emplace_back(new_index, cm); } } @@ -1228,7 +1227,7 @@ QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() con for (const QPersistentModelIndexData *data : std::as_const(persistent.indexes)) { const QModelIndex &proxy_index = data->index; QModelIndex source_index = q->mapToSource(proxy_index); - source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index))); + source_indexes.emplace_back(proxy_index, source_index); } return source_indexes; } diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index 002f500263c..dfbe72b2891 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -292,12 +292,12 @@ bool QStringListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, return true; } -static bool ascendingLessThan(const QPair &s1, const QPair &s2) +static bool ascendingLessThan(const std::pair &s1, const std::pair &s2) { return s1.first < s2.first; } -static bool decendingLessThan(const QPair &s1, const QPair &s2) +static bool decendingLessThan(const std::pair &s1, const std::pair &s2) { return s1.first > s2.first; } @@ -309,11 +309,11 @@ void QStringListModel::sort(int, Qt::SortOrder order) { emit layoutAboutToBeChanged(QList(), VerticalSortHint); - QList> list; + QList> list; const int lstCount = lst.size(); list.reserve(lstCount); for (int i = 0; i < lstCount; ++i) - list.append(QPair(lst.at(i), i)); + list.emplace_back(lst.at(i), i); if (order == Qt::AscendingOrder) std::sort(list.begin(), list.end(), ascendingLessThan);