ctkExampleWorkflowStepUsingSignalsAndSlots.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // Qt includes
  15. // CTK includes
  16. #include "ctkExampleWorkflowStepUsingSignalsAndSlots.h"
  17. #include "ctkWorkflowStep.h"
  18. // STD includes
  19. #include <iostream>
  20. //-----------------------------------------------------------------------------
  21. class ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate
  22. {
  23. public:
  24. ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate();
  25. // counters of the number of times we have run the onEntry()
  26. // and onExit() functions
  27. int numberOfTimesRanOnEntry;
  28. int numberOfTimesRanOnExit;
  29. ctkWorkflowStep * Step;
  30. };
  31. //-----------------------------------------------------------------------------
  32. // ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate methods
  33. //-----------------------------------------------------------------------------
  34. ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate::ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate()
  35. {
  36. this->numberOfTimesRanOnEntry = 0;
  37. this->numberOfTimesRanOnExit = 0;
  38. this->Step = 0;
  39. }
  40. //-----------------------------------------------------------------------------
  41. // ctkExampleWorkflowStepUsingSignalsAndSlots methods
  42. //-----------------------------------------------------------------------------
  43. ctkExampleWorkflowStepUsingSignalsAndSlots::ctkExampleWorkflowStepUsingSignalsAndSlots(
  44. ctkWorkflowStep * newStep, QObject* newParent) : Superclass(newParent)
  45. , d_ptr(new ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate)
  46. {
  47. Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
  48. d->Step = newStep;
  49. }
  50. //-----------------------------------------------------------------------------
  51. ctkExampleWorkflowStepUsingSignalsAndSlots::~ctkExampleWorkflowStepUsingSignalsAndSlots()
  52. {
  53. }
  54. //-----------------------------------------------------------------------------
  55. void ctkExampleWorkflowStepUsingSignalsAndSlots::validate(const QString& desiredBranchId)const
  56. {
  57. Q_D(const ctkExampleWorkflowStepUsingSignalsAndSlots);
  58. // Always returns true in this simple example
  59. QObject::staticMetaObject.invokeMethod(
  60. d->Step->ctkWorkflowStepQObject(), "validationComplete",
  61. Q_ARG(bool, true), Q_ARG(QString, desiredBranchId));
  62. }
  63. //-----------------------------------------------------------------------------
  64. void ctkExampleWorkflowStepUsingSignalsAndSlots::validateFails()const
  65. {
  66. Q_D(const ctkExampleWorkflowStepUsingSignalsAndSlots);
  67. // Always returns false in this simple example
  68. QObject::staticMetaObject.invokeMethod(
  69. d->Step->ctkWorkflowStepQObject(), "validationComplete",
  70. Q_ARG(bool, false), Q_ARG(QString, ""));
  71. }
  72. //-----------------------------------------------------------------------------
  73. void ctkExampleWorkflowStepUsingSignalsAndSlots::onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  74. {
  75. Q_UNUSED(comingFrom);
  76. Q_UNUSED(transitionType);
  77. // simply implements our counter of the number of times we have run
  78. // this function
  79. Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
  80. d->numberOfTimesRanOnEntry++;
  81. // signals that we are finished
  82. QObject::staticMetaObject.invokeMethod(
  83. d->Step->ctkWorkflowStepQObject(), "onEntryComplete");
  84. }
  85. //-----------------------------------------------------------------------------
  86. void ctkExampleWorkflowStepUsingSignalsAndSlots::onExit(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  87. {
  88. Q_UNUSED(goingTo);
  89. Q_UNUSED(transitionType);
  90. // simply implements our counter of the number of times we have run
  91. // this function
  92. Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
  93. d->numberOfTimesRanOnExit++;
  94. // signals that we are finished
  95. QObject::staticMetaObject.invokeMethod(
  96. d->Step->ctkWorkflowStepQObject(), "onExitComplete");
  97. }
  98. //-----------------------------------------------------------------------------
  99. CTK_GET_CPP(ctkExampleWorkflowStepUsingSignalsAndSlots, int, numberOfTimesRanOnEntry, numberOfTimesRanOnEntry);
  100. CTK_GET_CPP(ctkExampleWorkflowStepUsingSignalsAndSlots, int, numberOfTimesRanOnExit, numberOfTimesRanOnExit);