diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-12-12 09:58:57 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-12-14 04:16:16 +0100 |
commit | 91d341e560e9a54d201279d53701ff071256ad6c (patch) | |
tree | 3d21bf2bc3d719d2fcc84639a45130bd1f420850 | |
parent | 6ef62f7dc4d6cb690fc297954b3cfcd1de415910 (diff) |
Itemmodels: s/QPair/std::pair/
Also port from qMakePair() to just braced initialization and CTAD.
As a drive-by, use emplacement instead of appending pairs explicitly,
rewrite typedef into `using`, and remove the qpair.h include from the
.cpp file (cannot affect other TUs and <utility> is considered
included in qcompilerdetection.h).
Pick-to: 6.7
Task-number: QTBUG-115841
Change-Id: Ia985520dfce6b77b1c0fe7669fc92d2df97e1b06
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 10 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel_p.h | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 35 | ||||
-rw-r--r-- | src/corelib/itemmodels/qstringlistmodel.cpp | 8 |
4 files changed, 28 insertions, 29 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index a558a0aa2f..70063a10bf 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<QPair<QPersistentModelIndex, uint>> &result) +static void rowLengthsFromRange(const QItemSelectionRange &range, QList<std::pair<QPersistentModelIndex, uint>> &result) { if (range.isValid() && range.model()) { const QModelIndex topLeft = range.topLeft(); @@ -249,7 +249,7 @@ static void rowLengthsFromRange(const QItemSelectionRange &range, QList<QPair<QP // We don't need to keep track of ItemIsSelectable and ItemIsEnabled here. That is // required in indexesFromRange() because that method is called from public API // which requires the limitation. - result.push_back(qMakePair(QPersistentModelIndex(topLeft.sibling(row, column)), width)); + result.emplace_back(topLeft.sibling(row, column), width); } } } @@ -432,9 +432,9 @@ QModelIndexList QItemSelection::indexes() const return qSelectionIndexes<QModelIndexList>(*this); } -static QList<QPair<QPersistentModelIndex, uint>> qSelectionPersistentRowLengths(const QItemSelection &sel) +static QList<std::pair<QPersistentModelIndex, uint>> qSelectionPersistentRowLengths(const QItemSelection &sel) { - QList<QPair<QPersistentModelIndex, uint>> result; + QList<std::pair<QPersistentModelIndex, uint>> result; for (const QItemSelectionRange &range : sel) rowLengthsFromRange(range, result); return result; @@ -875,7 +875,7 @@ void QItemSelectionModelPrivate::layoutAboutToBeChanged(const QList<QPersistentM /*! \internal */ -static QItemSelection mergeRowLengths(const QList<QPair<QPersistentModelIndex, uint>> &rowLengths) +static QItemSelection mergeRowLengths(const QList<std::pair<QPersistentModelIndex, uint>> &rowLengths) { if (rowLengths.isEmpty()) return QItemSelection(); diff --git a/src/corelib/itemmodels/qitemselectionmodel_p.h b/src/corelib/itemmodels/qitemselectionmodel_p.h index d3138971d6..689cd26bd2 100644 --- a/src/corelib/itemmodels/qitemselectionmodel_p.h +++ b/src/corelib/itemmodels/qitemselectionmodel_p.h @@ -82,8 +82,8 @@ public: QItemSelectionModel::SelectionFlags currentCommand; QList<QPersistentModelIndex> savedPersistentIndexes; QList<QPersistentModelIndex> savedPersistentCurrentIndexes; - QList<QPair<QPersistentModelIndex, uint>> savedPersistentRowLengths; - QList<QPair<QPersistentModelIndex, uint>> savedPersistentCurrentRowLengths; + QList<std::pair<QPersistentModelIndex, uint>> savedPersistentRowLengths; + QList<std::pair<QPersistentModelIndex, uint>> 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 c02fb7619b..a9ead2e1eb 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -6,7 +6,6 @@ #include <qsize.h> #include <qdebug.h> #include <qdatetime.h> -#include <qpair.h> #include <qstringlist.h> #include <private/qabstractitemmodel_p.h> #include <private/qabstractproxymodel_p.h> @@ -16,7 +15,7 @@ QT_BEGIN_NAMESPACE -typedef QList<QPair<QModelIndex, QPersistentModelIndex>> QModelIndexPairList; +using QModelIndexPairList = QList<std::pair<QModelIndex, QPersistentModelIndex>>; struct QSortFilterProxyModelDataChanged { @@ -333,10 +332,10 @@ public: int find_source_sort_column() const; void sort_source_rows(QList<int> &source_rows, const QModelIndex &source_parent) const; - QList<QPair<int, QList<int>>> proxy_intervals_for_source_items_to_add( + QList<std::pair<int, QList<int>>> proxy_intervals_for_source_items_to_add( const QList<int> &proxy_to_source, const QList<int> &source_items, const QModelIndex &source_parent, Qt::Orientation orient) const; - QList<QPair<int, int>> proxy_intervals_for_source_items( + QList<std::pair<int, int>> proxy_intervals_for_source_items( const QList<int> &source_to_proxy, const QList<int> &source_items) const; void insert_source_items( QList<int> &source_to_proxy, QList<int> &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<QPair<int, int>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( +QList<std::pair<int, int>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items( const QList<int> &source_to_proxy, const QList<int> &source_items) const { - QList<QPair<int, int>> proxy_intervals; + QList<std::pair<int, int>> proxy_intervals; if (source_items.isEmpty()) return proxy_intervals; @@ -725,19 +724,19 @@ QList<QPair<int, int>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_ ++source_items_index; } // Add interval to result - proxy_intervals.append(QPair<int, int>(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<int, int> &interval = proxy_intervals[i]; - QPair<int, int> &preceeding_interval = proxy_intervals[i - 1]; + std::pair<int, int> &interval = proxy_intervals[i]; + std::pair<int, int> &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<int, int> interval) { return interval.first < 0; }); + proxy_intervals.removeIf([](std::pair<int, int> 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<int, int> &interval = *it; + const std::pair<int, int> &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<QPair<int, QList<int>>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( +QList<std::pair<int, QList<int>>> QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add( const QList<int> &proxy_to_source, const QList<int> &source_items, const QModelIndex &source_parent, Qt::Orientation orient) const { Q_Q(const QSortFilterProxyModel); - QList<QPair<int, QList<int>>> proxy_intervals; + QList<std::pair<int, QList<int>>> proxy_intervals; if (source_items.isEmpty()) return proxy_intervals; @@ -880,7 +879,7 @@ QList<QPair<int, QList<int>>> QSortFilterProxyModelPrivate::proxy_intervals_for_ } // Add interval to result - proxy_intervals.append(QPair<int, QList<int>>(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<int, QList<int>> &interval = *it; + const std::pair<int, QList<int>> &interval = *it; const int proxy_start = interval.first; const QList<int> &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<QPair<QModelIndex, Mapping *>> moved_source_index_mappings; + QList<std::pair<QModelIndex, Mapping *>> 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<QModelIndex, Mapping*>(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 002f500263..dfbe72b289 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<QString, int> &s1, const QPair<QString, int> &s2) +static bool ascendingLessThan(const std::pair<QString, int> &s1, const std::pair<QString, int> &s2) { return s1.first < s2.first; } -static bool decendingLessThan(const QPair<QString, int> &s1, const QPair<QString, int> &s2) +static bool decendingLessThan(const std::pair<QString, int> &s1, const std::pair<QString, int> &s2) { return s1.first > s2.first; } @@ -309,11 +309,11 @@ void QStringListModel::sort(int, Qt::SortOrder order) { emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint); - QList<QPair<QString, int>> list; + QList<std::pair<QString, int>> list; const int lstCount = lst.size(); list.reserve(lstCount); for (int i = 0; i < lstCount; ++i) - list.append(QPair<QString, int>(lst.at(i), i)); + list.emplace_back(lst.at(i), i); if (order == Qt::AscendingOrder) std::sort(list.begin(), list.end(), ascendingLessThan); |