ctkCmdLineModuleFrontendQtGui.h 12 KB

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