ctkExampleWorkflowStepUsingSignalsAndSlots.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.apache.org/licenses/LICENSE-2.0.txt
  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 __ctkExampleWorkflowStepUsingSignalsAndSlots_h
  15. #define __ctkExampleWorkflowStepUsingSignalsAndSlots_h
  16. // CTK includes
  17. #include "ctkPimpl.h"
  18. class ctkWorkflowStep;
  19. #include "ctkWorkflowTransitions.h"
  20. class ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate;
  21. ///
  22. /// ctkExampleWorkflowStepUsingSignalsAndSlots represents an example
  23. /// custom step created by deriving QObject (not ctkWorkflowStep) and
  24. /// implementing functions for validate(const QString&), onEntry() and
  25. /// onExit() that work using signals and slots.
  26. ///
  27. /// Need two connections to use this class's validate(const QString&) function, and
  28. /// must also set the step's hasValidateCommand flag:
  29. /// QObject::connect(step, SIGNAL(invokeValidateCommand(const QString&)), qObject,
  30. /// SLOT(validate(const QString&)))
  31. /// QObject::connect(qObject, SIGNAL(validationComplete(int)),
  32. /// workflow, SLOT(evaluateValidationResults(int)));
  33. /// step->setHasValidateCommand(1);
  34. ///
  35. /// Need two connections to use this class's onEntry()
  36. /// function, and must also set the step's hasOnEntryCommand
  37. /// flag:
  38. /// QObject::connect(step, SIGNAL(invokeOnEntryCommand(const
  39. /// ctkWorkflowStep*, const
  40. /// ctkWorkflowTransition::WorkflowTransitionType)), qObject,
  41. /// SLOT(onEntry(const ctkWorkflowStep*, const
  42. /// ctkWorkflowTransition::WorkflowTransitionType)));
  43. /// QObject::connect(qObject, SIGNAL(onEntryComplete()), step,
  44. /// SLOT(evaluateOnEntryResults()));
  45. /// step->setHasOnEntryCommand(1);
  46. ///
  47. /// Need two connectins to use this class's onExit() function,
  48. /// and must also set the step's hasOnExitCommand() flag:
  49. /// QObject::connect(step, SIGNAL(invokeOnExitCommand(const
  50. /// ctkWorkflowStep*, const
  51. /// ctkWorkflowTransition::WorkflowTransitionType)), qObject,
  52. /// SLOT(onExit(const ctkWorkflowStep*, const
  53. /// ctkWorkflowTransition::WorkflowTransitionType)));
  54. /// QObject::connect(qObject, SIGNAL(onExitComplete()), step,
  55. /// SLOT(evaluateOnExitResults()));
  56. /// step->setHasOnExitCommand(1);
  57. class ctkExampleWorkflowStepUsingSignalsAndSlots : public QObject
  58. {
  59. Q_OBJECT
  60. public:
  61. typedef QObject Superclass;
  62. explicit ctkExampleWorkflowStepUsingSignalsAndSlots(ctkWorkflowStep * newStep,
  63. QObject* newParent = 0);
  64. virtual ~ctkExampleWorkflowStepUsingSignalsAndSlots();
  65. /// Get the values for the counters of the number of times we have
  66. /// run the onEntry() and onExit() functions
  67. virtual int numberOfTimesRanOnEntry()const;
  68. virtual int numberOfTimesRanOnExit()const;
  69. protected Q_SLOTS:
  70. /// Always returns 1 (validation successful)
  71. virtual void validate(const QString& desiredBranchId = QString())const;
  72. /// Always returns 0 (validation failed)
  73. virtual void validateFails()const;
  74. /// Increments the counter numberOfTimesRanOnEntry
  75. virtual void onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  76. ///
  77. /// Increments the counter numberOfTimesRanOnExit
  78. virtual void onExit(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  79. Q_SIGNALS:
  80. ///
  81. /// Signals indicating to the workflow that these processes have
  82. /// completed
  83. void validationComplete(bool validationSucceeded, const QString& branchId = "")const;
  84. void onEntryComplete()const;
  85. void onExitComplete()const;
  86. protected:
  87. QScopedPointer<ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate> d_ptr;
  88. private:
  89. Q_DECLARE_PRIVATE(ctkExampleWorkflowStepUsingSignalsAndSlots);
  90. Q_DISABLE_COPY(ctkExampleWorkflowStepUsingSignalsAndSlots);
  91. };
  92. #endif