Qt 4.8
Classes | Public Types | Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QStateMachinePrivate Class Reference

#include <qstatemachine_p.h>

Inheritance diagram for QStateMachinePrivate:
QStatePrivate QAbstractStatePrivate QObjectPrivate QObjectData

Classes

struct  Handler
 

Public Types

enum  EventProcessingMode { DirectProcessing, QueuedProcessing }
 
typedef QEvent *(* f_cloneEvent) (QEvent *)
 
typedef QPair< QObject *, QByteArrayRestorableId
 
enum  State { NotRunning, Starting, Running }
 
enum  StopProcessingReason { EventQueueEmpty, Finished, Stopped }
 
- Public Types inherited from QAbstractStatePrivate
enum  StateType { AbstractState, StandardState, FinalState, HistoryState }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

void _q_animationFinished ()
 
void _q_process ()
 
void _q_start ()
 
void addStatesToEnter (QAbstractState *s, QState *root, QSet< QAbstractState *> &statesToEnter, QSet< QAbstractState *> &statesForDefaultEntry)
 
void applyProperties (const QList< QAbstractTransition *> &transitionList, const QList< QAbstractState *> &exitedStates, const QList< QAbstractState *> &enteredStates)
 
void cancelAllDelayedEvents ()
 
void clearHistory ()
 
QEventdequeueExternalEvent ()
 
QEventdequeueInternalEvent ()
 
QList< QAbstractState * > enterStates (QEvent *event, const QList< QAbstractTransition *> &enabledTransitions)
 
void executeTransitionContent (QEvent *event, const QList< QAbstractTransition *> &transitionList)
 
QList< QAbstractState * > exitStates (QEvent *event, const QList< QAbstractTransition *> &transitionList)
 
QAbstractStatefindErrorState (QAbstractState *context)
 
QStatefindLCA (const QList< QAbstractState *> &states) const
 
void goToState (QAbstractState *targetState)
 Causes this state machine to unconditionally transition to the given targetState. More...
 
void handleFilteredEvent (QObject *watched, QEvent *event)
 
void handleTransitionSignal (QObject *sender, int signalIndex, void **args)
 
bool hasRestorable (QObject *object, const QByteArray &propertyName) const
 Returns true if the variable with the given id has been registered for restoration. More...
 
QPair< QList< QAbstractAnimation * >, QList< QAbstractAnimation * > > initializeAnimation (QAbstractAnimation *abstractAnimation, const QPropertyAssignment &prop)
 
bool isAtomic (const QAbstractState *s) const
 
bool isCompound (const QAbstractState *s) const
 
bool isExternalEventQueueEmpty ()
 
bool isInFinalState (QAbstractState *s) const
 
bool isInternalEventQueueEmpty ()
 
bool isPreempted (const QAbstractState *s, const QSet< QAbstractTransition *> &transitions) const
 
void microstep (QEvent *event, const QList< QAbstractTransition *> &transitionList)
 
void postExternalEvent (QEvent *e)
 
void postInternalEvent (QEvent *e)
 
void processEvents (EventProcessingMode processingMode)
 
 QStateMachinePrivate ()
 
void registerEventTransition (QEventTransition *transition)
 
void registerRestorable (QObject *object, const QByteArray &propertyName)
 
void registerSignalTransition (QSignalTransition *transition)
 
void registerTransitions (QAbstractState *state)
 
void removeStartState ()
 
QList< QPropertyAssignmentrestorablesToPropertyList (const QHash< RestorableId, QVariant > &restorables) const
 
QVariant restorableValue (QObject *object, const QByteArray &propertyName) const
 
QStaterootState () const
 
QSet< QAbstractTransition * > selectTransitions (QEvent *event) const
 
void setError (QStateMachine::Error error, QAbstractState *currentContext)
 
QStatestartState ()
 
void unregisterAllTransitions ()
 
void unregisterEventTransition (QEventTransition *transition)
 
void unregisterRestorable (QObject *object, const QByteArray &propertyName)
 
void unregisterSignalTransition (QSignalTransition *transition)
 
void unregisterTransition (QAbstractTransition *transition)
 
 ~QStateMachinePrivate ()
 
- Public Functions inherited from QStatePrivate
QList< QAbstractState * > childStates () const
 
void emitFinished ()
 
void emitPropertiesAssigned ()
 
QList< QHistoryState * > historyStates () const
 
 QStatePrivate ()
 
QList< QAbstractTransition * > transitions () const
 
 ~QStatePrivate ()
 
- Public Functions inherited from QAbstractStatePrivate
void callOnEntry (QEvent *e)
 
void callOnExit (QEvent *e)
 
void emitEntered ()
 
void emitExited ()
 
QStateMachinemachine () const
 
 QAbstractStatePrivate (StateType type)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static QStateMachinePrivateget (QStateMachine *q)
 
static bool isDescendantOf (const QAbstractState *s, const QAbstractState *other)
 
static bool isFinal (const QAbstractState *s)
 
static bool isParallel (const QAbstractState *s)
 
static QList< QState * > properAncestors (const QAbstractState *s, const QState *upperBound)
 
static bool stateEntryLessThan (QAbstractState *s1, QAbstractState *s2)
 
static bool stateExitLessThan (QAbstractState *s1, QAbstractState *s2)
 
static QFinalStatetoFinalState (QAbstractState *state)
 
static QHistoryStatetoHistoryState (QAbstractState *state)
 
static QStatetoStandardState (QAbstractState *state)
 
static const QStatetoStandardState (const QAbstractState *state)
 
- Static Public Functions inherited from QStatePrivate
static QStatePrivateget (QState *q)
 
static const QStatePrivateget (const QState *q)
 
- Static Public Functions inherited from QAbstractStatePrivate
static QAbstractStatePrivateget (QAbstractState *q)
 
static const QAbstractStatePrivateget (const QAbstractState *q)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QState_startState
 
bool animated
 
QHash< QAbstractState *, QList< QAbstractAnimation * > > animationsForState
 
QSet< QAbstractState * > configuration
 
QHash< const QObject *, QVector< int > > connections
 
QList< QAbstractAnimation * > defaultAnimations
 
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForSource
 
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForTarget
 
QHash< int, QEvent * > delayedEvents
 
QMutex delayedEventsMutex
 
QStateMachine::Error error
 
QString errorString
 
QMutex externalEventMutex
 
QList< QEvent * > externalEventQueue
 
QStateMachine::RestorePolicy globalRestorePolicy
 
QMutex internalEventMutex
 
QList< QEvent * > internalEventQueue
 
QSet< QAbstractState * > pendingErrorStates
 
QSet< QAbstractState * > pendingErrorStatesForDefaultEntry
 
bool processing
 
bool processingScheduled
 
QHash< QAbstractAnimation *, QPropertyAssignmentpropertyForAnimation
 
QHash< QObject *, QHash< QEvent::Type, int > > qobjectEvents
 
QHash< RestorableId, QVariantregisteredRestorables
 
QSet< QAbstractAnimation * > resetAnimationEndValues
 
QSignalEventGeneratorsignalEventGenerator
 
State state
 
QHash< QAbstractAnimation *, QAbstractState * > stateForAnimation
 
bool stop
 
StopProcessingReason stopProcessingReason
 
- Public Variables inherited from QStatePrivate
QState::ChildMode childMode
 
QList< QAbstractState * > childStatesList
 
bool childStatesListNeedsRefresh
 
QAbstractStateerrorState
 
QAbstractStateinitialState
 
QList< QPropertyAssignmentpropertyAssignments
 
QList< QAbstractTransition * > transitionsList
 
bool transitionsListNeedsRefresh
 
- Public Variables inherited from QAbstractStatePrivate
uint isMachine:1
 
QStateparentState
 
uint stateType:31
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Static Public Variables

static const Handlerhandler = &qt_kernel_statemachine_handler
 

Detailed Description

Definition at line 85 of file qstatemachine_p.h.

Typedefs

◆ f_cloneEvent

typedef QEvent*(* QStateMachinePrivate::f_cloneEvent) (QEvent *)

Definition at line 238 of file qstatemachine_p.h.

◆ RestorableId

Definition at line 183 of file qstatemachine_p.h.

Enumerations

◆ EventProcessingMode

Enumerator
DirectProcessing 
QueuedProcessing 

Definition at line 94 of file qstatemachine_p.h.

◆ State

Enumerator
NotRunning 
Starting 
Running 

Definition at line 89 of file qstatemachine_p.h.

◆ StopProcessingReason

Enumerator
EventQueueEmpty 
Finished 
Stopped 

Definition at line 98 of file qstatemachine_p.h.

Constructors and Destructors

◆ QStateMachinePrivate()

QStateMachinePrivate::QStateMachinePrivate ( )

Definition at line 190 of file qstatemachine.cpp.

191 {
192  isMachine = true;
193 
194  state = NotRunning;
195  _startState = 0;
196  processing = false;
197  processingScheduled = false;
198  stop = false;
203 #ifndef QT_NO_ANIMATION
204  animated = true;
205 #endif
206 }
QStateMachine::RestorePolicy globalRestorePolicy
QStateMachine::Error error
StopProcessingReason stopProcessingReason
QSignalEventGenerator * signalEventGenerator

◆ ~QStateMachinePrivate()

QStateMachinePrivate::~QStateMachinePrivate ( )

Definition at line 208 of file qstatemachine.cpp.

209 {
212 }
QList< QEvent * > externalEventQueue
QList< QEvent * > internalEventQueue
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ _q_animationFinished()

void QStateMachinePrivate::_q_animationFinished ( )

Definition at line 1118 of file qstatemachine.cpp.

Referenced by applyProperties().

