From 569e4b636fc91a9d5c6f6e4d65967327786adb3c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 13:13:35 +0100 Subject: Remove return type of QState::addTransition(QAbstractTransition*) Returning the input argument in a function can lead to confusion and serves no purpose here. Instead, we'll mirror the API from QMenu::addAction() overloads, where the overload that takes a preconstructed object has a void return type. Reviewed-by: Kent Hansen --- src/corelib/statemachine/qstate.cpp | 15 +++++---- src/corelib/statemachine/qstate.h | 2 +- tests/auto/qstatemachine/tst_qstatemachine.cpp | 42 +++++++++++++++++--------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index bcd8364..ea20619 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -286,15 +286,14 @@ 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. If the transition is successfully - added, the function will return the \a transition pointer. Otherwise it will return null. + This state takes ownership of the transition. */ -QAbstractTransition *QState::addTransition(QAbstractTransition *transition) +void QState::addTransition(QAbstractTransition *transition) { Q_D(QState); if (!transition) { qWarning("QState::addTransition: cannot add null transition"); - return 0; + return ; } transition->setParent(this); @@ -303,18 +302,17 @@ QAbstractTransition *QState::addTransition(QAbstractTransition *transition) QAbstractState *t = targets.at(i).data(); if (!t) { qWarning("QState::addTransition: cannot add transition to null state"); - return 0; + return ; } 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 0; + return ; } } if (machine() != 0 && machine()->configuration().contains(this)) QStateMachinePrivate::get(machine())->registerTransitions(this); - return transition; } /*! @@ -379,7 +377,8 @@ QAbstractTransition *QState::addTransition(QAbstractState *target) return 0; } UnconditionalTransition *trans = new UnconditionalTransition(target); - return addTransition(trans); + addTransition(trans); + return trans; } /*! diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 7a47447..781382d 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -76,7 +76,7 @@ public: QAbstractState *errorState() const; void setErrorState(QAbstractState *state); - QAbstractTransition *addTransition(QAbstractTransition *transition); + void addTransition(QAbstractTransition *transition); QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target); QAbstractTransition *addTransition(QAbstractState *target); void removeTransition(QAbstractTransition *transition); diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 31ab3af..fb6567a 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -286,8 +286,8 @@ void tst_QStateMachine::transitionToRootState() machine.addState(initialState); machine.setInitialState(initialState); - QAbstractTransition *trans = initialState->addTransition(new EventTransition(QEvent::User, &machine)); - QVERIFY(trans != 0); + QAbstractTransition *trans = new EventTransition(QEvent::User, &machine); + initialState->addTransition(trans); QCOMPARE(trans->sourceState(), initialState); QCOMPARE(trans->targetState(), static_cast(&machine)); @@ -310,7 +310,7 @@ void tst_QStateMachine::transitionFromRootState() QState *root = &machine; QState *s1 = new QState(root); EventTransition *trans = new EventTransition(QEvent::User, s1); - QCOMPARE(root->addTransition(trans), static_cast(trans)); + root->addTransition(trans); QCOMPARE(trans->sourceState(), root); QCOMPARE(trans->targetState(), static_cast(s1)); } @@ -1155,7 +1155,7 @@ void tst_QStateMachine::stateEntryAndExit() QCOMPARE(t->targetState(), (QAbstractState*)s2); QCOMPARE(t->targetStates().size(), 1); QCOMPARE(t->targetStates().at(0), (QAbstractState*)s2); - QCOMPARE(s1->addTransition(t), (QAbstractTransition*)t); + s1->addTransition(t); QCOMPARE(t->sourceState(), (QState*)s1); QCOMPARE(t->machine(), &machine); @@ -1173,7 +1173,7 @@ void tst_QStateMachine::stateEntryAndExit() s2->removeTransition(trans); QCOMPARE(trans->sourceState(), (QState*)0); QCOMPARE(trans->targetState(), (QAbstractState*)s3); - QCOMPARE(s2->addTransition(trans), trans); + s2->addTransition(trans); QCOMPARE(trans->sourceState(), (QState*)s2); } @@ -3117,7 +3117,9 @@ void tst_QStateMachine::twoAnimatedTransitions() QState *s2 = new QState(&machine); s2->assignProperty(object, "foo", 5.0); QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3126,7 +3128,9 @@ void tst_QStateMachine::twoAnimatedTransitions() QState *s4 = new QState(&machine); s4->assignProperty(object, "foo", 2.0); QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4); - s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2); + trans = new EventTransition(QEvent::User, s4); + s3->addTransition(trans); + trans->addAnimation(fooAnimation2); QState *s5 = new QState(&machine); QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); @@ -3161,7 +3165,9 @@ void tst_QStateMachine::playAnimationTwice() QState *s2 = new QState(&machine); s2->assignProperty(object, "foo", 5.0); QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3169,7 +3175,9 @@ void tst_QStateMachine::playAnimationTwice() QState *s4 = new QState(&machine); s4->assignProperty(object, "foo", 2.0); - s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation); + trans = new EventTransition(QEvent::User, s4); + s3->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s5 = new QState(&machine); QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); @@ -3213,14 +3221,16 @@ void tst_QStateMachine::nestedTargetStateForAnimation() QState *s2Child2 = new QState(s2); s2Child2->assignProperty(object, "bar", 11.0); - QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2Child2); + s2Child->addTransition(at); QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2); animation->setDuration(2000); connect(animation, SIGNAL(finished()), &counter, SLOT(slot())); at->addAnimation(animation); - at = s1->addTransition(new EventTransition(QEvent::User, s2)); + at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); animation = new QPropertyAnimation(object, "foo", s2); connect(animation, SIGNAL(finished()), &counter, SLOT(slot())); @@ -3299,7 +3309,8 @@ void tst_QStateMachine::animatedGlobalRestoreProperty() QState *s4 = new QState(&machine); QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); - QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2); connect(pa, SIGNAL(finished()), &counter, SLOT(slot())); at->addAnimation(pa); @@ -3341,7 +3352,9 @@ void tst_QStateMachine::specificTargetValueOfAnimation() QPropertyAnimation *anim = new QPropertyAnimation(object, "foo"); anim->setEndValue(10.0); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(anim); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3495,7 +3508,8 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific() QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); - QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo"); connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot())); -- cgit v0.12