From ac0e56806c61feae8662c60db66060ce567e0eb9 Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Mon, 20 Feb 2023 14:34:51 +0200 Subject: Remove invoke-dynamic example and rename invoke-static to plain "invoke" The primary purpose of the example is to demonstrate invoking, and one example variant is probably adequate. Task-number: QTBUG-111090 Change-Id: I1f8a64be3bb82c9663687b7f37cf6682e0626060 Reviewed-by: Ulf Hermann (cherry picked from commit a21673b4315f9fce913a9c7bc513102874e6777f) Reviewed-by: Qt Cherry-pick Bot --- examples/scxml/CMakeLists.txt | 3 +- examples/scxml/invoke-common/Button.qml | 35 ----------- examples/scxml/invoke-common/MainView.qml | 58 ----------------- examples/scxml/invoke-common/SubView.qml | 26 -------- examples/scxml/invoke-common/statemachine.scxml | 32 ---------- examples/scxml/invoke-dynamic/CMakeLists.txt | 69 --------------------- .../invoke-dynamic/doc/images/invoke-dynamic.png | Bin 6580 -> 0 bytes .../invoke-dynamic/doc/src/invoke-dynamic.qdoc | 51 --------------- examples/scxml/invoke-dynamic/invoke-dynamic.cpp | 18 ------ examples/scxml/invoke-dynamic/invoke-dynamic.pro | 12 ---- examples/scxml/invoke-dynamic/invoke-dynamic.qml | 13 ---- examples/scxml/invoke-dynamic/invoke-dynamic.qrc | 9 --- examples/scxml/invoke-static/CMakeLists.txt | 69 --------------------- .../invoke-static/doc/images/invoke-static.png | Bin 7170 -> 0 bytes .../scxml/invoke-static/doc/src/invoke-static.qdoc | 67 -------------------- examples/scxml/invoke-static/invoke-static.cpp | 22 ------- examples/scxml/invoke-static/invoke-static.pro | 14 ----- examples/scxml/invoke-static/invoke-static.qml | 10 --- examples/scxml/invoke-static/invoke-static.qrc | 8 --- examples/scxml/invoke/Button.qml | 35 +++++++++++ examples/scxml/invoke/CMakeLists.txt | 56 +++++++++++++++++ examples/scxml/invoke/MainView.qml | 58 +++++++++++++++++ examples/scxml/invoke/SubView.qml | 26 ++++++++ examples/scxml/invoke/doc/images/invoke.png | Bin 0 -> 7170 bytes examples/scxml/invoke/doc/src/invoke.qdoc | 67 ++++++++++++++++++++ examples/scxml/invoke/invoke.cpp | 22 +++++++ examples/scxml/invoke/invoke.pro | 14 +++++ examples/scxml/invoke/invoke.qml | 10 +++ examples/scxml/invoke/invoke.qrc | 8 +++ examples/scxml/invoke/statemachine.scxml | 32 ++++++++++ examples/scxml/scxml.pro | 3 +- 31 files changed, 330 insertions(+), 517 deletions(-) delete mode 100644 examples/scxml/invoke-common/Button.qml delete mode 100644 examples/scxml/invoke-common/MainView.qml delete mode 100644 examples/scxml/invoke-common/SubView.qml delete mode 100644 examples/scxml/invoke-common/statemachine.scxml delete mode 100644 examples/scxml/invoke-dynamic/CMakeLists.txt delete mode 100644 examples/scxml/invoke-dynamic/doc/images/invoke-dynamic.png delete mode 100644 examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc delete mode 100644 examples/scxml/invoke-dynamic/invoke-dynamic.cpp delete mode 100644 examples/scxml/invoke-dynamic/invoke-dynamic.pro delete mode 100644 examples/scxml/invoke-dynamic/invoke-dynamic.qml delete mode 100644 examples/scxml/invoke-dynamic/invoke-dynamic.qrc delete mode 100644 examples/scxml/invoke-static/CMakeLists.txt delete mode 100644 examples/scxml/invoke-static/doc/images/invoke-static.png delete mode 100644 examples/scxml/invoke-static/doc/src/invoke-static.qdoc delete mode 100644 examples/scxml/invoke-static/invoke-static.cpp delete mode 100644 examples/scxml/invoke-static/invoke-static.pro delete mode 100644 examples/scxml/invoke-static/invoke-static.qml delete mode 100644 examples/scxml/invoke-static/invoke-static.qrc create mode 100644 examples/scxml/invoke/Button.qml create mode 100644 examples/scxml/invoke/CMakeLists.txt create mode 100644 examples/scxml/invoke/MainView.qml create mode 100644 examples/scxml/invoke/SubView.qml create mode 100644 examples/scxml/invoke/doc/images/invoke.png create mode 100644 examples/scxml/invoke/doc/src/invoke.qdoc create mode 100644 examples/scxml/invoke/invoke.cpp create mode 100644 examples/scxml/invoke/invoke.pro create mode 100644 examples/scxml/invoke/invoke.qml create mode 100644 examples/scxml/invoke/invoke.qrc create mode 100644 examples/scxml/invoke/statemachine.scxml diff --git a/examples/scxml/CMakeLists.txt b/examples/scxml/CMakeLists.txt index 257fe22..3257421 100644 --- a/examples/scxml/CMakeLists.txt +++ b/examples/scxml/CMakeLists.txt @@ -20,6 +20,5 @@ if(TARGET Qt::Qml AND TARGET Qt::Gui) qt_internal_add_example(trafficlight-qml-dynamic) qt_internal_add_example(trafficlight-qml-simple) qt_internal_add_example(mediaplayer) - qt_internal_add_example(invoke-static) - qt_internal_add_example(invoke-dynamic) + qt_internal_add_example(invoke) endif() diff --git a/examples/scxml/invoke-common/Button.qml b/examples/scxml/invoke-common/Button.qml deleted file mode 100644 index 0b7e6b2..0000000 --- a/examples/scxml/invoke-common/Button.qml +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick - -Item { - id: button - signal clicked - property string text: "hello" - property bool enabled: true - opacity: enabled ? 1.0 : 0.5 - - Rectangle { - x: 5 - y: 5 - width: parent.width - 10 - height: parent.height - 10 - radius: 5 - color: "lightsteelblue" - - Text { - anchors.fill: parent - color: "white" - text: button.text - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - } - - MouseArea { - id: mouse - anchors.fill: parent - onClicked: if (button.enabled) button.clicked() - } - } -} diff --git a/examples/scxml/invoke-common/MainView.qml b/examples/scxml/invoke-common/MainView.qml deleted file mode 100644 index 6ae5155..0000000 --- a/examples/scxml/invoke-common/MainView.qml +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick -import QtQuick.Window -import QtScxml - -Window { - id: window - visible: true - property StateMachine stateMachine - - color: "black" - width: 400 - height: 300 - - Item { - width: parent.width / 2 - height: parent.height - - Button { - id: nowhere - text: "Go Nowhere" - width: parent.width - height: parent.height / 2 - onClicked: stateMachine.submitEvent("goNowhere") - enabled: stateMachine.somewhere - } - - Button { - id: somewhere - text: "Go Somewhere" - width: parent.width - height: parent.height / 2 - y: parent.height / 2 - onClicked: stateMachine.submitEvent("goSomewhere") - enabled: stateMachine.nowhere - } - } - - Loader { - source: "SubView.qml" - active: stateMachine.somewhere - - x: parent.width / 2 - width: parent.width / 2 - height: parent.height - - InvokedServices { - id: services - stateMachine: window.stateMachine - } - - property var anywhere: services.children.anywhere ? services.children.anywhere.stateMachine - : undefined - } -} - diff --git a/examples/scxml/invoke-common/SubView.qml b/examples/scxml/invoke-common/SubView.qml deleted file mode 100644 index 413227b..0000000 --- a/examples/scxml/invoke-common/SubView.qml +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick - -Item { - // "anywhere" is a context property, so we always have to check if it's null - Button { - id: here - enabled: anywhere ? anywhere.here : false - text: "Go There" - width: parent.width / 2 - height: parent.height - onClicked: anywhere.submitEvent("goThere") - } - - Button { - id: there - enabled: anywhere ? anywhere.there : false - text: "Go Here" - width: parent.width / 2 - height: parent.height - x: width - onClicked: anywhere.submitEvent("goHere") - } -} diff --git a/examples/scxml/invoke-common/statemachine.scxml b/examples/scxml/invoke-common/statemachine.scxml deleted file mode 100644 index 6a0f5a9..0000000 --- a/examples/scxml/invoke-common/statemachine.scxml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/scxml/invoke-dynamic/CMakeLists.txt b/examples/scxml/invoke-dynamic/CMakeLists.txt deleted file mode 100644 index 25cd67f..0000000 --- a/examples/scxml/invoke-dynamic/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(invoke-dynamic LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/invoke-dynamic") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) - -qt_add_executable(invoke-dynamic - invoke-dynamic.cpp -) - -set_target_properties(invoke-dynamic PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(invoke-dynamic PUBLIC - Qt6::Core - Qt6::Gui - Qt6::Qml - Qt6::Scxml -) - -# Resources: -set_source_files_properties("../invoke-common/Button.qml" - PROPERTIES QT_RESOURCE_ALIAS "Button.qml" -) - -set_source_files_properties("../invoke-common/MainView.qml" - PROPERTIES QT_RESOURCE_ALIAS "MainView.qml" -) - -set_source_files_properties("../invoke-common/SubView.qml" - PROPERTIES QT_RESOURCE_ALIAS "SubView.qml" -) - -set_source_files_properties("../invoke-common/statemachine.scxml" - PROPERTIES QT_RESOURCE_ALIAS "statemachine.scxml" -) - -set(invoke-dynamic_resource_files - "../invoke-common/Button.qml" - "../invoke-common/MainView.qml" - "../invoke-common/SubView.qml" - "../invoke-common/statemachine.scxml" - "invoke-dynamic.qml" -) - -qt6_add_resources(invoke-dynamic "invoke-dynamic" - PREFIX - "/" - FILES - ${invoke-dynamic_resource_files} -) - -install(TARGETS invoke-dynamic - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/scxml/invoke-dynamic/doc/images/invoke-dynamic.png b/examples/scxml/invoke-dynamic/doc/images/invoke-dynamic.png deleted file mode 100644 index 4efa912..0000000 Binary files a/examples/scxml/invoke-dynamic/doc/images/invoke-dynamic.png and /dev/null differ diff --git a/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc b/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc deleted file mode 100644 index 76560ea..0000000 --- a/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example invoke-dynamic - \title Qt SCXML Invoke Example (Dynamic) - \ingroup examples-qtscxml - - \brief Invokes a dynamically loaded nested state machine. - - \image invoke-dynamic.png - - \e{Invoke Example (Dynamic)} demonstrates how to use the \c element - with generated nested state-machines, where the SCXML file is dynamically - loaded. The \c element is used to create an instance of an external - service. - - \include examples-run.qdocinc - - \section1 Invoking the State Machine - - In \e statemachine.scxml, we specify a state machine with the name - \e Directions of type \e http://www.w3.org/TR/scxml/ to invoke: - - \quotefromfile invoke-common/statemachine.scxml - \skipto scxml - \printuntil - - \section1 Dynamically Loading the State Machine - - We link against the Qt SCXML module by adding the following line to the - project build files. - - With qmake to the \e invoke-dynamic.pro - \quotefromfile invoke-dynamic/invoke-dynamic.pro - \skipto QT - \printline scxml - - With cmake to the \e CMakeLists.txt - \quotefromfile invoke-dynamic/CMakeLists.txt - \skipto find_package - \printline Scxml - \skipto target_link_libraries - \printuntil ) - - We dynamically create the state machine, as follows: - - \quotefromfile invoke-dynamic/invoke-dynamic.qml - \skipto import - \printuntil } -*/ diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.cpp b/examples/scxml/invoke-dynamic/invoke-dynamic.cpp deleted file mode 100644 index 93388fc..0000000 --- a/examples/scxml/invoke-dynamic/invoke-dynamic.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/invoke-dynamic.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; - - return app.exec(); -} diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.pro b/examples/scxml/invoke-dynamic/invoke-dynamic.pro deleted file mode 100644 index e4f07da..0000000 --- a/examples/scxml/invoke-dynamic/invoke-dynamic.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -QT += qml scxml -CONFIG += c++11 - -SOURCES += invoke-dynamic.cpp - -RESOURCES += invoke-dynamic.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/scxml/invoke-dynamic -INSTALLS += target - diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.qml b/examples/scxml/invoke-dynamic/invoke-dynamic.qml deleted file mode 100644 index a9c823d..0000000 --- a/examples/scxml/invoke-dynamic/invoke-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 - -MainView { - stateMachine: directions.stateMachine - - StateMachineLoader { - id: directions - source: "qrc:///statemachine.scxml" - } -} diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.qrc b/examples/scxml/invoke-dynamic/invoke-dynamic.qrc deleted file mode 100644 index ecf8bd1..0000000 --- a/examples/scxml/invoke-dynamic/invoke-dynamic.qrc +++ /dev/null @@ -1,9 +0,0 @@ - - - invoke-dynamic.qml - ../invoke-common/statemachine.scxml - ../invoke-common/MainView.qml - ../invoke-common/SubView.qml - ../invoke-common/Button.qml - - diff --git a/examples/scxml/invoke-static/CMakeLists.txt b/examples/scxml/invoke-static/CMakeLists.txt deleted file mode 100644 index 4ffea42..0000000 --- a/examples/scxml/invoke-static/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(invoke-static LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/invoke-static") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) - -qt_add_executable(invoke-static - invoke-static.cpp -) - -set_target_properties(invoke-static PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(invoke-static PUBLIC - Qt6::Core - Qt6::Gui - Qt6::Qml - Qt6::Scxml -) - -# Resources: -set_source_files_properties("../invoke-common/Button.qml" - PROPERTIES QT_RESOURCE_ALIAS "Button.qml" -) - -set_source_files_properties("../invoke-common/MainView.qml" - PROPERTIES QT_RESOURCE_ALIAS "MainView.qml" -) - -set_source_files_properties("../invoke-common/SubView.qml" - PROPERTIES QT_RESOURCE_ALIAS "SubView.qml" -) - -set(invoke-static_resource_files - "../invoke-common/Button.qml" - "../invoke-common/MainView.qml" - "../invoke-common/SubView.qml" - "invoke-static.qml" -) - -qt6_add_resources(invoke-static "invoke-static" - PREFIX - "/" - FILES - ${invoke-static_resource_files} -) - -# Statecharts: -qt6_add_statecharts(invoke-static - ../invoke-common/statemachine.scxml -) - -install(TARGETS invoke-static - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/scxml/invoke-static/doc/images/invoke-static.png b/examples/scxml/invoke-static/doc/images/invoke-static.png deleted file mode 100644 index fa73ebe..0000000 Binary files a/examples/scxml/invoke-static/doc/images/invoke-static.png and /dev/null differ diff --git a/examples/scxml/invoke-static/doc/src/invoke-static.qdoc b/examples/scxml/invoke-static/doc/src/invoke-static.qdoc deleted file mode 100644 index 2714dd1..0000000 --- a/examples/scxml/invoke-static/doc/src/invoke-static.qdoc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example invoke-static - \title Qt SCXML Invoke Example (Static) - \ingroup examples-qtscxml - - \brief Invokes a compiled nested state machine. - - \image invoke-static.png - - \e{Invoke Example (Static)} demonstrates how to use the \c element - with generated nested state-machines, where the SCXML file is compiled to - a C++ class. The \c element is used to create an instance of an - external service. - - \include examples-run.qdocinc - - \section1 Invoking the State Machine - - In \e statemachine.scxml, we specify a state machine with the name - \e Directions of type \e http://www.w3.org/TR/scxml/ to invoke: - - \quotefromfile invoke-common/statemachine.scxml - \skipto scxml - \printuntil - - \section1 Compiling the State Machine - We link against the Qt SCXML module by adding the following lines to the - example's build files. - - \section2 \e invoke-static.pro when using qmake: - - \quotefromfile invoke-static/invoke-static.pro - \skipto QT - \printline scxml - - We then specify the state machine to compile: - \skipto STATECHARTS - \printline scxml - - \section2 \e CMakeLists.txt when using cmake: - \quotefromfile invoke-static/CMakeLists.txt - \skipto find_package - \printline Scxml - \skipto target_link_libraries - \printuntil ) - - We then specify the state machine to compile: - \skipto qt6_add_statecharts - \printuntil ) - - The statechart directives \e STATECHARTS or \e qt6_add_statecharts invoke the Qt SCXML - Compiler, \c qscxmlc, which is run automatically to generate \e statemachine.h and - \e statemachine.cpp, which are then added appropriately as headers and sources for - compilation. - - \section1 Instantiating the State Machine - - We instantiate the generated \c Directions class in the \e invoke-static.cpp - file, as follows: - - \quotefromfile invoke-static/invoke-static.cpp - \skipto statemachine.h - \printuntil } -*/ diff --git a/examples/scxml/invoke-static/invoke-static.cpp b/examples/scxml/invoke-static/invoke-static.cpp deleted file mode 100644 index 2aa592d..0000000 --- a/examples/scxml/invoke-static/invoke-static.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include -#include -#include - -#include "statemachine.h" - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - - qmlRegisterType("Directions", 1, 0, "Directions"); - - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/invoke-static.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; - - return app.exec(); -} diff --git a/examples/scxml/invoke-static/invoke-static.pro b/examples/scxml/invoke-static/invoke-static.pro deleted file mode 100644 index e2e206c..0000000 --- a/examples/scxml/invoke-static/invoke-static.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = app - -QT += qml scxml -CONFIG += c++11 - -SOURCES += invoke-static.cpp - -RESOURCES += invoke-static.qrc - -STATECHARTS = ../invoke-common/statemachine.scxml - -target.path = $$[QT_INSTALL_EXAMPLES]/scxml/invoke-static -INSTALLS += target - diff --git a/examples/scxml/invoke-static/invoke-static.qml b/examples/scxml/invoke-static/invoke-static.qml deleted file mode 100644 index e28a6f2..0000000 --- a/examples/scxml/invoke-static/invoke-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 Directions 1.0 - -MainView { - stateMachine: Directions { - running: true - } -} diff --git a/examples/scxml/invoke-static/invoke-static.qrc b/examples/scxml/invoke-static/invoke-static.qrc deleted file mode 100644 index cc5bcad..0000000 --- a/examples/scxml/invoke-static/invoke-static.qrc +++ /dev/null @@ -1,8 +0,0 @@ - - - invoke-static.qml - ../invoke-common/MainView.qml - ../invoke-common/SubView.qml - ../invoke-common/Button.qml - - diff --git a/examples/scxml/invoke/Button.qml b/examples/scxml/invoke/Button.qml new file mode 100644 index 0000000..0b7e6b2 --- /dev/null +++ b/examples/scxml/invoke/Button.qml @@ -0,0 +1,35 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +Item { + id: button + signal clicked + property string text: "hello" + property bool enabled: true + opacity: enabled ? 1.0 : 0.5 + + Rectangle { + x: 5 + y: 5 + width: parent.width - 10 + height: parent.height - 10 + radius: 5 + color: "lightsteelblue" + + Text { + anchors.fill: parent + color: "white" + text: button.text + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + MouseArea { + id: mouse + anchors.fill: parent + onClicked: if (button.enabled) button.clicked() + } + } +} diff --git a/examples/scxml/invoke/CMakeLists.txt b/examples/scxml/invoke/CMakeLists.txt new file mode 100644 index 0000000..93bbf58 --- /dev/null +++ b/examples/scxml/invoke/CMakeLists.txt @@ -0,0 +1,56 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(invoke LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/invoke") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) + +qt_add_executable(invoke + invoke.cpp +) + +set_target_properties(invoke PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(invoke PUBLIC + Qt6::Core + Qt6::Gui + Qt6::Qml + Qt6::Scxml +) + +set(invoke_resource_files + "Button.qml" + "MainView.qml" + "SubView.qml" + "invoke.qml" +) + +qt6_add_resources(invoke "invoke" + PREFIX + "/" + FILES + ${invoke_resource_files} +) + +# Statecharts: +qt6_add_statecharts(invoke + statemachine.scxml +) + +install(TARGETS invoke + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/scxml/invoke/MainView.qml b/examples/scxml/invoke/MainView.qml new file mode 100644 index 0000000..6ae5155 --- /dev/null +++ b/examples/scxml/invoke/MainView.qml @@ -0,0 +1,58 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Window +import QtScxml + +Window { + id: window + visible: true + property StateMachine stateMachine + + color: "black" + width: 400 + height: 300 + + Item { + width: parent.width / 2 + height: parent.height + + Button { + id: nowhere + text: "Go Nowhere" + width: parent.width + height: parent.height / 2 + onClicked: stateMachine.submitEvent("goNowhere") + enabled: stateMachine.somewhere + } + + Button { + id: somewhere + text: "Go Somewhere" + width: parent.width + height: parent.height / 2 + y: parent.height / 2 + onClicked: stateMachine.submitEvent("goSomewhere") + enabled: stateMachine.nowhere + } + } + + Loader { + source: "SubView.qml" + active: stateMachine.somewhere + + x: parent.width / 2 + width: parent.width / 2 + height: parent.height + + InvokedServices { + id: services + stateMachine: window.stateMachine + } + + property var anywhere: services.children.anywhere ? services.children.anywhere.stateMachine + : undefined + } +} + diff --git a/examples/scxml/invoke/SubView.qml b/examples/scxml/invoke/SubView.qml new file mode 100644 index 0000000..413227b --- /dev/null +++ b/examples/scxml/invoke/SubView.qml @@ -0,0 +1,26 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +Item { + // "anywhere" is a context property, so we always have to check if it's null + Button { + id: here + enabled: anywhere ? anywhere.here : false + text: "Go There" + width: parent.width / 2 + height: parent.height + onClicked: anywhere.submitEvent("goThere") + } + + Button { + id: there + enabled: anywhere ? anywhere.there : false + text: "Go Here" + width: parent.width / 2 + height: parent.height + x: width + onClicked: anywhere.submitEvent("goHere") + } +} diff --git a/examples/scxml/invoke/doc/images/invoke.png b/examples/scxml/invoke/doc/images/invoke.png new file mode 100644 index 0000000..fa73ebe Binary files /dev/null and b/examples/scxml/invoke/doc/images/invoke.png differ diff --git a/examples/scxml/invoke/doc/src/invoke.qdoc b/examples/scxml/invoke/doc/src/invoke.qdoc new file mode 100644 index 0000000..8c1ff95 --- /dev/null +++ b/examples/scxml/invoke/doc/src/invoke.qdoc @@ -0,0 +1,67 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \example invoke + \title Qt SCXML Invoke Example + \ingroup examples-qtscxml + + \brief Invokes a compiled nested state machine. + + \image invoke.png + + \e{Invoke Example} demonstrates how to use the \c element + with generated nested state-machines, where the SCXML file is compiled to + a C++ class. The \c element is used to create an instance of an + external service. + + \include examples-run.qdocinc + + \section1 Invoking the State Machine + + In \e statemachine.scxml, we specify a state machine with the name + \e Directions of type \e http://www.w3.org/TR/scxml/ to invoke: + + \quotefromfile invoke/statemachine.scxml + \skipto scxml + \printuntil + + \section1 Compiling the State Machine + We link against the Qt SCXML module by adding the following lines to the + example's build files. + + \section2 \e invoke.pro when using qmake: + + \quotefromfile invoke/invoke.pro + \skipto QT + \printline scxml + + We then specify the state machine to compile: + \skipto STATECHARTS + \printline scxml + + \section2 \e CMakeLists.txt when using cmake: + \quotefromfile invoke/CMakeLists.txt + \skipto find_package + \printline Scxml + \skipto target_link_libraries + \printuntil ) + + We then specify the state machine to compile: + \skipto qt6_add_statecharts + \printuntil ) + + The statechart directives \e STATECHARTS or \e qt6_add_statecharts invoke the Qt SCXML + Compiler, \c qscxmlc, which is run automatically to generate \e statemachine.h and + \e statemachine.cpp, which are then added appropriately as headers and sources for + compilation. + + \section1 Instantiating the State Machine + + We instantiate the generated \c Directions class in the \e invoke.cpp + file, as follows: + + \quotefromfile invoke/invoke.cpp + \skipto statemachine.h + \printuntil } +*/ diff --git a/examples/scxml/invoke/invoke.cpp b/examples/scxml/invoke/invoke.cpp new file mode 100644 index 0000000..9a64243 --- /dev/null +++ b/examples/scxml/invoke/invoke.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include +#include +#include + +#include "statemachine.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + qmlRegisterType("Directions", 1, 0, "Directions"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/invoke.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/examples/scxml/invoke/invoke.pro b/examples/scxml/invoke/invoke.pro new file mode 100644 index 0000000..866ecdb --- /dev/null +++ b/examples/scxml/invoke/invoke.pro @@ -0,0 +1,14 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += invoke.cpp + +RESOURCES += invoke.qrc + +STATECHARTS = statemachine.scxml + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/invoke +INSTALLS += target + diff --git a/examples/scxml/invoke/invoke.qml b/examples/scxml/invoke/invoke.qml new file mode 100644 index 0000000..e28a6f2 --- /dev/null +++ b/examples/scxml/invoke/invoke.qml @@ -0,0 +1,10 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import Directions 1.0 + +MainView { + stateMachine: Directions { + running: true + } +} diff --git a/examples/scxml/invoke/invoke.qrc b/examples/scxml/invoke/invoke.qrc new file mode 100644 index 0000000..24c0e89 --- /dev/null +++ b/examples/scxml/invoke/invoke.qrc @@ -0,0 +1,8 @@ + + + invoke.qml + MainView.qml + SubView.qml + Button.qml + + diff --git a/examples/scxml/invoke/statemachine.scxml b/examples/scxml/invoke/statemachine.scxml new file mode 100644 index 0000000..6a0f5a9 --- /dev/null +++ b/examples/scxml/invoke/statemachine.scxml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/scxml/scxml.pro b/examples/scxml/scxml.pro index c7415a5..0c6b6a3 100644 --- a/examples/scxml/scxml.pro +++ b/examples/scxml/scxml.pro @@ -13,8 +13,7 @@ qtHaveModule(quick) { SUBDIRS += trafficlight-qml-dynamic SUBDIRS += trafficlight-qml-simple SUBDIRS += mediaplayer - SUBDIRS += invoke-static - SUBDIRS += invoke-dynamic + SUBDIRS += invoke } SUBDIRS += ftpclient -- cgit v1.2.3