ctkExampleHostLogic.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Qt includes
  2. #include <QDebug>
  3. #include <QFileDialog>
  4. #include <QApplication>
  5. #include <QModelIndex>
  6. #include <QTreeView>
  7. #include <QItemSelectionModel>
  8. // ctk includes
  9. #include "ctkExampleHostLogic.h"
  10. #include "ctkHostedAppPlaceholderWidget.h"
  11. #include "ctkExampleHostControlWidget.h"
  12. #include "ctkExampleDicomHost.h"
  13. #include "ctkDicomAvailableDataHelper.h"
  14. ctkExampleHostLogic::ctkExampleHostLogic(ctkHostedAppPlaceholderWidget* placeHolder,
  15. QWidget* placeHolderForControls, int hostPort, int appPort) :
  16. QObject(placeHolder),
  17. PlaceHolderForHostedApp(placeHolder),
  18. PlaceHolderForControls(placeHolderForControls),
  19. // ValidSelection(false),
  20. LastData(false),
  21. SendData(false)
  22. {
  23. this->Host = new ctkExampleDicomHost(PlaceHolderForHostedApp, hostPort, appPort);
  24. this->HostControls = new ctkExampleHostControlWidget(Host, PlaceHolderForControls);
  25. Data = new ctkDicomAppHosting::AvailableData;
  26. disconnect(this->Host,SIGNAL(startProgress()),this->Host,SLOT(onStartProgress()));
  27. connect(this->Host,SIGNAL(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection);
  28. connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData()), Qt::QueuedConnection);
  29. connect(this->PlaceHolderForHostedApp,SIGNAL(resized()),this,SLOT(placeHolderResized()));
  30. connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()) );
  31. }
  32. ctkExampleHostLogic::~ctkExampleHostLogic()
  33. {
  34. delete Data;
  35. }
  36. void ctkExampleHostLogic::aboutToQuit()
  37. {
  38. this->Host->exitApplicationBlocking();
  39. delete this->Host;
  40. this->Host = 0;
  41. }
  42. void ctkExampleHostLogic::configureHostedApp()
  43. {
  44. //qDebug() << "load button clicked";
  45. AppFileName = QFileDialog::getOpenFileName(PlaceHolderForHostedApp,"Choose hosted application",QApplication::applicationDirPath());
  46. HostControls->setAppFileName(AppFileName);
  47. // emit SelectionValid(((this->Host) && (this->HostControls->validAppFileName()) && (ValidSelection)));
  48. }
  49. void ctkExampleHostLogic::sendData(ctkDicomAppHosting::AvailableData& data, bool lastData)
  50. {
  51. if ((this->Host) && (this->HostControls->validAppFileName()) /*&& (ValidSelection)*/)
  52. {
  53. *Data = data;
  54. LastData = lastData;
  55. SendData = true;
  56. if(this->Host->getApplicationState() == ctkDicomAppHosting::EXIT)
  57. {
  58. this->HostControls->StartApplication(this->AppFileName);
  59. }
  60. if(this->Host->getApplicationState() == ctkDicomAppHosting::IDLE)
  61. {
  62. bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
  63. }
  64. if(this->Host->getApplicationState() == ctkDicomAppHosting::INPROGRESS)
  65. {
  66. publishSelectedData();
  67. }
  68. }
  69. }
  70. void ctkExampleHostLogic::onAppReady()
  71. {
  72. // emit SelectionValid(ValidSelection);
  73. if(SendData)
  74. {
  75. bool reply = this->Host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
  76. qDebug() << " setState(INPROGRESS) returned: " << reply;
  77. QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition());
  78. this->Host->getDicomAppService()->bringToFront(rect);
  79. }
  80. }
  81. //----------------------------------------------------------------------------
  82. void ctkExampleHostLogic::publishSelectedData()
  83. {
  84. if(SendData)
  85. {
  86. qDebug()<<"send dataDescriptors";
  87. bool success = Host->publishData(*Data, LastData);
  88. if(!success)
  89. {
  90. qCritical() << "Failed to publish data";
  91. }
  92. qDebug() << " notifyDataAvailable returned: " << success;
  93. SendData=false;
  94. QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition());
  95. this->Host->getDicomAppService()->bringToFront(rect);
  96. }
  97. }
  98. //----------------------------------------------------------------------------
  99. void ctkExampleHostLogic::placeHolderResized()
  100. {
  101. ///the following does not work (yet)
  102. if((this->Host) && (this->Host->getApplicationState() != ctkDicomAppHosting::EXIT))
  103. {
  104. QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition());
  105. this->Host->getDicomAppService()->bringToFront(rect);
  106. }
  107. }
  108. //----------------------------------------------------------------------------
  109. ctkExampleDicomHost* ctkExampleHostLogic::getHost()
  110. {
  111. return this->Host;
  112. }
  113. //----------------------------------------------------------------------------
  114. ctkExampleHostControlWidget* ctkExampleHostLogic::getHostControls()
  115. {
  116. return this->HostControls;
  117. }