diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-10 15:19:09 +0200 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-17 13:02:12 +0200 |
commit | 3314da2f16d2b0c1f52e8da07c299ee983314c59 (patch) | |
tree | 07d96f1197968222b79af4445194e60407c17f62 | |
parent | 3cb2fa15fc9b73453ada4b36577322bbea86c52c (diff) |
Revamp scxml trafficlight examples
In addition to general modernization, this commit changes
the trafficlight structure slightly so that the qml-static
and qml-dynamic variants have their own copies of the QML
files.
This way the examples remain standalone examples
whilst using the contemporary qt_add_qml_module, without
needing to introduce a shared common QML module. A shared
common QML module is a viable option but would unnecesarily
complicate example build/link/deployments.
Pick-to: 6.5
Task-number: QTBUG-111323
Change-Id: I7a289db2d2927d97438556362e4b2eff53821020
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
39 files changed, 424 insertions, 320 deletions
diff --git a/examples/scxml/trafficlight-common/statemachine.scxml b/examples/scxml/trafficlight-common/statemachine.scxml index e3979dc..9afe664 100644 --- a/examples/scxml/trafficlight-common/statemachine.scxml +++ b/examples/scxml/trafficlight-common/statemachine.scxml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause --> <scxml diff --git a/examples/scxml/trafficlight-common/trafficlight.cpp b/examples/scxml/trafficlight-common/trafficlight.cpp index f9a73ed..e29f2b5 100644 --- a/examples/scxml/trafficlight-common/trafficlight.cpp +++ b/examples/scxml/trafficlight-common/trafficlight.cpp @@ -1,24 +1,26 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "trafficlight.h" -#include <QPainter> -#include <QVBoxLayout> +#include <QtWidgets/qboxlayout.h> +#include <QtGui/qpainter.h> + +using namespace Qt::Literals::StringLiterals; class TrafficLightWidget : public QWidget { public: TrafficLightWidget(QWidget *parent = nullptr) - : QWidget(parent), m_background(QLatin1String(":/background.png")) + : QWidget(parent), m_background(":/background.png"_L1) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(0, 40, 0, 80); - m_red = new LightWidget(QLatin1String(":/red.png")); + m_red = new LightWidget(":/red.png"_L1); vbox->addWidget(m_red, 0, Qt::AlignHCenter); - m_yellow = new LightWidget(QLatin1String(":/yellow.png")); + m_yellow = new LightWidget(":/yellow.png"_L1); vbox->addWidget(m_yellow, 0, Qt::AlignHCenter); - m_green = new LightWidget(QLatin1String(":/green.png")); + m_green = new LightWidget(":/green.png"_L1); vbox->addWidget(m_green, 0, Qt::AlignHCenter); setLayout(vbox); } @@ -56,16 +58,11 @@ TrafficLight::TrafficLight(QScxmlStateMachine *machine, QWidget *parent) TrafficLightWidget *widget = new TrafficLightWidget(this); setFixedSize(widget->sizeHint()); - machine->connectToState(QStringLiteral("red"), - widget->redLight(), &LightWidget::switchLight); - machine->connectToState(QStringLiteral("redGoingGreen"), - widget->redLight(), &LightWidget::switchLight); - machine->connectToState(QStringLiteral("yellow"), - widget->yellowLight(), &LightWidget::switchLight); - machine->connectToState(QStringLiteral("blinking"), - widget->yellowLight(), &LightWidget::switchLight); - machine->connectToState(QStringLiteral("green"), - widget->greenLight(), &LightWidget::switchLight); + machine->connectToState(u"red"_s, widget->redLight(), &LightWidget::switchLight); + machine->connectToState(u"redGoingGreen"_s, widget->redLight(), &LightWidget::switchLight); + machine->connectToState(u"yellow"_s, widget->yellowLight(), &LightWidget::switchLight); + machine->connectToState(u"blinking"_s, widget->yellowLight(), &LightWidget::switchLight); + machine->connectToState(u"green"_s, widget->greenLight(), &LightWidget::switchLight); QAbstractButton *button = new ButtonWidget(this); auto setButtonGeometry = [this, button](){ @@ -77,8 +74,7 @@ TrafficLight::TrafficLight(QScxmlStateMachine *machine, QWidget *parent) connect(button, &QAbstractButton::toggled, this, setButtonGeometry); setButtonGeometry(); - connect(button, &QAbstractButton::toggled, - this, &TrafficLight::toggleWorking); + connect(button, &QAbstractButton::toggled, this, &TrafficLight::toggleWorking); } void TrafficLight::toggleWorking(bool pause) @@ -103,7 +99,9 @@ void LightWidget::setOn(bool on) } void LightWidget::switchLight(bool onoff) -{ setOn(onoff); } +{ + setOn(onoff); +} void LightWidget::paintEvent(QPaintEvent *) { @@ -120,8 +118,8 @@ QSize LightWidget::sizeHint() const } ButtonWidget::ButtonWidget(QWidget *parent) : - QAbstractButton(parent), m_playIcon(QLatin1String(":/play.png")), - m_pauseIcon(QLatin1String(":/pause.png")) + QAbstractButton(parent), m_playIcon(":/play.png"_L1), + m_pauseIcon(":/pause.png"_L1) { setCheckable(true); } diff --git a/examples/scxml/trafficlight-common/trafficlight.h b/examples/scxml/trafficlight-common/trafficlight.h index 768bfd3..97da67b 100644 --- a/examples/scxml/trafficlight-common/trafficlight.h +++ b/examples/scxml/trafficlight-common/trafficlight.h @@ -1,12 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef TRAFFICLIGHT_H #define TRAFFICLIGHT_H -#include <QAbstractButton> -#include <QScxmlStateMachine> -#include <QWidget> +#include <QtWidgets/qwidget.h> +#include <QtWidgets/qabstractbutton.h> +#include <QtScxml/qscxmlstatemachine.h> class TrafficLight : public QWidget { diff --git a/examples/scxml/trafficlight-common/Button.qml b/examples/scxml/trafficlight-qml-dynamic/Button.qml index 73dabbe..1333193 100644 --- a/examples/scxml/trafficlight-common/Button.qml +++ b/examples/scxml/trafficlight-qml-dynamic/Button.qml @@ -1,6 +1,8 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound + import QtQuick Image { diff --git a/examples/scxml/trafficlight-qml-dynamic/CMakeLists.txt b/examples/scxml/trafficlight-qml-dynamic/CMakeLists.txt index 83aee77..f1f2ee4 100644 --- a/examples/scxml/trafficlight-qml-dynamic/CMakeLists.txt +++ b/examples/scxml/trafficlight-qml-dynamic/CMakeLists.txt @@ -1,12 +1,9 @@ -# Copyright (C) 2022 The Qt Company Ltd. +# Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(trafficlight-qml-dynamic LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +11,7 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/trafficlight-qml-dynamic") find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) +qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(trafficlight-qml-dynamic trafficlight-qml-dynamic.cpp @@ -24,73 +22,60 @@ set_target_properties(trafficlight-qml-dynamic PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(trafficlight-qml-dynamic PUBLIC +target_link_libraries(trafficlight-qml-dynamic PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Scxml ) -# Resources: -set_source_files_properties("../trafficlight-common/Button.qml" - PROPERTIES QT_RESOURCE_ALIAS "Button.qml" -) - -set_source_files_properties("../trafficlight-common/Lights.ui.qml" - PROPERTIES QT_RESOURCE_ALIAS "Lights.ui.qml" -) - -set_source_files_properties("../trafficlight-common/TrafficLight.qml" - PROPERTIES QT_RESOURCE_ALIAS "TrafficLight.qml" -) - -set_source_files_properties("../trafficlight-common/background.png" - PROPERTIES QT_RESOURCE_ALIAS "background.png" +set_source_files_properties("../trafficlight-common/statemachine.scxml" + PROPERTIES QT_RESOURCE_ALIAS "statemachine.scxml" ) -set_source_files_properties("../trafficlight-common/green.png" - PROPERTIES QT_RESOURCE_ALIAS "green.png" +set_source_files_properties(../trafficlight-common/play.png + PROPERTIES QT_RESOURCE_ALIAS "play.png" ) -set_source_files_properties("../trafficlight-common/pause.png" - PROPERTIES QT_RESOURCE_ALIAS "pause.png" +set_source_files_properties(../trafficlight-common/play.png + PROPERTIES QT_RESOURCE_ALIAS "play.png" ) -set_source_files_properties("../trafficlight-common/play.png" - PROPERTIES QT_RESOURCE_ALIAS "play.png" +set_source_files_properties(../trafficlight-common/yellow.png + PROPERTIES QT_RESOURCE_ALIAS "yellow.png" ) -set_source_files_properties("../trafficlight-common/red.png" +set_source_files_properties(../trafficlight-common/red.png PROPERTIES QT_RESOURCE_ALIAS "red.png" ) -set_source_files_properties("../trafficlight-common/statemachine.scxml" - PROPERTIES QT_RESOURCE_ALIAS "statemachine.scxml" +set_source_files_properties(../trafficlight-common/green.png + PROPERTIES QT_RESOURCE_ALIAS "green.png" ) -set_source_files_properties("../trafficlight-common/yellow.png" - PROPERTIES QT_RESOURCE_ALIAS "yellow.png" +set_source_files_properties(../trafficlight-common/background.png + PROPERTIES QT_RESOURCE_ALIAS "background.png" ) -set(trafficlight-qml-dynamic_resource_files - "../trafficlight-common/Button.qml" - "../trafficlight-common/Lights.ui.qml" - "../trafficlight-common/TrafficLight.qml" - "../trafficlight-common/background.png" - "../trafficlight-common/green.png" - "../trafficlight-common/pause.png" - "../trafficlight-common/play.png" - "../trafficlight-common/red.png" - "../trafficlight-common/statemachine.scxml" - "../trafficlight-common/yellow.png" - "trafficlight-qml-dynamic.qml" +set_source_files_properties(../trafficlight-common/pause.png + PROPERTIES QT_RESOURCE_ALIAS "pause.png" ) -qt6_add_resources(trafficlight-qml-dynamic "trafficlight-qml-dynamic" - PREFIX - "/" - FILES - ${trafficlight-qml-dynamic_resource_files} +qt_add_qml_module(trafficlight-qml-dynamic + URI TrafficLightApplication + VERSION 1.0 + QML_FILES + MainView.qml + Button.qml + Lights.ui.qml + RESOURCES + ../trafficlight-common/statemachine.scxml + ../trafficlight-common/play.png + ../trafficlight-common/yellow.png + ../trafficlight-common/red.png + ../trafficlight-common/green.png + ../trafficlight-common/background.png + ../trafficlight-common/pause.png ) install(TARGETS trafficlight-qml-dynamic diff --git a/examples/scxml/trafficlight-qml-dynamic/Lights.ui.qml b/examples/scxml/trafficlight-qml-dynamic/Lights.ui.qml new file mode 100644 index 0000000..ef683f9 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/Lights.ui.qml @@ -0,0 +1,80 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +pragma ComponentBehavior: Bound + +import QtQuick +import QtScxml + +Image { + id: lights + + property alias button: button + required property StateMachine stateMachine + + source: "background.png" + + Column { + y: 40 + spacing: 27 + anchors.horizontalCenter: parent.horizontalCenter + + Image { + id: redLight + opacity: 0.2 + source: "red.png" + } + + Image { + id: yellowLight + opacity: 0.2 + source: "yellow.png" + } + + Image { + id: greenLight + opacity: 0.2 + source: "green.png" + } + } + + Button { + id: button + + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: 20 + source: "pause.png" + } + + states: [ + // Suppress qmllint warning, dynamic statemachine properties not known at compile-time + // qmllint disable missing-property + State { + name: "Red" + when: lights.stateMachine.red + + PropertyChanges { redLight.opacity: 1 } + }, + State { + name: "RedGoingGreen" + when: lights.stateMachine.redGoingGreen + + PropertyChanges { redLight.opacity: 1 } + PropertyChanges { yellowLight.opacity: 1 } + }, + State { + name: "Yellow" + when: lights.stateMachine.yellow || lights.stateMachine.blinking + + PropertyChanges { yellowLight.opacity: 1 } + }, + State { + name: "Green" + when: lights.stateMachine.green + + PropertyChanges { greenLight.opacity: 1 } + } + // qmllint enable missing-property + ] +} diff --git a/examples/scxml/trafficlight-qml-dynamic/MainView.qml b/examples/scxml/trafficlight-qml-dynamic/MainView.qml new file mode 100644 index 0000000..2923568 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/MainView.qml @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +pragma ComponentBehavior: Bound + +import QtQuick +import QtScxml +import TrafficLightApplication + +Window { + width: lights.width + height: lights.height + visible: true + + Lights { + id: lights + stateMachine: loader.stateMachine + // Suppress qmllint warning, dynamic statemachine properties not known at compile-time + // qmllint disable missing-property + button.source: stateMachine.working ? "pause.png" : "play.png" + button.onClicked: stateMachine.submitEvent(stateMachine.working ? "smash" : "repair"); + // qmllint enable missing-property + } + + StateMachineLoader { + id: loader + source: Qt.resolvedUrl("statemachine.scxml") + } +} diff --git a/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc b/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc index ec732cb..71ce0f3 100644 --- a/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc +++ b/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! @@ -37,7 +37,7 @@ We dynamically create the state machine in the main QML file: - \quotefromfile trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml + \quotefromfile trafficlight-qml-dynamic/MainView.qml \skipto import QtScxml \printuntil /^\}/ @@ -45,7 +45,7 @@ We connect to the states as follows: - \quotefromfile trafficlight-common/Lights.ui.qml + \quotefromfile trafficlight-qml-dynamic/Lights.ui.qml \skipto states \printuntil ] */ diff --git a/examples/scxml/trafficlight-qml-dynamic/qmldir b/examples/scxml/trafficlight-qml-dynamic/qmldir new file mode 100644 index 0000000..c375025 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/qmldir @@ -0,0 +1,6 @@ +module TrafficLightApplication +prefer :/qt/qml/TrafficLightApplication/ +MainView 1.0 MainView.qml +Button 1.0 Button.qml +Lights 1.0 Lights.ui.qml + diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp index 49d7549..5b945b7 100644 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp @@ -1,28 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QGuiApplication> -#include <QQmlApplicationEngine> -#include <QQmlContext> -#include <QScxmlStateMachine> +#include <QtGui/qguiapplication.h> +#include <QtQml/qqmlapplicationengine.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - /* Register QScxmlStateMachine as TrafficLightStateMachine. This is required to have a type - * for the state machine and allows full code completion in the static case, since we - * share the QML code. */ - qmlRegisterUncreatableType<QScxmlStateMachine>("TrafficLightStateMachine", - 1, 0, - "TrafficLightStateMachine", - QLatin1String("TrafficLightStateMachine is not creatable.")); - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:///trafficlight-qml-dynamic.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, + [](){ QCoreApplication::exit(EXIT_FAILURE); }, Qt::QueuedConnection); + engine.loadFromModule("TrafficLightApplication", "MainView"); return app.exec(); } - diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro index c03a7ef..f562c79 100644 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro @@ -4,7 +4,25 @@ QT += qml scxml SOURCES += trafficlight-qml-dynamic.cpp -RESOURCES += trafficlight-qml-dynamic.qrc +QML_IMPORT_NAME = TrafficLightApplication +QML_IMPORT_MAJOR_VERSION = 1 + +qml_resources.files = \ + qmldir \ + MainView.qml \ + Button.qml \ + Lights.ui.qml \ + ../trafficlight-common/statemachine.scxml \ + ../trafficlight-common/play.png \ + ../trafficlight-common/yellow.png \ + ../trafficlight-common/red.png \ + ../trafficlight-common/green.png \ + ../trafficlight-common/background.png \ + ../trafficlight-common/pause.png \ + +qml_resources.prefix = /qt/qml/TrafficLightApplication + +RESOURCES += qml_resources target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-qml-dynamic INSTALLS += target diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml deleted file mode 100644 index 290670b..0000000 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtScxml - -TrafficLight { - StateMachineLoader { - id: loader - source: "qrc:///statemachine.scxml" - } - - stateMachine: loader.stateMachine -} diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc deleted file mode 100644 index 547935b..0000000 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc +++ /dev/null @@ -1,15 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> - <file alias="Button.qml">../trafficlight-common/Button.qml</file> - <file alias="Lights.ui.qml">../trafficlight-common/Lights.ui.qml</file> - <file>trafficlight-qml-dynamic.qml</file> - <file alias="statemachine.scxml">../trafficlight-common/statemachine.scxml</file> - <file alias="green.png">../trafficlight-common/green.png</file> - <file alias="yellow.png">../trafficlight-common/yellow.png</file> - <file alias="red.png">../trafficlight-common/red.png</file> - <file alias="pause.png">../trafficlight-common/pause.png</file> - <file alias="play.png">../trafficlight-common/play.png</file> - <file alias="background.png">../trafficlight-common/background.png</file> - </qresource> -</RCC> diff --git a/examples/scxml/trafficlight-qml-simple/CMakeLists.txt b/examples/scxml/trafficlight-qml-simple/CMakeLists.txt index 511766a..cbadea2 100644 --- a/examples/scxml/trafficlight-qml-simple/CMakeLists.txt +++ b/examples/scxml/trafficlight-qml-simple/CMakeLists.txt @@ -1,11 +1,9 @@ -# Copyright (C) 2022 The Qt Company Ltd. +# Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(trafficlight-qml-simple LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -13,6 +11,7 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/trafficlight-qml-simple") find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) +qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(trafficlight-qml-simple trafficlight-qml-simple.cpp @@ -23,31 +22,28 @@ set_target_properties(trafficlight-qml-simple PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(trafficlight-qml-simple PUBLIC +target_link_libraries(trafficlight-qml-simple PRIVATE Qt::Core Qt::Gui Qt::Qml Qt::Scxml ) -# Resources: -set(trafficlight-qml-simple_resource_files - "Light.qml" - "TrafficLight.qml" -) - -qt6_add_resources(trafficlight-qml-simple "trafficlight-qml-simple" - PREFIX - "/" - FILES - ${trafficlight-qml-simple_resource_files} -) - # Statecharts: qt6_add_statecharts(trafficlight-qml-simple ../trafficlight-common/statemachine.scxml ) +qt_add_qml_module(trafficlight-qml-simple + URI TrafficLightApplication + VERSION 1.0 + QML_FILES + MainView.qml + Light.qml + SOURCES + trafficlight-qml.h +) + install(TARGETS trafficlight-qml-simple RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/scxml/trafficlight-qml-simple/Light.qml b/examples/scxml/trafficlight-qml-simple/Light.qml index cae4822..da6b30e 100644 --- a/examples/scxml/trafficlight-qml-simple/Light.qml +++ b/examples/scxml/trafficlight-qml-simple/Light.qml @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick diff --git a/examples/scxml/trafficlight-qml-simple/TrafficLight.qml b/examples/scxml/trafficlight-qml-simple/MainView.qml index 4ca6eb0..3e66f19 100644 --- a/examples/scxml/trafficlight-qml-simple/TrafficLight.qml +++ b/examples/scxml/trafficlight-qml-simple/MainView.qml @@ -1,9 +1,8 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick -import QtQuick.Window -import TrafficLightStateMachine 1.0 +import TrafficLightApplication Window { id: root diff --git a/examples/scxml/trafficlight-qml-simple/doc/src/trafficlight-qml-simple.qdoc b/examples/scxml/trafficlight-qml-simple/doc/src/trafficlight-qml-simple.qdoc index a3bb591..8a59aeb 100644 --- a/examples/scxml/trafficlight-qml-simple/doc/src/trafficlight-qml-simple.qdoc +++ b/examples/scxml/trafficlight-qml-simple/doc/src/trafficlight-qml-simple.qdoc @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! @@ -24,7 +24,7 @@ We instantiate the state machine as follows: - \quotefromfile trafficlight-qml-simple/TrafficLight.qml + \quotefromfile trafficlight-qml-simple/MainView.qml \skipto TrafficLightStateMachine { \printuntil } @@ -33,7 +33,7 @@ We connect to the states as follows: - \quotefromfile trafficlight-qml-simple/TrafficLight.qml + \quotefromfile trafficlight-qml-simple/MainView.qml \skipto Light { \printuntil /^ {4}\}/ */ diff --git a/examples/scxml/trafficlight-qml-simple/qmldir b/examples/scxml/trafficlight-qml-simple/qmldir new file mode 100644 index 0000000..179aefa --- /dev/null +++ b/examples/scxml/trafficlight-qml-simple/qmldir @@ -0,0 +1,5 @@ +module TrafficLightApplication +prefer :/qt/qml/TrafficLightApplication/ +MainView 1.0 MainView.qml +Light 1.0 Light.qml + diff --git a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp index ef707f2..5b945b7 100644 --- a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp +++ b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp @@ -1,24 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QGuiApplication> -#include <QQmlApplicationEngine> -#include <QQmlContext> - -#include "statemachine.h" +#include <QtGui/qguiapplication.h> +#include <QtQml/qqmlapplicationengine.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<TrafficLightStateMachine>("TrafficLightStateMachine", 1, 0, - "TrafficLightStateMachine"); - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/TrafficLight.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, + [](){ QCoreApplication::exit(EXIT_FAILURE); }, Qt::QueuedConnection); + engine.loadFromModule("TrafficLightApplication", "MainView"); return app.exec(); } - diff --git a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.pro b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.pro index 4de04ea..0424432 100644 --- a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.pro +++ b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.pro @@ -2,13 +2,31 @@ TEMPLATE = app QT += qml scxml CONFIG += c++11 +CONFIG += qmltypes SOURCES += trafficlight-qml-simple.cpp -RESOURCES += trafficlight-qml-simple.qrc +HEADERS += trafficlight-qml.h STATECHARTS = ../trafficlight-common/statemachine.scxml +QML_IMPORT_NAME = TrafficLightApplication +QML_IMPORT_MAJOR_VERSION = 1 + +qml_resources.files = \ + qmldir \ + MainView.qml \ + Light.qml \ + ../trafficlight-common/play.png \ + ../trafficlight-common/yellow.png \ + ../trafficlight-common/red.png \ + ../trafficlight-common/green.png \ + ../trafficlight-common/background.png \ + ../trafficlight-common/pause.png \ + +qml_resources.prefix = /qt/qml/TrafficLightApplication + +RESOURCES += qml_resources + target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-qml-simple INSTALLS += target - diff --git a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.qrc b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.qrc deleted file mode 100644 index bb75dba..0000000 --- a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>TrafficLight.qml</file> - <file>Light.qml</file> - </qresource> -</RCC> diff --git a/examples/scxml/trafficlight-qml-simple/trafficlight-qml.h b/examples/scxml/trafficlight-qml-simple/trafficlight-qml.h new file mode 100644 index 0000000..ac309bd --- /dev/null +++ b/examples/scxml/trafficlight-qml-simple/trafficlight-qml.h @@ -0,0 +1,20 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TRAFFICLIGHT_QML +#define TRAFFICLIGHT_QML + +#include "statemachine.h" + +#include <QtQml/qqml.h> +#include <QtCore/qobject.h> + +struct TrafficLightStateMachineRegistration +{ + Q_GADGET + QML_FOREIGN(TrafficLightStateMachine) + QML_NAMED_ELEMENT(TrafficLightStateMachine) + QML_ADDED_IN_VERSION(1, 0) +}; + +#endif // TRAFFICLIGHT_QML diff --git a/examples/scxml/trafficlight-qml-static/Button.qml b/examples/scxml/trafficlight-qml-static/Button.qml new file mode 100644 index 0000000..1333193 --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/Button.qml @@ -0,0 +1,17 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +pragma ComponentBehavior: Bound + +import QtQuick + +Image { + id: button + signal clicked + + MouseArea { + id: mouse + anchors.fill: parent + onClicked: button.clicked() + } +} diff --git a/examples/scxml/trafficlight-qml-static/CMakeLists.txt b/examples/scxml/trafficlight-qml-static/CMakeLists.txt index 4950dc6..3f2cd11 100644 --- a/examples/scxml/trafficlight-qml-static/CMakeLists.txt +++ b/examples/scxml/trafficlight-qml-static/CMakeLists.txt @@ -1,12 +1,9 @@ -# Copyright (C) 2022 The Qt Company Ltd. +# Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(trafficlight-qml-static LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +11,7 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/trafficlight-qml-static") find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) +qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(trafficlight-qml-static trafficlight-qml-static.cpp @@ -24,73 +22,62 @@ set_target_properties(trafficlight-qml-static PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(trafficlight-qml-static PUBLIC +target_link_libraries(trafficlight-qml-static PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Scxml ) -# Resources: -set_source_files_properties("../trafficlight-common/Button.qml" - PROPERTIES QT_RESOURCE_ALIAS "Button.qml" -) - -set_source_files_properties("../trafficlight-common/Lights.ui.qml" - PROPERTIES QT_RESOURCE_ALIAS "Lights.ui.qml" -) - -set_source_files_properties("../trafficlight-common/TrafficLight.qml" - PROPERTIES QT_RESOURCE_ALIAS "TrafficLight.qml" -) - -set_source_files_properties("../trafficlight-common/background.png" - PROPERTIES QT_RESOURCE_ALIAS "background.png" +# Statecharts: +qt6_add_statecharts(trafficlight-qml-static + ../trafficlight-common/statemachine.scxml ) -set_source_files_properties("../trafficlight-common/green.png" - PROPERTIES QT_RESOURCE_ALIAS "green.png" +set_source_files_properties(../trafficlight-common/play.png + PROPERTIES QT_RESOURCE_ALIAS "play.png" ) -set_source_files_properties("../trafficlight-common/pause.png" - PROPERTIES QT_RESOURCE_ALIAS "pause.png" +set_source_files_properties(../trafficlight-common/play.png + PROPERTIES QT_RESOURCE_ALIAS "play.png" ) -set_source_files_properties("../trafficlight-common/play.png" - PROPERTIES QT_RESOURCE_ALIAS "play.png" +set_source_files_properties(../trafficlight-common/yellow.png + PROPERTIES QT_RESOURCE_ALIAS "yellow.png" ) -set_source_files_properties("../trafficlight-common/red.png" +set_source_files_properties(../trafficlight-common/red.png PROPERTIES QT_RESOURCE_ALIAS "red.png" ) -set_source_files_properties("../trafficlight-common/yellow.png" - PROPERTIES QT_RESOURCE_ALIAS "yellow.png" +set_source_files_properties(../trafficlight-common/green.png + PROPERTIES QT_RESOURCE_ALIAS "green.png" ) -set(trafficlight-qml-static_resource_files - "../trafficlight-common/Button.qml" - "../trafficlight-common/Lights.ui.qml" - "../trafficlight-common/TrafficLight.qml" - "../trafficlight-common/background.png" - "../trafficlight-common/green.png" - "../trafficlight-common/pause.png" - "../trafficlight-common/play.png" - "../trafficlight-common/red.png" - "../trafficlight-common/yellow.png" - "trafficlight-qml-static.qml" +set_source_files_properties(../trafficlight-common/background.png + PROPERTIES QT_RESOURCE_ALIAS "background.png" ) -qt6_add_resources(trafficlight-qml-static "trafficlight-qml-static" - PREFIX - "/" - FILES - ${trafficlight-qml-static_resource_files} +set_source_files_properties(../trafficlight-common/pause.png + PROPERTIES QT_RESOURCE_ALIAS "pause.png" ) -# Statecharts: -qt6_add_statecharts(trafficlight-qml-static - ../trafficlight-common/statemachine.scxml +qt_add_qml_module(trafficlight-qml-static + URI TrafficLightApplication + VERSION 1.0 + QML_FILES + MainView.qml + Button.qml + Lights.ui.qml + SOURCES + trafficlight-qml.h + RESOURCES + ../trafficlight-common/play.png + ../trafficlight-common/yellow.png + ../trafficlight-common/red.png + ../trafficlight-common/green.png + ../trafficlight-common/background.png + ../trafficlight-common/pause.png ) install(TARGETS trafficlight-qml-static diff --git a/examples/scxml/trafficlight-common/Lights.ui.qml b/examples/scxml/trafficlight-qml-static/Lights.ui.qml index 95c4322..ace9cbc 100644 --- a/examples/scxml/trafficlight-common/Lights.ui.qml +++ b/examples/scxml/trafficlight-qml-static/Lights.ui.qml @@ -1,10 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound import QtQuick -import QtQuick.Window -import TrafficLightStateMachine 1.0 +import TrafficLightApplication Image { id: lights @@ -50,44 +50,28 @@ Image { states: [ State { name: "Red" - when: stateMachine.red + when: lights.stateMachine.red - PropertyChanges { - target: redLight - opacity: 1 - } + PropertyChanges { redLight.opacity: 1 } }, State { name: "RedGoingGreen" - when: stateMachine.redGoingGreen + when: lights.stateMachine.redGoingGreen - PropertyChanges { - target: redLight - opacity: 1 - } - - PropertyChanges { - target: yellowLight - opacity: 1 - } + PropertyChanges { redLight.opacity: 1 } + PropertyChanges { yellowLight.opacity: 1 } }, State { name: "Yellow" - when: stateMachine.yellow || stateMachine.blinking + when: lights.stateMachine.yellow || lights.stateMachine.blinking - PropertyChanges { - target: yellowLight - opacity: 1 - } + PropertyChanges { yellowLight.opacity: 1 } }, State { name: "Green" - when: stateMachine.green + when: lights.stateMachine.green - PropertyChanges { - target: greenLight - opacity: 1 - } + PropertyChanges { greenLight.opacity: 1 } } ] } diff --git a/examples/scxml/trafficlight-common/TrafficLight.qml b/examples/scxml/trafficlight-qml-static/MainView.qml index 04144ee..d4dce03 100644 --- a/examples/scxml/trafficlight-common/TrafficLight.qml +++ b/examples/scxml/trafficlight-qml-static/MainView.qml @@ -1,27 +1,22 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound + import QtQuick -import QtQuick.Window -import TrafficLightStateMachine 1.0 +import TrafficLightApplication Window { - id: root - - property TrafficLightStateMachine stateMachine - - visible: true width: lights.width height: lights.height - maximumWidth: lights.implicitWidth - maximumHeight: lights.implicitHeight + visible: true Lights { id: lights - - stateMachine: root.stateMachine + stateMachine: TrafficLightStateMachine { + running: true + } button.source: stateMachine.working ? "pause.png" : "play.png" - button.onClicked: stateMachine.submitEvent(stateMachine.working ? "smash" : "repair"); } } diff --git a/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc b/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc index 5005607..98689a0 100644 --- a/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc +++ b/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! @@ -24,7 +24,7 @@ We instantiate the state machine as follows: - \quotefromfile trafficlight-qml-static/trafficlight-qml-static.qml + \quotefromfile trafficlight-qml-static/MainView.qml \skipto TrafficLight \printuntil } @@ -33,7 +33,7 @@ We connect to the states as follows: - \quotefromfile trafficlight-common/Lights.ui.qml + \quotefromfile trafficlight-qml-static/Lights.ui.qml \skipto states \printuntil ] */ diff --git a/examples/scxml/trafficlight-qml-static/qmldir b/examples/scxml/trafficlight-qml-static/qmldir new file mode 100644 index 0000000..c375025 --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/qmldir @@ -0,0 +1,6 @@ +module TrafficLightApplication +prefer :/qt/qml/TrafficLightApplication/ +MainView 1.0 MainView.qml +Button 1.0 Button.qml +Lights 1.0 Lights.ui.qml + diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp index 0490a73..5b945b7 100644 --- a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp @@ -1,23 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QGuiApplication> -#include <QQmlApplicationEngine> -#include <QQmlContext> - -#include "statemachine.h" +#include <QtGui/qguiapplication.h> +#include <QtQml/qqmlapplicationengine.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<TrafficLightStateMachine>("TrafficLightStateMachine", 1, 0, "TrafficLightStateMachine"); - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/trafficlight-qml-static.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, + [](){ QCoreApplication::exit(EXIT_FAILURE); }, Qt::QueuedConnection); + engine.loadFromModule("TrafficLightApplication", "MainView"); return app.exec(); } - diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro index e5dd64c..2cc86aa 100644 --- a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro @@ -1,14 +1,34 @@ TEMPLATE = app QT += qml scxml + CONFIG += c++11 +CONFIG += qmltypes SOURCES += trafficlight-qml-static.cpp -RESOURCES += trafficlight-qml-static.qrc +HEADERS += trafficlight-qml.h STATECHARTS = ../trafficlight-common/statemachine.scxml +QML_IMPORT_NAME = TrafficLightApplication +QML_IMPORT_MAJOR_VERSION = 1 + +qml_resources.files = \ + qmldir \ + MainView.qml \ + Button.qml \ + Lights.ui.qml \ + ../trafficlight-common/play.png \ + ../trafficlight-common/yellow.png \ + ../trafficlight-common/red.png \ + ../trafficlight-common/green.png \ + ../trafficlight-common/background.png \ + ../trafficlight-common/pause.png \ + +qml_resources.prefix = /qt/qml/TrafficLightApplication + +RESOURCES += qml_resources + target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-qml-static INSTALLS += target - diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml deleted file mode 100644 index 564239a..0000000 --- a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import TrafficLightStateMachine 1.0 - -TrafficLight { - stateMachine: TrafficLightStateMachine { - running: true - } -} diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc deleted file mode 100644 index 890b4a7..0000000 --- a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc +++ /dev/null @@ -1,14 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>trafficlight-qml-static.qml</file> - <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> - <file alias="Button.qml">../trafficlight-common/Button.qml</file> - <file alias="Lights.ui.qml">../trafficlight-common/Lights.ui.qml</file> - <file alias="green.png">../trafficlight-common/green.png</file> - <file alias="yellow.png">../trafficlight-common/yellow.png</file> - <file alias="red.png">../trafficlight-common/red.png</file> - <file alias="pause.png">../trafficlight-common/pause.png</file> - <file alias="play.png">../trafficlight-common/play.png</file> - <file alias="background.png">../trafficlight-common/background.png</file> - </qresource> -</RCC> diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml.h b/examples/scxml/trafficlight-qml-static/trafficlight-qml.h new file mode 100644 index 0000000..ac309bd --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml.h @@ -0,0 +1,20 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TRAFFICLIGHT_QML +#define TRAFFICLIGHT_QML + +#include "statemachine.h" + +#include <QtQml/qqml.h> +#include <QtCore/qobject.h> + +struct TrafficLightStateMachineRegistration +{ + Q_GADGET + QML_FOREIGN(TrafficLightStateMachine) + QML_NAMED_ELEMENT(TrafficLightStateMachine) + QML_ADDED_IN_VERSION(1, 0) +}; + +#endif // TRAFFICLIGHT_QML diff --git a/examples/scxml/trafficlight-widgets-dynamic/CMakeLists.txt b/examples/scxml/trafficlight-widgets-dynamic/CMakeLists.txt index a97ad83..0215c76 100644 --- a/examples/scxml/trafficlight-widgets-dynamic/CMakeLists.txt +++ b/examples/scxml/trafficlight-widgets-dynamic/CMakeLists.txt @@ -1,11 +1,9 @@ -# Copyright (C) 2022 The Qt Company Ltd. +# Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(trafficlight-widgets-dynamic LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/trafficlight-widgets-dynami find_package(Qt6 REQUIRED COMPONENTS Core Gui Scxml Widgets) +qt_standard_project_setup() + qt_add_executable(trafficlight-widgets-dynamic ../trafficlight-common/trafficlight.cpp ../trafficlight-common/trafficlight.h trafficlight-widgets-dynamic.cpp @@ -24,7 +24,7 @@ set_target_properties(trafficlight-widgets-dynamic PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(trafficlight-widgets-dynamic PUBLIC +target_link_libraries(trafficlight-widgets-dynamic PRIVATE Qt6::Core Qt6::Gui Qt6::Scxml diff --git a/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc b/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc index a3a6f03..04db53d 100644 --- a/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc +++ b/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc @@ -1,9 +1,9 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example trafficlight-widgets-dynamic - \title SCXML Traffic Light Example (Dynamic, Widgets) + \title SCXML Traffic Light (Dynamic, Widgets) \ingroup examples-qtscxml \brief A widget-based application that uses a dynamically loaded state diff --git a/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp index 0b46f40..fbd02dd 100644 --- a/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp +++ b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp @@ -1,25 +1,26 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "../trafficlight-common/trafficlight.h" -#include <QApplication> -#include <QIODevice> -#include <QTextStream> +#include <QtWidgets/qapplication.h> +#include <QtCore/qiodevice.h> +#include <QtCore/qtextstream.h> + +using namespace Qt::Literals::StringLiterals; int main(int argc, char **argv) { QApplication app(argc, argv); - QScxmlStateMachine *machine = QScxmlStateMachine::fromFile( - QStringLiteral(":statemachine.scxml")); + QScxmlStateMachine *machine = QScxmlStateMachine::fromFile(u":statemachine.scxml"_s); + if (!machine->parseErrors().isEmpty()) { QTextStream errs(stderr, QIODevice::WriteOnly); const auto errors = machine->parseErrors(); for (const QScxmlError &error : errors) { errs << error.toString(); } - return -1; } diff --git a/examples/scxml/trafficlight-widgets-static/CMakeLists.txt b/examples/scxml/trafficlight-widgets-static/CMakeLists.txt index a306152..a3789fb 100644 --- a/examples/scxml/trafficlight-widgets-static/CMakeLists.txt +++ b/examples/scxml/trafficlight-widgets-static/CMakeLists.txt @@ -1,11 +1,9 @@ -# Copyright (C) 2022 The Qt Company Ltd. +# Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(trafficlight-widgets-static LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/trafficlight-widgets-static find_package(Qt6 REQUIRED COMPONENTS Core Gui Scxml Widgets) +qt_standard_project_setup() + qt_add_executable(trafficlight-widgets-static ../trafficlight-common/trafficlight.cpp ../trafficlight-common/trafficlight.h trafficlight-widgets-static.cpp @@ -24,7 +24,7 @@ set_target_properties(trafficlight-widgets-static PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(trafficlight-widgets-static PUBLIC +target_link_libraries(trafficlight-widgets-static PRIVATE Qt::Core Qt::Gui Qt::Scxml diff --git a/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc b/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc index 216b3ef..4fcf093 100644 --- a/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc +++ b/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! diff --git a/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp index e40ad5e..905a3c9 100644 --- a/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp +++ b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp @@ -1,10 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "statemachine.h" #include "../trafficlight-common/trafficlight.h" -#include <QApplication> +#include <QtWidgets/qapplication.h> int main(int argc, char **argv) { |