statemachine: Small refactoring of transition registration
Split the guts of registerTransitions() into a registerTransition() function. This allows a particular transition to be registered, instead of walking the source state's whole list of transitions every time. Move the logic for determining whether a transition should be registered to the state machine, since that's also where the actual registration takes place. Change-Id: I0496dee9454cd77b62cf2768942a82a96b320744 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
parent
08345c5dac
commit
058246c537
@ -125,9 +125,8 @@ void QEventTransitionPrivate::unregister()
|
|||||||
void QEventTransitionPrivate::maybeRegister()
|
void QEventTransitionPrivate::maybeRegister()
|
||||||
{
|
{
|
||||||
Q_Q(QEventTransition);
|
Q_Q(QEventTransition);
|
||||||
if (!machine() || !machine()->configuration().contains(sourceState()))
|
if (QStateMachine *mach = machine())
|
||||||
return;
|
QStateMachinePrivate::get(mach)->maybeRegisterEventTransition(q);
|
||||||
QStateMachinePrivate::get(machine())->registerEventTransition(q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -131,9 +131,8 @@ void QSignalTransitionPrivate::unregister()
|
|||||||
void QSignalTransitionPrivate::maybeRegister()
|
void QSignalTransitionPrivate::maybeRegister()
|
||||||
{
|
{
|
||||||
Q_Q(QSignalTransition);
|
Q_Q(QSignalTransition);
|
||||||
if (!machine() || !machine()->configuration().contains(sourceState()))
|
if (QStateMachine *mach = machine())
|
||||||
return;
|
QStateMachinePrivate::get(mach)->maybeRegisterSignalTransition(q);
|
||||||
QStateMachinePrivate::get(machine())->registerSignalTransition(q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -313,8 +313,8 @@ void QState::addTransition(QAbstractTransition *transition)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (machine() != 0 && machine()->configuration().contains(this))
|
if (QStateMachine *mach = machine())
|
||||||
QStateMachinePrivate::get(machine())->registerTransitions(this);
|
QStateMachinePrivate::get(mach)->maybeRegisterTransition(transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1660,17 +1660,34 @@ void QStateMachinePrivate::registerTransitions(QAbstractState *state)
|
|||||||
QList<QAbstractTransition*> transitions = QStatePrivate::get(group)->transitions();
|
QList<QAbstractTransition*> transitions = QStatePrivate::get(group)->transitions();
|
||||||
for (int i = 0; i < transitions.size(); ++i) {
|
for (int i = 0; i < transitions.size(); ++i) {
|
||||||
QAbstractTransition *t = transitions.at(i);
|
QAbstractTransition *t = transitions.at(i);
|
||||||
if (QSignalTransition *st = qobject_cast<QSignalTransition*>(t)) {
|
registerTransition(t);
|
||||||
registerSignalTransition(st);
|
|
||||||
}
|
|
||||||
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
|
||||||
else if (QEventTransition *oet = qobject_cast<QEventTransition*>(t)) {
|
|
||||||
registerEventTransition(oet);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QStateMachinePrivate::maybeRegisterTransition(QAbstractTransition *transition)
|
||||||
|
{
|
||||||
|
if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
|
||||||
|
maybeRegisterSignalTransition(st);
|
||||||
|
}
|
||||||
|
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
||||||
|
else if (QEventTransition *et = qobject_cast<QEventTransition*>(transition)) {
|
||||||
|
maybeRegisterEventTransition(et);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void QStateMachinePrivate::registerTransition(QAbstractTransition *transition)
|
||||||
|
{
|
||||||
|
if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
|
||||||
|
registerSignalTransition(st);
|
||||||
|
}
|
||||||
|
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
||||||
|
else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
|
||||||
|
registerEventTransition(oet);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition)
|
void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition)
|
||||||
{
|
{
|
||||||
if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
|
if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
|
||||||
@ -1683,6 +1700,13 @@ void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QStateMachinePrivate::maybeRegisterSignalTransition(QSignalTransition *transition)
|
||||||
|
{
|
||||||
|
Q_Q(QStateMachine);
|
||||||
|
if ((state == Running) && configuration.contains(transition->sourceState()))
|
||||||
|
registerSignalTransition(transition);
|
||||||
|
}
|
||||||
|
|
||||||
void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transition)
|
void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transition)
|
||||||
{
|
{
|
||||||
Q_Q(QStateMachine);
|
Q_Q(QStateMachine);
|
||||||
@ -1784,6 +1808,12 @@ void QStateMachinePrivate::unregisterAllTransitions()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
||||||
|
void QStateMachinePrivate::maybeRegisterEventTransition(QEventTransition *transition)
|
||||||
|
{
|
||||||
|
if ((state == Running) && configuration.contains(transition->sourceState()))
|
||||||
|
registerEventTransition(transition);
|
||||||
|
}
|
||||||
|
|
||||||
void QStateMachinePrivate::registerEventTransition(QEventTransition *transition)
|
void QStateMachinePrivate::registerEventTransition(QEventTransition *transition)
|
||||||
{
|
{
|
||||||
Q_Q(QStateMachine);
|
Q_Q(QStateMachine);
|
||||||
|
@ -170,9 +170,13 @@ public:
|
|||||||
void goToState(QAbstractState *targetState);
|
void goToState(QAbstractState *targetState);
|
||||||
|
|
||||||
void registerTransitions(QAbstractState *state);
|
void registerTransitions(QAbstractState *state);
|
||||||
|
void maybeRegisterTransition(QAbstractTransition *transition);
|
||||||
|
void registerTransition(QAbstractTransition *transition);
|
||||||
|
void maybeRegisterSignalTransition(QSignalTransition *transition);
|
||||||
void registerSignalTransition(QSignalTransition *transition);
|
void registerSignalTransition(QSignalTransition *transition);
|
||||||
void unregisterSignalTransition(QSignalTransition *transition);
|
void unregisterSignalTransition(QSignalTransition *transition);
|
||||||
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
|
||||||
|
void maybeRegisterEventTransition(QEventTransition *transition);
|
||||||
void registerEventTransition(QEventTransition *transition);
|
void registerEventTransition(QEventTransition *transition);
|
||||||
void unregisterEventTransition(QEventTransition *transition);
|
void unregisterEventTransition(QEventTransition *transition);
|
||||||
void handleFilteredEvent(QObject *watched, QEvent *event);
|
void handleFilteredEvent(QObject *watched, QEvent *event);
|
||||||
|
Loading…
Reference in New Issue
Block a user