1119 {
1120  Q_Q(QStateMachine);
1121  QAbstractAnimation *anim = qobject_cast<QAbstractAnimation*>(q->sender());
1122  Q_ASSERT(anim != 0);
1123  QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
1124  if (resetAnimationEndValues.contains(anim)) {
1125  qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize
1127  }
1128 
1129 #ifndef QT_NO_PROPERTIES
1130  // Set the final property value.
1132  Q_ASSERT(assn.object != 0);
1133  assn.object->setProperty(assn.propertyName, assn.value);
1134  if (!assn.explicitlySet)
1136 #endif
1137 
1139  Q_ASSERT(state != 0);
1141  it = animationsForState.find(state);
1142  Q_ASSERT(it != animationsForState.end());
1143  QList<QAbstractAnimation*> &animations = it.value();
1144  animations.removeOne(anim);
1145  if (animations.isEmpty()) {
1148  }
1149 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
bool remove(const T &value)
Definition: qset.h:89
#define SLOT(a)
Definition: qobjectdefs.h:226
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
QVariant value
Definition: qstate_p.h:74
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QObject * object
Definition: qstate_p.h:72
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QHash< QAbstractAnimation *, QPropertyAssignment > propertyForAnimation
The QAbstractState class is the base class of states of a QStateMachine.
bool contains(const T &value) const
Definition: qset.h:91
The QVariantAnimation class provides an abstract base class for animations.
The QAbstractAnimation class is the base of all animations.
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
void unregisterRestorable(QObject *object, const QByteArray &propertyName)
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
QByteArray propertyName
Definition: qstate_p.h:73
QHash< QAbstractAnimation *, QAbstractState * > stateForAnimation
void emitPropertiesAssigned()
Definition: qstate.cpp:159
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
QSet< QAbstractAnimation * > resetAnimationEndValues
static QState * toStandardState(QAbstractState *state)
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QHash< QAbstractState *, QList< QAbstractAnimation * > > animationsForState

◆ _q_process()

void QStateMachinePrivate::_q_process ( )

Definition at line 1250 of file qstatemachine.cpp.

Referenced by _q_start(), and processEvents().

1251 {
1252  Q_Q(QStateMachine);
1253  Q_ASSERT(state == Running);
1254  Q_ASSERT(!processing);
1255  processing = true;
1256  processingScheduled = false;
1257 #ifdef QSTATEMACHINE_DEBUG
1258  qDebug() << q << ": starting the event processing loop";
1259 #endif
1260  while (processing) {
1261  if (stop) {
1262  processing = false;
1263  break;
1264  }
1265  QSet<QAbstractTransition*> enabledTransitions;
1266  QEvent *e = new QEvent(QEvent::None);
1267  enabledTransitions = selectTransitions(e);
1268  if (enabledTransitions.isEmpty()) {
1269  delete e;
1270  e = 0;
1271  }
1272  if (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) {
1273 #ifdef QSTATEMACHINE_DEBUG
1274  qDebug() << q << ": dequeued internal event" << e << "of type" << e->type();
1275 #endif
1276  enabledTransitions = selectTransitions(e);
1277  if (enabledTransitions.isEmpty()) {
1278  delete e;
1279  e = 0;
1280  }
1281  }
1282  if (enabledTransitions.isEmpty()) {
1283  if ((e = dequeueExternalEvent()) != 0) {
1284 #ifdef QSTATEMACHINE_DEBUG
1285  qDebug() << q << ": dequeued external event" << e << "of type" << e->type();
1286 #endif
1287  enabledTransitions = selectTransitions(e);
1288  if (enabledTransitions.isEmpty()) {
1289  delete e;
1290  e = 0;
1291  }
1292  } else {
1293  if (isInternalEventQueueEmpty()) {
1294  processing = false;
1296  }
1297  }
1298  }
1299  if (!enabledTransitions.isEmpty()) {
1300  q->beginMicrostep(e);
1301  microstep(e, enabledTransitions.toList());
1302  q->endMicrostep(e);
1303  }
1304 #ifdef QSTATEMACHINE_DEBUG
1305  else {
1306  qDebug() << q << ": no transitions enabled";
1307  }
1308 #endif
1309  delete e;
1310  }
1311 #ifdef QSTATEMACHINE_DEBUG
1312  qDebug() << q << ": finished the event processing loop";
1313 #endif
1314  if (stop) {
1315  stop = false;
1317  }
1318 
1319  switch (stopProcessingReason) {
1320  case EventQueueEmpty:
1321  break;
1322  case Finished:
1323  state = NotRunning;
1326  emit q->finished();
1327  break;
1328  case Stopped:
1329  state = NotRunning;
1332  emit q->stopped();
1333  break;
1334  }
1335 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
bool isEmpty() const
Definition: qset.h:77
StopProcessingReason stopProcessingReason
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
QList< T > toList() const
Definition: qset.h:296
QSet< QAbstractTransition * > selectTransitions(QEvent *event) const
#define emit
Definition: qobjectdefs.h:76
QEvent * dequeueInternalEvent()
QEvent * dequeueExternalEvent()
void microstep(QEvent *event, const QList< QAbstractTransition *> &transitionList)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ _q_start()

void QStateMachinePrivate::_q_start ( )

Definition at line 1202 of file qstatemachine.cpp.

1203 {
1204  Q_Q(QStateMachine);
1205  Q_ASSERT(state == Starting);
1206  Q_ASSERT(rootState() != 0);
1207  QAbstractState *initial = rootState()->initialState();
1208  configuration.clear();
1213  clearHistory();
1214 
1215 #ifdef QSTATEMACHINE_DEBUG
1216  qDebug() << q << ": starting";
1217 #endif
1218  state = Running;
1219  processingScheduled = true; // we call _q_process() below
1220  emit q->started();
1221 
1222  QState *start = startState();
1223  Q_ASSERT(start != 0);
1224 
1226 
1227  // If a transition has already been added, then we skip this step, as the
1228  // initial transition in that case has been overridden.
1229  if (transitions.isEmpty()) {
1230  QAbstractTransition *initialTransition = new InitialTransition(initial);
1231  start->addTransition(initialTransition);
1232  transitions.append(initialTransition);
1233  }
1234 
1235  QEvent nullEvent(QEvent::None);
1236  executeTransitionContent(&nullEvent, transitions);
1237  QList<QAbstractState*> enteredStates = enterStates(&nullEvent, transitions);
1238 #ifndef QT_NO_PROPERTIES
1239  applyProperties(transitions, QList<QAbstractState*>() << start,
1240  enteredStates);
1241 #endif
1242  removeStartState();
1243 
1244 #ifdef QSTATEMACHINE_DEBUG
1245  qDebug() << q << ": initial configuration:" << configuration;
1246 #endif
1247  _q_process();
1248 }
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
QSet< QAbstractState * > configuration
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QAbstractState class is the base class of states of a QStateMachine.
#define emit
Definition: qobjectdefs.h:76
void clear()
Definition: qset.h:87
QList< QAbstractTransition * > transitions() const
Definition: qstate.cpp:227
QAbstractState * initialState
the initial state of this state (one of its child states)
Definition: qstate.h:64
QState * rootState() const
void applyProperties(const QList< QAbstractTransition *> &transitionList, const QList< QAbstractState *> &exitedStates, const QList< QAbstractState *> &enteredStates)
QList< QEvent * > externalEventQueue
void clear()
Removes all items from the list.
Definition: qlist.h:764
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
QList< QEvent * > internalEventQueue
void executeTransitionContent(QEvent *event, const QList< QAbstractTransition *> &transitionList)
QList< QAbstractState * > enterStates(QEvent *event, const QList< QAbstractTransition *> &enabledTransitions)
void addTransition(QAbstractTransition *transition)
Adds the given transition.
Definition: qstate.cpp:308
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ addStatesToEnter()

void QStateMachinePrivate::addStatesToEnter ( QAbstractState s,
QState root,
QSet< QAbstractState *> &  statesToEnter,
QSet< QAbstractState *> &  statesForDefaultEntry 
)

Definition at line 575 of file qstatemachine.cpp.

Referenced by enterStates(), and setError().

578 {
579  if (QHistoryState *h = toHistoryState(s)) {
581  if (!hconf.isEmpty()) {
582  for (int k = 0; k < hconf.size(); ++k) {
583  QAbstractState *s0 = hconf.at(k);
584  addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
585  }
586  #ifdef QSTATEMACHINE_DEBUG
587  qDebug() <<q_func() << ": restoring"
588  << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow")
589  << "history from" << s << ':' << hconf;
590  #endif
591  } else {
595 
596  if (hlst.isEmpty()) {
598  } else {
599  for (int k = 0; k < hlst.size(); ++k) {
600  QAbstractState *s0 = hlst.at(k);
601  addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
602  }
603  #ifdef QSTATEMACHINE_DEBUG
604  qDebug() << q_func() << ": initial history targets for" << s << ':' << hlst;
605  #endif
606  }
607  }
608  } else {
609  if (s == rootState()) {
610  // Error has already been set by exitStates().
612  return;
613  }
614  statesToEnter.insert(s);
615  if (isParallel(s)) {
616  QState *grp = toStandardState(s);
618  for (int i = 0; i < lst.size(); ++i) {
619  QAbstractState *child = lst.at(i);
620  addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry);
621  }
622  } else if (isCompound(s)) {
623  statesForDefaultEntry.insert(s);
624  QState *grp = toStandardState(s);
625  QAbstractState *initial = grp->initialState();
626  if (initial != 0) {
627  Q_ASSERT(initial->machine() == q_func());
628  addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry);
629  } else {
631  return;
632  }
633  }
634  QList<QState*> ancs = properAncestors(s, root);
635  for (int i = 0; i < ancs.size(); ++i) {
636  QState *anc = ancs.at(i);
637  if (!anc->parentState())
638  continue;
639  statesToEnter.insert(anc);
640  if (isParallel(anc)) {
642  for (int j = 0; j < lst.size(); ++j) {
643  QAbstractState *child = lst.at(j);
644  bool hasDescendantInList = false;
646  for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) {
647  if (isDescendantOf(*it, child)) {
648  hasDescendantInList = true;
649  break;
650  }
651  }
652  if (!hasDescendantInList)
653  addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry);
654  }
655  }
656  }
657  }
658 }
QStateMachine::Error error
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
QStateMachine * machine() const
Returns the state machine that this state is part of, or 0 if the state is not part of a state machin...
#define it(className, varName)
const_iterator constEnd() const
Definition: qset.h:171
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
QHistoryState::HistoryType historyType
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addStatesToEnter(QAbstractState *s, QState *root, QSet< QAbstractState *> &statesToEnter, QSet< QAbstractState *> &statesForDefaultEntry)
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
QList< QAbstractState * > configuration
QAbstractState * defaultState
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static QHistoryStatePrivate * get(QHistoryState *q)
void setError(QStateMachine::Error error, QAbstractState *currentContext)
The QAbstractState class is the base class of states of a QStateMachine.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isCompound(const QAbstractState *s) const
const_iterator insert(const T &value)
Definition: qset.h:179
QAbstractState * initialState
the initial state of this state (one of its child states)
Definition: qstate.h:64
QState * rootState() const
static QHistoryState * toHistoryState(QAbstractState *state)
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
The QHistoryState class provides a means of returning to a previously active substate.
Definition: qhistorystate.h:56
QList< QAbstractState * > childStates() const
Definition: qstate.cpp:199
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const_iterator constBegin() const
Definition: qset.h:168
static QList< QState * > properAncestors(const QAbstractState *s, const QState *upperBound)
static QState * toStandardState(QAbstractState *state)
static bool isParallel(const QAbstractState *s)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ applyProperties()

void QStateMachinePrivate::applyProperties ( const QList< QAbstractTransition *> &  transitionList,
const QList< QAbstractState *> &  exitedStates,
const QList< QAbstractState *> &  enteredStates 
)

Definition at line 662 of file qstatemachine.cpp.

Referenced by _q_start(), and microstep().

