From ae6ab698ea739ac82cc6245742b58c7265ee82f8 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>
Date: Tue, 21 Apr 2009 15:55:35 +0200
Subject: 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.
---
 src/corelib/statemachine/qstate.cpp | 9 +++++----
 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);
-- 
cgit v0.12