ctkCmdLineModuleFrontendQtGui.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * In addition, for image and file, input and output, it is normally necessary to define a set property within
  87. * the generated .ui file to contain various configuration flags to pass to the widget. For example, ctkPathLineEdit
  88. * has a "filters" property that can be used to configure the dialog behaviour when the browse button is pressed.
  89. * The following XSL parameters are available to create a set property and are also setable via
  90. * ctkCmdLineModuleXslTransform::bindVariable(). If the empty string is bound to the Set Property Name,
  91. * the set property will be omitted.
  92. *
  93. * \htmlonly
  94. * <style type="text/css">
  95. * table.xslparam { color:#333333; border-collapse:collapse; }
  96. * table.xslparam td { border: 1px solid #666666; padding: 5px; }
  97. * table.xslparam th { border: 1px solid #666666; padding: 5px; background-color: #dedede; font-weight: bold; }
  98. * </style>
  99. * <table class="xslparam">
  100. * <tr><th rowspan="2">Parameter Type</th><th colspan="4" align="center">XSL Parameters</th></tr>
  101. * <tr><th>Set Property Name</th><th>Default</th><th>Set Property Value</th><th>Default</th></tr>
  102. * <tr><td>file (input channel)</td><td>fileInputSetProperty</td><td>filters</td><td>fileInputSetValue</td><td>ctkPathLineEdit::Files|ctkPathLineEdit::Readable</td></tr>
  103. * <tr><td>file (output channel)</td><td>fileOutputSetProperty</td><td>filters</td><td>fileOutputSetValue</td><td>ctkPathLineEdit::Files|ctkPathLineEdit::Writable</td></tr>
  104. * <tr><td>image (input channel)</td><td>imageInputSetProperty</td><td>filters</td><td>imageInputSetProperty</td><td>ctkPathLineEdit::Files|ctkPathLineEdit::Readable</td></tr>
  105. * <tr><td>image (output channel)</td><td>imageOutputSetProperty</td><td>filters</td><td>imageOutputSetProperty</td><td>ctkPathLineEdit::Files|ctkPathLineEdit::Writable</td></tr>
  106. * </table>
  107. * \endhtmlonly
  108. */
  109. class CTK_CMDLINEMODULEQTGUI_EXPORT ctkCmdLineModuleFrontendQtGui : public ctkCmdLineModuleFrontend
  110. {
  111. public:
  112. ctkCmdLineModuleFrontendQtGui(const ctkCmdLineModuleReference& moduleRef);
  113. virtual ~ctkCmdLineModuleFrontendQtGui();
  114. // ctkCmdLineModuleFrontend overrides
  115. /**
  116. * @brief Create the actual Qt GUI.
  117. * @return The parent widget for the created GUI.
  118. *
  119. * The returned object is either NULL or can always be casted to QWidget*.
  120. */
  121. virtual QObject* guiHandle() const;
  122. /**
  123. * @brief Retrieves the current parameter value using the default QObject property for
  124. * parameter values.
  125. * @param parameter
  126. * @param role
  127. *
  128. * This implementation ignores the <code>role</code> argument and always returns
  129. * the value held by the default property, which usually correspongs to the
  130. * DisplayRole.
  131. *
  132. * @see ctkCmdLineModuleFrontend::value()
  133. */
  134. virtual QVariant value(const QString& parameter, int role = LocalResourceRole) const;
  135. /**
  136. * @brief Sets the parameter value.
  137. * @param parameter
  138. * @param value
  139. * @param role
  140. *
  141. * This implementation does nothing if the <code>role</code> parameter does not equal
  142. * ctkCmdLineModuleFrontend::DisplayRole. If it does, it sets the value of the default
  143. * QObject property to the provided value.
  144. *
  145. * @see ctkCmdLineModuleFrontend::setValue()
  146. */
  147. virtual void setValue(const QString& parameter, const QVariant& value, int role = DisplayRole);
  148. virtual QList<QString> parameterNames() const;
  149. /**
  150. * \brief There is a container QWidget within each group box, so you can
  151. * set the container widget to enabled/disabled, thereby affecting all
  152. * child widgets, without overwriting the enabled/disabled status of the
  153. * child widget.
  154. * @param enabled if true then enabled else disabled
  155. */
  156. virtual void setParameterContainerEnabled(const bool& enabled);
  157. protected:
  158. /**
  159. * @brief Get the QUiLoader for instantiating widgets.
  160. * @return The QUiLoader.
  161. *
  162. * Override this method to provide your own QUiLoader sub-class for application-specific
  163. * customization of certain widgets.
  164. *
  165. * @see ctkCmdLineModuleQtUiLoader
  166. */
  167. virtual QUiLoader* uiLoader() const;
  168. /**
  169. * @brief Get XSL transform used to transfrom the module XML description to a Qt .ui file.
  170. * @return The XSL transform.
  171. *
  172. * Override this method to either customize the default transformation or completely provide
  173. * your own.
  174. *
  175. * @see ctkCmdLineModuleXslTransform
  176. */
  177. virtual ctkCmdLineModuleXslTransform* xslTransform() const;
  178. /**
  179. * @brief Get the value of the given parameter using the given property name.
  180. * @param parameter The parameter name.
  181. * @param propertyName The property name from which to get the value.
  182. * @return The parameter value for the given property name.
  183. *
  184. * If \c propertyName is empty, this method returns the value of the property used store the values
  185. * for the DisplayRole role.
  186. *
  187. * Sub-classes can use this method to retrieve values for custom roles.
  188. */
  189. QVariant customValue(const QString& parameter, const QString& propertyName = QString()) const;
  190. /**
  191. * @brief Set the value of the given parameter to \c value using the given property name.
  192. * @param parameter The parameter name.
  193. * @param value The new value.
  194. * @param propertyName The property name for which to set the value.
  195. *
  196. * If \c propertyName is empty, this method sets the value of the property used store the values
  197. * for the DisplayRole role.
  198. *
  199. * Sub-classes can use this method to set values for custom roles.
  200. */
  201. void setCustomValue(const QString& parameter, const QVariant& value, const QString& propertyName = QString()) ;
  202. private:
  203. QScopedPointer<ctkCmdLineModuleFrontendQtGuiPrivate> d;
  204. };
  205. #endif // CTKCMDLINEMODULEFRONTENDQTGUI_H