665 {
666 #ifdef QT_NO_ANIMATION
667  Q_UNUSED(transitionList);
668  Q_UNUSED(exitedStates);
669 #else
671 #endif
672  // Process the property assignments of the entered states.
673  QHash<QAbstractState*, QList<QPropertyAssignment> > propertyAssignmentsForState;
675  for (int i = 0; i < enteredStates.size(); ++i) {
676  QState *s = toStandardState(enteredStates.at(i));
677  if (!s)
678  continue;
679 
681  for (int j = 0; j < assignments.size(); ++j) {
682  const QPropertyAssignment &assn = assignments.at(j);
685  }
686  pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
687  propertyAssignmentsForState[s].append(assn);
688  }
689 
690  // Remove pending restorables for all parent states to avoid restoring properties
691  // before the state that assigned them is exited. If state does not explicitly
692  // assign a property which is assigned by the parent, it inherits the parent's assignment.
693  QState *parentState = s;
694  while ((parentState = parentState->parentState()) != 0) {
695  assignments = QStatePrivate::get(parentState)->propertyAssignments;
696  for (int j=0; j<assignments.size(); ++j) {
697  const QPropertyAssignment &assn = assignments.at(j);
698  int c = pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
699  if (c > 0)
700  propertyAssignmentsForState[s].append(assn);
701  }
702  }
703  }
704  if (!pendingRestorables.isEmpty()) {
705  QAbstractState *s;
706  if (!enteredStates.isEmpty())
707  s = enteredStates.last(); // ### handle if parallel
708  else
709  s = 0;
710  propertyAssignmentsForState[s] << restorablesToPropertyList(pendingRestorables);
711  }
712 
713 #ifndef QT_NO_ANIMATION
714  // Gracefully terminate playing animations for states that are exited.
715  for (int i = 0; i < exitedStates.size(); ++i) {
716  QAbstractState *s = exitedStates.at(i);
718  for (int j = 0; j < animations.size(); ++j) {
719  QAbstractAnimation *anim = animations.at(j);
720  QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
722 
723  // Stop the (top-level) animation.
724  // ### Stopping nested animation has weird behavior.
725  QAbstractAnimation *topLevelAnim = anim;
726  while (QAnimationGroup *group = topLevelAnim->group())
727  topLevelAnim = group;
728  topLevelAnim->stop();
729 
730  if (resetAnimationEndValues.contains(anim)) {
731  qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize
733  }
735  Q_ASSERT(assn.object != 0);
736  // If there is no property assignment that sets this property,
737  // set the property to its target value.
738  bool found = false;
740  for (it = propertyAssignmentsForState.constBegin(); it != propertyAssignmentsForState.constEnd(); ++it) {
741  const QList<QPropertyAssignment> &assignments = it.value();
742  for (int k = 0; k < assignments.size(); ++k) {
743  if ((assignments.at(k).object == assn.object)
744  && (assignments.at(k).propertyName == assn.propertyName)) {
745  found = true;
746  break;
747  }
748  }
749  }
750  if (!found) {
751  assn.object->setProperty(assn.propertyName, assn.value);
752  }
753  }
754  }
755 
756  // Find the animations to use for the state change.
757  QList<QAbstractAnimation*> selectedAnimations;
758  if (animated) {
759  for (int i = 0; i < transitionList.size(); ++i) {
760  QAbstractTransition *transition = transitionList.at(i);
761 
762  selectedAnimations << transition->animations();
763  selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
764 
765  QList<QAbstractState *> targetStates = transition->targetStates();
766  for (int j=0; j<targetStates.size(); ++j)
767  selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));
768  }
769  selectedAnimations << defaultAnimations;
770  }
771 
772  // Initialize animations from property assignments.
773  for (int i = 0; i < selectedAnimations.size(); ++i) {
774  QAbstractAnimation *anim = selectedAnimations.at(i);
776  for (it = propertyAssignmentsForState.begin(); it != propertyAssignmentsForState.end(); ) {
778  QAbstractState *s = it.key();
779  QList<QPropertyAssignment> &assignments = it.value();
780  for (it2 = assignments.begin(); it2 != assignments.end(); ) {
782  ret = initializeAnimation(anim, *it2);
783  QList<QAbstractAnimation*> handlers = ret.first;
784  if (!handlers.isEmpty()) {
785  for (int j = 0; j < handlers.size(); ++j) {
786  QAbstractAnimation *a = handlers.at(j);
787  propertyForAnimation.insert(a, *it2);
789  animationsForState[s].append(a);
790  // ### connect to just the top-level animation?
792  }
793  it2 = assignments.erase(it2);
794  } else {
795  ++it2;
796  }
797  for (int j = 0; j < ret.second.size(); ++j)
799  }
800  if (assignments.isEmpty())
801  it = propertyAssignmentsForState.erase(it);
802  else
803  ++it;
804  }
805  // We require that at least one animation is valid.
806  // ### generalize
808  if (QVariantAnimation *va = qobject_cast<QVariantAnimation*>(anim))
809  variantAnims.append(va);
810 
811  bool hasValidEndValue = false;
812  for (int j = 0; j < variantAnims.size(); ++j) {
813  if (variantAnims.at(j)->endValue().isValid()) {
814  hasValidEndValue = true;
815  break;
816  }
817  }
818 
819  if (hasValidEndValue) {
820  if (anim->state() == QAbstractAnimation::Running) {
821  // The animation is still running. This can happen if the
822  // animation is a group, and one of its children just finished,
823  // and that caused a state to emit its propertiesAssigned() signal, and
824  // that triggered a transition in the machine.
825  // Just stop the animation so it is correctly restarted again.
826  anim->stop();
827  }
828  anim->start();
829  }
830  }
831 #endif // !QT_NO_ANIMATION
832 
833  // Immediately set the properties that are not animated.
834  {
836  for (it = propertyAssignmentsForState.constBegin(); it != propertyAssignmentsForState.constEnd(); ++it) {
837  const QList<QPropertyAssignment> &assignments = it.value();
838  for (int i = 0; i < assignments.size(); ++i) {
839  const QPropertyAssignment &assn = assignments.at(i);
840  assn.object->setProperty(assn.propertyName, assn.value);
841  }
842  }
843  }
844 
845  // Emit propertiesAssigned signal for entered states that have no animated properties.
846  for (int i = 0; i < enteredStates.size(); ++i) {
847  QState *s = toStandardState(enteredStates.at(i));
848  if (s
849 #ifndef QT_NO_ANIMATION
851 #endif
852  )
854  }
855 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
QVariant endValue
the end value of the animation
QStateMachine::RestorePolicy globalRestorePolicy
unsigned char c[8]
Definition: qnumeric_p.h:62
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
QPair< QList< QAbstractAnimation * >, QList< QAbstractAnimation * > > initializeAnimation(QAbstractAnimation *abstractAnimation, const QPropertyAssignment &prop)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
QList< QAbstractState * > targetStates
the target states of this transition
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
bool remove(const T &value)
Definition: qset.h:89
#define SLOT(a)
Definition: qobjectdefs.h:226
T1 first
Definition: qpair.h:65
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
T2 second
Definition: qpair.h:66
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QPair< QObject *, QByteArray > RestorableId
QVariant value
Definition: qstate_p.h:74
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForTarget
long ASN1_INTEGER_get ASN1_INTEGER * a
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QObject * object
Definition: qstate_p.h:72
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
State state
state of the animation.
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
void stop()
Stops the animation.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractAnimation * > animations() const
Returns the list of animations associated with this transition, or an empty list if it has no animati...
QAnimationGroup * group() const
If this animation is part of a QAnimationGroup, this function returns a pointer to the group; otherwi...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QHash< QAbstractAnimation *, QPropertyAssignment > propertyForAnimation
The QAbstractState class is the base class of states of a QStateMachine.
bool contains(const T &value) const
Definition: qset.h:91
The QVariantAnimation class provides an abstract base class for animations.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
const_iterator insert(const T &value)
Definition: qset.h:179
The QAbstractAnimation class is the base of all animations.
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
QList< QAbstractAnimation * > defaultAnimations
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
QState * sourceState
the source state (parent) of this transition
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QHash< RestorableId, QVariant > registeredRestorables
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QByteArray propertyName
Definition: qstate_p.h:73
QList< QPropertyAssignment > restorablesToPropertyList(const QHash< RestorableId, QVariant > &restorables) const
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QHash< QAbstractAnimation *, QAbstractState * > stateForAnimation
void emitPropertiesAssigned()
Definition: qstate.cpp:159
QSet< QAbstractAnimation * > resetAnimationEndValues
The QAnimationGroup class is an abstract base class for groups of animations.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static QState * toStandardState(QAbstractState *state)
QMultiHash< QAbstractState *, QAbstractAnimation * > defaultAnimationsForSource
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QList< QPropertyAssignment > propertyAssignments
Definition: qstate_p.h:107
QList< T > findChildren(const QString &aName=QString()) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
Definition: qobject.h:162
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
void registerRestorable(QObject *object, const QByteArray &propertyName)
QHash< QAbstractState *, QList< QAbstractAnimation * > > animationsForState

◆ cancelAllDelayedEvents()

void QStateMachinePrivate::cancelAllDelayedEvents ( )

Definition at line 1395 of file qstatemachine.cpp.

Referenced by _q_process().

