diff --git a/autotests/ktoolbar_unittest.cpp b/autotests/ktoolbar_unittest.cpp --- a/autotests/ktoolbar_unittest.cpp +++ b/autotests/ktoolbar_unittest.cpp @@ -92,7 +92,8 @@ QDir src = QDir(from); QDir dest = QDir(to.filePath(src.dirName())); to.mkpath(src.dirName()); - foreach (const QFileInfo &fileInfo, src.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { + const auto fileInfos = src.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + for (const QFileInfo &fileInfo : fileInfos) { if (fileInfo.isDir()) { copy_dir(fileInfo.filePath(), dest); } else { @@ -652,7 +653,8 @@ TestXmlGuiWindow kmw(m_xml, "tst_ktoolbar.rc"); kmw.createGUI(); - foreach (KToolBar *toolbar, kmw.toolBars()) { + const auto toolbars = kmw.toolBars(); + for (KToolBar *toolbar: toolbars) { QVERIFY(!toolbar->toggleViewAction()->isEnabled()); } } diff --git a/src/kedittoolbar.cpp b/src/kedittoolbar.cpp --- a/src/kedittoolbar.cpp +++ b/src/kedittoolbar.cpp @@ -686,7 +686,8 @@ m_accept = false; if (m_factory) { - foreach (KXMLGUIClient *client, m_factory->clients()) { + const auto clients = m_factory->clients(); + for (KXMLGUIClient *client : clients) { const QString file = client->localXMLFile(); if (file.isEmpty()) { continue; @@ -869,7 +870,8 @@ // add all of the client data bool first = true; - foreach (KXMLGUIClient *client, factory->clients()) { + const auto clients = factory->clients(); + for (KXMLGUIClient *client : clients) { if (client->xmlFile().isEmpty()) { continue; } @@ -899,7 +901,8 @@ m_widget->setMinimumSize(m_widget->sizeHint()); m_widget->actionCollection()->addAssociatedWidget(m_widget); - foreach (QAction *action, m_widget->actionCollection()->actions()) { + const auto widgetActions = m_widget->actionCollection()->actions(); + for (QAction *action : widgetActions) { action->setShortcutContext(Qt::WidgetWithChildrenShortcut); } } @@ -1260,7 +1263,8 @@ // iterate through this client's actions // This used to iterate through _all_ actions, but we don't support // putting any action into any client... - foreach (QAction *action, actionCollection->actions()) { + const auto actions = actionCollection->actions(); + for (QAction *action : actions) { // do we have a match? if (it.attribute(attrName) == action->objectName()) { // we have a match! @@ -1276,7 +1280,8 @@ } // go through the rest of the collection - foreach (QAction *action, actionCollection->actions()) { + const auto actions = actionCollection->actions(); + for (QAction *action : actions) { // skip our active ones if (active_list.contains(action->objectName())) { continue; diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp --- a/src/kmainwindow.cpp +++ b/src/kmainwindow.cpp @@ -137,14 +137,15 @@ KConfigGui::setSessionConfig(sm.sessionId(), sm.sessionKey()); KConfig *config = KConfigGui::sessionConfig(); - if (!KMainWindow::memberList().isEmpty()) { + const auto windows = KMainWindow::memberList(); + if (!windows.isEmpty()) { // According to Jochen Wilhelmy , this // hook is useful for better document orientation - KMainWindow::memberList().at(0)->saveGlobalProperties(config); + windows.at(0)->saveGlobalProperties(config); } int n = 0; - foreach (KMainWindow *mw, KMainWindow::memberList()) { + for (KMainWindow *mw : windows) { n++; mw->savePropertiesInternal(config, n); } @@ -188,7 +189,8 @@ Worst of all, that is a real problem with ksmserver - it will not save applications that quit on their own in state save-yourself-done. */ - foreach (KMainWindow *window, KMainWindow::memberList()) { + const auto windows = KMainWindow::memberList(); + for (KMainWindow *window : windows) { if (window->testAttribute(Qt::WA_WState_Hidden)) { continue; } @@ -617,7 +619,8 @@ } int n = 1; // Toolbar counter. toolbars are counted from 1, - foreach (KToolBar *toolbar, toolBars()) { + const auto toolBars = this->toolBars(); + for (KToolBar *toolbar : toolBars) { QByteArray groupName("Toolbar"); // Give a number to the toolbar, but prefer a name if there is one, // because there's no real guarantee on the ordering of toolbars @@ -698,7 +701,8 @@ } int n = 1; // Toolbar counter. toolbars are counted from 1, - foreach (KToolBar *toolbar, toolBars()) { + const auto toolBars = this->toolBars(); + for (KToolBar *toolbar : toolBars) { QByteArray groupName("Toolbar"); // Give a number to the toolbar, but prefer a name if there is one, // because there's no real guarantee on the ordering of toolbars diff --git a/src/kmenumenuhandler_p.cpp b/src/kmenumenuhandler_p.cpp --- a/src/kmenumenuhandler_p.cpp +++ b/src/kmenumenuhandler_p.cpp @@ -98,15 +98,17 @@ return; } QStringList toolbarlist; - foreach (KToolBar *b, window->toolBars()) { + const auto toolbars = window->toolBars(); + for (KToolBar *b : toolbars) { toolbarlist << (b->windowTitle().isEmpty() ? b->objectName() : b->windowTitle()); } m_toolbarAction->setItems(toolbarlist); } static KActionCollection *findParentCollection(KXMLGUIFactory *factory, QAction *action) { - foreach (KXMLGUIClient *client, factory->clients()) { + const auto clients = factory->clients(); + for (KXMLGUIClient *client : clients) { KActionCollection *collection = client->actionCollection(); // if the call to actions() is too slow, add KActionCollection::contains(QAction*). if (collection->actions().contains(action)) { @@ -140,7 +142,8 @@ QList checkCollections; KXMLGUIFactory *factory = dynamic_cast(m_builder)->factory(); parentCollection = findParentCollection(factory, m_popupAction); - foreach (KXMLGUIClient *client, factory->clients()) { + const auto clients = factory->clients(); + for (KXMLGUIClient *client : clients) { checkCollections += client->actionCollection(); } swidget.setCheckActionCollections(checkCollections); diff --git a/src/kshortcutschemeseditor.cpp b/src/kshortcutschemeseditor.cpp --- a/src/kshortcutschemeseditor.cpp +++ b/src/kshortcutschemeseditor.cpp @@ -51,7 +51,8 @@ const QStringList shortcutsDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QCoreApplication::applicationName() + QLatin1String("/shortcuts"), QStandardPaths::LocateDirectory); qCDebug(DEBUG_KXMLGUI) << "shortcut scheme dirs:" << shortcutsDirs; for (const QString &dir : shortcutsDirs) { - Q_FOREACH (const QString &file, QDir(dir).entryList(QDir::Files | QDir::NoDotAndDotDot)) { + const auto files = QDir(dir).entryList(QDir::Files | QDir::NoDotAndDotDot); + for (const QString &file : files) { qCDebug(DEBUG_KXMLGUI) << "shortcut scheme file:" << file; schemes << file; } @@ -154,7 +155,8 @@ QFile::remove(KShortcutSchemesHelper::writableApplicationShortcutSchemeFileName(currentScheme())); //delete all scheme files we can find for xmlguiclients in the user directories - foreach (KActionCollection *collection, m_dialog->actionCollections()) { + const auto dialogCollections = m_dialog->actionCollections(); + for (KActionCollection *collection : dialogCollections) { const KXMLGUIClient *client = collection->parentGUIClient(); if (!client) { continue; diff --git a/src/kshortcutschemeshelper.cpp b/src/kshortcutschemeshelper.cpp --- a/src/kshortcutschemeshelper.cpp +++ b/src/kshortcutschemeshelper.cpp @@ -57,7 +57,8 @@ collectionsByClientName.insertMulti(key, coll); } } - foreach (const QString &componentName, collectionsByClientName.uniqueKeys()) { + const auto componentNames = collectionsByClientName.uniqueKeys(); + for (const QString &componentName : componentNames) { qCDebug(DEBUG_KXMLGUI) << "Considering component" << componentName; QDomDocument doc; @@ -68,10 +69,12 @@ QDomElement elem = doc.createElement(QStringLiteral("ActionProperties")); docElem.appendChild(elem); - foreach (KActionCollection *collection, collectionsByClientName.values(componentName)) { + const auto componentCollections = collectionsByClientName.values(componentName); + for (KActionCollection *collection : componentCollections) { qCDebug(DEBUG_KXMLGUI) << "Saving shortcut scheme for action collection with" << collection->actions().count() << "actions"; - foreach (QAction *action, collection->actions()) { + const auto collectionActions = collection->actions(); + for (QAction *action : collectionActions) { if (!action) { continue; } diff --git a/src/kshortcutseditor.cpp b/src/kshortcutseditor.cpp --- a/src/kshortcutseditor.cpp +++ b/src/kshortcutseditor.cpp @@ -133,16 +133,18 @@ const QList categories = collection->findChildren(); for (KActionCategory *category : categories) { hier[KShortcutsEditorPrivate::Action] = d->findOrMakeItem(hier[KShortcutsEditorPrivate::Program], category->text()); - foreach (QAction *action, category->actions()) { + const auto categoryActions = category->actions(); + for (QAction *action : categoryActions) { // Set a marker that we have seen this action actionsSeen.insert(action); d->addAction(action, hier, KShortcutsEditorPrivate::Action); } } // The rest of the shortcuts is added as a direct shild of the action // collections root node - foreach (QAction *action, collection->actions()) { + const auto collectionActions = collection->actions(); + for (QAction *action : collectionActions) { if (actionsSeen.contains(action)) { continue; } diff --git a/src/ktoolbar.cpp b/src/ktoolbar.cpp --- a/src/ktoolbar.cpp +++ b/src/ktoolbar.cpp @@ -320,7 +320,8 @@ contextBottom = contextOrient->addAction(i18nc("toolbar position string", "Bottom"), q, SLOT(slotContextBottom())); QActionGroup *positionGroup = new QActionGroup(contextOrient); - Q_FOREACH (QAction *action, contextOrient->actions()) { + const auto orientActions = contextOrient->actions(); + for (QAction *action : orientActions) { action->setActionGroup(positionGroup); action->setCheckable(true); } @@ -333,7 +334,8 @@ contextTextUnder = contextMode->addAction(i18n("Text Under Icons"), q, SLOT(slotContextTextUnder())); QActionGroup *textGroup = new QActionGroup(contextMode); - Q_FOREACH (QAction *action, contextMode->actions()) { + const auto modeActions = contextMode->actions(); + for (QAction *action : modeActions) { action->setActionGroup(textGroup); action->setCheckable(true); } @@ -396,7 +398,8 @@ } QActionGroup *sizeGroup = new QActionGroup(contextSize); - Q_FOREACH (QAction *action, contextSize->actions()) { + const auto sizeActions = contextSize->actions(); + for (QAction *action : sizeActions) { action->setActionGroup(sizeGroup); action->setCheckable(true); } @@ -1096,8 +1099,9 @@ stream >> actionNames; + const auto allCollections = KActionCollection::allCollections(); for (const QString &actionName : qAsConst(actionNames)) { - Q_FOREACH (KActionCollection *ac, KActionCollection::allCollections()) { + for (KActionCollection *ac : allCollections) { QAction *newAction = ac->action(actionName); if (newAction) { d->actionsBeingDragged.append(newAction); @@ -1133,7 +1137,8 @@ if (d->dropIndicatorAction) { QAction *overAction = nullptr; - Q_FOREACH (QAction *action, actions()) { + const auto actions = this->actions(); + for (QAction *action : actions) { // want to make it feel that half way across an action you're dropping on the other side of it QWidget *widget = widgetForAction(action); if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) { @@ -1144,9 +1149,9 @@ if (overAction != d->dropIndicatorAction) { // Check to see if the indicator is already in the right spot - int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction); - if (dropIndicatorIndex + 1 < actions().count()) { - if (actions().at(dropIndicatorIndex + 1) == overAction) { + int dropIndicatorIndex = actions.indexOf(d->dropIndicatorAction); + if (dropIndicatorIndex + 1 < actions.count()) { + if (actions.at(dropIndicatorIndex + 1) == overAction) { break; } } else if (!overAction) { @@ -1290,7 +1295,8 @@ if (!this->isAncestorOf(ww)) { // New parent is not a subwidget - remove event filter ww->removeEventFilter(this); - Q_FOREACH (QWidget *child, ww->findChildren()) { + const auto children = ww->findChildren(); + for (QWidget *child : children) { child->removeEventFilter(this); } } @@ -1338,7 +1344,8 @@ if (widget) { widget->removeEventFilter(this); - Q_FOREACH (QWidget *child, widget->findChildren()) { + const auto children = widget->findChildren(); + for (QWidget *child : children) { child->removeEventFilter(this); } } @@ -1351,7 +1358,8 @@ if (widget) { widget->installEventFilter(this); - Q_FOREACH (QWidget *child, widget->findChildren()) { + const auto children = widget->findChildren(); + for (QWidget *child : children) { child->installEventFilter(this); } // Center widgets that do not have any use for more space. See bug 165274 @@ -1386,8 +1394,10 @@ if (KToolBar::Private::s_locked != locked) { KToolBar::Private::s_locked = locked; - Q_FOREACH (KMainWindow *mw, KMainWindow::memberList()) { - Q_FOREACH (KToolBar *toolbar, mw->findChildren()) { + const auto windows = KMainWindow::memberList(); + for (KMainWindow *mw : windows) { + const auto toolbars = mw->findChildren(); + for (KToolBar *toolbar : toolbars) { toolbar->d->setLocked(locked); } } diff --git a/src/kxmlguifactory.cpp b/src/kxmlguifactory.cpp --- a/src/kxmlguifactory.cpp +++ b/src/kxmlguifactory.cpp @@ -283,7 +283,8 @@ emit clientAdded(client); // build child clients - Q_FOREACH (KXMLGUIClient *child, client->childClients()) { + const auto children = client->childClients(); + for (KXMLGUIClient *child : children) { addClient(child); } diff --git a/src/kxmlguiwindow.cpp b/src/kxmlguiwindow.cpp --- a/src/kxmlguiwindow.cpp +++ b/src/kxmlguiwindow.cpp @@ -404,9 +404,11 @@ QMap shortcuts; QAction *editCutAction = actionCollection()->action(QStringLiteral("edit_cut")); QAction *deleteFileAction = actionCollection()->action(QStringLiteral("deletefile")); - foreach (QAction *action, actionCollection()->actions()) { + const auto actions = actionCollection()->actions(); + for (QAction *action : actions) { if (action->isEnabled()) { - foreach (const QKeySequence &shortcut, action->shortcuts()) { + const auto actionShortcuts = action->shortcuts(); + for (const QKeySequence &shortcut : actionShortcuts) { if (shortcut.isEmpty()) { continue; }