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

Fix ctkCLModuleExplorerMainWindow to match new QFuture API

MattClarkson лет назад: 13
Родитель
Сommit
f4d9a93d1b

+ 22 - 10
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.cpp

@@ -25,16 +25,17 @@
 #include <ctkCmdLineModuleXmlValidator.h>
 #include <ctkCmdLineModuleManager.h>
 #include <ctkCmdLineModule.h>
+#include <ctkCmdLineModuleFuture.h>
 #include <ctkCmdLineModuleFactoryQtGui.h>
 #include <ctkException.h>
 
-#include <QFuture>
 #include <QDebug>
 
 ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   QMainWindow(parent),
   ui(new Ui::ctkCLModuleExplorerMainWindow),
-  moduleManager(new ctkCmdLineModuleFactoryQtGui())
+  moduleManager(new ctkCmdLineModuleFactoryQtGui()),
+  watcher(NULL)
 {
   ui->setupUi(this);
 }
@@ -77,7 +78,17 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
   QStringList cmdLineArgs = module->commandLineArguments();
   qDebug() << cmdLineArgs;
 
-  QFuture<QString> future = module->run();
+  if (watcher != NULL)
+  {
+    delete watcher;
+  }
+  watcher = new QFutureWatcher<ctkCmdLineModuleResult>();
+  QObject::connect(watcher, SIGNAL(started()), this, SLOT(moduleStarted()));
+  QObject::connect(watcher, SIGNAL(finished()), this, SLOT(moduleFinished()));
+
+  ctkCmdLineModuleFuture future = module->run();
+  watcher->setFuture(future);
+
   try
   {
     future.waitForFinished();
@@ -86,17 +97,18 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
   {
     qDebug() << e.printStackTrace();
   }
-
 }
 
-void ctkCLModuleExplorerMainWindow::futureFinished()
+void ctkCLModuleExplorerMainWindow::moduleStarted()
 {
-  qDebug() << "*** Future finished";
+  qDebug() << "*** moduleStarted";
   //qDebug() << "stdout:" << futureWatcher.future().standardOutput();
   //qDebug() << "stderr:" << futureWatcher.future().standardError();
 }
 
-//ctkCmdLineModuleReference ctkCLModuleExplorerMainWindow::moduleReference(int tabIndex)
-//{
-//  return mapTabToModuleRef[tabIndex];
-//}
+void ctkCLModuleExplorerMainWindow::moduleFinished()
+{
+  qDebug() << "*** moduleFinished";
+  //qDebug() << "stdout:" << futureWatcher.future().standardOutput();
+  //qDebug() << "stderr:" << futureWatcher.future().standardError();
+}

+ 5 - 5
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.h

@@ -24,10 +24,11 @@
 
 #include <ctkCmdLineModuleManager.h>
 #include <ctkCmdLineModuleReference.h>
-//#include <ctkCmdLineModuleFuture.h>
+#include <ctkCmdLineModuleResult.h>
 
 #include <QMainWindow>
 #include <QHash>
+#include <QFutureWatcher>
 
 class ctkCmdLineModuleReference;
 
@@ -49,23 +50,22 @@ protected Q_SLOTS:
 
   void on_actionRun_triggered();
 
-  void futureFinished();
+  void moduleStarted();
+  void moduleFinished();
 
 protected:
 
   void addModuleTab(const ctkCmdLineModuleReference& moduleRef);
-
-  //ctkCmdLineModuleReference moduleReference(int tabIndex);
   
 private:
 
   Ui::ctkCLModuleExplorerMainWindow *ui;
 
   ctkCmdLineModuleManager moduleManager;
+  QFutureWatcher<ctkCmdLineModuleResult>* watcher;
 
   QHash<int, ctkCmdLineModule*> mapTabToModuleRef;
 
-  //ctkCmdLineModuleProcessFutureWatcher futureWatcher;
 };
 
 #endif // CTKCLIPLUGINEXPLORERMAINWINDOW_H