1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Ford Motor Company |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "state.h" |
41 | |
42 | #include <QQmlContext> |
43 | #include <QQmlEngine> |
44 | #include <QQmlInfo> |
45 | |
46 | State::State(QState *parent) |
47 | : QState(parent) |
48 | { |
49 | } |
50 | |
51 | void State::componentComplete() |
52 | { |
53 | if (this->machine() == nullptr) { |
54 | static bool once = false; |
55 | if (!once) { |
56 | once = true; |
57 | qmlWarning(me: this) << "No top level StateMachine found. Nothing will run without a StateMachine." ; |
58 | } |
59 | } |
60 | } |
61 | |
62 | QQmlListProperty<QObject> State::children() |
63 | { |
64 | return QQmlListProperty<QObject>(this, &m_children, |
65 | m_children.append, m_children.count, m_children.at, |
66 | m_children.clear, m_children.replace, m_children.removeLast); |
67 | } |
68 | |
69 | /*! |
70 | \qmltype QAbstractState |
71 | \inqmlmodule QtQml.StateMachine |
72 | \omit |
73 | \ingroup statemachine-qmltypes |
74 | \endomit |
75 | \since 5.4 |
76 | |
77 | \brief The QAbstractState type is the base type of States of a StateMachine. |
78 | |
79 | Do not use QAbstractState directly; use State, FinalState or |
80 | StateMachine instead. |
81 | |
82 | \sa StateMachine, State |
83 | */ |
84 | |
85 | /*! |
86 | \qmlproperty bool QAbstractState::active |
87 | \readonly active |
88 | |
89 | The active property of this state. A state is active between |
90 | entered() and exited() signals. This property is readonly. |
91 | |
92 | \sa entered, exited |
93 | */ |
94 | |
95 | /*! |
96 | \qmlsignal QAbstractState::entered() |
97 | |
98 | This signal is emitted when the State becomes active. |
99 | |
100 | \sa active, exited |
101 | */ |
102 | |
103 | /*! |
104 | \qmlsignal QAbstractState::exited() |
105 | |
106 | This signal is emitted when the State becomes inactive. |
107 | |
108 | \sa active, entered |
109 | */ |
110 | |
111 | /*! |
112 | \qmltype State |
113 | \inqmlmodule QtQml.StateMachine |
114 | \inherits QAbstractState |
115 | \ingroup statemachine-qmltypes |
116 | \since 5.4 |
117 | |
118 | \brief Provides a general-purpose state for StateMachine. |
119 | |
120 | State objects can have child states as well as transitions to other |
121 | states. State is part of \l{The Declarative State Machine Framework}. |
122 | |
123 | \section1 States with Child States |
124 | |
125 | The childMode property determines how child states are treated. For |
126 | non-parallel state groups, the initialState property must be used to |
127 | set the initial state. The child states are mutually exclusive states, |
128 | and the state machine needs to know which child state to enter when the |
129 | parent state is the target of a transition. |
130 | |
131 | The state emits the State::finished() signal when a final child state |
132 | (FinalState) is entered. |
133 | |
134 | The errorState sets the state's error state. The error state is the state |
135 | that the state machine will transition to if an error is detected when |
136 | attempting to enter the state (e.g. because no initial state has been set). |
137 | |
138 | \section1 Example Usage |
139 | |
140 | \snippet qml/statemachine/basicstate.qml document |
141 | |
142 | \clearfloat |
143 | |
144 | \sa StateMachine, FinalState |
145 | */ |
146 | |
147 | /*! |
148 | \qmlproperty enumeration State::childMode |
149 | |
150 | \brief The child mode of this state |
151 | |
152 | The default value of this property is QState.ExclusiveStates. |
153 | |
154 | This enum specifies how a state's child states are treated: |
155 | \list |
156 | \li QState.ExclusiveStates The child states are mutually exclusive and an initial state must be set by setting initialState property. |
157 | \li QState.ParallelStates The child states are parallel. When the parent state is entered, all its child states are entered in parallel. |
158 | \endlist |
159 | */ |
160 | |
161 | /*! |
162 | \qmlproperty QAbstractState State::errorState |
163 | |
164 | \brief The error state of this state. |
165 | */ |
166 | |
167 | /*! |
168 | \qmlproperty QAbstractState State::initialState |
169 | |
170 | \brief The initial state of this state (one of its child states). |
171 | */ |
172 | |
173 | /*! |
174 | \qmlsignal State::finished() |
175 | |
176 | This signal is emitted when a final child state of this state is entered. |
177 | |
178 | \sa QAbstractState::active, QAbstractState::entered, QAbstractState::exited |
179 | */ |
180 | |
181 | /*! |
182 | \qmltype HistoryState |
183 | \inqmlmodule QtQml.StateMachine |
184 | \inherits QAbstractState |
185 | \ingroup statemachine-qmltypes |
186 | \since 5.4 |
187 | |
188 | \brief The HistoryState type provides a means of returning to a previously active substate. |
189 | |
190 | A history state is a pseudo-state that represents the child state that the |
191 | parent state was in the last time the parent state was exited. A transition |
192 | with a history state as its target is in fact a transition to one of the |
193 | other child states of the parent state. |
194 | HistoryState is part of \l{The Declarative State Machine Framework}. |
195 | |
196 | Use the defaultState property to set the state that should be entered |
197 | if the parent state has never been entered. |
198 | |
199 | \section1 Example Usage |
200 | |
201 | \snippet qml/statemachine/historystate.qml document |
202 | |
203 | \clearfloat |
204 | |
205 | By default, a history state is shallow, meaning that it will not remember |
206 | nested states. This can be configured through the historyType property. |
207 | |
208 | \sa StateMachine, State |
209 | */ |
210 | |
211 | /*! |
212 | \qmlproperty QAbstractState HistoryState::defaultState |
213 | |
214 | \brief The default state of this history state. |
215 | |
216 | The default state indicates the state to transition to if the parent |
217 | state has never been entered before. |
218 | */ |
219 | |
220 | /*! |
221 | \qmlproperty enumeration HistoryState::historyType |
222 | |
223 | \brief The type of history that this history state records. |
224 | |
225 | The default value of this property is HistoryState.ShallowHistory. |
226 | |
227 | This enum specifies the type of history that a HistoryState records. |
228 | \list |
229 | \li HistoryState.ShallowHistory Only the immediate child states of the |
230 | parent state are recorded. In this case, a transition with the history |
231 | state as its target will end up in the immediate child state that the |
232 | parent was in the last time it was exited. This is the default. |
233 | \li HistoryState.DeepHistory Nested states are recorded. In this case |
234 | a transition with the history state as its target will end up in the |
235 | most deeply nested descendant state the parent was in the last time |
236 | it was exited. |
237 | \endlist |
238 | */ |
239 | |
240 | #include "moc_state.cpp" |
241 | |