ctkCmdLineModuleFrontendQtGui.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMDLINEMODULEFRONTENDQTGUI_H
  16. #define CTKCMDLINEMODULEFRONTENDQTGUI_H
  17. #include "ctkCmdLineModuleFrontend.h"
  18. #include "ctkCommandLineModulesFrontendQtGuiExport.h"
  19. class ctkCmdLineModuleReference;
  20. class ctkCmdLineModuleXslTransform;
  21. class QUiLoader;
  22. class QWidget;
  23. struct ctkCmdLineModuleFrontendQtGuiPrivate;
  24. /**
  25. * \class ctkCmdLineModuleFrontendQtGui
  26. * \brief A Qt based implementation of the module front end.
  27. * \ingroup CommandLineModulesFrontendQtGui_API
  28. *
  29. * This class is able to generate a Qt widgets based GUI from the XML description of
  30. * a given module. It uses a customizable XML stylesheet to transform the raw XML description
  31. * into a .ui file which is fed into a QUiLoader to generate the GUI at runtime.
  32. *
  33. * Sub-classes have several possibilities to customize the generated GUI:
  34. * <ul>
  35. * <li>Override uiLoader() and provide your own QUiLoader or ctkCmdLineModuleQtUiLoader sub-class
  36. * which knows how to instantiate widget types (see the table below for widget class names).</li>
  37. * <li>Bind variables to the ctkCmdLineModuleXslTranform object returned by xslTransform() to
  38. * customize widget class names and property names. This may require you to provide a Qt Designer
  39. * plug-in for your custom widget classes if you do not implement your own widget instantiation
  40. * code in a custom QUiLoader.</li>
  41. * <li>Advanced: Override fragments of the XML stylesheet using ctkCmdLineModuleXslTranform::setXslExtraTransformation()</li>
  42. * </ul>
  43. *
  44. * All widget classes are assumed to expose a readable and writable QObject property for storing and
  45. * retrieving current front-end values via the DisplayRole role.
  46. *
  47. * The following table lists the available XSL parameters (setable via ctkCmdLineModuleXslTransform::bindVariable()),
  48. * and their default values for all parameter types and created container widgets:
  49. *
  50. * \htmlonly
  51. * <style type="text/css">
  52. * table.xslparam { color:#333333; border-collapse:collapse; }
  53. * table.xslparam td { border: 1px solid #666666; padding: 5px; }
  54. * table.xslparam th { border: 1px solid #666666; padding: 5px; background-color: #dedede; font-weight: bold; }
  55. * </style>
  56. * <table class="xslparam">
  57. * <tr><th rowspan="2">Parameter Type</th><th colspan="4" align="center">XSL Parameters</th></tr>
  58. * <tr><th>Widget Class</th><th>Default</th><th>Property Name (DisplayRole)</th><th>Default</th></tr>
  59. * <tr><td>boolean</td><td>booleanWidget</td><td>QCheckBox</td><td>booleanValueProperty</td><td>checked</td></tr>
  60. * <tr><td>integer</td><td>integerWidget</td><td>QSpinBox</td><td>integerValueProperty</td><td>value</td></tr>
  61. * <tr><td>float</td><td>floatingWidget</td><td>QDoubleSpinBox</td><td>floatValueProperty</td><td>value</td></tr>
  62. * <tr><td>double</td><td>floatingWidget</td><td>QDoubleSpinBox</td><td>floatValueProperty</td><td>value</td></tr>
  63. * <tr><td>integer-vector</td><td>vectorWidget</td><td>QLineEdit</td><td>vectorValueProperty</td><td>text</td></tr>
  64. * <tr><td>float-vector</td><td>vectorWidget</td><td>QLineEdit</td><td>vectorValueProperty</td><td>value</td></tr>
  65. * <tr><td>double-vector</td><td>vectorWidget</td><td>QLineEdit</td><td>vectorValueProperty</td><td>value</td></tr>
  66. * <tr><td>string-vector</td><td>vectorWidget</td><td>QLineEdit</td><td>vectorValueProperty</td><td>value</td></tr>
  67. * <tr><td>integer-enumeration</td><td>enumWidget</td><td>QComboBox (ctkCmdLineModuleQtUiLoader instantiates a custom private QComboBox sub-class)</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  68. * <tr><td>float-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  69. * <tr><td>double-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  70. * <tr><td>string-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  71. * <tr><td>file (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>fileInputValueProperty</td><td>currentPath</td></tr>
  72. * <tr><td>file (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>fileOutputValueProperty</td><td>currentPath</td></tr>
  73. * <tr><td>geometry (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>geometryInputValueProperty</td><td>currentPath</td></tr>
  74. * <tr><td>geometry (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>geometryOutputValueProperty</td><td>currentPath</td></tr>
  75. * <tr><td>directory</td><td>directoryWidget</td><td>ctkPathLineEdit</td><td>directoryValueProperty</td><td>currentPath</td></tr>
  76. * <tr><td>point</td><td>pointWidget</td><td>ctkCoordinatesWidget</td><td>pointValueProperty</td><td>coordinates</td></tr>
  77. * <tr><td>region</td><td>pointWidget</td><td>ctkCoordinatesWidget</td><td>pointValueProperty</td><td>coordinates</td></tr>
  78. * <tr><td>image (input channel)</td><td>imageInputWidget</td><td>ctkPathLineEdit</td><td>imageInputValueProperty</td><td>currentPath</td></tr>
  79. * <tr><td>image (output channel)</td><td>imageOutputWidget</td><td>ctkPathLineEdit</td><td>imageOutputValueProperty</td><td>currentPath</td></tr>
  80. * <tr><td>[main container]</td><td>executableWidget</td><td>QWidget</td><td>n/a</td><td>n/a</td></tr>
  81. * <tr><td>[group container]</td><td>parametersWidget</td><td>ctkCollapsibleGroupBox</td><td>n/a</td><td>n/a</td></tr>
  82. * <tr><td>[unknown type]</td><td>unsupportedWidget</td><td>QLabel</td><td>n/a</td><td>n/a</td></tr>
  83. * </table>
  84. * \endhtmlonly
  85. */
  86. class CTK_CMDLINEMODULEQTGUI_EXPORT ctkCmdLineModuleFrontendQtGui : public ctkCmdLineModuleFrontend
  87. {
  88. public:
  89. ctkCmdLineModuleFrontendQtGui(const ctkCmdLineModuleReference& moduleRef);
  90. virtual ~ctkCmdLineModuleFrontendQtGui();
  91. // ctkCmdLineModuleFrontend overrides
  92. /**
  93. * @brief Create the actual Qt GUI.
  94. * @return The parent widget for the created GUI.
  95. *
  96. * The returned object is either NULL or can always be casted to QWidget*.
  97. */
  98. virtual QObject* guiHandle() const;
  99. /**
  100. * @brief Retrieves the current parameter value using the default QObject property for
  101. * parameter values.
  102. * @param parameter
  103. * @param role
  104. *
  105. * This implementation ignores the <code>role</code> argument and always returns
  106. * the value held by the default property, which usually correspongs to the
  107. * DisplayRole.
  108. *
  109. * @see ctkCmdLineModuleFrontend::value()
  110. */
  111. virtual QVariant value(const QString& parameter, int role = LocalResourceRole) const;
  112. /**
  113. * @brief Sets the parameter value.
  114. * @param parameter
  115. * @param value
  116. * @param role
  117. *
  118. * This implementation does nothing if the <code>role</code> parameter does not equal
  119. * ctkCmdLineModuleFrontend::DisplayRole. If it does, it sets the value of the default
  120. * QObject property to the provided value.
  121. *
  122. * @see ctkCmdLiineModuleFrontend::setValue()
  123. */
  124. virtual void setValue(const QString& parameter, const QVariant& value, int role = DisplayRole);
  125. virtual QList<QString> parameterNames() const;
  126. /**
  127. * \brief There is a container QWidget within each group box, so you can
  128. * set the container widget to enabled/disabled, thereby affecting all
  129. * child widgets, without overwriting the enabled/disabled status of the
  130. * child widget.
  131. * @param enabled if true then enabled else disabled
  132. */
  133. virtual void setParameterContainerEnabled(const bool& enabled);
  134. protected:
  135. /**
  136. * @brief Get the QUiLoader for instantiating widgets.
  137. * @return The QUiLoader.
  138. *
  139. * Override this method to provide your own QUiLoader sub-class for application-specific
  140. * customization of certain widgets.
  141. *
  142. * @see ctkCmdLineModuleQtUiLoader
  143. */
  144. virtual QUiLoader* uiLoader() const;
  145. /**
  146. * @brief Get XSL transform used to transfrom the module XML description to a Qt .ui file.
  147. * @return The XSL transform.
  148. *
  149. * Override this method to either customize the default transformation or completely provide
  150. * your own.
  151. *
  152. * @see ctkCmdLineModuleXslTransform
  153. */
  154. virtual ctkCmdLineModuleXslTransform* xslTransform() const;
  155. /**
  156. * @brief Get the value of the given parameter using the given property name.
  157. * @param parameter The parameter name.
  158. * @param propertyName The property name from which to get the value.
  159. * @return The parameter value for the given property name.
  160. *
  161. * If \c propertyName is empty, this method returns the value of the property used store the values
  162. * for the DisplayRole role.
  163. *
  164. * Sub-classes can use this method to retrieve values for custom roles.
  165. */
  166. QVariant customValue(const QString& parameter, const QString& propertyName = QString()) const;
  167. /**
  168. * @brief Set the value of the given parameter to \c value using the given property name.
  169. * @param parameter The parameter name.
  170. * @param value The new value.
  171. * @param propertyName The property name for which to set the value.
  172. *
  173. * If \c propertyName is empty, this method sets the value of the property used store the values
  174. * for the DisplayRole role.
  175. *
  176. * Sub-classes can use this method to set values for custom roles.
  177. */
  178. void setCustomValue(const QString& parameter, const QVariant& value, const QString& propertyName = QString()) ;
  179. private:
  180. QScopedPointer<ctkCmdLineModuleFrontendQtGuiPrivate> d;
  181. };
  182. #endif // CTKCMDLINEMODULEFRONTENDQTGUI_H