Explorar el Código

Added new property goBackToOriginStepUponSuccess for a ctkWorkflow.

If set to true, goToStep(targetId) goes back to the origin step after the attempt of going to the target step succeeded.
If set to false, goToStep(targetId) stays at the target step when the attempt succeeded.

By default, the property is true.
Daniel Haehn hace 14 años
padre
commit
162f4e81a8

+ 21 - 0
Libs/Core/Testing/Cpp/ctkWorkflowTest1.cpp

@@ -493,6 +493,27 @@ int ctkWorkflowTest1(int argc, char * argv [] )
     return EXIT_FAILURE;
     }  
 
+  // try to go automatically to step 4 and stay there by setting the property goBackToOriginStepUponSuccess to false
+  workflow->setGoBackToOriginStepUponSuccess(false);
+  workflow->goToStep("Step 4");
+  if (!transitionTest(workflow, defaultTime, app, step4, step1, 10, 10, step2, 8, 8, step3, 9, 9, step4, 5, 4))
+    {
+    std::cerr << "error staying at step 4 if property goBackToOriginStepUponSuccess is false";
+    return EXIT_FAILURE;
+    }
+
+  // after, going backwards to step 3,
+  // try to go automatically to step 4 with the property goBackToOriginStepUponSuccess set to true
+  workflow->setGoBackToOriginStepUponSuccess(true);
+  workflow->goBackward(); // now at step3
+  QTimer::singleShot(defaultTime, &app, SLOT(quit()));
+  app.exec();
+  workflow->goToStep("Step 4");
+  if (!transitionTest(workflow, defaultTime, app, step3, step1, 10, 10, step2, 8, 8, step3, 11, 10, step4, 6, 6))
+    {
+    std::cerr << "error while coming back to step 3 if property goBackToOriginStepUponSuccess is true";
+    return EXIT_FAILURE;
+    }
 
   // handles deletions of the workflow, steps, states and transitions
   delete workflow;

+ 16 - 2
Libs/Core/ctkWorkflow.cpp

@@ -53,6 +53,9 @@ ctkWorkflowPrivate::ctkWorkflowPrivate(ctkWorkflow& object)
   this->StartingStep = 0;
   this->TransitionToPreviousStartingStep = 0;
 
+  // By default, go back to the origin step upon success of the goToStep(targetId) attempt.
+  this->GoBackToOriginStepUponSuccess = true;
+
   this->ARTIFICIAL_BRANCH_ID_PREFIX = "ctkWorkflowArtificialBranchId_";
 }
 
@@ -841,6 +844,10 @@ void ctkWorkflow::goBackward(const QString& desiredBranchId)
 }
 
 // --------------------------------------------------------------------------
+CTK_GET_CPP(ctkWorkflow, bool, goBackToOriginStepUponSuccess, GoBackToOriginStepUponSuccess);
+CTK_SET_CPP(ctkWorkflow, bool, setGoBackToOriginStepUponSuccess, GoBackToOriginStepUponSuccess);
+
+// --------------------------------------------------------------------------
 void ctkWorkflow::goToStep(const QString& targetId)
 {
   Q_D(ctkWorkflow);
@@ -1025,14 +1032,21 @@ void ctkWorkflow::goToStepSucceeded()
 
   // after success, go back to the step at which we begin looking for
   // the finish step (will exit the current step and enter the starting step)
+  // only if the property goBackToOriginStepUponSuccess is true.
 
-  d->createTransitionToPreviousStartingStep(d->StartingStep, d->CurrentStep);
+  if (this->goBackToOriginStepUponSuccess())
+    {
+    d->createTransitionToPreviousStartingStep(d->StartingStep, d->CurrentStep);
+    }
 
   d->GoToStep = 0;
   d->StartingStep->setStatusText("Attempt to go to the finish step succeeded");
   d->StartingStep = 0;
 
-  this->goFromGoToStepToStartingStep();
+  if (this->goBackToOriginStepUponSuccess())
+    {
+    this->goFromGoToStepToStartingStep();
+    }
 }
 
 // --------------------------------------------------------------------------

+ 10 - 0
Libs/Core/ctkWorkflow.h

@@ -41,6 +41,7 @@ class CTK_CORE_EXPORT ctkWorkflow : public QObject
   Q_OBJECT
   Q_ENUMS(TransitionDirectionality)
   Q_PROPERTY(bool isRunning READ isRunning DESIGNABLE false)
+  Q_PROPERTY(bool goBackToOriginStepUponSuccess READ goBackToOriginStepUponSuccess WRITE setGoBackToOriginStepUponSuccess)
 
 public:
 
@@ -156,6 +157,15 @@ public:
   /// Get the steps that are 'finish' steps (i.e. have no step following them)
   Q_INVOKABLE QList<ctkWorkflowStep*> finishSteps()const;
 
+  /// Configures the behavior of goToStep(targetId).
+  ///
+  /// If set to true, goToStep(targetId) goes back to the origin step after
+  /// the attempt of going to the target step succeeded.
+  /// If set to false, goToStep(targetId) stays at the target step when the attempt
+  /// succeeded.
+  bool goBackToOriginStepUponSuccess()const;
+  void setGoBackToOriginStepUponSuccess(bool flag);
+
 public slots:
 
   /// Use this to trigger evaluation of the processing state of the current step, and subsequent

+ 2 - 0
Libs/Core/ctkWorkflow_p.h

@@ -290,6 +290,8 @@ public:
   // Temporary transition after successfully going to finish step, to get us back to the starting step
   ctkWorkflowInterstepTransition* TransitionToPreviousStartingStep;
 
+  bool GoBackToOriginStepUponSuccess;
+
   QString ARTIFICIAL_BRANCH_ID_PREFIX;
 
 };