From fcc8c3d3445514f549612b61274e837e341e87da Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sat, 4 Jan 2025 20:53:48 -0500 Subject: [PATCH] refactor: Action, dont use concatantaion, instead append --- src/apps/deskflow-gui/Action.cpp | 26 +++++++++++--------------- src/apps/deskflow-gui/Action.h | 1 + 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/apps/deskflow-gui/Action.cpp b/src/apps/deskflow-gui/Action.cpp index ba70f61d8..76ce7f940 100644 --- a/src/apps/deskflow-gui/Action.cpp +++ b/src/apps/deskflow-gui/Action.cpp @@ -31,51 +31,47 @@ const char *Action::m_lockCursorModeNames[] = {"toggle", "on", "off"}; QString Action::text() const { - QString text = QString(m_actionTypeNames[keySequence().isMouseButton() ? type() + 6 : type()]) + "("; + QString text = QString(m_actionTypeNames[keySequence().isMouseButton() ? type() + 6 : type()]); switch (type()) { case keyDown: case keyUp: case keystroke: { - text += keySequence().toString(); + QString commandArgs = keySequence().toString(); if (!keySequence().isMouseButton()) { const QStringList &screens = typeScreenNames(); if (haveScreens() && !screens.isEmpty()) { - text += ","; - + QString screenList; for (int i = 0; i < screens.size(); i++) { - text += screens[i]; + screenList.append(screens[i]); if (i != screens.size() - 1) - text += ":"; + screenList.append(QStringLiteral(":")); } + commandArgs.append(QStringLiteral(",%1").arg(screenList)); } else - text += ",*"; + commandArgs.append(QStringLiteral(",*")); } + text.append(m_commandTemplate.arg(commandArgs)); } break; case switchToScreen: - text += switchScreenName(); + text.append(m_commandTemplate.arg(m_switchScreenName)); break; case switchInDirection: - text += m_switchDirectionNames[m_switchDirection]; + text.append(m_commandTemplate.arg(m_switchDirectionNames[m_switchDirection])); break; case lockCursorToScreen: - text += m_lockCursorModeNames[m_lockCursorMode]; + text.append(m_commandTemplate.arg(m_lockCursorModeNames[m_lockCursorMode])); break; - case restartAllConnections: - text += "restart"; - break; default: Q_ASSERT(0); break; } - text += ")"; - return text; } diff --git a/src/apps/deskflow-gui/Action.h b/src/apps/deskflow-gui/Action.h index 2e030471d..8dd4c2425 100644 --- a/src/apps/deskflow-gui/Action.h +++ b/src/apps/deskflow-gui/Action.h @@ -175,6 +175,7 @@ private: static const char *m_actionTypeNames[]; static const char *m_switchDirectionNames[]; static const char *m_lockCursorModeNames[]; + inline static const QString m_commandTemplate = QStringLiteral("(%1)"); }; using ActionList = QList;