// Qt includes #include #include #include #include #include #include // ctk includes #include "ctkDICOMHostMainLogic.h" #include "ctkHostedAppPlaceholderWidget.h" #include "ctkExampleHostControlWidget.h" #include "ctkExampleDicomHost.h" #include "ctkDICOMAppWidget.h" #include "ctkDICOMModel.h" #include "ctkDICOMDatabase.h" #include "ctkDicomAvailableDataHelper.h" ctkDICOMHostMainLogic::ctkDICOMHostMainLogic(ctkHostedAppPlaceholderWidget* placeHolder, ctkDICOMAppWidget* dicomAppWidget) : QObject(placeHolder), PlaceHolderForHostedApp(placeHolder), DicomAppWidget(dicomAppWidget), 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(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection); connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData())); QTreeView * treeview = dicomAppWidget->findChild("TreeView"); QItemSelectionModel* selectionmodel = treeview->selectionModel(); connect(selectionmodel, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), this, SLOT(onTreeSelectionChanged(const QItemSelection &, const QItemSelection &))); } ctkDICOMHostMainLogic::~ctkDICOMHostMainLogic() { delete Data; } void ctkDICOMHostMainLogic::configureHostedApp() { //qDebug() << "load button clicked"; AppFileName = QFileDialog::getOpenFileName(PlaceHolderForHostedApp,"Choose hosted application",QApplication::applicationDirPath()); HostControls->setAppFileName(AppFileName); } void ctkDICOMHostMainLogic::sendDataToHostedApp() { 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->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 ctkDICOMHostMainLogic::onAppReady() { 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 ctkDICOMHostMainLogic::onTreeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) { ValidSelection=false; if(selected.indexes().count() > 0) { foreach (const QModelIndex &index, selected.indexes()) { ctkDICOMModel* model = const_cast(qobject_cast(index.model())); QModelIndex index0 = index.sibling(index.row(), 0); if(model && (model->data(index0,ctkDICOMModel::TypeRole) == static_cast(ctkDICOMModel::SeriesType))) { QString s = "Series selected: "; QString seriesUID = model->data(index0,ctkDICOMModel::UIDRole).toString(); s.append(seriesUID); SelectedFiles = DicomAppWidget->database()->filesForSeries(seriesUID); emit TreeSelectionChanged(s); ValidSelection=true; } } } if (ValidSelection==false) emit TreeSelectionChanged("no series selected"); emit SelectionValid(ValidSelection); } //---------------------------------------------------------------------------- void ctkDICOMHostMainLogic::publishSelectedData() { if(SendData) { qDebug()<<"send dataDescriptors"; bool success = Host->publishData(*Data, true); if(!success) { qCritical() << "Failed to publish data"; } qDebug() << " notifyDataAvailable returned: " << success; SendData=false; QRect rect (this->PlaceHolderForHostedApp->getAbsolutePosition()); this->Host->getDicomAppService()->bringToFront(rect); } }