1396 {
1397  Q_Q(QStateMachine);
1400  for (it = delayedEvents.constBegin(); it != delayedEvents.constEnd(); ++it) {
1401  int id = it.key();
1402  QEvent *e = it.value();
1403  q->killTimer(id);
1404  delete e;
1405  }
1406  delayedEvents.clear();
1407 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
void clear()
Removes all items from the hash.
Definition: qhash.h:574
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
#define Q_Q(Class)
Definition: qglobal.h:2483
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
QHash< int, QEvent * > delayedEvents
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ clearHistory()

void QStateMachinePrivate::clearHistory ( )

Definition at line 1192 of file qstatemachine.cpp.

Referenced by _q_start().

1193 {
1194  Q_Q(QStateMachine);
1195  QList<QHistoryState*> historyStates = q->findChildren<QHistoryState*>();
1196  for (int i = 0; i < historyStates.size(); ++i) {
1197  QHistoryState *h = historyStates.at(i);
1199  }
1200 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractState * > configuration
static QHistoryStatePrivate * get(QHistoryState *q)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QHistoryState class provides a means of returning to a previously active substate.
Definition: qhistorystate.h:56
QList< QHistoryState * > historyStates() const
Definition: qstate.cpp:215
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ dequeueExternalEvent()

QEvent * QStateMachinePrivate::dequeueExternalEvent ( )

Definition at line 1357 of file qstatemachine.cpp.

Referenced by _q_process().

1358 {
1361  return 0;
1362  return externalEventQueue.takeFirst();
1363 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
QList< QEvent * > externalEventQueue
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ dequeueInternalEvent()

QEvent * QStateMachinePrivate::dequeueInternalEvent ( )

Definition at line 1349 of file qstatemachine.cpp.

Referenced by _q_process().

1350 {
1353  return 0;
1354  return internalEventQueue.takeFirst();
1355 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QEvent * > internalEventQueue

◆ enterStates()

QList< QAbstractState * > QStateMachinePrivate::enterStates ( QEvent event,
const QList< QAbstractTransition *> &  enabledTransitions 
)

Definition at line 476 of file qstatemachine.cpp.

Referenced by _q_start(), and microstep().

477 {
478 #ifdef QSTATEMACHINE_DEBUG
480 #endif
481 // qDebug() << "enterStates(" << enabledTransitions << ')';
482  QSet<QAbstractState*> statesToEnter;
483  QSet<QAbstractState*> statesForDefaultEntry;
484 
485  if (pendingErrorStates.isEmpty()) {
486  for (int i = 0; i < enabledTransitions.size(); ++i) {
487  QAbstractTransition *t = enabledTransitions.at(i);
489  if (lst.isEmpty())
490  continue;
491  lst.prepend(t->sourceState());
492  QState *lca = findLCA(lst);
493  for (int j = 1; j < lst.size(); ++j) {
494  QAbstractState *s = lst.at(j);
495  addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
496  if (isParallel(lca)) {
498  foreach (QAbstractState* child,lcac) {
499  if (!statesToEnter.contains(child))
500  addStatesToEnter(child,lca,statesToEnter,statesForDefaultEntry);
501  }
502  }
503  }
504  }
505  }
506 
507  // Did an error occur while selecting transitions? Then we enter the error state.
508  if (!pendingErrorStates.isEmpty()) {
509  statesToEnter.clear();
510  statesToEnter = pendingErrorStates;
511  statesForDefaultEntry = pendingErrorStatesForDefaultEntry;
514  }
515 
516  QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList();
517  qSort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan);
518 
519  for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
520  QAbstractState *s = statesToEnter_sorted.at(i);
521 #ifdef QSTATEMACHINE_DEBUG
522  qDebug() << q << ": entering" << s;
523 #endif
528  if (statesForDefaultEntry.contains(s)) {
529  // ### executeContent(s.initial.transition.children())
530  }
531  if (isFinal(s)) {
532  QState *parent = s->parentState();
533  if (parent) {
534  if (parent != rootState()) {
535 #ifdef QSTATEMACHINE_DEBUG
536  qDebug() << q << ": emitting finished signal for" << parent;
537 #endif
538  QStatePrivate::get(parent)->emitFinished();
539  }
540  QState *grandparent = parent->parentState();
541  if (grandparent && isParallel(grandparent)) {
542  bool allChildStatesFinal = true;
544  for (int j = 0; j < childStates.size(); ++j) {
545  QAbstractState *cs = childStates.at(j);
546  if (!isInFinalState(cs)) {
547  allChildStatesFinal = false;
548  break;
549  }
550  }
551  if (allChildStatesFinal && (grandparent != rootState())) {
552 #ifdef QSTATEMACHINE_DEBUG
553  qDebug() << q << ": emitting finished signal for" << grandparent;
554 #endif
555  QStatePrivate::get(grandparent)->emitFinished();
556  }
557  }
558  }
559  }
560  }
561  {
563  for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
564  if (isFinal(*it) && (*it)->parentState() == rootState()) {
565  processing = false;
567  break;
568  }
569  }
570  }
571 // qDebug() << "configuration:" << configuration.toList();
572  return statesToEnter_sorted;
573 }
void callOnEntry(QEvent *e)
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
QList< QAbstractState * > targetStates
the target states of this transition
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
static bool stateEntryLessThan(QAbstractState *s1, QAbstractState *s2)
const_iterator constEnd() const
Definition: qset.h:171
bool isEmpty() const
Definition: qset.h:77
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
StopProcessingReason stopProcessingReason
QSet< QAbstractState * > configuration
void addStatesToEnter(QAbstractState *s, QState *root, QSet< QAbstractState *> &statesToEnter, QSet< QAbstractState *> &statesForDefaultEntry)
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
void registerTransitions(QAbstractState *state)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
QSet< QAbstractState * > pendingErrorStates
The QAbstractState class is the base class of states of a QStateMachine.
bool contains(const T &value) const
Definition: qset.h:91
QList< T > toList() const
Definition: qset.h:296
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
void clear()
Definition: qset.h:87
QState * rootState() const
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
static QAbstractStatePrivate * get(QAbstractState *q)
QState * sourceState
the source state (parent) of this transition
static bool isFinal(const QAbstractState *s)
QState * findLCA(const QList< QAbstractState *> &states) const
QList< QAbstractState * > childStates() const
Definition: qstate.cpp:199
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const_iterator constBegin() const
Definition: qset.h:168
QObject * parent
Definition: qobject.h:92
bool isInFinalState(QAbstractState *s) const
static bool isParallel(const QAbstractState *s)
QSet< QAbstractState * > pendingErrorStatesForDefaultEntry
void emitFinished()
Definition: qstate.cpp:153
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ executeTransitionContent()

void QStateMachinePrivate::executeTransitionContent ( QEvent event,
const QList< QAbstractTransition *> &  transitionList 
)

Definition at line 464 of file qstatemachine.cpp.

Referenced by _q_start(), and microstep().

465 {
466  for (int i = 0; i < enabledTransitions.size(); ++i) {
467  QAbstractTransition *t = enabledTransitions.at(i);
468 #ifdef QSTATEMACHINE_DEBUG
469  qDebug() << q_func() << ": triggering" << t;
470 #endif
473  }
474 }
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
Q_CORE_EXPORT void qDebug(const char *,...)
static QAbstractTransitionPrivate * get(QAbstractTransition *q)
virtual void callOnTransition(QEvent *e)

◆ exitStates()

QList< QAbstractState * > QStateMachinePrivate::exitStates ( QEvent event,
const QList< QAbstractTransition *> &  transitionList 
)

Definition at line 396 of file qstatemachine.cpp.

Referenced by microstep().

397 {
398 // qDebug() << "exitStates(" << enabledTransitions << ')';
399  QSet<QAbstractState*> statesToExit;
400 // QSet<QAbstractState*> statesToSnapshot;
401  for (int i = 0; i < enabledTransitions.size(); ++i) {
402  QAbstractTransition *t = enabledTransitions.at(i);
404  if (lst.isEmpty())
405  continue;
406  lst.prepend(t->sourceState());
407  QAbstractState *lca = findLCA(lst);
408  if (lca == 0) {
410  lst = pendingErrorStates.toList();
411  lst.prepend(t->sourceState());
412 
413  lca = findLCA(lst);
414  Q_ASSERT(lca != 0);
415  }
416 
417  {
419  for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
420  QAbstractState *s = *it;
421  if (isDescendantOf(s, lca))
422  statesToExit.insert(s);
423  }
424  }
425  }
426  QList<QAbstractState*> statesToExit_sorted = statesToExit.toList();
427  qSort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan);
428  for (int i = 0; i < statesToExit_sorted.size(); ++i) {
429  QAbstractState *s = statesToExit_sorted.at(i);
430  if (QState *grp = toStandardState(s)) {
432  for (int j = 0; j < hlst.size(); ++j) {
433  QHistoryState *h = hlst.at(j);
436  for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
437  QAbstractState *s0 = *it;
439  if (isAtomic(s0) && isDescendantOf(s0, s))
441  } else if (s0->parentState() == s) {
443  }
444  }
445 #ifdef QSTATEMACHINE_DEBUG
446  qDebug() << q_func() << ": recorded" << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow")
447  << "history for" << s << "in" << h << ':' << QHistoryStatePrivate::get(h)->configuration;
448 #endif
449  }
450  }
451  }
452  for (int i = 0; i < statesToExit_sorted.size(); ++i) {
453  QAbstractState *s = statesToExit_sorted.at(i);
454 #ifdef QSTATEMACHINE_DEBUG
455  qDebug() << q_func() << ": exiting" << s;
456 #endif
460  }
461  return statesToExit_sorted;
462 }
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
QList< QAbstractState * > targetStates
the target states of this transition
#define it(className, varName)
bool remove(const T &value)
Definition: qset.h:89
const_iterator constEnd() const
Definition: qset.h:171
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QHistoryState::HistoryType historyType
QSet< QAbstractState * > configuration
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
QList< QAbstractState * > configuration
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static QHistoryStatePrivate * get(QHistoryState *q)
void setError(QStateMachine::Error error, QAbstractState *currentContext)
QSet< QAbstractState * > pendingErrorStates
The QAbstractState class is the base class of states of a QStateMachine.
QList< T > toList() const
Definition: qset.h:296
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
void clear()
Removes all items from the list.
Definition: qlist.h:764
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
static QAbstractStatePrivate * get(QAbstractState *q)
void callOnExit(QEvent *e)
The QHistoryState class provides a means of returning to a previously active substate.
Definition: qhistorystate.h:56
QState * sourceState
the source state (parent) of this transition
QList< QHistoryState * > historyStates() const
Definition: qstate.cpp:215
static bool stateExitLessThan(QAbstractState *s1, QAbstractState *s2)
QState * findLCA(const QList< QAbstractState *> &states) const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const_iterator constBegin() const
Definition: qset.h:168
static QState * toStandardState(QAbstractState *state)
bool isAtomic(const QAbstractState *s) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ findErrorState()

QAbstractState * QStateMachinePrivate::findErrorState ( QAbstractState context)

Definition at line 1017 of file qstatemachine.cpp.

Referenced by setError().

1018 {
1019  // Find error state recursively in parent hierarchy if not set explicitly for context state
1021  if (context != 0) {
1022  QState *s = toStandardState(context);
1023  if (s != 0)
1024  errorState = s->errorState();
1025 
1026  if (errorState == 0)
1027  errorState = findErrorState(context->parentState());
1028  }
1029 
1030  return errorState;
1031 }
QAbstractState * findErrorState(QAbstractState *context)
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
The QAbstractState class is the base class of states of a QStateMachine.
static QState * toStandardState(QAbstractState *state)
QAbstractState * errorState
Definition: qstate_p.h:99
QAbstractState * errorState
the error state of this state
Definition: qstate.h:65

◆ findLCA()

QState * QStateMachinePrivate::findLCA ( const QList< QAbstractState *> &  states) const

Definition at line 299 of file qstatemachine.cpp.

Referenced by enterStates(), exitStates(), isPreempted(), and setError().

300 {
301  if (states.isEmpty())
302  return 0;
303  QList<QState*> ancestors = properAncestors(states.at(0), rootState()->parentState());
304  for (int i = 0; i < ancestors.size(); ++i) {
305  QState *anc = ancestors.at(i);
306  bool ok = true;
307  for (int j = states.size() - 1; (j > 0) && ok; --j) {
308  const QAbstractState *s = states.at(j);
309  if (!isDescendantOf(s, anc))
310  ok = false;
311  }
312  if (ok)
313  return anc;
314  }
315  return 0;
316 }
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QAbstractState class is the base class of states of a QStateMachine.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QState * rootState() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QList< QState * > properAncestors(const QAbstractState *s, const QState *upperBound)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ get()

