diff --git a/Plugins/org.mitk.gui.common/src/internal/org_mitk_gui_common_Activator.cpp b/Plugins/org.mitk.gui.common/src/internal/org_mitk_gui_common_Activator.cpp index d305cbe832..8ab0cd3681 100644 --- a/Plugins/org.mitk.gui.common/src/internal/org_mitk_gui_common_Activator.cpp +++ b/Plugins/org.mitk.gui.common/src/internal/org_mitk_gui_common_Activator.cpp @@ -1,35 +1,39 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "org_mitk_gui_common_Activator.h" +#include + +US_INITIALIZE_MODULE + namespace mitk { ctkPluginContext* org_mitk_gui_common_Activator::m_Context = nullptr; void org_mitk_gui_common_Activator::start(ctkPluginContext* context) { m_Context = context; } void org_mitk_gui_common_Activator::stop(ctkPluginContext* context) { Q_UNUSED(context) m_Context = nullptr; } ctkPluginContext *org_mitk_gui_common_Activator::GetContext() { return m_Context; } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDefaultDropTargetListener.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDefaultDropTargetListener.cpp index bbd6a6cde0..a21dfe6cd5 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDefaultDropTargetListener.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDefaultDropTargetListener.cpp @@ -1,86 +1,87 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkDefaultDropTargetListener.h" #include #include #include #include #include #include "internal/org_mitk_gui_qt_application_Activator.h" #include #include +#include #include #include class QmitkDefaultDropTargetListenerPrivate { public: mitk::IPreferences* GetPreferences() const { - auto* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService(); + auto* prefService = mitk::CoreServices::GetPreferencesService(); return prefService != nullptr ? prefService->GetSystemPreferences()->Node("/General") : nullptr; } bool GetOpenEditor() const { auto* prefs = GetPreferences(); return prefs != nullptr ? prefs->GetBool("OpenEditor", true) : true; } }; QmitkDefaultDropTargetListener::QmitkDefaultDropTargetListener() : berry::IDropTargetListener(), d(new QmitkDefaultDropTargetListenerPrivate()) { } QmitkDefaultDropTargetListener::~QmitkDefaultDropTargetListener() { } berry::IDropTargetListener::Events::Types QmitkDefaultDropTargetListener::GetDropTargetEventTypes() const { return Events::DROP; } void QmitkDefaultDropTargetListener::DropEvent(QDropEvent *event) { qDebug() << event->mimeData()->formats(); qDebug() << event->mimeData()->text(); QList fileNames = event->mimeData()->urls(); if (fileNames.empty()) return; QStringList fileNames2; foreach(QUrl url, fileNames) { fileNames2.push_back(url.toLocalFile()); } mitk::WorkbenchUtil::LoadFiles(fileNames2, berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(), d->GetOpenEditor()); event->accept(); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp index 0887b43a98..4b347b9af1 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp @@ -1,188 +1,189 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkFileOpenAction.h" #include "internal/org_mitk_gui_qt_application_Activator.h" #include #include #include +#include #include #include #include #include namespace { mitk::DataStorage::Pointer GetDataStorage() { auto context = mitk::org_mitk_gui_qt_application_Activator::GetContext(); if (nullptr == context) return nullptr; auto dataStorageServiceReference = context->getServiceReference(); if (!dataStorageServiceReference) return nullptr; auto dataStorageService = context->getService(dataStorageServiceReference); if (nullptr == dataStorageService) return nullptr; auto dataStorageReference = dataStorageService->GetDataStorage(); if (dataStorageReference.IsNull()) return nullptr; return dataStorageReference->GetDataStorage(); } mitk::DataNode::Pointer GetFirstSelectedNode() { auto dataStorage = GetDataStorage(); if (dataStorage.IsNull()) return nullptr; auto selectedNodes = dataStorage->GetSubset(mitk::NodePredicateProperty::New("selected", mitk::BoolProperty::New(true))); if (selectedNodes->empty()) return nullptr; return selectedNodes->front(); } QString GetPathOfFirstSelectedNode() { auto firstSelectedNode = GetFirstSelectedNode(); if (firstSelectedNode.IsNull()) return ""; auto data = firstSelectedNode->GetData(); if (nullptr == data) return ""; auto pathProperty = data->GetConstProperty("path"); if (pathProperty.IsNull()) return ""; return QFileInfo(QString::fromStdString(pathProperty->GetValueAsString())).canonicalPath(); } } class QmitkFileOpenActionPrivate { public: void Init(berry::IWorkbenchWindow* window, QmitkFileOpenAction* action) { m_Window = window; action->setText("&Open File..."); action->setToolTip("Open data files (images, surfaces,...)"); QObject::connect(action, SIGNAL(triggered(bool)), action, SLOT(Run())); } mitk::IPreferences* GetPreferences() const { - auto* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService(); + auto* prefService = mitk::CoreServices::GetPreferencesService(); return prefService != nullptr ? prefService->GetSystemPreferences()->Node("/General") : nullptr; } QString GetLastFileOpenPath() const { auto* prefs = GetPreferences(); return prefs != nullptr ? QString::fromStdString(prefs->Get("LastFileOpenPath", "")) : QString(); } void SetLastFileOpenPath(const QString& path) const { auto* prefs = GetPreferences(); if (prefs != nullptr) { prefs->Put("LastFileOpenPath", path.toStdString()); prefs->Flush(); } } bool GetOpenEditor() const { auto* prefs = GetPreferences(); return prefs != nullptr ? prefs->GetBool("OpenEditor", true) : true; } berry::IWorkbenchWindow* m_Window; }; QmitkFileOpenAction::QmitkFileOpenAction(berry::IWorkbenchWindow::Pointer window) : QAction(nullptr) , d(new QmitkFileOpenActionPrivate) { d->Init(window.GetPointer(), this); } QmitkFileOpenAction::QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window) : QAction(nullptr) , d(new QmitkFileOpenActionPrivate) { d->Init(window.GetPointer(), this); setIcon(icon); } QmitkFileOpenAction::QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow* window) : QAction(nullptr), d(new QmitkFileOpenActionPrivate) { d->Init(window, this); setIcon(icon); } QmitkFileOpenAction::~QmitkFileOpenAction() { } void QmitkFileOpenAction::Run() { auto path = GetPathOfFirstSelectedNode(); if (path.isEmpty()) path = d->GetLastFileOpenPath(); // Ask the user for a list of files to open QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, "Open", path, QmitkIOUtil::GetFileOpenFilterString()); if (fileNames.empty()) { return; } d->SetLastFileOpenPath(fileNames.front()); mitk::WorkbenchUtil::LoadFiles(fileNames, berry::IWorkbenchWindow::Pointer(d->m_Window), d->GetOpenEditor()); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp index 24aba232fb..58460a6b40 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp @@ -1,274 +1,275 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkFileSaveAction.h" #include "internal/org_mitk_gui_qt_application_Activator.h" #include #include #include +#include #include #include #include #include #include #include #include namespace { mitk::DataStorage::Pointer GetDataStorage() { auto context = mitk::org_mitk_gui_qt_application_Activator::GetContext(); if (nullptr == context) return nullptr; auto dataStorageServiceReference = context->getServiceReference(); if (!dataStorageServiceReference) return nullptr; auto dataStorageService = context->getService(dataStorageServiceReference); if (nullptr == dataStorageService) return nullptr; auto dataStorageReference = dataStorageService->GetDataStorage(); if (dataStorageReference.IsNull()) return nullptr; return dataStorageReference->GetDataStorage(); } QString GetParentPath(mitk::DataNode::Pointer dataNode) { if (dataNode.IsNull()) return ""; auto dataStorage = GetDataStorage(); if (dataStorage.IsNull()) return ""; auto sources = dataStorage->GetSources(dataNode); if (sources.IsNull() || sources->empty()) return ""; const auto &parentNode = sources->front(); if (parentNode.IsNull()) return ""; auto data = parentNode->GetData(); if (nullptr != data) { auto pathProperty = data->GetConstProperty("path"); if (pathProperty.IsNotNull()) return QFileInfo(QString::fromStdString(pathProperty->GetValueAsString())).canonicalPath(); } return GetParentPath(parentNode); } } class QmitkFileSaveActionPrivate { private: void HandleSelectionChanged(const berry::IWorkbenchPart::Pointer& /*part*/, const berry::ISelection::ConstPointer& selection) { this->SetEnabled(selection); } QScopedPointer m_SelectionListener; public: QmitkFileSaveActionPrivate() : m_SelectionListener(new berry::NullSelectionChangedAdapter( this, &QmitkFileSaveActionPrivate::HandleSelectionChanged)) { } ~QmitkFileSaveActionPrivate() { auto window = m_Window.Lock(); if (window.IsNotNull()) { window->GetSelectionService()->RemoveSelectionListener(m_SelectionListener.data()); } } void Init(berry::IWorkbenchWindow* window, QAction* action) { m_Window = berry::IWorkbenchWindow::Pointer(window); m_Action = action; m_Action->setText("&Save..."); m_Action->setToolTip("Save data objects (images, surfaces,...)"); berry::ISelectionService* selectionService = m_Window.Lock()->GetSelectionService(); SetEnabled(selectionService->GetSelection()); selectionService->AddSelectionListener(m_SelectionListener.data()); QObject::connect(m_Action, SIGNAL(triggered(bool)), m_Action, SLOT(Run())); } mitk::IPreferences* GetPreferences() const { - auto* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService(); + auto* prefService = mitk::CoreServices::GetPreferencesService(); return prefService != nullptr ? prefService->GetSystemPreferences()->Node("/General") : nullptr; } QString GetLastFileSavePath() const { auto* prefs = GetPreferences(); return prefs != nullptr ? QString::fromStdString(prefs->Get("LastFileSavePath", "")) : QString(); } void SetLastFileSavePath(const QString& path) const { auto* prefs = GetPreferences(); if (prefs != nullptr) { prefs->Put("LastFileSavePath", path.toStdString()); prefs->Flush(); } } void SetEnabled(berry::ISelection::ConstPointer selection) { mitk::DataNodeSelection::ConstPointer nodeSelection = selection.Cast(); if (nodeSelection.IsNotNull() && !selection->IsEmpty()) { bool enable = false; std::list dataNodes = nodeSelection->GetSelectedDataNodes(); for (std::list::const_iterator nodeIter = dataNodes.begin(), nodeIterEnd = dataNodes.end(); nodeIter != nodeIterEnd; ++nodeIter) { if ((*nodeIter)->GetData() != nullptr) { enable = true; break; } } m_Action->setEnabled(enable); } else { m_Action->setEnabled(false); } } berry::IWorkbenchWindow::WeakPtr m_Window; QAction* m_Action; }; QmitkFileSaveAction::QmitkFileSaveAction(berry::IWorkbenchWindow::Pointer window) : QAction(tr("Save...")) , d(new QmitkFileSaveActionPrivate) { d->Init(window.GetPointer(), this); } QmitkFileSaveAction::QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window) : QAction(tr("Save...")) , d(new QmitkFileSaveActionPrivate) { d->Init(window.GetPointer(), this); setIcon(icon); } QmitkFileSaveAction::QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow* window) : QAction(tr("Save...")) , d(new QmitkFileSaveActionPrivate) { d->Init(window, this); setIcon(icon); } QmitkFileSaveAction::~QmitkFileSaveAction() { } void QmitkFileSaveAction::Run() { // get the list of selected base data objects mitk::DataNodeSelection::ConstPointer selection = d->m_Window.Lock()->GetSelectionService()->GetSelection().Cast(); if (selection.IsNull() || selection->IsEmpty()) { MITK_ERROR << "Assertion failed: data node selection is nullptr or empty"; return; } std::list dataNodes = selection->GetSelectedDataNodes(); std::vector data; QStringList names; for (std::list::const_iterator nodeIter = dataNodes.begin(), nodeIterEnd = dataNodes.end(); nodeIter != nodeIterEnd; ++nodeIter) { data.push_back((*nodeIter)->GetData()); std::string name; (*nodeIter)->GetStringProperty("name", name); names.push_back(QString::fromStdString(name)); } QString path; if (1 == data.size()) { if (nullptr != data[0]) { auto pathProperty = data[0]->GetConstProperty("path"); if (pathProperty.IsNotNull()) path = QFileInfo(QString::fromStdString(pathProperty->GetValueAsString())).canonicalPath(); } if (path.isEmpty()) path = GetParentPath(dataNodes.front()); } if (path.isEmpty()) path = d->GetLastFileSavePath(); try { auto setPathProperty = true; auto fileNames = QmitkIOUtil::Save(data, names, path, d->m_Action->parentWidget(), setPathProperty); if (!fileNames.empty()) d->SetLastFileSavePath(QFileInfo(fileNames.back()).absolutePath()); } catch (const mitk::Exception& e) { MITK_INFO << e; return; } } diff --git a/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.cpp b/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.cpp index d34efacf4d..38ce44d27b 100644 --- a/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.cpp @@ -1,69 +1,52 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "org_mitk_gui_qt_application_Activator.h" -#include - #include "QmitkGeneralPreferencePage.h" #include "QmitkEditorsPreferencePage.h" #include #include "QmitkShowPreferencePageHandler.h" #include US_INITIALIZE_MODULE namespace mitk { - - org_mitk_gui_qt_application_Activator* org_mitk_gui_qt_application_Activator::m_Instance = nullptr; ctkPluginContext* org_mitk_gui_qt_application_Activator::m_Context = nullptr; void org_mitk_gui_qt_application_Activator::start(ctkPluginContext* context) { - this->m_Instance = this; - this->m_Context = context; + m_Context = context; BERRY_REGISTER_EXTENSION_CLASS(QmitkGeneralPreferencePage, context) BERRY_REGISTER_EXTENSION_CLASS(QmitkEditorsPreferencePage, context) BERRY_REGISTER_EXTENSION_CLASS(QmitkShowPreferencePageHandler, context) QmitkRegisterClasses(); } void org_mitk_gui_qt_application_Activator::stop(ctkPluginContext* context) { Q_UNUSED(context) - - this->m_Context = nullptr; - this->m_Instance = nullptr; + m_Context = nullptr; } ctkPluginContext* org_mitk_gui_qt_application_Activator::GetContext() { return m_Context; } - org_mitk_gui_qt_application_Activator *org_mitk_gui_qt_application_Activator::GetInstance() - { - return m_Instance; - } - - mitk::IPreferencesService* org_mitk_gui_qt_application_Activator::GetPreferencesService() - { - return mitk::CoreServices::GetPreferencesService(); - } - } diff --git a/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.h b/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.h index cb4d6d4948..4d51edfe83 100644 --- a/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.h +++ b/Plugins/org.mitk.gui.qt.application/src/internal/org_mitk_gui_qt_application_Activator.h @@ -1,50 +1,45 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef MITKPLUGINACTIVATOR_H #define MITKPLUGINACTIVATOR_H #include namespace mitk { -class IPreferencesService; - class org_mitk_gui_qt_application_Activator : public QObject, public ctkPluginActivator { Q_OBJECT Q_PLUGIN_METADATA(IID "org_mitk_gui_qt_application") Q_INTERFACES(ctkPluginActivator) public: void start(ctkPluginContext* context) override; void stop(ctkPluginContext* context) override; static ctkPluginContext* GetContext(); - static org_mitk_gui_qt_application_Activator* GetInstance(); - - mitk::IPreferencesService* GetPreferencesService(); private: - static org_mitk_gui_qt_application_Activator* m_Instance; static ctkPluginContext* m_Context; -}; // org_mitk_gui_common_Activator + +}; // org_mitk_gui_qt_application_Activator typedef org_mitk_gui_qt_application_Activator PluginActivator; } #endif // MITKPLUGINACTIVATOR_H