ctkExampleDerivedWorkflowWidgetStep.cpp 5.7 KB

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