Skip to content

Commit

Permalink
Class with example logic for a simple host
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Wolf committed Dec 14, 2012
1 parent 9e209c8 commit 942bc07
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Plugins/org.commontk.dah.examplehost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(PLUGIN_SRCS
ctkExampleDicomHostPlugin_p.h
ctkHostedAppPlaceholderWidget.cpp
ctkExampleHostControlWidget.cpp
ctkExampleHostLogic.cpp
)

# Files which should be processed by Qts moc
Expand All @@ -16,6 +17,7 @@ set(PLUGIN_MOC_SRCS
ctkExampleDicomHostPlugin_p.h
ctkHostedAppPlaceholderWidget.h
ctkExampleHostControlWidget.h
ctkExampleHostLogic.h
)

# Qt Designer files which should be processed by Qts uic
Expand Down
135 changes: 135 additions & 0 deletions Plugins/org.commontk.dah.examplehost/ctkExampleHostLogic.cpp
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 Plugins/org.commontk.dah.examplehost/ctkExampleHostLogic.h
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

0 comments on commit 942bc07

Please sign in to comment.