diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 3a4493474b..f305edb2c5 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -1830,7 +1830,7 @@ void ListenerObject::slotAboutToBeReset() void ListenerObject::slotReset() { - foreach (const QModelIndex &idx, m_persistentIndexes) { + for (const auto &idx : qAsConst(m_persistentIndexes)) { QVERIFY(!idx.isValid()); } } diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index f78f5bc138..c74101928a 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -32,6 +32,9 @@ #include +Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag) +Q_DECLARE_METATYPE(Qt::SortOrder) + class tst_QItemSelectionModel : public QObject { Q_OBJECT @@ -1463,7 +1466,7 @@ void tst_QItemSelectionModel::persistentselections() QFETCH(IntList, insertColumns); QFETCH(IntList, deleteRows); QFETCH(IntList, deleteColumns); - QFETCH(PairList, expectedList); + QFETCH(const PairList, expectedList); // make sure the model is sane (5x5) QCOMPARE(model->rowCount(QModelIndex()), 5); @@ -1504,7 +1507,7 @@ void tst_QItemSelectionModel::persistentselections() // check that the selected items are the correct number and indexes QModelIndexList selectedList = selection->selectedIndexes(); QCOMPARE(selectedList.count(), expectedList.count()); - foreach(IntPair pair, expectedList) { + for (const auto &pair : expectedList) { QModelIndex index = model->index(pair.first, pair.second, QModelIndex()); QVERIFY(selectedList.contains(index)); } @@ -1679,7 +1682,7 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() { QTest::addColumn("items"); QTest::addColumn("initialSelectedRanges"); - QTest::addColumn("sortOrder"); + QTest::addColumn("sortOrder"); QTest::addColumn("sortColumn"); QTest::addColumn("expectedSelectedRanges"); @@ -1689,7 +1692,7 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() << (IntList() << 3 << 2 << 1 << 0)) << (IntPairPairList() << IntPairPair(IntPair(0, 0), IntPair(3, 1))) - << int(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (IntPairPairList() << IntPairPair(IntPair(0, 0), IntPair(3, 1))); @@ -1699,7 +1702,7 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() << (IntList() << 3 << 2 << 1 << 0)) << (IntPairPairList() << IntPairPair(IntPair(0, 0), IntPair(1, 1))) - << int(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (IntPairPairList() << IntPairPair(IntPair(2, 0), IntPair(3, 1))); @@ -1709,7 +1712,7 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() << (IntList() << 3 << 2 << 1 << 0)) << (IntPairPairList() << IntPairPair(IntPair(1, 0), IntPair(2, 1))) - << int(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (IntPairPairList() << IntPairPair(IntPair(1, 0), IntPair(2, 1))); @@ -1720,7 +1723,7 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() << (IntPairPairList() << IntPairPair(IntPair(1, 0), IntPair(1, 1)) << IntPairPair(IntPair(3, 0), IntPair(3, 1))) - << int(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (IntPairPairList() << IntPairPair(IntPair(0, 0), IntPair(0, 1)) @@ -1730,8 +1733,8 @@ void tst_QItemSelectionModel::modelLayoutChanged_data() void tst_QItemSelectionModel::modelLayoutChanged() { QFETCH(IntListList, items); - QFETCH(IntPairPairList, initialSelectedRanges); - QFETCH(int, sortOrder); + QFETCH(const IntPairPairList, initialSelectedRanges); + QFETCH(Qt::SortOrder, sortOrder); QFETCH(int, sortColumn); QFETCH(IntPairPairList, expectedSelectedRanges); @@ -1746,9 +1749,9 @@ void tst_QItemSelectionModel::modelLayoutChanged() // select initial ranges QItemSelectionModel selectionModel(&model); - foreach (IntPairPair range, initialSelectedRanges) { - IntPair tl = range.first; - IntPair br = range.second; + for (const auto &range : initialSelectedRanges) { + const auto &tl = range.first; + const auto &br = range.second; QItemSelection selection( model.index(tl.first, tl.second), model.index(br.first, br.second)); @@ -1756,7 +1759,7 @@ void tst_QItemSelectionModel::modelLayoutChanged() } // sort the model - model.sort(sortColumn, Qt::SortOrder(sortOrder)); + model.sort(sortColumn, sortOrder); // verify that selection is as expected QItemSelection selection = selectionModel.selection(); @@ -2126,43 +2129,43 @@ void tst_QItemSelectionModel::merge_data() { QTest::addColumn("init"); QTest::addColumn("other"); - QTest::addColumn("command"); + QTest::addColumn("command"); QTest::addColumn("result"); QTest::newRow("Simple select") << QItemSelection() << QItemSelection(model->index(2, 1) , model->index(3, 4)) - << int(QItemSelectionModel::Select) + << QItemSelectionModel::Select << QItemSelection(model->index(2, 1) , model->index(3, 4)); QTest::newRow("Simple deselect") << QItemSelection(model->index(2, 1) , model->index(3, 4)) << QItemSelection(model->index(2, 1) , model->index(3, 4)) - << int(QItemSelectionModel::Deselect) + << QItemSelectionModel::Deselect << QItemSelection(); QTest::newRow("Simple Toggle deselect") << QItemSelection(model->index(2, 1) , model->index(3, 4)) << QItemSelection(model->index(2, 1) , model->index(3, 4)) - << int(QItemSelectionModel::Toggle) + << QItemSelectionModel::Toggle << QItemSelection(); QTest::newRow("Simple Toggle select") << QItemSelection() << QItemSelection(model->index(2, 1) , model->index(3, 4)) - << int(QItemSelectionModel::Toggle) + << QItemSelectionModel::Toggle << QItemSelection(model->index(2, 1) , model->index(3, 4)); QTest::newRow("Add select") << QItemSelection(model->index(2, 1) , model->index(3, 3)) << QItemSelection(model->index(2, 2) , model->index(3, 4)) - << int(QItemSelectionModel::Select) + << QItemSelectionModel::Select << QItemSelection(model->index(2, 1) , model->index(3, 4)); QTest::newRow("Deselect") << QItemSelection(model->index(2, 1) , model->index(3, 4)) << QItemSelection(model->index(2, 2) , model->index(3, 4)) - << int(QItemSelectionModel::Deselect) + << QItemSelectionModel::Deselect << QItemSelection(model->index(2, 1) , model->index(3, 1)); QItemSelection r1(model->index(2, 1) , model->index(3, 1)); @@ -2170,7 +2173,7 @@ void tst_QItemSelectionModel::merge_data() QTest::newRow("Toggle") << QItemSelection(model->index(2, 1) , model->index(3, 3)) << QItemSelection(model->index(2, 2) , model->index(3, 4)) - << int(QItemSelectionModel::Toggle) + << QItemSelectionModel::Toggle << r1; } @@ -2178,15 +2181,18 @@ void tst_QItemSelectionModel::merge() { QFETCH(QItemSelection, init); QFETCH(QItemSelection, other); - QFETCH(int, command); + QFETCH(QItemSelectionModel::SelectionFlag, command); QFETCH(QItemSelection, result); - init.merge(other, QItemSelectionModel::SelectionFlags(command)); + init.merge(other, command); - foreach(const QModelIndex &idx, init.indexes()) - QVERIFY(result.contains(idx)); - foreach(const QModelIndex &idx, result.indexes()) - QVERIFY(init.contains(idx)); + auto verify = [](const QModelIndexList &a, const QItemSelection &b) + { + for (const QModelIndex &idx : a) + QVERIFY(b.contains(idx)); + }; + verify(init.indexes(), result); + verify(result.indexes(), init); } void tst_QItemSelectionModel::isRowSelected() @@ -2267,13 +2273,12 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected1() proxy.setFilterRegularExpression(QRegularExpression("f")); QCOMPARE(proxy.rowCount(), 2); - QList indexList; - indexList << proxy.index(0,0) << proxy.index(1,0); - selection.select( QItemSelection(indexList.first(), indexList.last()), QItemSelectionModel::Select); + const QList indexList({proxy.index(0,0), proxy.index(1,0)}); + selection.select(QItemSelection(indexList.first(), indexList.last()), QItemSelectionModel::Select); //let's check the selection hasn't changed QCOMPARE(selection.selectedIndexes().count(), indexList.count()); - foreach(QPersistentModelIndex index, indexList) + for (const auto &index : indexList) QVERIFY(selection.isSelected(index)); proxy.setFilterRegularExpression(QRegularExpression()); @@ -2281,7 +2286,7 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected1() //let's check the selection hasn't changed QCOMPARE(selection.selectedIndexes().count(), indexList.count()); - foreach(QPersistentModelIndex index, indexList) + for (const auto &index : indexList) QVERIFY(selection.isSelected(index)); } @@ -2321,9 +2326,8 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected2() selection.select( QItemSelection(proxy.index(0,0), proxy.index(proxy.rowCount() - 1, proxy.columnCount() - 1)), QItemSelectionModel::Select); - QList indexList; - foreach(const QModelIndex &id, selection.selectedIndexes()) - indexList << id; + const auto selIndexes = selection.selectedIndexes(); + const QList indexList(selIndexes.begin(), selIndexes.end()); proxy.filtering = false; proxy.invalidate(); @@ -2331,7 +2335,7 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected2() //let's check the selection hasn't changed QCOMPARE(selection.selectedIndexes().count(), indexList.count()); - foreach(QPersistentModelIndex index, indexList) + for (const auto &index : indexList) QVERIFY(selection.isSelected(index)); } @@ -2375,7 +2379,8 @@ public: public slots: void selectionChanged(const QItemSelection & /* selected */, const QItemSelection &deselected) { - foreach(const QModelIndex &index, deselected.indexes()) { + const auto deselIndexes = deselected.indexes(); + for (const auto &index : deselIndexes) { QVERIFY(!m_itemSelectionModel->selection().contains(index)); } QCOMPARE(m_itemSelectionModel->selection().size(), 2); @@ -2633,9 +2638,9 @@ private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { - foreach(const QItemSelectionRange &range, selected) + for (const auto &range : selected) QVERIFY(range.isValid()); - foreach(const QItemSelectionRange &range, deselected) + for (const auto &range : deselected) QVERIFY(range.isValid()); } diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 0f7588a71a..624187349b 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -829,7 +829,7 @@ void tst_QSortFilterProxyModel::removeRows_data() void tst_QSortFilterProxyModel::removeRows() { - QFETCH(QStringList, initial); + QFETCH(const QStringList, initial); QFETCH(int, sortOrder); QFETCH(QString, filter); QFETCH(int, position); @@ -843,7 +843,7 @@ void tst_QSortFilterProxyModel::removeRows() proxy.setSourceModel(&model); // prepare model - foreach (QString s, initial) + for (const auto &s : initial) model.appendRow(new QStandardItem(s)); if (sortOrder != -1) @@ -3035,15 +3035,15 @@ void tst_QSortFilterProxyModel::removeRowsRecursive() QList sourceIndexes; QList proxyIndexes; - foreach (QStandardItem *item, items) { + for (const auto item : qAsConst(items)) { QModelIndex idx = item->index(); sourceIndexes << idx; proxyIndexes << proxy.mapFromSource(idx); } - foreach (const QPersistentModelIndex &pidx, sourceIndexes) + for (const auto &pidx : qAsConst(sourceIndexes)) QVERIFY(pidx.isValid()); - foreach (const QPersistentModelIndex &pidx, proxyIndexes) + for (const auto &pidx : qAsConst(proxyIndexes)) QVERIFY(pidx.isValid()); QList itemRow = pItem1->takeRow(0); @@ -3051,9 +3051,9 @@ void tst_QSortFilterProxyModel::removeRowsRecursive() QCOMPARE(itemRow.count(), 1); QCOMPARE(itemRow.first(), pItem11); - foreach (const QPersistentModelIndex &pidx, sourceIndexes) + for (const auto &pidx : qAsConst(sourceIndexes)) QVERIFY(!pidx.isValid()); - foreach (const QPersistentModelIndex &pidx, proxyIndexes) + for (const auto &pidx : qAsConst(proxyIndexes)) QVERIFY(!pidx.isValid()); delete pItem11; @@ -3280,10 +3280,8 @@ void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection() static bool isValid(const QItemSelection &selection) { - foreach (const QItemSelectionRange &range, selection) - if (!range.isValid()) - return false; - return true; + return std::all_of(selection.begin(), selection.end(), + [](const QItemSelectionRange &range) { return range.isValid(); }); } void tst_QSortFilterProxyModel::mapSelectionFromSource() @@ -3737,14 +3735,16 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged() QVERIFY(beforeParents.first() == proxy.mapFromSource(model.indexFromItem(model.invisibleRootItem()->child(1)))); - QList proxy2BeforeList = proxy2ParentsAboutToBeChangedSpy.first().first().value >(); - QList proxy2AfterList = proxy2ParentsChangedSpy.first().first().value >(); + const QList proxy2BeforeList = + proxy2ParentsAboutToBeChangedSpy.first().first().value >(); + const QList proxy2AfterList = + proxy2ParentsChangedSpy.first().first().value >(); QCOMPARE(proxy2BeforeList.size(), beforeParents.size()); QCOMPARE(proxy2AfterList.size(), afterParents.size()); - foreach (const QPersistentModelIndex &idx, proxy2BeforeList) + for (const QPersistentModelIndex &idx : proxy2BeforeList) QVERIFY(beforeParents.contains(proxy2.mapToSource(idx))); - foreach (const QPersistentModelIndex &idx, proxy2AfterList) + for (const QPersistentModelIndex &idx : proxy2AfterList) QVERIFY(afterParents.contains(proxy2.mapToSource(idx))); }