Bläddra i källkod

ENH: ask for available screen in example

ivowolf 14 år sedan
förälder
incheckning
136abfc92c

+ 7 - 2
Plugins/org.commontk.dicom.examplehost/ctkDicomExampleHost.cpp

@@ -23,23 +23,28 @@ void ctkDicomExampleHost::StartApplication(QString AppPath){
     l.append("--applicationURL");
     l.append(QString("http://localhost:") + QString::number(this->getAppPort()));
     l.append("dicomapp"); // the app plugin to use - has to be changed later
-
+    //if (!QProcess::startDetached (
+    //{
+    //    qCritical() << "application failed to start!";
+    //}
+    //qDebug() << "starting application: " << AppPath << " " << l;
     qDebug() << "starting application: " << AppPath << " " << l;
     this->appProcess.setProcessChannelMode(QProcess::MergedChannels);
     this->appProcess.start(AppPath,l);
-
 }
 
 QRect ctkDicomExampleHost::getAvailableScreen(const QRect& preferredScreen){
     qDebug()<< "Application asked for this area:"<< preferredScreen;
 
     QRect rect (this->placeholderWidget->getAbsolutePosition());
+
     emit giveAvailableScreen(rect);
     return rect;
 }
 
 
 void ctkDicomExampleHost::notifyStateChanged(ctkDicomWG23::State state){
+    qDebug()<< "new state received:"<< static_cast<int>(state);
     qDebug()<< "new state received:"<< ctkDicomSoapState::toStringValue(state);
     emit stateChangedReceived(state);
 }

+ 0 - 49
Plugins/org.commontk.dicom.wg23.core/ctkDicomWG23TypesHelper.h

@@ -174,53 +174,4 @@ class ctkDicomSoapArrayOfString : public QtSoapArray{
 
 };
 
-//Not easy to template, will see later for other types
-class ctkDicomSoapArrayOfString : public QtSoapArray{
-    public:
-    ctkDicomSoapArrayOfString ( const QString & name, const QStringList array):
-            QtSoapArray ( QtSoapQName(name),QtSoapType::String,
-                          array.size()){
-
-        for (QStringList::ConstIterator it = array.constBegin();
-                it < array.constEnd(); it++){
-            this->append(new QtSoapSimpleType(QtSoapQName("string"),*it));
-        }
-    };
-
-    static QStringList* getArray(const QtSoapArray& array){
-        QStringList * list = new QStringList();
-        for (int i = 0; i < array.count() ; i++ ){
-            const QString str = array.at(i).value().toString();
-            list->append( str);
-        }
-        return list;
-    };
-
-};
-
-//Not easy to template, will see later for other types
-class ctkDicomSoapArrayOfString : public QtSoapArray{
-    public:
-    ctkDicomSoapArrayOfString ( const QString & name, const QStringList array):
-            QtSoapArray ( QtSoapQName(name),QtSoapType::String,
-                          array.size()){
-
-        for (QStringList::ConstIterator it = array.constBegin();
-                it < array.constEnd(); it++){
-            this->append(new QtSoapSimpleType(QtSoapQName("string"),*it));
-        }
-    };
-
-    static QStringList* getArray(const QtSoapArray& array){
-        QStringList * list = new QStringList();
-        for (int i = 0; i < array.count() ; i++ ){
-            const QString str = array.at(i).value().toString();
-            list->append( str);
-        }
-        return list;
-    };
-
-};
-
-
 #endif

+ 28 - 14
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic.cpp

@@ -29,14 +29,8 @@
 ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host)
   : host(host)
 {
-  try
-  {
-    host->notifyStateChanged(ctkDicomWG23::IDLE);
-  }
-  catch (const std::runtime_error& e)
-  {
-    qCritical() << e.what();
-  }
+  connect(this, SIGNAL(stateChanged(int)), this, SLOT(changeState(int)), Qt::QueuedConnection);
+  emit stateChanged(ctkDicomWG23::IDLE);
 }
 
 ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
@@ -51,11 +45,7 @@ ctkDicomWG23::State ctkExampleDicomAppLogic::getState()
 bool ctkExampleDicomAppLogic::setState(ctkDicomWG23::State newState)
 {
   qDebug() << "setState called";
-  if (newState == ctkDicomWG23::INPROGRESS)
-  {
-    QPushButton *button = new QPushButton("Button from App");
-    button->show();
-  }
+  emit stateChanged(newState);
   return true;
 }
 
@@ -66,13 +56,37 @@ bool ctkExampleDicomAppLogic::bringToFront(const QRect& requestedScreenArea)
 
 void ctkExampleDicomAppLogic::do_something()
 {
-  QRect preferred;
+  QPushButton *button = new QPushButton("Button from App");
   try
   {
+    QRect preferred(50,50,100,100);
+    qDebug() << "  Asking:getAvailableScreen";
     QRect rect = host->getAvailableScreen(preferred);
+    qDebug() << "  got sth:" << rect.top();
+    button->move(rect.topLeft());
+    button->resize(rect.size());
+  }
+  catch (const std::runtime_error& e)
+  {
+    qCritical() << e.what();
+  }
+  button->show();
+}
+
+void ctkExampleDicomAppLogic::changeState(int anewstate)
+{
+  ctkDicomWG23::State newstate = (ctkDicomWG23::State)anewstate;
+  try
+  {
+    host->notifyStateChanged(newstate);
   }
   catch (const std::runtime_error& e)
   {
     qCritical() << e.what();
   }
+
+  if (newstate == ctkDicomWG23::INPROGRESS)
+  {
+    do_something();
+  }
 }

+ 4 - 0
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic_p.h

@@ -73,6 +73,10 @@ public:
 
   // some logic
   void do_something();
+signals:
+  void stateChanged(int);
+protected slots:
+  void changeState(int);
 private:
   ServiceAccessor<ctkDicomHostInterface> host;