Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static check fixes #43

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/core/export/qmlexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/export/scxmlexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/export/svgexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StateMachine *>(child)) {
if (!writeStateMachine(machine))
return false;
Expand Down
7 changes: 4 additions & 3 deletions src/core/layout/graphvizlayout/graphvizlayerlayouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *>(state))) {
for (const auto &kv : attributesForState(qobject_cast<State *>(state))) {
_agset(newNode, QString::fromLatin1(kv.first), QString::fromLatin1(kv.second));
}
}
Expand All @@ -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
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/layout/layoutimportexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/core/layout/layoututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/core/model/elementutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PseudoState *>(child)) {
if (pseudoState->kind() == PseudoState::InitialState) {
Transition *transition = pseudoState->transitions().value(0);
Expand All @@ -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<PseudoState *>(child)) {
if (pseudoState->kind() == PseudoState::InitialState) {
pseudoStateName = pseudoState->label();
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/core/model/runtimecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/core/tests/test_layouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -66,16 +66,16 @@ 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");
}
}

static void assertRegionContainsStates(State *region, const QList<State *> states)
static void assertRegionContainsStates(State *region, const QList<State *> &states)
{
const QRectF rect = region->boundingRect();
foreach (State *item, states) {
for (const State *item : states) {
QVERIFY(rect.contains(item->boundingRect()));
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/tests/test_layoutinformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/objecthelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ QString ObjectHelper::addressToString(const void *p)
QString ObjectHelper::className(const QObject *object, ObjectHelper::DisplayOption option)
{
QString className = QString::fromLatin1(object->metaObject()->className());
return option == StripNameSpace ? stripNameSpace(className) : className;
return option == StripNameSpace ? stripNameSpace(className) : std::move(className);
}

QString ObjectHelper::displayString(const QObject *object, DisplayOption option)
Expand Down
4 changes: 2 additions & 2 deletions src/core/util/objecthelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ KDSME_CORE_EXPORT int depth(const QObject *root, const QObject *object);
* Returns a list that only contains item of type @p FilterType
*/
template<class FilterType, class ItemType>
QList<FilterType> copy_if_type(const QList<ItemType> list)
QList<FilterType> copy_if_type(const QList<ItemType> &list)
{
QList<FilterType> filteredList;
Q_FOREACH (const ItemType object, list) {
for (const ItemType &object : list) {
if (FilterType filterObject = qobject_cast<FilterType>(object))
filteredList << filterObject;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/objecttreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void ObjectTreeModel::setRootObjects(const QList<QObject *> &rootObjects)
Q_D(ObjectTreeModel);
beginResetModel();
d->m_rootObjects.clear();
foreach (QObject *object, rootObjects) {
for (QObject *object : rootObjects) {
if (object)
d->m_rootObjects << object;
}
Expand Down
6 changes: 4 additions & 2 deletions src/view/widgets/propertyeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion src/view/widgets/statemachinetoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]() {
Expand Down
2 changes: 1 addition & 1 deletion src/view/widgets/statemachineview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void StateMachineView::setThemeName(const QString &themeName)
}
}

d->m_themeName = selectedThemeName;
d->m_themeName = std::move(selectedThemeName);
emit themeNameChanged(d->m_themeName);
}

Expand Down