Parcourir la source

Start hosted app and publish data with one button click

Ivo Wolf il y a 13 ans
Parent
commit
4731190e15

+ 1 - 0
Applications/ctkDICOMHost/ctkDICOMHostMain.cpp

@@ -163,6 +163,7 @@ int main(int argc, char** argv)
   logic->connect(ui.configureHostedApp,SIGNAL(clicked()), logic, SLOT(configureHostedApp()));
   logic->connect(ui.sendDataToHostedApp,SIGNAL(clicked()), logic, SLOT(sendDataToHostedApp()));
   logic->connect(logic, SIGNAL(TreeSelectionChanged(const QString &)), ui.selection, SLOT(setText(const QString &)));
+  logic->connect(logic, SIGNAL(SelectionValid(bool)), ui.sendDataToHostedApp, SLOT(setEnabled(bool)));
 
   //ctkDICOMAppWidget DICOMApp(widget);
 

+ 47 - 24
Applications/ctkDICOMHost/ctkDICOMHostMainLogic.cpp

@@ -20,14 +20,18 @@ ctkDICOMHostMainLogic::ctkDICOMHostMainLogic(ctkHostedAppPlaceholderWidget* plac
   QObject(placeHolder), 
   PlaceHolderForHostedApp(placeHolder),
   DicomAppWidget(dicomAppWidget),
-  ValidSelection(false)
+  ValidSelection(false),
+  SendData(false)
 {
   this->Host = new ctkExampleDicomHost(PlaceHolderForHostedApp);
   this->HostControls = new ctkExampleHostControlWidget(Host, placeHolder);
   this->HostControls->show();
 
+  Data = new ctkDicomAppHosting::AvailableData;
+
   disconnect(this->Host,SIGNAL(startProgress()),this->Host,SLOT(onStartProgress()));
-  connect(this->Host,SIGNAL(startProgress()),this,SLOT(onStartProgress()));
+  connect(this->Host,SIGNAL(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection);
+  connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData()));
 
   QTreeView * treeview = dicomAppWidget->findChild<QTreeView*>("TreeView");
   QItemSelectionModel* selectionmodel = treeview->selectionModel();
@@ -37,25 +41,53 @@ ctkDICOMHostMainLogic::ctkDICOMHostMainLogic(ctkHostedAppPlaceholderWidget* plac
 
 ctkDICOMHostMainLogic::~ctkDICOMHostMainLogic()
 {
+  delete Data;
 }
 
 void ctkDICOMHostMainLogic::configureHostedApp()
 {
   //qDebug() << "load button clicked";
   AppFileName = QFileDialog::getOpenFileName(PlaceHolderForHostedApp,"Choose hosted application",QApplication::applicationDirPath());
-  //HostControls->setAppFileName(name);
-  //if (this->Host)
-  //  {
-  //  this->Host->StartApplication(this->AppFileName);
-  //  bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
-  //  qDebug() << "  setState(INPROGRESS) returned: " << reply;
-  //  }
   HostControls->setAppFileName(AppFileName);
 }
 
 void ctkDICOMHostMainLogic::sendDataToHostedApp()
 {
-  //if(Host->
+  if ((this->Host) && (this->AppFileName.isEmpty()==false) && (ValidSelection))
+  {
+    foreach (const QString &str, SelectedFiles) {
+      if (str.isEmpty())
+        continue;
+      qDebug() << str;
+
+      ctkDicomAvailableDataHelper::addToAvailableData(*Data, 
+        Host->objectLocatorCache(), 
+        str);
+    }
+ 
+    SendData = true;
+    if(this->Host->getApplicationState() == ctkDicomAppHosting::EXIT)
+    {
+      this->Host->StartApplication(this->AppFileName);
+    }
+    if(this->Host->getApplicationState() == ctkDicomAppHosting::IDLE)
+    {
+      bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
+    }
+    if(this->Host->getApplicationState() == ctkDicomAppHosting::INPROGRESS)
+    {
+      publishSelectedData();
+    }
+  }
+}
+
+void ctkDICOMHostMainLogic::onAppReady()
+{
+  if(SendData)
+  {
+    bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
+    qDebug() << "  setState(INPROGRESS) returned: " << reply;
+  }
 }
 
 void ctkDICOMHostMainLogic::onTreeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
@@ -82,30 +114,21 @@ void ctkDICOMHostMainLogic::onTreeSelectionChanged(const QItemSelection & select
     }
     if (ValidSelection==false)
       emit TreeSelectionChanged("no series selected");
+    emit SelectionValid(ValidSelection);
 }
 
 //----------------------------------------------------------------------------
-void ctkDICOMHostMainLogic::onStartProgress()
+void ctkDICOMHostMainLogic::publishSelectedData()
 {
-  if(ValidSelection)
+  if(SendData)
   {
-    ctkDicomAppHosting::AvailableData data;
-    foreach (const QString &str, SelectedFiles) {
-      if (str.isEmpty())
-        continue;
-      qDebug() << str;
-
-      ctkDicomAvailableDataHelper::addToAvailableData(data, 
-        Host->objectLocatorCache(), 
-        str);
-    }
-
     qDebug()<<"send dataDescriptors";
-    bool success = Host->publishData(data, true);
+    bool success = Host->publishData(*Data, true);
     if(!success)
     {
       qCritical() << "Failed to publish data";
     }
     qDebug() << "  notifyDataAvailable returned: " << success;
+    SendData=false;
   }
 }

+ 6 - 1
Applications/ctkDICOMHost/ctkDICOMHostMainLogic.h

@@ -3,6 +3,7 @@
 
 #include <QObject.h>
 #include <QStringList.h>
+#include "ctkDicomAppHostingTypes.h"
 
 class ctkHostedAppPlaceholderWidget;
 class ctkExampleDicomHost;
@@ -23,17 +24,21 @@ public slots:
   void sendDataToHostedApp();
 protected slots:
   void onTreeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
-  void onStartProgress();
+  void publishSelectedData();
+  void onAppReady();
 signals:
   void TreeSelectionChanged(const QString &);
+  void SelectionValid(bool);
 protected:
   ctkExampleDicomHost* Host;
   ctkExampleHostControlWidget* HostControls;
   ctkHostedAppPlaceholderWidget* PlaceHolderForHostedApp;
   ctkDICOMAppWidget* DicomAppWidget;
+  ctkDicomAppHosting::AvailableData* Data;
   QString AppFileName;
   bool ValidSelection;
   QStringList SelectedFiles;
+  bool SendData;
 };
 
 #endif

+ 3 - 0
Applications/ctkDICOMHost/ctkDICOMHostMainWidget.ui

@@ -54,6 +54,9 @@
      </item>
      <item>
       <widget class="QPushButton" name="sendDataToHostedApp">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
        <property name="text">
         <string>Send Data to Hosted App</string>
        </property>

+ 0 - 2
Plugins/org.commontk.dah.examplehost/ctkExampleDicomHost.h

@@ -42,8 +42,6 @@ public:
   ctkExampleDicomHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort = 8080, int appPort = 8081);
   virtual ~ctkExampleDicomHost();
 
-  ctkDicomAppHosting::State getApplicationState() const;
-
   virtual void StartApplication(QString AppPath);
   virtual QString generateUID() { return ""; }
   virtual QRect getAvailableScreen(const QRect& preferredScreen);