ctkExampleWorkflowStepUsingSignalsAndSlots.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // 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. };
  30. //-----------------------------------------------------------------------------
  31. // ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate methods
  32. //-----------------------------------------------------------------------------
  33. ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate::ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate()
  34. {
  35. this->numberOfTimesRanOnEntry = 0;
  36. this->numberOfTimesRanOnExit = 0;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // ctkExampleWorkflowStepUsingSignalsAndSlots methods
  40. //-----------------------------------------------------------------------------
  41. ctkExampleWorkflowStepUsingSignalsAndSlots::ctkExampleWorkflowStepUsingSignalsAndSlots(QObject* _parent) : Superclass(_parent)
  42. , d_ptr(new ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate)
  43. {
  44. }
  45. //-----------------------------------------------------------------------------
  46. ctkExampleWorkflowStepUsingSignalsAndSlots::~ctkExampleWorkflowStepUsingSignalsAndSlots()
  47. {
  48. }
  49. //-----------------------------------------------------------------------------
  50. void ctkExampleWorkflowStepUsingSignalsAndSlots::validate(const QString& desiredBranchId)const
  51. {
  52. // Always returns true in this simple example
  53. emit validationComplete(true, desiredBranchId);
  54. }
  55. //-----------------------------------------------------------------------------
  56. void ctkExampleWorkflowStepUsingSignalsAndSlots::validateFails()const
  57. {
  58. // Always returns false in this simple example
  59. emit validationComplete(false);
  60. }
  61. //-----------------------------------------------------------------------------
  62. void ctkExampleWorkflowStepUsingSignalsAndSlots::onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  63. {
  64. Q_UNUSED(comingFrom);
  65. Q_UNUSED(transitionType);
  66. // simply implements our counter of the number of times we have run
  67. // this function
  68. Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
  69. d->numberOfTimesRanOnEntry++;
  70. // signals that we are finished
  71. emit onEntryComplete();
  72. }
  73. //-----------------------------------------------------------------------------
  74. void ctkExampleWorkflowStepUsingSignalsAndSlots::onExit(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  75. {
  76. Q_UNUSED(goingTo);
  77. Q_UNUSED(transitionType);
  78. // simply implements our counter of the number of times we have run
  79. // this function
  80. Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
  81. d->numberOfTimesRanOnExit++;
  82. // signals that we are finished
  83. emit onExitComplete();
  84. }
  85. //-----------------------------------------------------------------------------
  86. CTK_GET_CPP(ctkExampleWorkflowStepUsingSignalsAndSlots, int, numberOfTimesRanOnEntry, numberOfTimesRanOnEntry);
  87. CTK_GET_CPP(ctkExampleWorkflowStepUsingSignalsAndSlots, int, numberOfTimesRanOnExit, numberOfTimesRanOnExit);