瀏覽代碼

Add ctkWorkflowStep* ctkWorkflow::step(QString)

Convenient method to search and return a step. This can be useful when a
step needs knowledge of another step.
Julien Finet 12 年之前
父節點
當前提交
b47c9eff4c
共有 4 個文件被更改,包括 25 次插入0 次删除
  1. 8 0
      Libs/Core/ctkWorkflow.cpp
  2. 7 0
      Libs/Core/ctkWorkflow.h
  3. 8 0
      Libs/Widgets/ctkWorkflowWidget.cpp
  4. 2 0
      Libs/Widgets/ctkWorkflowWidget.h

+ 8 - 0
Libs/Core/ctkWorkflow.cpp

@@ -774,6 +774,14 @@ bool ctkWorkflow::hasStep(const QString& id)const
 }
 
 // --------------------------------------------------------------------------
+ctkWorkflowStep* ctkWorkflow::step(const QString& id)const
+{
+  Q_D(const ctkWorkflow);
+  return d->stepFromId(id);
+}
+
+
+// --------------------------------------------------------------------------
 // Convenience method to set the QStateMachine's initialState to a
 // specific step's processing state.
 CTK_GET_CPP(ctkWorkflow, ctkWorkflowStep*, initialStep, InitialStep);

+ 7 - 0
Libs/Core/ctkWorkflow.h

@@ -107,15 +107,22 @@ public:
 
   /// \brief Set/get the initial step.
   /// \note In not specified, the first step added will be considered as the initialStep
+  /// \sa currentStep(), step(), hasStep(), steps()
   Q_INVOKABLE ctkWorkflowStep* initialStep()const;
   Q_INVOKABLE virtual void setInitialStep(ctkWorkflowStep* step);
 
   /// Get the current step of the state machine
+  /// \sa initialStep(), step(), hasStep(), steps()
   Q_INVOKABLE ctkWorkflowStep* currentStep()const;
 
   /// Check to see if there is a step with a given id in the workflow.
+  /// \sa step(), currentStep(), steps()
   Q_INVOKABLE bool hasStep(const QString& id)const;
 
+  /// Return the step with matching \a id if any, 0 otherwise.
+  /// \sa hasStep(), currentStep(), steps()
+  Q_INVOKABLE ctkWorkflowStep* step(const QString& id)const;
+
   /// Returns whether or not we can go forward: i.e. there exists a step that directly follows the
   /// given step.
   ///

+ 8 - 0
Libs/Widgets/ctkWorkflowWidget.cpp

@@ -151,6 +151,14 @@ void ctkWorkflowWidget::setWorkflow(ctkWorkflow* newWorkflow)
 }
 
 // --------------------------------------------------------------------------
+ctkWorkflowWidgetStep* ctkWorkflowWidget::widgetStep(const QString& id)const
+{
+  Q_D(const ctkWorkflowWidget);
+  return dynamic_cast<ctkWorkflowWidgetStep*>(
+    !d->Workflow.isNull() ? d->Workflow.data()->step(id) : 0);
+}
+
+// --------------------------------------------------------------------------
 void ctkWorkflowWidget::onCurrentStepChanged(ctkWorkflowStep* currentStep)
 {
   if (currentStep)

+ 2 - 0
Libs/Widgets/ctkWorkflowWidget.h

@@ -55,6 +55,8 @@ public:
   Q_INVOKABLE virtual ctkWorkflow* workflow()const;
   Q_INVOKABLE virtual void setWorkflow(ctkWorkflow* newWorkflow);
 
+  Q_INVOKABLE ctkWorkflowWidgetStep* widgetStep(const QString& id)const;
+
   /// Get the widget constaining the title, subtitle, pre-text, post-text, error-text and client area
   /// layout.
   Q_INVOKABLE virtual ctkWorkflowGroupBox* workflowGroupBox()const;