summaryrefslogtreecommitdiffstats
path: root/src/statemachine/doc/snippets/qml/statemachine
diff options
context:
space:
mode:
Diffstat (limited to 'src/statemachine/doc/snippets/qml/statemachine')
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/Button.qml51
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/basicstate.qml18
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/finalstate.qml26
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/guardcondition.qml31
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/historystate.qml48
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/signaltransition.qml40
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/signaltransitionsignal.qml25
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/simplestatemachine.qml31
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/statemachine-button-history.qml112
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml97
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested.qml89
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/statemachine-button.qml63
-rw-r--r--src/statemachine/doc/snippets/qml/statemachine/timeouttransition.qml32
13 files changed, 663 insertions, 0 deletions
diff --git a/src/statemachine/doc/snippets/qml/statemachine/Button.qml b/src/statemachine/doc/snippets/qml/statemachine/Button.qml
new file mode 100644
index 0000000..b968a18
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/Button.qml
@@ -0,0 +1,51 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Window
+
+Item {
+ id: container
+
+ property alias text: buttonLabel.text
+ property alias label: buttonLabel
+ signal clicked
+ property alias containsMouse: mouseArea.containsMouse
+ property alias pressed: mouseArea.pressed
+ implicitHeight: Math.max(Screen.pixelDensity * 7, buttonLabel.implicitHeight * 1.2)
+ implicitWidth: Math.max(Screen.pixelDensity * 11, buttonLabel.implicitWidth * 1.3)
+ height: implicitHeight
+ width: implicitWidth
+ property bool checkable: false
+ property bool checked: false
+
+ SystemPalette { id: palette }
+
+ Rectangle {
+ id: frame
+ anchors.fill: parent
+ color: palette.button
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: mouseArea.pressed ? Qt.darker(palette.button, 1.3) : palette.button }
+ GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) }
+ }
+ antialiasing: true
+ radius: height / 6
+ border.color: Qt.darker(palette.button, 1.5)
+ border.width: 1
+ }
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ onClicked: container.clicked()
+ hoverEnabled: true
+ }
+
+ Text {
+ id: buttonLabel
+ text: container.text
+ color: palette.buttonText
+ anchors.centerIn: parent
+ }
+}
diff --git a/src/statemachine/doc/snippets/qml/statemachine/basicstate.qml b/src/statemachine/doc/snippets/qml/statemachine/basicstate.qml
new file mode 100644
index 0000000..dac2914
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/basicstate.qml
@@ -0,0 +1,18 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ DSM.State {
+ id: state
+ }
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/finalstate.qml b/src/statemachine/doc/snippets/qml/statemachine/finalstate.qml
new file mode 100644
index 0000000..160419a
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/finalstate.qml
@@ -0,0 +1,26 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ DSM.State {
+ id: state
+ DSM.TimeoutTransition {
+ targetState: finalState
+ timeout: 200
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ onFinished: console.log("state finished")
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/guardcondition.qml b/src/statemachine/doc/snippets/qml/statemachine/guardcondition.qml
new file mode 100644
index 0000000..9bacea3
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/guardcondition.qml
@@ -0,0 +1,31 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ DSM.StateMachine {
+ DSM.State {
+ DSM.SignalTransition {
+ targetState: finalState
+ signal: button.mysignal
+ // the guard condition uses the mystr string argument from mysignal
+ guard: mystr == "test"
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ }
+ // define the signal the SignalTransition is connected with
+ signal mysignal(mystr: string)
+ // on clicking the button emit the signal with a single string argument
+ onClicked: button.mysignal("test")
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/historystate.qml b/src/statemachine/doc/snippets/qml/statemachine/historystate.qml
new file mode 100644
index 0000000..e3e7a43
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/historystate.qml
@@ -0,0 +1,48 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Press me"
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: parentState
+ running: true
+ DSM.State {
+ id: parentState
+ initialState: child2
+ onEntered: console.log("parentState entered")
+ onExited: console.log("parentState exited")
+ DSM.State {
+ id: child1
+ onEntered: console.log("child1 entered")
+ onExited: console.log("child1 exited")
+ }
+ DSM.State {
+ id: child2
+ onEntered: console.log("child2 entered")
+ onExited: console.log("child2 exited")
+ }
+ DSM.HistoryState {
+ id: historyState
+ defaultState: child1
+ }
+ DSM.SignalTransition {
+ targetState: historyState
+
+ // Clicking the button will cause the state machine to enter the child state
+ // that parentState was in the last time parentState was exited, or the history state's default
+ // state if parentState has never been entered.
+ signal: button.clicked
+ }
+ }
+ }
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/signaltransition.qml b/src/statemachine/doc/snippets/qml/statemachine/signaltransition.qml
new file mode 100644
index 0000000..3d7b4b0
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/signaltransition.qml
@@ -0,0 +1,40 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ DSM.State {
+ id: state
+ DSM.SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ guard: guardButton.checked
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ onFinished: Qt.quit()
+ }
+ Row {
+ spacing: 2
+ Button {
+ id: button
+ text: "Finish state"
+ }
+
+ Button {
+ id: guardButton
+ checkable: true
+ text: checked ? "Press to block the SignalTransition" : "Press to unblock the SignalTransition"
+ }
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/signaltransitionsignal.qml b/src/statemachine/doc/snippets/qml/statemachine/signaltransitionsignal.qml
new file mode 100644
index 0000000..2aeae2a
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/signaltransitionsignal.qml
@@ -0,0 +1,25 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ DSM.StateMachine {
+ DSM.State {
+ DSM.SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ }
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/simplestatemachine.qml b/src/statemachine/doc/snippets/qml/statemachine/simplestatemachine.qml
new file mode 100644
index 0000000..cd7e01e
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/simplestatemachine.qml
@@ -0,0 +1,31 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Finish state"
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ DSM.State {
+ id: state
+ DSM.SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ onFinished: Qt.quit()
+ }
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-history.qml b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-history.qml
new file mode 100644
index 0000000..e5947ae
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-history.qml
@@ -0,0 +1,112 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine
+
+Rectangle {
+//![0]
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : s13.active ? "s13" : "s3"
+ }
+ Button {
+ id: interruptButton
+ text: s1.active ? "Interrupt" : "Resume"
+ }
+ Button {
+ id: quitButton
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ State {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ State {
+ id: s11
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+ State {
+ id: s12
+ // create a transition from s2 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+ State {
+ id: s13
+ // create a transition from s3 to s1 when the button is clicked
+ SignalTransition {
+ targetState: s1
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+
+ // create a transition from s1 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s3
+ signal: interruptButton.clicked
+ }
+ HistoryState {
+ id: s1h
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ State {
+ id: s3
+ SignalTransition {
+ targetState: s1h
+ signal: interruptButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s3 entered")
+ onExited: console.log("s3 exited")
+ }
+ onFinished: Qt.quit()
+ }
+//![0]
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml
new file mode 100644
index 0000000..db40f79
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml
@@ -0,0 +1,97 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine
+
+Rectangle {
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : "s13"
+ }
+ Button {
+ id: quitButton
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ State {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ State {
+ id: s11
+ // create a transition from s11 to s12 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+//![0]
+ State {
+ id: s12
+ // create a transition from s12 to s13 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+
+ // ignore Quit button when we are in state 12
+ SignalTransition {
+ targetState: s12
+ signal: quitButton.clicked
+ }
+
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+//![0]
+
+ State {
+ id: s13
+ // create a transition from s13 to s11 when the button is clicked
+ SignalTransition {
+ targetState: s11
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ onFinished: Qt.quit()
+ }
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested.qml b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested.qml
new file mode 100644
index 0000000..eae7427
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button-nested.qml
@@ -0,0 +1,89 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine
+
+Rectangle {
+//![0]
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : "s13"
+ }
+ Button {
+ id: quitButton
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ State {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ State {
+ id: s11
+ // create a transition from s11 to s12 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+ State {
+ id: s12
+ // create a transition from s12 to s13 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+ State {
+ id: s13
+ // create a transition from s13 to s11 when the button is clicked
+ SignalTransition {
+ targetState: s11
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ onFinished: Qt.quit()
+ }
+//![0]
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/statemachine-button.qml b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button.qml
new file mode 100644
index 0000000..8873117
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/statemachine-button.qml
@@ -0,0 +1,63 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine
+
+Rectangle {
+//![0]
+ Button {
+ anchors.fill: parent
+ id: button
+
+ // change the button label to the active state id
+ text: s1.active ? "s1" : s2.active ? "s2" : "s3"
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ State {
+ id: s1
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ }
+
+ State {
+ id: s2
+ // create a transition from s2 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s3
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ State {
+ id: s3
+ // create a transition from s3 to s1 when the button is clicked
+ SignalTransition {
+ targetState: s1
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s3 entered")
+ onExited: console.log("s3 exited")
+ }
+ }
+//![0]
+}
+//! [document]
diff --git a/src/statemachine/doc/snippets/qml/statemachine/timeouttransition.qml b/src/statemachine/doc/snippets/qml/statemachine/timeouttransition.qml
new file mode 100644
index 0000000..60bd420
--- /dev/null
+++ b/src/statemachine/doc/snippets/qml/statemachine/timeouttransition.qml
@@ -0,0 +1,32 @@
+// Copyright (C) 2014 Ford Motor Company
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [document]
+import QtQuick
+import QtQml.StateMachine as DSM
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Finish state"
+ enabled: !stateMachine.running
+ onClicked: stateMachine.running = true
+ DSM.StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ DSM.State {
+ id: state
+ DSM.TimeoutTransition {
+ targetState: finalState
+ timeout: 1000
+ }
+ }
+ DSM.FinalState {
+ id: finalState
+ }
+ }
+ }
+}
+//! [document]