Przeglądaj źródła

Merge branch 'cli-module-support' into dah

Ivo Wolf 13 lat temu
rodzic
commit
b6537faef8
33 zmienionych plików z 658 dodań i 694 usunięć
  1. 9 7
      Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.cpp
  2. 2 2
      Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.h
  3. 3 0
      Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp
  4. 5 6
      Libs/CommandLineModules/Core/CMakeLists.txt
  5. 1 1
      Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.cpp
  6. 2 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.h
  7. 21 21
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.cpp
  8. 93 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleFuture.h
  9. 105 73
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.cpp
  10. 19 5
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.h
  11. 3 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.h
  12. 0 2
      Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp
  13. 3 1
      Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h
  14. 0 266
      Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.cpp
  15. 2 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameter.h
  16. 5 3
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroup.h
  17. 11 18
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner.cpp
  18. 0 59
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.cpp
  19. 0 56
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.h
  20. 0 138
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.h
  21. 6 8
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner_p.h
  22. 1 1
      Libs/CommandLineModules/Core/ctkCmdLineModuleReference.cpp
  23. 3 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleReference.h
  24. 2 2
      Libs/CommandLineModules/Core/ctkCmdLineModuleReferencePrivate.cpp
  25. 3 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXmlException.h
  26. 3 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXmlValidator.h
  27. 3 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.h
  28. 18 0
      Libs/CommandLineModules/Documentation/CTKCommandLineModules.dox
  29. 2 0
      Libs/CommandLineModules/QtGui/CMakeLists.txt
  30. 45 5
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui.cpp
  31. 4 1
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui_p.h
  32. 258 0
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp
  33. 26 19
      Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.h

+ 9 - 7
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.cpp

@@ -26,8 +26,9 @@
 #include <ctkCmdLineModuleManager.h>
 #include <ctkCmdLineModuleInstance.h>
 #include <ctkCmdLineModuleInstanceFactoryQtGui.h>
-#include <ctkCmdLineModuleProcessFuture.h>
+//#include <ctkCmdLineModuleFuture.h>
 
+#include <QDebug>
 
 ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   QMainWindow(parent),
@@ -67,9 +68,6 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
 {
   qDebug() << "Creating module command line...";
 
-//  QStringList cmdLineArgs = ctkCmdLineModuleManager::createCommandLineArgs(ui->mainTabWidget->currentWidget());
-//  qDebug() << cmdLineArgs;
-
   ctkCmdLineModuleInstance* moduleInstance = mapTabToModuleRef[ui->mainTabWidget->currentIndex()];
   if (!moduleInstance)
   {
@@ -77,7 +75,11 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
     return;
   }
 
-  ctkCmdLineModuleProcessFuture future = moduleInstance->run();
+  QStringList cmdLineArgs = moduleInstance->commandLineArguments();
+  qDebug() << cmdLineArgs;
+
+
+  //ctkCmdLineModuleProcessFuture future = moduleInstance->run();
   //future.waitForFinished();
   //qDebug() << future.standardOutput();
 
@@ -89,8 +91,8 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
 void ctkCLModuleExplorerMainWindow::futureFinished()
 {
   qDebug() << "*** Future finished";
-  qDebug() << "stdout:" << futureWatcher.future().standardOutput();
-  qDebug() << "stderr:" << futureWatcher.future().standardError();
+  //qDebug() << "stdout:" << futureWatcher.future().standardOutput();
+  //qDebug() << "stderr:" << futureWatcher.future().standardError();
 }
 
 //ctkCmdLineModuleReference ctkCLModuleExplorerMainWindow::moduleReference(int tabIndex)

+ 2 - 2
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.h

@@ -24,7 +24,7 @@
 
 #include <ctkCmdLineModuleManager.h>
 #include <ctkCmdLineModuleReference.h>
-#include <ctkCmdLineModuleProcessFuture.h>
+//#include <ctkCmdLineModuleFuture.h>
 
 #include <QMainWindow>
 #include <QHash>
@@ -65,7 +65,7 @@ private:
 
   QHash<int, ctkCmdLineModuleInstance*> mapTabToModuleRef;
 
-  ctkCmdLineModuleProcessFutureWatcher futureWatcher;
+  //ctkCmdLineModuleProcessFutureWatcher futureWatcher;
 };
 
 #endif // CTKCLIPLUGINEXPLORERMAINWINDOW_H

+ 3 - 0
Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp

@@ -25,6 +25,9 @@
 #include <QFile>
 #include <QBuffer>
 #include <QWidget>
+#include <QProcess>
+
+#include <QDebug>
 
 #include <QtXmlPatterns/QXmlQuery>
 #include <QtUiTools/QUiLoader>

+ 5 - 6
Libs/CommandLineModules/Core/CMakeLists.txt