QStateMachinePrivate * QStateMachinePrivate::get ( QStateMachine q)
static

◆ goToState()

void QStateMachinePrivate::goToState ( QAbstractState targetState)

Causes this state machine to unconditionally transition to the given targetState.

Warning
This function is not part of the public interface.

Provides a backdoor for using the state machine "imperatively"; i.e. rather than defining explicit transitions, you drive the machine's execution by calling this function. It breaks the whole integrity of the transition-driven model, but is provided for pragmatic reasons.

Definition at line 1440 of file qstatemachine.cpp.

1441 {
1442  if (!targetState) {
1443  qWarning("QStateMachine::goToState(): cannot go to null state");
1444  return;
1445  }
1446 
1447  if (configuration.contains(targetState))
1448  return;
1449 
1450  QState *sourceState = 0;
1451  if (state == Running) {
1453  for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
1454  sourceState = toStandardState(*it);
1455  if (sourceState != 0)
1456  break;
1457  }
1458  } else {
1459  sourceState = startState();
1460  }
1461 
1462  Q_ASSERT(sourceState != 0);
1463  // Reuse previous GoToStateTransition in case of several calls to
1464  // goToState() in a row.
1465  GoToStateTransition *trans = sourceState->findChild<GoToStateTransition*>();
1466  if (!trans) {
1467  trans = new GoToStateTransition(targetState);
1468  sourceState->addTransition(trans);
1469  } else {
1470  trans->setTargetState(targetState);
1471  }
1472 
1474 }
#define it(className, varName)
const_iterator constEnd() const
Definition: qset.h:171
QSet< QAbstractState * > configuration
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
void processEvents(EventProcessingMode processingMode)
bool contains(const T &value) const
Definition: qset.h:91
Q_CORE_EXPORT void qWarning(const char *,...)
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
void setTargetState(QAbstractState *target)
Sets the target state of this transition.
const_iterator constBegin() const
Definition: qset.h:168
static QState * toStandardState(QAbstractState *state)
void addTransition(QAbstractTransition *transition)
Adds the given transition.
Definition: qstate.cpp:308

◆ handleFilteredEvent()

void QStateMachinePrivate::handleFilteredEvent ( QObject watched,
QEvent event 
)

Definition at line 1651 of file qstatemachine.cpp.

1652 {
1653  if (qobjectEvents.value(watched).contains(event->type())) {
1656  }
1657 }
The WrappedEvent class inherits QEvent and holds a clone of an event associated with a QObject...
Definition: qstatemachine.h:92
void postInternalEvent(QEvent *e)
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void processEvents(EventProcessingMode processingMode)
QHash< QObject *, QHash< QEvent::Type, int > > qobjectEvents
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static const Handler * handler

◆ handleTransitionSignal()

void QStateMachinePrivate::handleTransitionSignal ( QObject sender,
int  signalIndex,
void **  args 
)

Definition at line 1660 of file qstatemachine.cpp.

Referenced by QSignalEventGenerator::qt_metacall().

1662 {
1663  Q_ASSERT(connections[sender].at(signalIndex) != 0);
1664  const QMetaObject *meta = sender->metaObject();
1665  QMetaMethod method = meta->method(signalIndex);
1666  QList<QByteArray> parameterTypes = method.parameterTypes();
1667  int argc = parameterTypes.count();
1668  QList<QVariant> vargs;
1669  for (int i = 0; i < argc; ++i) {
1670  int type = QMetaType::type(parameterTypes.at(i));
1671  vargs.append(QVariant(type, argv[i+1]));
1672  }
1673 
1674 #ifdef QSTATEMACHINE_DEBUG
1675  qDebug() << q_func() << ": sending signal event ( sender =" << sender
1676  << ", signal =" << sender->metaObject()->method(signalIndex).signature() << ')';
1677 #endif
1680 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
void postInternalEvent(QEvent *e)
#define at(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void processEvents(EventProcessingMode processingMode)
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
QHash< const QObject *, QVector< int > > connections
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
The SignalEvent class represents a Qt signal event.
Definition: qstatemachine.h:73
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719

◆ hasRestorable()

bool QStateMachinePrivate::hasRestorable ( QObject object,
const QByteArray propertyName 
) const

Returns true if the variable with the given id has been registered for restoration.

Warning
This function is not part of the public interface.

Definition at line 993 of file qstatemachine.cpp.

994 {
995  return registeredRestorables.contains(RestorableId(object, propertyName));
996 }
QPair< QObject *, QByteArray > RestorableId
QHash< RestorableId, QVariant > registeredRestorables

◆ initializeAnimation()

QPair< QList< QAbstractAnimation * >, QList< QAbstractAnimation * > > QStateMachinePrivate::initializeAnimation ( QAbstractAnimation abstractAnimation,
const QPropertyAssignment prop 
)

Definition at line 1087 of file qstatemachine.cpp.

Referenced by applyProperties().

1089 {
1090  QList<QAbstractAnimation*> handledAnimations;
1091  QList<QAbstractAnimation*> localResetEndValues;
1092  QAnimationGroup *group = qobject_cast<QAnimationGroup*>(abstractAnimation);
1093  if (group) {
1094  for (int i = 0; i < group->animationCount(); ++i) {
1095  QAbstractAnimation *animationChild = group->animationAt(i);
1097  ret = initializeAnimation(animationChild, prop);
1098  handledAnimations << ret.first;
1099  localResetEndValues << ret.second;
1100  }
1101  } else {
1102  QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation);
1103  if (animation != 0
1104  && prop.object == animation->targetObject()
1105  && prop.propertyName == animation->propertyName()) {
1106 
1107  // Only change end value if it is undefined
1108  if (!animation->endValue().isValid()) {
1109  animation->setEndValue(prop.value);
1110  localResetEndValues.append(animation);
1111  }
1112  handledAnimations.append(animation);
1113  }
1114  }
1115  return qMakePair(handledAnimations, localResetEndValues);
1116 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QPropertyAnimation class animates Qt properties.
QAbstractAnimation * animationAt(int index) const
Returns a pointer to the animation at index in this group.
QPair< QList< QAbstractAnimation * >, QList< QAbstractAnimation * > > initializeAnimation(QAbstractAnimation *abstractAnimation, const QPropertyAssignment &prop)
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
int animationCount() const
Returns the number of animations managed by this group.
QVariant endValue() const
QVariant value
Definition: qstate_p.h:74
void setEndValue(const QVariant &value)
QObject * object
Definition: qstate_p.h:72
QObject * targetObject
the target QObject for this animation.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QAbstractAnimation class is the base of all animations.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
QByteArray propertyName
Definition: qstate_p.h:73
QByteArray propertyName
the target property name for this animation
The QAnimationGroup class is an abstract base class for groups of animations.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isAtomic()

bool QStateMachinePrivate::isAtomic ( const QAbstractState s) const

Definition at line 883 of file qstatemachine.cpp.

Referenced by exitStates(), and selectTransitions().

884 {
885  const QState *ss = toStandardState(s);
886  return (ss && QStatePrivate::get(ss)->childStates().isEmpty())
887  || isFinal(s)
888  // Treat the machine as atomic if it's a sub-state of this machine
889  || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState()));
890 }
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static bool isEmpty(const char *str)
QState * rootState() const
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
static bool isFinal(const QAbstractState *s)
QList< QAbstractState * > childStates() const
Definition: qstate.cpp:199
static QState * toStandardState(QAbstractState *state)

◆ isCompound()

bool QStateMachinePrivate::isCompound ( const QAbstractState s) const

Definition at line 870 of file qstatemachine.cpp.

Referenced by addStatesToEnter(), and isInFinalState().

871 {
872  const QState *group = toStandardState(s);
873  if (!group)
874  return false;
875  bool isMachine = QStatePrivate::get(group)->isMachine;
876  // Don't treat the machine as compound if it's a sub-state of this machine
877  if (isMachine && (group != rootState()))
878  return false;
879  return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty())
880  || isMachine;
881 }
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static bool isEmpty(const char *str)
QState * rootState() const
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
QList< QAbstractState * > childStates() const
Definition: qstate.cpp:199
static QState * toStandardState(QAbstractState *state)
static bool isParallel(const QAbstractState *s)

◆ isDescendantOf()

bool QStateMachinePrivate::isDescendantOf ( const QAbstractState s,
const QAbstractState other 
)
static

Definition at line 893 of file qstatemachine.cpp.

Referenced by addStatesToEnter(), exitStates(), findLCA(), indexOfDescendant(), isPreempted(), stateEntryLessThan(), and stateExitLessThan().

894 {
895  Q_ASSERT(state != 0);
896  for (QAbstractState *s = state->parentState(); s != 0; s = s->parentState()) {
897  if (s == other)
898  return true;
899  }
900  return false;
901 }
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QAbstractState class is the base class of states of a QStateMachine.

◆ isExternalEventQueueEmpty()

bool QStateMachinePrivate::isExternalEventQueueEmpty ( )

Definition at line 1371 of file qstatemachine.cpp.

