diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | examples/trafficlight-common/Button.qml (renamed from examples/trafficlight-qml-static/trafficlight-dynamic.qml) | 75 | ||||
-rw-r--r-- | examples/trafficlight-common/TrafficLight.qml | 147 | ||||
-rw-r--r-- | examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml | 64 | ||||
-rw-r--r-- | examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc | 2 | ||||
-rw-r--r-- | examples/trafficlight-qml-static/trafficlight-qml-dynamic.qmlproject | 19 | ||||
-rw-r--r-- | examples/trafficlight-qml-static/trafficlight-qml-static.qml | 122 | ||||
-rw-r--r-- | examples/trafficlight-qml-static/trafficlight-qml-static.qrc | 2 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/state.cpp | 12 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/state.h | 1 |
10 files changed, 190 insertions, 260 deletions
@@ -18,9 +18,9 @@ qrc_*.cpp tst_scion .qmake.cache *.pch -tests/scion/compiled_tests.h -tests/scion/scxml -tests/scion/scion.h +tests/auto/scion/compiled_tests.h +tests/auto/scion/scxml +tests/auto/scion/scion.h examples/trafficlight-qml/statemachine.cpp examples/trafficlight-qml/statemachine.h diff --git a/examples/trafficlight-qml-static/trafficlight-dynamic.qml b/examples/trafficlight-common/Button.qml index 4bfc9fc..9bfbf8e 100644 --- a/examples/trafficlight-qml-static/trafficlight-dynamic.qml +++ b/examples/trafficlight-common/Button.qml @@ -39,65 +39,32 @@ ****************************************************************************/ import QtQuick 2.5 -import QtQuick.Window 2.2 -import Scxml 1.0 as Scxml -Window { - visible: true - width: 100 - height: 300 - color: "black" +Item { + id: button + signal clicked + property string text: "hello" - MouseArea { - anchors.fill: parent - onClicked: { - Qt.quit(); - } - } - - Light { - id: redLight - anchors.top: parent.top - color: "red" - visible: red.active || redGoingGreen.active - } - - Light { - id: yellowLight - anchors.top: redLight.bottom - color: "yellow" - visible: yellow.active - } - - Light { - id: greenLight - anchors.top: yellowLight.bottom - color: "green" - visible: green.active - } - - Scxml.StateMachine { - filename: "statemachine.scxml" - - Scxml.State { - id: red - scxmlName: "red" - } + Rectangle { + x: 5 + y: 5 + width: parent.width - 10 + height: parent.height - 10 + radius: 5 + color: "blue" - Scxml.State { - id: yellow - scxmlName: "yellow" + Text { + anchors.fill: parent + color: "white" + text: button.text + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter } - Scxml.State { - id: redGoingGreen - scxmlName: "red-going-green" - } - - Scxml.State { - id: green - scxmlName: "green" + MouseArea { + id: mouse + anchors.fill: parent + onClicked: button.clicked() } } } - diff --git a/examples/trafficlight-common/TrafficLight.qml b/examples/trafficlight-common/TrafficLight.qml new file mode 100644 index 0000000..d3a19a8 --- /dev/null +++ b/examples/trafficlight-common/TrafficLight.qml @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 Scxml 1.0 as Scxml + +Window { + id: root + property QtObject stateMachine + property url filename + + visible: true + width: 100 + height: 350 + color: "black" + + Item { + id: lights + width: parent.width + height: 300 + + MouseArea { + anchors.fill: parent + onClicked: { + Qt.quit(); + } + } + + Light { + id: redLight + anchors.top: parent.top + color: "red" + visible: red.active || redGoingGreen.active + } + + Light { + id: yellowLight + anchors.top: redLight.bottom + color: "yellow" + visible: yellow.active || blinking.active + } + + Light { + id: greenLight + anchors.top: yellowLight.bottom + color: "green" + visible: green.active + } + } + + Button { + id: button + width: parent.width + anchors.top: lights.bottom + anchors.bottom: parent.bottom + + text: { + if (working.active) + "Pause" + else + "Unpause" + } + } + + Scxml.StateMachine { + stateMachine: root.stateMachine + filename: root.filename + + Scxml.State { + id: red + scxmlName: "red" + } + + Scxml.State { + id: yellow + scxmlName: "yellow" + } + + Scxml.State { + id: redGoingGreen + scxmlName: "red-going-green" + } + + Scxml.State { + id: green + scxmlName: "green" + } + + Scxml.State { + id: blinking + scxmlName: "blinking" + } + + Scxml.State { + id: working + scxmlName: "working" + } + + Scxml.SignalEvent { + signal: button.clicked + eventName: { + if (working.active) + "smash" + else + "repair" + } + } + } +} diff --git a/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml b/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml index b178384..b3a7525 100644 --- a/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml +++ b/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml @@ -38,66 +38,6 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Window 2.2 -import Scxml 1.0 as Scxml - -Window { - visible: true - width: 100 - height: 300 - color: "black" - - MouseArea { - anchors.fill: parent - onClicked: { - Qt.quit(); - } - } - - Light { - id: redLight - anchors.top: parent.top - color: "red" - visible: red.active || redGoingGreen.active - } - - Light { - id: yellowLight - anchors.top: redLight.bottom - color: "yellow" - visible: yellow.active - } - - Light { - id: greenLight - anchors.top: yellowLight.bottom - color: "green" - visible: green.active - } - - Scxml.StateMachine { - filename: "qrc:///statemachine.scxml" - - Scxml.State { - id: red - scxmlName: "red" - } - - Scxml.State { - id: yellow - scxmlName: "yellow" - } - - Scxml.State { - id: redGoingGreen - scxmlName: "red-going-green" - } - - Scxml.State { - id: green - scxmlName: "green" - } - } +TrafficLight { + filename: "qrc:///statemachine.scxml" } - diff --git a/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc b/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc index b4bcaec..fa110f2 100644 --- a/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc +++ b/examples/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc @@ -1,6 +1,8 @@ <RCC> <qresource prefix="/"> + <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> <file alias="Light.qml">../trafficlight-common/Light.qml</file> + <file alias="Button.qml">../trafficlight-common/Button.qml</file> <file>trafficlight-qml-dynamic.qml</file> <file alias="statemachine.scxml">../trafficlight-common/statemachine.scxml</file> </qresource> diff --git a/examples/trafficlight-qml-static/trafficlight-qml-dynamic.qmlproject b/examples/trafficlight-qml-static/trafficlight-qml-dynamic.qmlproject deleted file mode 100644 index 5f06f00..0000000 --- a/examples/trafficlight-qml-static/trafficlight-qml-dynamic.qmlproject +++ /dev/null @@ -1,19 +0,0 @@ -import QmlProject 1.1 - -Project { - mainFile: "trafficlight-dynamic.qml" - - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ "../exampleplugin" ] -} - diff --git a/examples/trafficlight-qml-static/trafficlight-qml-static.qml b/examples/trafficlight-qml-static/trafficlight-qml-static.qml index 92a9d9a..0c815b5 100644 --- a/examples/trafficlight-qml-static/trafficlight-qml-static.qml +++ b/examples/trafficlight-qml-static/trafficlight-qml-static.qml @@ -38,124 +38,6 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Window 2.2 -import Scxml 1.0 as Scxml - -Window { - visible: true - width: 100 - height: 350 - color: "black" - - Item { - id: lights - width: parent.width - height: 300 - - MouseArea { - anchors.fill: parent - onClicked: { - Qt.quit(); - } - } - - Light { - id: redLight - anchors.top: parent.top - color: "red" - visible: red.active || redGoingGreen.active - } - - Light { - id: yellowLight - anchors.top: redLight.bottom - color: "yellow" - visible: yellow.active || blinking.active - } - - Light { - id: greenLight - anchors.top: yellowLight.bottom - color: "green" - visible: green.active - } - } - - Item { - width: parent.width - anchors.top: lights.bottom - anchors.bottom: parent.bottom - - Rectangle { - x: 5 - y: 5 - width: parent.width - 10 - height: parent.height - 10 - radius: 5 - color: "blue" - - Text { - anchors.fill: parent - color: "white" - text: { - if (working.active) - "Pause" - else - "Unpause" - } - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - } - - MouseArea { - id: button - anchors.fill: parent - } - } - } - - Scxml.StateMachine { - stateMachine: trafficLightStateMachine - - Scxml.State { - id: red - scxmlName: "red" - } - - Scxml.State { - id: yellow - scxmlName: "yellow" - } - - Scxml.State { - id: redGoingGreen - scxmlName: "red-going-green" - } - - Scxml.State { - id: green - scxmlName: "green" - } - - Scxml.State { - id: blinking - scxmlName: "blinking" - } - - Scxml.State { - id: working - scxmlName: "working" - } - - Scxml.SignalEvent { - signal: button.clicked - eventName: { - if (working.active) - "smash" - else - "repair" - } - } - } +TrafficLight { + stateMachine: trafficLightStateMachine } diff --git a/examples/trafficlight-qml-static/trafficlight-qml-static.qrc b/examples/trafficlight-qml-static/trafficlight-qml-static.qrc index 4d1051d..d75853c 100644 --- a/examples/trafficlight-qml-static/trafficlight-qml-static.qrc +++ b/examples/trafficlight-qml-static/trafficlight-qml-static.qrc @@ -1,6 +1,8 @@ <RCC> <qresource prefix="/"> <file>trafficlight-qml-static.qml</file> + <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> <file alias="Light.qml">../trafficlight-common/Light.qml</file> + <file alias="Button.qml">../trafficlight-common/Button.qml</file> </qresource> </RCC> diff --git a/src/imports/scxmlstatemachine/state.cpp b/src/imports/scxmlstatemachine/state.cpp index da240b4..7f845b3 100644 --- a/src/imports/scxmlstatemachine/state.cpp +++ b/src/imports/scxmlstatemachine/state.cpp @@ -33,8 +33,11 @@ void State::componentComplete() completed = true; establishConnections(); - if (Scxml::StateTable *table = qobject_cast<StateMachine *>(parent())->stateMachine()) + StateMachine *stateMachine = qobject_cast<StateMachine *>(parent()); + if (Scxml::StateTable *table = stateMachine->stateMachine()) { active = table->currentStates().contains(m_scxmlName); + connect(stateMachine, SIGNAL(filenameChanged()), this, SLOT(onFilenameChanged())); + } if (active) emit activeChanged(active); } @@ -65,6 +68,12 @@ void State::setActive(bool active) emit activeChanged(active); } +void State::onFilenameChanged() +{ + breakConnections(); + establishConnections(); +} + void State::breakConnections() { disconnect(activeConnection); @@ -79,7 +88,6 @@ void State::establishConnections() Scxml::StateTable *table = qobject_cast<StateMachine *>(parent())->stateMachine(); if (table == nullptr) { - qmlInfo(this) << QStringLiteral("State is not part of a StateTable."); return; } diff --git a/src/imports/scxmlstatemachine/state.h b/src/imports/scxmlstatemachine/state.h index 53c3e37..de158ed 100644 --- a/src/imports/scxmlstatemachine/state.h +++ b/src/imports/scxmlstatemachine/state.h @@ -55,6 +55,7 @@ Q_SIGNALS: private Q_SLOTS: void setActive(bool active); + void onFilenameChanged(); private: void breakConnections(); |