diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-08 14:37:21 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-08 14:37:21 (GMT) |
commit | 98f3ebcf1f6751cb76f9268d33faf0bc5ac70f6e (patch) | |
tree | a3923f5ea068066999008eaea8d15a316b99592e /src/corelib/statemachine | |
parent | 110473e9eece3231c3df4fc50c3a958c6c25f2de (diff) | |
download | Qt-98f3ebcf1f6751cb76f9268d33faf0bc5ac70f6e.zip Qt-98f3ebcf1f6751cb76f9268d33faf0bc5ac70f6e.tar.gz Qt-98f3ebcf1f6751cb76f9268d33faf0bc5ac70f6e.tar.bz2 |
gracefully handle deletion of transition's target state
Diffstat (limited to 'src/corelib/statemachine')
-rw-r--r-- | src/corelib/statemachine/qabstracttransition.cpp | 16 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstracttransition_p.h | 3 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.cpp | 2 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp index 696da9f..6ddb416 100644 --- a/src/corelib/statemachine/qabstracttransition.cpp +++ b/src/corelib/statemachine/qabstracttransition.cpp @@ -273,7 +273,13 @@ void QAbstractTransition::setTargetState(QAbstractState* target) QList<QAbstractState*> QAbstractTransition::targetStates() const { Q_D(const QAbstractTransition); - return d->targetStates; + QList<QAbstractState*> result; + for (int i = 0; i < d->targetStates.size(); ++i) { + QAbstractState *target = d->targetStates.at(i); + if (target) + result.append(target); + } + return result; } /*! @@ -285,13 +291,19 @@ void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets) for (int i=0; i<targets.size(); ++i) { QAbstractState *target = targets.at(i); + if (!target) { + qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null"); + return; + } if (target->machine() != 0 && target->machine()->rootState() == target) { qWarning("QAbstractTransition::setTargetStates: root state cannot be target of transition"); return; } } - d->targetStates = targets; + d->targetStates.clear(); + for (int i = 0; i < targets.size(); ++i) + d->targetStates.append(targets.at(i)); } /*! diff --git a/src/corelib/statemachine/qabstracttransition_p.h b/src/corelib/statemachine/qabstracttransition_p.h index b4e1c88..eb0ec21 100644 --- a/src/corelib/statemachine/qabstracttransition_p.h +++ b/src/corelib/statemachine/qabstracttransition_p.h @@ -58,6 +58,7 @@ #endif #include <QtCore/qlist.h> +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE @@ -83,7 +84,7 @@ public: QState *sourceState() const; QStateMachine *machine() const; - QList<QAbstractState*> targetStates; + QList<QPointer<QAbstractState> > targetStates; #ifndef QT_NO_ANIMATION QList<QAbstractAnimation*> animations; diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 63a0a69..5f61865 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -312,7 +312,7 @@ QAbstractTransition *QState::addTransition(QAbstractTransition *transition) return 0; } - const QList<QAbstractState*> &targets = QAbstractTransitionPrivate::get(transition)->targetStates; + const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates; for (int i = 0; i < targets.size(); ++i) { QAbstractState *t = targets.at(i); if (!t) { |