summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine/qabstracttransition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/statemachine/qabstracttransition.cpp')
-rw-r--r--src/corelib/statemachine/qabstracttransition.cpp88
1 files changed, 32 insertions, 56 deletions
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp
index 1897aa6..a930581 100644
--- a/src/corelib/statemachine/qabstracttransition.cpp
+++ b/src/corelib/statemachine/qabstracttransition.cpp
@@ -125,9 +125,9 @@ QStateMachine *QAbstractTransitionPrivate::machine() const
return 0;
}
-bool QAbstractTransitionPrivate::callEventTest(QEvent *e) const
+bool QAbstractTransitionPrivate::callEventTest(QEvent *e)
{
- Q_Q(const QAbstractTransition);
+ Q_Q(QAbstractTransition);
return q->eventTest(e);
}
@@ -147,18 +147,8 @@ QState *QAbstractTransitionPrivate::sourceState() const
Constructs a new QAbstractTransition object with the given \a sourceState.
*/
QAbstractTransition::QAbstractTransition(QState *sourceState)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- *new QAbstractTransitionPrivate,
-#endif
- sourceState)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(new QAbstractTransitionPrivate)
-#endif
+ : QObject(*new QAbstractTransitionPrivate, sourceState)
{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
}
/*!
@@ -167,20 +157,9 @@ QAbstractTransition::QAbstractTransition(QState *sourceState)
*/
QAbstractTransition::QAbstractTransition(const QList<QAbstractState*> &targets,
QState *sourceState)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- *new QAbstractTransitionPrivate,
-#endif
- sourceState)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(new QAbstractTransitionPrivate)
-#endif
+ : QObject(*new QAbstractTransitionPrivate, sourceState)
{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
- Q_D(QAbstractTransition);
- d->targetStates = targets;
+ setTargetStates(targets);
}
/*!
@@ -188,18 +167,8 @@ QAbstractTransition::QAbstractTransition(const QList<QAbstractState*> &targets,
*/
QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
QState *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- dd,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(&dd)
-#endif
+ : QObject(dd, parent)
{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
}
/*!
@@ -208,20 +177,9 @@ QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
const QList<QAbstractState*> &targets,
QState *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- dd,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(&dd)
-#endif
+ : QObject(dd, parent)
{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
- Q_D(QAbstractTransition);
- d->targetStates = targets;
+ setTargetStates(targets);
}
/*!
@@ -229,9 +187,6 @@ QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
*/
QAbstractTransition::~QAbstractTransition()
{
-#ifdef QT_STATEMACHINE_SOLUTION
- delete d_ptr;
-#endif
}
/*!
@@ -265,7 +220,7 @@ void QAbstractTransition::setTargetState(QAbstractState* target)
if (!target)
d->targetStates.clear();
else
- d->targetStates = QList<QAbstractState*>() << target;
+ setTargetStates(QList<QAbstractState*>() << target);
}
/*!
@@ -275,7 +230,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;
}
/*!
@@ -284,7 +245,22 @@ QList<QAbstractState*> QAbstractTransition::targetStates() const
void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets)
{
Q_D(QAbstractTransition);
- d->targetStates = 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.clear();
+ for (int i = 0; i < targets.size(); ++i)
+ d->targetStates.append(targets.at(i));
}
/*!