diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 63c100fc..c7511102 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -88,9 +88,9 @@ void MainWindow::loadPresets(const QString &presetsDir) qWarning() << "Non-existent presets location:" << presetsDir; } - QStringList files = dir.entryList(QDir::Files); - foreach (const QString &file, files) { - if (!file.endsWith(QLatin1String(".scxml"))) + const QStringList files = dir.entryList(QDir::Files); + for (const QString &file : files) { + if (!file.endsWith(u".scxml")) continue; QStandardItem *item = new QStandardItem(file); diff --git a/src/core/export/qmlexporter.cpp b/src/core/export/qmlexporter.cpp index c6b7c1b0..32ed03c7 100644 --- a/src/core/export/qmlexporter.cpp +++ b/src/core/export/qmlexporter.cpp @@ -186,7 +186,7 @@ bool QmlExporter::Private::writeStateMachine(StateMachine *machine) m_out << indention() << importStmt; const QStringList customImports = machine->property("com.kdab.KDSME.DSMExporter.customImports").toStringList(); - foreach (const QString &customImport, customImports) + for (const QString &customImport : customImports) m_out << customImport << '\n'; m_out << '\n'; @@ -264,12 +264,14 @@ bool QmlExporter::Private::writeStateInner(State *state) writeAttribute(state, QStringLiteral("onEntered"), state->onEntry()); writeAttribute(state, QStringLiteral("onExited"), state->onExit()); - foreach (State *child, state->childStates()) { + const auto childStates = state->childStates(); + for (State *child : childStates) { if (!writeState(child)) return false; } - foreach (Transition *transition, state->transitions()) { + const auto stateTransitions = state->transitions(); + for (Transition *transition : stateTransitions) { if (!writeTransition(transition)) return false; } diff --git a/src/core/export/scxmlexporter.cpp b/src/core/export/scxmlexporter.cpp index d9da8730..c08feadd 100644 --- a/src/core/export/scxmlexporter.cpp +++ b/src/core/export/scxmlexporter.cpp @@ -144,12 +144,14 @@ bool ScxmlExporter::Private::writeStateInner(State *state) m_writer.writeAttribute(QStringLiteral("initial"), initial->label()); } - foreach (Transition *transition, state->transitions()) { + const auto stateTransitions = state->transitions(); + for (Transition *transition : stateTransitions) { if (!writeTransition(transition)) return false; } - foreach (State *child, state->childStates()) { + const auto childStates = state->childStates(); + for (State *child : childStates) { if (!writeState(child)) return false; } diff --git a/src/core/export/svgexporter.cpp b/src/core/export/svgexporter.cpp index ab58967d..34267a73 100644 --- a/src/core/export/svgexporter.cpp +++ b/src/core/export/svgexporter.cpp @@ -218,13 +218,15 @@ bool SvgExporterPrivate::writeStateInner(State *state) writer.writeStartElement(QStringLiteral("g")); writer.writeAttribute(QStringLiteral("transform"), QStringLiteral("translate(%1,%2)").arg(state->boundingRect().x()).arg(state->boundingRect().y())); - foreach (Transition *transition, state->transitions()) { + const auto stateTransitions = state->transitions(); + for (Transition *transition : stateTransitions) { if (!writeTransition(transition)) return false; } if (state->isExpanded()) { - foreach (State *child, state->childStates()) { + const auto childStates = state->childStates(); + for (State *child : childStates) { if (auto machine = qobject_cast(child)) { if (!writeStateMachine(machine)) return false; diff --git a/src/core/layout/graphvizlayout/graphvizlayerlayouter.cpp b/src/core/layout/graphvizlayout/graphvizlayerlayouter.cpp index 695f63ba..5847149c 100644 --- a/src/core/layout/graphvizlayout/graphvizlayerlayouter.cpp +++ b/src/core/layout/graphvizlayout/graphvizlayerlayouter.cpp @@ -46,12 +46,13 @@ QRectF GraphvizLayerLayouter::layout(State *state, const LayoutProperties *prope // Step 1: Create Graphviz structures out of the State/Transition tree // Step 1.1: build nodes - foreach (State *state, childStates) { + for (State *state : childStates) { m_backend->buildState(state); } // Step 1.2: build edges - foreach (State *state, childStates) { - foreach (Transition *transition, state->transitions()) { + for (State *state : childStates) { + const auto stateTransitions = state->transitions(); + for (Transition *transition : stateTransitions) { // TODO: What to do with transitions crossing hierarchies? if (!childStates.contains(transition->targetState())) { continue; // ignore for now diff --git a/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp b/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp index b756597e..a0742a12 100644 --- a/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp +++ b/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp @@ -226,7 +226,7 @@ void GraphvizLayouterBackend::Private::buildState(State *state, Agraph_t *graph) _agset(newNode, QStringLiteral("label"), state->label()); } - foreach (const auto &kv, attributesForState(qobject_cast(state))) { + for (const auto &kv : attributesForState(qobject_cast(state))) { _agset(newNode, QString::fromLatin1(kv.first), QString::fromLatin1(kv.second)); } } @@ -236,12 +236,14 @@ void GraphvizLayouterBackend::Private::buildTransitions(State *state, Agraph_t * { IF_DEBUG(qCDebug(KDSME_CORE) << state->label() << *state << graph); - foreach (Transition *transition, state->transitions()) { + const auto stateTransitions = state->transitions(); + for (Transition *transition : stateTransitions) { buildTransition(transition, graph); } if (m_layoutMode == RecursiveMode) { - foreach (State *childState, state->childStates()) { + const auto childStates = state->childStates(); + for (State *childState : childStates) { buildTransitions(childState, graph); // recursive call } } diff --git a/src/core/layout/layoutimportexport.cpp b/src/core/layout/layoutimportexport.cpp index 886125c0..c9832410 100644 --- a/src/core/layout/layoutimportexport.cpp +++ b/src/core/layout/layoutimportexport.cpp @@ -151,12 +151,14 @@ QJsonObject LayoutImportExport::exportLayout(const State *state) QJsonObject res = stateLayoutToJson(state); QJsonArray states; - foreach (State *child, state->childStates()) + const auto childStates = state->childStates(); + for (State *child : childStates) states.push_back(exportLayout(child)); res[u"childStates"] = states; QJsonArray transitions; - foreach (Transition *child, state->transitions()) + const auto stateTransitions = state->transitions(); + for (Transition *child : stateTransitions) transitions.push_back(transitionLayoutToJson(child)); res[u"transitions"] = transitions; diff --git a/src/core/layout/layoututils.cpp b/src/core/layout/layoututils.cpp index 3a8f02eb..bde9d320 100644 --- a/src/core/layout/layoututils.cpp +++ b/src/core/layout/layoututils.cpp @@ -43,7 +43,8 @@ bool LayoutUtils::moveInner(State *state, const QPointF &offset) return false; } - foreach (State *childState, state->childStates()) { + const auto childStates = state->childStates(); + for (State *childState : childStates) { childState->setPos(childState->pos() + offset); } return true; diff --git a/src/core/model/elementutil.cpp b/src/core/model/elementutil.cpp index ee1134f5..7e01609d 100644 --- a/src/core/model/elementutil.cpp +++ b/src/core/model/elementutil.cpp @@ -26,7 +26,8 @@ State *ElementUtil::findInitialState(const KDSME::State *state) if (!state) return nullptr; - foreach (State *child, state->childStates()) { + const auto childStates = state->childStates(); + for (State *child : childStates) { if (PseudoState *pseudoState = qobject_cast(child)) { if (pseudoState->kind() == PseudoState::InitialState) { Transition *transition = pseudoState->transitions().value(0); @@ -43,7 +44,8 @@ void ElementUtil::setInitialState(State *state, State *initialState) return; QString pseudoStateName, transitionName; - foreach (State *child, state->childStates()) { + const auto childStates = state->childStates(); + for (State *child : childStates) { if (PseudoState *pseudoState = qobject_cast(child)) { if (pseudoState->kind() == PseudoState::InitialState) { pseudoStateName = pseudoState->label(); @@ -80,7 +82,8 @@ State *ElementUtil::findState(State *root, const QString &label) if (label == root->label()) return root; - foreach (State *state, root->childStates()) + const auto childStates = root->childStates(); + for (State *state : childStates) if (State *st = findState(state, label)) return st; diff --git a/src/core/model/runtimecontroller.cpp b/src/core/model/runtimecontroller.cpp index 1e47950b..9cebd57b 100644 --- a/src/core/model/runtimecontroller.cpp +++ b/src/core/model/runtimecontroller.cpp @@ -52,11 +52,11 @@ struct RuntimeController::Private void RuntimeController::Private::updateActiveRegion() { - Configuration configuration = q->activeConfiguration(); + const Configuration configuration = q->activeConfiguration(); // Calculate the bounding rect of all states in that are currently active QRectF activeRegion; - foreach (State *state, configuration) { + for (State *state : configuration) { activeRegion = activeRegion.united(state->boundingRect()); } m_activeRegion = activeRegion; diff --git a/src/core/tests/test_layouter.cpp b/src/core/tests/test_layouter.cpp index bce182ff..b3b90f84 100644 --- a/src/core/tests/test_layouter.cpp +++ b/src/core/tests/test_layouter.cpp @@ -54,7 +54,7 @@ private Q_SLOTS: const State *reference = states[0]; const qreal referenceCenterY = reference->pos().y() + reference->height() / 2; - foreach (State *item, states) { + for (State *item : states) { const qreal centerY = item->pos().y() + item->height() / 2; QVERIFY2(qAbs(centerY - referenceCenterY) < epsilonY, "Not horizontally aligned"); } @@ -66,7 +66,7 @@ private Q_SLOTS: const State *reference = states[0]; const qreal referenceCenterX = reference->pos().x() + reference->width() / 2; - foreach (State *state, states) { + for (State *state : states) { const qreal centerX = state->pos().x() + state->width() / 2; QVERIFY2(qAbs(centerX - referenceCenterX) < epsilonX, "Not vertically aligned"); } diff --git a/src/core/tests/test_layoutinformation.cpp b/src/core/tests/test_layoutinformation.cpp index 5bed4585..23864c0c 100644 --- a/src/core/tests/test_layoutinformation.cpp +++ b/src/core/tests/test_layoutinformation.cpp @@ -47,14 +47,16 @@ void compare(const State *state1, const State *state2) QCOMPARE(state1->height(), state2->height()); auto copyChildren = state2->childStates(); - foreach (const State *child, state1->childStates()) { + const auto childStates = state1->childStates(); + for (const State *child : childStates) { auto copyChild = std::find_if(copyChildren.begin(), copyChildren.end(), [&child](State *state) -> bool { return state->label() == child->label(); }); if (copyChild != copyChildren.end()) compare(child, *copyChild); } auto copyTransitions = state2->transitions(); - foreach (const Transition *item, state1->transitions()) { + const auto state1Transitions = state1->transitions(); + for (const Transition *item : state1Transitions) { auto copyTransition = std::find_if(copyTransitions.begin(), copyTransitions.end(), [&item](Transition *state) -> bool { return state->label() == item->label(); }); if (copyTransition != copyTransitions.end()) { compare(item, *copyTransition); diff --git a/src/core/util/objecttreemodel.cpp b/src/core/util/objecttreemodel.cpp index d0724de9..53d58a15 100644 --- a/src/core/util/objecttreemodel.cpp +++ b/src/core/util/objecttreemodel.cpp @@ -207,7 +207,7 @@ void ObjectTreeModel::setRootObjects(const QList &rootObjects) Q_D(ObjectTreeModel); beginResetModel(); d->m_rootObjects.clear(); - foreach (QObject *object, rootObjects) { + for (QObject *object : rootObjects) { if (object) d->m_rootObjects << object; } diff --git a/src/view/widgets/propertyeditor.cpp b/src/view/widgets/propertyeditor.cpp index 4bf1eb41..7b922a71 100644 --- a/src/view/widgets/propertyeditor.cpp +++ b/src/view/widgets/propertyeditor.cpp @@ -167,7 +167,8 @@ static QStringList allStates(const State *state) if (!state->label().isEmpty()) ret << state->label(); - foreach (const State *st, state->childStates()) + const auto childStates = state->childStates(); + for (const State *st : childStates) ret << allStates(st); ret.removeDuplicates(); return ret; @@ -180,7 +181,8 @@ static QStringList childStates(const State *state) if (!state) return ret; - foreach (const State *st, state->childStates()) + const auto childStates = state->childStates(); + for (const State *st : childStates) if (!st->label().isEmpty()) ret << st->label(); diff --git a/src/view/widgets/statemachinetoolbar.cpp b/src/view/widgets/statemachinetoolbar.cpp index dc915860..9a8e71f3 100644 --- a/src/view/widgets/statemachinetoolbar.cpp +++ b/src/view/widgets/statemachinetoolbar.cpp @@ -90,7 +90,8 @@ StateMachineToolBar::StateMachineToolBar(StateMachineView *view, QWidget *parent themeSelectionButton->setText(tr("Theme")); themeSelectionButton->setPopupMode(QToolButton::InstantPopup); QMenu *themeSelectionMenu = new QMenu(themeSelectionButton); - foreach (const QString &themeName, availableThemeNames()) { + const auto themes = availableThemeNames(); + for (const QString &themeName : themes) { auto action = new QAction(themeName, this); action->setObjectName(QStringLiteral("action%1").arg(themeName)); connect(action, &QAction::triggered, this, [this, themeName]() {