ctkExampleWorkflowWidgetStepUsingSignalsAndSlots.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // Qt includes
  15. #include <QLabel>
  16. #include <QLineEdit>
  17. // CTK includes
  18. #include "ctkExampleWorkflowWidgetStepUsingSignalsAndSlots.h"
  19. #include "ctkWorkflowWidgetStep.h"
  20. #include "ctkWorkflowStep.h"
  21. #include "ctkWorkflowWidget.h"
  22. // STD includes
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. class ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate : public ctkPrivate<ctkExampleWorkflowWidgetStepUsingSignalsAndSlots>
  26. {
  27. public:
  28. CTK_DECLARE_PUBLIC(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  29. ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate();
  30. ~ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate(){}
  31. /// elements of this step's user interface
  32. QLabel* label;
  33. QLineEdit* lineEdit;
  34. int defaultLineEditValue;
  35. // counters of the number of times we have run the onEntry()
  36. // and onExit() functions
  37. int numberOfTimesRanOnEntry;
  38. int numberOfTimesRanOnExit;
  39. };
  40. //-----------------------------------------------------------------------------
  41. // ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate methods
  42. //-----------------------------------------------------------------------------
  43. ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate::ctkExampleWorkflowWidgetStepUsingSignalsAndSlotsPrivate()
  44. {
  45. this->label = 0;
  46. this->lineEdit = 0;
  47. this->defaultLineEditValue = 10;
  48. this->numberOfTimesRanOnEntry = 0;
  49. this->numberOfTimesRanOnExit = 0;
  50. }
  51. //-----------------------------------------------------------------------------
  52. // ctkExampleWorkflowWidgetStepUsingSignalsAndSlots methods
  53. //-----------------------------------------------------------------------------
  54. ctkExampleWorkflowWidgetStepUsingSignalsAndSlots::ctkExampleWorkflowWidgetStepUsingSignalsAndSlots(QObject* _parent) : Superclass(_parent)
  55. {
  56. CTK_INIT_PRIVATE(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  57. }
  58. //-----------------------------------------------------------------------------
  59. CTK_GET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, QLabel*, label, label);
  60. CTK_SET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, QLabel*, setLabel, label);
  61. CTK_GET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, QLineEdit*, lineEdit, lineEdit);
  62. CTK_SET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, QLineEdit*, setLineEdit, lineEdit);
  63. CTK_GET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, int, numberOfTimesRanOnEntry, numberOfTimesRanOnEntry);
  64. CTK_GET_CXX(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots, int, numberOfTimesRanOnExit, numberOfTimesRanOnExit);
  65. //-----------------------------------------------------------------------------
  66. void ctkExampleWorkflowWidgetStepUsingSignalsAndSlots::onEntry(
  67. const ctkWorkflowStep* comingFrom,
  68. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  69. {
  70. Q_UNUSED(comingFrom);
  71. Q_UNUSED(transitionType);
  72. // simply implements our counter of the number of times we have run
  73. // this function
  74. CTK_D(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  75. d->numberOfTimesRanOnEntry++;
  76. // signals that we are finished
  77. emit onEntryComplete();
  78. }
  79. //-----------------------------------------------------------------------------
  80. void ctkExampleWorkflowWidgetStepUsingSignalsAndSlots::onExit(
  81. const ctkWorkflowStep* goingTo,
  82. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  83. {
  84. Q_UNUSED(goingTo);
  85. Q_UNUSED(transitionType);
  86. // simply implements our counter of the number of times we have run
  87. // this function
  88. CTK_D(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  89. d->numberOfTimesRanOnExit++;
  90. // signals that we are finished
  91. emit onExitComplete();
  92. }
  93. //-----------------------------------------------------------------------------
  94. void ctkExampleWorkflowWidgetStepUsingSignalsAndSlots::populateStepWidgetsList(
  95. QList<QWidget*>& stepWidgetsList)
  96. {
  97. // add the user interface elements to the list
  98. CTK_D(ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  99. if (!d->label)
  100. {
  101. d->label = new QLabel();
  102. d->label->setText("enter a number greater than or equal to 10");
  103. stepWidgetsList << d->label;
  104. }
  105. if (!d->lineEdit)
  106. {
  107. d->lineEdit = new QLineEdit();
  108. d->lineEdit->setInputMask("000");
  109. d->lineEdit->setText("10");
  110. stepWidgetsList << d->lineEdit;
  111. }
  112. // signals that we are finished
  113. emit populateStepWidgetsListComplete();
  114. }
  115. //-----------------------------------------------------------------------------
  116. void ctkExampleWorkflowWidgetStepUsingSignalsAndSlots::validate(const QString& desiredBranchId)
  117. {
  118. CTK_D(const ctkExampleWorkflowWidgetStepUsingSignalsAndSlots);
  119. bool retVal;
  120. int val;
  121. bool ok;
  122. if (d->lineEdit)
  123. {
  124. QString text = d->lineEdit->text();
  125. val = text.toInt(&ok);
  126. }
  127. // used when going to a finish step
  128. else
  129. {
  130. val = d->defaultLineEditValue;
  131. ok = true;
  132. }
  133. if (!ok)
  134. {
  135. //this->setStatusText("invalid (not an integer or empty)");
  136. retVal = false;
  137. }
  138. else if (val < 10)
  139. {
  140. //this->setStatusText("invalid (invalid number)");
  141. retVal = false;
  142. }
  143. else
  144. {
  145. //this->setStatusText("");
  146. retVal = true;
  147. }
  148. // return the validation results
  149. emit validationComplete(retVal, desiredBranchId);
  150. }