From 9bcfeb3cd73fccdff2a7d2bd3458f5838dec7204 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Mon, 30 Dec 2019 17:05:24 +0100 Subject: [PATCH] GM: port foreach -> range-based for Signed-off-by: Juraj Oravec --- src/plugins/GreaseMonkey/gm_manager.cpp | 7 ++++--- src/plugins/GreaseMonkey/gm_plugin.cpp | 3 ++- src/plugins/GreaseMonkey/settings/gm_settings.cpp | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/GreaseMonkey/gm_manager.cpp b/src/plugins/GreaseMonkey/gm_manager.cpp index d17f61077..69e019d6e 100644 --- a/src/plugins/GreaseMonkey/gm_manager.cpp +++ b/src/plugins/GreaseMonkey/gm_manager.cpp @@ -107,7 +107,7 @@ QString GM_Manager::requireScripts(const QStringList &urlList) const QString script; - foreach (const QString &url, urlList) { + for (const QString &url : urlList) { if (settings.contains(url)) { QString fileName = settings.value(url).toString(); if (!QFileInfo(fileName).isAbsolute()) { @@ -158,7 +158,7 @@ QList GM_Manager::allScripts() const bool GM_Manager::containsScript(const QString &fullName) const { - foreach (GM_Script* script, m_scripts) { + for (GM_Script* script : qAsConst(m_scripts)) { if (fullName == script->fullName()) { return true; } @@ -248,7 +248,8 @@ void GM_Manager::load() settings.beginGroup("GreaseMonkey"); m_disabledScripts = settings.value("disabledScripts", QStringList()).toStringList(); - foreach (const QString &fileName, gmDir.entryList(QStringList("*.js"), QDir::Files)) { + const auto fileNames = gmDir.entryList(QStringList("*.js"), QDir::Files); + for (const QString &fileName : fileNames) { const QString absolutePath = gmDir.absoluteFilePath(fileName); GM_Script* script = new GM_Script(this, absolutePath); diff --git a/src/plugins/GreaseMonkey/gm_plugin.cpp b/src/plugins/GreaseMonkey/gm_plugin.cpp index 4ff73f473..a36180fd1 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.cpp +++ b/src/plugins/GreaseMonkey/gm_plugin.cpp @@ -40,7 +40,8 @@ void GM_Plugin::init(InitState state, const QString &settingsPath) // Make sure userscripts works also with already created WebPages if (state == LateInitState) { - foreach (BrowserWindow *window, mApp->windows()) { + const auto windows = mApp->windows(); + for (BrowserWindow *window : windows) { m_manager->mainWindowCreated(window); } } diff --git a/src/plugins/GreaseMonkey/settings/gm_settings.cpp b/src/plugins/GreaseMonkey/settings/gm_settings.cpp index bf1162872..3d1685e6c 100644 --- a/src/plugins/GreaseMonkey/settings/gm_settings.cpp +++ b/src/plugins/GreaseMonkey/settings/gm_settings.cpp @@ -152,7 +152,8 @@ void GM_Settings::loadScripts() ui->listWidget->clear(); - foreach (GM_Script* script, m_manager->allScripts()) { + const auto allScripts = m_manager->allScripts(); + for (GM_Script* script : allScripts) { QListWidgetItem* item = new QListWidgetItem(ui->listWidget); item->setText(script->name()); item->setIcon(script->icon());