ctkWorkflowAbstractWidgetStep.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef __ctkWorkflowAbstractWidgetStep_h
  15. #define __ctkWorkflowAbstractWidgetStep_h
  16. // QT includes
  17. class QObject;
  18. class QWidget;
  19. class QIcon;
  20. #include <QBoxLayout>
  21. #include <QFlags>
  22. // CTK includes
  23. #include "ctkPimpl.h"
  24. #include "ctkWidgetsExport.h"
  25. #include "ctkWorkflowStep.h"
  26. #include "ctkWorkflowTransitions.h"
  27. class ctkWorkflowGroupBox;
  28. class ctkWorkflowAbstractWidgetStepPrivate;
  29. ///
  30. /// \brief ctkWorkflowAbstractWidgetStep is a convienience class to quickly
  31. /// construct a ctkWorkflowStep with a user interface.
  32. ///
  33. /// It embeds a QWidget* stepArea, onto which step-specific widgets can be placed.
  34. /// The showUserInterface() and hideUserInterface() commands of ctkWorkflowStep are
  35. /// written for you, and, if you desire, the step's "Next" and/or "Back" buttons are
  36. /// added with the appropriate signals and slots.
  37. /// To create a custom step, you can derive from this class and
  38. /// implement only two functions:
  39. /// 1) ctkWorkflowAbstractWidgetStep::populateStepWidgetsList(), to define the
  40. /// step-specific widgets;
  41. /// 2) ctkWorkflowAbstractWidgetStep::validate(const QString&), to validate the processing
  42. /// state associated with this step.
  43. /// For additional customization, you can reimplement
  44. /// showUserInterface() and hideUserInterface() in derived classes.
  45. /// \sa showUserInterface() hideUserInterface()
  46. class CTK_WIDGETS_EXPORT ctkWorkflowAbstractWidgetStep : public ctkWorkflowStep
  47. {
  48. public:
  49. enum ButtonBoxHint {
  50. NoHints = 0x0,
  51. BackButtonHidden = 0x1,
  52. BackButtonDisabled = 0x2,
  53. NextButtonHidden = 0x4,
  54. NextButtonDisabled = 0x8,
  55. ButtonBoxHidden = 0x10
  56. };
  57. Q_DECLARE_FLAGS(ButtonBoxHints, ButtonBoxHint)
  58. typedef ctkWorkflowStep Superclass;
  59. explicit ctkWorkflowAbstractWidgetStep(ctkWorkflow* newWorkflow, const QString& newId);
  60. virtual ~ctkWorkflowAbstractWidgetStep();
  61. /// \brief Override the back button text of any ctkWorkflowButtonBox when this step
  62. /// is the current step
  63. virtual QString backButtonText()const;
  64. virtual void setBackButtonText(const QString& name);
  65. /// \brief Override the next button text of any ctkWorkflowButtonBox when this step
  66. /// is the current step
  67. virtual QString nextButtonText()const;
  68. virtual void setNextButtonText(const QString& name);
  69. /// \brief Override the button visibility of any ctkWorkflowButtonBox when this step is the
  70. /// current step
  71. void setButtonBoxHints(ButtonBoxHints buttonBoxHints);
  72. ButtonBoxHints buttonBoxHints()const;
  73. /// \brief Associate an icon with this step (ex. used by ctkWorkflowButtonBox to display an icon
  74. /// on 'goTo' buttons).
  75. QIcon icon()const;
  76. void setIcon(const QIcon& newIcon);
  77. /// Returns the QWidget onto which this step's user interface elements are placed.
  78. virtual QWidget* stepArea() = 0;
  79. /// Set/get whether a showUserInterfaceCommand has been provided in
  80. /// a separate QObject (see method 2 described for
  81. /// showUserInterface())
  82. virtual bool hasShowUserInterfaceCommand()const;
  83. virtual void setHasShowUserInterfaceCommand(bool flag);
  84. /// Set/get whether a createUserInterfaceCommand has been provided in
  85. /// a separate QObject (see method 2 described for
  86. /// createUserInterface())
  87. virtual bool hasCreateUserInterfaceCommand()const;
  88. virtual void setHasCreateUserInterfaceCommand(bool flag);
  89. protected:
  90. /// Creates the user interface associated with this step.
  91. virtual void createUserInterface() = 0;
  92. /// Prepares the step to be shown.
  93. virtual void showUserInterface();
  94. /// \brief Signal (emitted by the private implementation) indicating that the step's
  95. /// createUserInterface() method should be called.
  96. /// \sa createUserInterface()
  97. void invokeCreateUserInterfaceCommand()const;
  98. /// \brief Signal (emitted by the private implementation) indicating that the step's
  99. /// createUserInterface() method has completed.
  100. /// \sa createUserInterface()
  101. void createUserInterfaceComplete()const;
  102. /// \brief Signal (emitted by the private implementation) indicating that the step's
  103. /// 'showUserInterface() method should be called.
  104. /// \sa showUserInterface()
  105. void invokeShowUserInterfaceCommand()const;
  106. /// \brief Signal (emitted by the private implementation) indicating that the step's
  107. /// showUserInterface() method has completed.
  108. /// \sa showUserInterface()
  109. void showUserInterfaceComplete()const;
  110. private:
  111. Q_DECLARE_PRIVATE(ctkWorkflowAbstractWidgetStep);
  112. Q_DISABLE_COPY(ctkWorkflowAbstractWidgetStep);
  113. friend class ctkWorkflowGroupBox; // For access to showUserInterface()
  114. };
  115. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkWorkflowAbstractWidgetStep::ButtonBoxHints)
  116. #endif