ctkExampleWorkflowWidgetStepUsingSignalsAndSlots.h 4.7 KB

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