summaryrefslogtreecommitdiffstats
path: root/examples/scxml/trafficlight-qml-simple
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scxml/trafficlight-qml-simple')
-rw-r--r--examples/scxml/trafficlight-qml-simple/CMakeLists.txt51
-rw-r--r--examples/scxml/trafficlight-qml-simple/Light.qml53
-rw-r--r--examples/scxml/trafficlight-qml-simple/MainView.qml62
-rw-r--r--examples/scxml/trafficlight-qml-simple/TrafficLight.qml110
-rw-r--r--examples/scxml/trafficlight-qml-simple/doc/src/trafficlight-qml-simple.qdoc37
-rw-r--r--examples/scxml/trafficlight-qml-simple/qmldir5
-rw-r--r--examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp68
-rw-r--r--examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.pro22
-rw-r--r--examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.qrc6
-rw-r--r--examples/scxml/trafficlight-qml-simple/trafficlight-qml.h20
10 files changed, 175 insertions, 259 deletions
diff --git a/examples/scxml/trafficlight-qml-simple/CMakeLists.txt b/examples/scxml/trafficlight-qml-simple/CMakeLists.txt
new file mode 100644
index 0000000..b3d2bfe
--- /dev/null
+++ b/examples/scxml/trafficlight-qml-simple/CMakeLists.txt
@@ -0,0 +1,51 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(trafficlight-qml-simple LANGUAGES CXX)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+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
+)
+
+set_target_properties(trafficlight-qml-simple PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(trafficlight-qml-simple PRIVATE
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+ Qt::Scxml
+)
+
+# 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}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/scxml/trafficlight-qml-simple/Light.qml b/examples/scxml/trafficlight-qml-simple/Light.qml
index 8502d35..da6b30e 100644
--- a/examples/scxml/trafficlight-qml-simple/Light.qml
+++ b/examples/scxml/trafficlight-qml-simple/Light.qml
@@ -1,54 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtScxml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-import QtQuick 2.5
+import QtQuick
Item {
property color color
diff --git a/examples/scxml/trafficlight-qml-simple/MainView.qml b/examples/scxml/trafficlight-qml-simple/MainView.qml
new file mode 100644
index 0000000..3e66f19
--- /dev/null
+++ b/examples/scxml/trafficlight-qml-simple/MainView.qml
@@ -0,0 +1,62 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import TrafficLightApplication
+
+Window {
+ id: root
+ visible: true
+ width: 100
+ height: 350
+
+ TrafficLightStateMachine {
+ id: stateMachine
+ running: true
+ }
+
+ Item {
+ id: lights
+ width: parent.width
+ height: 300
+
+ Light {
+ anchors.top: parent.top
+ anchors.horizontalCenter: parent.horizontalCenter
+ color: "red"
+ visible: stateMachine.red || stateMachine.redGoingGreen
+ }
+
+ Light {
+ anchors.centerIn: parent
+ color: "yellow"
+ visible: stateMachine.yellow || stateMachine.blinking
+ }
+
+ Light {
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ color: "green"
+ visible: stateMachine.green
+ }
+ }
+
+ Rectangle {
+ anchors.top: lights.bottom
+ anchors.bottom: parent.bottom
+ width: parent.width
+ border.color: "black"
+
+ Text {
+ anchors.fill: parent
+ text: stateMachine.working ? "Pause" : "Unpause"
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: stateMachine.submitEvent(stateMachine.working ? "smash" : "repair");
+ }
+ }
+}
diff --git a/examples/scxml/trafficlight-qml-simple/TrafficLight.qml b/examples/scxml/trafficlight-qml-simple/TrafficLight.qml
deleted file mode 100644
index d2f9948..0000000
--- a/examples/scxml/trafficlight-qml-simple/TrafficLight.qml
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtScxml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 2.5
-import QtQuick.Window 2.2
-import TrafficLightStateMachine 1.0
-
-Window {
- id: root
- visible: true
- width: 100
- height: 350
-
- TrafficLightStateMachine {
- id: stateMachine
- running: true
- }
-
- Item {
- id: lights
- width: parent.width
- height: 300
-
- Light {
- anchors.top: parent.top
- anchors.horizontalCenter: parent.horizontalCenter
- color: "red"
- visible: stateMachine.red || stateMachine.redGoingGreen
- }
-
- Light {
- anchors.centerIn: parent
- color: "yellow"
- visible: stateMachine.yellow || stateMachine.blinking
- }
-
- Light {
- anchors.bottom: parent.bottom
- anchors.horizontalCenter: parent.horizontalCenter
- color: "green"
- visible: stateMachine.green
- }
- }
-
- Rectangle {
- anchors.top: lights.bottom
- anchors.bottom: parent.bottom
- width: parent.width
- border.color: "black"
-
- Text {
- anchors.fill: parent
- text: stateMachine.working ? "Pause" : "Unpause"
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
-
- MouseArea {
- anchors.fill: parent
- onClicked: stateMachine.submitEvent(stateMachine.working ? "smash" : "repair");
- }
- }
-}
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 f66f5f7..d4bd8ef 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,33 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example trafficlight-qml-simple
- \title Qt SCXML Traffic Light QML Example (Simple)
+ \title SCXML Traffic Light (Simple, QML)
+ \examplecategory {Data Processing & I/O}
\ingroup examples-qtscxml
\brief A Qt Quick application that uses a compiled state machine to
@@ -35,7 +12,7 @@
\image trafficlight.png
- \e{Traffic Light QML Example (Simple)} demonstrates how to connect to the
+ \e{Traffic Light} demonstrates how to connect to the
active properties of a state in a state machine that is compiled to a class.
The UI is created using Qt Quick.
@@ -48,7 +25,7 @@
We instantiate the state machine as follows:
- \quotefromfile trafficlight-qml-simple/TrafficLight.qml
+ \quotefromfile trafficlight-qml-simple/MainView.qml
\skipto TrafficLightStateMachine {
\printuntil }
@@ -57,7 +34,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 c9950c4..5b945b7 100644
--- a/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp
+++ b/examples/scxml/trafficlight-qml-simple/trafficlight-qml-simple.cpp
@@ -1,71 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtScxml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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