瀏覽代碼

ctkWorkflow - In not set, InitialStep default to the first added step

Jean-Christophe Fillion-Robin 14 年之前
父節點
當前提交
00bdccbab3
共有 2 個文件被更改,包括 11 次插入6 次删除
  1. 10 0
      Libs/Core/ctkWorkflow.cpp
  2. 1 6
      Libs/Core/ctkWorkflow.h

+ 10 - 0
Libs/Core/ctkWorkflow.cpp

@@ -596,6 +596,12 @@ bool ctkWorkflow::addTransition(ctkWorkflowStep* origin, ctkWorkflowStep* destin
       }
     }
 
+  // Set initialStep if needed
+  if (origin && d->StepToForwardAndBackwardStepMap.count() == 2 && !this->initialStep())
+    {
+    this->setInitialStep(origin);
+    }
+
   return true;
 }
 
@@ -708,8 +714,12 @@ bool ctkWorkflow::hasStep(const QString& id)const
 }
 
 // --------------------------------------------------------------------------
+// Convenience method to set the QStateMachine's initialState to a
+// specific step's processing state.
 CTK_GET_CPP(ctkWorkflow, ctkWorkflowStep*, initialStep, InitialStep);
 CTK_SET_CPP(ctkWorkflow, ctkWorkflowStep*, setInitialStep, InitialStep);
+
+// --------------------------------------------------------------------------
 CTK_GET_CPP(ctkWorkflow, ctkWorkflowStep*, currentStep, CurrentStep);
 
 // --------------------------------------------------------------------------

+ 1 - 6
Libs/Core/ctkWorkflow.h

@@ -104,12 +104,7 @@ public:
                                  = ctkWorkflow::Bidirectional);
 
   /// \brief Set/get the initial step.
-  ///
-  /// Convenience method to set the QStateMachine's initialState to a specific step's
-  /// processing state.
-  ///
-  /// \note The initialStep() function *must* be called to set the state machine's initial state
-  /// correctly
+  /// \note In not specified, the first step added will be considered as the initialStep
   Q_INVOKABLE ctkWorkflowStep* initialStep()const;
   Q_INVOKABLE virtual void setInitialStep(ctkWorkflowStep* step);