ctkWorkflowWidgetStep.cpp 8.1 KB

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