1372 {
1374  return externalEventQueue.isEmpty();
1375 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QEvent * > externalEventQueue
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ isFinal()

bool QStateMachinePrivate::isFinal ( const QAbstractState s)
static

Definition at line 859 of file qstatemachine.cpp.

Referenced by enterStates(), isAtomic(), and isInFinalState().

860 {
862 }
static QAbstractStatePrivate * get(QAbstractState *q)

◆ isInFinalState()

bool QStateMachinePrivate::isInFinalState ( QAbstractState s) const

Definition at line 941 of file qstatemachine.cpp.

Referenced by enterStates().

942 {
943  if (isCompound(s)) {
944  QState *grp = toStandardState(s);
946  for (int i = 0; i < lst.size(); ++i) {
947  QAbstractState *cs = lst.at(i);
948  if (isFinal(cs) && configuration.contains(cs))
949  return true;
950  }
951  return false;
952  } else if (isParallel(s)) {
953  QState *grp = toStandardState(s);
955  for (int i = 0; i < lst.size(); ++i) {
956  QAbstractState *cs = lst.at(i);
957  if (!isInFinalState(cs))
958  return false;
959  }
960  return true;
961  }
962  else
963  return false;
964 }
QSet< QAbstractState * > configuration
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
The QAbstractState class is the base class of states of a QStateMachine.
bool contains(const T &value) const
Definition: qset.h:91
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isCompound(const QAbstractState *s) const
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
static bool isFinal(const QAbstractState *s)
QList< QAbstractState * > childStates() const
Definition: qstate.cpp:199
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isInFinalState(QAbstractState *s) const
static QState * toStandardState(QAbstractState *state)
static bool isParallel(const QAbstractState *s)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isInternalEventQueueEmpty()

bool QStateMachinePrivate::isInternalEventQueueEmpty ( )

Definition at line 1365 of file qstatemachine.cpp.

Referenced by _q_process().

1366 {
1368  return internalEventQueue.isEmpty();
1369 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QEvent * > internalEventQueue

◆ isParallel()

bool QStateMachinePrivate::isParallel ( const QAbstractState s)
static

Definition at line 864 of file qstatemachine.cpp.

Referenced by addStatesToEnter(), enterStates(), isCompound(), and isInFinalState().

865 {
866  const QState *ss = toStandardState(s);
867  return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates);
868 }
QState::ChildMode childMode
Definition: qstate_p.h:101
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
static QState * toStandardState(QAbstractState *state)

◆ isPreempted()

bool QStateMachinePrivate::isPreempted ( const QAbstractState s,
const QSet< QAbstractTransition *> &  transitions 
) const

Definition at line 318 of file qstatemachine.cpp.

Referenced by selectTransitions().

319 {
321  for (it = transitions.constBegin(); it != transitions.constEnd(); ++it) {
322  QAbstractTransition *t = *it;
324  if (!lst.isEmpty()) {
325  lst.prepend(t->sourceState());
326  QAbstractState *lca = findLCA(lst);
327  if (isDescendantOf(s, lca)) {
328 #ifdef QSTATEMACHINE_DEBUG
329  qDebug() << q_func() << ':' << transitions << "preempts selection of a transition from"
330  << s << "because" << s << "is a descendant of" << lca;
331 #endif
332  return true;
333  }
334  }
335  }
336  return false;
337 }
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
QList< QAbstractState * > targetStates
the target states of this transition
#define it(className, varName)
const_iterator constEnd() const
Definition: qset.h:171
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
The QAbstractState class is the base class of states of a QStateMachine.
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
QState * sourceState
the source state (parent) of this transition
QState * findLCA(const QList< QAbstractState *> &states) const
const_iterator constBegin() const
Definition: qset.h:168
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ microstep()

void QStateMachinePrivate::microstep ( QEvent event,
const QList< QAbstractTransition *> &  transitionList 
)

Definition at line 375 of file qstatemachine.cpp.

Referenced by _q_process().

376 {
377 #ifdef QSTATEMACHINE_DEBUG
378  qDebug() << q_func() << ": begin microstep( enabledTransitions:" << enabledTransitions << ')';
379  qDebug() << q_func() << ": configuration before exiting states:" << configuration;
380 #endif
381  QList<QAbstractState*> exitedStates = exitStates(event, enabledTransitions);
382 #ifdef QSTATEMACHINE_DEBUG
383  qDebug() << q_func() << ": configuration after exiting states:" << configuration;
384 #endif
385  executeTransitionContent(event, enabledTransitions);
386  QList<QAbstractState*> enteredStates = enterStates(event, enabledTransitions);
387 #ifndef QT_NO_PROPERTIES
388  applyProperties(enabledTransitions, exitedStates, enteredStates);
389 #endif
390 #ifdef QSTATEMACHINE_DEBUG
391  qDebug() << q_func() << ": configuration after entering states:" << configuration;
392  qDebug() << q_func() << ": end microstep";
393 #endif
394 }
QSet< QAbstractState * > configuration
Q_CORE_EXPORT void qDebug(const char *,...)
void applyProperties(const QList< QAbstractTransition *> &transitionList, const QList< QAbstractState *> &exitedStates, const QList< QAbstractState *> &enteredStates)
void executeTransitionContent(QEvent *event, const QList< QAbstractTransition *> &transitionList)
QList< QAbstractState * > enterStates(QEvent *event, const QList< QAbstractTransition *> &enabledTransitions)
QList< QAbstractState * > exitStates(QEvent *event, const QList< QAbstractTransition *> &transitionList)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ postExternalEvent()

void QStateMachinePrivate::postExternalEvent ( QEvent e)

Definition at line 1343 of file qstatemachine.cpp.

1344 {
1347 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QEvent * > externalEventQueue
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ postInternalEvent()

void QStateMachinePrivate::postInternalEvent ( QEvent e)

Definition at line 1337 of file qstatemachine.cpp.

Referenced by handleFilteredEvent(), and handleTransitionSignal().

1338 {
1341 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QEvent * > internalEventQueue

◆ processEvents()

void QStateMachinePrivate::processEvents ( EventProcessingMode  processingMode)

Definition at line 1377 of file qstatemachine.cpp.

Referenced by goToState(), handleFilteredEvent(), and handleTransitionSignal().

1378 {
1379  Q_Q(QStateMachine);
1381  return;
1382  switch (processingMode) {
1383  case DirectProcessing:
1384  if (QThread::currentThread() == q->thread()) {
1385  _q_process();
1386  break;
1387  } // fallthrough -- processing must be done in the machine thread
1388  case QueuedProcessing:
1389  processingScheduled = true;
1391  break;
1392  }
1393 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define Q_Q(Class)
Definition: qglobal.h:2483
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ properAncestors()

QList< QState * > QStateMachinePrivate::properAncestors ( const QAbstractState s,
const QState upperBound 
)
static

Definition at line 903 of file qstatemachine.cpp.

Referenced by addStatesToEnter(), findLCA(), and selectTransitions().

904 {
905  Q_ASSERT(state != 0);
906  QList<QState*> result;
907  for (QState *s = state->parentState(); s && s != upperBound; s = s->parentState()) {
908  result.append(s);
909  }
910  return result;
911 }
QState * parentState() const
Returns this state&#39;s parent state, or 0 if the state has no parent state.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ registerEventTransition()

void QStateMachinePrivate::registerEventTransition ( QEventTransition transition)

Definition at line 1605 of file qstatemachine.cpp.

Referenced by QEventTransitionPrivate::maybeRegister(), and registerTransitions().

1606 {
1607  Q_Q(QStateMachine);
1608  if (QEventTransitionPrivate::get(transition)->registered)
1609  return;
1610  if (transition->eventType() >= QEvent::User) {
1611  qWarning("QObject event transitions are not supported for custom types");
1612  return;
1613  }
1614  QObject *object = QEventTransitionPrivate::get(transition)->object;
1615  if (!object)
1616  return;
1617  QObjectPrivate *od = QObjectPrivate::get(object);
1618  if (!od->eventFilters.contains(q))
1619  object->installEventFilter(q);
1620  ++qobjectEvents[object][transition->eventType()];
1621  QEventTransitionPrivate::get(transition)->registered = true;
1622 #ifdef QSTATEMACHINE_DEBUG
1623  qDebug() << q << ": added event transition from" << transition->sourceState()
1624  << ": ( object =" << object << ", event =" << transition->eventType()
1625  << ", targets =" << transition->targetStates() << ')';
1626 #endif
1627 }
static QEventTransitionPrivate * get(QEventTransition *q)
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QEvent::Type eventType
the type of event that this event transition is associated with
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
QHash< QObject *, QHash< QEvent::Type, int > > qobjectEvents
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractState * > targetStates() const
QList< QPointer< QObject > > eventFilters
Definition: qobject_p.h:211
Q_CORE_EXPORT void qDebug(const char *,...)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
Q_CORE_EXPORT void qWarning(const char *,...)
QState * sourceState() const
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070

◆ registerRestorable()

void QStateMachinePrivate::registerRestorable ( QObject object,
const QByteArray propertyName 
)

Definition at line 968 of file qstatemachine.cpp.

Referenced by applyProperties().

969 {
970  RestorableId id(object, propertyName);
971  if (!registeredRestorables.contains(id))
972  registeredRestorables.insert(id, object->property(propertyName));
973 }
QPair< QObject *, QByteArray > RestorableId
QHash< RestorableId, QVariant > registeredRestorables
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807

◆ registerSignalTransition()

void QStateMachinePrivate::registerSignalTransition ( QSignalTransition transition)

Definition at line 1507 of file qstatemachine.cpp.

Referenced by QSignalTransitionPrivate::maybeRegister(), and registerTransitions().

1508 {
1509  Q_Q(QStateMachine);
1510  if (QSignalTransitionPrivate::get(transition)->signalIndex != -1)
1511  return; // already registered
1512  QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
1513  if (!sender)
1514  return;
1515  QByteArray signal = QSignalTransitionPrivate::get(transition)->signal;
1516  if (signal.startsWith('0'+QSIGNAL_CODE))
1517  signal.remove(0, 1);
1518  const QMetaObject *meta = sender->metaObject();
1519  int signalIndex = meta->indexOfSignal(signal);
1520  int originalSignalIndex = signalIndex;
1521  if (signalIndex == -1) {
1522  signalIndex = meta->indexOfSignal(QMetaObject::normalizedSignature(signal));
1523  if (signalIndex == -1) {
1524  qWarning("QSignalTransition: no such signal: %s::%s",
1525  meta->className(), signal.constData());
1526  return;
1527  }
1528  }
1529  // The signal index we actually want to connect to is the one
1530  // that is going to be sent, i.e. the non-cloned original index.
1531  while (meta->method(signalIndex).attributes() & QMetaMethod::Cloned)
1532  --signalIndex;
1533 
1534  QVector<int> &connectedSignalIndexes = connections[sender];
1535  if (connectedSignalIndexes.size() <= signalIndex)
1536  connectedSignalIndexes.resize(signalIndex+1);
1537  if (connectedSignalIndexes.at(signalIndex) == 0) {
1538  if (!signalEventGenerator)
1540  bool ok = QMetaObject::connect(sender, signalIndex, signalEventGenerator,
1542  if (!ok) {
1543 #ifdef QSTATEMACHINE_DEBUG
1544  qDebug() << q << ": FAILED to add signal transition from" << transition->sourceState()
1545  << ": ( sender =" << sender << ", signal =" << signal
1546  << ", targets =" << transition->targetStates() << ')';
1547 #endif
1548  return;
1549  }
1550  }
1551  ++connectedSignalIndexes[signalIndex];
1553  QSignalTransitionPrivate::get(transition)->originalSignalIndex = originalSignalIndex;
1554 #ifdef QSTATEMACHINE_DEBUG
1555  qDebug() << q << ": added signal transition from" << transition->sourceState()
1556  << ": ( sender =" << sender << ", signal =" << signal
1557  << ", targets =" << transition->targetStates() << ')';
1558 #endif
1559 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QAbstractState * > targetStates() const
Q_CORE_EXPORT void qDebug(const char *,...)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
int methodOffset() const
Returns the method offset for this class; i.e.
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
QSignalEventGenerator * signalEventGenerator
QState * sourceState() const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QHash< const QObject *, QVector< int > > connections
#define QSIGNAL_CODE
Definition: qobjectdefs.h:244
static QSignalTransitionPrivate * get(QSignalTransition *q)
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
int attributes() const
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719

◆ registerTransitions()

void QStateMachinePrivate::registerTransitions ( QAbstractState state)

Definition at line 1476 of file qstatemachine.cpp.

Referenced by QState::addTransition(), and enterStates().

1477 {
1478  QState *group = toStandardState(state);
1479  if (!group)
1480  return;
1482  for (int i = 0; i < transitions.size(); ++i) {
1483  QAbstractTransition *t = transitions.at(i);
1484  if (QSignalTransition *st = qobject_cast<QSignalTransition*>(t)) {
1486  }
1487 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
1488  else if (QEventTransition *oet = qobject_cast<QEventTransition*>(t)) {
1490  }
1491 #endif
1492  }
1493 }
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
void registerSignalTransition(QSignalTransition *transition)
The QEventTransition class provides a QObject-specific transition for Qt events.
The QSignalTransition class provides a transition based on a Qt signal.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QAbstractTransition * > transitions() const
Definition: qstate.cpp:227
void registerEventTransition(QEventTransition *transition)
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
#define st(var, type, card)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QState * toStandardState(QAbstractState *state)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ removeStartState()

void QStateMachinePrivate::removeStartState ( )

Definition at line 1186 of file qstatemachine.cpp.

Referenced by _q_start().

1187 {
1188  delete _startState;
1189  _startState = 0;
1190 }

◆ restorablesToPropertyList()

QList< QPropertyAssignment > QStateMachinePrivate::restorablesToPropertyList ( const QHash< RestorableId, QVariant > &  restorables) const

Definition at line 975 of file qstatemachine.cpp.

Referenced by applyProperties().

976 {
979  for (it = restorables.constBegin(); it != restorables.constEnd(); ++it) {
980 // qDebug() << "restorable:" << it.key().first << it.key().second << it.value();
981  result.append(QPropertyAssignment(it.key().first, it.key().second, it.value(), /*explicitlySet=*/false));
982  }
983  return result;
984 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469

◆ restorableValue()

QVariant QStateMachinePrivate::restorableValue ( QObject object,
const QByteArray propertyName 
) const

Definition at line 998 of file qstatemachine.cpp.

999 {
1000  return registeredRestorables.value(RestorableId(object, propertyName), QVariant());
1001 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPair< QObject *, QByteArray > RestorableId
QHash< RestorableId, QVariant > registeredRestorables

◆ rootState()

QState * QStateMachinePrivate::rootState ( ) const

Definition at line 221 of file qstatemachine.cpp.

Referenced by _q_start(), addStatesToEnter(), enterStates(), findLCA(), isAtomic(), isCompound(), selectTransitions(), setError(), and unregisterAllTransitions().

222 {
223  return const_cast<QStateMachine*>(q_func());
224 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63

◆ selectTransitions()

QSet< QAbstractTransition * > QStateMachinePrivate::selectTransitions ( QEvent event) const

Definition at line 339 of file qstatemachine.cpp.

Referenced by _q_process().

340 {
341  Q_Q(const QStateMachine);
342  QSet<QAbstractTransition*> enabledTransitions;
344  const_cast<QStateMachine*>(q)->beginSelectTransitions(event);
345  for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
346  QAbstractState *state = *it;
347  if (!isAtomic(state))
348  continue;
349  if (isPreempted(state, enabledTransitions))
350  continue;
352  if (QState *grp = toStandardState(state))
353  lst.prepend(grp);
354  bool found = false;
355  for (int j = 0; (j < lst.size()) && !found; ++j) {
356  QState *s = lst.at(j);
358  for (int k = 0; k < transitions.size(); ++k) {
359  QAbstractTransition *t = transitions.at(k);
360  if (QAbstractTransitionPrivate::get(t)->callEventTest(event)) {
361 #ifdef QSTATEMACHINE_DEBUG
362  qDebug() << q << ": selecting transition" << t;
363 #endif
364  enabledTransitions.insert(t);
365  found = true;
366  break;
367  }
368  }
369  }
370  }
371  const_cast<QStateMachine*>(q)->endSelectTransitions(event);
372  return enabledTransitions;
373 }
The QAbstractTransition class is the base class of transitions between QAbstractState objects...
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
const_iterator constEnd() const
Definition: qset.h:171
QSet< QAbstractState * > configuration
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
The QAbstractState class is the base class of states of a QStateMachine.
static QAbstractTransitionPrivate * get(QAbstractTransition *q)
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
QList< QAbstractTransition * > transitions() const
Definition: qstate.cpp:227
QState * rootState() const
static QStatePrivate * get(QState *q)
Definition: qstate_p.h:89
bool isPreempted(const QAbstractState *s, const QSet< QAbstractTransition *> &transitions) const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const_iterator constBegin() const
Definition: qset.h:168
static QList< QState * > properAncestors(const QAbstractState *s, const QState *upperBound)
static QState * toStandardState(QAbstractState *state)
bool isAtomic(const QAbstractState *s) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setError()

void QStateMachinePrivate::setError ( QStateMachine::Error  error,
QAbstractState currentContext 
)

Definition at line 1033 of file qstatemachine.cpp.

Referenced by addStatesToEnter(), and exitStates().

1034 {
1035  Q_Q(QStateMachine);
1036 
1037  error = errorCode;
1038  switch (errorCode) {
1040  Q_ASSERT(currentContext != 0);
1041 
1042  errorString = QStateMachine::tr("Missing initial state in compound state '%1'")
1043  .arg(currentContext->objectName());
1044 
1045  break;
1047  Q_ASSERT(currentContext != 0);
1048 
1049  errorString = QStateMachine::tr("Missing default state in history state '%1'")
1050  .arg(currentContext->objectName());
1051  break;
1052 
1054  Q_ASSERT(currentContext != 0);
1055 
1056  errorString = QStateMachine::tr("No common ancestor for targets and source of transition from state '%1'")
1057  .arg(currentContext->objectName());
1058  break;
1059  default:
1060  errorString = QStateMachine::tr("Unknown error");
1061  };
1062 
1065 
1066  QAbstractState *currentErrorState = findErrorState(currentContext);
1067 
1068  // Avoid infinite loop if the error state itself has an error
1069  if (currentContext == currentErrorState)
1070  currentErrorState = 0;
1071 
1072  Q_ASSERT(currentErrorState != rootState());
1073 
1074  if (currentErrorState != 0) {
1075  QState *lca = findLCA(QList<QAbstractState*>() << currentErrorState << currentContext);
1077  } else {
1078  qWarning("Unrecoverable error detected in running state machine: %s",
1080  q->stop();
1081  }
1082 }
QAbstractState * findErrorState(QAbstractState *context)
QStateMachine::Error error
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addStatesToEnter(QAbstractState *s, QState *root, QSet< QAbstractState *> &statesToEnter, QSet< QAbstractState *> &statesForDefaultEntry)
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
#define Q_Q(Class)
Definition: qglobal.h:2483
QSet< QAbstractState * > pendingErrorStates
The QAbstractState class is the base class of states of a QStateMachine.
Q_CORE_EXPORT void qWarning(const char *,...)
void clear()
Definition: qset.h:87
QState * rootState() const
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QState * findLCA(const QList< QAbstractState *> &states) const
QString objectName() const
#define qPrintable(string)
Definition: qglobal.h:1750
QSet< QAbstractState * > pendingErrorStatesForDefaultEntry
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ startState()

QState * QStateMachinePrivate::startState ( )

Definition at line 1178 of file qstatemachine.cpp.

Referenced by _q_start(), and goToState().

1179 {
1180  Q_Q(QStateMachine);
1181  if (_startState == 0)
1182  _startState = new StartState(q);
1183  return _startState;
1184 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define Q_Q(Class)
Definition: qglobal.h:2483

◆ stateEntryLessThan()

bool QStateMachinePrivate::stateEntryLessThan ( QAbstractState s1,
QAbstractState s2 
)
static

Definition at line 263 of file qstatemachine.cpp.

Referenced by enterStates().

264 {
265  if (s1->parent() == s2->parent()) {
266  return s1->children().indexOf(s1)
267  < s2->children().indexOf(s2);
268  } else if (isDescendantOf(s1, s2)) {
269  return false;
270  } else if (isDescendantOf(s2, s1)) {
271  return true;
272  } else {
273  Q_ASSERT(s1->machine() != 0);
275  QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2);
276  Q_ASSERT(lca != 0);
277  return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
278  }
279 }
QStateMachine * machine() const
Returns the state machine that this state is part of, or 0 if the state is not part of a state machin...
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static QStateMachinePrivate * get(QStateMachine *q)
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
static int indexOfDescendant(QState *s, QAbstractState *desc)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ stateExitLessThan()

bool QStateMachinePrivate::stateExitLessThan ( QAbstractState s1,
QAbstractState s2 
)
static

Definition at line 281 of file qstatemachine.cpp.

Referenced by exitStates().

282 {
283  if (s1->parent() == s2->parent()) {
284  return s1->children().indexOf(s1)
285  < s2->children().indexOf(s2);
286  } else if (isDescendantOf(s1, s2)) {
287  return true;
288  } else if (isDescendantOf(s2, s1)) {
289  return false;
290  } else {
291  Q_ASSERT(s1->machine() != 0);
293  QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2);
294  Q_ASSERT(lca != 0);
295  return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
296  }
297 }
QStateMachine * machine() const
Returns the state machine that this state is part of, or 0 if the state is not part of a state machin...
static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static QStateMachinePrivate * get(QStateMachine *q)
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
static int indexOfDescendant(QState *s, QAbstractState *desc)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ toFinalState()

QFinalState * QStateMachinePrivate::toFinalState ( QAbstractState state)
static

Definition at line 927 of file qstatemachine.cpp.

928 {
930  return static_cast<QFinalState*>(state);
931  return 0;
932 }
The QFinalState class provides a final state.
Definition: qfinalstate.h:56
static QAbstractStatePrivate * get(QAbstractState *q)

◆ toHistoryState()

QHistoryState * QStateMachinePrivate::toHistoryState ( QAbstractState state)
static

Definition at line 934 of file qstatemachine.cpp.

Referenced by addStatesToEnter().

935 {
937  return static_cast<QHistoryState*>(state);
938  return 0;
939 }
static QAbstractStatePrivate * get(QAbstractState *q)
The QHistoryState class provides a means of returning to a previously active substate.
Definition: qhistorystate.h:56

◆ toStandardState() [1/2]

QState * QStateMachinePrivate::toStandardState ( QAbstractState state)
static

Definition at line 913 of file qstatemachine.cpp.

Referenced by _q_animationFinished(), addStatesToEnter(), applyProperties(), exitStates(), findErrorState(), goToState(), isAtomic(), isCompound(), isInFinalState(), isParallel(), registerTransitions(), and selectTransitions().

914 {
916  return static_cast<QState*>(state);
917  return 0;
918 }
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static QAbstractStatePrivate * get(QAbstractState *q)

◆ toStandardState() [2/2]

const QState * QStateMachinePrivate::toStandardState ( const QAbstractState state)
static

Definition at line 920 of file qstatemachine.cpp.

921 {
923  return static_cast<const QState*>(state);
924  return 0;
925 }
The QState class provides a general-purpose state for QStateMachine.
Definition: qstate.h:61
static QAbstractStatePrivate * get(QAbstractState *q)

◆ unregisterAllTransitions()

void QStateMachinePrivate::unregisterAllTransitions ( )

Definition at line 1583 of file qstatemachine.cpp.

Referenced by _q_process().

1584 {
1585  Q_Q(QStateMachine);
1586  {
1588  for (int i = 0; i < transitions.size(); ++i) {
1589  QSignalTransition *t = transitions.at(i);
1590  if (t->machine() == q)
1592  }
1593  }
1594  {
1596  for (int i = 0; i < transitions.size(); ++i) {
1597  QEventTransition *t = transitions.at(i);
1598  if (t->machine() == q)
1600  }
1601  }
1602 }
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
void unregisterSignalTransition(QSignalTransition *transition)
#define Q_Q(Class)
Definition: qglobal.h:2483
void unregisterEventTransition(QEventTransition *transition)
The QEventTransition class provides a QObject-specific transition for Qt events.
The QSignalTransition class provides a transition based on a Qt signal.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QAbstractTransition * > transitions() const
Definition: qstate.cpp:227
QState * rootState() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QStateMachine * machine() const
Returns the state machine that this transition is part of, or 0 if the transition is not part of a st...
QList< T > findChildren(const QString &aName=QString()) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
Definition: qobject.h:162
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ unregisterEventTransition()

void QStateMachinePrivate::unregisterEventTransition ( QEventTransition transition)

Definition at line 1629 of file qstatemachine.cpp.

Referenced by QEventTransitionPrivate::unregister(), unregisterAllTransitions(), and unregisterTransition().

1630 {
1631  Q_Q(QStateMachine);
1632  if (!QEventTransitionPrivate::get(transition)->registered)
1633  return;
1634  QObject *object = QEventTransitionPrivate::get(transition)->object;
1635  QHash<QEvent::Type, int> &events = qobjectEvents[object];
1636  Q_ASSERT(events.value(transition->eventType()) > 0);
1637  if (--events[transition->eventType()] == 0) {
1638  events.remove(transition->eventType());
1639  int sum = 0;
1641  for (it = events.constBegin(); it != events.constEnd(); ++it)
1642  sum += it.value();
1643  if (sum == 0) {
1644  qobjectEvents.remove(object);
1645  object->removeEventFilter(q);
1646  }
1647  }
1648  QEventTransitionPrivate::get(transition)->registered = false;
1649 }
static QEventTransitionPrivate * get(QEventTransition *q)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
The QStateMachine class provides a hierarchical finite state machine.
Definition: qstatemachine.h:63
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QEvent::Type eventType
the type of event that this event transition is associated with
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< QObject *, QHash< QEvent::Type, int > > qobjectEvents
#define Q_Q(Class)
Definition: qglobal.h:2483
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469

◆ unregisterRestorable()

void QStateMachinePrivate::unregisterRestorable ( QObject object,
const QByteArray propertyName 
)
Warning
This function is not part of the public interface. Unregisters the variable identified by id

Definition at line 1008 of file qstatemachine.cpp.

Referenced by _q_animationFinished().

1009 {
1010 // qDebug() << "unregisterRestorable(" << object << propertyName << ')';
1011  RestorableId id(object, propertyName);
1012  registeredRestorables.remove(id);
1013 }
QPair< QObject *, QByteArray > RestorableId
QHash< RestorableId, QVariant > registeredRestorables

◆ unregisterSignalTransition()

void QStateMachinePrivate::unregisterSignalTransition ( QSignalTransition transition)

Definition at line 1561 of file qstatemachine.cpp.

Referenced by QSignalTransitionPrivate::unregister(), unregisterAllTransitions(), and unregisterTransition().

1562 {
1564  if (signalIndex == -1)
1565  return; // not registered
1566  QSignalTransitionPrivate::get(transition)->signalIndex = -1;
1567  const QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
1568  QVector<int> &connectedSignalIndexes = connections[sender];
1569  Q_ASSERT(connectedSignalIndexes.size() > signalIndex);
1570  Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0);
1571  if (--connectedSignalIndexes[signalIndex] == 0) {
1573  QMetaObject::disconnect(sender, signalIndex, signalEventGenerator,
1575  int sum = 0;
1576  for (int i = 0; i < connectedSignalIndexes.size(); ++i)
1577  sum += connectedSignalIndexes.at(i);
1578  if (sum == 0)
1579  connections.remove(sender);
1580  }
1581 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
int methodOffset() const
Returns the method offset for this class; i.e.
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3276
QSignalEventGenerator * signalEventGenerator
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QHash< const QObject *, QVector< int > > connections
static QSignalTransitionPrivate * get(QSignalTransition *q)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719

◆ unregisterTransition()

void QStateMachinePrivate::unregisterTransition ( QAbstractTransition transition)

Definition at line 1495 of file qstatemachine.cpp.

Referenced by QState::removeTransition().

1496 {
1497  if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
1499  }
1500 #ifndef QT_NO_STATEMACHINE_EVENTFILTER
1501  else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
1503  }
1504 #endif
1505 }
void unregisterSignalTransition(QSignalTransition *transition)
void unregisterEventTransition(QEventTransition *transition)
The QEventTransition class provides a QObject-specific transition for Qt events.
The QSignalTransition class provides a transition based on a Qt signal.
#define st(var, type, card)

Properties

◆ _startState

QState* QStateMachinePrivate::_startState

Definition at line 193 of file qstatemachine_p.h.

Referenced by QStateMachinePrivate(), removeStartState(), and startState().

◆ animated

bool QStateMachinePrivate::animated

Definition at line 212 of file qstatemachine_p.h.

Referenced by applyProperties(), and QStateMachinePrivate().

◆ animationsForState

QHash<QAbstractState*, QList<QAbstractAnimation*> > QStateMachinePrivate::animationsForState

Definition at line 218 of file qstatemachine_p.h.

Referenced by _q_animationFinished(), and applyProperties().

◆ configuration

QSet<QAbstractState*> QStateMachinePrivate::configuration

◆ connections

QHash<const QObject*, QVector<int> > QStateMachinePrivate::connections

◆ defaultAnimations

QList<QAbstractAnimation *> QStateMachinePrivate::defaultAnimations

Definition at line 223 of file qstatemachine_p.h.

Referenced by applyProperties().

◆ defaultAnimationsForSource

QMultiHash<QAbstractState *, QAbstractAnimation *> QStateMachinePrivate::defaultAnimationsForSource

Definition at line 224 of file qstatemachine_p.h.

Referenced by applyProperties().

◆ defaultAnimationsForTarget

QMultiHash<QAbstractState *, QAbstractAnimation *> QStateMachinePrivate::defaultAnimationsForTarget

Definition at line 225 of file qstatemachine_p.h.

Referenced by applyProperties().

◆ delayedEvents

QHash<int, QEvent*> QStateMachinePrivate::delayedEvents

Definition at line 235 of file qstatemachine_p.h.

Referenced by cancelAllDelayedEvents().

◆ delayedEventsMutex

QMutex QStateMachinePrivate::delayedEventsMutex

Definition at line 236 of file qstatemachine_p.h.

Referenced by cancelAllDelayedEvents().

◆ error

QStateMachine::Error QStateMachinePrivate::error

Definition at line 204 of file qstatemachine_p.h.

Referenced by addStatesToEnter(), QStateMachinePrivate(), and setError().

◆ errorString

QString QStateMachinePrivate::errorString

Definition at line 207 of file qstatemachine_p.h.

Referenced by setError().

◆ externalEventMutex

QMutex QStateMachinePrivate::externalEventMutex

◆ externalEventQueue

QList<QEvent*> QStateMachinePrivate::externalEventQueue

◆ globalRestorePolicy

QStateMachine::RestorePolicy QStateMachinePrivate::globalRestorePolicy

Definition at line 205 of file qstatemachine_p.h.

Referenced by applyProperties(), and QStateMachinePrivate().

◆ handler

const QStateMachinePrivate::Handler * QStateMachinePrivate::handler = &qt_kernel_statemachine_handler
static

◆ internalEventMutex

QMutex QStateMachinePrivate::internalEventMutex

◆ internalEventQueue

QList<QEvent*> QStateMachinePrivate::internalEventQueue

◆ pendingErrorStates

QSet<QAbstractState *> QStateMachinePrivate::pendingErrorStates

Definition at line 208 of file qstatemachine_p.h.

Referenced by enterStates(), exitStates(), and setError().

◆ pendingErrorStatesForDefaultEntry

QSet<QAbstractState *> QStateMachinePrivate::pendingErrorStatesForDefaultEntry

Definition at line 209 of file qstatemachine_p.h.

Referenced by enterStates(), and setError().

◆ processing

bool QStateMachinePrivate::processing

Definition at line 194 of file qstatemachine_p.h.

Referenced by _q_process(), enterStates(), processEvents(), and QStateMachinePrivate().

◆ processingScheduled

bool QStateMachinePrivate::processingScheduled

Definition at line 195 of file qstatemachine_p.h.

Referenced by _q_process(), _q_start(), processEvents(), and QStateMachinePrivate().

◆ propertyForAnimation

QHash<QAbstractAnimation*, QPropertyAssignment> QStateMachinePrivate::propertyForAnimation

Definition at line 219 of file qstatemachine_p.h.

Referenced by _q_animationFinished(), and applyProperties().

◆ qobjectEvents

QHash<QObject*, QHash<QEvent::Type, int> > QStateMachinePrivate::qobjectEvents

◆ registeredRestorables

QHash<RestorableId, QVariant> QStateMachinePrivate::registeredRestorables

◆ resetAnimationEndValues

QSet<QAbstractAnimation*> QStateMachinePrivate::resetAnimationEndValues

Definition at line 221 of file qstatemachine_p.h.

Referenced by _q_animationFinished(), and applyProperties().

◆ signalEventGenerator

QSignalEventGenerator* QStateMachinePrivate::signalEventGenerator

◆ state

State QStateMachinePrivate::state

◆ stateForAnimation

QHash<QAbstractAnimation*, QAbstractState*> QStateMachinePrivate::stateForAnimation

Definition at line 220 of file qstatemachine_p.h.

Referenced by _q_animationFinished(), and applyProperties().

◆ stop

bool QStateMachinePrivate::stop

Definition at line 196 of file qstatemachine_p.h.

Referenced by _q_process(), and QStateMachinePrivate().

◆ stopProcessingReason

StopProcessingReason QStateMachinePrivate::stopProcessingReason

Definition at line 197 of file qstatemachine_p.h.

Referenced by _q_process(), enterStates(), and QStateMachinePrivate().


The documentation for this class was generated from the following files: