Просмотр исходного кода

Added convenience methods for retrieving and resetting parameters.

Sascha Zelzer лет назад: 12
Родитель
Сommit
21f0d8497f

+ 38 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleFrontend.cpp

@@ -128,3 +128,41 @@ void ctkCmdLineModuleFrontend::setValues(const QHash<QString, QVariant> &values)
     setValue(iter.key(), iter.value());
   }
 }
+
+//----------------------------------------------------------------------------
+QList<ctkCmdLineModuleParameter> ctkCmdLineModuleFrontend::parameters(const QString &type, ParameterFilters filters)
+{
+  ctkCmdLineModuleDescription description = this->moduleReference().description();
+  QList<ctkCmdLineModuleParameter> parameters;
+  foreach(ctkCmdLineModuleParameterGroup group, description.parameterGroups())
+  {
+    foreach(ctkCmdLineModuleParameter param, group.parameters())
+    {
+      if (filters.testFlag(Input) &&
+          (param.channel().isEmpty() || param.channel().compare("input", Qt::CaseInsensitive)))
+      {
+        if (type.isEmpty() || param.tag().compare(type, Qt::CaseInsensitive))
+        {
+          parameters << param;
+        }
+      }
+      if (filters.testFlag(Output) && param.channel().compare("output", Qt::CaseInsensitive))
+      {
+        if (type.isEmpty() || param.tag().compare(type, Qt::CaseInsensitive))
+        {
+          parameters << param;
+        }
+      }
+    }
+  }
+  return parameters;
+}
+
+//----------------------------------------------------------------------------
+void ctkCmdLineModuleFrontend::resetValues()
+{
+  foreach(ctkCmdLineModuleParameter param, this->parameters())
+  {
+    this->setValue(param.name(), param.defaultValue());
+  }
+}

+ 7 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleFrontend.h

@@ -31,6 +31,7 @@ class QUrl;
 
 class ctkCmdLineModuleFuture;
 class ctkCmdLineModuleReference;
+class ctkCmdLineModuleParameter;
 class ctkCmdLineModuleFrontendPrivate;
 
 /**
@@ -91,6 +92,12 @@ public:
 
   Q_SIGNAL void valueChanged(const QString& parameter, const QVariant& value);
 
+  // convenience methods
+
+  QList<ctkCmdLineModuleParameter> parameters(const QString& type = QString(), ParameterFilters filters = All);
+
+  void resetValues();
+
 protected:
 
   ctkCmdLineModuleFrontend(const ctkCmdLineModuleReference& moduleRef);