From 8327e0e0654abec01e0ee7183aea99d155a79200 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Fri, 15 Mar 2019 07:52:58 +0100 Subject: [PATCH] [kitemmodels] make it compile without foreach Summary: make it compile without foreach Test Plan: autotest ok Reviewers: dfaure Reviewed By: dfaure Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D19778 --- CMakeLists.txt | 2 +- .../proxymodeltestsuite/dynamictreemodel.cpp | 23 ++++++++++--------- .../proxymodeltestsuite/modeleventlogger.cpp | 4 ++-- .../proxymodeltestsuite/modeleventlogger.h | 4 ++-- autotests/proxymodeltestsuite/modelspy.cpp | 10 ++++---- autotests/proxymodeltestsuite/modelspy.h | 4 ++-- .../proxymodeltestsuite/proxymodeltest.cpp | 7 +++--- .../proxymodeltestsuite/proxymodeltest.h | 3 ++- autotests/test_model_helpers.h | 2 +- src/kbreadcrumbselectionmodel.cpp | 8 +++---- src/kcheckableproxymodel.cpp | 6 +++-- src/kconcatenaterowsproxymodel.cpp | 10 ++++---- src/kdescendantsproxymodel.cpp | 5 ++-- src/kextracolumnsproxymodel.cpp | 6 ++--- src/klinkitemselectionmodel.cpp | 2 +- src/kmodelindexproxymapper.cpp | 6 ++--- src/krecursivefilterproxymodel.cpp | 3 ++- src/kselectionproxymodel.cpp | 23 +++++++++++-------- tests/proxymodeltestapp/breadcrumbswidget.cpp | 4 ++-- .../kreparentingproxymodel.cpp | 8 +++---- .../proxymodeltestapp/matchcheckingwidget.cpp | 4 ++-- .../modelcommanderwidget.cpp | 2 +- 22 files changed, 78 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44660c0..650bd29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX KITEMMODELS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kitemmodels_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5ItemModelsConfigVersion.cmake" SOVERSION 5) - +add_definitions(-DQT_NO_FOREACH) add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(autotests) diff --git a/autotests/proxymodeltestsuite/dynamictreemodel.cpp b/autotests/proxymodeltestsuite/dynamictreemodel.cpp index 9e0f20d..8d6f933 100644 --- a/autotests/proxymodeltestsuite/dynamictreemodel.cpp +++ b/autotests/proxymodeltestsuite/dynamictreemodel.cpp @@ -195,7 +195,8 @@ bool DynamicTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action int _row; static const int column = 0; QHash > >::const_iterator it; - Q_FOREACH (const QByteArray &ba, encoded.split('\0')) { + const auto lst = encoded.split('\0'); + for (const QByteArray &ba : lst) { id = ba.toInt(&ok); if (!ok) { qDebug() << ba; @@ -281,7 +282,7 @@ bool DynamicTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action } int offset = firstCommand->endRow() - firstCommand->startRow() + 1; - Q_FOREACH (ModelMoveCommand *moveCommand, moveCommands) { + for (ModelMoveCommand *moveCommand : qAsConst(moveCommands)) { moveCommand->setDestAncestors(indexToPath(destParent)); moveCommand->setDestRow(destRowIndex.row() + offset); moveCommand->doCommand(); @@ -601,8 +602,8 @@ void ModelInsertAndRemoveQueuedCommand::purgeItem(qint64 parent) if (!childItemRows.isEmpty()) { for (int col = 0; col < m_numCols; col++) { - QList childItems = childItemRows[col]; - Q_FOREACH (qint64 item, childItems) { + const QList childItems = childItemRows[col]; + for (qint64 item : childItems) { purgeItem(item); m_model->m_childItems[parent][col].removeOne(item); } @@ -679,12 +680,12 @@ void ModelRemoveCommand::doCommand() void ModelRemoveCommand::purgeItem(qint64 parent) { - QList > childItemRows = m_model->m_childItems.value(parent); + const QList > childItemRows = m_model->m_childItems.value(parent); if (!childItemRows.isEmpty()) { for (int col = 0; col < m_numCols; col++) { - QList childItems = childItemRows[col]; - Q_FOREACH (qint64 item, childItems) { + const QList childItems = childItemRows[col]; + for (qint64 item : childItems) { purgeItem(item); m_model->m_childItems[parent][col].removeOne(item); } @@ -737,7 +738,7 @@ void ModelMoveCommand::doCommand() } for (int column = 0; column < m_numCols; ++column) { - QList l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1); + const QList l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1); for (int i = m_startRow; i <= m_endRow; i++) { m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow); @@ -753,7 +754,7 @@ void ModelMoveCommand::doCommand() } } - Q_FOREACH (const qint64 id, l) { + for (const qint64 id : l) { if (!m_model->m_childItems.contains(destParent.internalId())) { m_model->m_childItems[destParent.internalId()].append(QList()); @@ -926,7 +927,7 @@ void ModelLayoutChangeCommand::doCommand() m_model->layoutAboutToBeChanged(); QModelIndexList oldList; - Q_FOREACH (const PersistentChange &change, m_changes) { + for (const PersistentChange &change : qAsConst(m_changes)) { const IndexFinder oldFinder(m_model, change.oldPath); oldList << oldFinder.getIndex(); } @@ -941,7 +942,7 @@ void ModelLayoutChangeCommand::doCommand() } QModelIndexList newList; - Q_FOREACH (const PersistentChange &change, m_changes) { + for (const PersistentChange &change : qAsConst(m_changes)) { const IndexFinder newFinder(m_model, change.newPath); newList << newFinder.getIndex(); } diff --git a/autotests/proxymodeltestsuite/modeleventlogger.cpp b/autotests/proxymodeltestsuite/modeleventlogger.cpp index a132163..76fd4a0 100644 --- a/autotests/proxymodeltestsuite/modeleventlogger.cpp +++ b/autotests/proxymodeltestsuite/modeleventlogger.cpp @@ -155,7 +155,7 @@ QString ModelEvent::rowAncestors() const { QString result(QStringLiteral("QList()")); - Q_FOREACH (const int row, m_rowAncestors) { + for (const int row : qAsConst(m_rowAncestors)) { result.append(" << "); result.append(QString::number(row)); } @@ -271,7 +271,7 @@ void ModelEventLogger::layoutAboutToBeChanged() m_oldPaths.clear(); m_persistentIndexes.clear(); const QModelIndexList list = static_cast(m_model)->per(); - Q_FOREACH (const QPersistentModelIndex &idx, list) { + for (const QPersistentModelIndex &idx : list) { m_persistentIndexes.append(idx); m_oldPaths.append(IndexFinder::indexToIndexFinder(idx).rows()); } diff --git a/autotests/proxymodeltestsuite/modeleventlogger.h b/autotests/proxymodeltestsuite/modeleventlogger.h index 444cc88..f279412 100644 --- a/autotests/proxymodeltestsuite/modeleventlogger.h +++ b/autotests/proxymodeltestsuite/modeleventlogger.h @@ -45,7 +45,7 @@ public: QString getPath(const QList &path) const { QString result(QStringLiteral("QList()")); - Q_FOREACH (const int part, path) { + for (const int part : path) { result.append(QLatin1String(" << ")); result.append(QString::number(part)); } @@ -123,7 +123,7 @@ public: QVariantList changes() const { QVariantList list; - Q_FOREACH (PersistentChange *change, m_changedPaths) { + for (PersistentChange *change : qAsConst(m_changedPaths)) { list.append(QVariant::fromValue(static_cast(change))); } return list; diff --git a/autotests/proxymodeltestsuite/modelspy.cpp b/autotests/proxymodeltestsuite/modelspy.cpp index 8e311ca..436e0f4 100644 --- a/autotests/proxymodeltestsuite/modelspy.cpp +++ b/autotests/proxymodeltestsuite/modelspy.cpp @@ -203,16 +203,16 @@ QModelIndexList ModelSpy::getDescendantIndexes(const QModelIndex &parent) return list; } -QList< QPersistentModelIndex > ModelSpy::toPersistent(QModelIndexList list) +QList< QPersistentModelIndex > ModelSpy::toPersistent(const QModelIndexList &list) { QList persistentList; - Q_FOREACH (const QModelIndex &idx, list) { + for (const QModelIndex &idx : list) { persistentList << QPersistentModelIndex(idx); } return persistentList; } -QModelIndexList ModelSpy::getUnchangedIndexes(const QModelIndex &parent, QList ignoredRanges) +QModelIndexList ModelSpy::getUnchangedIndexes(const QModelIndex &parent, const QList &ignoredRanges) { QModelIndexList list; int rowCount = m_model->rowCount(parent); @@ -221,7 +221,7 @@ QModelIndexList ModelSpy::getUnchangedIndexes(const QModelIndex &parent, QListindex(row, column, parent); Q_ASSERT(idx.isValid()); bool found = false; - Q_FOREACH (const QItemSelectionRange &range, ignoredRanges) { + for (const QItemSelectionRange &range : ignoredRanges) { if (range.topLeft().parent() == parent && range.topLeft().row() == idx.row()) { row = range.bottomRight().row() + 1; found = true; @@ -320,7 +320,7 @@ static const char *const signaltypes[] = { QDebug operator<<(QDebug d, ModelSpy *modelSpy) { d << "ModelSpy("; - Q_FOREACH (const QVariantList &list, (QList)(*modelSpy)) { + for (const QVariantList &list : qAsConst(*modelSpy)) { d << "SIGNAL("; int sigType = list.first().toInt(); d << signaltypes[sigType]; diff --git a/autotests/proxymodeltestsuite/modelspy.h b/autotests/proxymodeltestsuite/modelspy.h index b596cad..b124998 100644 --- a/autotests/proxymodeltestsuite/modelspy.h +++ b/autotests/proxymodeltestsuite/modelspy.h @@ -99,9 +99,9 @@ protected Q_SLOTS: private: void doPersist(); - QModelIndexList getUnchangedIndexes(const QModelIndex &parent, QList< QItemSelectionRange > ignoredRanges); + QModelIndexList getUnchangedIndexes(const QModelIndex &parent, const QList &ignoredRanges); QModelIndexList getDescendantIndexes(const QModelIndex &index); - QList< QPersistentModelIndex > toPersistent(QModelIndexList list); + QList< QPersistentModelIndex > toPersistent(const QModelIndexList &list); private: QAbstractItemModel *m_model; diff --git a/autotests/proxymodeltestsuite/proxymodeltest.cpp b/autotests/proxymodeltestsuite/proxymodeltest.cpp index 0f34733..13231b2 100644 --- a/autotests/proxymodeltestsuite/proxymodeltest.cpp +++ b/autotests/proxymodeltestsuite/proxymodeltest.cpp @@ -86,9 +86,9 @@ void ProxyModelTest::verifyExecutedTests() if (m_dataTags.contains(ProxyModelTestData::failTag())) { return; } - QSet unimplemented = m_modelCommanderTags.toSet().subtract(m_dataTags.toSet()); + const QSet unimplemented = m_modelCommanderTags.toSet().subtract(m_dataTags.toSet()); QString unimplementedTestsString(QStringLiteral("(")); - Q_FOREACH (const QString &test, unimplemented) { + for (const QString &test : unimplemented) { unimplementedTestsString.append(test + ","); } unimplementedTestsString.append(")"); @@ -586,7 +586,8 @@ void ProxyModelTest::doTest() QVERIFY(m_modelSpy->isEmpty()); // Persistent indexes should change by the amount described in change objects. - Q_FOREACH (PersistentIndexChange change, m_modelSpy->getChangeList()) { + const auto lst = m_modelSpy->getChangeList(); + for (PersistentIndexChange change : lst) { for (int i = 0; i < change.indexes.size(); i++) { QModelIndex idx = change.indexes.at(i); QPersistentModelIndex persistentIndex = change.persistentIndexes.at(i); diff --git a/autotests/proxymodeltestsuite/proxymodeltest.h b/autotests/proxymodeltestsuite/proxymodeltest.h index 0c92bba..14adeb1 100644 --- a/autotests/proxymodeltestsuite/proxymodeltest.h +++ b/autotests/proxymodeltestsuite/proxymodeltest.h @@ -756,7 +756,8 @@ PROXYMODELTESTSUITE_EXPORT uint qHash(const QVariant &var); QList testObjects; \ QStringList arguments; \ bool ok; \ - Q_FOREACH(const QString &arg, app.arguments()) \ + const auto lst = app.arguments(); \ + for (const QString &arg : lst) \ { \ int testObject = arg.toInt(&ok); \ if (arg == "-count") \ diff --git a/autotests/test_model_helpers.h b/autotests/test_model_helpers.h index c0485d0..9fb215d 100644 --- a/autotests/test_model_helpers.h +++ b/autotests/test_model_helpers.h @@ -32,7 +32,7 @@ namespace TestModelHelpers inline QList makeStandardItems(const QStringList &texts) { QList items; - foreach (const QString &txt, texts) { + for (const QString &txt : texts) { items << new QStandardItem(txt); } return items; diff --git a/src/kbreadcrumbselectionmodel.cpp b/src/kbreadcrumbselectionmodel.cpp index 7d18f04..b4688fa 100644 --- a/src/kbreadcrumbselectionmodel.cpp +++ b/src/kbreadcrumbselectionmodel.cpp @@ -164,16 +164,16 @@ QItemSelection KBreadcrumbSelectionModelPrivate::getBreadcrumbSelection(const QI void KBreadcrumbSelectionModelPrivate::sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Q_Q(KBreadcrumbSelectionModel); - QItemSelection deselectedCrumbs = getBreadcrumbSelection(deselected); - QItemSelection selectedCrumbs = getBreadcrumbSelection(selected); + const QItemSelection deselectedCrumbs = getBreadcrumbSelection(deselected); + const QItemSelection selectedCrumbs = getBreadcrumbSelection(selected); QItemSelection removed = deselectedCrumbs; - Q_FOREACH (const QItemSelectionRange &range, selectedCrumbs) { + for (const QItemSelectionRange &range : selectedCrumbs) { removed.removeAll(range); } QItemSelection added = selectedCrumbs; - Q_FOREACH (const QItemSelectionRange &range, deselectedCrumbs) { + for (const QItemSelectionRange &range : deselectedCrumbs) { added.removeAll(range); } diff --git a/src/kcheckableproxymodel.cpp b/src/kcheckableproxymodel.cpp index 5f7675e..dd8b715 100644 --- a/src/kcheckableproxymodel.cpp +++ b/src/kcheckableproxymodel.cpp @@ -117,10 +117,12 @@ void KCheckableProxyModel::setSourceModel(QAbstractItemModel *sourceModel) void KCheckableProxyModelPrivate::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Q_Q(KCheckableProxyModel); - Q_FOREACH (const QItemSelectionRange &range, q->mapSelectionFromSource(selected)) { + const auto lstSelected = q->mapSelectionFromSource(selected); + for (const QItemSelectionRange &range : lstSelected) { emit q->dataChanged(range.topLeft(), range.bottomRight()); } - Q_FOREACH (const QItemSelectionRange &range, q->mapSelectionFromSource(deselected)) { + const auto lstDeselected = q->mapSelectionFromSource(deselected); + for (const QItemSelectionRange &range : lstDeselected) { emit q->dataChanged(range.topLeft(), range.bottomRight()); } } diff --git a/src/kconcatenaterowsproxymodel.cpp b/src/kconcatenaterowsproxymodel.cpp index c944e68..9dd8cc1 100644 --- a/src/kconcatenaterowsproxymodel.cpp +++ b/src/kconcatenaterowsproxymodel.cpp @@ -314,7 +314,7 @@ void KConcatenateRowsProxyModelPrivate::slotSourceLayoutAboutToBeChanged(const Q { QList parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; @@ -329,7 +329,7 @@ void KConcatenateRowsProxyModelPrivate::slotSourceLayoutAboutToBeChanged(const Q const QModelIndexList persistentIndexList = q->persistentIndexList(); layoutChangePersistentIndexes.reserve(persistentIndexList.size()); - foreach (const QPersistentModelIndex &proxyPersistentIndex, persistentIndexList) { + for (const QPersistentModelIndex &proxyPersistentIndex : persistentIndexList) { proxyIndexes << proxyPersistentIndex; Q_ASSERT(proxyPersistentIndex.isValid()); const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); @@ -351,7 +351,7 @@ void KConcatenateRowsProxyModelPrivate::slotSourceLayoutChanged(const QList parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; @@ -394,7 +394,7 @@ void KConcatenateRowsProxyModelPrivate::slotModelReset() int KConcatenateRowsProxyModelPrivate::computeRowsPrior(const QAbstractItemModel *sourceModel) const { int rowsPrior = 0; - foreach (const QAbstractItemModel *model, m_models) { + for (const QAbstractItemModel *model : qAsConst(m_models)) { if (model == sourceModel) { break; } @@ -407,7 +407,7 @@ QAbstractItemModel *KConcatenateRowsProxyModelPrivate::sourceModelForRow(int row { int rowCount = 0; QAbstractItemModel *selection = nullptr; - foreach (QAbstractItemModel *model, m_models) { + for (QAbstractItemModel *model : qAsConst(m_models)) { const int subRowCount = model->rowCount(); if (rowCount + subRowCount > row) { selection = model; diff --git a/src/kdescendantsproxymodel.cpp b/src/kdescendantsproxymodel.cpp index 7896240..e21d77f 100644 --- a/src/kdescendantsproxymodel.cpp +++ b/src/kdescendantsproxymodel.cpp @@ -904,7 +904,8 @@ void KDescendantsProxyModelPrivate::sourceLayoutAboutToBeChanged() emit q->layoutAboutToBeChanged(); QPersistentModelIndex srcPersistentIndex; - Q_FOREACH (const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { + const auto lst = q->persistentIndexList(); + for (const QPersistentModelIndex &proxyPersistentIndex : lst) { m_proxyIndexes << proxyPersistentIndex; Q_ASSERT(proxyPersistentIndex.isValid()); srcPersistentIndex = q->mapToSource(proxyPersistentIndex); @@ -975,7 +976,7 @@ QMimeData *KDescendantsProxyModel::mimeData(const QModelIndexList &indexes) cons } Q_ASSERT(sourceModel()); QModelIndexList sourceIndexes; - Q_FOREACH (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { sourceIndexes << mapToSource(index); } return sourceModel()->mimeData(sourceIndexes); diff --git a/src/kextracolumnsproxymodel.cpp b/src/kextracolumnsproxymodel.cpp index bd7fedc..4e3d629 100644 --- a/src/kextracolumnsproxymodel.cpp +++ b/src/kextracolumnsproxymodel.cpp @@ -275,7 +275,7 @@ void KExtraColumnsProxyModelPrivate::_ec_sourceLayoutAboutToBeChanged(const QLis QList parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; @@ -291,7 +291,7 @@ void KExtraColumnsProxyModelPrivate::_ec_sourceLayoutAboutToBeChanged(const QLis layoutChangePersistentIndexes.reserve(persistentIndexList.size()); layoutChangeProxyColumns.reserve(persistentIndexList.size()); - foreach (QPersistentModelIndex proxyPersistentIndex, persistentIndexList) { + for (QPersistentModelIndex proxyPersistentIndex : persistentIndexList) { proxyIndexes << proxyPersistentIndex; Q_ASSERT(proxyPersistentIndex.isValid()); const int column = proxyPersistentIndex.column(); @@ -323,7 +323,7 @@ void KExtraColumnsProxyModelPrivate::_ec_sourceLayoutChanged(const QList parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; diff --git a/src/klinkitemselectionmodel.cpp b/src/klinkitemselectionmodel.cpp index b385ef4..1fa9a31 100644 --- a/src/klinkitemselectionmodel.cpp +++ b/src/klinkitemselectionmodel.cpp @@ -46,7 +46,7 @@ public: bool assertSelectionValid(const QItemSelection &selection) const { - Q_FOREACH (const QItemSelectionRange &range, selection) { + for (const QItemSelectionRange &range : selection) { if (!range.isValid()) { qCDebug(KITEMMODELS_LOG) << selection; } diff --git a/src/kmodelindexproxymapper.cpp b/src/kmodelindexproxymapper.cpp index 4312740..0730f34 100644 --- a/src/kmodelindexproxymapper.cpp +++ b/src/kmodelindexproxymapper.cpp @@ -43,7 +43,7 @@ class KModelIndexProxyMapperPrivate bool assertSelectionValid(const QItemSelection &selection) const { - Q_FOREACH (const QItemSelectionRange &range, selection) { + for (const QItemSelectionRange &range : selection) { if (!range.isValid()) { qCDebug(KITEMMODELS_LOG) << selection << m_leftModel << m_rightModel << m_proxyChainDown << m_proxyChainUp; } @@ -102,10 +102,10 @@ class KModelIndexProxyMapperPrivate void KModelIndexProxyMapperPrivate::createProxyChain() { - Q_FOREACH (auto p, m_proxyChainUp) { + for (auto p : qAsConst(m_proxyChainUp)) { p->disconnect(q_ptr); } - Q_FOREACH (auto p, m_proxyChainDown) { + for (auto p : qAsConst(m_proxyChainDown)) { p->disconnect(q_ptr); } m_proxyChainUp.clear(); diff --git a/src/krecursivefilterproxymodel.cpp b/src/krecursivefilterproxymodel.cpp index 014e107..00e6547 100644 --- a/src/krecursivefilterproxymodel.cpp +++ b/src/krecursivefilterproxymodel.cpp @@ -285,7 +285,8 @@ QModelIndexList KRecursiveFilterProxyModel::match(const QModelIndex &start, int return list; QModelIndex proxyIndex; - Q_FOREACH (const QModelIndex &idx, sourceModel()->match(mapToSource(start), role, value, hits, flags)) { + const auto lst = sourceModel()->match(mapToSource(start), role, value, hits, flags); + for (const QModelIndex &idx : lst) { proxyIndex = mapFromSource(idx); if (proxyIndex.isValid()) { list << proxyIndex; diff --git a/src/kselectionproxymodel.cpp b/src/kselectionproxymodel.cpp index de0571a..c1acd65 100644 --- a/src/kselectionproxymodel.cpp +++ b/src/kselectionproxymodel.cpp @@ -251,7 +251,7 @@ static int getRootListRow(const QList &list, const QModelIndex &inde // i.e., new items are inserted in the expected location. QList rootAncestors; - Q_FOREACH (const QModelIndex &root, list) { + for (const QModelIndex &root : list) { QModelIndexList ancestors; ancestors << root; QModelIndex parent = root.parent(); @@ -768,7 +768,7 @@ void KSelectionProxyModelPrivate::sourceLayoutAboutToBeChanged() emit q->layoutAboutToBeChanged(); QItemSelection selection; - Q_FOREACH (const QModelIndex &rootIndex, m_rootIndexList) { + for (const QModelIndex &rootIndex : qAsConst(m_rootIndexList)) { // This will be optimized later. emit q->rootIndexAboutToBeRemoved(rootIndex); selection.append(QItemSelectionRange(rootIndex, rootIndex)); @@ -778,7 +778,8 @@ void KSelectionProxyModelPrivate::sourceLayoutAboutToBeChanged() emit q->rootSelectionAboutToBeRemoved(selection); QPersistentModelIndex srcPersistentIndex; - Q_FOREACH (const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { + const auto lst = q->persistentIndexList(); + for (const QPersistentModelIndex &proxyPersistentIndex : lst) { m_proxyIndexes << proxyPersistentIndex; Q_ASSERT(proxyPersistentIndex.isValid()); srcPersistentIndex = q->mapToSource(proxyPersistentIndex); @@ -1083,7 +1084,7 @@ void KSelectionProxyModelPrivate::sourceRowsInserted(const QModelIndex &parent, m_rowsInserted = false; endInsertRows(parent, start, end); q->endInsertRows(); - Q_FOREACH (const PendingSelectionChange &pendingChange, m_pendingSelectionChanges) { + for (const PendingSelectionChange &pendingChange : qAsConst(m_pendingSelectionChanges)) { selectionChanged(pendingChange.selected, pendingChange.deselected); } m_pendingSelectionChanges.clear(); @@ -1861,7 +1862,7 @@ void KSelectionProxyModelPrivate::selectionChanged(const QItemSelection &_select // range is not a descendant of the selection, but maybe the selection is a descendant of range. // no need to check selected here. That's already in newRootRanges. // existingRootRanges and newRootRanges do not overlap. - Q_FOREACH (const QItemSelectionRange &selectedRange, existingRootRanges) { + for (const QItemSelectionRange &selectedRange : existingRootRanges) { const QModelIndex selectedRangeTopLeft = selectedRange.topLeft(); // existingSelection (and selectedRangeTopLeft) is D. // D is a descendant of B, so when B was removed, D might have been exposed as a root. @@ -1940,7 +1941,8 @@ void KSelectionProxyModelPrivate::insertSelectionIntoProxy(const QItemSelection return; } - Q_FOREACH (const QModelIndex &newIndex, selection.indexes()) { + const auto lst = selection.indexes(); + for (const QModelIndex &newIndex : lst) { Q_ASSERT(newIndex.model() == q->sourceModel()); if (newIndex.column() > 0) { continue; @@ -2307,7 +2309,7 @@ QMimeData *KSelectionProxyModel::mimeData(const QModelIndexList &indexes) const return QAbstractProxyModel::mimeData(indexes); } QModelIndexList sourceIndexes; - Q_FOREACH (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { sourceIndexes << mapToSource(index); } return sourceModel()->mimeData(sourceIndexes); @@ -2465,7 +2467,8 @@ QModelIndexList KSelectionProxyModel::match(const QModelIndex &start, int role, QModelIndexList list; QModelIndex proxyIndex; - Q_FOREACH (const QModelIndex &idx, sourceModel()->match(mapToSource(start), role, value, hits, flags)) { + const auto lst = sourceModel()->match(mapToSource(start), role, value, hits, flags); + for (const QModelIndex &idx : lst) { proxyIndex = mapFromSource(idx); if (proxyIndex.isValid()) { list << proxyIndex; @@ -2481,7 +2484,7 @@ QItemSelection KSelectionProxyModel::mapSelectionFromSource(const QItemSelection // QAbstractProxyModel::mapSelectionFromSource puts invalid ranges in the result // without checking. We can't have that. QItemSelection proxySelection; - Q_FOREACH (const QItemSelectionRange &range, selection) { + for (const QItemSelectionRange &range : selection) { QModelIndex proxyTopLeft = mapFromSource(range.topLeft()); if (!proxyTopLeft.isValid()) { continue; @@ -2523,7 +2526,7 @@ QItemSelection KSelectionProxyModel::mapSelectionToSource(const QItemSelection & // QAbstractProxyModel::mapSelectionFromSource puts invalid ranges in the result // without checking. We can't have that. QItemSelection sourceSelection; - Q_FOREACH (const QItemSelectionRange &range, selection) { + for (const QItemSelectionRange &range : selection) { QModelIndex sourceTopLeft = mapToSource(range.topLeft()); Q_ASSERT(sourceTopLeft.isValid()); diff --git a/tests/proxymodeltestapp/breadcrumbswidget.cpp b/tests/proxymodeltestapp/breadcrumbswidget.cpp index 784008e..79c6704 100644 --- a/tests/proxymodeltestapp/breadcrumbswidget.cpp +++ b/tests/proxymodeltestapp/breadcrumbswidget.cpp @@ -40,7 +40,7 @@ MultiSelectionModel::MultiSelectionModel(QAbstractItemModel *model, QList< QItem void MultiSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { - Q_FOREACH (QItemSelectionModel *selectionModel, m_selectionModels) { + for (QItemSelectionModel *selectionModel : qAsConst(m_selectionModels)) { selectionModel->select(index, command); } QItemSelectionModel::select(index, command); @@ -48,7 +48,7 @@ void MultiSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: void MultiSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) { - Q_FOREACH (QItemSelectionModel *selectionModel, m_selectionModels) { + for (QItemSelectionModel *selectionModel : qAsConst(m_selectionModels)) { selectionModel->select(selection, command); } QItemSelectionModel::select(selection, command); diff --git a/tests/proxymodeltestapp/kreparentingproxymodel.cpp b/tests/proxymodeltestapp/kreparentingproxymodel.cpp index 4493565..2fe53dd 100644 --- a/tests/proxymodeltestapp/kreparentingproxymodel.cpp +++ b/tests/proxymodeltestapp/kreparentingproxymodel.cpp @@ -539,7 +539,7 @@ QModelIndex KReparentingProxyModel::mapToSource(const QModelIndex &proxyIndex) c if (d->m_pendingRemovalChildIndexes.contains(sourceParent)) { // qDebug() << "#############"; - Q_FOREACH (const KReparentingProxyModelPrivate::PendingRemoval &pendingRemoval, d->m_pendingRemovals) { + for (const KReparentingProxyModelPrivate::PendingRemoval &pendingRemoval : qAsConst(d->m_pendingRemovals)) { // qDebug() << "In" << pendingRemoval.index << pendingRemoval.sourceIndex << sourceParent; if (pendingRemoval.sourceIndex == sourceParent) { // qDebug() << "Out" << pendingRemoval.sourceIndex << sourceParent; @@ -666,7 +666,7 @@ QModelIndex KReparentingProxyModel::parent(const QModelIndex &child) const int KReparentingProxyModelPrivate::pendingRemovalRowCount(const QModelIndex &sourceIndex) const { - Q_FOREACH (const PendingRemoval &pendingRemoval, m_pendingRemovals) { + for (const PendingRemoval &pendingRemoval : qAsConst(m_pendingRemovals)) { // qDebug() << pendingRemoval.sourceIndex; if (pendingRemoval.sourceIndex == sourceIndex) { return pendingRemoval.end - pendingRemoval.start + 1; @@ -782,7 +782,7 @@ void KReparentingProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelInde QHash KReparentingProxyModelPrivate::mergeDescendants(QHash mappings, const QModelIndex &parent, int start) { - QModelIndexList childIndexes = mappings.take(parent); + const QModelIndexList childIndexes = mappings.take(parent); // qDebug() << childIndexes; if (!childIndexes.isEmpty()) { if (!m_parents.values().contains(parent)) { @@ -790,7 +790,7 @@ QHash KReparentingProxyModelPrivate::mergeDescenda } } int row = start; - Q_FOREACH (const QModelIndex &idx, childIndexes) { + for (const QModelIndex &idx : childIndexes) { m_childIndexes[parent].insert(row++, QPersistentModelIndex(idx)); mappings = mergeDescendants(mappings, idx, 0); } diff --git a/tests/proxymodeltestapp/matchcheckingwidget.cpp b/tests/proxymodeltestapp/matchcheckingwidget.cpp index 9fab07b..26e2b47 100644 --- a/tests/proxymodeltestapp/matchcheckingwidget.cpp +++ b/tests/proxymodeltestapp/matchcheckingwidget.cpp @@ -77,14 +77,14 @@ void MatchCheckingWidget::matchChanged(const QString &matchData) m_dynamicTreeWidget->treeView()->selectionModel()->clearSelection(); list = m_dynamicTreeWidget->model()->match(m_dynamicTreeWidget->model()->index(0, 0), DynamicTreeModel::DynamicTreeModelId, id); qDebug() << list; - Q_FOREACH (const QModelIndex &idx, list) { + for (const QModelIndex &idx : qAsConst(list)) { m_dynamicTreeWidget->treeView()->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent); } } else if (m_selectionModelRadioButton->isChecked()) { m_selectionTreeView->selectionModel()->clearSelection(); list = m_selectionTreeView->model()->match(m_selectionTreeView->model()->index(0, 0), DynamicTreeModel::DynamicTreeModelId, id); qDebug() << list; - Q_FOREACH (const QModelIndex &idx, list) { + for (const QModelIndex &idx : qAsConst(list)) { m_selectionTreeView->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent); } } diff --git a/tests/proxymodeltestapp/modelcommanderwidget.cpp b/tests/proxymodeltestapp/modelcommanderwidget.cpp index 30f60a0..aa0cdba 100644 --- a/tests/proxymodeltestapp/modelcommanderwidget.cpp +++ b/tests/proxymodeltestapp/modelcommanderwidget.cpp @@ -62,7 +62,7 @@ void ModelCommanderWidget::init() Q_RETURN_ARG(QStringList, testData), Q_ARG(QString, QString())); - Q_FOREACH (const QString &testRun, testData) { + for (const QString &testRun : qAsConst(testData)) { new QTreeWidgetItem(testFunctionItem, QStringList() << testRun); } }