diff --git a/CMakeExternals/CTK.cmake b/CMakeExternals/CTK.cmake index 0cfc835d01..81d35de915 100644 --- a/CMakeExternals/CTK.cmake +++ b/CMakeExternals/CTK.cmake @@ -1,95 +1,95 @@ #----------------------------------------------------------------------------- # CTK #----------------------------------------------------------------------------- if(MITK_USE_CTK) # Sanity checks if(DEFINED CTK_DIR AND NOT EXISTS ${CTK_DIR}) message(FATAL_ERROR "CTK_DIR variable is defined but corresponds to non-existing directory") endif() set(proj CTK) set(proj_DEPENDENCIES ) set(CTK_DEPENDS ${proj}) if(NOT DEFINED CTK_DIR) - set(revision_tag 1dd16ae7) + set(revision_tag fd3ecf96) #IF(${proj}_REVISION_TAG) # SET(revision_tag ${${proj}_REVISION_TAG}) #ENDIF() set(ctk_optional_cache_args ) if(MITK_USE_Python) list(APPEND ctk_optional_cache_args -DCTK_LIB_Scripting/Python/Widgets:BOOL=ON -DCTK_ENABLE_Python_Wrapping:BOOL=ON -DCTK_APP_ctkSimplePythonShell:BOOL=ON -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2} -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} ) else() list(APPEND ctk_optional_cache_args -DCTK_LIB_Scripting/Python/Widgets:BOOL=OFF -DCTK_ENABLE_Python_Wrapping:BOOL=OFF -DCTK_APP_ctkSimplePythonShell:BOOL=OFF ) endif() if(MITK_USE_DCMTK) list(APPEND ctk_optional_cache_args -DDCMTK_DIR:PATH=${DCMTK_DIR} ) list(APPEND proj_DEPENDENCIES DCMTK) else() list(APPEND ctk_optional_cache_args -DDCMTK_URL:STRING=${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/CTK_DCMTK_085525e6.tar.gz ) endif() FOREACH(type RUNTIME ARCHIVE LIBRARY) IF(DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY) LIST(APPEND mitk_optional_cache_args -DCTK_PLUGIN_${type}_OUTPUT_DIRECTORY:PATH=${CTK_PLUGIN_${type}_OUTPUT_DIRECTORY}) ENDIF() ENDFOREACH() ExternalProject_Add(${proj} SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}-src BINARY_DIR ${proj}-build PREFIX ${proj}-cmake URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/CTK_${revision_tag}.tar.gz - URL_MD5 03438db5c9a8324deb45d82c8a27784c + URL_MD5 a33be5c622fee05179c55e67a7d1b9cf UPDATE_COMMAND "" INSTALL_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_ARGS ${ep_common_args} ${ctk_optional_cache_args} -DDESIRED_QT_VERSION:STRING=${DESIRED_QT_VERSION} -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DGit_EXECUTABLE:FILEPATH=${GIT_EXECUTABLE} -DGIT_EXECUTABLE:FILEPATH=${GIT_EXECUTABLE} -DCTK_LIB_CommandLineModules/Backend/LocalProcess:BOOL=ON -DCTK_LIB_CommandLineModules/Frontend/QtGui:BOOL=ON -DCTK_LIB_PluginFramework:BOOL=ON -DCTK_LIB_DICOM/Widgets:BOOL=ON -DCTK_LIB_XNAT/Core:BOOL=ON -DCTK_PLUGIN_org.commontk.eventadmin:BOOL=ON -DCTK_PLUGIN_org.commontk.configadmin:BOOL=ON -DCTK_USE_GIT_PROTOCOL:BOOL=OFF -DDCMTK_URL:STRING=${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/CTK_DCMTK_085525e6.tar.gz -DqRestAPI_URL:STRING=${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/qRestAPI_5f3a03b1.tar.gz DEPENDS ${proj_DEPENDENCIES} ) set(CTK_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif() endif() diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp index a79f97c3ec..989dbb8a71 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp @@ -1,453 +1,482 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkXnatEditor.h" // Qmitk #include "QmitkXnatObjectEditorInput.h" #include "org_mitk_gui_qt_xnatinterface_Activator.h" // CTK XNAT Core #include "ctkXnatObject.h" #include "ctkXnatDataModel.h" #include "ctkXnatScanFolder.h" #include "ctkXnatFile.h" // CTK XNAT Widgets #include "ctkXnatListModel.h" // Blueberry #include #include // Qt #include #include #include #include #include // MITK #include #include const std::string QmitkXnatEditor::EDITOR_ID = "org.mitk.editors.xnat.browser"; QmitkXnatEditor::QmitkXnatEditor() : m_DataStorageServiceTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()), m_Session(0), m_ListModel(new ctkXnatListModel()), m_SelectionListener(new berry::SelectionChangedAdapter(this, &QmitkXnatEditor::SelectionChanged)), m_DownloadPath(berry::Platform::GetServiceRegistry(). GetServiceById(berry::IPreferencesService::ID)-> GetSystemPreferences()->Node("/XnatConnection")->Get("Download Path", "").c_str()) { m_DataStorageServiceTracker.open(); if(m_DownloadPath.isEmpty()) { QString xnatFolder = "XNAT_DOWNLOADS"; QDir dir(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()->getDataFile("").absoluteFilePath()); dir.mkdir(xnatFolder); dir.setPath(dir.path() + "/" + xnatFolder); m_DownloadPath = dir.path() + "/"; } } QmitkXnatEditor::~QmitkXnatEditor() { delete m_ListModel; berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); s->RemoveSelectionListener(m_SelectionListener); m_DataStorageServiceTracker.close(); } bool QmitkXnatEditor::IsDirty() const { return false; } bool QmitkXnatEditor::IsSaveAsAllowed() const { return false; } void QmitkXnatEditor::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) { - this->SetInput(input); this->SetSite(site); + berry::QtEditorPart::SetInput(input); + this->SetInput(input); } void QmitkXnatEditor::DoSave() { } void QmitkXnatEditor::DoSaveAs() { } void QmitkXnatEditor::SetInput(berry::IEditorInput::Pointer input) { - // If the input is not a QmitkXnatObjectEditorInput the semi global xnat session will be loaded. QmitkXnatObjectEditorInput::Pointer oPtr = input.Cast(); if(oPtr.IsNotNull()) { - SetInputWithNotify(oPtr); + berry::QtEditorPart::SetInput(oPtr); this->GetEditorInput().Cast()->GetXnatObject()->fetch(); } - else - { - // Get the XNAT Session from Activator - m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); - - if(m_Session == 0) - { - QMessageBox::critical(QApplication::activeWindow(), "Error", - "Please check the Preferences of XNAT. Maybe they are not ok.\nClose the tab 'XNAT Editor' and start it again."); - MITK_INFO << "Please check your XNAT Connection Preferences!"; - } - else - { - QmitkXnatObjectEditorInput::Pointer xoPtr = QmitkXnatObjectEditorInput::New( m_Session->dataModel() ); - berry::IEditorInput::Pointer editorInput( xoPtr ); - SetInputWithNotify(editorInput); - this->GetEditorInput().Cast()->GetXnatObject()->fetch(); - } - } } void QmitkXnatEditor::SetFocus() { } void QmitkXnatEditor::CreateQtPartControl( QWidget *parent ) { - if(m_Session != 0) return; - // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); - m_Controls.treeView->setModel(m_ListModel); GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener(m_SelectionListener); connect( m_Controls.treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(OnObjectActivated(const QModelIndex&)) ); connect( m_Controls.buttonDownloadResource, SIGNAL(clicked()), this, SLOT(DownloadResource()) ); connect( m_Controls.buttonDownloadFile, SIGNAL(clicked()), this, SLOT(DownloadFile()) ); connect( m_Controls.buttonDataModel, SIGNAL(clicked()), this, SLOT(OnDataModelButtonClicked()) ); connect( m_Controls.buttonProject, SIGNAL(clicked()), this, SLOT(OnProjectButtonClicked()) ); connect( m_Controls.buttonSubject, SIGNAL(clicked()), this, SLOT(OnSubjectButtonClicked()) ); connect( m_Controls.buttonExperiment, SIGNAL(clicked()), this, SLOT(OnExperimentButtonClicked()) ); connect( m_Controls.buttonKindOfData, SIGNAL(clicked()), this, SLOT(OnKindOfDataButtonClicked()) ); connect( m_Controls.buttonSession, SIGNAL(clicked()), this, SLOT(OnSessionButtonClicked()) ); connect( m_Controls.buttonResource, SIGNAL(clicked()), this, SLOT(OnResourceButtonClicked()) ); // Makes the breadcrumb feature invisible for(int i = 0; i < m_Controls.breadcrumbHorizontalLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(false); } for(int i = 0; i < m_Controls.breadcrumbDescriptionLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbDescriptionLayout->itemAt(i); child->widget()->setVisible(false); } - UpdateList(); + QmitkXnatObjectEditorInput::Pointer oPtr = GetEditorInput().Cast(); + if(oPtr.IsNotNull()) + { + UpdateList(); + } + else + { + UpdateSession(); + } } void QmitkXnatEditor::UpdateList() { QmitkXnatObjectEditorInput::Pointer xoPtr(GetEditorInput().Cast()); if( xoPtr.IsNull() ) return; ctkXnatObject* inputObject = xoPtr->GetXnatObject(); if( inputObject == NULL ) return; + + m_Controls.treeView->setModel(m_ListModel); m_ListModel->setRootObject( inputObject ); m_Controls.treeView->reset(); // recursive method to check parents of the inputObject m_ParentCount = ParentChecker(inputObject); // breadcrumb labels for(int i = 0; i < m_Controls.breadcrumbHorizontalLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(false); } for(int i = 0; i < m_Controls.breadcrumbDescriptionLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbDescriptionLayout->itemAt(i); child->widget()->setVisible(false); } ctkXnatObject* parent = NULL; for(int i = m_ParentCount*2; i >= 0; i--) { if(i > 12) break; m_Controls.breadcrumbDescriptionLayout->itemAt(i)->widget()->setVisible(true); QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(true); if(i>0) { m_Controls.breadcrumbHorizontalLayout->itemAt(i-1)->widget()->setVisible(true); m_Controls.breadcrumbDescriptionLayout->itemAt(i-1)->widget()->setVisible(true); } if(parent == NULL) { parent = inputObject; } - // make breadcrumb button + // create breadcrumb button QPushButton* breadcrumbButton = dynamic_cast(child->widget()); breadcrumbButton->setText(parent->id()); parent = parent->parent(); i--; } + m_Controls.buttonDataModel->setText("root"); } void QmitkXnatEditor::SelectionChanged(berry::IWorkbenchPart::Pointer sourcepart, berry::ISelection::ConstPointer selection) { // check for null selection if (selection.IsNull()) { return; } // exclude own selection events and check whether this kind of selection can be handled if (sourcepart != this && selection.Cast()) { berry::IStructuredSelection::ConstPointer currentSelection = selection.Cast(); // iterates over the selection for (berry::IStructuredSelection::iterator itr = currentSelection->Begin(); itr != currentSelection->End(); ++itr) { if (berry::SmartPointer objectPointer = itr->Cast()) { // get object of selected ListWidgetElement ctkXnatObject* object = objectPointer->GetQModelIndex().data(Qt::UserRole).value(); // if a file is selected, don't change the input and list view if ( dynamic_cast(object) == NULL ) { QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( object ); berry::IEditorInput::Pointer editorInput( oPtr ); if ( !(editorInput == this->GetEditorInput()) ) this->SetInput(editorInput); UpdateList(); } } } } } void QmitkXnatEditor::DownloadResource() { if (!m_Controls.treeView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex(); QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatScanFolder* resource = dynamic_cast(variant.value()); if (resource != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString resourcePath = m_DownloadPath + resource->id() + ".zip"; resource->download(resourcePath); // Testing if the path exists QDir downDir(m_DownloadPath); if( downDir.exists(resource->id() + ".zip") ) { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip was completed!"; } else { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip failed!"; } } else { MITK_INFO << "Selection was not a resource folder!"; } } } void QmitkXnatEditor::DownloadFile() { if (!m_Controls.treeView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex(); InternalFileDownload(index); } void QmitkXnatEditor::ToHigherLevel() { ctkXnatObject* parent = GetEditorInput().Cast()->GetXnatObject()->parent(); if( parent == NULL) { return; } QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( parent ); berry::IEditorInput::Pointer editorInput( oPtr ); - SetInput(editorInput); + this->SetInput(editorInput); UpdateList(); } void QmitkXnatEditor::OnObjectActivated(const QModelIndex &index) { if (!index.isValid()) return; ctkXnatObject* child = GetEditorInput().Cast()->GetXnatObject()->children().at(index.row()); if( child != NULL ) { ctkXnatFile* file = dynamic_cast(child); if( file != NULL ) { // Download file and put into datamanager InternalFileDownload(index); mitk::IDataStorageService* dsService = m_DataStorageServiceTracker.getService(); if(dsService != NULL) { mitk::DataNode::Pointer node = mitk::IOUtil::LoadDataNode((m_DownloadPath + file->id()).toStdString()); if ( ( node.IsNotNull() ) && ( node->GetData() != NULL ) ) { dsService->GetDataStorage()->GetDataStorage()->Add(node); mitk::BaseData::Pointer basedata = node->GetData(); mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); } } } else { // Updates the root item QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( child ); berry::IEditorInput::Pointer editorInput( oPtr ); - SetInput(editorInput); + this->SetInput(editorInput); this->GetEditorInput().Cast()->GetXnatObject()->fetch(); UpdateList(); } } } void QmitkXnatEditor::InternalFileDownload(const QModelIndex& index) { QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatFile* file = dynamic_cast(variant.value()); if (file != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString filePath = m_DownloadPath + file->id(); file->download(filePath); // Testing if the file exists QDir downDir(m_DownloadPath); if( downDir.exists(file->id()) ) { MITK_INFO << "Download of " << file->id().toStdString() << " was completed!"; } else { MITK_INFO << "Download of " << file->id().toStdString() << " failed!"; } } else { MITK_INFO << "Selection was not a file!"; } } } int QmitkXnatEditor::ParentChecker(ctkXnatObject* child) { int sum; if( child->parent() == NULL ) { return 0; } else { sum = 1 + ParentChecker(child->parent()); } return sum; } void QmitkXnatEditor::OnDataModelButtonClicked() { for(int i = m_ParentCount; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnProjectButtonClicked() { for(int i = m_ParentCount-1; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnSubjectButtonClicked() { for(int i = m_ParentCount-2; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnExperimentButtonClicked() { for(int i = m_ParentCount-3; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnKindOfDataButtonClicked() { for(int i = m_ParentCount-4; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnSessionButtonClicked() { for(int i = m_ParentCount-5; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnResourceButtonClicked() { for(int i = m_ParentCount-6; i > 0; i--) { ToHigherLevel(); } } + +void QmitkXnatEditor::UpdateSession() +{ + GetSite()->GetWorkbenchWindow()->GetSelectionService()->RemoveSelectionListener(m_SelectionListener); + + if(m_Session != 0 && m_Session->isOpen()) + { + m_ListModel->setRootObject(NULL); + m_Controls.treeView->reset(); + } + + // Get the XNAT Session from Activator + m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); + + if(m_Session != NULL) + { + m_Controls.labelInfo->setText("Current Position:"); + m_Controls.labelInfo->setStyleSheet("QLabel { color: black; }"); + m_Controls.buttonDownloadFile->setEnabled(true); + m_Controls.buttonDownloadResource->setEnabled(true); + + connect( this->m_Session, SIGNAL(aboutToBeClosed()), this, SLOT(UpdateSession()) ); + + // Fill model and show in the GUI + QmitkXnatObjectEditorInput::Pointer xoPtr = QmitkXnatObjectEditorInput::New( m_Session->dataModel() ); + berry::IEditorInput::Pointer editorInput( xoPtr ); + this->SetInput(editorInput); + this->GetEditorInput().Cast()->GetXnatObject()->fetch(); + UpdateList(); + } + else + { + m_Controls.labelInfo->setText("Please check the Preferences of the XNAT Connection.\nMaybe they are not ok. Close and reopen the tab."); + m_Controls.labelInfo->setStyleSheet("QLabel { color: red; }"); + m_Controls.buttonDownloadFile->setEnabled(false); + m_Controls.buttonDownloadResource->setEnabled(false); + } + + GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener(m_SelectionListener); +} diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.h index 9709681ffd..36cdebf47e 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.h @@ -1,123 +1,126 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKXNATEDITOR_h #define QMITKXNATEDITOR_h #include #include #include #include #include #include "ui_QmitkXnatEditorControls.h" #include "ctkXnatListModel.h" #include "ctkXnatSession.h" #include /*! \brief QmitkXnatEditor \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class QmitkXnatEditor : public berry::QtEditorPart, public berry::IReusableEditor { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: berryObjectMacro(QmitkXnatEditor) QmitkXnatEditor(); ~QmitkXnatEditor(); static const std::string EDITOR_ID; void CreateQtPartControl(QWidget *parent); void DoSave(/*IProgressMonitor monitor*/); void DoSaveAs(); void Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input); bool IsDirty() const; bool IsSaveAsAllowed() const; void SetInput(berry::IEditorInput::Pointer input); /** \brief Here the root object will be set and the view reset. Additionally the breadcrumbs will set visible. */ void UpdateList(); protected slots: /** \brief A resource folder will be downloaded to the chosen download path. */ void DownloadResource(); /** \brief A file will be downloaded to the chosen download path. */ void DownloadFile(); /** \brief Every time you activate a node in the list, the root item will be updated to a child of the previous parent.\ In exception of the node is a file. The file will be downloaded and loaded to the DataManager. */ void OnObjectActivated(const QModelIndex& index); // Breadcrumb button slots void OnDataModelButtonClicked(); void OnProjectButtonClicked(); void OnSubjectButtonClicked(); void OnExperimentButtonClicked(); void OnKindOfDataButtonClicked(); void OnSessionButtonClicked(); void OnResourceButtonClicked(); + /// \brief Updates the ctkXnatSession and the user interface + void UpdateSession(); + protected: virtual void SetFocus(); Ui::QmitkXnatEditorControls m_Controls; private: int m_ParentCount; QString m_DownloadPath; ctkServiceTracker m_DataStorageServiceTracker; void InternalFileDownload(const QModelIndex& index); int ParentChecker(ctkXnatObject* child); void ToHigherLevel(); ctkXnatListModel* m_ListModel; ctkXnatSession* m_Session; berry::ISelectionListener::Pointer m_SelectionListener; void SelectionChanged(berry::IWorkbenchPart::Pointer sourcepart, berry::ISelection::ConstPointer selection); }; #endif // QMITKXNATEDITOR_h diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditorControls.ui b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditorControls.ui index 5f13d15459..6fbb01a659 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditorControls.ui +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditorControls.ui @@ -1,460 +1,467 @@ QmitkXnatEditorControls 0 0 - 823 - 706 + 719 + 655 0 0 QmitkTemplate xnat_icon.icoxnat_icon.ico - + Current Position: 0 0 Server 0 0 >> 0 0 Project 0 0 >> 0 0 Subject 0 0 >> 0 0 Experiment 0 0 >> 0 0 Kind of Data 0 0 >> 0 0 Image Session 0 0 >> 0 0 Resource Folder Qt::Horizontal 40 20 6 QLayout::SetDefaultConstraint 0 0 0 Data Model true 0 0 >> 0 0 Qt::LeftToRight Project 0 0 >> 0 0 Subject 0 0 >> 0 0 Experiment 0 0 >> 0 0 Kind of Data 0 0 >> 0 0 Session 0 0 >> 0 0 Resource Qt::Horizontal 40 20 - - - (no function) + + + Qt::Horizontal - + + QSizePolicy::Minimum + + + + 250 + 20 + + + Download Folder Download File - - - + diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp index 2cfaa010b6..575d78396e 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp @@ -1,93 +1,83 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkXnatSessionManager.h" #include "berryPlatform.h" #include "berryIPreferences.h" #include "mitkLogMacros.h" #include #include #include "ctkXnatException.h" QmitkXnatSessionManager::QmitkXnatSessionManager() : m_Session(0) { m_PreferencesService = berry::Platform::GetServiceRegistry(). GetServiceById(berry::IPreferencesService::ID); - berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); - berry::IPreferences::Pointer nodeConnectionPref = prefService->GetSystemPreferences()->Node("/XnatConnection"); - - QUrl url(QString::fromStdString(nodeConnectionPref->Get("Server Address", ""))); - url.setPort(QString::fromStdString(nodeConnectionPref->Get("Port", "")).toInt()); - - ctkXnatLoginProfile profile; - profile.setName("Default"); - profile.setServerUrl(url); - profile.setUserName(QString::fromStdString(nodeConnectionPref->Get("Username", ""))); - profile.setPassword(QString::fromStdString(nodeConnectionPref->Get("Password", ""))); - profile.setDefault(true); - - m_Session = new ctkXnatSession(profile); + UpdateXnatSession(); } QmitkXnatSessionManager::~QmitkXnatSessionManager() { delete m_Session; } ctkXnatSession* QmitkXnatSessionManager::GetXnatSession() { if(m_Session == NULL) return NULL; if(!m_Session->isOpen()) { try { m_Session->open(); } catch(const ctkException& e) { MITK_ERROR << "Just look if your XNAT preferences are ok. Maybe the server is not running.\nTry to use 'Test Connection' funktionality.\n" << e.message().toStdString(); return NULL; } } return m_Session; } void QmitkXnatSessionManager::UpdateXnatSession() { - m_Session->deleteLater(); + if(m_Session != 0) + { + m_Session->deleteLater(); + } berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); berry::IPreferences::Pointer nodeConnectionPref = prefService->GetSystemPreferences()->Node("/XnatConnection"); QUrl url(QString::fromStdString(nodeConnectionPref->Get("Server Address", ""))); url.setPort(QString::fromStdString(nodeConnectionPref->Get("Port", "")).toInt()); ctkXnatLoginProfile profile; profile.setName("Default"); profile.setServerUrl(url); profile.setUserName(QString::fromStdString(nodeConnectionPref->Get("Username", ""))); profile.setPassword(QString::fromStdString(nodeConnectionPref->Get("Password", ""))); profile.setDefault(true); m_Session = new ctkXnatSession(profile); } diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp index 5b307f4efd..9f3b718a7d 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp @@ -1,124 +1,145 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkXnatTreeBrowserView.h" // Qmitk #include "QmitkXnatObjectEditorInput.h" #include "QmitkXnatEditor.h" #include "org_mitk_gui_qt_xnatinterface_Activator.h" // Blueberry #include // CTK XNAT Core #include "ctkXnatFile.h" const std::string QmitkXnatTreeBrowserView::VIEW_ID = "org.mitk.views.xnat.treebrowser"; QmitkXnatTreeBrowserView::QmitkXnatTreeBrowserView(): m_Session(0), m_TreeModel(new ctkXnatTreeModel()) { } QmitkXnatTreeBrowserView::~QmitkXnatTreeBrowserView() { delete m_TreeModel; } void QmitkXnatTreeBrowserView::SetFocus() { } void QmitkXnatTreeBrowserView::CreateQtPartControl( QWidget *parent ) { - // Get the XNAT Session from Activator - m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); - - if(m_Session == 0) - { - m_Controls.labelError->setText("Please check the Preferences of XNAT. Maybe they are not ok."); - m_Controls.labelError->setStyleSheet("QLabel { color: red; }"); - return; - } - // Create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); m_Controls.treeView->setModel(m_TreeModel); m_Controls.treeView->header()->hide(); + m_Controls.labelError->setText("Please check the Preferences of the XNAT Connection.\nMaybe they are not ok."); + m_Controls.labelError->setStyleSheet("QLabel { color: red; }"); m_SelectionProvider = new berry::QtSelectionProvider(); - m_SelectionProvider->SetItemSelectionModel(m_Controls.treeView->selectionModel()); this->SetSelectionProvider(); m_Controls.treeView->setSelectionMode(QAbstractItemView::SingleSelection); - connect( m_Controls.treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(OnActivatedNode(const QModelIndex&)) ); + UpdateSession(); + + if(m_Session == 0) + { + m_Controls.labelError->show(); + return; + } + else + { + m_Controls.labelError->hide(); + } - // Fill model and show in the GUI - m_TreeModel->addDataModel(m_Session->dataModel()); - m_Controls.treeView->reset(); + connect( m_Controls.treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(OnActivatedNode(const QModelIndex&)) ); } void QmitkXnatTreeBrowserView::OnActivatedNode(const QModelIndex& index) { if (!index.isValid()) return; berry::IWorkbenchPage::Pointer page = GetSite()->GetPage(); QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( index.data(Qt::UserRole).value() ); berry::IEditorInput::Pointer editorInput( oPtr ); berry::IEditorPart::Pointer reuseEditor = page->FindEditor(editorInput); if(reuseEditor) { // Just set it activ page->Activate(reuseEditor); } else { std::vector editors = page->FindEditors(berry::IEditorInput::Pointer(0), QmitkXnatEditor::EDITOR_ID, berry::IWorkbenchPage::MATCH_ID); if (editors.empty()) { // No XnatEditor is currently open, create a new one ctkXnatFile* file = dynamic_cast(oPtr->GetXnatObject()); if(file != NULL) { // If a file is activated take the parent and open a new editor QmitkXnatObjectEditorInput::Pointer oPtr2 = QmitkXnatObjectEditorInput::New( file->parent() ); berry::IEditorInput::Pointer editorInput2( oPtr2 ); page->OpenEditor(editorInput2, QmitkXnatEditor::EDITOR_ID); } else { page->OpenEditor(editorInput, QmitkXnatEditor::EDITOR_ID); } } else { // Reuse an existing editor reuseEditor = editors.front()->GetEditor(true); page->ReuseEditor(reuseEditor.Cast(), editorInput); page->Activate(reuseEditor); } } } void QmitkXnatTreeBrowserView::SetSelectionProvider() { GetSite()->SetSelectionProvider(m_SelectionProvider); } + +void QmitkXnatTreeBrowserView::UpdateSession() +{ + if(m_Session != 0 && m_Session->isOpen()) + { + m_TreeModel->removeDataModel(m_Session->dataModel()); + m_Controls.treeView->reset(); + } + + // Get the XNAT Session from Activator + m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); + + if(m_Session != NULL) + { + connect( this->m_Session, SIGNAL(aboutToBeClosed()), this, SLOT(UpdateSession()) ); + + // Fill model and show in the GUI + m_TreeModel->addDataModel(m_Session->dataModel()); + m_Controls.treeView->reset(); + m_SelectionProvider->SetItemSelectionModel(m_Controls.treeView->selectionModel()); + } +} diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h index 8c6de2b22c..d479113692 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h @@ -1,76 +1,78 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKXNATTREEBROWSERVIEW_H #define QMITKXNATTREEBROWSERVIEW_H #include #include #include "ui_QmitkXnatTreeBrowserViewControls.h" // ctkXnatCore #include "ctkXnatSession.h" // ctkXnatWidget #include "ctkXnatTreeModel.h" /*! \brief QmitkXnatTreeBrowserView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class QmitkXnatTreeBrowserView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: QmitkXnatTreeBrowserView(); ~QmitkXnatTreeBrowserView(); static const std::string VIEW_ID; virtual void CreateQtPartControl(QWidget *parent); - berry::QtSelectionProvider::Pointer m_SelectionProvider; - protected slots: /// \brief Opens or reuses the xnat editor with the activated node as root item. void OnActivatedNode(const QModelIndex& index); + /// \brief Updates the ctkXnatSession and the user interface + void UpdateSession(); + protected: virtual void SetFocus(); Ui::QmitkXnatTreeBrowserViewControls m_Controls; private: + berry::QtSelectionProvider::Pointer m_SelectionProvider; void SetSelectionProvider(); ctkXnatSession* m_Session; ctkXnatTreeModel* m_TreeModel; }; #endif // QMITKXNATTREEBROWSERVIEW_H