diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-04-21 13:55:35 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-04-21 13:55:35 (GMT) |
commit | ae6ab698ea739ac82cc6245742b58c7265ee82f8 (patch) | |
tree | 4597334d94b2150a12adb0fe835467425cd869da /src/corelib | |
parent | 381e67f03155167cd9c1c0c3c4c3905196f287df (diff) | |
download | Qt-ae6ab698ea739ac82cc6245742b58c7265ee82f8.zip Qt-ae6ab698ea739ac82cc6245742b58c7265ee82f8.tar.gz Qt-ae6ab698ea739ac82cc6245742b58c7265ee82f8.tar.bz2 |
Have QState::addTransition(QAbstractTransition*) return the transition object
when it is added. Reduces the number of temporary variables you have to declare
in your code since you can do things like:
state->addTransition(new Transition())->addAnimation(new Animation());
Could also be used for error checking.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/statemachine/qstate.cpp | 9 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.h | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index e3da1c5..abd7379 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -247,28 +247,29 @@ void QState::setErrorState(QAbstractState *state) Adds the given \a transition. The transition has this state as the source. This state takes ownership of the transition. */ -void QState::addTransition(QAbstractTransition *transition) +QAbstractTransition *QState::addTransition(QAbstractTransition *transition) { Q_D(QState); if (!transition) { qWarning("QState::addTransition: cannot add null transition"); - return; + return 0; } const QList<QAbstractState*> &targets = QAbstractTransitionPrivate::get(transition)->targetStates; for (int i = 0; i < targets.size(); ++i) { QAbstractState *t = targets.at(i); if (!t) { qWarning("QState::addTransition: cannot add transition to null state"); - return; + return 0; } if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) && QAbstractStatePrivate::get(t)->machine() && d->machine()) { qWarning("QState::addTransition: cannot add transition " "to a state in a different state machine"); - return; + return 0; } } transition->setParent(this); + return transition; } /*! diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 4c86e02..1ec0896 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -81,7 +81,7 @@ public: QAbstractState *errorState() const; void setErrorState(QAbstractState *state); - void addTransition(QAbstractTransition *transition); + QAbstractTransition *addTransition(QAbstractTransition *transition); QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target); QAbstractTransition *addTransition(QAbstractState *target); QStateFinishedTransition *addFinishedTransition(QAbstractState *target); |