ctkWorkflowWidgetStep.cpp 8.1 KB

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