diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ set(KDE_NO_DEPRECATED TRUE) set(CMAKE_AUTOMOC_MOC_OPTIONS "-DKDE_NO_DEPRECATED") endif() - +add_definitions(-DQT_NO_FOREACH) ################# now find all used packages ################# set (REQUIRED_QT_VERSION 5.10.0) diff --git a/autotests/coronatest.cpp b/autotests/coronatest.cpp --- a/autotests/coronatest.cpp +++ b/autotests/coronatest.cpp @@ -146,7 +146,8 @@ m_corona->loadLayout(QStringLiteral("plasma-test-appletsrc")); QCOMPARE(m_corona->containments().count(), 3); - foreach (auto cont, m_corona->containments()) { + const auto lst = m_corona->containments(); + for (auto cont : lst) { switch (cont->id()) { case 1: QCOMPARE(cont->applets().count(), 2); @@ -212,40 +213,48 @@ m_corona->setImmutability(Plasma::Types::UserImmutable); QCOMPARE(m_corona->immutability(), Plasma::Types::UserImmutable); - foreach (Plasma::Containment *cont, m_corona->containments()) { + auto lst = m_corona->containments(); + for (Plasma::Containment *cont : qAsConst(lst)) { QCOMPARE(cont->immutability(), Plasma::Types::UserImmutable); - foreach (Plasma::Applet *app, cont->applets()) { + const auto lstApplets = cont->applets(); + for (Plasma::Applet *app : lstApplets) { QCOMPARE(app->immutability(), Plasma::Types::UserImmutable); } } m_corona->setImmutability(Plasma::Types::Mutable); QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable); - foreach (Plasma::Containment *cont, m_corona->containments()) { + lst = m_corona->containments(); + for (Plasma::Containment *cont : qAsConst(lst)) { QCOMPARE(cont->immutability(), Plasma::Types::Mutable); - foreach (Plasma::Applet *app, cont->applets()) { + const auto lstApplets = cont->applets(); + for (Plasma::Applet *app : lstApplets) { QCOMPARE(app->immutability(), Plasma::Types::Mutable); } } m_corona->setImmutability(Plasma::Types::SystemImmutable); QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable); - foreach (Plasma::Containment *cont, m_corona->containments()) { + lst = m_corona->containments(); + for (Plasma::Containment *cont : qAsConst(lst)) { QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable); - foreach (Plasma::Applet *app, cont->applets()) { + const auto lstApplets = cont->applets(); + for (Plasma::Applet *app : lstApplets) { QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable); } } //can't unlock systemimmutable m_corona->setImmutability(Plasma::Types::Mutable); QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable); - foreach (Plasma::Containment *cont, m_corona->containments()) { + lst = m_corona->containments(); + for (Plasma::Containment *cont : qAsConst(lst)) { QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable); - foreach (Plasma::Applet *app, cont->applets()) { + const auto lstApplets = cont->applets(); + for (Plasma::Applet *app : lstApplets) { QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable); } } diff --git a/autotests/packagestructuretest.cpp b/autotests/packagestructuretest.cpp --- a/autotests/packagestructuretest.cpp +++ b/autotests/packagestructuretest.cpp @@ -175,27 +175,26 @@ void PackageStructureTest::directories() { - QList dirs; - dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui"; + const QList dirs{"config", "data", "images", "theme", "scripts", "translations", "ui"}; - QList psDirs = ps.directories(); + const QList psDirs = ps.directories(); QCOMPARE(dirs.count(), psDirs.count()); - foreach (const char *dir, psDirs) { + for (const char *dir : psDirs) { bool found = false; - foreach (const char *check, dirs) { + for (const char *check : dirs) { if (qstrcmp(dir, check)) { found = true; break; } } QVERIFY(found); } - foreach (const char *dir, dirs) { + for (const char *dir : dirs) { bool found = false; - foreach (const char *check, psDirs) { + for (const char *check : psDirs) { if (qstrcmp(dir, check)) { found = true; break; @@ -213,17 +212,16 @@ void PackageStructureTest::files() { - QList files; - files << "mainconfigui" << "mainconfigxml" << "mainscript"; + const QList files{"mainconfigui", "mainconfigxml", "mainscript"}; - QList psFiles = ps.files(); + const QList psFiles = ps.files(); //for (int i = 0; i < psFiles.count(); ++i) { // qDebug() << psFiles[i]; //} - foreach (const char *file, psFiles) { + for (const char *file : psFiles) { bool found = false; - foreach (const char *check, files) { + for (const char *check : files) { if (qstrcmp(file, check)) { found = true; break; diff --git a/src/declarativeimports/calendar/daysmodel.cpp b/src/declarativeimports/calendar/daysmodel.cpp --- a/src/declarativeimports/calendar/daysmodel.cpp +++ b/src/declarativeimports/calendar/daysmodel.cpp @@ -98,7 +98,8 @@ const QDate modelFirstDay(m_data->at(0).yearNumber, m_data->at(0).monthNumber, m_data->at(0).dayNumber); if (m_pluginsManager) { - Q_FOREACH (CalendarEvents::CalendarEventsPlugin *eventsPlugin, m_pluginsManager->plugins()) { + const auto lst = m_pluginsManager->plugins(); + for (CalendarEvents::CalendarEventsPlugin *eventsPlugin : lst) { eventsPlugin->loadEventsForDateRange(modelFirstDay, modelFirstDay.addDays(42)); } } @@ -140,7 +141,7 @@ m_agendaNeedsUpdate = true; } - Q_FOREACH (const QDate date, updatesList) { + for (const QDate date : qAsConst(updatesList)) { const QModelIndex changedIndex = indexForDate(date); if (changedIndex.isValid()) { Q_EMIT dataChanged(changedIndex, changedIndex, @@ -167,7 +168,7 @@ m_agendaNeedsUpdate = true; } - Q_FOREACH (const QDate date, updatesList) { + for (const QDate date : qAsConst(updatesList)) { const QModelIndex changedIndex = indexForDate(date); if (changedIndex.isValid()) { Q_EMIT dataChanged(changedIndex, changedIndex, @@ -195,7 +196,7 @@ return b.type() > a.type() || b.startDateTime() > a.startDateTime(); }); - Q_FOREACH (const CalendarEvents::EventData &event, events) { + for (const CalendarEvents::EventData &event : qAsConst(events)) { m_qmlData << new EventDataDecorator(event, this); } diff --git a/src/declarativeimports/calendar/eventpluginsmanager.cpp b/src/declarativeimports/calendar/eventpluginsmanager.cpp --- a/src/declarativeimports/calendar/eventpluginsmanager.cpp +++ b/src/declarativeimports/calendar/eventpluginsmanager.cpp @@ -141,7 +141,7 @@ [](const KPluginMetaData &md) { return md.serviceTypes().contains(QLatin1String("PlasmaCalendar/Plugin")); }); - Q_FOREACH (const KPluginMetaData &plugin, plugins) { + for (const KPluginMetaData &plugin : qAsConst(plugins)) { m_availablePlugins.insert(plugin.fileName(), { plugin.name(), plugin.description(), @@ -152,17 +152,17 @@ // Fallback for legacy pre-KPlugin plugins so we can still load them const QStringList paths = QCoreApplication::libraryPaths(); - Q_FOREACH (const QString &libraryPath, paths) { + for (const QString &libraryPath : paths) { const QString path(libraryPath + QStringLiteral("/plasmacalendarplugins")); QDir dir(path); if (!dir.exists()) { continue; } - QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); + const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); - Q_FOREACH (const QString &fileName, entryList) { + for (const QString &fileName : entryList) { const QString absolutePath = dir.absoluteFilePath(fileName); if (m_availablePlugins.contains(absolutePath)) { continue; @@ -217,7 +217,7 @@ } // Now load all the plugins left in pluginsList - Q_FOREACH (const QString &pluginPath, pluginsList) { + for (const QString &pluginPath : qAsConst(pluginsList)) { loadPlugin(pluginPath); } diff --git a/src/declarativeimports/core/datamodel.h b/src/declarativeimports/core/datamodel.h --- a/src/declarativeimports/core/datamodel.h +++ b/src/declarativeimports/core/datamodel.h @@ -253,7 +253,7 @@ int DataModel::countItems() const { int count = 0; - foreach (const QVector &v, m_items) { + for (const QVector &v : qAsConst(m_items)) { count += v.count(); } return count; diff --git a/src/declarativeimports/core/datamodel.cpp b/src/declarativeimports/core/datamodel.cpp --- a/src/declarativeimports/core/datamodel.cpp +++ b/src/declarativeimports/core/datamodel.cpp @@ -256,7 +256,8 @@ QVariantList list; if (!m_dataSource->data()->isEmpty()) { - foreach (const QString &key, m_dataSource->data()->keys()) { + const auto lst = m_dataSource->data()->keys(); + for (const QString &key : lst) { if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) { continue; } @@ -305,7 +306,8 @@ m_dataSource = source; - foreach (const QString &key, m_dataSource->data()->keys()) { + const auto lst = m_dataSource->data()->keys(); + for (const QString &key : lst) { dataUpdated(key, m_dataSource->data()->value(key).value()); } @@ -396,7 +398,7 @@ if (!list.isEmpty()) { if (list.first().canConvert()) { - foreach (const QVariant &item, list) { + for (const QVariant &item : qAsConst(list)) { const QVariantMap &vh = item.value(); QMapIterator it(vh); while (it.hasNext()) { @@ -410,7 +412,7 @@ } } } else { - foreach (const QVariant &item, list) { + for (const QVariant &item : qAsConst(list)) { const QVariantMap &vh = item.value(); QMapIterator it(vh); while (it.hasNext()) { diff --git a/src/declarativeimports/core/datasource.cpp b/src/declarativeimports/core/datasource.cpp --- a/src/declarativeimports/core/datasource.cpp +++ b/src/declarativeimports/core/datasource.cpp @@ -49,7 +49,7 @@ void DataSource::setConnectedSources(const QStringList &sources) { bool sourcesChanged = false; - foreach (const QString &source, sources) { + for (const QString &source : sources) { if (!m_connectedSources.contains(source)) { sourcesChanged = true; if (m_dataEngine) { @@ -60,7 +60,7 @@ } } - foreach (const QString &source, m_connectedSources) { + for (const QString &source : qAsConst(m_connectedSources)) { if (!sources.contains(source)) { m_data->clear(source); sourcesChanged = true; @@ -161,7 +161,7 @@ qDeleteAll(m_services); m_services.clear(); - foreach (const QString &source, m_connectedSources) { + for (const QString &source : qAsConst(m_connectedSources)) { m_dataEngine->connectSource(source, this, m_interval, m_intervalAlignment); emit sourceConnected(source); } diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -625,7 +625,7 @@ // It is more efficient to do it here, as KIconLoader::drawOverlays() // assumes that an overlay will be drawn and has some additional // setup time. - foreach (const QString& overlay, m_overlays) { + for (const QString& overlay : qAsConst(m_overlays)) { if (!overlay.isEmpty()) { // There is at least one overlay, draw all overlays above m_pixmap // and cancel the check diff --git a/src/declarativeimports/core/tooltipdialog.cpp b/src/declarativeimports/core/tooltipdialog.cpp --- a/src/declarativeimports/core/tooltipdialog.cpp +++ b/src/declarativeimports/core/tooltipdialog.cpp @@ -56,7 +56,8 @@ if (!m_qmlObject->rootObject()) { //HACK: search our own import - foreach (const QString &path, m_qmlObject->engine()->importPathList()) { + const auto lst = m_qmlObject->engine()->importPathList(); + for (const QString &path : lst) { if (QFile::exists(path + QStringLiteral("/org/kde/plasma/core"))) { m_qmlObject->setSource(QUrl::fromLocalFile(path + QStringLiteral("/org/kde/plasma/core/private/DefaultToolTip.qml"))); break; diff --git a/src/declarativeimports/plasmacomponents/qmenu.cpp b/src/declarativeimports/plasmacomponents/qmenu.cpp --- a/src/declarativeimports/plasmacomponents/qmenu.cpp +++ b/src/declarativeimports/plasmacomponents/qmenu.cpp @@ -99,7 +99,7 @@ if (action) { action->setMenu(m_menu); m_menu->clear(); - foreach (QMenuItem *item, m_items) { + for (QMenuItem *item : qAsConst(m_items)) { if (item->section()) { if (!item->isVisible()) { continue; @@ -288,7 +288,7 @@ { m_menu->clear(); - foreach (QMenuItem *item, m_items) { + for (QMenuItem *item : qAsConst(m_items)) { if (item->section()) { if (!item->isVisible()) { continue; diff --git a/src/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp b/src/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp --- a/src/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp +++ b/src/declarativeimports/plasmaextracomponents/fallbackcomponent.cpp @@ -58,7 +58,7 @@ { QString resolved; - foreach (const QString &path, m_candidates) { + for (const QString &path : qAsConst(m_candidates)) { // qDebug() << "Searching for:" << path + path; if (m_possiblePaths.contains(path + key)) { resolved = *m_possiblePaths.object(path + key); diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -186,7 +186,8 @@ //qCDebug(LOG_PLASMA) << cfg.keyList(); if (cfg.exists()) { - foreach (const QString &key, cfg.keyList()) { + const auto keyList = cfg.keyList(); + for (const QString &key : keyList) { //qCDebug(LOG_PLASMA) << "loading" << key; setContainmentActions(key, cfg.readEntry(key, QString())); } @@ -208,7 +209,8 @@ } if (defaultActionsCfg.isValid()) { defaultActionsCfg = KConfigGroup(&defaultActionsCfg, "ContainmentActions"); - foreach (const QString &key, defaultActionsCfg.keyList()) { + const auto keyList = defaultActionsCfg.keyList(); + for (const QString &key : keyList) { setContainmentActions(key, defaultActionsCfg.readEntry(key, QString())); } } @@ -253,7 +255,7 @@ void Containment::saveContents(KConfigGroup &group) const { KConfigGroup applets(&group, "Applets"); - foreach (const Applet *applet, d->applets) { + for (const Applet *applet : qAsConst(d->applets)) { KConfigGroup appletConfig(&applets, QString::number(applet->id())); applet->save(appletConfig); } @@ -270,7 +272,7 @@ // Sort the applet configs in order of geometry to ensure that applets // are added from left to right or top to bottom for a panel containment QList appletConfigs; - foreach (const QString &appletGroup, groups) { + for (const QString &appletGroup : qAsConst(groups)) { //qCDebug(LOG_PLASMA) << "reading from applet group" << appletGroup; KConfigGroup appletConfig(&applets, appletGroup); appletConfigs.append(appletConfig); @@ -294,7 +296,8 @@ if (Containment::applets().isEmpty()) { d->appletsUiReady = true; } - foreach (Applet *applet, Containment::applets()) { + const auto lstApplets = Containment::applets(); + for (Applet *applet : lstApplets) { if (!applet->pluginMetaData().isValid()) { applet->updateConstraints(Plasma::Types::UiReadyConstraint); } @@ -356,7 +359,7 @@ d->location = location; - foreach (Applet *applet, d->applets) { + for (Applet *applet : qAsConst(d->applets)) { applet->updateConstraints(Plasma::Types::LocationConstraint); } @@ -421,7 +424,8 @@ applet->configScheme()->setCurrentGroup(applet->configScheme()->currentGroup().replace(0, oldGroupPrefix.length(), newGroupPrefix)); - foreach (KConfigSkeletonItem *item, applet->configScheme()->items()) { + const auto lstItems = applet->configScheme()->items(); + for (KConfigSkeletonItem *item : lstItems) { item->setGroup(item->group().replace(0, oldGroupPrefix.length(), newGroupPrefix)); } } diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -110,7 +110,8 @@ void Corona::exportLayout(KConfigGroup &config, QList containments) { - foreach (const QString &group, config.groupList()) { + const auto groupList = config.groupList(); + for (const QString &group : groupList) { KConfigGroup cg(&config, group); cg.deleteGroup(); } @@ -121,14 +122,15 @@ KConfigGroup dest(&config, "Containments"); KConfigGroup dummy; - foreach (Plasma::Containment *c, containments) { + for (Plasma::Containment *c : qAsConst(containments)) { c->save(dummy); c->config().reparent(&dest); //ensure the containment is unlocked //this is done directly because we have to bypass any Types::SystemImmutable checks c->Applet::d->immutability = Types::Mutable; - foreach (Applet *a, c->applets()) { + const auto lstApplet = c->applets(); + for (Applet *a : lstApplet) { a->d->immutability = Types::Mutable; } @@ -191,7 +193,7 @@ Containment *Corona::containmentForScreen(int screen) const { - foreach (Containment *containment, d->containments) { + for (Containment *containment : qAsConst(d->containments)) { if (containment->screen() == screen && (containment->containmentType() == Plasma::Types::DesktopContainment || containment->containmentType() == Plasma::Types::CustomContainment)) { @@ -214,7 +216,7 @@ { Containment *containment = nullptr; - foreach (Containment *cont, d->containments) { + for (Containment *cont : qAsConst(d->containments)) { if (cont->lastScreen() == screen && (cont->activity().isEmpty() || cont->activity() == activity) && (cont->containmentType() == Plasma::Types::DesktopContainment || @@ -388,7 +390,8 @@ freeEdges << Plasma::Types::TopEdge << Plasma::Types::BottomEdge << Plasma::Types::LeftEdge << Plasma::Types::RightEdge; - foreach (Containment *containment, containments()) { + const auto lst = containments(); + for (Containment *containment : lst) { if (containment->screen() == screen && freeEdges.contains(containment->location())) { freeEdges.removeAll(containment->location()); @@ -461,16 +464,16 @@ void CoronaPrivate::saveLayout(KSharedConfigPtr cg) const { KConfigGroup containmentsGroup(cg, "Containments"); - foreach (const Containment *containment, containments) { + for (const Containment *containment : qAsConst(containments)) { QString cid = QString::number(containment->id()); KConfigGroup containmentConfig(&containmentsGroup, cid); containment->save(containmentConfig); } } void CoronaPrivate::updateContainmentImmutability() { - foreach (Containment *c, containments) { + for (Containment *c : qAsConst(containments)) { // we need to tell each containment that immutability has been altered c->updateConstraints(Types::ImmutableConstraint); } @@ -593,15 +596,15 @@ QList newContainments; QSet containmentsIds; - foreach (Containment *containment, containments) { + for (Containment *containment : qAsConst(containments)) { containmentsIds.insert(containment->id()); } KConfigGroup containmentsGroup(&conf, "Containments"); QStringList groups = containmentsGroup.groupList(); std::sort(groups.begin(), groups.end()); - foreach (const QString &group, groups) { + for (const QString &group : qAsConst(groups)) { KConfigGroup containmentConfig(&containmentsGroup, group); if (containmentConfig.entryMap().isEmpty()) { @@ -650,7 +653,7 @@ void CoronaPrivate::notifyContainmentsReady() { containmentsStarting = 0; - foreach (Containment *containment, containments) { + for (Containment *containment : qAsConst(containments)) { if (!containment->isUiReady() && containment->screen() >= 0) { ++containmentsStarting; QObject::connect(containment, &Plasma::Containment::uiReadyChanged, q, [this](bool ready) { containmentReady(ready); } ); diff --git a/src/plasma/datacontainer.cpp b/src/plasma/datacontainer.cpp --- a/src/plasma/datacontainer.cpp +++ b/src/plasma/datacontainer.cpp @@ -354,7 +354,7 @@ if (d->dirty) { emit dataUpdated(objectName(), d->data); - foreach (SignalRelay *relay, d->relays) { + for (SignalRelay *relay : qAsConst(d->relays)) { relay->checkQueueing(); } @@ -369,7 +369,7 @@ emit dataUpdated(objectName(), d->data); } - foreach (SignalRelay *relay, d->relays) { + for (SignalRelay *relay : qAsConst(d->relays)) { relay->forceImmediateUpdate(); } } diff --git a/src/plasma/dataengine.cpp b/src/plasma/dataengine.cpp --- a/src/plasma/dataengine.cpp +++ b/src/plasma/dataengine.cpp @@ -128,7 +128,7 @@ void DataEngine::connectAllSources(QObject *visualization, uint pollingInterval, Plasma::Types::IntervalAlignment intervalAlignment) const { - foreach (DataContainer *s, d->sources) { + for (DataContainer *s : qAsConst(d->sources)) { d->connectSource(s, visualization, pollingInterval, intervalAlignment); } } @@ -387,7 +387,7 @@ void DataEngine::forceImmediateUpdateOfAllVisualizations() { - foreach (DataContainer *source, d->sources) { + for (DataContainer *source : qAsConst(d->sources)) { if (source->isUsed()) { source->forceImmediateUpdate(); } diff --git a/src/plasma/dataengineconsumer.cpp b/src/plasma/dataengineconsumer.cpp --- a/src/plasma/dataengineconsumer.cpp +++ b/src/plasma/dataengineconsumer.cpp @@ -80,7 +80,7 @@ DataEngineConsumer::~DataEngineConsumer() { - foreach (const QString &engine, d->loadedEngines) { + for (const QString &engine : qAsConst(d->loadedEngines)) { DataEngineManager::self()->unloadEngine(engine); } diff --git a/src/plasma/package.cpp b/src/plasma/package.cpp --- a/src/plasma/package.cpp +++ b/src/plasma/package.cpp @@ -260,7 +260,8 @@ QList Package::directories() const { QList dirs; - foreach (const auto &data, d->internalPackage->directories()) { + const auto lstDirs = d->internalPackage->directories(); + for (const auto &data : lstDirs) { dirs << data.constData(); } @@ -270,7 +271,8 @@ QList Package::requiredDirectories() const { QList dirs; - foreach (const auto &data, d->internalPackage->requiredDirectories()) { + const auto lstDirs = d->internalPackage->requiredDirectories(); + for (const auto &data : lstDirs) { dirs << data.constData(); } @@ -280,7 +282,8 @@ QList Package::files() const { QList files; - foreach (const auto &data, d->internalPackage->files()) { + const auto lstFiles = d->internalPackage->files(); + for (const auto &data : lstFiles) { files << data.constData(); } @@ -290,7 +293,8 @@ QList Package::requiredFiles() const { QList files; - foreach (const auto &data, d->internalPackage->requiredFiles()) { + const auto lstFiles = d->internalPackage->requiredFiles(); + for (const auto &data : lstFiles) { files << data.constData(); } diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -142,7 +142,7 @@ PluginLoader::~PluginLoader() { typedef QPointer pswp; - foreach (pswp wp, d->structures) { + for (pswp wp : qAsConst(d->structures)) { delete wp.data(); } delete d; @@ -320,7 +320,7 @@ plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter); } - foreach (auto& plugin, plugins) { + for (auto& plugin : qAsConst(plugins)) { engines << plugin.pluginId(); } @@ -564,7 +564,7 @@ //NOTE: it still produces kplugininfos from KServices because some user code expects //info.service() to be valid and would crash otherwise - foreach (auto& md, plugins) { + for (auto& md : plugins) { auto pi = md.metaDataFileName().endsWith(QLatin1String(".json")) ? KPluginInfo(md) : KPluginInfo(KService::serviceByStorageId(md.metaDataFileName())); if (!pi.isValid()) { qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin"; @@ -605,9 +605,9 @@ const QList allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); QList filtered; - foreach (const KPluginMetaData &md, allApplets) { - QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); - foreach (const QString &glob, urlPatterns) { + for (const KPluginMetaData &md : allApplets) { + const QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); + for (const QString &glob : urlPatterns) { QRegExp rx(glob); rx.setPatternSyntax(QRegExp::Wildcard); if (rx.exactMatch(url.toString())) { @@ -642,7 +642,7 @@ QStringList categories; - foreach (auto& plugin, allApplets) { + for (auto& plugin : allApplets) { if (plugin.category().isEmpty()) { if (!categories.contains(i18nc("misc category", "Miscellaneous"))) { categories << i18nc("misc category", "Miscellaneous"); @@ -727,12 +727,12 @@ QStringList PluginLoader::listContainmentTypes() { - KPluginInfo::List containmentInfos = listContainments(); + const KPluginInfo::List containmentInfos = listContainments(); QSet types; - foreach (const KPluginInfo &containmentInfo, containmentInfos) { - QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); - foreach (const QString &type, theseTypes) { + for (const KPluginInfo &containmentInfo : containmentInfos) { + const QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); + for (const QString &type : theseTypes) { types.insert(type); } } @@ -777,14 +777,14 @@ list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); QSet knownPlugins; - foreach (const KPluginInfo &p, list) { + for (const KPluginInfo &p : qAsConst(list)) { knownPlugins.insert(p.pluginName()); } //FIXME: this is only for backwards compatibility, but probably will have to stay //for the time being - KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); - foreach (KService::Ptr s, offers) { + const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); + for (KService::Ptr s : offers) { if (!knownPlugins.contains(s->pluginKeyword())) { list.append(KPluginInfo(s)); } @@ -859,14 +859,14 @@ QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"), QStandardPaths::LocateFile); - KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); + const KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); if (category.isEmpty() || allInfo.isEmpty()) { return allInfo; } KPluginInfo::List matchingInfo; - foreach (const KPluginInfo &info, allInfo) { + for (const KPluginInfo &info : allInfo) { if (info.category().compare(category, Qt::CaseInsensitive) == 0) { matchingInfo << info; } diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -201,7 +201,7 @@ auto filter = [&provides](const KPluginMetaData &md) -> bool { const QStringList provided = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-Provides")); - foreach (const QString &p, provides) { + for (const QString &p : provides) { if (provided.contains(p)) { return true; } @@ -246,7 +246,8 @@ Plasma::Containment *asContainment = qobject_cast(q); if (asContainment) { - foreach(Applet *a , asContainment->applets()) + const auto lstApplets = asContainment->applets(); + for (Applet *a : lstApplets) a->d->setDestroyed(destroyed); } } @@ -411,10 +412,9 @@ if (q->isContainment()) { //a horrible hack to avoid clobbering corona settings //we pull them out, then read, then put them back - QList names; QList qactions; - names << QStringLiteral("add sibling containment") << QStringLiteral("configure shortcuts") << QStringLiteral("lock widgets"); - foreach (const QString &name, names) { + const QList names = QList() << QStringLiteral("add sibling containment") << QStringLiteral("configure shortcuts") << QStringLiteral("lock widgets"); + for (const QString &name : names) { QAction *a = actions->action(name); actions->takeAction(a); //FIXME this is stupid, KActionCollection needs a takeAction(QString) method qactions << a; diff --git a/src/plasma/private/containment_p.cpp b/src/plasma/private/containment_p.cpp --- a/src/plasma/private/containment_p.cpp +++ b/src/plasma/private/containment_p.cpp @@ -116,7 +116,7 @@ if (appletStatus < q->status() || appletStatus == Plasma::Types::HiddenStatus) { // check to see if any other applet has a higher status, and stick with that if we do // we'll treat HiddenStatus as lowest as we cannot change the enum value which is highest anymore - foreach (Applet *applet, applets) { + for (Applet *applet : qAsConst(applets)) { if (applet->status() > appletStatus && applet->status() != Plasma::Types::HiddenStatus) { appletStatus = applet->status(); } @@ -157,7 +157,7 @@ } // tell the applets too - foreach (Applet *a, applets) { + for (Applet *a : qAsConst(applets)) { /*Why qMin? * the applets immutability() is the maximum between internal applet immutability * and the immutability of its containment. @@ -180,7 +180,7 @@ } if (appletConstraints != Types::NoConstraint) { - foreach (Applet *applet, applets) { + for (Applet *applet : qAsConst(applets)) { applet->updateConstraints(appletConstraints); } } diff --git a/src/plasma/private/dataenginemanager.cpp b/src/plasma/private/dataenginemanager.cpp --- a/src/plasma/private/dataenginemanager.cpp +++ b/src/plasma/private/dataenginemanager.cpp @@ -58,7 +58,7 @@ ~DataEngineManagerPrivate() { - foreach (Plasma::DataEngine *engine, engines) { + for (Plasma::DataEngine *engine : qAsConst(engines)) { delete engine; } engines.clear(); @@ -177,7 +177,8 @@ out << " Actual # of sources: " << engine->containerDict().count() << endl; out << endl << " Source Details" << endl; - foreach (DataContainer *dc, engine->containerDict()) { + const auto lst = engine->containerDict(); + for (DataContainer *dc : lst) { out << " * " << dc->objectName() << endl; out << " Data count: " << dc->d->data.count() << endl; out << " Stored: " << dc->isStorageEnabled() << ' ' << endl; @@ -190,7 +191,7 @@ if (relays > 0) { out << " Relays: " << dc->d->relays.count() << endl; QString times; - foreach (SignalRelay *relay, dc->d->relays) { + for (SignalRelay *relay : qAsConst(dc->d->relays)) { times.append(QLatin1Char(' ') + QString::number(relay->m_interval)); } out << " Relay Timeouts: " << times << ' ' << endl; diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -820,7 +820,7 @@ fallbackThemes.append(QLatin1String(ThemePrivate::defaultTheme)); } - foreach (const QString &theme, fallbackThemes) { + for (const QString &theme : qAsConst(fallbackThemes)) { QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal(PLASMA_RELATIVE_DATA_INSTALL_DIR "/desktoptheme/") % theme % QLatin1Literal("/metadata.desktop"))); KConfig metadata(metadataPath, KConfig::SimpleConfig); processWallpaperSettings(&metadata); diff --git a/src/plasma/private/timetracker.cpp b/src/plasma/private/timetracker.cpp --- a/src/plasma/private/timetracker.cpp +++ b/src/plasma/private/timetracker.cpp @@ -41,7 +41,7 @@ void print() { QJsonArray array; - Q_FOREACH(const ObjectHistory& history, m_data) { + for (const ObjectHistory& history : qAsConst(m_data)) { array.append(QJsonObject { { QStringLiteral("events"), serializeEvents(history.events) }, { QStringLiteral("initial"), QJsonValue::fromVariant(history.initial) } @@ -68,7 +68,7 @@ QJsonArray serializeEvents(const QVector& events) const { QJsonArray ret; Q_ASSERT(!events.isEmpty()); - foreach(const TimeEvent& ev, events) { + for (const TimeEvent& ev : events) { ret.append(QJsonObject { { QStringLiteral("comment"), ev.comment }, { QStringLiteral("time"), ev.moment.toMSecsSinceEpoch() - *s_beginning } diff --git a/src/plasma/scripting/scriptengine.cpp b/src/plasma/scripting/scriptengine.cpp --- a/src/plasma/scripting/scriptengine.cpp +++ b/src/plasma/scripting/scriptengine.cpp @@ -63,7 +63,7 @@ QStringList languages; const QVector plugins = KPluginLoader::findPlugins(QStringLiteral("plasma/scriptengines")); - foreach (const auto &plugin, plugins) { + for (const auto &plugin : plugins) { const QStringList componentTypes = KPluginMetaData::readStringList(plugins.first().rawData(), QStringLiteral("X-Plasma-ComponentTypes")); if (((types & Types::AppletComponent) && componentTypes.contains(QStringLiteral("Applet"))) ||((types & Types::DataEngineComponent) && componentTypes.contains(QStringLiteral("DataEngine")))) { diff --git a/src/plasma/service.cpp b/src/plasma/service.cpp --- a/src/plasma/service.cpp +++ b/src/plasma/service.cpp @@ -176,10 +176,12 @@ KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("/dev/null"), KConfig::SimpleConfig); KConfigLoader loader(config, xml); - foreach (const QString &group, loader.groupList()) { + const auto groupList = loader.groupList(); + for (const QString &group : groupList) { d->operationsMap[group][QStringLiteral("_name")] = group; } - foreach (KConfigSkeletonItem *item, loader.items()) { + const auto itemsList = loader.items(); + for (KConfigSkeletonItem *item : itemsList) { d->operationsMap[item->group()][item->key()] = item->property(); } } diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -311,7 +311,8 @@ // and store them locally. QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE(QStringLiteral("(\\d+)-(\\d+)-(.+)"), status, ratio)); - foreach (const QString &key, cacheAndColorsTheme()->listCachedRectKeys(path)) { + const auto lst = cacheAndColorsTheme()->listCachedRectKeys(path); + for (const QString &key : lst) { if (sizeHintedKeyExpr.exactMatch(key)) { QString baseElementId = sizeHintedKeyExpr.cap(3); QSize sizeHint(sizeHintedKeyExpr.cap(1).toInt(), @@ -332,12 +333,12 @@ // Look at the size hinted elements and try to find the smallest one with an // identical aspect ratio. if (s.isValid() && !elementId.isEmpty()) { - QList elementSizeHints = elementsWithSizeHints.values(elementId); + const QList elementSizeHints = elementsWithSizeHints.values(elementId); if (!elementSizeHints.isEmpty()) { QSize bestFit(-1, -1); - Q_FOREACH (QSize hint, elementSizeHints) { + for (QSize hint : elementSizeHints) { if (hint.width() >= s.width() * ratio && hint.height() >= s.height() * ratio && (!bestFit.isValid() || diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -115,7 +115,8 @@ //Search a child that has the needed Layout properties //HACK: here we are not type safe, but is the only way to access to a pointer of Layout - foreach (QObject *child, item->children()) { + const auto lstChildren = item->children(); + for (QObject *child : lstChildren) { //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && @@ -156,7 +157,8 @@ QObject *ownLayout = nullptr; - foreach (QObject *child, q->children()) { + const auto lstChild = q->children(); + for (QObject *child : lstChild) { //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && @@ -600,7 +602,8 @@ if (d->applet->failedToLaunch()) { reason = d->applet->launchErrorMessage(); } else if (d->applet->kPackage().isValid()) { - foreach (QQmlError error, d->qmlObject->mainComponent()->errors()) { + const auto lst = d->qmlObject->mainComponent()->errors(); + for (QQmlError error : lst) { reason += error.toString() + QLatin1Char('\n'); } reason = i18n("Error loading QML file: %1", reason); diff --git a/src/plasmaquick/configview.cpp b/src/plasmaquick/configview.cpp --- a/src/plasmaquick/configview.cpp +++ b/src/plasmaquick/configview.cpp @@ -157,7 +157,7 @@ configModel = new ConfigModel(q); } - foreach (const QString &kcm, kcms) { + for (const QString &kcm : qAsConst(kcms)) { KPluginLoader loader(KPluginLoader::findPlugin(QLatin1String("kcms/") + kcm)); KPluginMetaData md(loader.fileName()); @@ -243,7 +243,8 @@ //Search a child that has the needed Layout properties //HACK: here we are not type safe, but is the only way to access to a pointer of Layout - foreach (QObject *child, q->rootObject()->children()) { + const auto children = q->rootObject()->children(); + for (QObject *child : children) { //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -173,7 +173,8 @@ // we simply iterate over the virtual screens and pick the one our QWindow // says it's at. QRect avail; - Q_FOREACH (QScreen *screen, QGuiApplication::screens()) { + const auto screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { //we check geometry() but then take availableGeometry() //to reliably check in which screen a position is, we need the full //geometry, including areas for panels @@ -802,7 +803,8 @@ //Search a child that has the needed Layout properties //HACK: here we are not type safe, but is the only way to access to a pointer of Layout - foreach (QObject *child, mainItem->children()) { + const auto lstChild = mainItem->children(); + for (QObject *child : lstChild) { //find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() && child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() && diff --git a/src/plasmaquick/dialogshadows.cpp b/src/plasmaquick/dialogshadows.cpp --- a/src/plasmaquick/dialogshadows.cpp +++ b/src/plasmaquick/dialogshadows.cpp @@ -461,7 +461,7 @@ return; } - foreach (const QPixmap &pixmap, m_shadowPixmaps) { + for (const QPixmap &pixmap : qAsConst(m_shadowPixmaps)) { if (!pixmap.isNull()) { XFreePixmap(display, reinterpret_cast(createPixmap(pixmap))); } diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -416,7 +416,7 @@ return actions; } - foreach (const QString &name, m_actions) { + for (const QString &name : qAsConst(m_actions)) { QAction *action = a->actions()->action(name); if (action) { @@ -482,7 +482,8 @@ void AppletInterface::clearActions() { - Q_FOREACH (const QString &action, m_actions) { + const auto oldActionsList = m_actions; + for (const QString &action : oldActionsList) { removeAction(action); } } @@ -745,7 +746,7 @@ } bool keySequenceUsed = false; - foreach (auto a, actions) { + for (auto a : qAsConst(actions)) { if (a->shortcut().isEmpty()) { continue; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -239,7 +239,8 @@ QObject *ContainmentInterface::containmentAt(int x, int y) { QObject *desktop = nullptr; - foreach (Plasma::Containment *c, m_containment->corona()->containments()) { + const auto lst = m_containment->corona()->containments(); + for (Plasma::Containment *c : lst) { ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value(); if (contInterface && contInterface->isVisible()) { @@ -456,16 +457,16 @@ if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); - foreach (const QString &appletName, appletNames) { + for (const QString &appletName : appletNames) { qDebug() << "adding" << appletName; metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); } } else if (mimeData->hasUrls()) { //TODO: collect the mimetypes of available script engines and offer // to create widgets out of the matching URLs, if any const QList urls = KUrlMimeData::urlsFromMimeData(mimeData); - foreach (const QUrl &url, urls) { + for (const QUrl &url : urls) { QMimeDatabase db; const QMimeType &mime = db.mimeTypeForUrl(url); QString mimeName = mime.name(); @@ -497,14 +498,14 @@ } } else { - QStringList formats = mimeData->formats(); + const QStringList formats = mimeData->formats(); QHash seenPlugins; QHash pluginFormats; - foreach (const QString &format, formats) { + for (const QString &format : formats) { const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); - foreach (const auto &plugin, plugins) { + for (const auto &plugin : plugins) { if (seenPlugins.contains(plugin.pluginId())) { continue; } @@ -534,7 +535,7 @@ } QList extraActions; QHash actionsToPlugins; - foreach (const auto &info, seenPlugins) { + for (const auto &info : qAsConst(seenPlugins)) { QAction *action; if (!info.iconName().isEmpty()) { action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), nullptr); @@ -700,7 +701,7 @@ action->setSeparator(true); dropActions << action; } - foreach (const auto &info, appletList) { + for (const auto &info : qAsConst(appletList)) { const QString actionText = i18nc("Add widget", "Add %1", info.name()); QAction *action = new QAction(actionText, nullptr); if (!info.iconName().isEmpty()) { @@ -742,11 +743,11 @@ } QMap sorted; - foreach (const auto &info, appletList) { + for (const auto &info : qAsConst(appletList)) { sorted.insert(info.name(), info); } - foreach (const KPluginMetaData &info, wallpaperList) { + for (const KPluginMetaData &info : qAsConst(wallpaperList)) { const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); QAction *action = new QAction(actionText, nullptr); if (!info.iconName().isEmpty()) { @@ -904,7 +905,8 @@ //use a multimap to sort by action type QMultiMap actions; int i = 0; - foreach (QAction *a, m_containment->actions()->actions()) { + auto listActions = m_containment->actions()->actions(); + for (QAction *a : qAsConst(listActions)) { if (!actionOrder.contains(a->objectName())) { //FIXME QML visualizations don't support menus for now, *and* there is no way to //distinguish them on QML side @@ -918,7 +920,8 @@ } i = 0; - foreach (QAction *a, m_containment->corona()->actions()->actions()) { + listActions = m_containment->corona()->actions()->actions(); + for (QAction *a : qAsConst(listActions)) { if (a->objectName() == QStringLiteral("lock widgets") || a->menu()) { //It is up to the Containment to decide if the user is allowed or not //to lock/unluck the widgets, so corona should not add one when there is none @@ -936,7 +939,7 @@ } QList actionList = actions.values(); - foreach (const QString &name, actionOrder) { + for (const QString &name : qAsConst(actionOrder)) { QAction *a = orderedActions.value(name); if (a && !a->menu()) { actionList << a; @@ -985,7 +988,7 @@ //FIXME: very inefficient appletAt() implementation Plasma::Applet *applet = nullptr; - foreach (QObject *appletObject, m_appletInterfaces) { + for (QObject *appletObject : qAsConst(m_appletInterfaces)) { if (AppletInterface *ai = qobject_cast(appletObject)) { if (ai->isVisible() && ai->contains(ai->mapFromItem(this, event->localPos()))) { applet = ai->applet(); @@ -1113,7 +1116,8 @@ void ContainmentInterface::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event) { - foreach (QAction *action, applet->contextualActions()) { + const auto listActions = applet->contextualActions(); + for (QAction *action : listActions) { if (action) { desktopMenu->addAction(action); } @@ -1154,7 +1158,8 @@ if (enabled) { //if there is only one, don't create a submenu if (enabled < 2) { - foreach (QAction *action, containmentMenu->actions()) { + const auto listActions = containmentMenu->actions(); + for (QAction *action : listActions) { if (action->isVisible() && !action->isSeparator()) { desktopMenu->addAction(action); } diff --git a/tests/kplugins/plugintest.cpp b/tests/kplugins/plugintest.cpp --- a/tests/kplugins/plugintest.cpp +++ b/tests/kplugins/plugintest.cpp @@ -128,7 +128,7 @@ bool ok = false; const QStringList allEngines = Plasma::PluginLoader::self()->listAllEngines(); qDebug() << "All engines: " << allEngines; - foreach (const QString &e, allEngines) { + for (const QString &e : allEngines) { Plasma::DataEngine *engine = Plasma::PluginLoader::self()->loadDataEngine(e); if (engine) { engine->connectSource(QStringLiteral("Europe/Amsterdam"), this);