author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qstate.h" |
|
43 |
||
44 |
#ifndef QT_NO_STATEMACHINE |
|
45 |
||
46 |
#include "qstate_p.h" |
|
47 |
#include "qhistorystate.h" |
|
48 |
#include "qhistorystate_p.h" |
|
49 |
#include "qabstracttransition.h" |
|
50 |
#include "qabstracttransition_p.h" |
|
51 |
#include "qsignaltransition.h" |
|
52 |
#include "qstatemachine.h" |
|
53 |
#include "qstatemachine_p.h" |
|
54 |
||
55 |
QT_BEGIN_NAMESPACE |
|
56 |
||
57 |
/*! |
|
58 |
\class QState |
|
59 |
||
60 |
\brief The QState class provides a general-purpose state for QStateMachine. |
|
61 |
||
62 |
\since 4.6 |
|
63 |
\ingroup statemachine |
|
64 |
||
65 |
QState objects can have child states, and can have transitions to other |
|
66 |
states. QState is part of \l{The State Machine Framework}. |
|
67 |
||
68 |
The addTransition() function adds a transition. The removeTransition() |
|
69 |
function removes a transition. |
|
70 |
||
71 |
The assignProperty() function is used for defining property assignments that |
|
72 |
should be performed when a state is entered. |
|
73 |
||
74 |
Top-level states must be passed a QStateMachine object as their parent |
|
75 |
state, or added to a state machine using QStateMachine::addState(). |
|
76 |
||
77 |
\section1 States with Child States |
|
78 |
||
79 |
The childMode property determines how child states are treated. For |
|
80 |
non-parallel state groups, the setInitialState() function must be called to |
|
81 |
set the initial state. The child states are mutually exclusive states, and |
|
82 |
the state machine needs to know which child state to enter when the parent |
|
83 |
state is the target of a transition. |
|
84 |
||
85 |
The state emits the QState::finished() signal when a final child state |
|
86 |
(QFinalState) is entered. |
|
87 |
||
88 |
The setErrorState() sets the state's error state. The error state is the |
|
89 |
state that the state machine will transition to if an error is detected when |
|
90 |
attempting to enter the state (e.g. because no initial state has been set). |
|
91 |
||
92 |
*/ |
|
93 |
||
94 |
/*! |
|
95 |
\property QState::initialState |
|
96 |
||
97 |
\brief the initial state of this state (one of its child states) |
|
98 |
*/ |
|
99 |
||
100 |
/*! |
|
101 |
\property QState::errorState |
|
102 |
||
103 |
\brief the error state of this state |
|
104 |
*/ |
|
105 |
||
106 |
/*! |
|
107 |
\property QState::childMode |
|
108 |
||
109 |
\brief the child mode of this state |
|
110 |
||
111 |
The default value of this property is QState::ExclusiveStates. |
|
112 |
*/ |
|
113 |
||
114 |
/*! |
|
115 |
\enum QState::ChildMode |
|
116 |
||
117 |
This enum specifies how a state's child states are treated. |
|
118 |
||
119 |
\value ExclusiveStates The child states are mutually exclusive and an |
|
120 |
initial state must be set by calling QState::setInitialState(). |
|
121 |
||
122 |
\value ParallelStates The child states are parallel. When the parent state |
|
123 |
is entered, all its child states are entered in parallel. |
|
124 |
*/ |
|
125 |
||
126 |
QStatePrivate::QStatePrivate() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
: QAbstractStatePrivate(StandardState), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
errorState(0), initialState(0), childMode(QState::ExclusiveStates), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) |
0 | 130 |
{ |
131 |
} |
|
132 |
||
133 |
QStatePrivate::~QStatePrivate() |
|
134 |
{ |
|
135 |
} |
|
136 |
||
137 |
void QStatePrivate::emitFinished() |
|
138 |
{ |
|
139 |
Q_Q(QState); |
|
140 |
emit q->finished(); |
|
141 |
} |
|
142 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
void QStatePrivate::emitPropertiesAssigned() |
0 | 144 |
{ |
145 |
Q_Q(QState); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
emit q->propertiesAssigned(); |
0 | 147 |
} |
148 |
||
149 |
/*! |
|
150 |
Constructs a new state with the given \a parent state. |
|
151 |
*/ |
|
152 |
QState::QState(QState *parent) |
|
153 |
: QAbstractState(*new QStatePrivate, parent) |
|
154 |
{ |
|
155 |
} |
|
156 |
||
157 |
/*! |
|
158 |
Constructs a new state with the given \a childMode and the given \a parent |
|
159 |
state. |
|
160 |
*/ |
|
161 |
QState::QState(ChildMode childMode, QState *parent) |
|
162 |
: QAbstractState(*new QStatePrivate, parent) |
|
163 |
{ |
|
164 |
Q_D(QState); |
|
165 |
d->childMode = childMode; |
|
166 |
} |
|
167 |
||
168 |
/*! |
|
169 |
\internal |
|
170 |
*/ |
|
171 |
QState::QState(QStatePrivate &dd, QState *parent) |
|
172 |
: QAbstractState(dd, parent) |
|
173 |
{ |
|
174 |
} |
|
175 |
||
176 |
/*! |
|
177 |
Destroys this state. |
|
178 |
*/ |
|
179 |
QState::~QState() |
|
180 |
{ |
|
181 |
} |
|
182 |
||
183 |
QList<QAbstractState*> QStatePrivate::childStates() const |
|
184 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
if (childStatesListNeedsRefresh) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
childStatesList.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
QList<QObject*>::const_iterator it; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
for (it = children.constBegin(); it != children.constEnd(); ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
QAbstractState *s = qobject_cast<QAbstractState*>(*it); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
if (!s || qobject_cast<QHistoryState*>(s)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
childStatesList.append(s); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
childStatesListNeedsRefresh = false; |
0 | 195 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
return childStatesList; |
0 | 197 |
} |
198 |
||
199 |
QList<QHistoryState*> QStatePrivate::historyStates() const |
|
200 |
{ |
|
201 |
QList<QHistoryState*> result; |
|
202 |
QList<QObject*>::const_iterator it; |
|
203 |
for (it = children.constBegin(); it != children.constEnd(); ++it) { |
|
204 |
QHistoryState *h = qobject_cast<QHistoryState*>(*it); |
|
205 |
if (h) |
|
206 |
result.append(h); |
|
207 |
} |
|
208 |
return result; |
|
209 |
} |
|
210 |
||
211 |
QList<QAbstractTransition*> QStatePrivate::transitions() const |
|
212 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
if (transitionsListNeedsRefresh) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
transitionsList.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
QList<QObject*>::const_iterator it; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
for (it = children.constBegin(); it != children.constEnd(); ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
if (t) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
transitionsList.append(t); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
transitionsListNeedsRefresh = false; |
0 | 222 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
return transitionsList; |
0 | 224 |
} |
225 |
||
226 |
#ifndef QT_NO_PROPERTIES |
|
227 |
||
228 |
/*! |
|
229 |
Instructs this state to set the property with the given \a name of the given |
|
230 |
\a object to the given \a value when the state is entered. |
|
231 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
\sa propertiesAssigned() |
0 | 233 |
*/ |
234 |
void QState::assignProperty(QObject *object, const char *name, |
|
235 |
const QVariant &value) |
|
236 |
{ |
|
237 |
Q_D(QState); |
|
238 |
if (!object) { |
|
239 |
qWarning("QState::assignProperty: cannot assign property '%s' of null object", name); |
|
240 |
return; |
|
241 |
} |
|
242 |
for (int i = 0; i < d->propertyAssignments.size(); ++i) { |
|
243 |
QPropertyAssignment &assn = d->propertyAssignments[i]; |
|
244 |
if ((assn.object == object) && (assn.propertyName == name)) { |
|
245 |
assn.value = value; |
|
246 |
return; |
|
247 |
} |
|
248 |
} |
|
249 |
d->propertyAssignments.append(QPropertyAssignment(object, name, value)); |
|
250 |
} |
|
251 |
||
252 |
#endif // QT_NO_PROPERTIES |
|
253 |
||
254 |
/*! |
|
255 |
Returns this state's error state. |
|
256 |
||
257 |
\sa QStateMachine::error() |
|
258 |
*/ |
|
259 |
QAbstractState *QState::errorState() const |
|
260 |
{ |
|
261 |
Q_D(const QState); |
|
262 |
return d->errorState; |
|
263 |
} |
|
264 |
||
265 |
/*! |
|
266 |
Sets this state's error state to be the given \a state. If the error state |
|
267 |
is not set, or if it is set to 0, the state will inherit its parent's error |
|
268 |
state recursively. If no error state is set for the state itself or any of |
|
269 |
its ancestors, an error will cause the machine to stop executing and an error |
|
270 |
will be printed to the console. |
|
271 |
*/ |
|
272 |
void QState::setErrorState(QAbstractState *state) |
|
273 |
{ |
|
274 |
Q_D(QState); |
|
275 |
if (state != 0 && qobject_cast<QStateMachine*>(state)) { |
|
276 |
qWarning("QStateMachine::setErrorState: root state cannot be error state"); |
|
277 |
return; |
|
278 |
} |
|
279 |
if (state != 0 && (!state->machine() || ((state->machine() != machine()) && !qobject_cast<QStateMachine*>(this)))) { |
|
280 |
qWarning("QState::setErrorState: error state cannot belong " |
|
281 |
"to a different state machine"); |
|
282 |
return; |
|
283 |
} |
|
284 |
||
285 |
d->errorState = state; |
|
286 |
} |
|
287 |
||
288 |
/*! |
|
289 |
Adds the given \a transition. The transition has this state as the source. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
This state takes ownership of the transition. |
0 | 291 |
*/ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
void QState::addTransition(QAbstractTransition *transition) |
0 | 293 |
{ |
294 |
Q_D(QState); |
|
295 |
if (!transition) { |
|
296 |
qWarning("QState::addTransition: cannot add null transition"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
return ; |
0 | 298 |
} |
299 |
||
300 |
transition->setParent(this); |
|
301 |
const QList<QWeakPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; |
|
302 |
for (int i = 0; i < targets.size(); ++i) { |
|
303 |
QAbstractState *t = targets.at(i).data(); |
|
304 |
if (!t) { |
|
305 |
qWarning("QState::addTransition: cannot add transition to null state"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
return ; |
0 | 307 |
} |
308 |
if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) |
|
309 |
&& QAbstractStatePrivate::get(t)->machine() && d->machine()) { |
|
310 |
qWarning("QState::addTransition: cannot add transition " |
|
311 |
"to a state in a different state machine"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
return ; |
0 | 313 |
} |
314 |
} |
|
315 |
if (machine() != 0 && machine()->configuration().contains(this)) |
|
316 |
QStateMachinePrivate::get(machine())->registerTransitions(this); |
|
317 |
} |
|
318 |
||
319 |
/*! |
|
320 |
Adds a transition associated with the given \a signal of the given \a sender |
|
321 |
object, and returns the new QSignalTransition object. The transition has |
|
322 |
this state as the source, and the given \a target as the target state. |
|
323 |
*/ |
|
324 |
QSignalTransition *QState::addTransition(QObject *sender, const char *signal, |
|
325 |
QAbstractState *target) |
|
326 |
{ |
|
327 |
if (!sender) { |
|
328 |
qWarning("QState::addTransition: sender cannot be null"); |
|
329 |
return 0; |
|
330 |
} |
|
331 |
if (!signal) { |
|
332 |
qWarning("QState::addTransition: signal cannot be null"); |
|
333 |
return 0; |
|
334 |
} |
|
335 |
if (!target) { |
|
336 |
qWarning("QState::addTransition: cannot add transition to null state"); |
|
337 |
return 0; |
|
338 |
} |
|
339 |
int offset = (*signal == '0'+QSIGNAL_CODE) ? 1 : 0; |
|
340 |
const QMetaObject *meta = sender->metaObject(); |
|
341 |
if (meta->indexOfSignal(signal+offset) == -1) { |
|
342 |
if (meta->indexOfSignal(QMetaObject::normalizedSignature(signal+offset)) == -1) { |
|
343 |
qWarning("QState::addTransition: no such signal %s::%s", |
|
344 |
meta->className(), signal+offset); |
|
345 |
return 0; |
|
346 |
} |
|
347 |
} |
|
348 |
QSignalTransition *trans = new QSignalTransition(sender, signal); |
|
349 |
trans->setTargetState(target); |
|
350 |
addTransition(trans); |
|
351 |
return trans; |
|
352 |
} |
|
353 |
||
354 |
namespace { |
|
355 |
||
356 |
// ### Make public? |
|
357 |
class UnconditionalTransition : public QAbstractTransition |
|
358 |
{ |
|
359 |
public: |
|
360 |
UnconditionalTransition(QAbstractState *target) |
|
361 |
: QAbstractTransition() |
|
362 |
{ setTargetState(target); } |
|
363 |
protected: |
|
364 |
void onTransition(QEvent *) {} |
|
365 |
bool eventTest(QEvent *) { return true; } |
|
366 |
}; |
|
367 |
||
368 |
} // namespace |
|
369 |
||
370 |
/*! |
|
371 |
Adds an unconditional transition from this state to the given \a target |
|
372 |
state, and returns then new transition object. |
|
373 |
*/ |
|
374 |
QAbstractTransition *QState::addTransition(QAbstractState *target) |
|
375 |
{ |
|
376 |
if (!target) { |
|
377 |
qWarning("QState::addTransition: cannot add transition to null state"); |
|
378 |
return 0; |
|
379 |
} |
|
380 |
UnconditionalTransition *trans = new UnconditionalTransition(target); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
addTransition(trans); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
return trans; |
0 | 383 |
} |
384 |
||
385 |
/*! |
|
386 |
Removes the given \a transition from this state. The state releases |
|
387 |
ownership of the transition. |
|
388 |
||
389 |
\sa addTransition() |
|
390 |
*/ |
|
391 |
void QState::removeTransition(QAbstractTransition *transition) |
|
392 |
{ |
|
393 |
Q_D(QState); |
|
394 |
if (!transition) { |
|
395 |
qWarning("QState::removeTransition: cannot remove null transition"); |
|
396 |
return; |
|
397 |
} |
|
398 |
if (transition->sourceState() != this) { |
|
399 |
qWarning("QState::removeTransition: transition %p's source state (%p)" |
|
400 |
" is different from this state (%p)", |
|
401 |
transition, transition->sourceState(), this); |
|
402 |
return; |
|
403 |
} |
|
404 |
QStateMachinePrivate *mach = QStateMachinePrivate::get(d->machine()); |
|
405 |
if (mach) |
|
406 |
mach->unregisterTransition(transition); |
|
407 |
transition->setParent(0); |
|
408 |
} |
|
409 |
||
410 |
/*! |
|
411 |
\reimp |
|
412 |
*/ |
|
413 |
void QState::onEntry(QEvent *event) |
|
414 |
{ |
|
415 |
Q_UNUSED(event); |
|
416 |
} |
|
417 |
||
418 |
/*! |
|
419 |
\reimp |
|
420 |
*/ |
|
421 |
void QState::onExit(QEvent *event) |
|
422 |
{ |
|
423 |
Q_UNUSED(event); |
|
424 |
} |
|
425 |
||
426 |
/*! |
|
427 |
Returns this state's initial state, or 0 if the state has no initial state. |
|
428 |
*/ |
|
429 |
QAbstractState *QState::initialState() const |
|
430 |
{ |
|
431 |
Q_D(const QState); |
|
432 |
return d->initialState; |
|
433 |
} |
|
434 |
||
435 |
/*! |
|
436 |
Sets this state's initial state to be the given \a state. |
|
437 |
\a state has to be a child of this state. |
|
438 |
*/ |
|
439 |
void QState::setInitialState(QAbstractState *state) |
|
440 |
{ |
|
441 |
Q_D(QState); |
|
442 |
if (d->childMode == QState::ParallelStates) { |
|
443 |
qWarning("QState::setInitialState: ignoring attempt to set initial state " |
|
444 |
"of parallel state group %p", this); |
|
445 |
return; |
|
446 |
} |
|
447 |
if (state && (state->parentState() != this)) { |
|
448 |
qWarning("QState::setInitialState: state %p is not a child of this state (%p)", |
|
449 |
state, this); |
|
450 |
return; |
|
451 |
} |
|
452 |
d->initialState = state; |
|
453 |
} |
|
454 |
||
455 |
/*! |
|
456 |
Returns the child mode of this state. |
|
457 |
*/ |
|
458 |
QState::ChildMode QState::childMode() const |
|
459 |
{ |
|
460 |
Q_D(const QState); |
|
461 |
return d->childMode; |
|
462 |
} |
|
463 |
||
464 |
/*! |
|
465 |
Sets the child \a mode of this state. |
|
466 |
*/ |
|
467 |
void QState::setChildMode(ChildMode mode) |
|
468 |
{ |
|
469 |
Q_D(QState); |
|
470 |
d->childMode = mode; |
|
471 |
} |
|
472 |
||
473 |
/*! |
|
474 |
\reimp |
|
475 |
*/ |
|
476 |
bool QState::event(QEvent *e) |
|
477 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
Q_D(QState); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
d->childStatesListNeedsRefresh = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
d->transitionsListNeedsRefresh = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
} |
0 | 483 |
return QAbstractState::event(e); |
484 |
} |
|
485 |
||
486 |
/*! |
|
487 |
\fn QState::finished() |
|
488 |
||
489 |
This signal is emitted when a final child state of this state is entered. |
|
490 |
||
491 |
\sa QFinalState |
|
492 |
*/ |
|
493 |
||
494 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
\fn QState::propertiesAssigned() |
0 | 496 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
This signal is emitted when all properties have been assigned their final value. If the state |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
assigns a value to one or more properties for which an animation exists (either set on the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
transition or as a default animation on the state machine), then the signal will not be emitted |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
until all such animations have finished playing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
501 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
If there are no relevant animations, or no property assignments defined for the state, then |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
the signal will be emitted immediately before the state is entered. |
0 | 504 |
|
505 |
\sa QState::assignProperty(), QAbstractTransition::addAnimation() |
|
506 |
*/ |
|
507 |
||
508 |
QT_END_NAMESPACE |
|
509 |
||
510 |
#endif //QT_NO_STATEMACHINE |