diff --git a/shell/panelview.cpp b/shell/panelview.cpp --- a/shell/panelview.cpp +++ b/shell/panelview.cpp @@ -999,7 +999,8 @@ //Extended struts against a screen edge near to another screen are really harmful, so windows maximized under the panel is a lesser pain //TODO: force "windows can cover" in those cases? - foreach (int id, m_corona->screenIds()) { + const auto screenIds = m_corona->screenIds(); + for (int id : screenIds) { if (id == containment()->screen()) { continue; } diff --git a/shell/screenpool.cpp b/shell/screenpool.cpp --- a/shell/screenpool.cpp +++ b/shell/screenpool.cpp @@ -66,7 +66,8 @@ } //restore the known ids to connector mappings - foreach (const QString &key, m_configGroup.keyList()) { + const auto keys = m_configGroup.keyList(); + for (const QString &key : keys) { QString connector = m_configGroup.readEntry(key, QString()); if (!key.isEmpty() && !connector.isEmpty() && !m_connectorForId.contains(key.toInt()) && diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -366,8 +366,9 @@ } } - foreach (const QString &groupName, cg.groupList()) { - if (groupName == QStringLiteral("Applets") || + const auto groupList = cg.groupList(); + for (const QString &groupName : groupList) { + if (groupName == QLatin1String("Applets") || visitedNodes.contains(groupID() + '/' + groupName)) { continue; } @@ -414,7 +415,7 @@ QJsonArray panelsJsonArray; - foreach (Plasma::Containment *cont, containments) { + for (Plasma::Containment *cont : containments) { if (!isPanel(cont)) { continue; } @@ -478,7 +479,7 @@ // Consider the applet order to be valid only if there are as many entries as applets() if (appletsOrderStrings.length() == cont->applets().length()) { - foreach (const QString &appletId, appletsOrderStrings) { + for (const QString &appletId : appletsOrderStrings) { KConfigGroup appletConfig(&contConfig, QStringLiteral("Applets")); appletConfig = KConfigGroup(&appletConfig, appletId); @@ -498,7 +499,8 @@ } } else { - foreach (Plasma::Applet *applet, cont->applets()) { + const auto applets = cont->applets(); + for (Plasma::Applet *applet : applets) { QJsonObject appletJson; KConfigGroup appletConfig = applet->config(); @@ -523,7 +525,7 @@ const auto currentActivity = m_activityController->currentActivity(); - foreach (Plasma::Containment *cont, containments) { + for (Plasma::Containment *cont : containments) { if (!isDesktop(cont) || cont->activity() != currentActivity) { continue; } @@ -544,7 +546,7 @@ QHash appletGeometries; - foreach (const QString &encoded, appletsGeomStrings) { + for (const QString &encoded : appletsGeomStrings) { const QStringList keyValue = encoded.split(QChar(':')); if (keyValue.length() != 2) { continue; @@ -563,7 +565,8 @@ QJsonArray appletsJsonArray; - foreach (Plasma::Applet *applet, cont->applets()) { + const auto applets = cont->applets(); + for (Plasma::Applet *applet : applets) { const QRect geometry = appletGeometries.value( QStringLiteral("Applet-") % QString::number(applet->id())); @@ -662,7 +665,8 @@ processUpdateScripts(); } else { processUpdateScripts(); - foreach(Plasma::Containment *containment, containments()) { + const auto containments = this->containments(); + for (Plasma::Containment *containment : containments) { if (containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment) { //Don't give a view to containments that don't want one (negative lastscreen) //(this is pretty mucha special case for the systray) @@ -750,7 +754,7 @@ m_redundantOutputs.insert(oldPrimary); } - foreach (PanelView *panel, m_panelViews) { + for (PanelView *panel : qAsConst(m_panelViews)) { if (panel->screen() == oldPrimary) { panel->setScreenToFollow(newPrimary); } else if (panel->screen() == newPrimary) { @@ -923,8 +927,8 @@ // We need to know which activities are here in order for // the scripting engine to work. activityAdded does not mind // if we pass it the same activity multiple times - QStringList existingActivities = m_activityController->activities(); - foreach (const QString &id, existingActivities) { + const QStringList existingActivities = m_activityController->activities(); + for (const QString &id : existingActivities) { activityAdded(id); } @@ -1002,7 +1006,7 @@ } QRegion r = view->geometry(); - foreach (const PanelView *v, m_panelViews) { + for (const PanelView *v : m_panelViews) { if (v->isVisible() && view->screen() == v->screen() && v->visibilityMode() != PanelView::AutoHide) { //if the panel is being moved around, we still want to calculate it from the edge r -= v->geometryByDistance(0); @@ -1022,7 +1026,7 @@ } QRect r = view->geometry(); - foreach (PanelView *v, m_panelViews) { + for (PanelView *v : m_panelViews) { if (v->isVisible() && v->screen() == view->screen() && v->visibilityMode() != PanelView::AutoHide) { switch (v->location()) { case Plasma::Types::LeftEdge: @@ -1087,7 +1091,7 @@ QList ShellCorona::panelsForScreen(QScreen *screen) const { QList ret; - foreach (PanelView *v, m_panelViews) { + for (PanelView *v : m_panelViews) { if (v->screenToFollow() == screen) { ret += v; } @@ -1124,7 +1128,8 @@ //* its geometry is contained in another one //* if their resolutions are different, the "biggest" one wins //* if they have the same geometry, the one with the lowest id wins (arbitrary, but gives reproducible behavior and makes the primary screen win) - foreach (QScreen* s, qGuiApp->screens()) { + const auto screens = qGuiApp->screens(); + for (QScreen* s : screens) { //don't compare with itself if (screen == s) { continue; @@ -1155,7 +1160,8 @@ void ShellCorona::reconsiderOutputs() { - foreach (QScreen* screen, qGuiApp->screens()) { + const auto screens = qGuiApp->screens(); + for (QScreen* screen : screens) { if (m_redundantOutputs.contains(screen)) { if (!isOutputRedundant(screen)) { //qDebug() << "not redundant anymore" << screen; @@ -1293,7 +1299,7 @@ { QList stillWaitingPanels; - foreach (Plasma::Containment *cont, m_waitingPanels) { + for (Plasma::Containment *cont : qAsConst(m_waitingPanels)) { //ignore non existing (yet?) screens int requestedScreen = cont->lastScreen(); if (requestedScreen < 0) { @@ -1393,7 +1399,7 @@ void ShellCorona::toggleWidgetExplorer() { const QPoint cursorPos = QCursor::pos(); - foreach (DesktopView *view, m_desktopViewforId) { + for (DesktopView *view : qAsConst(m_desktopViewforId)) { if (view->screen()->geometry().contains(cursorPos)) { //The view QML has to provide something to display the widget explorer view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "toggleWidgetExplorer", Q_ARG(QVariant, QVariant::fromValue(sender()))); @@ -1405,7 +1411,7 @@ void ShellCorona::toggleActivityManager() { const QPoint cursorPos = QCursor::pos(); - foreach (DesktopView *view, m_desktopViewforId) { + for (DesktopView *view : qAsConst(m_desktopViewforId)) { if (view->screen()->geometry().contains(cursorPos)) { //The view QML has to provide something to display the activity explorer view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "toggleActivityManager", Qt::QueuedConnection); @@ -1539,8 +1545,8 @@ return; } - QStringList existingActivities = m_activityController->activities(); - foreach (const QString &id, existingActivities) { + const QStringList existingActivities = m_activityController->activities(); + for (const QString &id : existingActivities) { activityAdded(id); } @@ -1550,7 +1556,8 @@ "null uuid", "There is a nulluuid activity present"); // Killing the unassigned containments - foreach (Plasma::Containment *cont, containments()) { + const auto conts = containments(); + for (Plasma::Containment *cont : conts) { if ((cont->containmentType() == Plasma::Types::DesktopContainment || cont->containmentType() == Plasma::Types::CustomContainment) && !existingActivities.contains(cont->activity())) { @@ -1563,14 +1570,14 @@ { // qDebug() << "Activity changed:" << newActivity; - foreach (int id, m_desktopViewforId.keys()) { - Plasma::Containment *c = createContainmentForActivity(newActivity, id); + for (auto it = m_desktopViewforId.constBegin(); it != m_desktopViewforId.constEnd(); ++it) { + Plasma::Containment *c = createContainmentForActivity(newActivity, it.key()); QAction *removeAction = c->actions()->action(QStringLiteral("remove")); if (removeAction) { removeAction->deleteLater(); } - m_desktopViewforId.value(id)->setContainment(c); + (*it)->setContainment(c); } } @@ -1616,10 +1623,10 @@ } m_activityContainmentPlugins.insert(id, plugin); - foreach (int screenId, m_desktopViewforId.keys()) { - Plasma::Containment *c = createContainmentForActivity(id, screenId); + for (auto it = m_desktopViewforId.constBegin(); it != m_desktopViewforId.constEnd(); ++it) { + Plasma::Containment *c = createContainmentForActivity(id, it.key()); if (c) { - c->config().writeEntry("lastScreen", screenId); + c->config().writeEntry("lastScreen", it.key()); } } } @@ -1639,7 +1646,7 @@ } DesktopView *view = nullptr; - foreach (DesktopView *v, m_desktopViewforId) { + for (DesktopView *v : qAsConst(m_desktopViewforId)) { if (v->containment() == oldContainment) { view = v; break; @@ -1676,7 +1683,8 @@ //this makes containment->config() work, is a separate thing from its configscheme KConfigGroup newCg2 = newContainment->config(); - foreach (const QString &group, oldCg.groupList()) { + const auto groups = oldCg.groupList(); + for (const QString &group : groups) { if (group != QLatin1String("Applets")) { KConfigGroup subGroup(&oldCg, group); KConfigGroup newSubGroup(&newCg, group); @@ -1695,7 +1703,8 @@ emit containmentAdded(newContainment); //Move the applets - foreach (Plasma::Applet *applet, oldContainment->applets()) { + const auto applets = oldContainment->applets(); + for (Plasma::Applet *applet : applets) { newContainment->addApplet(applet); } @@ -1765,9 +1774,9 @@ m_addPanelsMenu->clear(); const KPluginInfo emptyInfo; - KPluginInfo::List panelContainmentPlugins = Plasma::PluginLoader::listContainmentsOfType(QStringLiteral("Panel")); + const KPluginInfo::List panelContainmentPlugins = Plasma::PluginLoader::listContainmentsOfType(QStringLiteral("Panel")); QMap > sorted; - foreach (const KPluginInfo &plugin, panelContainmentPlugins) { + for (const KPluginInfo &plugin : panelContainmentPlugins) { if (plugin.property(QStringLiteral("NoDisplay")).toString() == QStringLiteral("true")) { continue; } @@ -1849,8 +1858,8 @@ QList availableLocations; availableLocations << Plasma::Types::LeftEdge << Plasma::Types::TopEdge << Plasma::Types::RightEdge << Plasma::Types::BottomEdge; - foreach (const Plasma::Containment *cont, m_panelViews.keys()) { - availableLocations.removeAll(cont->location()); + for (auto it = m_panelViews.constBegin(); it != m_panelViews.constEnd(); ++it) { + availableLocations.removeAll((*it)->location()); } Plasma::Types::Location loc; @@ -1880,7 +1889,8 @@ m_waitingPanelsTimer.start(); const QPoint cursorPos(QCursor::pos()); - foreach (QScreen *screen, QGuiApplication::screens()) { + const auto screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { //m_panelViews.contains(panel) == false iff addPanel is executed in a startup script auto panelView = m_panelViews.value(panel); if (panelView && screen->geometry().contains(cursorPos)) { @@ -2045,7 +2055,7 @@ void ShellCorona::updateStruts() { - foreach(PanelView* view, m_panelViews) { + for (PanelView* view : qAsConst(m_panelViews)) { view->updateStruts(); } }