summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-12-07 12:00:48 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-01-07 13:15:59 +0000
commit1f2c23a7ca1699b345578aeb52fbd97b612e079a (patch)
treef9c738188b43e737e51772ba3376f16aa2d76386 /examples/widgets/tools
parentbec817334705d86bc4e99af2e7220bb877f036d3 (diff)
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 <v.ronin@yahoo.it> Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/widgets/tools')
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp14
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp2
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.cpp3
-rw-r--r--examples/widgets/tools/i18n/languagechooser.cpp8
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp6
5 files changed, 18 insertions, 15 deletions
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<int> 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<QTextCodec *> &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);