122 \value ParallelStates The child states are parallel. When the parent state |
122 \value ParallelStates The child states are parallel. When the parent state |
123 is entered, all its child states are entered in parallel. |
123 is entered, all its child states are entered in parallel. |
124 */ |
124 */ |
125 |
125 |
126 QStatePrivate::QStatePrivate() |
126 QStatePrivate::QStatePrivate() |
127 : errorState(0), initialState(0), childMode(QState::ExclusiveStates) |
127 : QAbstractStatePrivate(StandardState), |
|
128 errorState(0), initialState(0), childMode(QState::ExclusiveStates), |
|
129 childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) |
128 { |
130 { |
129 } |
131 } |
130 |
132 |
131 QStatePrivate::~QStatePrivate() |
133 QStatePrivate::~QStatePrivate() |
132 { |
134 { |
178 { |
180 { |
179 } |
181 } |
180 |
182 |
181 QList<QAbstractState*> QStatePrivate::childStates() const |
183 QList<QAbstractState*> QStatePrivate::childStates() const |
182 { |
184 { |
183 QList<QAbstractState*> result; |
185 if (childStatesListNeedsRefresh) { |
184 QList<QObject*>::const_iterator it; |
186 childStatesList.clear(); |
185 for (it = children.constBegin(); it != children.constEnd(); ++it) { |
187 QList<QObject*>::const_iterator it; |
186 QAbstractState *s = qobject_cast<QAbstractState*>(*it); |
188 for (it = children.constBegin(); it != children.constEnd(); ++it) { |
187 if (!s || qobject_cast<QHistoryState*>(s)) |
189 QAbstractState *s = qobject_cast<QAbstractState*>(*it); |
188 continue; |
190 if (!s || qobject_cast<QHistoryState*>(s)) |
189 result.append(s); |
191 continue; |
190 } |
192 childStatesList.append(s); |
191 return result; |
193 } |
|
194 childStatesListNeedsRefresh = false; |
|
195 } |
|
196 return childStatesList; |
192 } |
197 } |
193 |
198 |
194 QList<QHistoryState*> QStatePrivate::historyStates() const |
199 QList<QHistoryState*> QStatePrivate::historyStates() const |
195 { |
200 { |
196 QList<QHistoryState*> result; |
201 QList<QHistoryState*> result; |
203 return result; |
208 return result; |
204 } |
209 } |
205 |
210 |
206 QList<QAbstractTransition*> QStatePrivate::transitions() const |
211 QList<QAbstractTransition*> QStatePrivate::transitions() const |
207 { |
212 { |
208 QList<QAbstractTransition*> result; |
213 if (transitionsListNeedsRefresh) { |
209 QList<QObject*>::const_iterator it; |
214 transitionsList.clear(); |
210 for (it = children.constBegin(); it != children.constEnd(); ++it) { |
215 QList<QObject*>::const_iterator it; |
211 QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); |
216 for (it = children.constBegin(); it != children.constEnd(); ++it) { |
212 if (t) |
217 QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it); |
213 result.append(t); |
218 if (t) |
214 } |
219 transitionsList.append(t); |
215 return result; |
220 } |
|
221 transitionsListNeedsRefresh = false; |
|
222 } |
|
223 return transitionsList; |
216 } |
224 } |
217 |
225 |
218 #ifndef QT_NO_PROPERTIES |
226 #ifndef QT_NO_PROPERTIES |
219 |
227 |
220 /*! |
228 /*! |
221 Instructs this state to set the property with the given \a name of the given |
229 Instructs this state to set the property with the given \a name of the given |
222 \a object to the given \a value when the state is entered. |
230 \a object to the given \a value when the state is entered. |
223 |
231 |
224 \sa polished() |
232 \sa propertiesAssigned() |
225 */ |
233 */ |
226 void QState::assignProperty(QObject *object, const char *name, |
234 void QState::assignProperty(QObject *object, const char *name, |
227 const QVariant &value) |
235 const QVariant &value) |
228 { |
236 { |
229 Q_D(QState); |
237 Q_D(QState); |
277 d->errorState = state; |
285 d->errorState = state; |
278 } |
286 } |
279 |
287 |
280 /*! |
288 /*! |
281 Adds the given \a transition. The transition has this state as the source. |
289 Adds the given \a transition. The transition has this state as the source. |
282 This state takes ownership of the transition. If the transition is successfully |
290 This state takes ownership of the transition. |
283 added, the function will return the \a transition pointer. Otherwise it will return null. |
291 */ |
284 */ |
292 void QState::addTransition(QAbstractTransition *transition) |
285 QAbstractTransition *QState::addTransition(QAbstractTransition *transition) |
|
286 { |
293 { |
287 Q_D(QState); |
294 Q_D(QState); |
288 if (!transition) { |
295 if (!transition) { |
289 qWarning("QState::addTransition: cannot add null transition"); |
296 qWarning("QState::addTransition: cannot add null transition"); |
290 return 0; |
297 return ; |
291 } |
298 } |
292 |
299 |
293 transition->setParent(this); |
300 transition->setParent(this); |
294 const QList<QWeakPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; |
301 const QList<QWeakPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; |
295 for (int i = 0; i < targets.size(); ++i) { |
302 for (int i = 0; i < targets.size(); ++i) { |
296 QAbstractState *t = targets.at(i).data(); |
303 QAbstractState *t = targets.at(i).data(); |
297 if (!t) { |
304 if (!t) { |
298 qWarning("QState::addTransition: cannot add transition to null state"); |
305 qWarning("QState::addTransition: cannot add transition to null state"); |
299 return 0; |
306 return ; |
300 } |
307 } |
301 if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) |
308 if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) |
302 && QAbstractStatePrivate::get(t)->machine() && d->machine()) { |
309 && QAbstractStatePrivate::get(t)->machine() && d->machine()) { |
303 qWarning("QState::addTransition: cannot add transition " |
310 qWarning("QState::addTransition: cannot add transition " |
304 "to a state in a different state machine"); |
311 "to a state in a different state machine"); |
305 return 0; |
312 return ; |
306 } |
313 } |
307 } |
314 } |
308 if (machine() != 0 && machine()->configuration().contains(this)) |
315 if (machine() != 0 && machine()->configuration().contains(this)) |
309 QStateMachinePrivate::get(machine())->registerTransitions(this); |
316 QStateMachinePrivate::get(machine())->registerTransitions(this); |
310 return transition; |
|
311 } |
317 } |
312 |
318 |
313 /*! |
319 /*! |
314 Adds a transition associated with the given \a signal of the given \a sender |
320 Adds a transition associated with the given \a signal of the given \a sender |
315 object, and returns the new QSignalTransition object. The transition has |
321 object, and returns the new QSignalTransition object. The transition has |
370 if (!target) { |
376 if (!target) { |
371 qWarning("QState::addTransition: cannot add transition to null state"); |
377 qWarning("QState::addTransition: cannot add transition to null state"); |
372 return 0; |
378 return 0; |
373 } |
379 } |
374 UnconditionalTransition *trans = new UnconditionalTransition(target); |
380 UnconditionalTransition *trans = new UnconditionalTransition(target); |
375 return addTransition(trans); |
381 addTransition(trans); |
|
382 return trans; |
376 } |
383 } |
377 |
384 |
378 /*! |
385 /*! |
379 Removes the given \a transition from this state. The state releases |
386 Removes the given \a transition from this state. The state releases |
380 ownership of the transition. |
387 ownership of the transition. |
478 |
490 |
479 \sa QFinalState |
491 \sa QFinalState |
480 */ |
492 */ |
481 |
493 |
482 /*! |
494 /*! |
483 \fn QState::polished() |
495 \fn QState::propertiesAssigned() |
484 |
496 |
485 This signal is emitted when all properties have been assigned their final value. |
497 This signal is emitted when all properties have been assigned their final value. If the state |
|
498 assigns a value to one or more properties for which an animation exists (either set on the |
|
499 transition or as a default animation on the state machine), then the signal will not be emitted |
|
500 until all such animations have finished playing. |
|
501 |
|
502 If there are no relevant animations, or no property assignments defined for the state, then |
|
503 the signal will be emitted immediately before the state is entered. |
486 |
504 |
487 \sa QState::assignProperty(), QAbstractTransition::addAnimation() |
505 \sa QState::assignProperty(), QAbstractTransition::addAnimation() |
488 */ |
506 */ |
489 |
507 |
490 QT_END_NAMESPACE |
508 QT_END_NAMESPACE |