/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#ifndef CTKCMDLINEMODULEFRONTENDQTGUI_H
#define CTKCMDLINEMODULEFRONTENDQTGUI_H
#include "ctkCmdLineModuleFrontend.h"
#include "ctkCommandLineModulesFrontendQtGuiExport.h"
class ctkCmdLineModuleReference;
class ctkCmdLineModuleXslTransform;
class QUiLoader;
class QWidget;
struct ctkCmdLineModuleFrontendQtGuiPrivate;
/**
* \class ctkCmdLineModuleFrontendQtGui
* \brief A Qt based implementation of the module front end.
* \ingroup CommandLineModulesFrontendQtGui_API
*
* This class is able to generate a Qt widgets based GUI from the XML description of
* a given module. It uses a customizable XML stylesheet to transform the raw XML description
* into a .ui file which is fed into a QUiLoader to generate the GUI at runtime.
*
* Sub-classes have several possibilities to customize the generated GUI:
*
* - Override uiLoader() and provide your own QUiLoader or ctkCmdLineModuleQtUiLoader sub-class
* which knows how to instantiate widget types (see the table below for widget class names).
* - Bind variables to the ctkCmdLineModuleXslTranform object returned by xslTransform() to
* customize widget class names and property names. This may require you to provide a Qt Designer
* plug-in for your custom widget classes if you do not implement your own widget instantiation
* code in a custom QUiLoader.
* - Advanced: Override fragments of the XML stylesheet using ctkCmdLineModuleXslTranform::setXslExtraTransformation()
*
*
* All widget classes are assumed to expose a readable and writable QObject property for storing and
* retrieving current front-end values via the DisplayRole role.
*
* The following table lists the available XSL parameters (setable via ctkCmdLineModuleXslTransform::bindVariable()),
* and their default values for all parameter types and created container widgets:
*
* \htmlonly
*
*
* Parameter Type | XSL Parameters |
* Widget Class | Default | Property Name (DisplayRole) | Default |
* boolean | booleanWidget | QCheckBox | booleanValueProperty | checked |
* integer | integerWidget | QSpinBox | integerValueProperty | value |
* float | floatingWidget | QDoubleSpinBox | floatValueProperty | value |
* double | floatingWidget | QDoubleSpinBox | floatValueProperty | value |
* string | vectorWidget | QLineEdit | vectorValueProperty | text |
* integer-vector | vectorWidget | QLineEdit | vectorValueProperty | text |
* float-vector | vectorWidget | QLineEdit | vectorValueProperty | value |
* double-vector | vectorWidget | QLineEdit | vectorValueProperty | value |
* string-vector | vectorWidget | QLineEdit | vectorValueProperty | value |
* integer-enumeration | enumWidget | QComboBox (ctkCmdLineModuleQtUiLoader instantiates a custom private QComboBox sub-class) | enumerationValueProperty | currentEnumeration |
* float-enumeration | enumWidget | QComboBox | enumerationValueProperty | currentEnumeration |
* double-enumeration | enumWidget | QComboBox | enumerationValueProperty | currentEnumeration |
* string-enumeration | enumWidget | QComboBox | enumerationValueProperty | currentEnumeration |
* file (input channel) | fileInputWidget | ctkPathLineEdit | fileInputValueProperty | currentPath |
* file (output channel) | fileOutputWidget | ctkPathLineEdit | fileOutputValueProperty | currentPath |
* geometry (input channel) | fileInputWidget | ctkPathLineEdit | geometryInputValueProperty | currentPath |
* geometry (output channel) | fileOutputWidget | ctkPathLineEdit | geometryOutputValueProperty | currentPath |
* directory | directoryWidget | ctkPathLineEdit | directoryValueProperty | currentPath |
* point | pointWidget | ctkCoordinatesWidget | pointValueProperty | coordinates |
* region | pointWidget | ctkCoordinatesWidget | pointValueProperty | coordinates |
* image (input channel) | imageInputWidget | ctkPathLineEdit | imageInputValueProperty | currentPath |
* image (output channel) | imageOutputWidget | ctkPathLineEdit | imageOutputValueProperty | currentPath |
* [main container] | executableWidget | QWidget | n/a | n/a |
* [group container] | parametersWidget | ctkCollapsibleGroupBox | n/a | n/a |
* [unknown type] | unsupportedWidget | QLabel | n/a | n/a |
*
* \endhtmlonly
*
* In addition, for image and file, input and output, it is normally necessary to define a set property within
* the generated .ui file to contain various configuration flags to pass to the widget. For example, ctkPathLineEdit
* has a "filters" property that can be used to configure the dialog behaviour when the browse button is pressed.
* The following XSL parameters are available to create a set property and are also setable via
* ctkCmdLineModuleXslTransform::bindVariable(). If the empty string is bound to the Set Property Name,
* the set property will be omitted.
*
* \htmlonly
*
*
* Parameter Type | XSL Parameters |
* Set Property Name | Default | Set Property Value | Default |
* file (input channel) | fileInputSetProperty | filters | fileInputSetValue | ctkPathLineEdit::Files|ctkPathLineEdit::Readable |
* file (output channel) | fileOutputSetProperty | filters | fileOutputSetValue | ctkPathLineEdit::Files|ctkPathLineEdit::Writable |
* image (input channel) | imageInputSetProperty | filters | imageInputSetProperty | ctkPathLineEdit::Files|ctkPathLineEdit::Readable |
* image (output channel) | imageOutputSetProperty | filters | imageOutputSetProperty | ctkPathLineEdit::Files|ctkPathLineEdit::Writable |
*
* \endhtmlonly
*/
class CTK_CMDLINEMODULEQTGUI_EXPORT ctkCmdLineModuleFrontendQtGui : public ctkCmdLineModuleFrontend
{
public:
ctkCmdLineModuleFrontendQtGui(const ctkCmdLineModuleReference& moduleRef);
virtual ~ctkCmdLineModuleFrontendQtGui();
// ctkCmdLineModuleFrontend overrides
/**
* @brief Create the actual Qt GUI.
* @return The parent widget for the created GUI.
*
* The returned object is either NULL or can always be casted to QWidget*.
*/
virtual QObject* guiHandle() const;
/**
* @brief Retrieves the current parameter value using the default QObject property for
* parameter values.
* @param parameter
* @param role
*
* This implementation ignores the role
argument and always returns
* the value held by the default property, which usually correspongs to the
* DisplayRole.
*
* @see ctkCmdLineModuleFrontend::value()
*/
virtual QVariant value(const QString& parameter, int role = LocalResourceRole) const;
/**
* @brief Sets the parameter value.
* @param parameter
* @param value
* @param role
*
* This implementation does nothing if the role
parameter does not equal
* ctkCmdLineModuleFrontend::DisplayRole. If it does, it sets the value of the default
* QObject property to the provided value.
*
* @see ctkCmdLineModuleFrontend::setValue()
*/
virtual void setValue(const QString& parameter, const QVariant& value, int role = DisplayRole);
virtual QList parameterNames() const;
/**
* \brief There is a container QWidget within each group box, so you can
* set the container widget to enabled/disabled, thereby affecting all
* child widgets, without overwriting the enabled/disabled status of the
* child widget.
* @param enabled if true then enabled else disabled
*/
virtual void setParameterContainerEnabled(const bool& enabled);
protected:
/**
* @brief Get the QUiLoader for instantiating widgets.
* @return The QUiLoader.
*
* Override this method to provide your own QUiLoader sub-class for application-specific
* customization of certain widgets.
*
* @see ctkCmdLineModuleQtUiLoader
*/
virtual QUiLoader* uiLoader() const;
/**
* @brief Get XSL transform used to transfrom the module XML description to a Qt .ui file.
* @return The XSL transform.
*
* Override this method to either customize the default transformation or completely provide
* your own.
*
* @see ctkCmdLineModuleXslTransform
*/
virtual ctkCmdLineModuleXslTransform* xslTransform() const;
/**
* @brief Get the value of the given parameter using the given property name.
* @param parameter The parameter name.
* @param propertyName The property name from which to get the value.
* @return The parameter value for the given property name.
*
* If \c propertyName is empty, this method returns the value of the property used store the values
* for the DisplayRole role.
*
* Sub-classes can use this method to retrieve values for custom roles.
*/
QVariant customValue(const QString& parameter, const QString& propertyName = QString()) const;
/**
* @brief Set the value of the given parameter to \c value using the given property name.
* @param parameter The parameter name.
* @param value The new value.
* @param propertyName The property name for which to set the value.
*
* If \c propertyName is empty, this method sets the value of the property used store the values
* for the DisplayRole role.
*
* Sub-classes can use this method to set values for custom roles.
*/
void setCustomValue(const QString& parameter, const QVariant& value, const QString& propertyName = QString()) ;
private:
QScopedPointer d;
};
#endif // CTKCMDLINEMODULEFRONTENDQTGUI_H