From aac6ba691f7497076df1b9110fedab993b96f9d9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 5 Aug 2023 10:43:43 +0200 Subject: [PATCH] tst_QFileDialog/2: port away from Q_FOREACH These are all trivial: all are over (already or newly-made) const local variables. The only noteworthy point here is that, in order to mark it as const, I had to move a container definition to the more narrow scope in which it was actually initialized. There are no references to the container outside the narrow scope that would require it to be defined in the larger scope. Task-number: QTBUG-115803 Change-Id: I20890f48a48ca662679f55fa5db759419d4db8c5 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit 32e8b272858ded710930db7f314794eb2f77d04c) Reviewed-by: Qt Cherry-pick Bot --- .../widgets/dialogs/qfiledialog/tst_qfiledialog.cpp | 5 ++--- .../widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index d7faf8a76ba..4424ecec62a 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -517,7 +517,6 @@ void tst_QFiledialog::completer() for (int i = 0; i < input.size(); ++i) QTest::keyPress(lineEdit, input[i].toLatin1()); - QStringList expectedFiles; if (expected == -1) { QString fullPath = startPath; if (!fullPath.endsWith(QLatin1Char('/'))) @@ -530,11 +529,11 @@ void tst_QFiledialog::completer() QFileInfo fi(fullPath); QDir x(fi.absolutePath()); - expectedFiles = x.entryList(model->filter()); + const QStringList expectedFiles = x.entryList(model->filter()); expected = 0; if (input.startsWith("..")) input.clear(); - foreach (const QString &expectedFile, expectedFiles) { + for (const QString &expectedFile : expectedFiles) { if (expectedFile.startsWith(input, caseSensitivity)) ++expected; } diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index e54839cdd4f..a8d3c5fe1ea 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -682,13 +682,13 @@ void tst_QFileDialog2::completionOnLevelAfterRoot() #if defined(Q_OS_WIN) fd.setDirectory("C:/"); QDir current = fd.directory(); - QStringList entryList = current.entryList(QStringList(), QDir::Dirs); + const QStringList entryList = current.entryList(QStringList(), QDir::Dirs); // Find a suitable test dir under c:-root: // - At least 6 characters long // - Ascii, letters only // - No another dir with same start QString testDir; - foreach (const QString &entry, entryList) { + for (const QString &entry : entryList) { if (entry.size() > 5 && QString(entry.toLatin1()).compare(entry) == 0) { bool invalid = false; for (int i = 0; i < 5; i++) { @@ -698,7 +698,7 @@ void tst_QFileDialog2::completionOnLevelAfterRoot() } } if (!invalid) { - foreach (const QString &check, entryList) { + for (const QString &check : entryList) { if (check.startsWith(entry.left(5), Qt::CaseInsensitive) && check != entry) { invalid = true; break; @@ -948,9 +948,9 @@ void tst_QFileDialog2::task239706_editableFilterCombo() d.show(); QVERIFY(QTest::qWaitForWindowExposed(&d)); - QList comboList = d.findChildren(); + const QList comboList = d.findChildren(); QComboBox *filterCombo = nullptr; - foreach (QComboBox *combo, comboList) { + for (QComboBox *combo : comboList) { if (combo->objectName() == QString("fileTypeCombo")) { filterCombo = combo; break;