ctkWorkflowWidget.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef __ctkWorkflowWidget_h
  15. #define __ctkWorkflowWidget_h
  16. // Qt includes
  17. #include <QWidget>
  18. #include <QVariant>
  19. class QAbstractButton;
  20. // CTK includes
  21. #include "ctkPimpl.h"
  22. #include "ctkWidgetsExport.h"
  23. class ctkWorkflow;
  24. class ctkWorkflowStep;
  25. class ctkWorkflowButtonBoxWidget;
  26. class ctkWorkflowGroupBox;
  27. class ctkWorkflowWidgetStep;
  28. class ctkWorkflowWidgetPrivate;
  29. /// \ingroup Widgets
  30. /// \brief ctkWorkflowWidget is the basis for a workflow with a user interface. It groups together
  31. /// and manages a ctkWorkflowGroupBox (to display the step) and a ctkWorkflowButtonBoxWidget
  32. /// (providing buttons for traversing the workflow).
  33. class CTK_WIDGETS_EXPORT ctkWorkflowWidget : public QWidget
  34. {
  35. Q_OBJECT
  36. Q_PROPERTY(bool showButtonBoxWidget READ showButtonBoxWidget WRITE setShowButtonBoxWidget)
  37. public:
  38. typedef QWidget Superclass;
  39. explicit ctkWorkflowWidget(QWidget* parent = 0);
  40. virtual ~ctkWorkflowWidget();
  41. /// Set/get the workflow associated with this widget.
  42. Q_INVOKABLE virtual ctkWorkflow* workflow()const;
  43. Q_INVOKABLE virtual void setWorkflow(ctkWorkflow* newWorkflow);
  44. Q_INVOKABLE ctkWorkflowWidgetStep* widgetStep(const QString& id)const;
  45. /// Get the widget constaining the title, subtitle, pre-text, post-text, error-text and client area
  46. /// layout.
  47. Q_INVOKABLE virtual ctkWorkflowGroupBox* workflowGroupBox()const;
  48. /// Set/get whether or not to associate a buttonBoxWidget with this step (default true)
  49. bool showButtonBoxWidget()const;
  50. void setShowButtonBoxWidget(bool newShowButtonBoxWidget);
  51. /// Get the widget with the 'next', 'back' and 'goTo' buttons
  52. Q_INVOKABLE ctkWorkflowButtonBoxWidget* buttonBoxWidget()const;
  53. /// Apply the text, icon and tooltip format to the button.
  54. /// * {PROP}, [prop] or (PROP): value of the PROP property (e.g. stepid,
  55. /// name, description...) used as button text, icon or tooltip respectively.
  56. /// PROP can be prefixed by 'back:', 'next:' or 'current:',
  57. /// the property will then be the one of the previous, next or current step.
  58. /// * [<-]: Back arrow icon. If it is the first item, the icon is to the left
  59. /// of the button text.
  60. /// * [->]: Next arrow icon. If it is the last item, the icon is to the right
  61. /// of the button text if the button is a ctkPushButton.
  62. /// * {#} or (#): 1-based index of the step (int)
  63. /// * {!#} or {!#} : Total number of steps (int)
  64. /// * "ABCD": text for the button
  65. /// * {PROP|"ABCD"}: Use ABCD as fallback if PROP is not a valid property or
  66. /// if the text is empty.
  67. ///
  68. /// Examples:
  69. /// "{next:#}"/"{!#}") "{next:name}(next:description)[->]" will format the button with:
  70. /// * text="3/3) Compute Algorithm" if the next step is the last step of a
  71. /// 3-step-workflow, and its name is "Compute Algorithm".
  72. /// * icon=QStyle::SP_ArrowRight
  73. /// * tooltip="This step computes the algorithm" if the next step description
  74. /// is "This step...".
  75. /// \sa parse(), formatText()
  76. static void formatButton(QAbstractButton* button, const QString& format, ctkWorkflowWidgetStep* step);
  77. /// Return the text contained in \a format.
  78. /// \sa parse(), formatButton()
  79. static QString formatText(const QString& format, ctkWorkflowWidgetStep* step);
  80. public Q_SLOTS:
  81. /// Triggers updates of the the workflowGroupBox and the buttonBoxWidget when the current workflow
  82. /// step has changed.
  83. virtual void onCurrentStepChanged(ctkWorkflowStep* currentStep);
  84. protected Q_SLOTS:
  85. void onStepRegistered(ctkWorkflowStep* step);
  86. protected:
  87. // Triggers updates of the workflowGroupBox when the current workflow step has changed.
  88. virtual void updateStepUI(ctkWorkflowStep* currentStep);
  89. // Triggers updates of the buttonBoxWidget when the current workflow step has changed.
  90. void updateButtonBoxUI(ctkWorkflowStep* currentStep);
  91. /// Return the value of the formatItem.
  92. /// \sa format()
  93. static QVariant buttonItem(QString formatItem, ctkWorkflowWidgetStep* step);
  94. /// Return a dictionary of formats. Keys can be 'text', 'icon', 'iconalignment' or 'tooltip'.
  95. /// \sa buttonItem(), formatButton(), formatText()
  96. static QMap<QString, QVariant> parse(const QString& format, ctkWorkflowWidgetStep* step);
  97. protected:
  98. QScopedPointer<ctkWorkflowWidgetPrivate> d_ptr;
  99. private:
  100. Q_DECLARE_PRIVATE(ctkWorkflowWidget);
  101. Q_DISABLE_COPY(ctkWorkflowWidget);
  102. };
  103. #endif