From 685b3974845ddf01c725faad8aa3673c127abea2 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Wed, 3 Jan 2024 16:32:07 -0300 Subject: [PATCH] Add stricter definitions in order to be included in other projects as submodule --- .github/workflows/build.yml | 6 +- .gitignore | 1 + CMakeLists.txt | 31 +++++---- docs/api/Doxyfile.cmake | 6 +- examples/export/main.cpp | 6 +- examples/layoutexport/main.cpp | 2 +- examples/qscxmldebugger/trafficlight.cpp | 2 +- examples/qsmdebugger/trafficlight.cpp | 8 +-- examples/scxmlimport/main.cpp | 2 +- examples/simplestatemachine/main.cpp | 4 +- src/app/main.cpp | 14 ++-- src/core/export/qmlexporter.cpp | 68 +++++++++---------- src/core/export/scxmlexporter.cpp | 28 ++++---- src/core/export/svgexporter.cpp | 20 +++--- src/core/import/scxmlimporter.cpp | 32 ++++----- src/core/kdsmeconstants.h | 2 +- .../graphvizlayouterbackend.cpp | 54 +++++++-------- .../graphvizlayouterbackend_p.h | 2 +- src/core/layout/graphvizlayout/gvutils.cpp | 2 +- src/core/layout/layoutimportexport.cpp | 68 +++++++++---------- src/core/model/element.cpp | 2 +- src/core/model/elementmodel.cpp | 4 +- src/core/model/elementutil.cpp | 4 +- src/core/model/state.cpp | 6 +- src/core/tests/test_layouter.cpp | 4 +- src/core/tests/test_layoutinformation.cpp | 24 +++---- src/core/tests/test_models.cpp | 8 +-- src/core/tests/test_qmlexport.cpp | 20 +++--- src/core/tests/test_qsmintegration.cpp | 8 +-- src/core/tests/test_scxmlexport.cpp | 10 +-- src/core/tests/test_scxmlimport.cpp | 14 ++-- src/core/tests/test_statemachine.cpp | 4 +- src/core/util/objecthelper.cpp | 13 ++-- src/core/util/objecttreemodel.cpp | 6 +- src/view/command/createelementcommand.cpp | 2 +- src/view/command/deleteelementcommand.cpp | 2 +- src/view/command/modifypropertycommand.cpp | 6 +- src/view/editcontroller.cpp | 6 +- src/view/quick/quickrecursiveinstantiator.cpp | 2 +- src/view/tests/test_commands.cpp | 6 +- src/view/widgets/codeeditor.cpp | 2 +- src/view/widgets/propertyeditor.cpp | 26 +++---- .../widgets/statemachinepalettewidget.cpp | 26 +++---- src/view/widgets/statemachinetoolbar.cpp | 12 ++-- src/view/widgets/statemachineview.cpp | 32 ++++----- 45 files changed, 305 insertions(+), 302 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65a3d67a..76b2cf35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,9 +19,9 @@ jobs: fail-fast: true matrix: os: - - ubuntu-22.04 - - windows-2022 - - macos-12 + - ubuntu-latest + - windows-latest + - macos-latest build_type: - Debug - Release diff --git a/.gitignore b/.gitignore index 6ca9aa03..ed631074 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # general +build*/ *.kdev4 *~ *.rej diff --git a/CMakeLists.txt b/CMakeLists.txt index 55650b54..83a60f33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,14 +48,19 @@ project( DESCRIPTION "A framework for creating Qt State Machine metacode using a graphical user interface" HOMEPAGE_URL "https://github.com/KDAB/KDStateMachineEditor" LANGUAGES CXX C + VERSION 1.99.50 +) + +add_definitions( + -DQT_NO_CAST_TO_ASCII + -DQT_NO_CAST_FROM_ASCII + -DQT_STRICT_ITERATORS + -DQT_NO_URL_CAST_FROM_STRING + -DQT_NO_CAST_FROM_BYTEARRAY + -DQT_USE_QSTRINGBUILDER + -DQT_USE_FAST_OPERATOR_PLUS ) -set(KDSME_VERSION_MAJOR "1") -set(KDSME_VERSION_MINOR "99") -set(KDSME_VERSION_PATCH "50") -set(KDSME_VERSION ${KDSME_VERSION_MAJOR}.${KDSME_VERSION_MINOR}.${KDSME_VERSION_PATCH}) -set(PROJECT_VERSION ${KDSME_VERSION}) #PROJECT_VERSION is needed by some ECM modules -set(${PROJECT_NAME}_SOVERSION ${KDSME_VERSION_MAJOR}) set(KDSME_SOVERSION "2") #means the 2.x ABI is frozen. ABI changes will must go to version 3 include(FeatureSummary) @@ -395,7 +400,7 @@ endif() if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) set(${PROJECT_NAME}_IS_ROOT_PROJECT TRUE) - message(STATUS "Building ${PROJECT_NAME} ${KDSME_VERSION} in ${CMAKE_BUILD_TYPE} mode. " + message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} in ${CMAKE_BUILD_TYPE} mode. " "Installing to ${CMAKE_INSTALL_PREFIX}" ) else() @@ -428,7 +433,7 @@ set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/${CONFIG_DIR}) # Generate library version files include(ECMSetupVersion) ecm_setup_version( - ${KDSME_VERSION} + ${PROJECT_VERSION} VARIABLE_PREFIX KDSME VERSION_HEADER @@ -465,16 +470,16 @@ if(${PROJECT_NAME}_IS_ROOT_PROJECT) set(README_FILE "README.md") #CPACK - set(CPACK_PACKAGE_VERSION_MAJOR "${KDSME_VERSION_MAJOR}") - set(CPACK_PACKAGE_VERSION_MINOR "${KDSME_VERSION_MINOR}") - set(CPACK_PACKAGE_VERSION_PATCH "${KDSME_VERSION_PATCH}") - set(CPACK_PACKAGE_VERSION "${KDSME_VERSION}") + set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") + set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") + set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") + set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") set(CPACK_PACKAGE_VENDOR "KDAB") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/${README_FILE}") if(WIN32) set(CPACK_GENERATOR "NSIS") set(CPACK_PACKAGE_INSTALL_DIRECTORY "KDStateMachineEditor") - set(CPACK_PACKAGE_FILE_NAME "KDStateMachineEditor-${KDSME_VERSION}") + set(CPACK_PACKAGE_FILE_NAME "KDStateMachineEditor-${PROJECT_VERSION}") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSES/${LICENSE_FILE}") set(CPACK_NSIS_EXECUTABLES_DIRECTORY "${BIN_INSTALL_DIR}") set(CPACK_NSIS_URL_INFO_ABOUT "https://www.kdab.com/") diff --git a/docs/api/Doxyfile.cmake b/docs/api/Doxyfile.cmake index ecae9c50..243671cb 100644 --- a/docs/api/Doxyfile.cmake +++ b/docs/api/Doxyfile.cmake @@ -38,7 +38,7 @@ PROJECT_NAME = "KDStateMachineEditor API Documentation" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = @KDSME_VERSION_MAJOR@.@KDSME_VERSION_MINOR@ +PROJECT_NUMBER = @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@ # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a @@ -1413,7 +1413,7 @@ QCH_FILE = "@DOXYGEN_OUTPUT_DIR@/qch/kdstatemachineeditor-api.qch" # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_NAMESPACE = com.kdab.KDStateMachineEditor.api.@KDSME_VERSION@ +QHP_NAMESPACE = com.kdab.KDStateMachineEditor.api.@PROJECT_VERSION@ # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual @@ -1422,7 +1422,7 @@ QHP_NAMESPACE = com.kdab.KDStateMachineEditor.api.@KDSME_VERSION@ # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_VIRTUAL_FOLDER = KDStateMachineEditor-@KDSME_VERSION@ +QHP_VIRTUAL_FOLDER = KDStateMachineEditor-@PROJECT_VERSION@ # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom diff --git a/examples/export/main.cpp b/examples/export/main.cpp index b21923b6..1e415afc 100644 --- a/examples/export/main.cpp +++ b/examples/export/main.cpp @@ -42,11 +42,11 @@ int main() //! [Construct the state machine] StateMachine machine; - machine.setLabel("root"); + machine.setLabel(QStringLiteral("root")); State s1(&machine); - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); State s2(&machine); - s2.setLabel("s2"); + s2.setLabel(QStringLiteral("s2")); s1.addSignalTransition(&s2); //! [Construct the state machine] diff --git a/examples/layoutexport/main.cpp b/examples/layoutexport/main.cpp index 8034e01b..da43710c 100644 --- a/examples/layoutexport/main.cpp +++ b/examples/layoutexport/main.cpp @@ -35,7 +35,7 @@ int main() QTextStream qErr(stderr); QTextStream qOut(stdout); - const QString fileName = TEST_DATA_DIR "/scxml/trafficlight_alternative.scxml"; + const QString fileName = QStringLiteral(TEST_DATA_DIR) + u"/scxml/trafficlight_alternative.scxml"; QFile file(fileName); if (!file.exists()) { qErr << "File does not exist:" << file.fileName(); diff --git a/examples/qscxmldebugger/trafficlight.cpp b/examples/qscxmldebugger/trafficlight.cpp index 66ed289e..aac506a5 100644 --- a/examples/qscxmldebugger/trafficlight.cpp +++ b/examples/qscxmldebugger/trafficlight.cpp @@ -127,7 +127,7 @@ TrafficLight::TrafficLight(QScxmlStateMachine *machine, QWidget *parent) void TrafficLight::toggleWorking(bool pause) { - m_machine->submitEvent(pause ? "smash" : "repair"); + m_machine->submitEvent(pause ? QStringLiteral("smash") : QStringLiteral("repair")); } LightWidget::LightWidget(const QString &image, QWidget *parent) diff --git a/examples/qsmdebugger/trafficlight.cpp b/examples/qsmdebugger/trafficlight.cpp index 9034aae2..3a631ceb 100644 --- a/examples/qsmdebugger/trafficlight.cpp +++ b/examples/qsmdebugger/trafficlight.cpp @@ -132,15 +132,15 @@ TrafficLight::TrafficLight(QWidget *parent) QStateMachine *machine = new QStateMachine(this); QState *redGoingYellow = createLightState(widget->redLight(), 3000); - redGoingYellow->setObjectName("redGoingYellow"); + redGoingYellow->setObjectName(QStringLiteral("redGoingYellow")); QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000); - yellowGoingGreen->setObjectName("yellowGoingGreen"); + yellowGoingGreen->setObjectName(QStringLiteral("yellowGoingGreen")); redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen); QState *greenGoingYellow = createLightState(widget->greenLight(), 3000); - greenGoingYellow->setObjectName("greenGoingYellow"); + greenGoingYellow->setObjectName(QStringLiteral("greenGoingYellow")); yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow); QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000); - yellowGoingRed->setObjectName("yellowGoingRed"); + yellowGoingRed->setObjectName(QStringLiteral("yellowGoingRed")); greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed); yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow); diff --git a/examples/scxmlimport/main.cpp b/examples/scxmlimport/main.cpp index 66178d89..b0f9ff03 100644 --- a/examples/scxmlimport/main.cpp +++ b/examples/scxmlimport/main.cpp @@ -34,7 +34,7 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - const QString fileName = TEST_DATA_DIR "/scxml/microwave.scxml"; + const QString fileName = QStringLiteral(TEST_DATA_DIR "/scxml/microwave.scxml"); QFile file(fileName); if (!file.exists()) { qWarning() << "File does not exist:" << file.fileName(); diff --git a/examples/simplestatemachine/main.cpp b/examples/simplestatemachine/main.cpp index a758f619..0ca56093 100644 --- a/examples/simplestatemachine/main.cpp +++ b/examples/simplestatemachine/main.cpp @@ -35,9 +35,9 @@ int main(int argc, char **argv) //! [Display the state machine] StateMachine machine; State s1(&machine); - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); State s2(&machine); - s2.setLabel("s2"); + s2.setLabel(QStringLiteral("s2")); s1.addSignalTransition(&s2); StateMachineView view; diff --git a/src/app/main.cpp b/src/app/main.cpp index 0ec3cf30..fc6e2d3f 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -31,7 +31,7 @@ namespace { QString presetsLocation() { - const QString presetsLocation = qgetenv("KDSME_PRESETS_LOCATION"); + const QString presetsLocation = qEnvironmentVariable("KDSME_PRESETS_LOCATION"); if (!presetsLocation.isEmpty()) { return presetsLocation; } @@ -40,7 +40,7 @@ QString presetsLocation() QString scxmlPresetsLocation() { - return presetsLocation() + "/scxml"; + return presetsLocation() + u"/scxml"; } } @@ -51,15 +51,15 @@ int main(int argc, char **argv) QQmlDebuggingEnabler enabler; QApplication app(argc, argv); - app.setOrganizationName("KDAB"); - app.setApplicationName("kdsme"); - app.setApplicationVersion("0.1"); + app.setOrganizationName(QStringLiteral("KDAB")); + app.setApplicationName(QStringLiteral("kdsme")); + app.setApplicationVersion(QStringLiteral("0.1")); QCommandLineParser parser; - parser.setApplicationDescription("State Machine Editor"); + parser.setApplicationDescription(QStringLiteral("State Machine Editor")); parser.addHelpOption(); parser.addVersionOption(); - parser.addPositionalArgument("source", QCoreApplication::translate("main", "SCXML file")); + parser.addPositionalArgument(QStringLiteral("source"), QCoreApplication::translate("main", "SCXML file")); parser.process(app); const QStringList args = parser.positionalArguments(); const QString source = args.value(0); diff --git a/src/core/export/qmlexporter.cpp b/src/core/export/qmlexporter.cpp index 84baf420..c6b7c1b0 100644 --- a/src/core/export/qmlexporter.cpp +++ b/src/core/export/qmlexporter.cpp @@ -30,8 +30,8 @@ using namespace KDSME; namespace { -const char KDSME_QML_MODULE[] = "QtQml.StateMachine"; -const char KDSME_QML_MODULE_VERSION[] = "1.0"; +#define KDSME_QML_MODULE "QtQml.StateMachine" +#define KDSME_QML_MODULE_VERSION "1.0" class LevelIncrementer { @@ -60,18 +60,18 @@ QString elementToComponent(Element *element) const Element::Type type = element->type(); switch (type) { case Element::StateMachineType: - return "StateMachine"; + return QStringLiteral("StateMachine"); case Element::FinalStateType: - return "FinalState"; + return QStringLiteral("FinalState"); case Element::HistoryStateType: - return "HistoryState"; + return QStringLiteral("HistoryState"); case Element::StateType: - return "State"; + return QStringLiteral("State"); case Element::TransitionType: // fall-through case Element::SignalTransitionType: - return "SignalTransition"; + return QStringLiteral("SignalTransition"); case Element::TimeoutTransitionType: - return "TimeoutTransition"; + return QStringLiteral("TimeoutTransition"); case Element::PseudoStateType: // fall-through case Element::ElementType: return QString(); @@ -91,9 +91,9 @@ QString toQmlId(const QString &input) std::replace_if( out.begin(), out.end(), [](const QChar &c) -> bool { - return !(c.isLetterOrNumber() || c == '_'); + return !(c.isLetterOrNumber() || c == u'_'); }, - QChar('_')); + u'_'); out[0] = out.at(0).toLower(); return out; @@ -164,12 +164,12 @@ bool QmlExporter::exportMachine(StateMachine *machine) d->m_level = 0; if (!machine) { - setErrorString("Null machine instance passed"); + setErrorString(QStringLiteral("Null machine instance passed")); return false; } if (d->m_out.status() != QTextStream::Ok) { - setErrorString(QString("Invalid QTextStream status: %1").arg(d->m_out.status())); + setErrorString(QStringLiteral("Invalid QTextStream status: %1").arg(d->m_out.status())); return false; } @@ -182,7 +182,7 @@ bool QmlExporter::Private::writeStateMachine(StateMachine *machine) { Q_ASSERT(machine); - const QString importStmt = QString("import %1 %2\n").arg(KDSME_QML_MODULE).arg(KDSME_QML_MODULE_VERSION); + const QString importStmt = QStringLiteral("import %1 %2\n").arg(QStringLiteral(KDSME_QML_MODULE)).arg(QStringLiteral(KDSME_QML_MODULE_VERSION)); m_out << indention() << importStmt; const QStringList customImports = machine->property("com.kdab.KDSME.DSMExporter.customImports").toStringList(); @@ -191,10 +191,10 @@ bool QmlExporter::Private::writeStateMachine(StateMachine *machine) m_out << '\n'; const QString qmlComponent = elementToComponent(machine); - m_out << indention() << QString("%1 {\n").arg(qmlComponent); + m_out << indention() << QStringLiteral("%1 {\n").arg(qmlComponent); if (!writeStateInner(machine)) return false; - m_out << indention() << QString("}\n"); + m_out << indention() << QStringLiteral("}\n"); return true; } @@ -209,10 +209,10 @@ bool QmlExporter::Private::writeState(State *state) return true; // external defined states, like sourced from other qml files, are not exported const QString qmlComponent = elementToComponent(state); - m_out << indention() << QString("%1 {\n").arg(qmlComponent); + m_out << indention() << QStringLiteral("%1 {\n").arg(qmlComponent); if (!writeStateInner(state)) return false; - m_out << indention() << QString("}\n"); + m_out << indention() << QStringLiteral("}\n"); return true; } @@ -229,7 +229,7 @@ void QmlExporter::Private::writeAttribute(Element *element, const QString &name, } } - m_out << indention() << QString("%1: %2\n").arg(name).arg(value); + m_out << indention() << QStringLiteral("%1: %2\n").arg(name).arg(value); } bool QmlExporter::Private::writeStateInner(State *state) @@ -239,30 +239,30 @@ bool QmlExporter::Private::writeStateInner(State *state) LevelIncrementer levelinc(&m_level); Q_UNUSED(levelinc); - writeAttribute(state, "id", toQmlId(state->label())); + writeAttribute(state, QStringLiteral("id"), toQmlId(state->label())); if (StateMachine *stateMachine = qobject_cast(state)) { const QString running = stateMachine->property("com.kdab.KDSME.DSMExporter.running").toString(); - writeAttribute(state, "running", running); + writeAttribute(state, QStringLiteral("running"), running); } if (state->childMode() == State::ParallelStates) { - writeAttribute(state, "childMode", "State.ParallelStates"); + writeAttribute(state, QStringLiteral("childMode"), QStringLiteral("State.ParallelStates")); } if (State *initial = ElementUtil::findInitialState(state)) { - writeAttribute(state, "initialState", toQmlId(initial->label())); + writeAttribute(state, QStringLiteral("initialState"), toQmlId(initial->label())); } if (HistoryState *historyState = qobject_cast(state)) { if (State *defaultState = historyState->defaultState()) - writeAttribute(state, "defaultState", toQmlId(defaultState->label())); + writeAttribute(state, QStringLiteral("defaultState"), toQmlId(defaultState->label())); if (historyState->historyType() == HistoryState::DeepHistory) - writeAttribute(state, "historyType", "HistoryState.DeepHistory"); + writeAttribute(state, QStringLiteral("historyType"), QStringLiteral("HistoryState.DeepHistory")); } - writeAttribute(state, "onEntered", state->onEntry()); - writeAttribute(state, "onExited", state->onExit()); + writeAttribute(state, QStringLiteral("onEntered"), state->onEntry()); + writeAttribute(state, QStringLiteral("onExited"), state->onExit()); foreach (State *child, state->childStates()) { if (!writeState(child)) @@ -280,36 +280,36 @@ bool QmlExporter::Private::writeStateInner(State *state) bool QmlExporter::Private::writeTransition(Transition *transition) { Q_ASSERT(transition); - m_out << indention() << QString("%1 {\n").arg(elementToComponent(transition)); + m_out << indention() << QStringLiteral("%1 {\n").arg(elementToComponent(transition)); { LevelIncrementer levelinc(&m_level); Q_UNUSED(levelinc); - writeAttribute(transition, "id", toQmlId(transition->label())); + writeAttribute(transition, QStringLiteral("id"), toQmlId(transition->label())); if (transition->targetState()) { - writeAttribute(transition, "targetState", toQmlId(transition->targetState()->label())); + writeAttribute(transition, QStringLiteral("targetState"), toQmlId(transition->targetState()->label())); } if (transition->type() == Element::SignalTransitionType) { auto t = qobject_cast(transition); - writeAttribute(transition, "signal", t->signal()); + writeAttribute(transition, QStringLiteral("signal"), t->signal()); } if (transition->type() == Element::TimeoutTransitionType) { auto t = qobject_cast(transition); if (t->timeout() != -1) { - writeAttribute(transition, "timeout", QString::number(t->timeout())); + writeAttribute(transition, QStringLiteral("timeout"), QString::number(t->timeout())); } } - writeAttribute(transition, "guard", transition->guard()); + writeAttribute(transition, QStringLiteral("guard"), transition->guard()); } - m_out << indention() << QString("}\n"); + m_out << indention() << QStringLiteral("}\n"); return true; } QString QmlExporter::Private::indention() const { - return QString().fill(QChar(' '), m_indent * m_level); + return QString { m_indent * m_level, u' ' }; } diff --git a/src/core/export/scxmlexporter.cpp b/src/core/export/scxmlexporter.cpp index e8a5b733..d9da8730 100644 --- a/src/core/export/scxmlexporter.cpp +++ b/src/core/export/scxmlexporter.cpp @@ -80,12 +80,12 @@ bool ScxmlExporter::exportMachine(StateMachine *machine) setErrorString(QString()); if (!machine) { - setErrorString("Null machine instance passed"); + setErrorString(QStringLiteral("Null machine instance passed")); return false; } if (d->m_writer.hasError()) { - setErrorString("Setting up XML writer failed"); + setErrorString(QStringLiteral("Setting up XML writer failed")); return false; } @@ -100,9 +100,9 @@ bool ScxmlExporter::Private::writeStateMachine(StateMachine *machine) // TODO: Check if preconditions are met, e.g. that all state labels are unique? m_writer.writeStartDocument(); - m_writer.writeStartElement("scxml"); - m_writer.writeDefaultNamespace("http://www.w3.org/2005/07/scxml"); - m_writer.writeAttribute("version", "1.0"); + m_writer.writeStartElement(QStringLiteral("scxml")); + m_writer.writeDefaultNamespace(QStringLiteral("http://www.w3.org/2005/07/scxml")); + m_writer.writeAttribute(QStringLiteral("version"), QStringLiteral("1.0")); if (!writeStateInner(machine)) return false; m_writer.writeEndElement(); @@ -116,7 +116,7 @@ bool ScxmlExporter::Private::writeState(State *state) return true; // pseudo states are ignored } - m_writer.writeStartElement("state"); + m_writer.writeStartElement(QStringLiteral("state")); if (!writeStateInner(state)) return false; m_writer.writeEndElement(); @@ -126,22 +126,22 @@ bool ScxmlExporter::Private::writeState(State *state) bool ScxmlExporter::Private::writeStateInner(State *state) { if (state->label().isEmpty()) { - q->setErrorString(QString("Encountered empty label for state: %1").arg(ObjectHelper::displayString(state))); + q->setErrorString(QStringLiteral("Encountered empty label for state: %1").arg(ObjectHelper::displayString(state))); return false; } if (qobject_cast(state)) { - m_writer.writeAttribute("name", state->label()); + m_writer.writeAttribute(QStringLiteral("name"), state->label()); } else { - m_writer.writeAttribute("id", state->label()); + m_writer.writeAttribute(QStringLiteral("id"), state->label()); } if (State *initial = ElementUtil::findInitialState(state)) { if (initial->label().isEmpty()) { - q->setErrorString(QString("Encountered empty label for state: %1").arg(ObjectHelper::displayString(initial))); + q->setErrorString(QStringLiteral("Encountered empty label for state: %1").arg(ObjectHelper::displayString(initial))); return false; } - m_writer.writeAttribute("initial", initial->label()); + m_writer.writeAttribute(QStringLiteral("initial"), initial->label()); } foreach (Transition *transition, state->transitions()) { @@ -158,10 +158,10 @@ bool ScxmlExporter::Private::writeStateInner(State *state) bool ScxmlExporter::Private::writeTransition(Transition *transition) { - m_writer.writeStartElement("transition"); - m_writer.writeAttribute("event", transition->label()); + m_writer.writeStartElement(QStringLiteral("transition")); + m_writer.writeAttribute(QStringLiteral("event"), transition->label()); if (State *targetState = transition->targetState()) { - m_writer.writeAttribute("target", targetState->label()); + m_writer.writeAttribute(QStringLiteral("target"), targetState->label()); } m_writer.writeEndElement(); return true; diff --git a/src/core/export/svgexporter.cpp b/src/core/export/svgexporter.cpp index 106919a3..b913bf96 100644 --- a/src/core/export/svgexporter.cpp +++ b/src/core/export/svgexporter.cpp @@ -119,13 +119,13 @@ void SvgExporterPrivate::writeSvgPath(const QPainterPath &path, bool fill) auto pathElement = path.elementAt(i); switch (pathElement.type) { case QPainterPath::MoveToElement: - pathData += QStringLiteral(" M") + QString::number(pathElement.x) + ',' + QString::number(pathElement.y); + pathData += QStringLiteral(" M") + QString::number(pathElement.x) + u',' + QString::number(pathElement.y); break; case QPainterPath::LineToElement: - pathData += QStringLiteral(" L") + QString::number(pathElement.x) + ',' + QString::number(pathElement.y); + pathData += QStringLiteral(" L") + QString::number(pathElement.x) + u',' + QString::number(pathElement.y); break; case QPainterPath::CurveToElement: - pathData += QStringLiteral(" C") + QString::number(pathElement.x) + ',' + QString::number(pathElement.y); + pathData += QStringLiteral(" C") + QString::number(pathElement.x) + u',' + QString::number(pathElement.y); ++i; while (i < path.elementCount()) { auto pathElement = path.elementAt(i); @@ -133,7 +133,7 @@ void SvgExporterPrivate::writeSvgPath(const QPainterPath &path, bool fill) --i; break; } - pathData += ' ' + QString::number(pathElement.x) + ',' + QString::number(pathElement.y); + pathData += u' ' + QString::number(pathElement.x) + u',' + QString::number(pathElement.y); ++i; } break; @@ -274,11 +274,7 @@ double SvgExporterPrivate::headerHeight() const double SvgExporterPrivate::margin() const { QFontMetricsF metrics(QGuiApplication::font()); -#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) - return metrics.horizontalAdvance('x'); -#else - return metrics.width('x'); -#endif + return metrics.horizontalAdvance(u'x'); } double SvgExporterPrivate::arrowSize() const @@ -300,15 +296,15 @@ SvgExporter::~SvgExporter() bool SvgExporter::exportMachine(StateMachine *machine) { - setErrorString(QString()); + setErrorString({}); if (!machine) { - setErrorString("Null machine instance passed"); + setErrorString(QStringLiteral("Null machine instance passed")); return false; } if (d->writer.hasError()) { - setErrorString("Setting up XML writer failed"); + setErrorString(QStringLiteral("Setting up XML writer failed")); return false; } diff --git a/src/core/import/scxmlimporter.cpp b/src/core/import/scxmlimporter.cpp index 29d6bf10..a8133d71 100644 --- a/src/core/import/scxmlimporter.cpp +++ b/src/core/import/scxmlimporter.cpp @@ -128,7 +128,7 @@ StateMachine *ScxmlImporter::Private::visitScxml() const QXmlStreamAttributes attributes = m_reader.attributes(); StateMachine *state = new StateMachine; - state->setLabel(attributes.value("name").toString()); + state->setLabel(attributes.value(QStringLiteral("name")).toString()); tryCreateInitialState(state); @@ -144,7 +144,7 @@ StateMachine *ScxmlImporter::Private::visitScxml() } else if (m_reader.name() == QStringLiteral("script")) { m_reader.skipCurrentElement(); } else { - raiseUnexpectedElementError("scxml"); + raiseUnexpectedElementError(QStringLiteral("scxml")); } } return state; @@ -176,7 +176,7 @@ void ScxmlImporter::Private::visitParallel(State *parent) } else if (m_reader.name() == QStringLiteral("history")) { visitHistory(state); } else { - raiseUnexpectedElementError("parallel"); + raiseUnexpectedElementError(QStringLiteral("parallel")); } } } @@ -210,7 +210,7 @@ void ScxmlImporter::Private::visitState(State *parent) } else if (m_reader.name() == QStringLiteral("invoke")) { m_reader.skipCurrentElement(); } else { - raiseUnexpectedElementError("state"); + raiseUnexpectedElementError(QStringLiteral("state")); } } } @@ -223,17 +223,17 @@ void ScxmlImporter::Private::visitInitial(State *parent) // Must have exactly one child Transition *transition = nullptr; while (m_reader.readNextStartElement()) { - if (m_reader.name() == QStringLiteral("transition")) { + if (m_reader.name() == u"transition") { State *initialState = new PseudoState(PseudoState::InitialState, parent); const QXmlStreamAttributes attributes = m_reader.attributes(); - const QString targetStateId = attributes.value("target").toString(); + const QString targetStateId = attributes.value(QStringLiteral("target")).toString(); transition = createTransition(initialState, targetStateId); } else { - raiseUnexpectedElementError("initial"); + raiseUnexpectedElementError(QStringLiteral("initial")); } } if (!transition) { - m_reader.raiseError(QString("Encountered element with invalid child")); + m_reader.raiseError(QStringLiteral("Encountered element with invalid child")); } m_reader.skipCurrentElement(); @@ -256,8 +256,8 @@ void ScxmlImporter::Private::visitTransiton(State *parent) IF_DEBUG(qCDebug(KDSME_CORE) << Q_FUNC_INFO;) const QXmlStreamAttributes attributes = m_reader.attributes(); - const QString event = attributes.value("event").toString(); - const QString targetStateId = attributes.value("target").toString(); + const QString event = attributes.value(QLatin1String("event")).toString(); + const QString targetStateId = attributes.value(QLatin1String("target")).toString(); Transition *transition = createTransition(parent, targetStateId); if (transition) { transition->setLabel(event); @@ -269,7 +269,7 @@ void ScxmlImporter::Private::visitTransiton(State *parent) void ScxmlImporter::Private::visitHistory(State *parent) { Q_UNUSED(parent); - Q_ASSERT(m_reader.isStartElement() && m_reader.name() == QStringLiteral("transition")); + Q_ASSERT(m_reader.isStartElement() && m_reader.name() == u"transition"); IF_DEBUG(qCDebug(KDSME_CORE) << Q_FUNC_INFO;) qCWarning(KDSME_CORE) << "NYI"; @@ -286,7 +286,7 @@ void ScxmlImporter::Private::resolveTargetStates() const QString targetStateId = it.value(); State *targetState = m_nameToStateMap.value(targetStateId); if (!targetState) { - m_reader.raiseError(QString("Unknown state id: %1").arg(targetStateId)); + m_reader.raiseError(QStringLiteral("Unknown state id: %1").arg(targetStateId)); return; } @@ -299,9 +299,9 @@ void ScxmlImporter::Private::resolveTargetStates() State *ScxmlImporter::Private::tryCreateInitialState(State *parent) { const QXmlStreamAttributes attributes = m_reader.attributes(); - if (attributes.hasAttribute("initial")) { + if (attributes.hasAttribute(QStringLiteral("initial"))) { State *initialState = new PseudoState(PseudoState::InitialState, parent); - const QString initialStateId = attributes.value("initial").toString(); + const QString initialStateId = attributes.value(QStringLiteral("initial")).toString(); createTransition(initialState, initialStateId); } return nullptr; @@ -312,7 +312,7 @@ void ScxmlImporter::Private::initState(State *state) Q_ASSERT(state); const QXmlStreamAttributes attributes = m_reader.attributes(); - const QString id = attributes.value("id").toString(); + const QString id = attributes.value(QStringLiteral("id")).toString(); IF_DEBUG(qCDebug(KDSME_CORE) << parent->label() << id;) if (id.isEmpty()) { qCWarning(KDSME_CORE) << "Unnamed state at offset:" << m_reader.characterOffset(); @@ -342,6 +342,6 @@ void ScxmlImporter::Private::reset() void ScxmlImporter::Private::raiseUnexpectedElementError(const QString &context) { - m_reader.raiseError(QString("Unexpected element found while parsing '%1': %2") + m_reader.raiseError(QStringLiteral("Unexpected element found while parsing '%1': %2") .arg(context, m_reader.name().toString())); } diff --git a/src/core/kdsmeconstants.h b/src/core/kdsmeconstants.h index 90c070a0..4e525db9 100644 --- a/src/core/kdsmeconstants.h +++ b/src/core/kdsmeconstants.h @@ -18,6 +18,6 @@ static const char KDSME_QML_NAMESPACE[] = "com.kdab.kdsme"; -static const char KDSME_QML_URI_PREFIX[] = "kdsme"; +#define KDSME_QML_URI_PREFIX "kdsme" #endif diff --git a/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp b/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp index 135cf3aa..9dcabae0 100644 --- a/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp +++ b/src/core/layout/graphvizlayout/graphvizlayouterbackend.cpp @@ -197,15 +197,15 @@ void GraphvizLayouterBackend::Private::buildState(State *state, Agraph_t *graph) // build nodes if (m_layoutMode == RecursiveMode && !state->childStates().isEmpty()) { - const QString graphName = "cluster" + addressToString(state); + const QString graphName = u"cluster" + addressToString(state); Agraph_t *newGraph = _agsubg(graph, graphName); m_elementToPointerMap[state] = newGraph; - _agset(newGraph, "label", state->label().isEmpty() ? QObject::tr("") : state->label() + " ###"); // add a placeholder for the expand/collapse button + _agset(newGraph, QStringLiteral("label"), state->label().isEmpty() ? QObject::tr("") : state->label() + u" ###"); // add a placeholder for the expand/collapse button - auto dummyNode = _agnode(newGraph, "dummynode_" + graphName); - _agset(dummyNode, "shape", "point"); - _agset(dummyNode, "style", "invis"); + auto dummyNode = _agnode(newGraph, u"dummynode_" + graphName); + _agset(dummyNode, QStringLiteral("shape"), QStringLiteral("point")); + _agset(dummyNode, QStringLiteral("style"), QStringLiteral("invis")); m_elementToDummyNodeMap[state] = dummyNode; if (!isAncestorCollapsed(state)) { @@ -222,16 +222,16 @@ void GraphvizLayouterBackend::Private::buildState(State *state, Agraph_t *graph) m_elementToPointerMap[state] = newNode; if (!qIsNull(state->width()) && !qIsNull(state->height())) { - _agset(newNode, "width", QString::number(state->width() / DISPLAY_DPI)); - _agset(newNode, "height", QString::number(state->height() / DISPLAY_DPI)); - _agset(newNode, "fixedsize", "true"); + _agset(newNode, QStringLiteral("width"), QString::number(state->width() / DISPLAY_DPI)); + _agset(newNode, QStringLiteral("height"), QString::number(state->height() / DISPLAY_DPI)); + _agset(newNode, QStringLiteral("fixedsize"), QStringLiteral("true")); } if (!state->label().isEmpty()) { - _agset(newNode, "label", state->label()); + _agset(newNode, QStringLiteral("label"), state->label()); } foreach (const auto &kv, attributesForState(qobject_cast(state))) { - _agset(newNode, kv.first, kv.second); + _agset(newNode, QString::fromLatin1(kv.first), QString::fromLatin1(kv.second)); } } } @@ -281,18 +281,18 @@ void GraphvizLayouterBackend::Private::buildTransition(Transition *transition, A targetDummyNode ? targetDummyNode : target, addressToString(transition), true); if (!transition->label().isEmpty() && m_properties->showTransitionLabels()) { - _agset(edge, "label", transition->label()); + _agset(edge, QStringLiteral("label"), transition->label()); } // in order to connect subgraphs we need to leverage ltail + lhead attribute of edges // see: https://stackoverflow.com/questions/2012036/graphviz-how-to-connect-subgraphs if (sourceDummyNode) { - const QString graphName = "cluster" + addressToString(sourceState); - _agset(edge, "ltail", graphName); + const QString graphName = u"cluster" + addressToString(sourceState); + _agset(edge, QStringLiteral("ltail"), graphName); } if (targetDummyNode) { - const QString graphName = "cluster" + addressToString(targetState); - _agset(edge, "lhead", graphName); + const QString graphName = u"cluster" + addressToString(targetState); + _agset(edge, QStringLiteral("lhead"), graphName); } m_elementToPointerMap[transition] = edge; Q_ASSERT(edge); @@ -419,14 +419,14 @@ void GraphvizLayouterBackend::Private::openContext(const QString &id) // modify settings if (m_layoutMode == RecursiveMode) { - _agset(m_graph, "compound", "true"); + _agset(m_graph, QStringLiteral("compound"), QStringLiteral("true")); } - _agset(m_graph, "overlap", "prism"); - _agset(m_graph, "overlap_shrink", "true"); - _agset(m_graph, "splines", "true"); - _agset(m_graph, "pad", "0.0"); - _agset(m_graph, "dpi", "96.0"); - _agset(m_graph, "nodesep", "0.2"); + _agset(m_graph, QStringLiteral("overlap"), QStringLiteral("prism")); + _agset(m_graph, QStringLiteral("overlap_shrink"), QStringLiteral("true")); + _agset(m_graph, QStringLiteral("splines"), QStringLiteral("true")); + _agset(m_graph, QStringLiteral("pad"), QStringLiteral("0.0")); + _agset(m_graph, QStringLiteral("dpi"), QStringLiteral("96.0")); + _agset(m_graph, QStringLiteral("nodesep"), QStringLiteral("0.2")); } void GraphvizLayouterBackend::Private::closeLayout() @@ -562,10 +562,10 @@ void GraphvizLayouterBackend::layout() const QString machineName = !machine->label().isEmpty() ? machine->label() : ObjectHelper::addressToString(machine); const QString stateName = !state->label().isEmpty() ? state->label() : ObjectHelper::addressToString(state); QDir tmpDir = QDir::temp(); - tmpDir.mkdir("kdsme_debug"); - const QString baseName = QString("%1/%2_%3").arg(tmpDir.filePath("kdsme_debug")).arg(machineName).arg(stateName); - saveToFile(baseName + ".png"); - saveToFile(baseName + ".dot", "dot"); + tmpDir.mkdir(QStringLiteral("kdsme_debug")); + const QString baseName = QStringLiteral("%1/%2_%3").arg(tmpDir.filePath(QStringLiteral("kdsme_debug"))).arg(machineName).arg(stateName); + saveToFile(baseName + u".png"); + saveToFile(baseName + u".dot", QStringLiteral("dot")); } } @@ -594,7 +594,7 @@ void GraphvizLayouterBackend::openLayout(State *state, const LayoutProperties *p d->m_root = state; d->m_properties = properties; - d->openContext(QString("GraphvizLayouterBackend@%1").arg(addressToString(this))); + d->openContext(QStringLiteral("GraphvizLayouterBackend@%1").arg(addressToString(this))); } void GraphvizLayouterBackend::closeLayout() diff --git a/src/core/layout/graphvizlayout/graphvizlayouterbackend_p.h b/src/core/layout/graphvizlayout/graphvizlayouterbackend_p.h index 4240ba22..3971bca4 100644 --- a/src/core/layout/graphvizlayout/graphvizlayouterbackend_p.h +++ b/src/core/layout/graphvizlayout/graphvizlayouterbackend_p.h @@ -81,7 +81,7 @@ class GraphvizLayouterBackend * * @note Context must be open */ - void saveToFile(const QString &filePath, const QString &format = "png"); + void saveToFile(const QString &filePath, const QString &format = QStringLiteral("png")); private: struct Private; diff --git a/src/core/layout/graphvizlayout/gvutils.cpp b/src/core/layout/graphvizlayout/gvutils.cpp index d5ec95bf..ca271362 100644 --- a/src/core/layout/graphvizlayout/gvutils.cpp +++ b/src/core/layout/graphvizlayout/gvutils.cpp @@ -40,7 +40,7 @@ Agraph_t *GVUtils::_agopen(const QString &name, int kind) QString GVUtils::_agget(void *object, const QString &attr, const QString &alt) { - const QString str = agget(object, const_cast(qPrintable(attr))); + const QString str = QString::fromUtf8(agget(object, attr.toUtf8().data())); if (str.isEmpty()) { return alt; } else { diff --git a/src/core/layout/layoutimportexport.cpp b/src/core/layout/layoutimportexport.cpp index 37fed660..886125c0 100644 --- a/src/core/layout/layoutimportexport.cpp +++ b/src/core/layout/layoutimportexport.cpp @@ -35,49 +35,49 @@ namespace { QJsonObject stateLayoutToJson(const State *state) { QJsonObject res; - res["label"] = state->label(); - res["x"] = state->pos().x(); - res["y"] = state->pos().y(); - res["width"] = state->width(); - res["height"] = state->height(); + res[u"label"] = state->label(); + res[u"x"] = state->pos().x(); + res[u"y"] = state->pos().y(); + res[u"width"] = state->width(); + res[u"height"] = state->height(); return res; } QJsonObject transitionLayoutToJson(const Transition *transition) { QJsonObject res; - res["label"] = transition->label(); - res["x"] = transition->pos().x(); - res["y"] = transition->pos().y(); + res[u"label"] = transition->label(); + res[u"x"] = transition->pos().x(); + res[u"y"] = transition->pos().y(); QRectF labelRect = transition->labelBoundingRect(); QJsonObject lbr; - lbr["x"] = labelRect.x(); - lbr["y"] = labelRect.y(); - lbr["width"] = labelRect.width(); - lbr["height"] = labelRect.height(); - res["labelBoundingRect"] = lbr; + lbr[u"x"] = labelRect.x(); + lbr[u"y"] = labelRect.y(); + lbr[u"width"] = labelRect.width(); + lbr[u"height"] = labelRect.height(); + res[u"labelBoundingRect"] = lbr; QByteArray shapeData; QDataStream ds(&shapeData, QIODevice::WriteOnly); ds << transition->shape(); - res["shape"] = QLatin1String(shapeData.toBase64()); + res[u"shape"] = QLatin1String(shapeData.toBase64()); return res; } void importStateLayout(const QJsonObject &data, State *state) { - QJsonObject::const_iterator x = data.find("x"); + QJsonObject::const_iterator x = data.find(u"x"); if (x == data.end()) return; - QJsonObject::const_iterator y = data.find("y"); + QJsonObject::const_iterator y = data.find(u"y"); if (y == data.end()) return; - QJsonObject::const_iterator width = data.find("width"); + QJsonObject::const_iterator width = data.find(u"width"); if (width == data.end()) return; - QJsonObject::const_iterator height = data.find("height"); + QJsonObject::const_iterator height = data.find(u"height"); if (height == data.end()) return; @@ -88,38 +88,38 @@ void importStateLayout(const QJsonObject &data, State *state) bool isValidState(const QJsonObject &data, State *state) { - return data.value("label") == state->label() && data.contains("x") && data.contains("y") && data.contains("width") && data.contains("height"); + return data.value(u"label") == state->label() && data.contains(u"x") && data.contains(u"y") && data.contains(u"width") && data.contains(u"height"); } bool isValidTransition(const QJsonObject &data, Transition *state) { - return data.value("label") == state->label() && data.contains("x") && data.contains("y") && data.contains("labelBoundingRect") && data.contains("shape"); + return data.value(u"label") == state->label() && data.contains(u"x") && data.contains(u"y") && data.contains(u"labelBoundingRect") && data.contains(u"shape"); } void importTransitionLayout(const QJsonObject &data, Transition *transition) { - QJsonObject::const_iterator x = data.find("x"); + QJsonObject::const_iterator x = data.find(u"x"); if (x == data.end()) return; - QJsonObject::const_iterator y = data.find("y"); + QJsonObject::const_iterator y = data.find(u"y"); if (y == data.end()) return; - QJsonObject::const_iterator lbrIt = data.find("labelBoundingRect"); + QJsonObject::const_iterator lbrIt = data.find(u"labelBoundingRect"); if (lbrIt == data.end()) return; - QJsonObject::const_iterator shape = data.find("shape"); + QJsonObject::const_iterator shape = data.find(u"shape"); if (shape == data.end()) return; transition->setPos(QPointF((*x).toDouble(), (*y).toDouble())); QJsonObject lbr = (*lbrIt).toObject(); - transition->setLabelBoundingRect(QRectF(lbr["x"].toDouble(), - lbr["y"].toDouble(), - lbr["width"].toDouble(), - lbr["height"].toDouble())); + transition->setLabelBoundingRect(QRectF(lbr[u"x"].toDouble(), + lbr[u"y"].toDouble(), + lbr[u"width"].toDouble(), + lbr[u"height"].toDouble())); QByteArray shapeData = QByteArray::fromBase64((*shape).toString().toLatin1()); QPainterPath shapePath; QDataStream ds(&shapeData, QIODevice::ReadOnly); @@ -133,13 +133,13 @@ void LayoutImportExport::importLayout(const QJsonObject &data, State *state) { importStateLayout(data, state); - const QJsonArray states = data.value("childStates").toArray(); + const QJsonArray states = data.value(u"childStates").toArray(); for (int i = 0; i < states.size() && i < state->childStates().size(); ++i) { State *child = state->childStates().at(i); importLayout(states.at(i).toObject(), child); } - const QJsonArray transitions = data.value("transitions").toArray(); + const QJsonArray transitions = data.value(u"transitions").toArray(); for (int i = 0; i < transitions.size() && i < state->transitions().size(); ++i) { Transition *child = state->transitions().at(i); importTransitionLayout(transitions.at(i).toObject(), child); @@ -153,12 +153,12 @@ QJsonObject LayoutImportExport::exportLayout(const State *state) QJsonArray states; foreach (State *child, state->childStates()) states.push_back(exportLayout(child)); - res["childStates"] = states; + res[u"childStates"] = states; QJsonArray transitions; foreach (Transition *child, state->transitions()) transitions.push_back(transitionLayoutToJson(child)); - res["transitions"] = transitions; + res[u"transitions"] = transitions; return res; } @@ -168,7 +168,7 @@ bool LayoutImportExport::matches(const QJsonObject &data, State *state) if (!isValidState(data, state)) return false; - const QJsonArray states = data.value("childStates").toArray(); + const QJsonArray states = data.value(u"childStates").toArray(); if (states.size() != state->childStates().size()) return false; @@ -178,7 +178,7 @@ bool LayoutImportExport::matches(const QJsonObject &data, State *state) return false; } - const QJsonArray transitions = data.value("transitions").toArray(); + const QJsonArray transitions = data.value(u"transitions").toArray(); if (transitions.size() != state->transitions().size()) return false; diff --git a/src/core/model/element.cpp b/src/core/model/element.cpp index 3b190563..346fbba4 100644 --- a/src/core/model/element.cpp +++ b/src/core/model/element.cpp @@ -223,7 +223,7 @@ QString Element::toDisplayString() const if (label().isEmpty()) { return str; } - return QString("%1 [Label: %2]").arg(str).arg(label()); + return QStringLiteral("%1 [Label: %2]").arg(str).arg(label()); } const char *Element::typeToString(Element::Type type) diff --git a/src/core/model/elementmodel.cpp b/src/core/model/elementmodel.cpp index 4e783f4b..2bcd665b 100644 --- a/src/core/model/elementmodel.cpp +++ b/src/core/model/elementmodel.cpp @@ -209,9 +209,9 @@ QVariant TransitionListModel::data(const QModelIndex &index, int role) const case NameColumn: return transition->toDisplayString(); case SourceStateColumn: - return (transition->sourceState() ? transition->sourceState()->toDisplayString() : QString("0x0")); + return (transition->sourceState() ? transition->sourceState()->toDisplayString() : QStringLiteral("0x0")); case TargetStateColumn: - return (transition->targetState() ? transition->targetState()->toDisplayString() : QString("0x0")); + return (transition->targetState() ? transition->targetState()->toDisplayString() : QStringLiteral("0x0")); default: return QVariant(); } diff --git a/src/core/model/elementutil.cpp b/src/core/model/elementutil.cpp index 5dc7d9b0..ee1134f5 100644 --- a/src/core/model/elementutil.cpp +++ b/src/core/model/elementutil.cpp @@ -59,10 +59,10 @@ void ElementUtil::setInitialState(State *state, State *initialState) return; if (pseudoStateName.isEmpty()) - pseudoStateName = QString("initalState_%1_%2").arg(state->label()).arg(initialState->label()); + pseudoStateName = QStringLiteral("initalState_%1_%2").arg(state->label()).arg(initialState->label()); if (transitionName.isEmpty()) - transitionName = QString("transitionInitalState_%1_%2").arg(state->label()).arg(initialState->label()); + transitionName = QStringLiteral("transitionInitalState_%1_%2").arg(state->label()).arg(initialState->label()); State *ps = new PseudoState(PseudoState::InitialState, state); ps->setLabel(pseudoStateName); diff --git a/src/core/model/state.cpp b/src/core/model/state.cpp index c626ded3..5138ff6c 100644 --- a/src/core/model/state.cpp +++ b/src/core/model/state.cpp @@ -302,8 +302,8 @@ Element::Type HistoryState::type() const QString HistoryState::toDisplayString() const { const QString thisClassName = ObjectHelper::className(this, ObjectHelper::StripNameSpace); - const QString defaultClassName = d->m_defaultState ? ObjectHelper::className(d->m_defaultState, ObjectHelper::StripNameSpace) : "None"; - return QString("%1 [Default: %2]").arg(thisClassName).arg(defaultClassName); + const QString defaultClassName = d->m_defaultState ? ObjectHelper::className(d->m_defaultState, ObjectHelper::StripNameSpace) : QStringLiteral("None"); + return QStringLiteral("%1 [Default: %2]").arg(thisClassName).arg(defaultClassName); } State *HistoryState::defaultState() const @@ -408,7 +408,7 @@ QString PseudoState::kindString() const QString PseudoState::toDisplayString() const { const QString str = ObjectHelper::className(this, ObjectHelper::StripNameSpace); - return QString("%1 [Kind: %2]").arg(str).arg(kindString()); + return QStringLiteral("%1 [Kind: %2]").arg(str).arg(kindString()); } QDebug KDSME::operator<<(QDebug dbg, const State *state) diff --git a/src/core/tests/test_layouter.cpp b/src/core/tests/test_layouter.cpp index 38d9424f..e249bce3 100644 --- a/src/core/tests/test_layouter.cpp +++ b/src/core/tests/test_layouter.cpp @@ -87,7 +87,7 @@ void LayouterTest::testBasicState() State chart: (I) -> (S1) -> (S2) -> (Final) */ - ScxmlImporter importer(ParseHelper::readFile(TEST_DATA_DIR "/scxml/basicstate.scxml")); + ScxmlImporter importer(ParseHelper::readFile(QStringLiteral(TEST_DATA_DIR "/scxml/basicstate.scxml"))); QScopedPointer machine(importer.import()); auto elements = machine->findChildren(); @@ -105,7 +105,7 @@ void LayouterTest::testParallelState() S1: (I) -> (S11) -> (S1Final) S2: (I) -> (S21) -> (S2Final) */ - ScxmlImporter importer(ParseHelper::readFile(TEST_DATA_DIR "/scxml/parallelstate.scxml")); + ScxmlImporter importer(ParseHelper::readFile(QStringLiteral(TEST_DATA_DIR "/scxml/parallelstate.scxml"))); QScopedPointer machine(importer.import()); QVERIFY(machine); diff --git a/src/core/tests/test_layoutinformation.cpp b/src/core/tests/test_layoutinformation.cpp index 3e659633..5bed4585 100644 --- a/src/core/tests/test_layoutinformation.cpp +++ b/src/core/tests/test_layoutinformation.cpp @@ -97,8 +97,8 @@ private Q_SLOTS: void LayoutInformationTest::testLayoutInformation() { State rootState, copyState; - rootState.setLabel("root"); - copyState.setLabel("root"); + rootState.setLabel(QStringLiteral("root")); + copyState.setLabel(QStringLiteral("root")); rootState.setPos(QPointF(123, 456)); rootState.setWidth(1.2); rootState.setHeight(3.4); @@ -106,13 +106,13 @@ void LayoutInformationTest::testLayoutInformation() State *lastCopyState = nullptr; for (int i = 0; i < 3; ++i) { State *state = new State(); - state->setLabel(QString("state %1").arg(i)); + state->setLabel(QStringLiteral("state %1").arg(i)); state->setPos(QPointF(i, 10 * i)); state->setWidth(100 + i); state->setHeight(50 + i); if (lastState) { Transition *transition = new Transition(lastState); - transition->setLabel(QString("trans %1").arg(i)); + transition->setLabel(QStringLiteral("trans %1").arg(i)); transition->setTargetState(static_cast(state)); transition->setTargetState(state); transition->setPos(QPointF(i * 10, i * 10)); @@ -122,10 +122,10 @@ void LayoutInformationTest::testLayoutInformation() lastState = state; state = new State(); - state->setLabel(QString("state %1").arg(i)); + state->setLabel(QStringLiteral("state %1").arg(i)); if (lastCopyState) { Transition *transition = new Transition(lastCopyState); - transition->setLabel(QString("trans %1").arg(i)); + transition->setLabel(QStringLiteral("trans %1").arg(i)); transition->setTargetState(static_cast(state)); transition->setTargetState(state); } @@ -146,25 +146,25 @@ void LayoutInformationTest::testLayoutMatches() { // check switching label of an element State s1; - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); QJsonDocument doc(LayoutImportExport::exportLayout(&s1)); QVERIFY(LayoutImportExport::matches(doc.object(), &s1)); - s1.setLabel("s2"); + s1.setLabel(QStringLiteral("s2")); QVERIFY(!LayoutImportExport::matches(doc.object(), &s1)); } { // check keeping ids but turn them into another type (transition <-> state) State s1; - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); Transition t1(&s1); - t1.setLabel("t1"); + t1.setLabel(QStringLiteral("t1")); QJsonDocument doc(LayoutImportExport::exportLayout(&s1)); QVERIFY(LayoutImportExport::matches(doc.object(), &s1)); - s1.setLabel("t1"); - t1.setLabel("s1"); + s1.setLabel(QStringLiteral("t1")); + t1.setLabel(QStringLiteral("s1")); QVERIFY(!LayoutImportExport::matches(doc.object(), &s1)); } } diff --git a/src/core/tests/test_models.cpp b/src/core/tests/test_models.cpp index 0aff4712..f3132bd5 100644 --- a/src/core/tests/test_models.cpp +++ b/src/core/tests/test_models.cpp @@ -36,11 +36,11 @@ namespace { QObject *createQObjectTreeSample() { QObject *o1 = new QObject; - o1->setObjectName("root"); + o1->setObjectName(QStringLiteral("root")); QObject *o11 = new QObject(o1); - o11->setObjectName("o1"); + o11->setObjectName(QStringLiteral("o1")); QObject *o12 = new QObject(o1); - o12->setObjectName("o2"); + o12->setObjectName(QStringLiteral("o2")); return o1; } @@ -91,7 +91,7 @@ void ModelsTest::testObjectTreeModel_AppendOperation_SingleObject() { ObjectTreeModel::AppendOperation insert(&model, root.data()); appendedObject = new QObject(root.data()); - appendedObject->setObjectName("appendedObject"); + appendedObject->setObjectName(QStringLiteral("appendedObject")); } QCOMPARE(spy.count(), 1); diff --git a/src/core/tests/test_qmlexport.cpp b/src/core/tests/test_qmlexport.cpp index ce30cfd4..5d4ef414 100644 --- a/src/core/tests/test_qmlexport.cpp +++ b/src/core/tests/test_qmlexport.cpp @@ -34,13 +34,13 @@ static QString stripQml(const QByteArray &input) { QStringList result; #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - Q_FOREACH (const QString &s, QString::fromUtf8(input).split('\n', Qt::SkipEmptyParts)) { + Q_FOREACH (const QString &s, QString::fromUtf8(input).split(u'\n', Qt::SkipEmptyParts)) { #else - Q_FOREACH (const QString &s, QString::fromUtf8(input).split('\n', QString::SkipEmptyParts)) { + Q_FOREACH (const QString &s, QString::fromUtf8(input).split(u'\n', QString::SkipEmptyParts)) { #endif result.append(s.simplified().trimmed()); } - return result.join("\n"); + return result.join(u'\n'); } } @@ -76,9 +76,9 @@ void QmlExportTest::testInvalidIds() "}\n"; */ StateMachine root; - root.setLabel("root"); + root.setLabel(QStringLiteral("root")); State s1(&root); - s1.setLabel("s1.foo"); + s1.setLabel(QStringLiteral("s1.foo")); QByteArray output; QmlExporter exporter(&output); @@ -110,15 +110,15 @@ void QmlExportTest::testSimpleStateMachine() "}\n"; StateMachine root; - root.setLabel("root"); + root.setLabel(QStringLiteral("root")); State s1(&root); - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); State s2(&root); - s2.setLabel("s2"); + s2.setLabel(QStringLiteral("s2")); Transition *t1 = s1.addSignalTransition(&s2); - t1->setLabel("e1"); + t1->setLabel(QStringLiteral("e1")); Transition *t2 = s2.addTimeoutTransition(&s1, 1000); - t2->setLabel("e2"); + t2->setLabel(QStringLiteral("e2")); PseudoState initialState(PseudoState::InitialState, &root); initialState.addSignalTransition(&s1); diff --git a/src/core/tests/test_qsmintegration.cpp b/src/core/tests/test_qsmintegration.cpp index 12a40cb8..f66773f0 100644 --- a/src/core/tests/test_qsmintegration.cpp +++ b/src/core/tests/test_qsmintegration.cpp @@ -84,7 +84,7 @@ void QsmIntegrationTest::testEmptyInput() void QsmIntegrationTest::testSimpleQSM() { QStateMachine qsm; - qsm.setObjectName("myStateMachine"); + qsm.setObjectName(QStringLiteral("myStateMachine")); QsmAdapter adapter; QSignalSpy spy(&adapter, &QsmAdapter::repopulateView); @@ -107,13 +107,13 @@ void QsmIntegrationTest::testSimpleQSM() void QsmIntegrationTest::testRunningQSM() { QStateMachine qsm; - qsm.setObjectName("myStateMachine"); + qsm.setObjectName(QStringLiteral("myStateMachine")); QState qsmInitial(&qsm); - qsmInitial.setObjectName("initial"); + qsmInitial.setObjectName(QStringLiteral("initial")); qsm.setInitialState(&qsmInitial); QFinalState qsmFinal(&qsm); - qsmFinal.setObjectName("final"); + qsmFinal.setObjectName(QStringLiteral("final")); qsm.addState(&qsmFinal); QTimer timer; diff --git a/src/core/tests/test_scxmlexport.cpp b/src/core/tests/test_scxmlexport.cpp index 9577aa5a..cc8f5266 100644 --- a/src/core/tests/test_scxmlexport.cpp +++ b/src/core/tests/test_scxmlexport.cpp @@ -86,19 +86,19 @@ void ScxmlExportTest::testEmptyLabels() ScxmlExporter exporter(&output); bool success = exporter.exportMachine(&root); QVERIFY(!success); - QVERIFY(exporter.errorString().contains("empty label")); + QVERIFY(exporter.errorString().contains(u"empty label")); } void ScxmlExportTest::testSimpleStateMachine() { StateMachine root; - root.setLabel("root"); + root.setLabel(QStringLiteral("root")); State s1(&root); - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); State s2(&root); - s2.setLabel("s2"); + s2.setLabel(QStringLiteral("s2")); Transition *t1 = s1.addSignalTransition(&s2); - t1->setLabel("e1"); + t1->setLabel(QStringLiteral("e1")); PseudoState initialState(PseudoState::InitialState, &root); initialState.addSignalTransition(&s1); diff --git a/src/core/tests/test_scxmlimport.cpp b/src/core/tests/test_scxmlimport.cpp index 3d2f0337..ece4c87d 100644 --- a/src/core/tests/test_scxmlimport.cpp +++ b/src/core/tests/test_scxmlimport.cpp @@ -56,7 +56,7 @@ StateMachine *parse(const QByteArray &data) StateMachine *parseFile(const QString &fileName) { - const QByteArray data = ParseHelper::readFile(QStringLiteral(TEST_DATA_DIR) + '/' + fileName); + const QByteArray data = ParseHelper::readFile(QStringLiteral(TEST_DATA_DIR) + u'/' + fileName); return parse(data); } @@ -177,7 +177,7 @@ void ScxmlImportTest::testBasicState() State chart: (I) -> (S1) -> (S2) -> (Final) */ - State *root = parseFile("scxml/basicstate.scxml"); + State *root = parseFile(QStringLiteral("scxml/basicstate.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("basicstate")); QCOMPARE(root->childStates().size(), 4); @@ -204,7 +204,7 @@ void ScxmlImportTest::testParallelState() Special case: Contains */ - State *root = parseFile("scxml/parallelstate.scxml"); + State *root = parseFile(QStringLiteral("scxml/parallelstate.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("parallelstate")); QCOMPARE(root->childStates().size(), 2); @@ -262,7 +262,7 @@ void ScxmlImportTest::testExampleCalculator() Special case: Contains , , */ - State *root = parseFile("scxml/calculator.scxml"); + State *root = parseFile(QStringLiteral("scxml/calculator.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("Calculator")); QCOMPARE(root->childStates().size(), 2); @@ -293,7 +293,7 @@ void ScxmlImportTest::testExampleMicrowave() Special case: Contains element */ - State *root = parseFile("scxml/microwave.scxml"); + State *root = parseFile(QStringLiteral("scxml/microwave.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("")); QCOMPARE(root->childStates().size(), 3); @@ -319,7 +319,7 @@ void ScxmlImportTest::testExampleTrafficLight() (I) -> (redGoingYellow) -> (yellowGoingGreen) -> (greenGoingYellow) -> (yellowGoingRed) --. ^--------------------------------------------------------------------------' */ - State *root = parseFile("scxml/trafficlight_alternative.scxml"); + State *root = parseFile(QStringLiteral("scxml/trafficlight_alternative.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("trafficlight")); QCOMPARE(root->childStates().size(), 5); @@ -350,7 +350,7 @@ void ScxmlImportTest::testExampleTrafficReport() Special case: Contains */ - State *root = parseFile("scxml/trafficreport.scxml"); + State *root = parseFile(QStringLiteral("scxml/trafficreport.scxml")); QVERIFY(root); QCOMPARE(root->label(), QLatin1String("")); QCOMPARE(root->childStates().size(), 8); diff --git a/src/core/tests/test_statemachine.cpp b/src/core/tests/test_statemachine.cpp index 1aaf891b..b0bd3283 100644 --- a/src/core/tests/test_statemachine.cpp +++ b/src/core/tests/test_statemachine.cpp @@ -33,9 +33,9 @@ private Q_SLOTS: void StateMachineTest::testProperties() { State machine; - machine.setLabel("machine"); + machine.setLabel(QStringLiteral("machine")); State s1(&machine); - s1.setLabel("s1"); + s1.setLabel(QStringLiteral("s1")); QCOMPARE(machine.label(), QLatin1String("machine")); QCOMPARE(s1.label(), QLatin1String("s1")); diff --git a/src/core/util/objecthelper.cpp b/src/core/util/objecthelper.cpp index 979d7741..ce74b9bc 100644 --- a/src/core/util/objecthelper.cpp +++ b/src/core/util/objecthelper.cpp @@ -26,7 +26,7 @@ namespace { QString stripNameSpace(const QString &className) { - const int pos = className.lastIndexOf("::"); + const int pos = className.lastIndexOf(QLatin1String("::")); if (pos != -1) return className.mid(pos + 2); return className; @@ -40,13 +40,14 @@ QString ObjectHelper::addressToString(const void *p) QString ObjectHelper::className(const QObject *object, ObjectHelper::DisplayOption option) { - return (option == StripNameSpace ? stripNameSpace(object->metaObject()->className()) : object->metaObject()->className()); + QString className = QString::fromLatin1(object->metaObject()->className()); + return option == StripNameSpace ? stripNameSpace(className) : className; } QString ObjectHelper::displayString(const QObject *object, DisplayOption option) { if (!object) { - return "QObject(0x0)"; + return QStringLiteral("QObject(0x0)"); } if (object->objectName().isEmpty()) { return QString::fromLatin1("%1 (%2)").arg(addressToString(object)).arg(className(object, option)); @@ -70,17 +71,17 @@ int ObjectHelper::stringToEnum(const QMetaObject *metaObject, const char *name, QString ObjectHelper::toString(const QPointF &point) { - return QString("(%1,%2)").arg(point.x()).arg(point.y()); + return QStringLiteral("(%1,%2)").arg(point.x()).arg(point.y()); } QString ObjectHelper::toString(const QSizeF &size) { - return QString("(%1,%2)").arg(size.width()).arg(size.height()); + return QStringLiteral("(%1,%2)").arg(size.width()).arg(size.height()); } QString ObjectHelper::toString(const QRectF &rect) { - return QString("(pos=%1,size=%2)") + return QStringLiteral("(pos=%1,size=%2)") .arg(toString(rect.topLeft())) .arg(toString(rect.size())); } diff --git a/src/core/util/objecttreemodel.cpp b/src/core/util/objecttreemodel.cpp index 3de8c5f6..d0724de9 100644 --- a/src/core/util/objecttreemodel.cpp +++ b/src/core/util/objecttreemodel.cpp @@ -225,20 +225,20 @@ void ObjectTreeModel::clear() QVariant ObjectTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { - return QVariant(); + return {}; } Q_D(const ObjectTreeModel); QObject *obj = d->mapModelIndex2QObject(index); Q_ASSERT(obj); if (role == Qt::DisplayRole) { - return ("0x" + QString::number(reinterpret_cast(obj), 16)); + return QString { u"0x" + QString::number(reinterpret_cast(obj), 16) }; } else if (role == ObjectRole) { return QVariant::fromValue(obj); } else if (role == ObjectIdRole) { return reinterpret_cast(obj); } - return QVariant(); + return {}; } int ObjectTreeModel::columnCount(const QModelIndex &parent) const diff --git a/src/view/command/createelementcommand.cpp b/src/view/command/createelementcommand.cpp index 70efd6e4..8fea5690 100644 --- a/src/view/command/createelementcommand.cpp +++ b/src/view/command/createelementcommand.cpp @@ -113,5 +113,5 @@ void CreateElementCommand::undo() void CreateElementCommand::updateText() { - setText(tr("Create %1").arg(m_createdElement ? m_createdElement->toDisplayString() : (""))); + setText(tr("Create %1").arg(m_createdElement ? m_createdElement->toDisplayString() : QStringLiteral(""))); } diff --git a/src/view/command/deleteelementcommand.cpp b/src/view/command/deleteelementcommand.cpp index 7ea24a55..1130dfa8 100644 --- a/src/view/command/deleteelementcommand.cpp +++ b/src/view/command/deleteelementcommand.cpp @@ -80,5 +80,5 @@ void DeleteElementCommand::undo() void DeleteElementCommand::updateText() { - setText(tr("Delete %1").arg(m_deletedElement ? m_deletedElement->toDisplayString() : (""))); + setText(tr("Delete %1").arg(m_deletedElement ? m_deletedElement->toDisplayString() : QStringLiteral(""))); } diff --git a/src/view/command/modifypropertycommand.cpp b/src/view/command/modifypropertycommand.cpp index 25b6e1a5..4864e547 100644 --- a/src/view/command/modifypropertycommand.cpp +++ b/src/view/command/modifypropertycommand.cpp @@ -65,8 +65,8 @@ void ModifyPropertyCommand::redo() auto it = m_propertyMap.constBegin(); while (it != m_propertyMap.constEnd()) { - m_oldPropertyMap.insert(it.key(), m_object->property(it.key())); - if (!m_object->setProperty(it.key(), it.value())) { + m_oldPropertyMap.insert(it.key(), m_object->property(it.key().constData())); + if (!m_object->setProperty(it.key().constData(), it.value())) { qCDebug(KDSME_VIEW) << "Failed to set property" << it.key(); } ++it; @@ -82,7 +82,7 @@ void ModifyPropertyCommand::undo() auto it = m_oldPropertyMap.constBegin(); while (it != m_oldPropertyMap.constEnd()) { - if (!m_object->setProperty(it.key(), it.value())) { + if (!m_object->setProperty(it.key().constData(), it.value())) { qCDebug(KDSME_VIEW) << "Failed to set property" << it.key(); } ++it; diff --git a/src/view/editcontroller.cpp b/src/view/editcontroller.cpp index 34af4595..45b86b0b 100644 --- a/src/view/editcontroller.cpp +++ b/src/view/editcontroller.cpp @@ -88,7 +88,7 @@ bool EditController::sendDragEnterEvent(Element *sender, Element *target, const // we only accept one item only for now const QUrl url = urls.first(); - if (url.scheme() != KDSME_QML_URI_PREFIX) { + if (url.scheme() != QStringLiteral(KDSME_QML_URI_PREFIX)) { qCDebug(KDSME_VIEW) << "Unexpected Url Schema=" << url.scheme(); return false; } @@ -110,13 +110,13 @@ bool EditController::sendDropEvent(Element *sender, Element *target, const QPoin // we only accept one item only for now const QUrl url = urls.first(); - if (url.scheme() != KDSME_QML_URI_PREFIX) { + if (url.scheme() != QStringLiteral(KDSME_QML_URI_PREFIX)) { qCDebug(KDSME_VIEW) << "Unexpected Url Schema=" << url.scheme(); return false; } const QString str = url.toString(QUrl::RemoveScheme); - const QString typeString = str.split('/').last(); + const QString typeString = str.split(u'/').last(); if (typeString.isEmpty()) return false; diff --git a/src/view/quick/quickrecursiveinstantiator.cpp b/src/view/quick/quickrecursiveinstantiator.cpp index 47efdf7b..510b6719 100644 --- a/src/view/quick/quickrecursiveinstantiator.cpp +++ b/src/view/quick/quickrecursiveinstantiator.cpp @@ -117,7 +117,7 @@ QObject *QuickRecursiveInstantiator::createItems(const QModelIndex &index, QObje Q_ASSERT(object); auto creationContext = m_delegate->creationContext(); auto context = new QQmlContext(creationContext ? creationContext : qmlContext(this)); - context->setContextProperty("object", object); + context->setContextProperty(QStringLiteral("object"), object); auto createdObject = m_delegate->create(context); createdObject->setParent(parent); diff --git a/src/view/tests/test_commands.cpp b/src/view/tests/test_commands.cpp index 11fb440e..e64400f7 100644 --- a/src/view/tests/test_commands.cpp +++ b/src/view/tests/test_commands.cpp @@ -151,7 +151,7 @@ void CommandsTest::testLayoutSnapshot() void CommandsTest::testModifyProperty() { TestHarness harness; - QAction action("foo", nullptr); + QAction action(QStringLiteral("foo"), nullptr); // via (const char*, QVariant) ctor QCOMPARE(action.isCheckable(), false); @@ -166,8 +166,8 @@ void CommandsTest::testModifyProperty() QCOMPARE(action.isCheckable(), false); QCOMPARE(action.autoRepeat(), true); QJsonObject object; - object.insert("checkable", true); - object.insert("autoRepeat", false); + object.insert(QStringLiteral("checkable"), true); + object.insert(QStringLiteral("autoRepeat"), false); cmd = new ModifyPropertyCommand(&action, object); QCOMPARE(action.isCheckable(), false); QCOMPARE(action.autoRepeat(), true); diff --git a/src/view/widgets/codeeditor.cpp b/src/view/widgets/codeeditor.cpp index b8ead715..0d3c98fb 100644 --- a/src/view/widgets/codeeditor.cpp +++ b/src/view/widgets/codeeditor.cpp @@ -53,7 +53,7 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); - QFont font("Monospace"); + QFont font(QStringLiteral("Monospace")); font.setStyleHint(QFont::TypeWriter); setFont(font); diff --git a/src/view/widgets/propertyeditor.cpp b/src/view/widgets/propertyeditor.cpp index 8bcbaada..43f2ad5b 100644 --- a/src/view/widgets/propertyeditor.cpp +++ b/src/view/widgets/propertyeditor.cpp @@ -97,15 +97,15 @@ PropertyEditor::PropertyEditor(QWidget *parent) d->m_transitionWidget->setupUi(w); d->m_transitionWidgetIndex = addWidget(w); - d->m_widgetToPropertyMap.insert(d->m_stateWidget->labelLineEdit, "label"); - d->m_widgetToPropertyMap.insert(d->m_stateWidget->onEntryEditor, "onEntry"); - d->m_widgetToPropertyMap.insert(d->m_stateWidget->onExitEditor, "onExit"); - d->m_widgetToPropertyMap.insert(d->m_stateWidget->childModeEdit, "childMode"); - d->m_widgetToPropertyMap.insert(d->m_stateWidget->historyTypeEdit, "historyType"); - d->m_widgetToPropertyMap.insert(d->m_transitionWidget->labelLineEdit, "label"); - d->m_widgetToPropertyMap.insert(d->m_transitionWidget->guardEditor, "guard"); - d->m_widgetToPropertyMap.insert(d->m_transitionWidget->signalEdit, "signal"); - d->m_widgetToPropertyMap.insert(d->m_transitionWidget->timeoutEdit, "timeout"); + d->m_widgetToPropertyMap.insert(d->m_stateWidget->labelLineEdit, QStringLiteral("label")); + d->m_widgetToPropertyMap.insert(d->m_stateWidget->onEntryEditor, QStringLiteral("onEntry")); + d->m_widgetToPropertyMap.insert(d->m_stateWidget->onExitEditor, QStringLiteral("onExit")); + d->m_widgetToPropertyMap.insert(d->m_stateWidget->childModeEdit, QStringLiteral("childMode")); + d->m_widgetToPropertyMap.insert(d->m_stateWidget->historyTypeEdit, QStringLiteral("historyType")); + d->m_widgetToPropertyMap.insert(d->m_transitionWidget->labelLineEdit, QStringLiteral("label")); + d->m_widgetToPropertyMap.insert(d->m_transitionWidget->guardEditor, QStringLiteral("guard")); + d->m_widgetToPropertyMap.insert(d->m_transitionWidget->signalEdit, QStringLiteral("signal")); + d->m_widgetToPropertyMap.insert(d->m_transitionWidget->timeoutEdit, QStringLiteral("timeout")); connect(d->m_stateWidget->labelLineEdit, SIGNAL(editingFinished()), SLOT(updateSimpleProperty())); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) @@ -228,7 +228,7 @@ void PropertyEditor::Private::setCurrentElement(KDSME::Element *element) const QMetaProperty prop = m_currentElement->metaObject()->property(i); if (!prop.hasNotifySignal()) continue; - q->connect(m_currentElement, "2" + prop.notifySignal().methodSignature(), q, SLOT(loadFromCurrentElement())); // krazy:exclude=doublequote_chars + q->connect(m_currentElement, QByteArray { "2" + prop.notifySignal().methodSignature() }.constData(), q, SLOT(loadFromCurrentElement())); // krazy:exclude=doublequote_chars } } loadFromCurrentElement(); @@ -263,7 +263,7 @@ void PropertyEditor::Private::loadFromCurrentElement() if (state->type() == Element::HistoryStateType) { m_stateWidget->defaultStateComboBox->addItems(allStates(state->machine())); State *defaultState = qobject_cast(state)->defaultState(); - m_stateWidget->defaultStateComboBox->setCurrentText(defaultState ? defaultState->label() : ""); + m_stateWidget->defaultStateComboBox->setCurrentText(defaultState ? defaultState->label() : QLatin1String("")); } m_stateWidget->onEntryEditor->setPlainText(state->onEntry()); @@ -330,7 +330,7 @@ void PropertyEditor::Private::updateSimpleProperty() const QString propertyName = m_widgetToPropertyMap.value(object); Q_ASSERT(!propertyName.isEmpty()); - const QVariant currentValue = m_currentElement->property(propertyName.toUtf8()); + const QVariant currentValue = m_currentElement->property(propertyName.toUtf8().constData()); QVariant newValue; QComboBox *comboBox = qobject_cast(object); @@ -343,7 +343,7 @@ void PropertyEditor::Private::updateSimpleProperty() return; Q_ASSERT(m_commandController); - ModifyPropertyCommand *command = new ModifyPropertyCommand(m_currentElement, propertyName.toUtf8(), newValue); + ModifyPropertyCommand *command = new ModifyPropertyCommand(m_currentElement, propertyName.toUtf8().constData(), newValue); m_commandController->undoStack()->push(command); } diff --git a/src/view/widgets/statemachinepalettewidget.cpp b/src/view/widgets/statemachinepalettewidget.cpp index 5ce72c7b..380eca0c 100644 --- a/src/view/widgets/statemachinepalettewidget.cpp +++ b/src/view/widgets/statemachinepalettewidget.cpp @@ -73,13 +73,13 @@ class PaletteModel : public QAbstractListModel PaletteModel::PaletteModel(QObject *parent) : QAbstractListModel(parent) { - m_entries << Entry(Element::StateMachineType, ":/kdsme/icons/state_machine.png", tr("State Machine")); - m_entries << Entry(Element::StateType, ":/kdsme/icons/state.png", tr("State")); - m_entries << Entry(Element::FinalStateType, ":/kdsme/icons/final_state.png", tr("Final State")); - m_entries << Entry(Element::HistoryStateType, ":/kdsme/icons/shallow_history.png", tr("History State")); + m_entries << Entry(Element::StateMachineType, QStringLiteral(":/kdsme/icons/state_machine.png"), tr("State Machine")); + m_entries << Entry(Element::StateType, QStringLiteral(":/kdsme/icons/state.png"), tr("State")); + m_entries << Entry(Element::FinalStateType, QStringLiteral(":/kdsme/icons/final_state.png"), tr("Final State")); + m_entries << Entry(Element::HistoryStateType, QStringLiteral(":/kdsme/icons/shallow_history.png"), tr("History State")); - m_entries << Entry(Element::SignalTransitionType, ":/kdsme/icons/transition.png", tr("Signal Transition")); - m_entries << Entry(Element::TimeoutTransitionType, ":/kdsme/icons/transition.png", tr("Timeout Transition")); + m_entries << Entry(Element::SignalTransitionType, QStringLiteral(":/kdsme/icons/transition.png"), tr("Signal Transition")); + m_entries << Entry(Element::TimeoutTransitionType, QStringLiteral(":/kdsme/icons/transition.png"), tr("Timeout Transition")); } int PaletteModel::rowCount(const QModelIndex &parent) const @@ -115,22 +115,22 @@ QMimeData *PaletteModel::mimeData(const QModelIndexList &indexes) const const QModelIndex index = indexes.first(); auto type = index.data(ElementTypeRole).value(); - const QString typeString = Element::typeToString(type); + const QString typeString = QString::fromLatin1(Element::typeToString(type)); QMimeData *mimeData = new QMimeData; - mimeData->setUrls(QList() << QUrl(QString("%1:Element/%2").arg(KDSME_QML_URI_PREFIX, typeString))); + mimeData->setUrls({ QUrl(QStringLiteral("%1:Element/%2").arg(QStringLiteral(KDSME_QML_URI_PREFIX)).arg(typeString)) }); // Following setData calls are used in QML DropArea.keys to accept/reject a drag and drop // depending on the data given. We are using this to allow for example "TransitionType" // elements not to be placed on a UmlStateMachine.qml but only "StateType" elements. - if (typeString.contains(QRegularExpression(".+StateType$"))) - mimeData->setData("StateType", ""); - if (typeString.contains(QRegularExpression(".+TransitionType$"))) - mimeData->setData("TransitionType", ""); + if (typeString.contains(QRegularExpression(QStringLiteral(".+StateType$")))) + mimeData->setData(QStringLiteral("StateType"), ""); + if (typeString.contains(QRegularExpression(QStringLiteral(".+TransitionType$")))) + mimeData->setData(QStringLiteral("TransitionType"), ""); - mimeData->setData("external", ""); + mimeData->setData(QStringLiteral("external"), ""); mimeData->setData(typeString, ""); return mimeData; diff --git a/src/view/widgets/statemachinetoolbar.cpp b/src/view/widgets/statemachinetoolbar.cpp index 0baaa019..dc915860 100644 --- a/src/view/widgets/statemachinetoolbar.cpp +++ b/src/view/widgets/statemachinetoolbar.cpp @@ -39,10 +39,10 @@ namespace { QStringList availableThemeNames() { - QDir dir(":/kdsme/qml/themes"); + QDir dir(QStringLiteral(":/kdsme/qml/themes")); auto entries = dir.entryList(); std::transform(entries.cbegin(), entries.cend(), entries.begin(), [](const QString &x) { - return QString(x).remove(".qml"); + return QString(x).remove(QStringLiteral(".qml")); }); return entries; } @@ -82,7 +82,7 @@ StateMachineToolBar::StateMachineToolBar(StateMachineView *view, QWidget *parent setWindowTitle(tr("State Machine Tool Bar")); d->m_exportAction = new QAction(tr("Export to File..."), this); d->m_exportAction->setObjectName(QStringLiteral("actionExportToFile")); - d->m_exportAction->setStatusTip("Export current state machine to a file."); + d->m_exportAction->setStatusTip(QStringLiteral("Export current state machine to a file.")); connect(d->m_exportAction, SIGNAL(triggered()), this, SLOT(handleExport())); addAction(d->m_exportAction); @@ -110,7 +110,7 @@ void StateMachineToolBar::Private::handleExport() { auto stateMachine = m_view->scene()->rootState()->machine(); if (!stateMachine) { - QMessageBox::information(q, QString(), "State machine unavailable"); + QMessageBox::information(q, QString(), QStringLiteral("State machine unavailable")); return; } @@ -132,9 +132,9 @@ void StateMachineToolBar::Private::exportToFile(StateMachine *machine, const QSt const QString suffix = QFileInfo(fileName).suffix(); AbstractExporter *exporter; - if (suffix == "qml") { + if (suffix == u"qml") { exporter = new QmlExporter(&file); - } else if (suffix == "svg") { + } else if (suffix == u"svg") { exporter = new SvgExporter(&file); } else { // fallback diff --git a/src/view/widgets/statemachineview.cpp b/src/view/widgets/statemachineview.cpp index d7ae6f57..a27a0823 100644 --- a/src/view/widgets/statemachineview.cpp +++ b/src/view/widgets/statemachineview.cpp @@ -73,7 +73,7 @@ static QString kdsme_qmlErrorString(const QList errors) { QString s; Q_FOREACH (const QQmlError &e, errors) { - s += e.toString() + '\n'; + s += e.toString() + u'\n'; } return s; } @@ -145,16 +145,16 @@ StateMachineView::StateMachineView(QWidget *parent) qmlRegisterType(KDSME_QML_NAMESPACE, 1, 0, "SemanticZoomManager"); qmlRegisterType(KDSME_QML_NAMESPACE, 1, 0, "StateMachineScene"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "AbstractMask", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "AbstractScene", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "EditController", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "CommandController", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "RuntimeController", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "Element", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "HistoryState", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "PseudoState", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "State", "Access to object"); - qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "Transition", "Access to object"); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "AbstractMask", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "AbstractScene", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "EditController", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "CommandController", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "RuntimeController", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "Element", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "HistoryState", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "PseudoState", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "State", QStringLiteral("Access to object")); + qmlRegisterUncreatableType(KDSME_QML_NAMESPACE, 1, 0, "Transition", QStringLiteral("Access to object")); // singletons qmlRegisterSingletonType(KDSME_QML_NAMESPACE, 1, 0, "Global", kdsme_global_singletontype_provider); @@ -163,7 +163,7 @@ StateMachineView::StateMachineView(QWidget *parent) d->m_controller = new CommandController(new QUndoStack(this), this); d->m_editController = new EditController(this); - engine()->rootContext()->setContextProperty("_quickView", this); + engine()->rootContext()->setContextProperty(QStringLiteral("_quickView"), this); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Does not seem to work under Qt 6 -- yields a black QML scene if enabled there @@ -173,7 +173,7 @@ StateMachineView::StateMachineView(QWidget *parent) #endif setResizeMode(QQuickWidget::SizeRootObjectToView); - setSource(QUrl("qrc:/kdsme/qml/StateMachineView.qml")); + setSource(QUrl(QStringLiteral("qrc:/kdsme/qml/StateMachineView.qml"))); #if !defined(NDEBUG) Q_ASSERT_X(errors().isEmpty(), __FUNCTION__, qPrintable(kdsme_qmlErrorString(errors()))); #endif @@ -247,14 +247,14 @@ void StateMachineView::setThemeName(const QString &themeName) QQuickItem *StateMachineView::viewPortObject() const { - QQuickItem *item = rootObject()->findChild("stateMachineViewport"); + QQuickItem *item = rootObject()->findChild(QStringLiteral("stateMachineViewport")); Q_ASSERT(item); return item; } QQuickItem *StateMachineView::sceneObject() const { - QQuickItem *item = rootObject()->findChild("stateMachineScene"); + QQuickItem *item = rootObject()->findChild(QStringLiteral("stateMachineScene")); Q_ASSERT(item); return item; } @@ -287,7 +287,7 @@ QRectF StateMachineView::Private::adjustedViewRect() { static const int margin = 10; - const QQuickItem *viewPort = q->rootObject()->findChild("scrollView"); + const QQuickItem *viewPort = q->rootObject()->findChild(QStringLiteral("scrollView")); const QRectF viewRect(viewPort->x(), viewPort->y(), viewPort->width(), viewPort->height()); if (viewRect.isEmpty()) return QRectF();