From 1f2c23a7ca1699b345578aeb52fbd97b612e079a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 7 Dec 2018 12:00:48 +0100 Subject: Cleanup Widgets examples - foreach Cleanup the Widget examples - replace foreach with range-based for loop in subdirectory tools, touch and tutorials Change-Id: I008d23b5993a18a3332fe9f5e5bca68cb0561066 Reviewed-by: Luca Beldi Reviewed-by: Sze Howe Koh Reviewed-by: Paul Wicking --- examples/widgets/tools/codecs/mainwindow.cpp | 14 +++++++------- examples/widgets/tools/codecs/previewform.cpp | 2 +- .../widgets/tools/echoplugin/echowindow/echowindow.cpp | 3 ++- examples/widgets/tools/i18n/languagechooser.cpp | 8 ++++---- examples/widgets/tools/settingseditor/settingstree.cpp | 6 ++++-- 5 files changed, 18 insertions(+), 15 deletions(-) (limited to 'examples/widgets/tools') diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp index 229c2ccfd4..53db9fe61f 100644 --- a/examples/widgets/tools/codecs/mainwindow.cpp +++ b/examples/widgets/tools/codecs/mainwindow.cpp @@ -127,11 +127,10 @@ void MainWindow::about() void MainWindow::aboutToShowSaveAsMenu() { - QString currentText = textEdit->toPlainText(); - - foreach (QAction *action, saveAsActs) { - QByteArray codecName = action->data().toByteArray(); - QTextCodec *codec = QTextCodec::codecForName(codecName); + const QString currentText = textEdit->toPlainText(); + for (QAction *action : qAsConst(saveAsActs)) { + const QByteArray codecName = action->data().toByteArray(); + const QTextCodec *codec = QTextCodec::codecForName(codecName); action->setVisible(codec && codec->canEncode(currentText)); } } @@ -142,7 +141,8 @@ void MainWindow::findCodecs() QRegularExpression iso8859RegExp("^ISO[- ]8859-([0-9]+).*$"); QRegularExpressionMatch match; - foreach (int mib, QTextCodec::availableMibs()) { + const QList mibs = QTextCodec::availableMibs(); + for (int mib : mibs) { QTextCodec *codec = QTextCodec::codecForMib(mib); QString sortKey = codec->name().toUpper(); @@ -177,7 +177,7 @@ void MainWindow::createMenus() QMenu *saveAsMenu = fileMenu->addMenu(tr("&Save As")); connect(saveAsMenu, &QMenu::aboutToShow, this, &MainWindow::aboutToShowSaveAsMenu); - foreach (const QTextCodec *codec, codecs) { + for (const QTextCodec *codec : qAsConst(codecs)) { const QByteArray name = codec->name(); QAction *action = saveAsMenu->addAction(tr("%1...").arg(QLatin1String(name))); action->setData(QVariant(name)); diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp index d19b9c0833..206b5757cd 100644 --- a/examples/widgets/tools/codecs/previewform.cpp +++ b/examples/widgets/tools/codecs/previewform.cpp @@ -182,7 +182,7 @@ PreviewForm::PreviewForm(QWidget *parent) void PreviewForm::setCodecList(const QList &list) { encodingComboBox->clear(); - foreach (const QTextCodec *codec, list) { + for (const QTextCodec *codec : list) { encodingComboBox->addItem(QLatin1String(codec->name()), QVariant(codec->mibEnum())); } diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp index 64b59d506e..6886a4cd88 100644 --- a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp +++ b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp @@ -113,7 +113,8 @@ bool EchoWindow::loadPlugin() } #endif pluginsDir.cd("plugins"); - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + const QStringList entries = pluginsDir.entryList(QDir::Files); + for (const QString &fileName : entries) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = pluginLoader.instance(); if (plugin) { diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp index 58cf9d4047..f07d0ddee3 100644 --- a/examples/widgets/tools/i18n/languagechooser.cpp +++ b/examples/widgets/tools/i18n/languagechooser.cpp @@ -148,14 +148,14 @@ void LanguageChooser::checkBoxToggled() void LanguageChooser::showAll() { - foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys()) - checkBox->setChecked(true); + for (auto it = qmFileForCheckBoxMap.keyBegin(); it != qmFileForCheckBoxMap.keyEnd(); ++it) + (*it)->setChecked(true); } void LanguageChooser::hideAll() { - foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys()) - checkBox->setChecked(false); + for (auto it = qmFileForCheckBoxMap.keyBegin(); it != qmFileForCheckBoxMap.keyEnd(); ++it) + (*it)->setChecked(false); } QStringList LanguageChooser::findQmFiles() diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp index 4ca843784e..8585792787 100644 --- a/examples/widgets/tools/settingseditor/settingstree.cpp +++ b/examples/widgets/tools/settingseditor/settingstree.cpp @@ -170,7 +170,8 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent) { int dividerIndex = 0; - foreach (QString group, settings->childGroups()) { + const QStringList childGroups = settings->childGroups(); + for (const QString &group : childGroups) { QTreeWidgetItem *child; int childIndex = findChild(parent, group, dividerIndex); if (childIndex != -1) { @@ -190,7 +191,8 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent) settings->endGroup(); } - foreach (const QString &key, settings->childKeys()) { + const QStringList childKeys = settings->childKeys(); + for (const QString &key : childKeys) { QTreeWidgetItem *child; int childIndex = findChild(parent, key, 0); -- cgit v1.2.3