ctkCmdLineModuleFrontend.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 CTKCMDLINEMODULEFRONTEND_H
  16. #define CTKCMDLINEMODULEFRONTEND_H
  17. #include "ctkCommandLineModulesCoreExport.h"
  18. #include <QObject>
  19. template<class K, class V> class QHash;
  20. class QUrl;
  21. class ctkCmdLineModuleFuture;
  22. class ctkCmdLineModuleReference;
  23. class ctkCmdLineModuleParameter;
  24. struct ctkCmdLineModuleFrontendPrivate;
  25. /**
  26. * \class ctkCmdLineModuleFrontend
  27. * \brief Abstract base class for all front-end command
  28. * line module implementations.
  29. * \ingroup CommandLineModulesCore
  30. * \see ctkCmdLineModuleFrontendQtGui
  31. * \see ctkCmdLineModuleFrontendQtWebKit
  32. */
  33. class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleFrontend : public QObject
  34. {
  35. Q_OBJECT
  36. public:
  37. enum ParameterValueRole {
  38. /**
  39. * Data returned using this role must not be of any type not supported by
  40. * QVariant by default. For complex parameter types (like file, image,
  41. * geometry, etc.) the data must be convertible to a QString pointing
  42. * to a local resource.
  43. */
  44. LocalResourceRole = 0,
  45. /**
  46. * This role can be used in custom frontends to return a QVariant
  47. * containing for example an in-memory representation of a complex object.
  48. * One can then either convert the in-memory representation to a local
  49. * resource before running a module such that arbitrary backends relying on
  50. * the LocalResourceRole can process the data. Or one creates a custom
  51. * backend which knows how to handle QVariants returned by this role.
  52. */
  53. UserRole = 8
  54. };
  55. enum ParameterFilter {
  56. Input = 0x01,
  57. Output = 0x02,
  58. All = Input | Output
  59. };
  60. Q_DECLARE_FLAGS(ParameterFilters, ParameterFilter)
  61. ~ctkCmdLineModuleFrontend();
  62. /**
  63. * @brief Returns the GUI representation, currently supporting only
  64. * QObject subclasses.
  65. * @return The GUI that can then be embeded in an applicaiton
  66. * window for instance.
  67. */
  68. virtual QObject* guiHandle() const = 0;
  69. /**
  70. * @brief GUIs will need to be able to read parameters,
  71. * here we retrieve by role.
  72. * @return QVariant
  73. * @see ParameterValueRole
  74. */
  75. virtual QVariant value(const QString& parameter,
  76. int role = LocalResourceRole) const = 0;
  77. /**
  78. * @brief Set the value of a certain parameters
  79. * @param parameter The name of the parameter, as defined in the XML.
  80. * @param value The value for that parameter.
  81. */
  82. virtual void setValue(const QString& parameter, const QVariant& value) = 0;
  83. /**
  84. * @brief Return the ctkCmdLineModuleFuture, derived from QFuture to
  85. * provide asynchronous processing.
  86. * @see ctkCmdLineModuleFuture
  87. */
  88. virtual ctkCmdLineModuleFuture future() const;
  89. /**
  90. * @brief Returns a QUrl to define the location of the module that is run.
  91. *
  92. * For a local process this may be the file location of the command
  93. * line module. For other implementations, such as a web-service,
  94. * this could be a web URL.
  95. *
  96. * @return QUrl A resource independent URL defining where the module is.
  97. */
  98. QUrl location() const;
  99. /**
  100. * @brief Returns a ctkCmdLineModuleReference value object that refers
  101. * and provides access to the module.
  102. * @return ctkCmdLineModuleReference
  103. */
  104. ctkCmdLineModuleReference moduleReference() const;
  105. /**
  106. * @brief Returns a list of all valid parameter names.
  107. */
  108. virtual QList<QString> parameterNames() const;
  109. /**
  110. * @brief Returns a map of parameter names and values.
  111. */
  112. virtual QHash<QString,QVariant> values() const;
  113. /**
  114. * @brief Enables the parameter values to be set.
  115. */
  116. virtual void setValues(const QHash<QString,QVariant>& values);
  117. /**
  118. * @brief Indicates if the underlying process is currently active.
  119. * @return true if running and false otherwise.
  120. */
  121. bool isRunning() const;
  122. /**
  123. * @brief Indicates if the underlying process is currently paused.
  124. * @return true if paused and false otherwise.
  125. */
  126. bool isPaused() const;
  127. Q_SIGNAL void valueChanged(const QString& parameter, const QVariant& value);
  128. // convenience methods
  129. /**
  130. * @brief Useful method to return subsets of parameter objects, searhing
  131. * by type for example "image" and filter for example "input"/"output".
  132. * @param type The type of parameter, as defined in the XML element.
  133. * @param filters flag to define whether we want input/output.
  134. * @return QList of ctkCmdLineModuleParameter depending on type and filters.
  135. * @see ParameterFilter
  136. */
  137. QList<ctkCmdLineModuleParameter> parameters(
  138. const QString& type = QString(),
  139. ParameterFilters filters = All);
  140. void resetValues();
  141. protected:
  142. /**
  143. * @brief Constructor.
  144. */
  145. ctkCmdLineModuleFrontend(const ctkCmdLineModuleReference& moduleRef);
  146. /**
  147. * @brief Sets the ctkCmdLineModuleFuture which effectively
  148. * contains the backend that is run.
  149. */
  150. void setFuture(const ctkCmdLineModuleFuture& future);
  151. private:
  152. Q_DISABLE_COPY(ctkCmdLineModuleFrontend)
  153. friend class ctkCmdLineModuleManager;
  154. friend class ctkCmdLineModulePrivate;
  155. QScopedPointer<ctkCmdLineModuleFrontendPrivate> d;
  156. };
  157. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkCmdLineModuleFrontend::ParameterFilters)
  158. #endif // CTKCMDLINEMODULEFRONTEND_H