diff --git a/autotests/src/vimode/emulatedcommandbar.cpp b/autotests/src/vimode/emulatedcommandbar.cpp --- a/autotests/src/vimode/emulatedcommandbar.cpp +++ b/autotests/src/vimode/emulatedcommandbar.cpp @@ -3113,8 +3113,8 @@ // Find the "Print" action for later use. QAction *printAction = nullptr; - foreach(QAction* action, kate_view->actionCollection()->actions()) - { + const auto viewActions = kate_view->actionCollection()->actions(); + for (QAction* action : viewActions) { if (action->shortcut() == QKeySequence("Ctrl+p")) { printAction = action; diff --git a/src/completion/katecompletionwidget.cpp b/src/completion/katecompletionwidget.cpp --- a/src/completion/katecompletionwidget.cpp +++ b/src/completion/katecompletionwidget.cpp @@ -214,7 +214,8 @@ } int realItemCount = 0; - foreach (KTextEditor::CodeCompletionModel *model, m_presentationModel->completionModels()) { + const auto completionModels = m_presentationModel->completionModels(); + for (KTextEditor::CodeCompletionModel *model : completionModels) { realItemCount += model->rowCount(); } if (!m_isSuspended && ((isHidden() && m_argumentHintTree->isHidden()) || m_needShow) && realItemCount != 0) { diff --git a/src/dialogs/katedialogs.cpp b/src/dialogs/katedialogs.cpp --- a/src/dialogs/katedialogs.cpp +++ b/src/dialogs/katedialogs.cpp @@ -348,7 +348,8 @@ KateDocumentConfig::global()->setOnTheFlySpellCheck(settings.value(QStringLiteral("checkerEnabledByDefault"), false).toBool()); KateDocumentConfig::global()->configEnd(); - foreach (KTextEditor::DocumentPrivate *doc, KTextEditor::EditorPrivate::self()->kateDocuments()) { + const auto docs = KTextEditor::EditorPrivate::self()->kateDocuments(); + for (KTextEditor::DocumentPrivate *doc : docs) { doc->refreshOnTheFlyCheck(); } } @@ -590,7 +591,8 @@ observeChanges(spellCheckConfigTab); int i = tabWidget->count(); - Q_FOREACH(KateAbstractInputModeFactory *factory, KTextEditor::EditorPrivate::self()->inputModeFactories()) { + const auto inputModeFactories = KTextEditor::EditorPrivate::self()->inputModeFactories(); + for (KateAbstractInputModeFactory *factory : inputModeFactories) { KateConfigPage *tab = factory->createConfigPage(this); if (tab) { m_inputModeConfigTabs << tab; diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -4233,7 +4233,8 @@ int count = -1; - foreach (KTextEditor::DocumentPrivate *doc, KTextEditor::EditorPrivate::self()->kateDocuments()) { + const auto docs = KTextEditor::EditorPrivate::self()->kateDocuments(); + for (KTextEditor::DocumentPrivate *doc : docs) { if ((doc != this) && (doc->url().fileName() == url().fileName())) if (doc->m_docNameNumber > count) { count = doc->m_docNameNumber; @@ -6051,7 +6052,8 @@ m_messageHash[message] = QList >(); // reparent actions, as we want full control over when they are deleted - foreach (QAction *action, message->actions()) { + const auto messageActions = message->actions(); + for (QAction *action : messageActions) { action->setParent(nullptr); m_messageHash[message].append(QSharedPointer(action)); } diff --git a/src/mode/katemodemanager.cpp b/src/mode/katemodemanager.cpp --- a/src/mode/katemodemanager.cpp +++ b/src/mode/katemodemanager.cpp @@ -183,7 +183,8 @@ newg << type->name; } - foreach (const QString &groupName, katerc.groupList()) { + const auto groupNames = katerc.groupList(); + for (const QString &groupName : groupNames) { if (newg.indexOf(groupName) == -1) { katerc.deleteGroup(groupName); } diff --git a/src/printing/printconfigwidgets.cpp b/src/printing/printconfigwidgets.cpp --- a/src/printing/printconfigwidgets.cpp +++ b/src/printing/printconfigwidgets.cpp @@ -549,7 +549,8 @@ sbBoxMargin->setValue(6); gbBoxProps->setEnabled(false); - Q_FOREACH (const KateSchema &schema, KTextEditor::EditorPrivate::self()->schemaManager()->list()) { + const auto schemas = KTextEditor::EditorPrivate::self()->schemaManager()->list(); + for (const KateSchema &schema : schemas) { cmbSchema->addItem(schema.translatedName(), QVariant(schema.rawName)); } diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -848,7 +848,8 @@ color = m_caretOverrideColor; } else { // search for the FormatRange that includes the cursor - foreach (const QTextLayout::FormatRange &r, range->layout()->additionalFormats()) { + const auto formatRanges = range->layout()->additionalFormats(); + for (const QTextLayout::FormatRange &r : formatRanges) { if ((r.start <= cursor->column()) && ((r.start + r.length) > cursor->column())) { // check for Qt::NoBrush, as the returned color is black() and no invalid QColor QBrush foregroundBrush = r.format.foreground(); diff --git a/src/schema/kateschema.cpp b/src/schema/kateschema.cpp --- a/src/schema/kateschema.cpp +++ b/src/schema/kateschema.cpp @@ -64,7 +64,8 @@ QList KateSchemaManager::list() { QList schemas; - Q_FOREACH (QString s, m_config.groupList()) { + const auto names = m_config.groupList(); + for (const QString &s : names) { schemas.append(schemaData(s)); } @@ -119,7 +120,8 @@ } QString id = view->renderer()->config()->schema(); - foreach (QAction *a, menu()->actions()) { + const auto menuActions = menu()->actions(); + for (QAction *a : menuActions) { a->setChecked(a->data().toString() == id); } diff --git a/src/script/katescriptmanager.cpp b/src/script/katescriptmanager.cpp --- a/src/script/katescriptmanager.cpp +++ b/src/script/katescriptmanager.cpp @@ -94,7 +94,8 @@ { QStringList list; - Q_FOREACH (const QJsonValue &value, value.toArray()) { + const auto array = value.toArray(); + for (const QJsonValue &value : array) { if (value.isString()) { list.append(value.toString()); } @@ -131,7 +132,8 @@ // then all other locations, this includes global stuff installed by other applications // this will not allow global stuff to overwrite the stuff we ship in our resources to allow to install a more up-to-date ktexteditor lib locally! - foreach (const QString &dir, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) { + const auto genericDataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + for (const QString &dir : genericDataDirs) { dirs.append(dir + basedir); } diff --git a/src/spellcheck/ontheflycheck.cpp b/src/spellcheck/ontheflycheck.cpp --- a/src/spellcheck/ontheflycheck.cpp +++ b/src/spellcheck/ontheflycheck.cpp @@ -80,7 +80,8 @@ // load the settings for the speller updateConfig(); - foreach (KTextEditor::View *view, document->views()) { + const auto views = document->views(); + for (KTextEditor::View *view : views) { addView(document, view); } refreshSpellCheck(); @@ -155,7 +156,8 @@ return; } // for performance reasons we only want to schedule spellchecks for ranges that are visible - foreach (KTextEditor::View *i, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *i : views) { KTextEditor::ViewPrivate *view = static_cast(i); KTextEditor::Range visibleIntersection = documentIntersection.intersect(view->visibleRange()); if (visibleIntersection.isValid()) { // allow empty intersections @@ -245,7 +247,8 @@ } // for performance reasons we only want to schedule spellchecks for ranges that are visible - foreach (KTextEditor::View *i, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *i : views) { KTextEditor::ViewPrivate *view = static_cast(i); KTextEditor::Range visibleIntersection = documentIntersection.intersect(view->visibleRange()); if (visibleIntersection.isValid()) { // see above @@ -542,7 +545,8 @@ // remove it from all our structures removeRangeFromEverything(range); range->setFeedback(nullptr); - foreach (KTextEditor::View *view, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *view : views) { static_cast(view)->spellingMenu()->rangeDeleted(range); } delete(range); @@ -731,7 +735,8 @@ KTextEditor::MovingRange *movingRange = item.first; if (!movingRange->overlaps(newDisplayRange)) { bool stillVisible = false; - foreach (KTextEditor::View *it2, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *it2 : views) { KTextEditor::ViewPrivate *view2 = static_cast(it2); if (view != view2 && movingRange->overlaps(view2->visibleRange())) { stillVisible = true; @@ -750,7 +755,8 @@ for (int line = newDisplayRange.end().line(); line >= newDisplayRange.start().line(); --line) { if (!oldDisplayRange.containsLine(line)) { bool visible = false; - foreach (KTextEditor::View *it2, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *it2 : views) { KTextEditor::ViewPrivate *view2 = static_cast(it2); if (view != view2 && view2->visibleRange().containsLine(line)) { visible = true; @@ -887,7 +893,8 @@ void KateOnTheFlyChecker::deleteMovingRangeQuickly(KTextEditor::MovingRange *range) { range->setFeedback(nullptr); - foreach (KTextEditor::View *view, m_document->views()) { + const auto views = m_document->views(); + for (KTextEditor::View *view : views) { static_cast(view)->spellingMenu()->rangeDeleted(range); } delete(range); diff --git a/src/utils/kateautoindent.cpp b/src/utils/kateautoindent.cpp --- a/src/utils/kateautoindent.cpp +++ b/src/utils/kateautoindent.cpp @@ -468,7 +468,8 @@ const QStringList modes = KateAutoIndent::listModes(); menu()->clear(); - foreach (QAction *action, actionGroup->actions()) { + const auto actions = actionGroup->actions(); + for (QAction *action : actions) { actionGroup->removeAction(action); } for (int z = 0; z < modes.size(); ++z) { diff --git a/src/utils/kateconfig.cpp b/src/utils/kateconfig.cpp --- a/src/utils/kateconfig.cpp +++ b/src/utils/kateconfig.cpp @@ -601,7 +601,8 @@ } if (isGlobal()) { - foreach (KTextEditor::ViewPrivate* view, KTextEditor::EditorPrivate::self()->views()) { + const auto allViews = KTextEditor::EditorPrivate::self()->views(); + for (KTextEditor::ViewPrivate* view : allViews) { view->updateConfig(); } @@ -783,7 +784,8 @@ { if (isGlobal()) { setSchemaInternal(m_schema); - foreach (KTextEditor::ViewPrivate *view, KTextEditor::EditorPrivate::self()->views()) { + const auto allViews = KTextEditor::EditorPrivate::self()->views(); + for (KTextEditor::ViewPrivate *view : allViews) { view->renderer()->config()->reloadSchema(); } } diff --git a/src/utils/katetemplatehandler.cpp b/src/utils/katetemplatehandler.cpp --- a/src/utils/katetemplatehandler.cpp +++ b/src/utils/katetemplatehandler.cpp @@ -92,7 +92,8 @@ } // only do complex stuff when required if ( have_editable_field ) { - foreach (View *view, doc()->views()) { + const auto views = doc()->views(); + for (View *view : views) { setupEventHandler(view); } diff --git a/src/variableeditor/variablelineedit.cpp b/src/variableeditor/variablelineedit.cpp --- a/src/variableeditor/variablelineedit.cpp +++ b/src/variableeditor/variablelineedit.cpp @@ -303,7 +303,9 @@ // Add 'scheme' to list QStringList schemas; - Q_FOREACH (const KateSchema &schema, KTextEditor::EditorPrivate::self()->schemaManager()->list()) { + const auto schemaList = KTextEditor::EditorPrivate::self()->schemaManager()->list(); + schemas.reserve(schemaList.size()); + for (const KateSchema &schema : schemaList) { schemas.append(schema.rawName); } item = new VariableStringListItem(QStringLiteral("scheme"), schemas, rendererConfig->schema()); diff --git a/src/view/katemessagewidget.cpp b/src/view/katemessagewidget.cpp --- a/src/view/katemessagewidget.cpp +++ b/src/view/katemessagewidget.cpp @@ -114,12 +114,14 @@ } // remove all actions from the message widget - foreach (QAction *a, m_messageWidget->actions()) { + const auto messageWidgetActions = m_messageWidget->actions(); + for (QAction *a : messageWidgetActions) { m_messageWidget->removeAction(a); } // add new actions to the message widget - foreach (QAction *a, m_currentMessage->actions()) { + const auto m_currentMessageActions = m_currentMessage->actions(); + for (QAction *a : m_currentMessageActions) { m_messageWidget->addAction(a); } diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -887,7 +887,8 @@ ac->addAssociatedWidget(m_viewInternal); - foreach (QAction *action, ac->actions()) { + const auto actions = ac->actions(); + for (QAction *action : actions) { action->setShortcutContext(Qt::WidgetWithChildrenShortcut); } @@ -1411,7 +1412,8 @@ config()->setValue(KateViewConfig::InputMode, mode); // TODO: this could be called from read config procedure, so it's not a good idea to set a specific view mode here /* small duplication, but need to do this if not toggled by action */ - Q_FOREACH(QAction *action, m_inputModeActions->actions()) { + const auto inputModeActions = m_inputModeActions->actions(); + for (QAction *action : inputModeActions) { if (static_cast(action->data().toInt()) == mode) { action->setChecked(true); break; diff --git a/src/view/kateviewhelpers.cpp b/src/view/kateviewhelpers.cpp --- a/src/view/kateviewhelpers.cpp +++ b/src/view/kateviewhelpers.cpp @@ -2712,7 +2712,8 @@ q->setToolBarMode(MenuMode); int i; - foreach (const QStringList &encodingsForScript, KCharsets::charsets()->encodingsByScript()) { + const auto encodingsByScript = KCharsets::charsets()->encodingsByScript(); + for (const QStringList &encodingsForScript : encodingsByScript) { KSelectAction *tmp = new KSelectAction(encodingsForScript.at(0), q); for (i = 1; i < encodingsForScript.size(); ++i) { diff --git a/src/vimode/appcommands.cpp b/src/vimode/appcommands.cpp --- a/src/vimode/appcommands.cpp +++ b/src/vimode/appcommands.cpp @@ -72,7 +72,8 @@ QRegularExpressionMatch match; if ((match = re_write.match(command)).hasMatch()) { //TODO: handle writing to specific file if (!match.captured(1).isEmpty()) { // [a]ll - Q_FOREACH(KTextEditor::Document *doc, app->documents()) { + const auto docs = app->documents(); + for (KTextEditor::Document *doc : docs) { doc->save(); } msg = i18n("All documents written to disk"); @@ -91,13 +92,15 @@ if (allDocuments) { if (save) { - Q_FOREACH(KTextEditor::Document *doc, app->documents()) { + const auto docs = app->documents(); + for (KTextEditor::Document *doc : docs) { doc->save(); } } if (doNotPromptForSave) { - Q_FOREACH(KTextEditor::Document *doc, app->documents()) { + const auto docs = app->documents(); + for (KTextEditor::Document *doc : docs) { if (doc->isModified()) { doc->setModified(false); } @@ -126,7 +129,8 @@ } } else if ((match = re_exit.match(command)).hasMatch()) { if (!match.captured(1).isEmpty()) { // a[ll] - Q_FOREACH(KTextEditor::Document *doc, app->documents()) { + const auto docs = app->documents(); + for (KTextEditor::Document *doc : docs) { doc->save(); } QTimer::singleShot(0, this, SLOT(quit())); @@ -280,7 +284,8 @@ KTextEditor::View * AppCommands::findViewInDifferentSplitView(KTextEditor::MainWindow *window, KTextEditor::View *view) { - Q_FOREACH (KTextEditor::View *it, window->views()) { + const auto views = window->views(); + for (KTextEditor::View *it : views) { if (!window->viewsInSameSplitView(it, view)) { return it; } diff --git a/src/vimode/keymapper.cpp b/src/vimode/keymapper.cpp --- a/src/vimode/keymapper.cpp +++ b/src/vimode/keymapper.cpp @@ -94,7 +94,9 @@ bool isPartialMapping = false; bool isFullMapping = false; m_fullMappingMatch.clear(); - foreach (const QString &mapping, m_viInputModeManager->globalState()->mappings()->getAll(Mappings::mappingModeForCurrentViMode(m_viInputModeManager->inputAdapter()), false, true)) { + const auto mappingMode = Mappings::mappingModeForCurrentViMode(m_viInputModeManager->inputAdapter()); + const auto mappings = m_viInputModeManager->globalState()->mappings()->getAll(mappingMode, false, true); + for (const QString &mapping : mappings) { if (mapping.startsWith(m_mappingKeys)) { if (mapping == m_mappingKeys) { isFullMapping = true; diff --git a/src/vimode/mappings.cpp b/src/vimode/mappings.cpp --- a/src/vimode/mappings.cpp +++ b/src/vimode/mappings.cpp @@ -46,7 +46,10 @@ config.writeEntry(mappingModeName + QLatin1String(" Mode Mapping Keys"), getAll(mappingMode, true)); QStringList l; QList recursives; - foreach (const QString &s, getAll(mappingMode)) { + const auto all = getAll(mappingMode); + l.reserve(all.size()); + recursives.reserve(all.size()); + for (const QString &s : all) { l << KeyParser::self()->decodeKeySequence(get(mappingMode, s)); recursives << isRecursive(mappingMode, s); } diff --git a/src/vimode/modes/modebase.cpp b/src/vimode/modes/modebase.cpp --- a/src/vimode/modes/modebase.cpp +++ b/src/vimode/modes/modebase.cpp @@ -1232,9 +1232,9 @@ void ModeBase::switchView(Direction direction) { - QList visible_views; - foreach (KTextEditor::ViewPrivate *view, KTextEditor::EditorPrivate::self()->views()) { + const auto views = KTextEditor::EditorPrivate::self()->views(); + for (KTextEditor::ViewPrivate *view : views) { if (view->isVisible()) { visible_views.push_back(view); }