ctkWorkflowStep.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkWorkflowStep_h
  15. #define __ctkWorkflowStep_h
  16. // Qt includes
  17. class QObject;
  18. class QState;
  19. // CTK includes
  20. #include "ctkPimpl.h"
  21. #include "ctkWorkflow_p.h"
  22. #include "ctkWorkflowTransitions.h"
  23. #include "ctkCoreExport.h"
  24. class ctkWorkflow;
  25. class ctkWorkflowStepPrivate;
  26. /// \brief ctkWorkflowStep is the basis for a workflow step.
  27. ///
  28. /// A workflow step is a placeholder for various states and transitions that are used in a
  29. /// typical workflow. Such steps can be added to instances of the ctkWorkflow class.
  30. class CTK_CORE_EXPORT ctkWorkflowStep
  31. {
  32. public:
  33. explicit ctkWorkflowStep();
  34. explicit ctkWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId);
  35. virtual ~ctkWorkflowStep();
  36. /// Get the \a workflow associated with this step
  37. ctkWorkflow* workflow()const;
  38. /// Get id
  39. QString id()const;
  40. /// Set/get \a name
  41. QString name()const;
  42. void setName(const QString& newName);
  43. /// Set/get \a description
  44. QString description()const;
  45. void setDescription(const QString& newDescription);
  46. /// Get \a statusText
  47. QString statusText()const;
  48. /// Set/get whether a validationCommand has been provided in a separate QObject
  49. /// \note see method 2 described for validation()
  50. /// \sa validation()
  51. bool hasValidateCommand()const;
  52. void setHasValidateCommand(bool newHasValidateCommand);
  53. /// Set/get whether an onEntryCommand has been provided in a separate QObject
  54. /// \note See method2 in onEntry()
  55. /// \sa onEntry()
  56. bool hasOnEntryCommand()const;
  57. void setHasOnEntryCommand(bool newHasOnEntryCommand);
  58. ///
  59. /// Set/get whether an onExitCommand has been provided in a separate QObject
  60. /// \note See method2 in onExit()
  61. /// \sa onExit()
  62. bool hasOnExitCommand()const;
  63. void setHasOnExitCommand(bool newHasOnExitCommand);
  64. /// Get QObject associated with this step, to connect signals/slots
  65. QObject* ctkWorkflowStepQObject();
  66. protected:
  67. explicit ctkWorkflowStep(ctkWorkflowStepPrivate * pimpl);
  68. explicit ctkWorkflowStep(ctkWorkflowStepPrivate * pimpl,
  69. ctkWorkflow* newWorkflow, const QString& newId);
  70. /// Set step Id
  71. void setId(const QString& newStepId);
  72. /// Set workflow
  73. void setWorkflow(ctkWorkflow* newWorkflow);
  74. void setStatusText(const QString& newText);
  75. /// \brief Get the step's processing state.
  76. ///
  77. /// This state is used to perform the processing associated with this step.
  78. QState* processingState()const;
  79. /// \brief Get the step's validation state.
  80. ///
  81. /// This state is used to validate the processing associated with this step.
  82. QState* validationState()const;
  83. /// \brief Get the step's validation transition.
  84. ///
  85. /// The validation transition is used to bring the state machine
  86. /// from the step's processingState to its validationState.
  87. /// More specifically:
  88. /// <ul>
  89. /// <li>its origin state is the processingState state</li>
  90. /// <li>its destination state is the validationState state</li>
  91. /// </ul>
  92. ///
  93. /// The transition is of type ctkWorkflowTransition with the value
  94. /// ctkWorkflowTransitionType::ValidationTransition.
  95. ctkWorkflowIntrastepTransition* validationTransition()const;
  96. /// \brief Get the step's validation failed transition.
  97. ///
  98. /// The validationFailed transition is used to bring the state
  99. /// machine from the step's validationState state back to its
  100. /// processingState, when validation of the processing step fails
  101. /// (i.e. validate(const QString&) returns false).
  102. ///
  103. /// More specifically:
  104. /// <ul>
  105. /// <li>its origin state is the validatationState state</li>
  106. /// <li>its destination state is the processingState state</li>
  107. /// </ul>
  108. ///
  109. /// The transition is of type ctkWorkflowTransition with the value
  110. /// ctkWorkflowTransitionType::ValidationFailedTransition.
  111. ctkWorkflowIntrastepTransition* validationFailedTransition()const;
  112. /// \brief Reimplement this function for step-specific processing when entering a step.
  113. ///
  114. /// To define a custom step, developers can either reimplement the onEntry() method in a subclass
  115. /// of ctkWorkflowStep, or create a ctkWorkflowStep instance and use signals and slots, as
  116. /// similarly as described for validate().
  117. ///
  118. /// Each step should be self-contained, \a comingFrom and \a transitionType may
  119. /// be used only to decide on how processing should be done for the current step.
  120. ///
  121. /// \param comingFrom gives the step that the state machine was in before
  122. /// transitioning to this step.
  123. ///
  124. /// \param transitionType gives the type of the transition used to get to this step.
  125. virtual void onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  126. /// \brief Reimplement this function for step-specific processing when exiting a step.
  127. ///
  128. /// To define a custom step, developers can either reimplement the onExit() method
  129. /// in a subclass of ctkWorkflowStep, or create a ctkWorkflowStep instance and use signals and
  130. /// slots, similarly as described for validate().
  131. ///
  132. /// Each step should be self-contained, \a goingTo and \a transitionType may be used only to
  133. /// decide on how processing should be done for the current step.
  134. ///
  135. /// \param goingTo gives the step that the state machine will go to after
  136. /// transitioning from this step.
  137. ///
  138. /// \param transitionType gives the type of the transition used to get to this step.
  139. virtual void onExit(const ctkWorkflowStep* goingTo,
  140. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  141. /// \brief Validates the computation performed in this step's processing state.
  142. ///
  143. /// When creating a custom step, developers can create a validate(const QString&) method is one of two ways:
  144. /// 1) Reimplement the validate(const QString&) method in a subclass of
  145. /// ctkWorkflowStep, following these instructions:
  146. /// <ul>
  147. /// <li>invoke the superclass method ctkWorkflowStep::validateComplete(bool, const QString&)
  148. /// (true on successful validation, false on failure; the QString is the desired branchId to use
  149. /// with branching workflows)</li>
  150. /// </ul>
  151. //
  152. /// OR:
  153. ///
  154. /// 2) Create an instance of a ctkWorkflowStep then:
  155. /// <ul>
  156. /// <li>Call setHasValidateCommand(1) on the step
  157. /// <li>Create a slot foo() associated with any QObject*, following these instructions:</li>
  158. /// <ul>
  159. /// <li>Set the following connection:</li>
  160. /// <ul>
  161. /// <li>QObject::connect(step, SIGNAL(invokeValidateCommand(const QString&)), object,
  162. /// SLOT(foo(const QString&)))</li>
  163. /// </ul>
  164. /// </ul>
  165. /// </ul>
  166. virtual void validate(const QString& desiredBranchId = QString());
  167. /// \brief Signal (emitted by the private implementation) indicating that validation of this
  168. /// step's processing should be performed.
  169. ///
  170. /// \sa validation()
  171. void invokeValidateCommand(const QString& desiredBranchId = QString())const;
  172. /// \brief Signal (emitted by the private implementation) indicating that validation of this
  173. /// step's processing has completed.
  174. ///
  175. /// \sa validation()
  176. void validationComplete(bool validationSuceeded, const QString& branchId = QString())const;
  177. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onEntry'
  178. /// processing should be performed.
  179. ///
  180. /// \sa onEntry()
  181. void invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const;
  182. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onEntry'
  183. /// processing has completed.
  184. ///
  185. /// \sa onEntry()
  186. void onEntryComplete()const;
  187. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onExit'
  188. /// processing should be performed.
  189. ///
  190. /// \sa onExit()
  191. void invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const;
  192. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onExit'
  193. /// processing has completed.
  194. ///
  195. /// \sa onExit()
  196. void onExitComplete()const;
  197. protected:
  198. QScopedPointer<ctkWorkflowStepPrivate> d_ptr;
  199. private:
  200. Q_DECLARE_PRIVATE(ctkWorkflowStep);
  201. Q_DISABLE_COPY(ctkWorkflowStep);
  202. friend class ctkWorkflow; // For access to processingState, validationState, setWorkflow, validate
  203. friend class ctkWorkflowPrivate; // For access to invokeOn{Entry,Exit}Command, on{Entry,Exit}
  204. };
  205. #endif