ctkWorkflowWidgetStep.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #include <QList>
  16. #include <QDebug>
  17. // CTK includes
  18. #include "ctkWorkflowWidgetStep.h"
  19. #include "ctkWorkflowWidgetStep_p.h"
  20. #include "ctkWorkflowWidget.h"
  21. #include "ctkWorkflow.h"
  22. // STD includes
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. // ctkWorkflowWidgetStepPrivate methods
  26. //-----------------------------------------------------------------------------
  27. ctkWorkflowWidgetStepPrivate::ctkWorkflowWidgetStepPrivate(ctkWorkflowWidgetStep& object)
  28. :Superclass(object), q_ptr(&object)
  29. {
  30. this->WidgetType = true;
  31. // this->buttonBoxWidget = 0;
  32. // this->hasButtonBoxWidget = false;
  33. this->icon = QIcon();
  34. this->created = false;
  35. }
  36. //-----------------------------------------------------------------------------
  37. ctkWorkflowWidgetStepPrivate::~ctkWorkflowWidgetStepPrivate()
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. void ctkWorkflowWidgetStepPrivate::invokeShowUserInterfaceCommandInternal()const
  42. {
  43. emit invokeShowUserInterfaceCommand();
  44. }
  45. //-----------------------------------------------------------------------------
  46. void ctkWorkflowWidgetStepPrivate::showUserInterfaceCompleteInternal()const
  47. {
  48. emit showUserInterfaceComplete();
  49. }
  50. //-----------------------------------------------------------------------------
  51. void ctkWorkflowWidgetStepPrivate::showUserInterface()
  52. {
  53. Q_Q(ctkWorkflowWidgetStep);
  54. q->showUserInterface();
  55. }
  56. //-----------------------------------------------------------------------------
  57. void ctkWorkflowWidgetStepPrivate::invokeCreateUserInterfaceCommandInternal()const
  58. {
  59. emit invokeCreateUserInterfaceCommand();
  60. }
  61. //-----------------------------------------------------------------------------
  62. void ctkWorkflowWidgetStepPrivate::createUserInterfaceCompleteInternal()const
  63. {
  64. emit createUserInterfaceComplete();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // ctkWorkflowWidgetStep methods
  68. //-----------------------------------------------------------------------------
  69. ctkWorkflowWidgetStep::ctkWorkflowWidgetStep(QWidget* newParent) :
  70. QWidget(newParent),
  71. ctkWorkflowStep(new ctkWorkflowWidgetStepPrivate(*this), QString())
  72. {
  73. Q_D(ctkWorkflowWidgetStep);
  74. d->hasShowUserInterfaceCommand = false;
  75. d->hasCreateUserInterfaceCommand = false;
  76. d->ButtonBoxHints = ctkWorkflowWidgetStep::NoHints;
  77. }
  78. //-----------------------------------------------------------------------------
  79. ctkWorkflowWidgetStep::ctkWorkflowWidgetStep(const QString& newId, QWidget* newParent) :
  80. QWidget(newParent),
  81. ctkWorkflowStep(new ctkWorkflowWidgetStepPrivate(*this), newId)
  82. {
  83. Q_D(ctkWorkflowWidgetStep);
  84. d->hasShowUserInterfaceCommand = false;
  85. d->hasCreateUserInterfaceCommand = false;
  86. d->ButtonBoxHints = ctkWorkflowWidgetStep::NoHints;
  87. }
  88. //-----------------------------------------------------------------------------
  89. ctkWorkflowWidgetStep::~ctkWorkflowWidgetStep()
  90. {
  91. }
  92. //-----------------------------------------------------------------------------
  93. CTK_GET_CPP(ctkWorkflowWidgetStep, bool, hasShowUserInterfaceCommand, hasShowUserInterfaceCommand);
  94. CTK_SET_CPP(ctkWorkflowWidgetStep, bool, setHasShowUserInterfaceCommand, hasShowUserInterfaceCommand);
  95. CTK_GET_CPP(ctkWorkflowWidgetStep, bool, hasCreateUserInterfaceCommand, hasCreateUserInterfaceCommand);
  96. CTK_SET_CPP(ctkWorkflowWidgetStep, bool, setHasCreateUserInterfaceCommand, hasCreateUserInterfaceCommand);
  97. CTK_GET_CPP(ctkWorkflowWidgetStep, QString, backButtonText, backButtonText);
  98. CTK_SET_CPP(ctkWorkflowWidgetStep, const QString&, setBackButtonText, backButtonText);
  99. CTK_GET_CPP(ctkWorkflowWidgetStep, QString, nextButtonText, nextButtonText);
  100. CTK_SET_CPP(ctkWorkflowWidgetStep, const QString&, setNextButtonText, nextButtonText);
  101. // CTK_GET_CPP(ctkWorkflowWidgetStep, QList<QString>, finishButtonTexts, finishButtonTexts);
  102. // CTK_SET_CPP(ctkWorkflowWidgetStep, QList<QString>, setFinishButtonTexts, finishButtonTexts);
  103. //CTK_GET_CPP(ctkWorkflowWidgetStep, bool, hasButtonBoxWidget, hasButtonBoxWidget);
  104. //CTK_SET_CPP(ctkWorkflowWidgetStep, bool, setHasButtonBoxWidget, hasButtonBoxWidget);
  105. CTK_GET_CPP(ctkWorkflowWidgetStep, QIcon, icon, icon);
  106. CTK_SET_CPP(ctkWorkflowWidgetStep, const QIcon&, setIcon, icon);
  107. //-----------------------------------------------------------------------------
  108. QWidget* ctkWorkflowWidgetStep::stepArea()
  109. {
  110. return this;
  111. }
  112. //-----------------------------------------------------------------------------
  113. CTK_GET_CPP(ctkWorkflowWidgetStep, ctkWorkflowWidgetStep::ButtonBoxHints,
  114. buttonBoxHints, ButtonBoxHints);
  115. CTK_SET_CPP(ctkWorkflowWidgetStep, ctkWorkflowWidgetStep::ButtonBoxHints,
  116. setButtonBoxHints, ButtonBoxHints);
  117. //-----------------------------------------------------------------------------
  118. // void ctkWorkflowWidgetStep::setFinishButtonText(const QString& name)
  119. // {
  120. // QList<QString> names;
  121. // names << name;
  122. // this->setFinishButtonTexts(names);
  123. // }
  124. // //-----------------------------------------------------------------------------
  125. // ctkWorkflowButtonBoxWidget* ctkWorkflowWidgetStep::buttonBoxWidget()
  126. // {
  127. // Q_D(ctkWorkflowWidgetStep);
  128. // if (!d->hasButtonBoxWidget)
  129. // {
  130. // return 0;
  131. // }
  132. // if (!d->buttonBoxWidget)
  133. // {
  134. // if (!this->workflow())
  135. // {
  136. // qWarning() << "buttonBoxWidget - Cannot create buttonBoxWidget without a workflow";
  137. // return 0;
  138. // }
  139. // d->buttonBoxWidget = new ctkWorkflowButtonBoxWidget(this->workflow());
  140. // }
  141. // return d->buttonBoxWidget;
  142. // }
  143. //-----------------------------------------------------------------------------
  144. void ctkWorkflowWidgetStep::showUserInterface()
  145. {
  146. Q_D(ctkWorkflowWidgetStep);
  147. // use the user's showUserInterfaceCommand if given
  148. if (d->hasShowUserInterfaceCommand)
  149. {
  150. this->invokeShowUserInterfaceCommand();
  151. return;
  152. }
  153. // otherwise we provide an implementation here
  154. if (this->workflow()->verbose())
  155. {
  156. qDebug() << QString("showUserInterface - showing %1").arg(this->name());
  157. }
  158. // create the user interface if this is the first time we're showing this step
  159. if (!d->created)
  160. {
  161. if (d->hasCreateUserInterfaceCommand)
  162. {
  163. this->invokeCreateUserInterfaceCommand();
  164. }
  165. else
  166. {
  167. this->createUserInterface();
  168. }
  169. d->created = true;
  170. }
  171. emit showUserInterfaceComplete();
  172. }
  173. //-----------------------------------------------------------------------------
  174. void ctkWorkflowWidgetStep::invokeShowUserInterfaceCommand()const
  175. {
  176. Q_D(const ctkWorkflowWidgetStep);
  177. d->invokeShowUserInterfaceCommandInternal();
  178. }
  179. //-----------------------------------------------------------------------------
  180. void ctkWorkflowWidgetStep::showUserInterfaceComplete()const
  181. {
  182. Q_D(const ctkWorkflowWidgetStep);
  183. d->showUserInterfaceCompleteInternal();
  184. }
  185. //-----------------------------------------------------------------------------
  186. void ctkWorkflowWidgetStep::invokeCreateUserInterfaceCommand()const
  187. {
  188. Q_D(const ctkWorkflowWidgetStep);
  189. d->invokeCreateUserInterfaceCommandInternal();
  190. }
  191. //-----------------------------------------------------------------------------
  192. void ctkWorkflowWidgetStep::createUserInterfaceComplete()const
  193. {
  194. Q_D(const ctkWorkflowWidgetStep);
  195. d->createUserInterfaceCompleteInternal();
  196. }