From f493b72ee7e6c525159a6df5df13536021ed6b91 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 8 Aug 2023 07:56:32 +0200 Subject: DynamicTreeModel test helper: port away from Q_FOREACH This source file is included in four other test projects, so it makes more sense to port it away from Q_FOREACH than to white-list it everywhere it's used. The change in ModelMoveCommand::doCommand() is trivial. I only dropped the pointless top-level const of the loop variable as a drive-by. The change regarding `parents` in ModelChangeChildrenLayoutsCommand's doCommand() is also trivial, I just ported to braced initialization to get the QList to be const. We're forced by the Qt API (layoutChanged()) to use a QList here, therefore no array. Ibid., the change regarding `persistent` is simple. The container cannot be marked as const without a lot of churn to its initialization (applying IILE, basically), but other than that, it's a local variable, and the loop body clearly doesn't modify it. Task-number: QTBUG-115839 Pick-to: 6.6 6.5 Change-Id: I7a0e85804626a3cc612921b49e72e4b9f30b676d Reviewed-by: Ivan Solovev --- .../auto/other/qabstractitemmodelutils/dynamictreemodel.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp index 378c198949..1bd7caeb9b 100644 --- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp +++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp @@ -191,7 +191,7 @@ void ModelMoveCommand::doCommand() return; for (int column = 0; column < m_numCols; ++column) { - QList l = m_model->m_childItems.value(srcParent.internalId())[column].mid( + 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++) @@ -206,7 +206,7 @@ void ModelMoveCommand::doCommand() d = m_destRow; } - foreach (const qint64 id, l) + for (qint64 id : l) m_model->m_childItems[destParent.internalId()][column].insert(d++, id); } @@ -283,9 +283,7 @@ void ModelChangeChildrenLayoutsCommand::doCommand() const QPersistentModelIndex parent1 = findIndex(m_rowNumbers); const QPersistentModelIndex parent2 = findIndex(m_secondRowNumbers); - QList parents; - parents << parent1; - parents << parent2; + const QList parents = { parent1, parent2 }; emit m_model->layoutAboutToBeChanged(parents); @@ -309,13 +307,13 @@ void ModelChangeChildrenLayoutsCommand::doCommand() // changing any children of that parent. The reason is that we're keeping parent1 and parent2 // around as QPersistentModelIndex instances, and we query idx.parent() in the loop. QModelIndexList persistent = m_model->persistentIndexList(); - foreach (const QModelIndex &parent, parents) { + for (const QModelIndex &parent : parents) { int idx = persistent.indexOf(parent); if (idx != -1) persistent.move(idx, 0); } - foreach (const QModelIndex &idx, persistent) { + for (const QModelIndex &idx : std::as_const(persistent)) { if (idx.parent() == parent1) { if (idx.row() == rowSize1 - 1) { m_model->changePersistentIndex(idx, -- cgit v1.2.3