forked from commontk/CTK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Class with example logic for a simple host
- Loading branch information
Ivo Wolf
committed
Dec 14, 2012
1 parent
9e209c8
commit 942bc07
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
Plugins/org.commontk.dah.examplehost/ctkExampleHostLogic.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Qt includes | ||
#include <QDebug> | ||
#include <QFileDialog> | ||
#include <QApplication> | ||
#include <QModelIndex> | ||
#include <QTreeView> | ||
#include <QItemSelectionModel> | ||
|
||
// ctk includes | ||
#include "ctkExampleHostLogic.h" | ||
#include "ctkHostedAppPlaceholderWidget.h" | ||
#include "ctkExampleHostControlWidget.h" | ||
#include "ctkExampleDicomHost.h" | ||
#include "ctkDicomAvailableDataHelper.h" | ||
|
||
ctkExampleHostLogic::ctkExampleHostLogic(ctkHostedAppPlaceholderWidget* placeHolder, | ||
QWidget* placeHolderForControls, int hostPort, int appPort) : | ||
QObject(placeHolder), | ||
PlaceHolderForHostedApp(placeHolder), | ||
PlaceHolderForControls(placeHolderForControls), | ||
// ValidSelection(false), | ||
LastData(false), | ||
SendData(false) | ||
{ | ||
this->Host = new ctkExampleDicomHost(PlaceHolderForHostedApp, hostPort, appPort); | ||
this->HostControls = new ctkExampleHostControlWidget(Host, PlaceHolderForControls); | ||
|
||
Data = new ctkDicomAppHosting::AvailableData; | ||
|
||
disconnect(this->Host,SIGNAL(startProgress()),this->Host,SLOT(onStartProgress())); | ||
connect(this->Host,SIGNAL(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection); | ||
connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData()), Qt::QueuedConnection); | ||
connect(this->PlaceHolderForHostedApp,SIGNAL(resized()),this,SLOT(placeHolderResized())); | ||
|
||
connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()) ); | ||
} | ||
|
||
ctkExampleHostLogic::~ctkExampleHostLogic() | ||
{ | ||
delete Data; | ||
} | ||
|
||
void ctkExampleHostLogic::aboutToQuit() | ||
{ | ||
this->Host->exitApplicationBlocking(); | ||
|
||
delete this->Host; | ||
this->Host = 0; | ||
} | ||
|
||
void ctkExampleHostLogic::configureHostedApp() | ||
{ | ||
//qDebug() << "load button clicked"; | ||
AppFileName = QFileDialog::getOpenFileName(PlaceHolderForHostedApp,"Choose hosted application",QApplication::applicationDirPath()); | ||
HostControls->setAppFileName(AppFileName); | ||
// emit SelectionValid(((this->Host) && (this->HostControls->validAppFileName()) && (ValidSelection))); | ||
} | ||
|
||
void ctkExampleHostLogic::sendData(ctkDicomAppHosting::AvailableData& data, bool lastData) | ||
{ | ||
if ((this->Host) && (this->HostControls->validAppFileName()) /*&& (ValidSelection)*/) | ||
{ | ||
*Data = data; | ||
LastData = lastData; | ||
|
||
SendData = true; | ||
if(this->Host->getApplicationState() == ctkDicomAppHosting::EXIT) | ||
{ | ||
this->HostControls->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 ctkExampleHostLogic::onAppReady() | ||
{ | ||
// emit SelectionValid(ValidSelection); | ||
if(SendData) | ||
{ | ||
bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS); | ||
qDebug() << " setState(INPROGRESS) returned: " << reply; | ||
|
||
QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition()); | ||
this->Host->getDicomAppService()->bringToFront(rect); | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
void ctkExampleHostLogic::publishSelectedData() | ||
{ | ||
if(SendData) | ||
{ | ||
qDebug()<<"send dataDescriptors"; | ||
bool success = Host->publishData(*Data, LastData); | ||
if(!success) | ||
{ | ||
qCritical() << "Failed to publish data"; | ||
} | ||
qDebug() << " notifyDataAvailable returned: " << success; | ||
SendData=false; | ||
|
||
QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition()); | ||
this->Host->getDicomAppService()->bringToFront(rect); | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
void ctkExampleHostLogic::placeHolderResized() | ||
{ | ||
///the following does not work (yet) | ||
if((this->Host) && (this->Host->getApplicationState() != ctkDicomAppHosting::EXIT)) | ||
{ | ||
QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition()); | ||
this->Host->getDicomAppService()->bringToFront(rect); | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
ctkExampleDicomHost* ctkExampleHostLogic::getHost() | ||
{ | ||
return this->Host; | ||
} | ||
|
||
//---------------------------------------------------------------------------- | ||
ctkExampleHostControlWidget* ctkExampleHostLogic::getHostControls() | ||
{ | ||
return this->HostControls; | ||
} |
49 changes: 49 additions & 0 deletions
49
Plugins/org.commontk.dah.examplehost/ctkExampleHostLogic.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef CTKDICOMHOSTMAINLOGIC_H | ||
#define CTKDICOMHOSTMAINLOGIC_H | ||
|
||
#include <QObject> | ||
#include <QStringList> | ||
|
||
#include "ctkDicomAppHostingTypes.h" | ||
|
||
#include <org_commontk_dah_examplehost_Export.h> | ||
|
||
class ctkHostedAppPlaceholderWidget; | ||
class ctkExampleDicomHost; | ||
class ctkExampleHostControlWidget; | ||
class ctkDICOMAppWidget; | ||
class QModelIndex; | ||
class QItemSelection; | ||
|
||
class ctkExampleDicomHost; | ||
|
||
class org_commontk_dah_examplehost_EXPORT ctkExampleHostLogic : | ||
public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
ctkExampleHostLogic(ctkHostedAppPlaceholderWidget*, QWidget* placeHolderForControls, int hostPort = 8080, int appPort = 8081); | ||
virtual ~ctkExampleHostLogic(); | ||
ctkExampleDicomHost* getHost(); | ||
ctkExampleHostControlWidget* getHostControls(); | ||
public slots: | ||
void configureHostedApp(); | ||
void sendData(ctkDicomAppHosting::AvailableData& data, bool lastData); | ||
protected slots: | ||
void publishSelectedData(); | ||
void onAppReady(); | ||
void placeHolderResized(); | ||
void aboutToQuit(); | ||
protected: | ||
ctkExampleDicomHost* Host; | ||
ctkExampleHostControlWidget* HostControls; | ||
ctkHostedAppPlaceholderWidget* PlaceHolderForHostedApp; | ||
QWidget* PlaceHolderForControls; | ||
ctkDicomAppHosting::AvailableData* Data; | ||
QString AppFileName; | ||
//bool ValidSelection; | ||
bool LastData; | ||
bool SendData; | ||
}; | ||
|
||
#endif |