aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/statemachine/state.cpp
blob: 56ecd015f58caa3d05146bfec6add21ef1a2aa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/****************************************************************************
**
** Copyright (C) 2014 Ford Motor Company
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "state.h"

#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlInfo>

State::State(QState *parent)
    : QState(parent)
{
}

void State::componentComplete()
{
    if (this->machine() == NULL) {
        static bool once = false;
        if (!once) {
            once = true;
            qmlInfo(this) << "No top level StateMachine found.  Nothing will run without a StateMachine.";
        }
    }
}

QQmlListProperty<QObject> State::children()
{
    return QQmlListProperty<QObject>(this, &m_children, m_children.append, m_children.count, m_children.at, m_children.clear);
}

/*!
    \qmltype QAbstractState
    \inqmlmodule QtQml.StateMachine
    \omit
    \ingroup statemachine-qmltypes
    \endomit
    \since 5.4

    \brief The QAbstractState type is the base type of States of a StateMachine.

    Do not use QAbstractState directly; use State, FinalState or
    StateMachine instead.

    \sa StateMachine, State
*/

/*!
    \qmlproperty bool QAbstractState::active
    \readonly active

    The active property of this state. A state is active between
    entered() and exited() signals. This property is readonly.

    \sa entered, exited
*/

/*!
    \qmlsignal QAbstractState::entered()

    This signal is emitted when the State becomes active.

    The corresponding handler is \c onEntered.

    \sa active, exited
*/

/*!
    \qmlsignal QAbstractState::exited()

    This signal is emitted when the State becomes inactive.

    The corresponding handler is \c onExited.

    \sa active, entered
*/

/*!
    \qmltype State
    \inqmlmodule QtQml.StateMachine
    \inherits QAbstractState
    \ingroup statemachine-qmltypes
    \since 5.4

    \brief Provides a general-purpose state for StateMachine.


    State objects can have child states as well as transitions to other
    states. State is part of \l{The Declarative State Machine Framework}.

    \section1 States with Child States

    The childMode property determines how child states are treated.  For
    non-parallel state groups, the initialState property must be used to
    set the initial state.  The child states are mutually exclusive states,
    and the state machine needs to know which child state to enter when the
    parent state is the target of a transition.

    The state emits the State::finished() signal when a final child state
    (FinalState) is entered.

    The errorState sets the state's error state.  The error state is the state
    that the state machine will transition to if an error is detected when
    attempting to enter the state (e.g. because no initial state has been set).

    \section1 Example Usage

    \snippet qml/statemachine/basicstate.qml document

    \clearfloat

    \sa StateMachine, FinalState
*/

/*!
    \qmlproperty enumeration State::childMode

    \brief The child mode of this state

    The default value of this property is QState.ExclusiveStates.

    This enum specifies how a state's child states are treated:
    \list
    \li QState.ExclusiveStates The child states are mutually exclusive and an initial state must be set by setting initialState property.
    \li QState.ParallelStates The child states are parallel. When the parent state is entered, all its child states are entered in parallel.
    \endlist
*/

/*!
    \qmlproperty QAbstractState State::errorState

    \brief The error state of this state.
*/

/*!
    \qmlproperty QAbstractState State::initialState

    \brief The initial state of this state (one of its child states).
*/

/*!
    \qmlsignal State::finished()

    This signal is emitted when a final child state of this state is entered.

    The corresponding handler is \c onFinished.

    \sa QAbstractState::active, QAbstractState::entered, QAbstractState::exited
*/

/*!
    \qmltype HistoryState
    \inqmlmodule QtQml.StateMachine
    \inherits QAbstractState
    \ingroup statemachine-qmltypes
    \since 5.4

    \brief The HistoryState type provides a means of returning to a previously active substate.

    A history state is a pseudo-state that represents the child state that the
    parent state was in the last time the parent state was exited.  A transition
    with a history state as its target is in fact a transition to one of the
    other child states of the parent state.
    HistoryState is part of \l{The Declarative State Machine Framework}.

    Use the defaultState property to set the state that should be entered
    if the parent state has never been entered.

    \section1 Example Usage

    \snippet qml/statemachine/historystate.qml document

    \clearfloat

    By default, a history state is shallow, meaning that it will not remember
    nested states.  This can be configured through the historyType property.

    \sa StateMachine, State
*/

/*!
    \qmlproperty QAbstractState HistoryState::defaultState

    \brief The default state of this history state.

    The default state indicates the state to transition to if the parent
    state has never been entered before.
*/

/*!
    \qmlproperty enumeration HistoryState::historyType

    \brief The type of history that this history state records.

    The default value of this property is QHistoryState.ShallowHistory.

    This enum specifies the type of history that a QHistoryState records.
    \list
    \li QHistoryState.ShallowHistory Only the immediate child states of the
        parent state are recorded.  In this case, a transition with the history
        state as its target will end up in the immediate child state that the
        parent was in the last time it was exited.  This is the default.
    \li QHistoryState.DeepHistory Nested states are recorded.  In this case
        a transition with the history state as its target will end up in the
        most deeply nested descendant state the parent was in the last time
        it was exited.
    \endlist
*/