ctkExampleWorkflowWidgetStepUsingSignalsAndSlots.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 __ctkExampleWorkflowWidgetStepUsingSignalsAndSlots_h
  15. #define __ctkExampleWorkflowWidgetStepUsingSignalsAndSlots_h
  16. // CTK includes
  17. #include "ctkPimpl.h"
  18. #include "ctkWorkflowTransitions.h"
  19. class ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate;
  20. class ctkWorkflowWidget;
  21. class ctkWorkflowStep;
  22. class QLabel;
  23. class QLineEdit;
  24. class QWidget;
  25. ///
  26. /// ctkExampleWorkflowWidgetStepUsingSignalsAndSlots represents an example
  27. /// custom step with a user interface, created by deriving QObject
  28. /// (not ctkWorkflowWidgetStep) and implementing functions for
  29. /// validate(const QString&), onEntry() and onExit() that work using
  30. /// signals and slots.
  31. ///
  32. /// Need two connections to use this class's validate(const QString&) function, and
  33. /// must also set the step's hasValidateCommand flag:
  34. /// QObject::connect(step, SIGNAL(invokeValidateCommand(const QString&)), qObject,
  35. /// SLOT(validate(const QString&)))
  36. /// QObject::connect(qObject, SIGNAL(validationComplete(int)),
  37. /// workflow, SLOT(evaluateValidationResults(int)));
  38. /// step->setHasValidateCommand(1);
  39. ///
  40. /// Need two connections to use this class's onEntry()
  41. /// function, and must also set the step's hasOnEntryCommand
  42. /// flag:
  43. /// QObject::connect(step, SIGNAL(invokeOnEntryCommand(const
  44. /// ctkWorkflowWidgetStep*, const
  45. /// ctkWorkflowTransition::WorkflowTransitionType)), qObject,
  46. /// SLOT(onEntry(const ctkWorkflowWidgetStep*, const
  47. /// ctkWorkflowTransition::WorkflowTransitionType)));
  48. /// QObject::connect(qObject, SIGNAL(onEntryComplete()), step,
  49. /// SLOT(evaluateOnEntryResults()));
  50. /// step->setHasOnEntryCommand(1);
  51. ///
  52. /// Need two connectins to use this class's onExit() function,
  53. /// and must also set the step's hasOnExitCommand() flag:
  54. /// QObject::connect(step, SIGNAL(invokeOnExitCommand(const
  55. /// ctkWorkflowWidgetStep*, const
  56. /// ctkWorkflowTransition::WorkflowTransitionType)), qObject,
  57. /// SLOT(onExit(const ctkWorkflowWidgetStep*, const
  58. /// ctkWorkflowTransition::WorkflowTransitionType)));
  59. /// QObject::connect(qObject, SIGNAL(onExitComplete()), step,
  60. /// SLOT(evaluateOnExitResults()));
  61. /// step->setHasOnExitCommand(1);
  62. class ctkExampleWorkflowWidgetStepUsingSignalsAndSlots : public QObject
  63. {
  64. Q_OBJECT
  65. public:
  66. typedef QObject Superclass;
  67. explicit ctkExampleWorkflowWidgetStepUsingSignalsAndSlots(ctkWorkflowStep* newStep,
  68. QObject* newParent = 0);
  69. virtual ~ctkExampleWorkflowWidgetStepUsingSignalsAndSlots();
  70. // Set/get the widget onto which this step's user interface will be placed
  71. QWidget* widget()const;
  72. void setWidget(QWidget* widget);
  73. /// Set/get the label on this step's user interface
  74. QLabel* label()const;
  75. void setLabel(QLabel* label);
  76. /// Set/get the line edit on this step's user interface
  77. QLineEdit* lineEdit()const;
  78. void setLineEdit(QLineEdit* lineEdit);
  79. ///
  80. /// Get the values for the counters of the number of times we have
  81. /// run the onEntry() and onExit() functions
  82. int numberOfTimesRanOnEntry()const;
  83. int numberOfTimesRanOnExit()const;
  84. public slots:
  85. /// Returns 1 (validation successful) if the step's lineEdit
  86. /// contains an integer whose value is greater than or equal to 10,
  87. /// returns 0 (validation failed) otherwise
  88. virtual void validate(const QString& desiredBranchId = QString());
  89. /// Increments the counter numberOfTimesRanOnEntry
  90. virtual void onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType tracnsitionType);
  91. /// Increments the counter numberOfTimesRanOnExit
  92. virtual void onExit(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  93. /// Adds the label and line edit on this step's user interface to
  94. /// the given list, which will be used by the superclass's
  95. /// showUserInterface() function
  96. virtual void createUserInterface();
  97. signals:
  98. /// Signals indicating to the workflow that these processes have
  99. /// completed
  100. void validationComplete(bool validationSucceeded, const QString& branchId="")const;
  101. void onEntryComplete()const;
  102. void onExitComplete()const;
  103. void createUserInterfaceComplete()const;
  104. protected:
  105. QScopedPointer<ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate> d_ptr;
  106. private:
  107. Q_DECLARE_PRIVATE(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  108. Q_DISABLE_COPY(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  109. };
  110. #endif