@@ -16,19 +16,18 @@ set(KIT_export_directive "CTK_CMDLINEMODULECORE_EXPORT")
 set(KIT_SRCS
   ctkCmdLineModuleDescription.cpp
   ctkCmdLineModuleDescriptionPrivate.h
+  ctkCmdLineModuleFuture.h
+  #ctkCmdLineModuleFuture.cpp
   ctkCmdLineModuleInstance.cpp
   ctkCmdLineModuleInstanceFactory.cpp
   ctkCmdLineModuleManager.cpp
-  ctkCmdLineModuleObjectHierarchyReader.cpp
   ctkCmdLineModuleParameter.cpp
   ctkCmdLineModuleParameterPrivate.cpp
   ctkCmdLineModuleParameterGroup.cpp
   ctkCmdLineModuleParameterGroupPrivate.h
   ctkCmdLineModuleParameterParsers_p.h
-  ctkCmdLineModuleProcessException.cpp
-  ctkCmdLineModuleProcessFuture.cpp
-  ctkCmdLineModuleProcessRunner.cpp
-  ctkCmdLineModuleProcessRunner_p.h
+  #ctkCmdLineModuleProcess.cpp
+  ctkCmdLineModuleProcess_p.h
   ctkCmdLineModuleReference.cpp
   ctkCmdLineModuleReferencePrivate.cpp
   ctkCmdLineModuleXmlException.cpp
@@ -43,7 +42,7 @@ set(KIT_SRCS
 # Headers that should run through moc
 set(KIT_MOC_SRCS
   ctkCmdLineModuleInstance.h
-  ctkCmdLineModuleProcessRunner_p.h
+  #ctkCmdLineModuleProcess_p.h
 )
 
 # UI files

+ 1 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.cpp

@@ -31,7 +31,7 @@ limitations under the License.
 
 //----------------------------------------------------------------------------
 ctkCmdLineModuleDescription::ctkCmdLineModuleDescription()
-  : d(new ctkCmdLineModuleDescriptionPrivate)
+  : d(new ctkCmdLineModuleDescriptionPrivate())
 {
 }
 

+ 2 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.h

@@ -35,6 +35,8 @@ class ctkCmdLineModuleParameterGroup;
 class ctkCmdLineModuleParameter;
 
 /**
+ * \ingroup CommandLineModulesCore
+ *
  * Description of the parameters of a command line module.
  *
  * The parameters can be used for automated GUI generation or execution

+ 21 - 21
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.cpp

@@ -19,11 +19,11 @@
   
 =============================================================================*/
 
-#include "ctkCmdLineModuleProcessFuture.h"
+#include "ctkCmdLineModuleFuture.h"
 
-struct ctkCmdLineModuleProcessFutureInterfacePrivate
+struct ctkCmdLineModuleFutureInterfacePrivate
 {
-  ctkCmdLineModuleProcessFutureInterfacePrivate()
+  ctkCmdLineModuleFutureInterfacePrivate()
     : refCount(1), _exitCode(0), _exitStatus(QProcess::NormalExit),
       _processError(QProcess::UnknownError)
   {}
@@ -38,20 +38,20 @@ struct ctkCmdLineModuleProcessFutureInterfacePrivate
   QString _stdErr;
 };
 
-ctkCmdLineModuleProcessFutureInterface::QFutureInterface(State initialState)
-  : QFutureInterfaceBase(initialState), d(new ctkCmdLineModuleProcessFutureInterfacePrivate)
+ctkCmdLineModuleFutureInterface::QFutureInterface(State initialState)
+  : QFutureInterfaceBase(initialState), d(new ctkCmdLineModuleFutureInterfacePrivate)
 { }
 
-ctkCmdLineModuleProcessFutureInterface::QFutureInterface(const ctkCmdLineModuleProcessFutureInterface& other)
+ctkCmdLineModuleFutureInterface::QFutureInterface(const ctkCmdLineModuleFutureInterface& other)
   : QFutureInterfaceBase(other), d(other.d)
 {
   d->refCount.ref();
 }
 
-ctkCmdLineModuleProcessFutureInterface ctkCmdLineModuleProcessFutureInterface::canceledResult()
-{ return ctkCmdLineModuleProcessFutureInterface(State(Started | Finished | Canceled)); }
+ctkCmdLineModuleFutureInterface ctkCmdLineModuleFutureInterface::canceledResult()
+{ return ctkCmdLineModuleFutureInterface(State(Started | Finished | Canceled)); }
 
-ctkCmdLineModuleProcessFutureInterface& ctkCmdLineModuleProcessFutureInterface::operator=(const ctkCmdLineModuleProcessFutureInterface& other)
+ctkCmdLineModuleFutureInterface& ctkCmdLineModuleFutureInterface::operator=(const ctkCmdLineModuleFutureInterface& other)
 {
   QFutureInterfaceBase::operator=(other);
   other.d->refCount.ref();
@@ -60,38 +60,38 @@ ctkCmdLineModuleProcessFutureInterface& ctkCmdLineModuleProcessFutureInterface::
   return *this;
 }
 
-int ctkCmdLineModuleProcessFutureInterface::exitCode() const
+int ctkCmdLineModuleFutureInterface::exitCode() const
 { QMutexLocker lock(this->mutex()); return d->_exitCode; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportExitCode(int code)
+void ctkCmdLineModuleFutureInterface::reportExitCode(int code)
 { QMutexLocker lock(this->mutex()); d->_exitCode = code; }
 
-QProcess::ExitStatus ctkCmdLineModuleProcessFutureInterface::exitStatus() const
+QProcess::ExitStatus ctkCmdLineModuleFutureInterface::exitStatus() const
 { QMutexLocker lock(this->mutex()); return d->_exitStatus; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportExitStatus(QProcess::ExitStatus status)
+void ctkCmdLineModuleFutureInterface::reportExitStatus(QProcess::ExitStatus status)
 { QMutexLocker lock(this->mutex()); d->_exitStatus = status; }
 
-QProcess::ProcessError ctkCmdLineModuleProcessFutureInterface::error() const
+QProcess::ProcessError ctkCmdLineModuleFutureInterface::error() const
 { QMutexLocker lock(this->mutex()); return d->_processError; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportProcessError(QProcess::ProcessError procErr)
+void ctkCmdLineModuleFutureInterface::reportProcessError(QProcess::ProcessError procErr)
 { QMutexLocker lock(this->mutex()); d->_processError = procErr; }
 
-QString ctkCmdLineModuleProcessFutureInterface::errorString() const
+QString ctkCmdLineModuleFutureInterface::errorString() const
 { QMutexLocker lock(this->mutex()); return d->_errorString; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportErrorString(const QString& errorStr)
+void ctkCmdLineModuleFutureInterface::reportErrorString(const QString& errorStr)
 { QMutexLocker lock(this->mutex()); d->_errorString = errorStr; }
 
-QString ctkCmdLineModuleProcessFutureInterface::standardOutput() const
+QString ctkCmdLineModuleFutureInterface::standardOutput() const
 { QMutexLocker lock(this->mutex()); return d->_stdOut; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportStandardOutput(const QString& stdOut)
+void ctkCmdLineModuleFutureInterface::reportStandardOutput(const QString& stdOut)
 { QMutexLocker lock(this->mutex()); d->_stdOut = stdOut; }
 
-QString ctkCmdLineModuleProcessFutureInterface::standardError() const
+QString ctkCmdLineModuleFutureInterface::standardError() const
 { QMutexLocker lock(this->mutex()); return d->_stdErr; }
 
-void ctkCmdLineModuleProcessFutureInterface::reportStandardError(const QString& stdErr)
+void ctkCmdLineModuleFutureInterface::reportStandardError(const QString& stdErr)
 { QMutexLocker lock(this->mutex()); d->_stdErr = stdErr; }

+ 93 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleFuture.h

@@ -0,0 +1,93 @@
+/*=============================================================================
+  
+  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 CTKCMDLINEMODULEFUTURE_H
+#define CTKCMDLINEMODULEFUTURE_H
+
+#include <ctkCommandLineModulesCoreExport.h>
+
+//#include <QFutureInterface>
+//#include <QFutureWatcher>
+#include <QProcess>
+
+/**
+ * \ingroup CommandLineModulesCore
+ */
+class ctkCmdLineModuleFuture
+{
+
+public:
+
+  ctkCmdLineModuleFuture()
+    : d(ctkCmdLineModuleFutureInterface::canceledResult())
+  { }
+
+  explicit ctkCmdLineModuleFuture(const ctkCmdLineModuleProcess& p) // internal
+    : d(*p)
+  { }
+
+  ctkCmdLineModuleFuture(const ctkCmdLineModuleFuture &other)
+    : d(other.d)
+  { }
+
+  ~ctkCmdLineModuleFuture()
+  { }
+
+  ctkCmdLineModuleFuture& operator=(const ctkCmdLineModuleFuture& other);
+  bool operator==(const ctkCmdLineModuleFuture& other) const { return (d == other.d); }
+  bool operator!=(const ctkCmdLineModuleFuture& other) const { return (d != other.d); }
+
+  void cancel() { d.cancel(); }
+  bool isCanceled() const { return d.isCanceled(); }
+
+  bool isStarted() const { return d.isStarted(); }
+  bool isFinished() const { return d.isFinished(); }
+  bool isRunning() const { return d.isRunning(); }
+
+  int exitCode() const { return d.exitCode(); }
+  int exitStatus() const { return d.exitStatus(); }
+  QProcess::ProcessError error() const { return d.error(); }
+  QString errorString() const { return d.errorString(); }
+
+  QString standardOutput() const { return d.standardOutput(); }
+  QString standardError() const { return d.standardError(); }
+
+  int progressValue() const { return d.progressValue(); }
+  int progressMinimum() const { return d.progressMinimum(); }
+  int progressMaximum() const { return d.progressMaximum(); }
+  QString progressText() const { return d.progressText(); }
+  void waitForFinished() { d.waitForFinished(); }
+
+private:
+
+  friend class ctkCmdLineModuleFutureWatcher;
+
+  mutable ctkCmdLineModuleProcess d;
+};
+
+
+inline ctkCmdLineModuleFuture& ctkCmdLineModuleFuture::operator=(const ctkCmdLineModuleFuture& other)
+{
+  d = other.d;
+  return *this;
+}
+
+#endif // CTKCMDLINEMODULEFUTURE_H

+ 105 - 73
Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.cpp

@@ -20,24 +20,17 @@
 =============================================================================*/
 
 #include "ctkCmdLineModuleInstance.h"
+#include "ctkCmdLineModuleDescription.h"
+#include "ctkCmdLineModuleParameter.h"
+#include "ctkCmdLineModuleParameterGroup.h"
 #include "ctkCmdLineModuleReference.h"
-#include "ctkCmdLineModuleObjectHierarchyReader.h"
-#include "ctkCmdLineModuleObjectHierarchyReader.h"
-#include "ctkCmdLineModuleProcessRunner_p.h"
+#include "ctkCmdLineModuleProcess_p.h"
 
 #include "ctkException.h"
 
 #include <QStringList>
 #include <QDebug>
 
-namespace {
-
-QString normalizeFlag(const QString& flag)
-{
-  return flag.trimmed().remove(QRegExp("^-*"));
-}
-
-}
 
 struct ctkCmdLineModuleInstancePrivate
 {
@@ -48,59 +41,15 @@ struct ctkCmdLineModuleInstancePrivate
 
   }
 
-  QStringList createCommandLineArgs()
+  QString normalizeFlag(const QString& flag)
   {
-    ctkCmdLineModuleObjectHierarchyReader reader(q->parameterValueModel());
-
-    QStringList cmdLineArgs;
-    QHash<int, QString> indexedArgs;
-    while(reader.readNextParameter())
-    {
-      if (reader.index() > -1)
-      {
-        indexedArgs.insert(reader.index(), reader.value());
-      }
-      else
-      {
-        QString argFlag;
-        if (reader.longFlag().isEmpty())
-        {
-          argFlag = QString("-") + normalizeFlag(reader.flag());
-        }
-        else
-        {
-          argFlag = QString("--") + normalizeFlag(reader.longFlag());
-        }
-
-        QStringList args;
-        if (reader.isMultiple())
-        {
-          args = reader.value().split(',', QString::SkipEmptyParts);
-        }
-        else
-        {
-          args.push_back(reader.value());
-        }
-
-        foreach(QString arg, args)
-        {
-          cmdLineArgs << argFlag << arg;
-        }
-      }
-    }
-
-    QList<int> indexes = indexedArgs.keys();
-    qSort(indexes.begin(), indexes.end());
-    foreach(int index, indexes)
-    {
-      cmdLineArgs << indexedArgs[index];
-    }
-
-    return cmdLineArgs;
+    return flag.trimmed().remove(QRegExp("^-*"));
   }
 
   ctkCmdLineModuleReference ModuleReference;
 
+  QList<QString> ParameterNames;
+
 private:
 
   ctkCmdLineModuleInstance* q;
@@ -117,32 +66,115 @@ ctkCmdLineModuleInstance::~ctkCmdLineModuleInstance()
 {
 }
 
-QObject *ctkCmdLineModuleInstance::parameterValueModel() const
+QList<QString> ctkCmdLineModuleInstance::parameterNames() const
 {
-  return guiHandle();
+  if (!d->ParameterNames.isEmpty()) return d->ParameterNames;
+
+  foreach (ctkCmdLineModuleParameterGroup paramGroup,
+           moduleReference().description().parameterGroups())
+  {
+    foreach (ctkCmdLineModuleParameter param, paramGroup.parameters())
+    {
+      d->ParameterNames.push_back(param.name());
+    }
+  }
+  return d->ParameterNames;
 }
 
-QVariant ctkCmdLineModuleInstance::value(const QString &parameter) const
+ctkCmdLineModuleReference ctkCmdLineModuleInstance::moduleReference() const
 {
-  throw ctkException("not implemented yet");
+  return d->ModuleReference;
 }
 
-void ctkCmdLineModuleInstance::setValue(const QString &parameter, const QVariant &value)
+QString ctkCmdLineModuleInstance::location() const
 {
-  throw ctkException("not implemented yet");
+  return d->ModuleReference.location();
 }
 
-ctkCmdLineModuleReference ctkCmdLineModuleInstance::moduleReference() const
+QStringList ctkCmdLineModuleInstance::commandLineArguments() const
 {
-  return d->ModuleReference;
+  QStringList cmdLineArgs;
+  QHash<int, QString> indexedArgs;
+
+  QHash<QString,QVariant> currentValues = values();
+  ctkCmdLineModuleDescription description = moduleReference().description();
+  QHashIterator<QString,QVariant> valuesIter(currentValues);
+  while(valuesIter.hasNext())
+  {
+    valuesIter.next();
+    ctkCmdLineModuleParameter parameter = description.parameter(valuesIter.key());
+    if (parameter.index() > -1)
+    {
+      indexedArgs.insert(parameter.index(), valuesIter.value().toString());
+    }
+    else
+    {
+      QString argFlag;
+      if (parameter.longFlag().isEmpty())
+      {
+        argFlag = QString("-") + d->normalizeFlag(parameter.flag());
+      }
+      else
+      {
+        argFlag = QString("--") + d->normalizeFlag(parameter.longFlag());
+      }
+
+      QStringList args;
+      if (parameter.multiple())
+      {
+        args = valuesIter.value().toString().split(',', QString::SkipEmptyParts);
+      }
+      else
+      {
+        args.push_back(valuesIter.value().toString());
+      }
+
+      foreach(QString arg, args)
+      {
+        cmdLineArgs << argFlag << arg;
+      }
+    }
+  }
+
+  QList<int> indexes = indexedArgs.keys();
+  qSort(indexes.begin(), indexes.end());
+  foreach(int index, indexes)
+  {
+    cmdLineArgs << indexedArgs[index];
+  }
+
+  return cmdLineArgs;
 }
 
-ctkCmdLineModuleProcessFuture ctkCmdLineModuleInstance::run() const
+struct ctkCmdLineModuleFuture {};
+
+ctkCmdLineModuleFuture ctkCmdLineModuleInstance::run() const
 {
-  // TODO: manage memory
-  QStringList args = d->createCommandLineArgs();
+//  // TODO: manage memory
+  QStringList args = commandLineArguments();
   qDebug() << args;
-  ctkCmdLineModuleProcessRunner* moduleProcess =
-      new ctkCmdLineModuleProcessRunner(d->ModuleReference.location(), args);
-  return moduleProcess->start();
+//  ctkCmdLineModuleProcessRunner* moduleProcess =
+//      new ctkCmdLineModuleProcessRunner(d->ModuleReference.location(), args);
+//  return moduleProcess->start();
+}
+
+
+QHash<QString, QVariant> ctkCmdLineModuleInstance::values() const
+{
+  QHash<QString,QVariant> result;
+  foreach(QString parameterName, parameterNames())
+  {
+    result.insert(parameterName, value(parameterName));
+  }
+  return result;
+}
+
+void ctkCmdLineModuleInstance::setValues(const QHash<QString, QVariant> &values)
+{
+  QHashIterator<QString,QVariant> iter(values);
+  while(iter.hasNext())
+  {
+    iter.next();
+    setValue(iter.key(), iter.value());
+  }
 }

+ 19 - 5
Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.h

@@ -23,13 +23,18 @@
 #define CTKCMDLINEMODULEINSTANCE_H
 
 #include "ctkCommandLineModulesCoreExport.h"
-#include "ctkCmdLineModuleProcessFuture.h"
 
 #include <QObject>
 
+template<class K, class V> class QHash;
+
+class ctkCmdLineModuleFuture;
 class ctkCmdLineModuleReference;
 class ctkCmdLineModuleInstancePrivate;
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleInstance : public QObject
 {
   Q_OBJECT
@@ -40,12 +45,21 @@ public:
 
   virtual QObject* guiHandle() const = 0;
 
-  QVariant value(const QString& parameter) const;
-  void setValue(const QString& parameter, const QVariant& value);
+  virtual QVariant value(const QString& parameter) const = 0;
+  virtual void setValue(const QString& parameter, const QVariant& value) = 0;
+
+  virtual QList<QString> parameterNames() const;
+
+  virtual QHash<QString,QVariant> values() const;
+  virtual void setValues(const QHash<QString,QVariant>& values);
 
   ctkCmdLineModuleReference moduleReference() const;
 
-  ctkCmdLineModuleProcessFuture run() const;
+  QString location() const;
+
+  QStringList commandLineArguments() const;
+
+  ctkCmdLineModuleFuture run() const;
 
   Q_SIGNAL void valueChanged(const QString& parameter, const QVariant& value);
 
@@ -53,7 +67,7 @@ protected:
 
   ctkCmdLineModuleInstance(const ctkCmdLineModuleReference& moduleRef);
 
-  virtual QObject* parameterValueModel() const;
+  //virtual QObject* parameterValueModel() const;
 
 private:
 

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.h

@@ -27,6 +27,9 @@
 class ctkCmdLineModuleInstance;
 class ctkCmdLineModuleReference;
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 struct CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleInstanceFactory
 {
   virtual ~ctkCmdLineModuleInstanceFactory();

+ 0 - 2
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp

@@ -22,8 +22,6 @@
 #include "ctkCmdLineModuleManager.h"
 
 #include "ctkCmdLineModuleXmlValidator.h"
-#include "ctkCmdLineModuleObjectHierarchyReader.h"
-#include "ctkCmdLineModuleProcessRunner_p.h"
 #include "ctkCmdLineModuleReference.h"
 #include "ctkCmdLineModuleReferencePrivate.h"
 #include "ctkCmdLineModuleInstanceFactory.h"

+ 3 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h

@@ -33,7 +33,9 @@ class ctkCmdLineModuleInstance;
 class ctkCmdLineModuleReference;
 class ctkCmdLineModuleManagerPrivate;
 
-/// The methods in this class are for playing around... no API design yet
+/**
+ * \ingroup CommandLineModulesCore
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleManager
 {
 

+ 0 - 266
Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.cpp

@@ -1,266 +0,0 @@
-/*=============================================================================
-  
-  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.
-  
-=============================================================================*/
-
-#include "ctkCmdLineModuleObjectHierarchyReader.h"
-
-#include <QObject>
-#include <QStack>
-#include <QVariant>
-
-namespace {
-
-static QString PREFIX_EXECUTABLE = "executable:";
-static QString PREFIX_PARAMETER_GROUP = "paramGroup:";
-static QString PREFIX_PARAMETER = "parameter:";
-
-}
-
-class ctkCmdLineModuleObjectHierarchyReaderPrivate
-{
-public:
-
-  ctkCmdLineModuleObjectHierarchyReaderPrivate(QObject* root)
-    : rootObject(root), currentObject(0), currentToken(ctkCmdLineModuleObjectHierarchyReader::NoToken),
-      atEnd(false)
-  {
-  }
-
-  QVariant property(const QString& propName) const
-  {
-    if (currentObject == 0) return QString();
-
-    QString prefixedName;
-    switch(currentToken)
-    {
-    case ctkCmdLineModuleObjectHierarchyReader::Executable: prefixedName = PREFIX_EXECUTABLE + propName;
-    case ctkCmdLineModuleObjectHierarchyReader::ParameterGroup: prefixedName = PREFIX_PARAMETER_GROUP + propName;
-    case ctkCmdLineModuleObjectHierarchyReader::Parameter: prefixedName = PREFIX_PARAMETER + propName;
-    default: ;
-    }
-
-    return currentObject->property(qPrintable(prefixedName));
-  }
-
-  ctkCmdLineModuleObjectHierarchyReader::TokenType token(QObject* obj)
-  {
-    if (obj == 0) return ctkCmdLineModuleObjectHierarchyReader::NoToken;
-    QString name = obj->objectName();
-    if (name.startsWith(PREFIX_EXECUTABLE)) return ctkCmdLineModuleObjectHierarchyReader::Executable;
-    if (name.startsWith(PREFIX_PARAMETER_GROUP)) return ctkCmdLineModuleObjectHierarchyReader::ParameterGroup;
-    if (name.startsWith(PREFIX_PARAMETER)) return ctkCmdLineModuleObjectHierarchyReader::Parameter;
-    return ctkCmdLineModuleObjectHierarchyReader::NoToken;
-  }
-
-  bool setCurrent(QObject* obj)
-  {
-    ctkCmdLineModuleObjectHierarchyReader::TokenType t = token(obj);
-    if (t != ctkCmdLineModuleObjectHierarchyReader::NoToken)
-    {
-      currentObject = obj;
-      currentToken = t;
-      return true;
-    }
-    return false;
-  }
-
-  QObject* rootObject;
-  QObject* currentObject;
-
-  ctkCmdLineModuleObjectHierarchyReader::TokenType currentToken;
-  bool atEnd;
-
-  QStack<QObject*> objectStack;
-};
-
-ctkCmdLineModuleObjectHierarchyReader::ctkCmdLineModuleObjectHierarchyReader(QObject *root)
-  : d(new ctkCmdLineModuleObjectHierarchyReaderPrivate(root))
-{
-}
-
-ctkCmdLineModuleObjectHierarchyReader::~ctkCmdLineModuleObjectHierarchyReader()
-{
-}
-
-void ctkCmdLineModuleObjectHierarchyReader::setRootObject(QObject* root)
-{
-  d->rootObject = root;
-  clear();
-}
-
-void ctkCmdLineModuleObjectHierarchyReader::clear()
-{
-  d->currentToken = NoToken;
-  d->currentObject = 0;
-  d->objectStack.clear();
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::atEnd() const
-{
-  return d->atEnd || d->rootObject == 0;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::isParameterGroup() const
-{
-  return d->currentToken == ParameterGroup;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::isParameter() const
-{
-  return d->currentToken == Parameter;
-}
-
-QString ctkCmdLineModuleObjectHierarchyReader::name() const
-{
-  if (d->currentObject == 0) return QString();
-  switch(d->currentToken)
-  {
-  case Executable: return d->currentObject->objectName().mid(PREFIX_EXECUTABLE.size());
-  case ParameterGroup: return d->currentObject->objectName().mid(PREFIX_PARAMETER_GROUP.size());
-  case Parameter: return d->currentObject->objectName().mid(PREFIX_PARAMETER.size());
-  default: return QString();
-  }
-}
-
-QString ctkCmdLineModuleObjectHierarchyReader::label() const
-{
-  if (d->currentObject == 0) return QString();
-  switch(d->currentToken)
-  {
-  case Executable: return d->currentObject->objectName().mid(PREFIX_EXECUTABLE.size());
-  case ParameterGroup: return d->property("title").toString();
-  case Parameter: return property("label").toString();
-  default: return QString();
-  }
-}
-
-QString ctkCmdLineModuleObjectHierarchyReader::value() const
-{
-  QString valProp = property("valueProperty").toString();
-  return property(valProp).toString();
-}
-
-QString ctkCmdLineModuleObjectHierarchyReader::flag() const
-{
-  QVariant v = property("flag");
-  return v.isValid() ? v.toString() : QString();
-}
-
-QString ctkCmdLineModuleObjectHierarchyReader::longFlag() const
-{
-  QVariant v = property("longflag");
-  return v.isValid() ? v.toString() : QString();
-}
-
-int ctkCmdLineModuleObjectHierarchyReader::index() const
-{
-  QVariant v = property("index");
-  return v.isValid() ? v.toInt() : -1;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::isMultiple() const
-{
-  QVariant v = property("multiple");
-  return v.isValid() ? v.toBool() : false;
-}
-
-QVariant ctkCmdLineModuleObjectHierarchyReader::property(const QString &propName) const
-{
-  if (d->currentObject == 0) return QVariant();
-
-  // First try to get a prefixed property
-  QVariant res = d->property(propName);
-  // Try to get a property with the original name
-  if (!res.isValid()) res = d->currentObject->property(qPrintable(propName));
-  return res;
-}
-
-ctkCmdLineModuleObjectHierarchyReader::TokenType ctkCmdLineModuleObjectHierarchyReader::readNext() const
-{
-  if (d->atEnd) return NoToken;
-
-  QObject* curr = 0;
-  if (d->currentObject == 0)
-  {
-    curr = d->rootObject;
-    if (d->setCurrent(curr)) return d->currentToken;
-  }
-  else
-  {
-    curr = d->currentObject;
-  }
-
-  while (true)
-  {
-    if (curr)
-    {
-      QObjectList children = curr->children();
-      QListIterator<QObject*> i(children);
-      i.toBack();
-      while (i.hasPrevious())
-      {
-        d->objectStack.push(i.previous());
-      }
-      if (children.isEmpty())
-      {
-        curr = 0;
-      }
-      else
-      {
-        curr = d->objectStack.pop();
-        if (d->setCurrent(curr)) return d->currentToken;
-      }
-      continue;
-    }
-
-    if (d->objectStack.isEmpty()) break;
-    curr = d->objectStack.pop();
-    if (d->setCurrent(curr)) return d->currentToken;
-  }
-
-  d->atEnd = true;
-  d->currentObject = 0;
-  d->currentToken = NoToken;
-
-  return NoToken;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::readNextExecutable() const
-{
-  while (!(readNext() == Executable || d->atEnd));
-  return !d->atEnd;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::readNextParameterGroup() const
-{
-  while (!(readNext() == ParameterGroup || d->atEnd));
-  return !d->atEnd;
-}
-
-bool ctkCmdLineModuleObjectHierarchyReader::readNextParameter() const
-{
-  while (!(readNext() == Parameter || d->atEnd));
-  return !d->atEnd;
-}
-
-ctkCmdLineModuleObjectHierarchyReader::TokenType ctkCmdLineModuleObjectHierarchyReader::tokenType() const
-{
-  return d->currentToken;
-}

+ 2 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleParameter.h

@@ -31,6 +31,8 @@ class QStringList;
 class ctkCmdLineModuleParameterPrivate;
 
 /** 
+ *  \ingroup CommandLineModulesCore
+ *
  *  \brief Single parameter to a module, like a threshold of a filter.
  *
  * ctkCmdLineModuleParameter describes a single parameters to a

+ 5 - 3
Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroup.h

@@ -32,9 +32,11 @@ class ctkCmdLineModuleParameter;
 class ctkCmdLineModuleParameterGroupPrivate;
 
 /** 
-*  \brief Group of parameters
-*
-*/
+ *  \ingroup CommandLineModulesCore
+ *
+ *  \brief Group of parameters
+ *
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleParameterGroup
 {
 

+ 11 - 18
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner.cpp

@@ -19,40 +19,33 @@
   
 =============================================================================*/
 
-#include "ctkCmdLineModuleProcessRunner_p.h"
+#include "ctkCmdLineModuleProcess_p.h"
 
-#include "ctkCmdLineModuleProcessException.h"
 
-
-ctkCmdLineModuleProcessRunner::ctkCmdLineModuleProcessRunner(const QString& location, const QStringList& args)
+ctkCmdLineModuleProcess::ctkCmdLineModuleProcess(const QString& location, const QStringList& args)
   : process(), location(location), args(args)
 {
 }
 
-ctkCmdLineModuleProcessFuture ctkCmdLineModuleProcessRunner::start()
+ctkCmdLineModuleFuture ctkCmdLineModuleProcess::start()
 {
   this->reportStarted();
-  ctkCmdLineModuleProcessFuture future(this);
-  run();
-  return future;
-}
-
-void ctkCmdLineModuleProcessRunner::run()
-{
+  ctkCmdLineModuleFuture future(this);
   connect(&process, SIGNAL(started()), this, SLOT(processStarted()));
   connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
   connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
 
   process.start(location, args);
+  return future;
 }
 
-void ctkCmdLineModuleProcessRunner::processStarted()
+void ctkCmdLineModuleProcess::processStarted()
 {
   qDebug() << "Reporting process started";
   this->reportStarted();
 }
 
-void ctkCmdLineModuleProcessRunner::processFinished(int exitCode, QProcess::ExitStatus status)
+void ctkCmdLineModuleProcess::processFinished(int exitCode, QProcess::ExitStatus status)
 {
   Q_UNUSED(exitCode)
   Q_UNUSED(status)
@@ -66,9 +59,9 @@ void ctkCmdLineModuleProcessRunner::processFinished(int exitCode, QProcess::Exit
   this->reportFinished();
 }
 
-void ctkCmdLineModuleProcessRunner::processError(QProcess::ProcessError)
+void ctkCmdLineModuleProcess::processError(QProcess::ProcessError)
 {
-  qDebug() << "Reporting process error";
-  this->reportException(ctkCmdLineModuleProcessException(process.errorString(), process.exitCode(),
-                                                  process.exitStatus()));
+  //qDebug() << "Reporting process error";
+  //this->reportException(ctkCmdLineModuleProcessException(process.errorString(), process.exitCode(),
+  //                                                process.exitStatus()));
 }

+ 0 - 59
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.cpp

@@ -1,59 +0,0 @@
-/*=============================================================================
-  
-  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.
-  
-=============================================================================*/
-
-#include "ctkCmdLineModuleProcessException.h"
-
-ctkCmdLineModuleProcessException::ctkCmdLineModuleProcessException(const QString& msg, int code,
-                                                     QProcess::ExitStatus status)
-  : msg(msg), code(code), status(status)
-{}
-
-int ctkCmdLineModuleProcessException::exitCode() const
-{
-  return code;
-}
-
-QProcess::ExitStatus ctkCmdLineModuleProcessException::exitStatus() const
-{
-  return status;
-}
-
-QString ctkCmdLineModuleProcessException::message() const
-{
-  return msg;
-}
-
-const char* ctkCmdLineModuleProcessException::what() const throw()
-{
-  static std::string strMsg;
-  strMsg = msg.toStdString();
-  return strMsg.c_str();
-}
-
-void ctkCmdLineModuleProcessException::raise() const
-{
-  throw *this;
-}
-
-ctkCmdLineModuleProcessException* ctkCmdLineModuleProcessException::clone() const
-{
-  return new ctkCmdLineModuleProcessException(*this);
-}

+ 0 - 56
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.h

@@ -1,56 +0,0 @@
-/*=============================================================================
-  
-  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 CTKCMDLINEMODULEPROCESSEXCEPTION_H
-#define CTKCMDLINEMODULEPROCESSEXCEPTION_H
-
-#include <qtconcurrentexception.h>
-
-#include <QProcess>
-
-class ctkCmdLineModuleProcessException : public QtConcurrent::Exception
-{
-public:
-
-  ctkCmdLineModuleProcessException(const QString& msg, int code = 0,
-                            QProcess::ExitStatus status = QProcess::NormalExit);
-
-  ~ctkCmdLineModuleProcessException() throw() {}
-
-  int exitCode() const;
-
-  QProcess::ExitStatus exitStatus() const;
-
-  QString message() const;
-
-  const char* what() const throw();
-
-  void raise() const;
-  ctkCmdLineModuleProcessException* clone() const;
-
-private:
-
-  QString msg;
-  int code;
-  QProcess::ExitStatus status;
-};
-
-#endif // CTKCMDLINEMODULEPROCESSEXCEPTION_H

+ 0 - 138
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.h

@@ -1,138 +0,0 @@
-/*=============================================================================
-  
-  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 CTKCMDLINEMODULEPROCESSFUTURE_H
-#define CTKCMDLINEMODULEPROCESSFUTURE_H
-
-#include <ctkCommandLineModulesCoreExport.h>
-
-#include <QFutureInterface>
-#include <QFutureWatcher>
-#include <QProcess>
-
-class ctkCmdLineModuleProcessFutureInterfacePrivate;
-
-struct ctkCmdLineModuleProcessDummy {};
-typedef QFutureWatcher<ctkCmdLineModuleProcessDummy> ctkCmdLineModuleProcessFutureWatcher;
-
-
-template<>
-class CTK_CMDLINEMODULECORE_EXPORT QFutureInterface<ctkCmdLineModuleProcessDummy> : public QFutureInterfaceBase
-{
-
-public:
-
-  QFutureInterface(State initialState = NoState);
-  QFutureInterface(const QFutureInterface& other);
-
-  static QFutureInterface canceledResult();
-
-  QFutureInterface& operator=(const QFutureInterface& other);
-
-  int exitCode() const;
-  void reportExitCode(int code);
-
-  QProcess::ExitStatus exitStatus() const;
-  void reportExitStatus(QProcess::ExitStatus status);
-
-  QProcess::ProcessError error() const;
-  void reportProcessError(QProcess::ProcessError procErr);
-
-  QString errorString() const;
-  void reportErrorString(const QString& errorStr);
-
-  QString standardOutput() const;
-  void reportStandardOutput(const QString& stdOut);
-
-  QString standardError() const;
-  void reportStandardError(const QString& stdErr);
-
-private:
-
-  ctkCmdLineModuleProcessFutureInterfacePrivate* d;
-};
-
-typedef QFutureInterface<ctkCmdLineModuleProcessDummy> ctkCmdLineModuleProcessFutureInterface;
-
-
-template<>
-class QFuture<ctkCmdLineModuleProcessDummy>
-{
-
-public:
-
-  QFuture()
-    : d(ctkCmdLineModuleProcessFutureInterface::canceledResult())
-  { }
-
-  explicit QFuture(ctkCmdLineModuleProcessFutureInterface *p) // internal
-    : d(*p)
-  { }
-
-  QFuture(const QFuture &other)
-    : d(other.d)
-  { }
-
-  ~QFuture()
-  { }
-
-  QFuture& operator=(const QFuture& other);
-  bool operator==(const QFuture& other) const { return (d == other.d); }
-  bool operator!=(const QFuture& other) const { return (d != other.d); }
-
-  void cancel() { d.cancel(); }
-  bool isCanceled() const { return d.isCanceled(); }
-
-  bool isStarted() const { return d.isStarted(); }
-  bool isFinished() const { return d.isFinished(); }
-  bool isRunning() const { return d.isRunning(); }
-
-  int exitCode() const { return d.exitCode(); }
-  int exitStatus() const { return d.exitStatus(); }
-  QProcess::ProcessError error() const { return d.error(); }
-  QString errorString() const { return d.errorString(); }
-
-  QString standardOutput() const { return d.standardOutput(); }
-  QString standardError() const { return d.standardError(); }
-
-  int progressValue() const { return d.progressValue(); }
-  int progressMinimum() const { return d.progressMinimum(); }
-  int progressMaximum() const { return d.progressMaximum(); }
-  QString progressText() const { return d.progressText(); }
-  void waitForFinished() { d.waitForFinished(); }
-
-private:
-
-  friend class QFutureWatcher<ctkCmdLineModuleProcessDummy>;
-
-  mutable ctkCmdLineModuleProcessFutureInterface d;
-};
-
-typedef QFuture<ctkCmdLineModuleProcessDummy> ctkCmdLineModuleProcessFuture;
-
-
-inline ctkCmdLineModuleProcessFuture& ctkCmdLineModuleProcessFuture::operator=(const ctkCmdLineModuleProcessFuture& other)
-{
-  d = other.d;
-  return *this;
-}
-
-#endif // CTKCMDLINEMODULEPROCESSFUTURE_H

+ 6 - 8
Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner_p.h

@@ -19,25 +19,23 @@
   
 =============================================================================*/
 
-#ifndef CTKCMDLINEMODULEPROCESSRUNNER_P_H
-#define CTKCMDLINEMODULEPROCESSRUNNER_P_H
+#ifndef CTKCMDLINEMODULEPROCESS_P_H
+#define CTKCMDLINEMODULEPROCESS_P_H
 
 #include <QObject>
 #include <QProcess>
 
-#include "ctkCmdLineModuleProcessFuture.h"
+class ctkCmdLineModuleFuture;
 
-class ctkCmdLineModuleProcessRunner : public QObject, public QRunnable, public ctkCmdLineModuleProcessFutureInterface
+class ctkCmdLineModuleProcess : public QObject
 {
   Q_OBJECT
 
 public:
 
-  ctkCmdLineModuleProcessRunner(const QString& location, const QStringList& args);
+  ctkCmdLineModuleProcess(const QString& location, const QStringList& args);
 
-  ctkCmdLineModuleProcessFuture start();
-
-  void run();
+  ctkCmdLineModuleFuture start();
 
 protected Q_SLOTS:
 

+ 1 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleReference.cpp

@@ -43,7 +43,7 @@ ctkCmdLineModuleReference &ctkCmdLineModuleReference::operator =(const ctkCmdLin
 
 ctkCmdLineModuleReference::operator bool()
 {
-  return d;
+  return !d->RawXmlDescription.isEmpty();
 }
 
 ctkCmdLineModuleDescription ctkCmdLineModuleReference::description() const

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleReference.h

@@ -29,6 +29,9 @@
 class ctkCmdLineModuleDescription;
 class ctkCmdLineModuleReferencePrivate;
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleReference
 {
 public:

+ 2 - 2
Libs/CommandLineModules/Core/ctkCmdLineModuleReferencePrivate.cpp

@@ -26,8 +26,8 @@
 
 ctkCmdLineModuleDescription ctkCmdLineModuleReferencePrivate::description() const
 {
-  // lazy creation
-  if (!Description.d)
+  // Lazy creation. The title is a requirement XML element.
+  if (Description.title().isNull())
   {
     QByteArray xml(RawXmlDescription);
     QBuffer xmlInput(&xml);

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlException.h

@@ -26,6 +26,9 @@
 
 #include "ctkCommandLineModulesCoreExport.h"
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 CTK_DECLARE_EXCEPTION(CTK_CMDLINEMODULECORE_EXPORT, ctkCmdLineModuleXmlException, ctkException)
 
 #endif // CTKCMDLINEMODULEXMLEXCEPTION_H

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlValidator.h

@@ -28,6 +28,9 @@
 
 class QIODevice;
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXmlValidator
 {
 

+ 3 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.h

@@ -29,6 +29,9 @@
 
 class QIODevice;
 
+/**
+ * \ingroup CommandLineModulesCore
+ */
 class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
     : public ctkCmdLineModuleXmlValidator
 {

+ 18 - 0
Libs/CommandLineModules/Documentation/CTKCommandLineModules.dox

@@ -0,0 +1,18 @@
+/**
+
+\defgroup CommandLineModules Command Line Modules
+\ingroup Projects
+
+CTK provides an API for interfacing with command line modules through a
+self-describing XML description of the supported command line arguments.
+
+\defgroup CommandLineModulesCore Command Line Module Support
+\ingroup Libs
+\ingroup CommandLineModules
+
+\defgroup CommandLineModulesQtGui Command Line Module QtGui Support
+\ingroup Libs
+\ingroup CommandLineModules
+
+*/
+

+ 2 - 0
Libs/CommandLineModules/QtGui/CMakeLists.txt

@@ -17,6 +17,8 @@ set(KIT_SRCS
   ctkCmdLineModuleInstanceFactoryQtGui.cpp
   ctkCmdLineModuleInstanceQtGui_p.h
   ctkCmdLineModuleInstanceQtGui.cpp
+  ctkCmdLineModuleObjectTreeWalker_p.h
+  ctkCmdLineModuleObjectTreeWalker.cpp
 )
 
 # Headers that should run through moc

+ 45 - 5
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui.cpp

@@ -22,6 +22,7 @@
 #include "ctkCmdLineModuleInstanceQtGui_p.h"
 #include "ctkCmdLineModuleReference.h"
 #include "ctkCmdLineModuleXslTransform.h"
+#include "ctkCmdLineModuleObjectTreeWalker_p.h"
 
 #include <QBuffer>
 #include <QUiLoader>
@@ -32,7 +33,7 @@
 
 ctkCmdLineModuleInstanceQtGui::ctkCmdLineModuleInstanceQtGui(const ctkCmdLineModuleReference& moduleRef)
   : ctkCmdLineModuleInstance(moduleRef),
-    WidgetTree(NULL), XmlDescription(moduleRef.rawXmlDescription())
+    WidgetTree(NULL)
 {
 }
 
@@ -41,7 +42,7 @@ QObject* ctkCmdLineModuleInstanceQtGui::guiHandle() const
   if (WidgetTree) return WidgetTree;
 
   QBuffer input;
-  input.setData(XmlDescription);
+  input.setData(moduleReference().rawXmlDescription());
 
   ctkCmdLineModuleXslTransform xslTransform(&input);
   if (!xslTransform.transform())
@@ -56,15 +57,54 @@ QObject* ctkCmdLineModuleInstanceQtGui::guiHandle() const
   uiBlob.append(xslTransform.output());
 
   QBuffer uiForm(&uiBlob);
-  return uiLoader.load(&uiForm);
+  WidgetTree = uiLoader.load(&uiForm);
+  return WidgetTree;
 }
 
-QVariant ctkCmdLineModuleInstanceQtGui::value(const QString& parameter) const
+QVariant ctkCmdLineModuleInstanceQtGui::value(const QString &parameter) const
 {
+  if (!WidgetTree) return QVariant();
+
+  ctkCmdLineModuleObjectTreeWalker reader(WidgetTree);
+  while(reader.readNextParameter())
+  {
+    if(reader.name() == parameter)
+    {
+      return reader.value();
+    }
+  }
   return QVariant();
 }
 
-void ctkCmdLineModuleInstanceQtGui::setValue(const QString& parameter, const QVariant& value)
+void ctkCmdLineModuleInstanceQtGui::setValue(const QString &parameter, const QVariant &value)
+{
+  if (!WidgetTree) return;
+
+  ctkCmdLineModuleObjectTreeWalker walker(WidgetTree);
+  while(walker.readNextParameter())
+  {
+    if(walker.name() == parameter && walker.value() != value)
+    {
+      walker.setValue(value);
+      emit valueChanged(parameter, value);
+    }
+  }
+}
+
+QList<QString> ctkCmdLineModuleInstanceQtGui::parameterNames() const
 {
+  if (!ParameterNames.empty()) return ParameterNames;
 
+  // Compute the list of parameter names using the widget hierarchy
+  // if it has already created (otherwise fall back to the superclass
+  // implementation.
+  // This avoids creating a ctkCmdLineModuleDescription instance.
+  if (WidgetTree == 0) return ctkCmdLineModuleInstance::parameterNames();
+
+  ctkCmdLineModuleObjectTreeWalker walker(WidgetTree);
+  while(walker.readNextParameter())
+  {
+    ParameterNames.push_back(walker.name());
+  }
+  return ParameterNames;
 }

+ 4 - 1
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui_p.h

@@ -40,11 +40,14 @@ public:
   virtual QVariant value(const QString& parameter) const;
   virtual void setValue(const QString& parameter, const QVariant& value);
 
+  virtual QList<QString> parameterNames() const;
+
 private:
 
   mutable QWidget* WidgetTree;
 
-  const QByteArray XmlDescription;
+  // Cache the list of parameter names
+  mutable QList<QString> ParameterNames;
 };
 
 #endif // CTKCMDLINEMODULEINSTANCEQTGUI_H

+ 258 - 0
Libs/CommandLineModules/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp

@@ -0,0 +1,258 @@
+/*=============================================================================
+  
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleObjectTreeWalker_p.h"
+
+#include <QObject>
+#include <QStack>
+#include <QVariant>
+
+namespace {
+
+static QString PREFIX_EXECUTABLE = "executable:";
+static QString PREFIX_PARAMETER_GROUP = "paramGroup:";
+static QString PREFIX_PARAMETER = "parameter:";
+
+}
+
+ctkCmdLineModuleObjectTreeWalker::ctkCmdLineModuleObjectTreeWalker(QObject *root)
+  : RootObject(root), CurrentObject(0), CurrentToken(NoToken),
+    AtEnd(false)
+{
+}
+
+ctkCmdLineModuleObjectTreeWalker::~ctkCmdLineModuleObjectTreeWalker()
+{
+}
+
+void ctkCmdLineModuleObjectTreeWalker::setRootObject(QObject* root)
+{
+  RootObject = root;
+  clear();
+}
+
+void ctkCmdLineModuleObjectTreeWalker::clear()
+{
+  CurrentToken = NoToken;
+  CurrentObject = 0;
+  ObjectStack.clear();
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::atEnd() const
+{
+  return AtEnd || RootObject == 0;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::isParameterGroup() const
+{
+  return CurrentToken == ParameterGroup;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::isParameter() const
+{
+  return CurrentToken == Parameter;
+}
+
+QString ctkCmdLineModuleObjectTreeWalker::name() const
+{
+  if (CurrentObject == 0) return QString();
+  switch(CurrentToken)
+  {
+  case Executable: return CurrentObject->objectName().mid(PREFIX_EXECUTABLE.size());
+  case ParameterGroup: return CurrentObject->objectName().mid(PREFIX_PARAMETER_GROUP.size());
+  case Parameter: return CurrentObject->objectName().mid(PREFIX_PARAMETER.size());
+  default: return QString();
+  }
+}
+
+QString ctkCmdLineModuleObjectTreeWalker::label() const
+{
+  if (CurrentObject == 0) return QString();
+  switch(CurrentToken)
+  {
+  case Executable: return CurrentObject->objectName().mid(PREFIX_EXECUTABLE.size());
+  case ParameterGroup: return property("title").toString();
+  case Parameter: return property("label").toString();
+  default: return QString();
+  }
+}
+
+QVariant ctkCmdLineModuleObjectTreeWalker::value() const
+{
+  QString valProp = property("valueProperty").toString();
+  return property(valProp);
+}
+
+void ctkCmdLineModuleObjectTreeWalker::setValue(const QVariant& value)
+{
+  QVariant valProp = property("valueProperty");
+  if (valProp.isValid())
+  {
+    CurrentObject->setProperty(qPrintable(valProp.toString()), value);
+  }
+}
+
+QString ctkCmdLineModuleObjectTreeWalker::flag() const
+{
+  QVariant v = property("flag");
+  return v.isValid() ? v.toString() : QString();
+}
+
+QString ctkCmdLineModuleObjectTreeWalker::longFlag() const
+{
+  QVariant v = property("longflag");
+  return v.isValid() ? v.toString() : QString();
+}
+
+int ctkCmdLineModuleObjectTreeWalker::index() const
+{
+  QVariant v = property("index");
+  return v.isValid() ? v.toInt() : -1;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::isMultiple() const
+{
+  QVariant v = property("multiple");
+  return v.isValid() ? v.toBool() : false;
+}
+
+QVariant ctkCmdLineModuleObjectTreeWalker::property(const QString &propName) const
+{
+  if (CurrentObject == 0) return QVariant();
+
+  // First try to get a prefixed property
+  QVariant res = prefixedProperty(propName);
+  // Try to get a property with the original name
+  if (!res.isValid()) res = CurrentObject->property(qPrintable(propName));
+  return res;
+}
+
+ctkCmdLineModuleObjectTreeWalker::TokenType ctkCmdLineModuleObjectTreeWalker::readNext()
+{
+  if (AtEnd) return NoToken;
+
+  QObject* curr = 0;
+  if (CurrentObject == 0)
+  {
+    curr = RootObject;
+    if (setCurrent(curr)) return CurrentToken;
+  }
+  else
+  {
+    curr = CurrentObject;
+  }
+
+  while (true)
+  {
+    if (curr)
+    {
+      QObjectList children = curr->children();
+      QListIterator<QObject*> i(children);
+      i.toBack();
+      while (i.hasPrevious())
+      {
+        ObjectStack.push(i.previous());
+      }
+      if (children.isEmpty())
+      {
+        curr = 0;
+      }
+      else
+      {
+        curr = ObjectStack.pop();
+        if (setCurrent(curr)) return CurrentToken;
+      }
+      continue;
+    }
+
+    if (ObjectStack.isEmpty()) break;
+    curr = ObjectStack.pop();
+    if (setCurrent(curr)) return CurrentToken;
+  }
+
+  AtEnd = true;
+  CurrentObject = 0;
+  CurrentToken = NoToken;
+
+  return NoToken;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::readNextExecutable()
+{
+  while (!(readNext() == Executable || AtEnd));
+  return !AtEnd;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::readNextParameterGroup()
+{
+  while (!(readNext() == ParameterGroup || AtEnd));
+  return !AtEnd;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::readNextParameter()
+{
+  while (!(readNext() == Parameter || AtEnd));
+  return !AtEnd;
+}
+
+ctkCmdLineModuleObjectTreeWalker::TokenType ctkCmdLineModuleObjectTreeWalker::tokenType() const
+{
+  return CurrentToken;
+}
+
+QVariant ctkCmdLineModuleObjectTreeWalker::prefixedProperty(const QString& propName) const
+{
+  if (CurrentObject == 0) return QString();
+
+  QString prefixedName;
+  switch(CurrentToken)
+  {
+  case ctkCmdLineModuleObjectTreeWalker::Executable: prefixedName = PREFIX_EXECUTABLE + propName;
+  case ctkCmdLineModuleObjectTreeWalker::ParameterGroup: prefixedName = PREFIX_PARAMETER_GROUP + propName;
+  case ctkCmdLineModuleObjectTreeWalker::Parameter: prefixedName = PREFIX_PARAMETER + propName;
+  default: ;
+  }
+
+  return CurrentObject->property(qPrintable(prefixedName));
+}
+
+ctkCmdLineModuleObjectTreeWalker::TokenType
+ctkCmdLineModuleObjectTreeWalker::token(QObject* obj)
+{
+  if (obj == 0) return ctkCmdLineModuleObjectTreeWalker::NoToken;
+  QString name = obj->objectName();
+  if (name.startsWith(PREFIX_EXECUTABLE)) return ctkCmdLineModuleObjectTreeWalker::Executable;
+  if (name.startsWith(PREFIX_PARAMETER_GROUP)) return ctkCmdLineModuleObjectTreeWalker::ParameterGroup;
+  if (name.startsWith(PREFIX_PARAMETER)) return ctkCmdLineModuleObjectTreeWalker::Parameter;
+  return ctkCmdLineModuleObjectTreeWalker::NoToken;
+}
+
+bool ctkCmdLineModuleObjectTreeWalker::setCurrent(QObject* obj)
+{
+  ctkCmdLineModuleObjectTreeWalker::TokenType t = token(obj);
+  if (t != ctkCmdLineModuleObjectTreeWalker::NoToken)
+  {
+    CurrentObject = obj;
+    CurrentToken = t;
+    return true;
+  }
+  return false;
+}

+ 26 - 19
Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.h

@@ -19,20 +19,15 @@
   
 =============================================================================*/
 
-#ifndef CTKCMDLINEMODULEOBJECTHIERARCHYREADER_H
-#define CTKCMDLINEMODULEOBJECTHIERARCHYREADER_H
+#ifndef CTKCMDLINEMODULEOBJECTTREEWALKER_H
+#define CTKCMDLINEMODULEOBJECTTREEWALKER_H
 
-#include <QString>
-#include <QScopedPointer>
-#include <QVariant>
-
-#include <ctkCommandLineModulesCoreExport.h>
+#include <QStack>
 
 class QObject;
+class QVariant;
 
-class ctkCmdLineModuleObjectHierarchyReaderPrivate;
-
-class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleObjectHierarchyReader
+class ctkCmdLineModuleObjectTreeWalker
 {
 
 public:
@@ -44,8 +39,8 @@ public:
     Parameter
   };
 
-  ctkCmdLineModuleObjectHierarchyReader(QObject* root = 0);
-  ~ctkCmdLineModuleObjectHierarchyReader();
+  ctkCmdLineModuleObjectTreeWalker(QObject* root = 0);
+  ~ctkCmdLineModuleObjectTreeWalker();
 
   void setRootObject(QObject* root);
   void clear();
@@ -57,7 +52,9 @@ public:
 
   QString name() const;
   QString label() const;
-  QString value() const;
+  QVariant value() const;
+
+  void setValue(const QVariant& value);
 
   QString flag() const;
   QString longFlag() const;
@@ -68,17 +65,27 @@ public:
 
   QVariant property(const QString& propName) const;
 
-  TokenType readNext() const;
-  bool readNextExecutable() const;
-  bool readNextParameterGroup() const;
-  bool readNextParameter() const;
+  TokenType readNext();
+  bool readNextExecutable();
+  bool readNextParameterGroup();
+  bool readNextParameter();
 
   TokenType tokenType() const;
 
 private:
 
-  QScopedPointer<ctkCmdLineModuleObjectHierarchyReaderPrivate> d;
+  TokenType token(QObject* obj);
+  bool setCurrent(QObject* obj);
+  QVariant prefixedProperty(const QString& propName) const;
+
+  QObject* RootObject;
+  QObject* CurrentObject;
+
+  TokenType CurrentToken;
+  bool AtEnd;
+
+  QStack<QObject*> ObjectStack;
 
 };
 
-#endif // CTKCMDLINEMODULEOBJECTHIERARCHYREADER_H
+#endif // CTKCMDLINEMODULEOBJECTTREEWALKER_H