diff --git a/Modules/QtWidgets/include/QmitkNodeDescriptorManager.h b/Modules/QtWidgets/include/QmitkNodeDescriptorManager.h index 924be1623b..8b8024a523 100644 --- a/Modules/QtWidgets/include/QmitkNodeDescriptorManager.h +++ b/Modules/QtWidgets/include/QmitkNodeDescriptorManager.h @@ -1,117 +1,118 @@ /*=================================================================== 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 QmitkNodeDescriptorManager_h #define QmitkNodeDescriptorManager_h #include #include "QmitkNodeDescriptor.h" /** * \ingroup QmitkModule * \brief QmitkNodeDescriptorManager manages a set of QmitkNodeDescriptors * * \sa QmitkNodeDescriptor */ class MITKQTWIDGETS_EXPORT QmitkNodeDescriptorManager : public QObject { Q_OBJECT + public: /// /// \return the solely instance of QmitkNodeDescriptorManager /// - static QmitkNodeDescriptorManager *GetInstance(); + static QmitkNodeDescriptorManager* GetInstance(); /// /// Initializes the QmitkNodeDescriptorManager. /// Adds a few standard Descriptors. /// This Descriptors are added: /// - A QmitkNodeDescriptor for the class of "Image" DataNodes /// - A QmitkNodeDescriptor for the class of "Image Mask" DataNodes /// - A QmitkNodeDescriptor for the class of "Surface" DataNodes /// - A QmitkNodeDescriptor for the class of "PointSet" DataNodes /// virtual void Initialize(); /// /// Adds a new descriptor to the manager. The manager takes the ownership. /// - void AddDescriptor(QmitkNodeDescriptor *_Descriptor); + void AddDescriptor(QmitkNodeDescriptor* descriptor); /// /// Removes and deletes a descriptor from the manager /// - void RemoveDescriptor(QmitkNodeDescriptor *_Descriptor); + void RemoveDescriptor(QmitkNodeDescriptor* descriptor); /// /// Get the last descriptor in the descriptors list that matches the given node. /// *Attention*: More specialized Descriptors should therefore be appended at /// the end of the list, e.g. first add "Image", then add "Image Mask" /// /// \return a QmitkNodeDescriptor for the given node or a QmitkNodeDescriptor describing unknown nodes (never 0) /// \sa AddDescriptor() /// - QmitkNodeDescriptor *GetDescriptor(const mitk::DataNode *_Node) const; + QmitkNodeDescriptor* GetDescriptor(const mitk::DataNode* node) const; /// /// Get the last QmitkNodeDescriptor for the given class name /// /// \return a QmitkNodeDescriptor for the given class name or 0 if there is no QmitkNodeDescriptor for _ClassName /// - QmitkNodeDescriptor *GetDescriptor(const QString &_ClassName) const; + QmitkNodeDescriptor* GetDescriptor(const QString& className) const; /// /// \return The UnknownDataNodeDescriptor, which is the default Descriptor for all Nodes. /// - QmitkNodeDescriptor *GetUnknownDataNodeDescriptor() const; + QmitkNodeDescriptor* GetUnknownDataNodeDescriptor() const; /// /// Returns a list of all actions that are associated with the given node. /// If there are more than one Descriptors for this node all actions /// will be merged together. /// E.g. all actions from the "unknown" DataNodes will be added to /// this list. Generic Actions like Save, Load, etc. are stored there. /// - QList GetActions(const mitk::DataNode *_Node) const; + QList GetActions(const mitk::DataNode* node) const; /// /// \return a list of actions associated with the given nodes /// - QList GetActions(const QList &_Nodes) const; + QList GetActions(const QList& nodes) const; /// /// Deletes all Descriptors in the list /// ~QmitkNodeDescriptorManager() override; protected: /// /// Creates the m_UnknownDataNodeDescriptor /// Calls Initialize /// QmitkNodeDescriptorManager(); protected: /// /// This is the standard QmitkNodeDescriptor matching every node /// - QmitkNodeDescriptor *m_UnknownDataNodeDescriptor; + QmitkNodeDescriptor* m_UnknownDataNodeDescriptor; /// /// Holds all user defined descriptors /// - QList m_NodeDescriptors; + QList m_NodeDescriptors; }; #endif // QmitkNodeDescriptorManager_h diff --git a/Modules/QtWidgets/src/QmitkNodeDescriptorManager.cpp b/Modules/QtWidgets/src/QmitkNodeDescriptorManager.cpp index 1a7b67c88c..c8d380adac 100644 --- a/Modules/QtWidgets/src/QmitkNodeDescriptorManager.cpp +++ b/Modules/QtWidgets/src/QmitkNodeDescriptorManager.cpp @@ -1,180 +1,175 @@ /*=================================================================== 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 "QmitkNodeDescriptorManager.h" #include #include #include #include #include #include #include #include -QmitkNodeDescriptorManager *QmitkNodeDescriptorManager::GetInstance() +QmitkNodeDescriptorManager* QmitkNodeDescriptorManager::GetInstance() { - static QmitkNodeDescriptorManager _Instance; - return &_Instance; + static QmitkNodeDescriptorManager instance; + return &instance; } void QmitkNodeDescriptorManager::Initialize() { auto isImage = mitk::NodePredicateDataType::New("Image"); - this->AddDescriptor(new QmitkNodeDescriptor(tr("Image"), QString(":/Qmitk/Images_48.png"), isImage, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("Image"), QString(":/Qmitk/Images_48.png"), isImage, this)); - auto isMultiComponentImage = - mitk::NodePredicateAnd::New(isImage, mitk::NodePredicateProperty::New("Image.Displayed Component")); - this->AddDescriptor(new QmitkNodeDescriptor( - tr("MultiComponentImage"), QString(": / Qmitk / Images_48.png"), isMultiComponentImage, this)); + auto isMultiComponentImage = mitk::NodePredicateAnd::New(isImage, mitk::NodePredicateProperty::New("Image.Displayed Component")); + AddDescriptor(new QmitkNodeDescriptor(tr("MultiComponentImage"), QString(": / Qmitk / Images_48.png"), isMultiComponentImage, this)); auto isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)); auto isBinaryImage = mitk::NodePredicateAnd::New(isBinary, isImage); - this->AddDescriptor( - new QmitkNodeDescriptor(tr("ImageMask"), QString(":/Qmitk/Binaerbilder_48.png"), isBinaryImage, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("ImageMask"), QString(":/Qmitk/Binaerbilder_48.png"), isBinaryImage, this)); auto isLabelSetImage = mitk::NodePredicateDataType::New("LabelSetImage"); - this->AddDescriptor( - new QmitkNodeDescriptor(tr("LabelSetImage"), QString(":/Qmitk/LabelSetImage_48.png"), isLabelSetImage, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("LabelSetImage"), QString(":/Qmitk/LabelSetImage_48.png"), isLabelSetImage, this)); auto isPointSet = mitk::NodePredicateDataType::New("PointSet"); - this->AddDescriptor(new QmitkNodeDescriptor(tr("PointSet"), QString(":/Qmitk/PointSet_48.png"), isPointSet, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("PointSet"), QString(":/Qmitk/PointSet_48.png"), isPointSet, this)); auto isSurface = mitk::NodePredicateDataType::New("Surface"); - this->AddDescriptor(new QmitkNodeDescriptor(tr("Surface"), QString(":/Qmitk/Surface_48.png"), isSurface, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("Surface"), QString(":/Qmitk/Surface_48.png"), isSurface, this)); auto isNotBinary = mitk::NodePredicateNot::New(isBinary); auto isNoneBinaryImage = mitk::NodePredicateAnd::New(isImage, isNotBinary); - this->AddDescriptor( - new QmitkNodeDescriptor(tr("NoneBinaryImage"), QString(":/Qmitk/Images_48.png"), isNoneBinaryImage, this)); + AddDescriptor(new QmitkNodeDescriptor(tr("NoneBinaryImage"), QString(":/Qmitk/Images_48.png"), isNoneBinaryImage, this)); } -void QmitkNodeDescriptorManager::AddDescriptor(QmitkNodeDescriptor *_Descriptor) +void QmitkNodeDescriptorManager::AddDescriptor(QmitkNodeDescriptor* descriptor) { - _Descriptor->setParent(this); - m_NodeDescriptors.push_back(_Descriptor); + descriptor->setParent(this); + m_NodeDescriptors.push_back(descriptor); } -void QmitkNodeDescriptorManager::RemoveDescriptor(QmitkNodeDescriptor *_Descriptor) +void QmitkNodeDescriptorManager::RemoveDescriptor(QmitkNodeDescriptor* descriptor) { - int index = m_NodeDescriptors.indexOf(_Descriptor); + int index = m_NodeDescriptors.indexOf(descriptor); if (index != -1) { m_NodeDescriptors.removeAt(index); - _Descriptor->setParent(nullptr); - delete _Descriptor; + descriptor->setParent(nullptr); + delete descriptor; } } -QmitkNodeDescriptor *QmitkNodeDescriptorManager::GetDescriptor(const mitk::DataNode *_Node) const +QmitkNodeDescriptor* QmitkNodeDescriptorManager::GetDescriptor(const mitk::DataNode* node) const { - QmitkNodeDescriptor *_Descriptor = m_UnknownDataNodeDescriptor; + QmitkNodeDescriptor* descriptor = m_UnknownDataNodeDescriptor; for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { - if ((*it)->CheckNode(_Node)) - _Descriptor = *it; + if ((*it)->CheckNode(node)) + descriptor = *it; } - return _Descriptor; + return descriptor; } -QmitkNodeDescriptor *QmitkNodeDescriptorManager::GetDescriptor(const QString &_ClassName) const +QmitkNodeDescriptor* QmitkNodeDescriptorManager::GetDescriptor(const QString& className) const { - QmitkNodeDescriptor *_Descriptor = nullptr; + QmitkNodeDescriptor* descriptor = nullptr; - if (_ClassName == "Unknown") + if (className == "Unknown") { return m_UnknownDataNodeDescriptor; } else { - for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); - ++it) + for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { - if ((*it)->GetNameOfClass() == _ClassName) - _Descriptor = *it; + if ((*it)->GetNameOfClass() == className) + descriptor = *it; } } - return _Descriptor; + return descriptor; } -QList QmitkNodeDescriptorManager::GetActions(const mitk::DataNode *_Node) const + +QList QmitkNodeDescriptorManager::GetActions(const mitk::DataNode* node) const { - QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); + QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); actions.append(m_UnknownDataNodeDescriptor->GetActions()); - QmitkNodeDescriptor *lastDescriptor = m_UnknownDataNodeDescriptor; + QmitkNodeDescriptor* lastDescriptor = m_UnknownDataNodeDescriptor; for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { - if ((*it)->CheckNode(_Node)) + if ((*it)->CheckNode(node)) { actions.append(lastDescriptor->GetSeparator()); lastDescriptor = *it; actions.append(lastDescriptor->GetBatchActions()); actions.append(lastDescriptor->GetActions()); } } return actions; } -QList QmitkNodeDescriptorManager::GetActions(const QList &_Nodes) const +QList QmitkNodeDescriptorManager::GetActions(const QList& nodes) const { - QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); - QSet nodeDescriptors; - QmitkNodeDescriptor *lastDescriptor; + QList actions = m_UnknownDataNodeDescriptor->GetBatchActions(); + QmitkNodeDescriptor* lastDescriptor = m_UnknownDataNodeDescriptor; // find all descriptors for the nodes (unique) - foreach (mitk::DataNode::Pointer node, _Nodes) + QSet nodeDescriptors; + for (const auto& node : nodes) { - for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) + for (QList::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it) { if ((*it)->CheckNode(node)) { nodeDescriptors.insert(*it); } } } + // add all actions for the found descriptors - lastDescriptor = m_UnknownDataNodeDescriptor; - foreach (QmitkNodeDescriptor *descr, nodeDescriptors) + for (const auto& nodeDescriptor : nodeDescriptors) { actions.append(lastDescriptor->GetSeparator()); - lastDescriptor = descr; + lastDescriptor = nodeDescriptor; actions.append(lastDescriptor->GetBatchActions()); } return actions; } QmitkNodeDescriptorManager::QmitkNodeDescriptorManager() : m_UnknownDataNodeDescriptor(new QmitkNodeDescriptor("Unknown", QString(":/Qmitk/DataTypeUnknown_48.png"), nullptr, this)) { - this->Initialize(); + Initialize(); } QmitkNodeDescriptorManager::~QmitkNodeDescriptorManager() { // delete m_UnknownDataNodeDescriptor; // qDeleteAll(m_NodeDescriptors); } QmitkNodeDescriptor *QmitkNodeDescriptorManager::GetUnknownDataNodeDescriptor() const { return m_UnknownDataNodeDescriptor; } diff --git a/Plugins/org.mitk.gui.qt.application/CMakeLists.txt b/Plugins/org.mitk.gui.qt.application/CMakeLists.txt index 15c4e7f713..04efa26bd0 100644 --- a/Plugins/org.mitk.gui.qt.application/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.application/CMakeLists.txt @@ -1,9 +1,9 @@ project(org_mitk_gui_qt_application) mitk_create_plugin( EXPORT_DIRECTIVE MITK_QT_APP EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDS MitkQtWidgets + MODULE_DEPENDS MitkQtWidgets MitkQtWidgetsExt PACKAGE_DEPENDS Qt5|OpenGL+Xml SUBPROJECTS MITK-CoreUI ) diff --git a/Plugins/org.mitk.gui.qt.application/files.cmake b/Plugins/org.mitk.gui.qt.application/files.cmake index bcd9b22a2e..19301027e2 100644 --- a/Plugins/org.mitk.gui.qt.application/files.cmake +++ b/Plugins/org.mitk.gui.qt.application/files.cmake @@ -1,55 +1,85 @@ set(SRC_CPP_FILES + QmitkAbstractDataNodeAction.cpp QmitkCloseProjectAction.cpp + QmitkDataNodeColorAction.cpp + QmitkDataNodeColorMapAction.cpp + QmitkDataNodeComponentAction.cpp + QmitkDataNodeContextMenu.cpp + QmitkDataNodeGlobalReinitAction.cpp + QmitkDataNodeHideAllNodesAction.cpp + QmitkDataNodeOpacityAction.cpp + QmitkDataNodeReinitAction.cpp + QmitkDataNodeRemoveAction.cpp + QmitkDataNodeShowDetailsAction.cpp + QmitkDataNodeShowSelectedNodesAction.cpp + QmitkDataNodeSurfaceRepresentationAction.cpp + QmitkDataNodeTextureInterpolationAction.cpp + QmitkDataNodeToggleVisibilityAction.cpp QmitkDefaultDropTargetListener.cpp QmitkFileExitAction.cpp QmitkFileOpenAction.cpp QmitkFileSaveAction.cpp QmitkUndoAction.cpp QmitkRedoAction.cpp QmitkPreferencesDialog.cpp QmitkStatusBar.cpp ) set(INTERNAL_CPP_FILES org_mitk_gui_qt_application_Activator.cpp QmitkEditorsPreferencePage.cpp QmitkGeneralPreferencePage.cpp QmitkShowPreferencePageHandler.cpp ) set(MOC_H_FILES + src/QmitkAbstractDataNodeAction.h src/QmitkCloseProjectAction.h + src/QmitkDataNodeColorAction.h + src/QmitkDataNodeColorMapAction.h + src/QmitkDataNodeComponentAction.h + src/QmitkDataNodeGlobalReinitAction.h + src/QmitkDataNodeContextMenu.h + src/QmitkDataNodeHideAllNodesAction.h + src/QmitkDataNodeOpacityAction.h + src/QmitkDataNodeReinitAction.h + src/QmitkDataNodeRemoveAction.h + src/QmitkDataNodeShowDetailsAction.h + src/QmitkDataNodeShowSelectedNodesAction.h + src/QmitkDataNodeSurfaceRepresentationAction.h + src/QmitkDataNodeTextureInterpolationAction.h + src/QmitkDataNodeToggleVisibilityAction.h src/QmitkFileExitAction.h src/QmitkFileOpenAction.h src/QmitkFileSaveAction.h src/QmitkUndoAction.h src/QmitkRedoAction.h src/QmitkPreferencesDialog.h src/internal/org_mitk_gui_qt_application_Activator.h src/internal/QmitkEditorsPreferencePage.h src/internal/QmitkGeneralPreferencePage.h src/internal/QmitkShowPreferencePageHandler.h ) set(UI_FILES src/QmitkPreferencesDialog.ui ) set(CACHED_RESOURCE_FILES plugin.xml ) set(QRC_FILES resources/resources.qrc ) set(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp new file mode 100644 index 0000000000..f0efa77163 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp @@ -0,0 +1,92 @@ +/*=================================================================== + +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 + +#include "mitkIRenderWindowPart.h" + +// mitk gui common plugin +#include + +// berry +#include + +QmitkAbstractDataNodeAction::QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite) +{ + m_WorkbenchPartSite = workbenchPartSite; +} + +QmitkAbstractDataNodeAction::QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite* workbenchPartSite) +{ + m_WorkbenchPartSite = berry::IWorkbenchPartSite::Pointer(workbenchPartSite); +} + +QmitkAbstractDataNodeAction::~QmitkAbstractDataNodeAction() +{ + // nothing here +} + +void QmitkAbstractDataNodeAction::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + // set the new data storage + m_DataStorage = dataStorage; + } +} + +void QmitkAbstractDataNodeAction::InitializeWithDataNode(const mitk::DataNode* dataNode) +{ + // can be overwritten in sub classes +} + +QList QmitkAbstractDataNodeAction::GetSelectedNodes() +{ + QList selectedNodes; + if (m_WorkbenchPartSite.Expired()) + { + return selectedNodes; + } + + berry::ISelection::ConstPointer selection = m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); + mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); + + if (currentSelection.IsNull() || currentSelection->IsEmpty()) + { + return selectedNodes; + } + + selectedNodes = QList::fromStdList(currentSelection->GetSelectedDataNodes()); + return selectedNodes; +} + +mitk::DataNode::Pointer QmitkAbstractDataNodeAction::GetSelectedNode() +{ + QList selectedNodes = GetSelectedNodes(); + if (selectedNodes.empty()) + { + return nullptr; + } + + // no batch action; should only be called with a single node + mitk::DataNode::Pointer dataNode = selectedNodes.front(); + if (nullptr == dataNode) + { + return nullptr; + } + + return dataNode; +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h new file mode 100644 index 0000000000..b6f233df03 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h @@ -0,0 +1,57 @@ +/*=================================================================== + +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 QMITKABSTRACTDATANODEACTION_H +#define QMITKABSTRACTDATANODEACTION_H + +#include + +// mitk core +#include +#include + +// berry +#include + +// qt +#include + +class MITK_QT_APP QmitkAbstractDataNodeAction +{ + +public: + + QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkAbstractDataNodeAction(); + + virtual void SetDataStorage(mitk::DataStorage* dataStorage); + + virtual void InitializeWithDataNode(const mitk::DataNode* dataNode); + +protected: + + virtual void InitializeAction() = 0; + mitk::DataNode::Pointer GetSelectedNode(); + QList GetSelectedNodes(); + + berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; + mitk::WeakPointer m_DataStorage; + +}; + +#endif // QMITKABSTRACTDATANODEACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp new file mode 100644 index 0000000000..08facb9981 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp @@ -0,0 +1,130 @@ +/*=================================================================== + +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 + +// mitk core +#include + +// qt +#include +#include +#include + +QmitkDataNodeColorAction::QmitkDataNodeColorAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(workbenchPartSite) +{ + InitializeAction(); +} + +QmitkDataNodeColorAction::QmitkDataNodeColorAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) +{ + InitializeAction(); +} + +QmitkDataNodeColorAction::~QmitkDataNodeColorAction() +{ + // nothing here +} + +void QmitkDataNodeColorAction::InitializeAction() +{ + m_ColorButton = new QPushButton; + m_ColorButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + connect(m_ColorButton, &QPushButton::clicked, this, &QmitkDataNodeColorAction::OnColorChanged); + + QLabel* colorLabel = new QLabel(tr("Color: ")); + colorLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + QHBoxLayout* colorWidgetLayout = new QHBoxLayout; + colorWidgetLayout->setContentsMargins(4, 4, 4, 4); + colorWidgetLayout->addWidget(colorLabel); + colorWidgetLayout->addWidget(m_ColorButton); + + QWidget* colorWidget = new QWidget; + colorWidget->setLayout(colorWidgetLayout); + + setDefaultWidget(colorWidget); + + connect(this, &QmitkDataNodeColorAction::changed, this, &QmitkDataNodeColorAction::OnActionChanged); +} + +void QmitkDataNodeColorAction::InitializeWithDataNode(const mitk::DataNode* dataNode) +{ + float rgb[3]; + if (dataNode->GetColor(rgb)) + { + QColor color(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); + QString styleSheet = QString("background-color: ") + color.name(QColor::HexRgb); + m_ColorButton->setAutoFillBackground(true); + m_ColorButton->setStyleSheet(styleSheet); + } +} + +void QmitkDataNodeColorAction::OnColorChanged() +{ + bool selectedColor = false; + QColor newColor; + + auto selectedNodes = GetSelectedNodes(); + for (auto& dataNode : selectedNodes) + { + if (dataNode.IsNull()) + { + continue; + } + + float rgb[3]; + if (dataNode->GetColor(rgb)) + { + if (!selectedColor) + { + QColor initial(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); + newColor = QColorDialog::getColor(initial, nullptr, QString(tr("Change color"))); + + if (newColor.isValid()) + { + selectedColor = true; + } + else + { + return; + } + } + + dataNode->SetProperty("color", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); + if (dataNode->GetProperty("binaryimage.selectedcolor")) + { + dataNode->SetProperty("binaryimage.selectedcolor", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); + } + } + } + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} + +void QmitkDataNodeColorAction::OnActionChanged() +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + InitializeWithDataNode(dataNode); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.h new file mode 100644 index 0000000000..01a9dfffb6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.h @@ -0,0 +1,56 @@ +/*=================================================================== + +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 QMITKDATANODECOLORACTION_H +#define QMITKDATANODECOLORACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include +#include + +class MITK_QT_APP QmitkDataNodeColorAction : public QWidgetAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeColorAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeColorAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeColorAction() override; + + virtual void InitializeWithDataNode(const mitk::DataNode* dataNode) override; + +private Q_SLOTS: + + void OnColorChanged(); + void OnActionChanged(); + +protected: + + virtual void InitializeAction() override; + +private: + + QPushButton* m_ColorButton; + +}; + +#endif // QMITKDATANODECOLORACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp new file mode 100644 index 0000000000..8ca6eccd9e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp @@ -0,0 +1,141 @@ +/*=================================================================== + +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 + +// mitk core +#include +#include +#include +#include +#include + +// mitk gui common plugin +#include + +// berry +#include + +// qt +#include + +QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Colormap")); + InitializeAction(); +} + +QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QObject* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Colormap")); + InitializeAction(); +} + +QmitkDataNodeColorMapAction::~QmitkDataNodeColorMapAction() +{ + // nothing here +} + +void QmitkDataNodeColorMapAction::InitializeAction() +{ + setCheckable(true); + + setMenu(new QMenu); + connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeColorMapAction::OnMenuAboutShow); +} + +void QmitkDataNodeColorMapAction::OnMenuAboutShow() +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable")); + if (lookupTableProperty.IsNull()) + { + mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); + lookupTableProperty = mitk::LookupTableProperty::New(); + lookupTableProperty->SetLookupTable(mitkLut); + dataNode->SetProperty("LookupTable", lookupTableProperty); + } + + mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); + if (lookupTable.IsNull()) + { + return; + } + + menu()->clear(); + QAction* tmp; + + int i = 0; + std::string lutType = lookupTable->typenameList[i]; + + while (lutType != "END_OF_ARRAY") + { + tmp = menu()->addAction(QString::fromStdString(lutType)); + tmp->setCheckable(true); + + if (lutType == lookupTable->GetActiveTypeAsString()) + { + tmp->setChecked(true); + } + + connect(tmp, &QAction::triggered, this, &QmitkDataNodeColorMapAction::OnActionTriggered); + + lutType = lookupTable->typenameList[++i]; + } +} + +void QmitkDataNodeColorMapAction::OnActionTriggered(bool checked) +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable")); + if (lookupTableProperty.IsNull()) + { + return; + } + + mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); + if (lookupTable.IsNull()) + { + return; + } + + QAction* senderAction = qobject_cast(QObject::sender()); + if (nullptr == senderAction) + { + return; + } + + std::string activatedItem = senderAction->text().toStdString(); + lookupTable->SetType(activatedItem); + lookupTableProperty->SetValue(lookupTable); + mitk::RenderingModeProperty::Pointer renderingMode = dynamic_cast(dataNode->GetProperty("Image Rendering.Mode")); + renderingMode->SetValue(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h new file mode 100644 index 0000000000..527a905e3e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h @@ -0,0 +1,49 @@ +/*=================================================================== + +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 QMITKDATANODECOLORMAPACTION_H +#define QMITKDATANODECOLORMAPACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeColorMapAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeColorMapAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeColorMapAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeColorMapAction() override; + +private Q_SLOTS: + + void OnMenuAboutShow(); + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODECOLORMAPACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp new file mode 100644 index 0000000000..79ea415c8e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp @@ -0,0 +1,111 @@ +/*=================================================================== + +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 + +// mitk core +#include +#include +#include + +// mitk gui common plugin +#include + +// berry +#include + +// qt +#include +#include + +QmitkDataNodeComponentAction::QmitkDataNodeComponentAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + InitializeAction(); +} + +QmitkDataNodeComponentAction::QmitkDataNodeComponentAction(QObject* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + InitializeAction(); +} + +QmitkDataNodeComponentAction::~QmitkDataNodeComponentAction() +{ + // nothing here +} + +void QmitkDataNodeComponentAction::InitializeAction() +{ + setCheckable(true); + + m_ComponentSlider = new QmitkNumberPropertySlider; + m_ComponentSlider->setOrientation(Qt::Horizontal); + + QLabel* componentLabel = new QLabel(tr("Component: ")); + QHBoxLayout* componentWidgetLayout = new QHBoxLayout; + componentWidgetLayout->setContentsMargins(4, 4, 4, 4); + componentWidgetLayout->addWidget(componentLabel); + componentWidgetLayout->addWidget(m_ComponentSlider); + QLabel* componentValueLabel = new QLabel(); + componentWidgetLayout->addWidget(componentValueLabel); + connect(m_ComponentSlider, &QmitkNumberPropertySlider::valueChanged, componentValueLabel, static_cast(&QLabel::setNum)); + + QWidget* componentWidget = new QWidget; + componentWidget->setLayout(componentWidgetLayout); + + setDefaultWidget(componentWidget); + + connect(this, &QmitkDataNodeComponentAction::changed, this, &QmitkDataNodeComponentAction::OnActionChanged); +} + +void QmitkDataNodeComponentAction::InitializeWithDataNode(const mitk::DataNode* dataNode) +{ + if (nullptr == dataNode) + { + m_ComponentSlider->SetProperty(static_cast(nullptr)); + return; + } + + mitk::Image* img = dynamic_cast(dataNode->GetData()); + if (nullptr == img) + { + m_ComponentSlider->SetProperty(static_cast(nullptr)); + return; + } + + int numComponents = 0; + numComponents = img->GetPixelType().GetNumberOfComponents(); + mitk::IntProperty* componentProperty = dynamic_cast(dataNode->GetProperty("Image.Displayed Component")); + if (numComponents <= 1 || nullptr == componentProperty) + { + m_ComponentSlider->SetProperty(static_cast(nullptr)); + return; + } + + m_ComponentSlider->SetProperty(componentProperty); + m_ComponentSlider->setMinValue(0); + m_ComponentSlider->setMaxValue(numComponents - 1); +} + +void QmitkDataNodeComponentAction::OnActionChanged() +{ + auto dataNode = GetSelectedNode(); + + InitializeWithDataNode(dataNode); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.h new file mode 100644 index 0000000000..829af08109 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.h @@ -0,0 +1,57 @@ +/*=================================================================== + +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 QMITKDATANODECOMPONENTACTION_H +#define QMITKDATANODECOMPONENTACTION_H + +#include + +// qt widgets ext module +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeComponentAction : public QWidgetAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeComponentAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeComponentAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeComponentAction() override; + + virtual void InitializeWithDataNode(const mitk::DataNode* dataNode) override; + +private Q_SLOTS: + + void OnActionChanged(); + +protected: + + virtual void InitializeAction() override; + +private: + + QmitkNumberPropertySlider* m_ComponentSlider; + +}; + +#endif // QMITKDATANODECOMPONENTACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp new file mode 100644 index 0000000000..cef369037f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp @@ -0,0 +1,496 @@ +/*=================================================================== + +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 "QmitkDataNodeContextMenu.h" + +// mitk gui qt application plugin +#include "mitkIContextMenuAction.h" +#include "QmitkFileSaveAction.h" + +// mitk gui common plugin +#include + +// qt widgets module +#include +#include + +// berry +#include +#include +#include +#include +#include + +QmitkDataNodeContextMenu::QmitkDataNodeContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent) + : QMenu(parent) +{ + m_Parent = parent; + m_WorkbenchPartSite = workbenchPartSite; + + InitNodeDescriptors(); + InitDefaultActions(); + InitExtensionPointActions(); +} + +QmitkDataNodeContextMenu::~QmitkDataNodeContextMenu() +{ + // remove the registered actions from each descriptor + for (std::vector>::iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) + { + (it->first)->RemoveAction(it->second); + } +} + +void QmitkDataNodeContextMenu::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + // set the new data storage - also for all actions + m_DataStorage = dataStorage; + for (std::vector>::iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) + { + QmitkAbstractDataNodeAction* abstractDataNodeAction = dynamic_cast(it->second); + if(nullptr != abstractDataNodeAction) + { + abstractDataNodeAction->SetDataStorage(m_DataStorage.Lock()); + } + } + } +} + +void QmitkDataNodeContextMenu::SetSurfaceDecimation(bool surfaceDecimation) +{ + m_SurfaceDecimation = surfaceDecimation; +} + +void QmitkDataNodeContextMenu::InitNodeDescriptors() +{ + m_UnknownDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); + m_ImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); + m_MultiComponentImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("MultiComponentImage"); + m_DiffusionImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("DiffusionImage"); + m_FiberBundleDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("FiberBundle"); + m_PeakImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PeakImage"); + m_SegmentDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Segment"); + m_SurfaceDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); + m_PointSetNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PointSet"); + m_PlanarLineNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarLine"); + m_PlanarCircleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarCircle"); + m_PlanarEllipseNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarEllipse"); + m_PlanarAngleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarAngle"); + m_PlanarFourPointAngleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarFourPointAngle"); + m_PlanarRectangleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarRectangle"); + m_PlanarPolygonNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPolygon"); + m_PlanarPathNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPath"); + m_PlanarDoubleEllipseNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarDoubleEllipse"); + m_PlanarBezierCurveNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarBezierCurve"); + m_PlanarSubdivisionPolygonNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarSubdivisionPolygon"); +} + +void QmitkDataNodeContextMenu::InitDefaultActions() +{ + m_GlobalReinitAction = new QmitkDataNodeGlobalReinitAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_GlobalReinitAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_GlobalReinitAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_GlobalReinitAction)); + + m_ReinitAction = new QmitkDataNodeReinitAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_ReinitAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_ReinitAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ReinitAction)); + + QAction* saveAction = new QmitkFileSaveAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()); + m_UnknownDataNodeDescriptor->AddAction(saveAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, saveAction)); + + m_RemoveAction = new QmitkDataNodeRemoveAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_RemoveAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_RemoveAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_RemoveAction)); + + m_ShowSelectedNodesAction = new QmitkDataNodeShowSelectedNodesAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_RemoveAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_ShowSelectedNodesAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ShowSelectedNodesAction)); + + m_ToggleVisibilityAction = new QmitkDataNodeToggleVisibilityAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_ToggleVisibilityAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_ToggleVisibilityAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ToggleVisibilityAction)); + + m_ShowDetailsAction = new QmitkDataNodeShowDetailsAction(m_Parent, m_WorkbenchPartSite.Lock()); + m_ShowDetailsAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png")); + m_UnknownDataNodeDescriptor->AddAction(m_ShowDetailsAction); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ShowDetailsAction)); + + // default widget actions + m_OpacityAction = new QmitkDataNodeOpacityAction(m_Parent, m_WorkbenchPartSite.Lock()); + // not used for batch actions (no multi-selection action) + m_UnknownDataNodeDescriptor->AddAction(m_OpacityAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_OpacityAction)); + + m_ColorAction = new QmitkDataNodeColorAction(m_Parent, m_WorkbenchPartSite.Lock()); + AddColorAction(m_ColorAction); + + m_ColormapAction = new QmitkDataNodeColorMapAction(m_Parent, m_WorkbenchPartSite.Lock()); + // not used for batch actions (no multi-selection action) + m_ImageDataNodeDescriptor->AddAction(m_ColormapAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, m_ColormapAction)); + + if (m_DiffusionImageDataNodeDescriptor != nullptr) + { + // not used for batch actions (no multi-selection action) + m_DiffusionImageDataNodeDescriptor->AddAction(m_ColormapAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_ColormapAction)); + } + + m_ComponentAction = new QmitkDataNodeComponentAction(m_Parent, m_WorkbenchPartSite.Lock()); + // not used for batch actions (no multi-selection action) + m_MultiComponentImageDataNodeDescriptor->AddAction(m_ComponentAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_MultiComponentImageDataNodeDescriptor, m_ComponentAction)); + + if (m_DiffusionImageDataNodeDescriptor != nullptr) + { + // not used for batch actions (no multi-selection action) + m_DiffusionImageDataNodeDescriptor->AddAction(m_ComponentAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_ComponentAction)); + } + + m_TextureInterpolationAction = new QmitkDataNodeTextureInterpolationAction(m_Parent, m_WorkbenchPartSite.Lock()); + // not used for batch actions (no multi-selection action) + m_ImageDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, m_TextureInterpolationAction)); + + if (m_DiffusionImageDataNodeDescriptor != nullptr) + { + // not used for batch actions (no multi-selection action) + m_DiffusionImageDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_TextureInterpolationAction)); + } + + if (m_SegmentDataNodeDescriptor != nullptr) + { + // not used for batch actions (no multi-selection action) + m_SegmentDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_SegmentDataNodeDescriptor, m_TextureInterpolationAction)); + } + + m_SurfaceRepresentationAction = new QmitkDataNodeSurfaceRepresentationAction(m_Parent, m_WorkbenchPartSite.Lock()); + // not used for batch actions (no multi-selection action) + m_SurfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentationAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_SurfaceDataNodeDescriptor, m_SurfaceRepresentationAction)); +} + +void QmitkDataNodeContextMenu::InitExtensionPointActions() +{ + // find contextMenuAction extension points and add them to the node descriptor + berry::IExtensionRegistry* extensionPointService = berry::Platform::GetExtensionRegistry(); + QList customMenuConfigs = extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions"); + + // prepare all custom QActions + m_ConfElements.clear(); + DescriptorActionListType descriptorActionList; + for (const auto& customMenuConfig : customMenuConfigs) + { + QString actionNodeDescriptorName = customMenuConfig->GetAttribute("nodeDescriptorName"); + QString actionLabel = customMenuConfig->GetAttribute("label"); + QString actionClass = customMenuConfig->GetAttribute("class"); + + if (actionNodeDescriptorName.isEmpty() || actionLabel.isEmpty() || actionClass.isEmpty()) + { + // no properties found for the current extension point + continue; + } + + // find matching descriptor + auto nodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(actionNodeDescriptorName); + if (nullptr == nodeDescriptor) + { + MITK_WARN << "Cannot add action \"" << actionLabel << "\" because descriptor " << actionNodeDescriptorName << " does not exist."; + continue; + } + + // create action with or without icon + QAction* contextMenuAction; + QString actionIconName = customMenuConfig->GetAttribute("icon"); + if (!actionIconName.isEmpty()) + { + QIcon actionIcon; + if (QFile::exists(actionIconName)) + { + actionIcon = QIcon(actionIconName); + } + else + { + actionIcon = berry::AbstractUICTKPlugin::ImageDescriptorFromPlugin(customMenuConfig->GetContributor()->GetName(), actionIconName); + } + contextMenuAction = new QAction(actionIcon, actionLabel, m_Parent); + } + else + { + contextMenuAction = new QAction(actionLabel, m_Parent); + } + + // connect action trigger + connect(contextMenuAction, static_cast(&QAction::triggered), this, &QmitkDataNodeContextMenu::OnExtensionPointActionTriggered); + + // mark configuration element into lookup list for context menu handler + m_ConfElements[contextMenuAction] = customMenuConfig; + // mark new action in sortable list for addition to descriptor + descriptorActionList.emplace_back(nodeDescriptor, contextMenuAction); + } + + AddDescriptorActionList(descriptorActionList); +} + +void QmitkDataNodeContextMenu::InitServiceActions() +{ + +} + +void QmitkDataNodeContextMenu::OnContextMenuRequested(const QPoint& pos) +{ + if (m_WorkbenchPartSite.Expired()) + { + return; + } + + berry::ISelection::ConstPointer selection = m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); + mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); + + if (currentSelection.IsNull() || currentSelection->IsEmpty()) + { + return; + } + + m_SelectedNodes = QList::fromStdList(currentSelection->GetSelectedDataNodes()); + if (!m_SelectedNodes.isEmpty()) + { + clear(); + QList actions; + if (m_SelectedNodes.size() == 1) + { + // no batch action; should only contain a single node + actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(m_SelectedNodes.front()); + } + else + { + actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(m_SelectedNodes); + } + + for (auto& action : actions) + { + QmitkAbstractDataNodeAction* abstractDataNodeAction = dynamic_cast(action); + if (nullptr != abstractDataNodeAction) + { + // use the first selected node to initialize the data node actions + abstractDataNodeAction->InitializeWithDataNode(m_SelectedNodes.front()); + } + } + + /* + if (!m_ShowInActions.isEmpty()) + { + QMenu* showInMenu = m_NodeMenu->addMenu(tr("Show In")); + showInMenu->addActions(m_ShowInActions); + } + */ + + addActions(actions); + popup(QCursor::pos()); + } +} + +void QmitkDataNodeContextMenu::OnExtensionPointActionTriggered(bool) +{ + QAction* action = qobject_cast(sender()); + std::map::iterator it = m_ConfElements.find(action); + if (it == m_ConfElements.end()) + { + MITK_WARN << "Associated configuration element for action " << action->text().toStdString() << " not found."; + return; + } + + berry::IConfigurationElement::Pointer confElem = it->second; + mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); + + QString className = confElem->GetAttribute("class"); + QString smoothed = confElem->GetAttribute("smoothed"); + + if (!m_DataStorage.IsExpired()) + { + auto dataStorage = m_DataStorage.Lock(); + contextMenuAction->SetDataStorage(dataStorage); + } + + if (className == "QmitkCreatePolygonModelAction") + { + if (smoothed == "false") + { + contextMenuAction->SetSmoothed(false); + } + else + { + contextMenuAction->SetSmoothed(true); + } + contextMenuAction->SetDecimated(m_SurfaceDecimation); + } + + contextMenuAction->Run(m_SelectedNodes); +} + +void QmitkDataNodeContextMenu::AddColorAction(QWidgetAction* colorAction) +{ + bool colorActionCanBatch = true; + if (nullptr != m_ImageDataNodeDescriptor) + { + m_ImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_MultiComponentImageDataNodeDescriptor) + { + m_MultiComponentImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_MultiComponentImageDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_DiffusionImageDataNodeDescriptor) + { + m_DiffusionImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_FiberBundleDataNodeDescriptor) + { + m_FiberBundleDataNodeDescriptor->AddAction(colorAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_FiberBundleDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_PeakImageDataNodeDescriptor) + { + m_PeakImageDataNodeDescriptor->AddAction(colorAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_PeakImageDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_SegmentDataNodeDescriptor) + { + m_SegmentDataNodeDescriptor->AddAction(colorAction, false); + m_DescriptorActionList.push_back(std::make_pair(m_SegmentDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_SurfaceDataNodeDescriptor) + { + m_SurfaceDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_SurfaceDataNodeDescriptor, colorAction)); + } + + if (nullptr != m_PointSetNodeDescriptor) + { + m_PointSetNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PointSetNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarLineNodeDescriptor) + { + m_PlanarLineNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarLineNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarCircleNodeDescriptor) + { + m_PlanarCircleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarCircleNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarEllipseNodeDescriptor) + { + m_PlanarEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarEllipseNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarAngleNodeDescriptor) + { + m_PlanarAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarAngleNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarFourPointAngleNodeDescriptor) + { + m_PlanarFourPointAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarFourPointAngleNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarRectangleNodeDescriptor) + { + m_PlanarRectangleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarRectangleNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarPolygonNodeDescriptor) + { + m_PlanarPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarPolygonNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarPathNodeDescriptor) + { + m_PlanarPathNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarPathNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarDoubleEllipseNodeDescriptor) + { + m_PlanarDoubleEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarDoubleEllipseNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarBezierCurveNodeDescriptor) + { + m_PlanarBezierCurveNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarBezierCurveNodeDescriptor, colorAction)); + } + + if (nullptr != m_PlanarSubdivisionPolygonNodeDescriptor) + { + m_PlanarSubdivisionPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); + m_DescriptorActionList.push_back(std::make_pair(m_PlanarSubdivisionPolygonNodeDescriptor, colorAction)); + } +} + +void QmitkDataNodeContextMenu::AddDescriptorActionList(DescriptorActionListType& descriptorActionList) +{ + // sort all custom QActions by their texts + using ListEntryType = std::pair; + std::sort(descriptorActionList.begin(), descriptorActionList.end(), + [](const ListEntryType& left, const ListEntryType& right) -> bool + { + assert(left.second != nullptr && right.second != nullptr); // unless we messed up above + return left.second->text() < right.second->text(); + }); + + // add custom QActions in sorted order + for (auto& descriptorActionPair : descriptorActionList) + { + auto& nodeDescriptor = descriptorActionPair.first; + auto& contextMenuAction = descriptorActionPair.second; + + // add action to the descriptor + nodeDescriptor->AddAction(contextMenuAction); + + // mark new action into list of descriptors to remove in destructor + m_DescriptorActionList.push_back(descriptorActionPair); + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h new file mode 100644 index 0000000000..3fd2a98a34 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h @@ -0,0 +1,130 @@ +/*=================================================================== + +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 QMITKDATANODECONTEXTMENU_H +#define QMITKDATANODECONTEXTMENU_H + +#include + +// qt widgets module +#include "QmitkDataNodeGlobalReinitAction.h" +#include "QmitkDataNodeReinitAction.h" +#include "QmitkDataNodeRemoveAction.h" +#include "QmitkDataNodeShowSelectedNodesAction.h" +#include "QmitkDataNodeToggleVisibilityAction.h" +#include "QmitkDataNodeShowDetailsAction.h" +#include "QmitkDataNodeOpacityAction.h" +#include "QmitkDataNodeColorAction.h" +#include "QmitkDataNodeColorMapAction.h" +#include "QmitkDataNodeComponentAction.h" +#include "QmitkDataNodeTextureInterpolationAction.h" +#include "QmitkDataNodeSurfaceRepresentationAction.h" +#include "QmitkNodeDescriptor.h" + +// mitk core +#include +#include + +// blueberry ui qt plugin +#include +#include + +// qt +#include + +class MITK_QT_APP QmitkDataNodeContextMenu : public QMenu +{ + Q_OBJECT + +public: + + QmitkDataNodeContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent = nullptr); + + virtual ~QmitkDataNodeContextMenu() override; + + void SetDataStorage(mitk::DataStorage* dataStorage); + void SetSurfaceDecimation(bool surfaceDecimation); + +public Q_SLOTS: + + void OnContextMenuRequested(const QPoint& pos); + void OnExtensionPointActionTriggered(bool); + +private: + + using DescriptorActionListType = std::vector>; + + void InitNodeDescriptors(); + void InitDefaultActions(); + void InitExtensionPointActions(); + void InitServiceActions(); + + void AddColorAction(QWidgetAction* colorAction); + void AddDescriptorActionList(DescriptorActionListType& descriptorActionList); + + QWidget* m_Parent; + berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; + + mitk::WeakPointer m_DataStorage; + QList m_SelectedNodes; + + // store a list of all actions to remove them on menu destruction + DescriptorActionListType m_DescriptorActionList; + + // stores the configuration elements for the context menu actions from extension points + std::map m_ConfElements; + + QmitkNodeDescriptor* m_UnknownDataNodeDescriptor; + QmitkNodeDescriptor* m_ImageDataNodeDescriptor; + QmitkNodeDescriptor* m_MultiComponentImageDataNodeDescriptor; + QmitkNodeDescriptor* m_DiffusionImageDataNodeDescriptor; + QmitkNodeDescriptor* m_FiberBundleDataNodeDescriptor; + QmitkNodeDescriptor* m_PeakImageDataNodeDescriptor; + QmitkNodeDescriptor* m_SegmentDataNodeDescriptor; + QmitkNodeDescriptor* m_SurfaceDataNodeDescriptor; + QmitkNodeDescriptor* m_PointSetNodeDescriptor; + QmitkNodeDescriptor* m_PlanarLineNodeDescriptor; + QmitkNodeDescriptor* m_PlanarCircleNodeDescriptor; + QmitkNodeDescriptor* m_PlanarEllipseNodeDescriptor; + QmitkNodeDescriptor* m_PlanarAngleNodeDescriptor; + QmitkNodeDescriptor* m_PlanarFourPointAngleNodeDescriptor; + QmitkNodeDescriptor* m_PlanarRectangleNodeDescriptor; + QmitkNodeDescriptor* m_PlanarPolygonNodeDescriptor; + QmitkNodeDescriptor* m_PlanarPathNodeDescriptor; + QmitkNodeDescriptor* m_PlanarDoubleEllipseNodeDescriptor; + QmitkNodeDescriptor* m_PlanarBezierCurveNodeDescriptor; + QmitkNodeDescriptor* m_PlanarSubdivisionPolygonNodeDescriptor; + + ////////////////////////////////////////////////////////////////////////// + // default actions + ////////////////////////////////////////////////////////////////////////// + QmitkDataNodeGlobalReinitAction* m_GlobalReinitAction; + QmitkDataNodeReinitAction* m_ReinitAction; + QmitkDataNodeRemoveAction* m_RemoveAction; + QmitkDataNodeShowSelectedNodesAction* m_ShowSelectedNodesAction; + QmitkDataNodeToggleVisibilityAction* m_ToggleVisibilityAction; + QmitkDataNodeShowDetailsAction* m_ShowDetailsAction; + QmitkDataNodeOpacityAction* m_OpacityAction; + QmitkDataNodeColorAction* m_ColorAction; + QmitkDataNodeColorMapAction* m_ColormapAction; + QmitkDataNodeComponentAction* m_ComponentAction; + QmitkDataNodeTextureInterpolationAction* m_TextureInterpolationAction; + QmitkDataNodeSurfaceRepresentationAction* m_SurfaceRepresentationAction; + + bool m_SurfaceDecimation; +}; + +#endif // QMITKDATANODECONTEXTMENU_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.cpp new file mode 100644 index 0000000000..a176ce1960 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.cpp @@ -0,0 +1,85 @@ +/*=================================================================== + +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 + +// mitk core +#include + +// mitk gui common plugin +#include + +// namespace that contains the concrete action +namespace GlobalReinitAction +{ + void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage) + { + auto renderWindow = mitk::WorkbenchUtil::GetRenderWindowPart(workbenchPartSite->GetPage(), mitk::WorkbenchUtil::NONE); + + if (nullptr == renderWindow) + { + renderWindow = mitk::WorkbenchUtil::OpenRenderWindowPart(workbenchPartSite->GetPage(), false); + if (nullptr == renderWindow) + { + // no render window available + return; + } + } + + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage); + } +} + +QmitkDataNodeGlobalReinitAction::QmitkDataNodeGlobalReinitAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchPartSite) +{ + setText(tr("Global Reinit")); + InitializeAction(); +} + +QmitkDataNodeGlobalReinitAction::QmitkDataNodeGlobalReinitAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) +{ + setText(tr("Global Reinit")); + InitializeAction(); +} + +QmitkDataNodeGlobalReinitAction::~QmitkDataNodeGlobalReinitAction() +{ + // nothing here +} + +void QmitkDataNodeGlobalReinitAction::InitializeAction() +{ + connect(this, &QmitkDataNodeGlobalReinitAction::triggered, this, &QmitkDataNodeGlobalReinitAction::OnActionTriggered); +} + +void QmitkDataNodeGlobalReinitAction::OnActionTriggered(bool checked) +{ + if (m_WorkbenchPartSite.Expired()) + { + return; + } + + if (m_DataStorage.IsExpired()) + { + return; + } + + GlobalReinitAction::Run(m_WorkbenchPartSite.Lock(), m_DataStorage.Lock()); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.h new file mode 100644 index 0000000000..6c2b0e56f6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeGlobalReinitAction.h @@ -0,0 +1,53 @@ +/*=================================================================== + +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 QMITKDATANODEGLOBALREINITACTION_H +#define QMITKDATANODEGLOBALREINITACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +namespace GlobalReinitAction +{ + MITK_QT_APP void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage); +} + +class MITK_QT_APP QmitkDataNodeGlobalReinitAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeGlobalReinitAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeGlobalReinitAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeGlobalReinitAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +private: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODEGLOBALREINITACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp new file mode 100644 index 0000000000..4e9d33b305 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp @@ -0,0 +1,63 @@ +/*=================================================================== + +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 + +// mitk core +#include + +QmitkDataNodeHideAllNodesAction::QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Hide all nodes")); + InitializeAction(); +} + +QmitkDataNodeHideAllNodesAction::QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Hide all nodes")); + InitializeAction(); +} + +QmitkDataNodeHideAllNodesAction::~QmitkDataNodeHideAllNodesAction() +{ + // nothing here +} + +void QmitkDataNodeHideAllNodesAction::InitializeAction() +{ + connect(this, &QmitkDataNodeHideAllNodesAction::triggered, this, &QmitkDataNodeHideAllNodesAction::OnActionTriggered); +} + +void QmitkDataNodeHideAllNodesAction::OnActionTriggered(bool checked) +{ + if (!m_DataStorage.IsExpired()) + { + auto nodeset = m_DataStorage.Lock()->GetAll(); + for (auto& node : *nodeset) + { + if (node.IsNotNull()) + { + node->SetVisibility(false); + } + } + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.h new file mode 100644 index 0000000000..e398114567 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.h @@ -0,0 +1,48 @@ +/*=================================================================== + +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 QMITKDATANODEHIDEALLNODESACTION_H +#define QMITKDATANODEHIDEALLNODESACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeHideAllNodesAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeHideAllNodesAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODEHIDEALLNODESACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp new file mode 100644 index 0000000000..090dc93e3a --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp @@ -0,0 +1,99 @@ +/*=================================================================== + +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 + +// mitk core +#include + +// qt +#include +#include + +QmitkDataNodeOpacityAction::QmitkDataNodeOpacityAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(workbenchPartSite) +{ + InitializeAction(); +} + +QmitkDataNodeOpacityAction::QmitkDataNodeOpacityAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite) + : QWidgetAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) +{ + InitializeAction(); +} + +QmitkDataNodeOpacityAction::~QmitkDataNodeOpacityAction() +{ + // nothing here +} + +void QmitkDataNodeOpacityAction::InitializeAction() +{ + m_OpacitySlider = new QSlider; + m_OpacitySlider->setMinimum(0); + m_OpacitySlider->setMaximum(100); + m_OpacitySlider->setOrientation(Qt::Horizontal); + connect(m_OpacitySlider, &QSlider::valueChanged, this, &QmitkDataNodeOpacityAction::OnOpacityChanged); + + QLabel* opacityLabel = new QLabel(tr("Opacity: ")); + QHBoxLayout* opacityWidgetLayout = new QHBoxLayout; + opacityWidgetLayout->setContentsMargins(4, 4, 4, 4); + opacityWidgetLayout->addWidget(opacityLabel); + opacityWidgetLayout->addWidget(m_OpacitySlider); + + QWidget* opacityWidget = new QWidget; + opacityWidget->setLayout(opacityWidgetLayout); + + setDefaultWidget(opacityWidget); + + connect(this, &QAction::changed, this, &QmitkDataNodeOpacityAction::OnActionChanged); +} + +void QmitkDataNodeOpacityAction::InitializeWithDataNode(const mitk::DataNode* dataNode) +{ + float opacity = 0.0; + if (dataNode->GetFloatProperty("opacity", opacity)) + { + m_OpacitySlider->setValue(static_cast(opacity * 100)); + } +} + +void QmitkDataNodeOpacityAction::OnOpacityChanged(int value) +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + float opacity = static_cast(value) / 100.0f; + dataNode->SetFloatProperty("opacity", opacity); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} + +void QmitkDataNodeOpacityAction::OnActionChanged() +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + InitializeWithDataNode(dataNode); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.h new file mode 100644 index 0000000000..20f5ada785 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.h @@ -0,0 +1,54 @@ +/*=================================================================== + +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 QMITKDATANODEOPACITYACTION_H +#define QMITKDATANODEOPACITYACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include +#include + +class MITK_QT_APP QmitkDataNodeOpacityAction : public QWidgetAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeOpacityAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeOpacityAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeOpacityAction() override; + + virtual void InitializeWithDataNode(const mitk::DataNode* dataNode) override; + +private Q_SLOTS: + + void OnOpacityChanged(int); + void OnActionChanged(); + +protected: + + virtual void InitializeAction() override; + + QSlider* m_OpacitySlider; + +}; + +#endif // QMITKDATANODEOPACITYACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp new file mode 100644 index 0000000000..516652ddd5 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp @@ -0,0 +1,104 @@ +/*=================================================================== + +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 + +// mitk core +#include +#include +#include +#include +#include + +// mitk gui common plugin +#include + +QmitkDataNodeReinitAction::QmitkDataNodeReinitAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Reinit")); + InitializeAction(); +} + +QmitkDataNodeReinitAction::QmitkDataNodeReinitAction(QObject* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Reinit")); + InitializeAction(); +} + +QmitkDataNodeReinitAction::~QmitkDataNodeReinitAction() +{ + // nothing here +} + +void QmitkDataNodeReinitAction::InitializeAction() +{ + connect(this, &QmitkDataNodeReinitAction::triggered, this, &QmitkDataNodeReinitAction::OnActionTriggered); +} + +void QmitkDataNodeReinitAction::OnActionTriggered(bool checked) +{ + if (m_WorkbenchPartSite.Expired()) + { + return; + } + + auto renderWindow = mitk::WorkbenchUtil::GetRenderWindowPart(m_WorkbenchPartSite.Lock()->GetPage(), mitk::WorkbenchUtil::NONE); + + if (nullptr == renderWindow) + { + renderWindow = mitk::WorkbenchUtil::OpenRenderWindowPart(m_WorkbenchPartSite.Lock()->GetPage(), false); + if (nullptr == renderWindow) + { + // no render window available + return; + } + } + + if (m_DataStorage.IsExpired()) + { + return; + } + + auto dataStorage = m_DataStorage.Lock(); + + auto boundingBoxPredicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); + auto selectedpredicate = mitk::NodePredicateProperty::New("selected", mitk::BoolProperty::New(true)); + auto selectedNodesIncludedInBoundingBox = mitk::NodePredicateAnd::New(boundingBoxPredicate, selectedpredicate); + + auto nodes = dataStorage->GetSubset(selectedNodesIncludedInBoundingBox); + if (nodes->empty()) + { + return; + } + + if (1 == nodes->Size()) // Special case: If exactly one ... + { + auto image = dynamic_cast(nodes->ElementAt(0)->GetData()); + + if (nullptr != image) // ... image is selected, reinit is expected to rectify askew images. + { + mitk::RenderingManager::GetInstance()->InitializeViews(image->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); + return; + } + } + + auto boundingGeometry = dataStorage->ComputeBoundingGeometry3D(nodes, "visible"); + mitk::RenderingManager::GetInstance()->InitializeViews(boundingGeometry); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.h new file mode 100644 index 0000000000..8b7bd2aa4b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.h @@ -0,0 +1,48 @@ +/*=================================================================== + +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 QMITKDATANODEREINITACTION_H +#define QMITKDATANODEREINITACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeReinitAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeReinitAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeReinitAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeReinitAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODEREINITACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp new file mode 100644 index 0000000000..ee8b91a9a1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp @@ -0,0 +1,95 @@ +/*=================================================================== + +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 +#include + +// qt +#include + +QmitkDataNodeRemoveAction::QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Remove")); + m_Parent = parent; + InitializeAction(); +} + +QmitkDataNodeRemoveAction::QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Remove")); + m_Parent = parent; + InitializeAction(); +} + +QmitkDataNodeRemoveAction::~QmitkDataNodeRemoveAction() +{ + // nothing here +} + +void QmitkDataNodeRemoveAction::InitializeAction() +{ + connect(this, &QmitkDataNodeRemoveAction::triggered, this, &QmitkDataNodeRemoveAction::OnActionTriggered); +} + +void QmitkDataNodeRemoveAction::OnActionTriggered(bool checked) +{ + QString question = tr("Do you really want to remove "); + auto selectedNodes = GetSelectedNodes(); + for (auto& dataNode : selectedNodes) + { + if (nullptr == dataNode) + { + continue; + } + + question.append(QString::fromStdString(dataNode->GetName())); + question.append(", "); + } + + // remove the last two characters = ", " + question = question.remove(question.size() - 2, 2); + question.append(tr(" from data storage?")); + + QMessageBox::StandardButton answerButton = QMessageBox::question(m_Parent, tr("DataManager"), question, + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (answerButton == QMessageBox::Yes) + { + for (auto& dataNode : selectedNodes) + { + if (nullptr == dataNode) + { + continue; + } + + if (m_DataStorage.IsExpired()) + { + return; + } + + auto dataStorage = m_DataStorage.Lock(); + dataStorage->Remove(dataNode); + if (true)//m_GlobalReinitOnNodeDelete) + { + GlobalReinitAction::Run(m_WorkbenchPartSite.Lock(), m_DataStorage.Lock()); + } + } + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.h new file mode 100644 index 0000000000..42be9f33c8 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.h @@ -0,0 +1,52 @@ +/*=================================================================== + +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 QMITKDATANODEREMOVEACTION_H +#define QMITKDATANODEREMOVEACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeRemoveAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeRemoveAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +private: + + QWidget* m_Parent; + +}; + +#endif // QMITKDATANODEREMOVEACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.cpp new file mode 100644 index 0000000000..0e55a7da54 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.cpp @@ -0,0 +1,56 @@ +/*=================================================================== + +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 + +// mitk gui qt application +#include "src/internal/QmitkInfoDialog.h" + +QmitkDataNodeShowDetailsAction::QmitkDataNodeShowDetailsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Show details")); + m_Parent = parent; + InitializeAction(); +} + +QmitkDataNodeShowDetailsAction::QmitkDataNodeShowDetailsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Show details")); + m_Parent = parent; + InitializeAction(); +} + +QmitkDataNodeShowDetailsAction::~QmitkDataNodeShowDetailsAction() +{ + // nothing here +} + +void QmitkDataNodeShowDetailsAction::InitializeAction() +{ + connect(this, &QmitkDataNodeShowDetailsAction::triggered, this, &QmitkDataNodeShowDetailsAction::OnActionTriggered); +} + +void QmitkDataNodeShowDetailsAction::OnActionTriggered(bool checked) +{ + auto selectedNodes = GetSelectedNodes(); + + QmitkInfoDialog infoDialog(selectedNodes, m_Parent); + infoDialog.exec(); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.h new file mode 100644 index 0000000000..37128e25bd --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowDetailsAction.h @@ -0,0 +1,52 @@ +/*=================================================================== + +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 QMITKDATANODESHOWDETAILSACTION_H +#define QMITKDATANODESHOWDETAILSACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeShowDetailsAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeShowDetailsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeShowDetailsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeShowDetailsAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +private: + + QWidget* m_Parent; + +}; + +#endif // QMITKDATANODESHOWDETAILSACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp new file mode 100644 index 0000000000..f494d5e997 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp @@ -0,0 +1,64 @@ +/*=================================================================== + +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 + +// mitk core +#include + +QmitkDataNodeShowSelectedNodesAction::QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Show only selected nodes")); + InitializeAction(); +} + +QmitkDataNodeShowSelectedNodesAction::QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Show only selected nodes")); + InitializeAction(); +} + +QmitkDataNodeShowSelectedNodesAction::~QmitkDataNodeShowSelectedNodesAction() +{ + // nothing here +} + +void QmitkDataNodeShowSelectedNodesAction::InitializeAction() +{ + connect(this, &QmitkDataNodeShowSelectedNodesAction::triggered, this, &QmitkDataNodeShowSelectedNodesAction::OnActionTriggered); +} + +void QmitkDataNodeShowSelectedNodesAction::OnActionTriggered(bool checked) +{ + if (!m_DataStorage.IsExpired()) + { + auto selectedNodes = GetSelectedNodes(); + auto nodeset = m_DataStorage.Lock()->GetAll(); + for (auto& node : *nodeset) + { + if (node.IsNotNull()) + { + node->SetVisibility(selectedNodes.contains(node)); + } + } + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.h new file mode 100644 index 0000000000..1847481291 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.h @@ -0,0 +1,48 @@ +/*=================================================================== + +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 QMITKDATANODESHOWSELECTEDNODESACTION_H +#define QMITKDATANODESHOWSELECTEDNODESACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeShowSelectedNodesAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeShowSelectedNodesAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODESHOWSELECTEDNODESACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp new file mode 100644 index 0000000000..c5cfeb3bf5 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp @@ -0,0 +1,118 @@ +/*=================================================================== + +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 + +// mitk core +#include +#include + +// qt +#include + +QmitkDataNodeSurfaceRepresentationAction::QmitkDataNodeSurfaceRepresentationAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Surface Representation")); + InitializeAction(); +} + +QmitkDataNodeSurfaceRepresentationAction::QmitkDataNodeSurfaceRepresentationAction(QObject* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Surface Representation")); + InitializeAction(); +} + +QmitkDataNodeSurfaceRepresentationAction::~QmitkDataNodeSurfaceRepresentationAction() +{ + // nothing here +} + +void QmitkDataNodeSurfaceRepresentationAction::InitializeAction() +{ + setCheckable(true); + + setMenu(new QMenu); + connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeSurfaceRepresentationAction::OnMenuAboutShow); +} + +void QmitkDataNodeSurfaceRepresentationAction::OnMenuAboutShow() +{ + mitk::DataNode::Pointer dataNode = GetSelectedNode(); + if (nullptr == dataNode) + { + return; + } + + mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation")); + if (nullptr == representationProp) + { + return; + } + + menu()->clear(); + QAction* tmp; + + for (mitk::EnumerationProperty::EnumConstIterator it = representationProp->Begin(); it != representationProp->End(); ++it) + { + tmp = menu()->addAction(QString::fromStdString(it->second)); + tmp->setCheckable(true); + + if (it->second == representationProp->GetValueAsString()) + { + tmp->setChecked(true); + } + + connect(tmp, &QAction::triggered, this, &QmitkDataNodeSurfaceRepresentationAction::OnActionTriggered); + } +} + +void QmitkDataNodeSurfaceRepresentationAction::OnActionTriggered(bool checked) +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation")); + if (nullptr == representationProp) + { + return; + } + + QAction* senderAction = qobject_cast(QObject::sender()); + if (nullptr == senderAction) + { + return; + } + + std::string activatedItem = senderAction->text().toStdString(); + if (activatedItem != representationProp->GetValueAsString()) + { + if (representationProp->IsValidEnumerationValue(activatedItem)) + { + representationProp->SetValue(activatedItem); + representationProp->InvokeEvent(itk::ModifiedEvent()); + representationProp->Modified(); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.h new file mode 100644 index 0000000000..97a1696a73 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.h @@ -0,0 +1,49 @@ +/*=================================================================== + +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 QMITKDATANODESURFACEREPRESENTATIONACTION_H +#define QMITKDATANODESURFACEREPRESENTATIONACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeSurfaceRepresentationAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeSurfaceRepresentationAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeSurfaceRepresentationAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeSurfaceRepresentationAction() override; + +private Q_SLOTS: + + void OnMenuAboutShow(); + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODESURFACEREPRESENTATIONACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp new file mode 100644 index 0000000000..27101d34c6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp @@ -0,0 +1,79 @@ +/*=================================================================== + +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 + +// mitk core +#include + +QmitkDataNodeTextureInterpolationAction::QmitkDataNodeTextureInterpolationAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Texture Interpolation")); + InitializeAction(); +} + +QmitkDataNodeTextureInterpolationAction::QmitkDataNodeTextureInterpolationAction(QObject* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Texture Interpolation")); + InitializeAction(); +} + +QmitkDataNodeTextureInterpolationAction::~QmitkDataNodeTextureInterpolationAction() +{ + // nothing here +} + +void QmitkDataNodeTextureInterpolationAction::InitializeAction() +{ + setCheckable(true); + + connect(this, &QmitkDataNodeTextureInterpolationAction::toggled, this, &QmitkDataNodeTextureInterpolationAction::OnActionToggled); + connect(this, &QmitkDataNodeTextureInterpolationAction::changed, this, &QmitkDataNodeTextureInterpolationAction::OnActionChanged); +} + +void QmitkDataNodeTextureInterpolationAction::InitializeWithDataNode(const mitk::DataNode* dataNode) +{ + bool textureInterpolation = false; + dataNode->GetBoolProperty("texture interpolation", textureInterpolation); + setChecked(textureInterpolation); +} + +void QmitkDataNodeTextureInterpolationAction::OnActionToggled(bool checked) +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + dataNode->SetBoolProperty("texture interpolation", checked); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} + +void QmitkDataNodeTextureInterpolationAction::OnActionChanged() +{ + auto dataNode = GetSelectedNode(); + if (dataNode.IsNull()) + { + return; + } + + InitializeWithDataNode(dataNode); +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.h new file mode 100644 index 0000000000..4c5a73fd9d --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.h @@ -0,0 +1,51 @@ +/*=================================================================== + +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 QMITKDATANODETEXTUREINTERPOLATIONACTION_H +#define QMITKDATANODETEXTUREINTERPOLATIONACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeTextureInterpolationAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeTextureInterpolationAction(QObject* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeTextureInterpolationAction(QObject* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeTextureInterpolationAction() override; + + virtual void InitializeWithDataNode(const mitk::DataNode* dataNode) override; + +private Q_SLOTS: + + void OnActionChanged(); + void OnActionToggled(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODETEXTUREINTERPOLATIONACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp new file mode 100644 index 0000000000..b99729b3c7 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp @@ -0,0 +1,71 @@ +/*=================================================================== + +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 +#include + +// mitk core +#include + +QmitkDataNodeToggleVisibilityAction::QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(workbenchpartSite) +{ + setText(tr("Toggle visibility")); + InitializeAction(); +} + +QmitkDataNodeToggleVisibilityAction::QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) + : QAction(parent) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) +{ + setText(tr("Toggle visibility")); + InitializeAction(); +} + +QmitkDataNodeToggleVisibilityAction::~QmitkDataNodeToggleVisibilityAction() +{ + // nothing here +} + +void QmitkDataNodeToggleVisibilityAction::InitializeAction() +{ + connect(this, &QmitkDataNodeToggleVisibilityAction::triggered, this, &QmitkDataNodeToggleVisibilityAction::OnActionTriggered); +} + +void QmitkDataNodeToggleVisibilityAction::OnActionTriggered(bool checked) +{ + auto selectedNodes = GetSelectedNodes(); + bool isVisible; + for (auto node : selectedNodes) + { + if (node.IsNotNull()) + { + isVisible = false; + node->GetBoolProperty("visible", isVisible); + node->SetVisibility(!isVisible); + } + } + + if (false)//m_GlobalReinitOnNodeVisibilityChanged) + { + GlobalReinitAction::Run(m_WorkbenchPartSite.Lock(), m_DataStorage.Lock()); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h new file mode 100644 index 0000000000..042ce8658f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h @@ -0,0 +1,48 @@ +/*=================================================================== + +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 QMITKDATANODETOGGLEVISIBILITYACTION_H +#define QMITKDATANODETOGGLEVISIBILITYACTION_H + +#include + +#include "QmitkAbstractDataNodeAction.h" + +// qt +#include + +class MITK_QT_APP QmitkDataNodeToggleVisibilityAction : public QAction, public QmitkAbstractDataNodeAction +{ + Q_OBJECT + +public: + + QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); + QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); + + virtual ~QmitkDataNodeToggleVisibilityAction() override; + +private Q_SLOTS: + + void OnActionTriggered(bool); + +protected: + + virtual void InitializeAction() override; + +}; + +#endif // QMITKDATANODETOGGLEVISIBILITYACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp index f8cbab6c8a..8e37af88e6 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.cpp @@ -1,123 +1,125 @@ /*=================================================================== 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 "QmitkFileOpenAction.h" #include "internal/org_mitk_gui_qt_application_Activator.h" #include #include #include #include class QmitkFileOpenActionPrivate { public: - void init ( berry::IWorkbenchWindow* window, QmitkFileOpenAction* action ) + 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())); } berry::IPreferences::Pointer GetPreferences() const { berry::IPreferencesService* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService(); - if (prefService) + if (prefService != nullptr) { return prefService->GetSystemPreferences()->Node("/General"); } return berry::IPreferences::Pointer(nullptr); } - QString getLastFileOpenPath() const + QString GetLastFileOpenPath() const { berry::IPreferences::Pointer prefs = GetPreferences(); - if(prefs.IsNotNull()) + if (prefs.IsNotNull()) { return prefs->Get("LastFileOpenPath", ""); } return QString(); } - void setLastFileOpenPath(const QString& path) const + void SetLastFileOpenPath(const QString& path) const { berry::IPreferences::Pointer prefs = GetPreferences(); - if(prefs.IsNotNull()) + if (prefs.IsNotNull()) { prefs->Put("LastFileOpenPath", path); prefs->Flush(); } } bool GetOpenEditor() const { berry::IPreferences::Pointer prefs = GetPreferences(); - if(prefs.IsNotNull()) + if (prefs.IsNotNull()) { return prefs->GetBool("OpenEditor", true); } return true; } berry::IWorkbenchWindow* m_Window; }; QmitkFileOpenAction::QmitkFileOpenAction(berry::IWorkbenchWindow::Pointer window) - : QAction(nullptr), d(new QmitkFileOpenActionPrivate) + : QAction(nullptr) + , d(new QmitkFileOpenActionPrivate) { - d->init(window.GetPointer(), this); + d->Init(window.GetPointer(), this); } -QmitkFileOpenAction::QmitkFileOpenAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window) - : QAction(nullptr), d(new QmitkFileOpenActionPrivate) +QmitkFileOpenAction::QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window) + : QAction(nullptr) + , d(new QmitkFileOpenActionPrivate) { - d->init(window.GetPointer(), this); - this->setIcon(icon); + d->Init(window.GetPointer(), this); + setIcon(icon); } QmitkFileOpenAction::QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow* window) : QAction(nullptr), d(new QmitkFileOpenActionPrivate) { - d->init(window, this); - this->setIcon(icon); + d->Init(window, this); + setIcon(icon); } QmitkFileOpenAction::~QmitkFileOpenAction() { } void QmitkFileOpenAction::Run() { - - // Ask the user for a list of files to open + // ask the user for a list of files to open QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, "Open", - d->getLastFileOpenPath(), + d->GetLastFileOpenPath(), QmitkIOUtil::GetFileOpenFilterString()); if (fileNames.empty()) + { return; + } - d->setLastFileOpenPath(fileNames.front()); - mitk::WorkbenchUtil::LoadFiles(fileNames, berry::IWorkbenchWindow::Pointer(d->m_Window), - d->GetOpenEditor()); + 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/QmitkFileOpenAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.h index 79675eb528..5f032d9d6a 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileOpenAction.h @@ -1,56 +1,53 @@ /*=================================================================== 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 QMITKFILEOPENACTION_H_ #define QMITKFILEOPENACTION_H_ -#include -#include +#include #include -#include - -#include +// qt +#include +#include class QmitkFileOpenActionPrivate; -/** - * \ingroup org_mitk_gui_qt_application - */ class MITK_QT_APP QmitkFileOpenAction : public QAction { Q_OBJECT public: + QmitkFileOpenAction(berry::IWorkbenchWindow::Pointer window); - QmitkFileOpenAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window); - QmitkFileOpenAction(const QIcon & icon, berry::IWorkbenchWindow* window); + QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window); + QmitkFileOpenAction(const QIcon& icon, berry::IWorkbenchWindow* window); - ~QmitkFileOpenAction() override; + virtual ~QmitkFileOpenAction() override; protected slots: virtual void Run(); private: const QScopedPointer d; }; #endif /*QMITKFILEOPENACTION_H_*/ diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp index d755511a5f..8efe3f43eb 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.cpp @@ -1,196 +1,193 @@ /*=================================================================== 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 "QmitkFileSaveAction.h" #include "internal/org_mitk_gui_qt_application_Activator.h" #include #include #include #include #include #include -#include -#include - class QmitkFileSaveActionPrivate { private: void HandleSelectionChanged(const berry::IWorkbenchPart::Pointer& /*part*/, const berry::ISelection::ConstPointer& selection) { - this->setEnabled(selection); + this->SetEnabled(selection); } QScopedPointer m_SelectionListener; public: QmitkFileSaveActionPrivate() : m_SelectionListener(new berry::NullSelectionChangedAdapter( this, &QmitkFileSaveActionPrivate::HandleSelectionChanged)) { } ~QmitkFileSaveActionPrivate() { if (!m_Window.Expired()) { m_Window.Lock()->GetSelectionService()->RemoveSelectionListener(m_SelectionListener.data()); } } - void init ( berry::IWorkbenchWindow* window, QmitkFileSaveAction* action ) + void Init(berry::IWorkbenchWindow* window, QAction* action) { m_Window = berry::IWorkbenchWindow::Pointer(window); m_Action = action; - action->setText("&Save..."); - action->setToolTip("Save data objects (images, surfaces,...)"); + m_Action->setText("&Save..."); + m_Action->setToolTip("Save data objects (images, surfaces,...)"); berry::ISelectionService* selectionService = m_Window.Lock()->GetSelectionService(); - setEnabled(selectionService->GetSelection()); + SetEnabled(selectionService->GetSelection()); selectionService->AddSelectionListener(m_SelectionListener.data()); - QObject::connect(action, SIGNAL(triggered(bool)), action, SLOT(Run())); + QObject::connect(m_Action, SIGNAL(triggered(bool)), m_Action, SLOT(Run())); } berry::IPreferences::Pointer GetPreferences() const { berry::IPreferencesService* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService(); if (prefService != nullptr) { return prefService->GetSystemPreferences()->Node("/General"); } return berry::IPreferences::Pointer(nullptr); } - QString getLastFileSavePath() const + QString GetLastFileSavePath() const { berry::IPreferences::Pointer prefs = GetPreferences(); - if(prefs.IsNotNull()) + if (prefs.IsNotNull()) { return prefs->Get("LastFileSavePath", ""); } return QString(); } - void setLastFileSavePath(const QString& path) const + void SetLastFileSavePath(const QString& path) const { berry::IPreferences::Pointer prefs = GetPreferences(); - if(prefs.IsNotNull()) + if (prefs.IsNotNull()) { prefs->Put("LastFileSavePath", path); prefs->Flush(); } } - void setEnabled(berry::ISelection::ConstPointer selection) + 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) + 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(nullptr), d(new QmitkFileSaveActionPrivate) + : QAction(tr("Save...")) + , d(new QmitkFileSaveActionPrivate) { - d->init(window.GetPointer(), this); + d->Init(window.GetPointer(), this); } -QmitkFileSaveAction::QmitkFileSaveAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window) - : QAction(nullptr), d(new QmitkFileSaveActionPrivate) +QmitkFileSaveAction::QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window) + : QAction(tr("Save...")) + , d(new QmitkFileSaveActionPrivate) { - d->init(window.GetPointer(), this); - this->setIcon(icon); + d->Init(window.GetPointer(), this); + setIcon(icon); } QmitkFileSaveAction::QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow* window) - : QAction(nullptr), d(new QmitkFileSaveActionPrivate) + : QAction(tr("Save...")) + , d(new QmitkFileSaveActionPrivate) { - d->init(window, this); - this->setIcon(icon); + d->Init(window, this); + setIcon(icon); } QmitkFileSaveAction::~QmitkFileSaveAction() { } void QmitkFileSaveAction::Run() { - // Get the list of selected base data objects + // 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) + 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)); } try { - QStringList fileNames = QmitkIOUtil::Save(data, names, d->getLastFileSavePath(), - d->m_Action->parentWidget()); + QStringList fileNames = QmitkIOUtil::Save(data, names, d->GetLastFileSavePath(), d->m_Action->parentWidget()); if (!fileNames.empty()) { - d->setLastFileSavePath(QFileInfo(fileNames.back()).absolutePath()); + 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/QmitkFileSaveAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.h index e6c5e0deb4..069afbdc42 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkFileSaveAction.h @@ -1,56 +1,53 @@ /*=================================================================== 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 QMITKFILESAVEACTION_H_ #define QMITKFILESAVEACTION_H_ -#include -#include +#include #include -#include - -#include +// qt +#include +#include class QmitkFileSaveActionPrivate; -/** - * \ingroup org_mitk_gui_qt_application - */ class MITK_QT_APP QmitkFileSaveAction : public QAction { Q_OBJECT public: + QmitkFileSaveAction(berry::IWorkbenchWindow::Pointer window); - QmitkFileSaveAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window); - QmitkFileSaveAction(const QIcon & icon, berry::IWorkbenchWindow* window); + QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow::Pointer window); + QmitkFileSaveAction(const QIcon& icon, berry::IWorkbenchWindow* window); - ~QmitkFileSaveAction() override; + virtual ~QmitkFileSaveAction() override; protected slots: virtual void Run(); private: const QScopedPointer d; }; #endif /*QMITKFILESAVEACTION_H_*/ diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h b/Plugins/org.mitk.gui.qt.application/src/mitkIContextMenuAction.h similarity index 89% rename from Plugins/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h rename to Plugins/org.mitk.gui.qt.application/src/mitkIContextMenuAction.h index fa3dabbc5c..18133dcdd5 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/mitkIContextMenuAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/mitkIContextMenuAction.h @@ -1,53 +1,53 @@ /*=================================================================== 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 mitkIContextMenuAction_H_ #define mitkIContextMenuAction_H_ #include #include #include #include #include "mitkDataStorage.h" namespace mitk { /** * A context menu action, which is linked to the context menu
* through an extension point. For an example check the
* plugin.xml and the connected classes of
* the the segmentation bundle and also the QmitkDataManagerView.cpp
* in this bundle. */ struct IContextMenuAction { - /** - * @brief Executes the action, that linked to the context menu entry. - */ - virtual void Run( const QList& selectedNodes ) = 0; + /** + * @brief Executes the action, that linked to the context menu entry. + */ + virtual void Run(const QList& selectedNodes) = 0; // Setters virtual void SetDataStorage(mitk::DataStorage* dataStorage) = 0; virtual void SetSmoothed(bool smoothed) = 0; virtual void SetDecimated(bool decimated) = 0; virtual void SetFunctionality(berry::QtViewPart* functionality) = 0; }; } Q_DECLARE_INTERFACE(mitk::IContextMenuAction, "org.mitk.datamanager.IContextMenuAction") #endif // mitkIContextMenuAction_H_ diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp index 6eb4dc9bb7..499f2adfe5 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp +++ b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp @@ -1,1218 +1,308 @@ /*=================================================================== 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 "QmitkDataManagerView.h" -//# Own Includes -//## mitk -#include "mitkDataStorageEditorInput.h" -#include "mitkIDataStorageReference.h" -#include "mitkNodePredicateDataType.h" -#include "mitkCoreObjectFactory.h" -#include "mitkColorProperty.h" -#include "mitkCommon.h" -#include "mitkNodePredicateData.h" -#include "mitkNodePredicateNot.h" -#include "mitkNodePredicateOr.h" -#include "mitkNodePredicateProperty.h" -#include "mitkEnumerationProperty.h" -#include "mitkLookupTableProperty.h" -#include "mitkProperties.h" -#include +// mitk gui qt datamanager +#include "src/internal/QmitkNodeTableViewKeyFilter.h" +#include "src/internal/QmitkInfoDialog.h" +#include "src/internal/QmitkDataManagerItemDelegate.h" + +// mitk core +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// mitk core services plugin +#include #include -#include -#include -//## Qmitk -#include -#include -#include + +// qt widgets module #include -#include #include -#include -#include "src/internal/QmitkNodeTableViewKeyFilter.h" -#include "src/internal/QmitkInfoDialog.h" -#include "src/internal/QmitkDataManagerItemDelegate.h" -//## Berry +#include +#include +#include + +// beery plugins #include #include #include -#include +#include +#include #include +#include #include #include -#include -//# Toolkit Includes -#include -#include + +// mitk gui qt application plugin +#include +// qt #include -#include #include -#include -#include #include #include -#include -#include +#include #include -#include #include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #include -#include "mitkDataNodeObject.h" -#include "mitkIContextMenuAction.h" -#include "berryIExtensionRegistry.h" -#include "mitkRenderingModeProperty.h" +// mitk gui common plugin +#include +#include +#include + +// mitk gui qt common plugin +#include const QString QmitkDataManagerView::VIEW_ID = "org.mitk.views.datamanager"; QmitkDataManagerView::QmitkDataManagerView() : m_GlobalReinitOnNodeDelete(true) , m_GlobalReinitOnNodeVisibilityChanged(false) , m_ItemDelegate(nullptr) { } QmitkDataManagerView::~QmitkDataManagerView() { - //Remove all registered actions from each descriptor - for (std::vector< std::pair< QmitkNodeDescriptor*, QAction* > >::iterator it = m_DescriptorActionList.begin();it != m_DescriptorActionList.end(); it++) - { - // first== the NodeDescriptor; second== the registered QAction - (it->first)->RemoveAction(it->second); - } + // nothing here } void QmitkDataManagerView::CreateQtPartControl(QWidget* parent) { m_CurrentRowCount = 0; m_Parent = parent; //# Preferences berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); - - berry::IBerryPreferences::Pointer prefs - = (prefService->GetSystemPreferences()->Node(VIEW_ID)) - .Cast(); - assert( prefs ); - prefs->OnChanged.AddListener( berry::MessageDelegate1( this - , &QmitkDataManagerView::OnPreferencesChanged ) ); + berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node(VIEW_ID)).Cast(); + assert(prefs); + prefs->OnChanged.AddListener(berry::MessageDelegate1(this, &QmitkDataManagerView::OnPreferencesChanged)); //# GUI - m_NodeTreeModel = new QmitkDataStorageTreeModel(this->GetDataStorage(), prefs->GetBool("Place new nodes on top", true)); - m_NodeTreeModel->setParent( parent ); - m_NodeTreeModel->SetAllowHierarchyChange( - prefs->GetBool("Allow changing of parent node", false)); + m_NodeTreeModel = new QmitkDataStorageTreeModel(GetDataStorage(), prefs->GetBool("Place new nodes on top", true)); + m_NodeTreeModel->setParent(parent); + m_NodeTreeModel->SetAllowHierarchyChange(prefs->GetBool("Allow changing of parent node", false)); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); // Prepare filters m_HelperObjectFilterPredicate = mitk::NodePredicateOr::New( - mitk::NodePredicateProperty::New("helper object", mitk::BoolProperty::New(true)), - mitk::NodePredicateProperty::New("hidden object", mitk::BoolProperty::New(true))); + mitk::NodePredicateProperty::New("helper object", mitk::BoolProperty::New(true)), + mitk::NodePredicateProperty::New("hidden object", mitk::BoolProperty::New(true))); m_NodeWithNoDataFilterPredicate = mitk::NodePredicateData::New(nullptr); m_FilterModel = new QmitkDataStorageFilterProxyModel(); m_FilterModel->setSourceModel(m_NodeTreeModel); m_FilterModel->AddFilterPredicate(m_HelperObjectFilterPredicate); m_FilterModel->AddFilterPredicate(m_NodeWithNoDataFilterPredicate); //# Tree View (experimental) m_NodeTreeView = new QTreeView; m_NodeTreeView->setHeaderHidden(true); - m_NodeTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection ); - m_NodeTreeView->setSelectionBehavior( QAbstractItemView::SelectRows ); + m_NodeTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_NodeTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); m_NodeTreeView->setAlternatingRowColors(true); m_NodeTreeView->setDragEnabled(true); m_NodeTreeView->setDropIndicatorShown(true); m_NodeTreeView->setAcceptDrops(true); m_NodeTreeView->setContextMenuPolicy(Qt::CustomContextMenu); m_NodeTreeView->setModel(m_FilterModel); m_NodeTreeView->setTextElideMode(Qt::ElideMiddle); m_NodeTreeView->installEventFilter(new QmitkNodeTableViewKeyFilter(this)); m_ItemDelegate = new QmitkDataManagerItemDelegate(m_NodeTreeView); m_NodeTreeView->setItemDelegate(m_ItemDelegate); - connect( m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)) - , this, SLOT(NodeTableViewContextMenuRequested(const QPoint&)) ); - connect( m_NodeTreeModel, SIGNAL(rowsInserted (const QModelIndex&, int, int)) - , this, SLOT(NodeTreeViewRowsInserted ( const QModelIndex&, int, int )) ); - connect( m_NodeTreeModel, SIGNAL(rowsRemoved (const QModelIndex&, int, int)) - , this, SLOT(NodeTreeViewRowsRemoved( const QModelIndex&, int, int )) ); - connect( m_NodeTreeView->selectionModel() - , SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection & ) ) - , this - , SLOT( NodeSelectionChanged ( const QItemSelection &, const QItemSelection & ) ) ); + connect(m_NodeTreeModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(NodeTreeViewRowsInserted(const QModelIndex&, int, int))); + connect(m_NodeTreeModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(NodeTreeViewRowsRemoved(const QModelIndex&, int, int))); + connect(m_NodeTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(NodeSelectionChanged(const QItemSelection &, const QItemSelection &))); connect(m_NodeTreeModel, &QmitkDataStorageTreeModel::nodeVisibilityChanged, this, &QmitkDataManagerView::OnNodeVisibilityChanged); - //# m_NodeMenu - m_NodeMenu = new QMenu(m_NodeTreeView); + // data node context menu and menu actions + m_DataNodeContextMenu = new QmitkDataNodeContextMenu(GetSite(), m_NodeTreeView); + m_DataNodeContextMenu->SetDataStorage(GetDataStorage()); + m_DataNodeContextMenu->SetSurfaceDecimation(m_SurfaceDecimation); + connect(m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), m_DataNodeContextMenu, SLOT(OnContextMenuRequested(const QPoint&))); - // # Actions berry::IEditorRegistry* editorRegistry = berry::PlatformUI::GetWorkbench()->GetEditorRegistry(); QList editors = editorRegistry->GetEditors("*.mitk"); if (editors.size() > 1) { m_ShowInMapper = new QSignalMapper(this); foreach(berry::IEditorDescriptor::Pointer descriptor, editors) { QAction* action = new QAction(descriptor->GetLabel(), this); m_ShowInActions << action; m_ShowInMapper->connect(action, SIGNAL(triggered()), m_ShowInMapper, SLOT(map())); m_ShowInMapper->setMapping(action, descriptor->GetId()); } connect(m_ShowInMapper, SIGNAL(mapped(QString)), this, SLOT(ShowIn(QString))); } - auto unknownDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); - - auto imageDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); - - auto multiComponentImageDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("MultiComponentImage"); - - auto diffusionImageDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("DiffusionImage"); - - auto fiberBundleDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("FiberBundle"); - - auto peakImageDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PeakImage"); - - auto segmentDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Segment"); - - auto surfaceDataNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); - - auto pointSetNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PointSet"); - - auto planarLineNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarLine"); - auto planarCircleNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarCircle"); - auto planarEllipseNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarEllipse"); - auto planarAngleNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarAngle"); - auto planarFourPointAngleNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarFourPointAngle"); - auto planarRectangleNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarRectangle"); - auto planarPolygonNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPolygon"); - auto planarPathNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPath"); - auto planarDoubleEllipseNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarDoubleEllipse"); - auto planarBezierCurveNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarBezierCurve"); - auto planarSubdivisionPolygonNodeDescriptor = - QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarSubdivisionPolygon"); - - QAction* globalReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), tr("Global Reinit"), this); - QObject::connect( globalReinitAction, SIGNAL( triggered(bool) ) - , this, SLOT( GlobalReinit(bool) ) ); - unknownDataNodeDescriptor->AddAction(globalReinitAction); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor, globalReinitAction)); - - QAction* saveAction = new QmitkFileSaveAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), - this->GetSite()->GetWorkbenchWindow()); - unknownDataNodeDescriptor->AddAction(saveAction); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,saveAction)); - - QAction* removeAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png"), tr("Remove"), this); - QObject::connect( removeAction, SIGNAL( triggered(bool) ) - , this, SLOT( RemoveSelectedNodes(bool) ) ); - unknownDataNodeDescriptor->AddAction(removeAction); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,removeAction)); - - QAction* reinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), tr("Reinit"), this); - QObject::connect( reinitAction, SIGNAL( triggered(bool) ) - , this, SLOT( ReinitSelectedNodes(bool) ) ); - unknownDataNodeDescriptor->AddAction(reinitAction); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,reinitAction)); - - // find contextMenuAction extension points and add them to the node descriptor - berry::IExtensionRegistry* extensionPointService = berry::Platform::GetExtensionRegistry(); - QList customMenuConfigs = - extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions"); - - // Prepare all custom QActions - m_ConfElements.clear(); - DescriptorActionListType customMenuEntries; - for (auto& customMenuConfig : customMenuConfigs) - { - QString actionNodeDescriptorName = customMenuConfig->GetAttribute("nodeDescriptorName"); - QString actionLabel = customMenuConfig->GetAttribute("label"); - QString actionClass = customMenuConfig->GetAttribute("class"); - - if (actionNodeDescriptorName.isEmpty() || actionLabel.isEmpty() || actionClass.isEmpty()) - { - continue; - } - - QString actionIconName = customMenuConfig->GetAttribute("icon"); - - // Find matching descriptor - auto nodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(actionNodeDescriptorName); - if ( nodeDescriptor == nullptr) - { - MITK_WARN << "Cannot add action \"" << actionLabel << "\" because descriptor " << actionNodeDescriptorName << " does not exist."; - continue; - } - - // Create action with or without icon - QAction* contextMenuAction; - if ( !actionIconName.isEmpty() ) - { - QIcon actionIcon; - if ( QFile::exists(actionIconName) ) - { - actionIcon = QIcon(actionIconName); - } else - { - actionIcon = berry::AbstractUICTKPlugin::ImageDescriptorFromPlugin( - customMenuConfig->GetContributor()->GetName(), actionIconName); - } - contextMenuAction = new QAction(actionIcon, actionLabel, parent); - } else - { - contextMenuAction = new QAction(actionLabel, parent); - } - - // Define menu handler to trigger on click - connect(contextMenuAction, static_cast(&QAction::triggered), - this, &QmitkDataManagerView::ContextMenuActionTriggered); - - // Mark configuration element into lookup list for context menu handler - m_ConfElements[contextMenuAction] = customMenuConfig; - // Mark new action in sortable list for addition to descriptor - customMenuEntries.emplace_back(nodeDescriptor, contextMenuAction); - } - - // Sort all custom QActions by their texts - { - using ListEntryType = std::pair; - std::sort(customMenuEntries.begin(), customMenuEntries.end(), - [](const ListEntryType& left, const ListEntryType& right) -> bool - { - assert (left.second != nullptr && right.second != nullptr); // unless we messed up above - return left.second->text() < right.second->text(); - }); - } - - // Add custom QActions in sorted order - int globalAddedMenuIndex=1; - for (auto& menuEntryToAdd : customMenuEntries) - { - auto& nodeDescriptor = menuEntryToAdd.first; - auto& contextMenuAction = menuEntryToAdd.second; - - // TODO is the action "data" used by anything? Otherwise remove! - contextMenuAction->setData(static_cast(globalAddedMenuIndex)); - ++globalAddedMenuIndex; - - // Really add this action to that descriptor (in pre-defined order) - nodeDescriptor->AddAction(contextMenuAction); - - // Mark new action into list of descriptors to remove in d'tor - m_DescriptorActionList.push_back(menuEntryToAdd); - } - - m_OpacitySlider = new QSlider; - m_OpacitySlider->setMinimum(0); - m_OpacitySlider->setMaximum(100); - m_OpacitySlider->setOrientation(Qt::Horizontal); - QObject::connect( m_OpacitySlider, SIGNAL( valueChanged(int) ) - , this, SLOT( OpacityChanged(int) ) ); - - QLabel* _OpacityLabel = new QLabel(tr("Opacity: ")); - QHBoxLayout* _OpacityWidgetLayout = new QHBoxLayout; - _OpacityWidgetLayout->setContentsMargins(4,4,4,4); - _OpacityWidgetLayout->addWidget(_OpacityLabel); - _OpacityWidgetLayout->addWidget(m_OpacitySlider); - QWidget* _OpacityWidget = new QWidget; - _OpacityWidget->setLayout(_OpacityWidgetLayout); - - QWidgetAction* opacityAction = new QWidgetAction(this); - opacityAction ->setDefaultWidget(_OpacityWidget); - QObject::connect( opacityAction , SIGNAL( changed() ) - , this, SLOT( OpacityActionChanged() ) ); - unknownDataNodeDescriptor->AddAction(opacityAction , false); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,opacityAction)); - - m_ColorButton = new QPushButton; - m_ColorButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); - //m_ColorButton->setText("Change color"); - QObject::connect( m_ColorButton, SIGNAL( clicked() ) - , this, SLOT( ColorChanged() ) ); - - QLabel* _ColorLabel = new QLabel(tr("Color: ")); - _ColorLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); - QHBoxLayout* _ColorWidgetLayout = new QHBoxLayout; - _ColorWidgetLayout->setContentsMargins(4,4,4,4); - _ColorWidgetLayout->addWidget(_ColorLabel); - _ColorWidgetLayout->addWidget(m_ColorButton); - QWidget* _ColorWidget = new QWidget; - _ColorWidget->setLayout(_ColorWidgetLayout); - - QWidgetAction* colorAction = new QWidgetAction(this); - colorAction->setDefaultWidget(_ColorWidget); - QObject::connect( colorAction, SIGNAL( changed() ) - , this, SLOT( ColorActionChanged() ) ); - - { // only give the color context menu option where appropriate - bool colorActionCanBatch = true; - if (imageDataNodeDescriptor != nullptr) - { - imageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(imageDataNodeDescriptor, colorAction)); - } - if (multiComponentImageDataNodeDescriptor != nullptr) - { - multiComponentImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(multiComponentImageDataNodeDescriptor, colorAction)); - } - if (diffusionImageDataNodeDescriptor != nullptr) - { - diffusionImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(diffusionImageDataNodeDescriptor, colorAction)); - } - if (fiberBundleDataNodeDescriptor != nullptr) - { - fiberBundleDataNodeDescriptor->AddAction(colorAction, false); - m_DescriptorActionList.push_back(std::make_pair(fiberBundleDataNodeDescriptor, colorAction)); - } - if (peakImageDataNodeDescriptor != nullptr) - { - peakImageDataNodeDescriptor->AddAction(colorAction, false); - m_DescriptorActionList.push_back(std::make_pair(peakImageDataNodeDescriptor, colorAction)); - } - if (segmentDataNodeDescriptor != nullptr) - { - segmentDataNodeDescriptor->AddAction(colorAction, false); - m_DescriptorActionList.push_back(std::make_pair(segmentDataNodeDescriptor, colorAction)); - } - if (surfaceDataNodeDescriptor != nullptr) - { - surfaceDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(surfaceDataNodeDescriptor, colorAction)); - } - if (pointSetNodeDescriptor != nullptr) - { - pointSetNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(pointSetNodeDescriptor, colorAction)); - } - - if (planarLineNodeDescriptor != nullptr) - { - planarLineNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarLineNodeDescriptor, colorAction)); - } - - if (planarCircleNodeDescriptor != nullptr) - { - planarCircleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarCircleNodeDescriptor, colorAction)); - } - - if (planarEllipseNodeDescriptor != nullptr) - { - planarEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarEllipseNodeDescriptor, colorAction)); - } - - if (planarAngleNodeDescriptor != nullptr) - { - planarAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarAngleNodeDescriptor, colorAction)); - } - - if (planarFourPointAngleNodeDescriptor != nullptr) - { - planarFourPointAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarFourPointAngleNodeDescriptor, colorAction)); - } - - if (planarRectangleNodeDescriptor != nullptr) - { - planarRectangleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarRectangleNodeDescriptor, colorAction)); - } - - if (planarPolygonNodeDescriptor != nullptr) - { - planarPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarPolygonNodeDescriptor, colorAction)); - } - - if (planarPathNodeDescriptor != nullptr) - { - planarPathNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarPathNodeDescriptor, colorAction)); - } - - if (planarDoubleEllipseNodeDescriptor != nullptr) - { - planarDoubleEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarDoubleEllipseNodeDescriptor, colorAction)); - } - - if (planarBezierCurveNodeDescriptor != nullptr) - { - planarBezierCurveNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarBezierCurveNodeDescriptor, colorAction)); - } - - if (planarSubdivisionPolygonNodeDescriptor != nullptr) - { - planarSubdivisionPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); - m_DescriptorActionList.push_back(std::make_pair(planarSubdivisionPolygonNodeDescriptor, colorAction)); - } - } - - m_ComponentSlider = new QmitkNumberPropertySlider; - m_ComponentSlider->setOrientation(Qt::Horizontal); - //QObject::connect( m_OpacitySlider, SIGNAL( valueChanged(int) ) - // , this, SLOT( OpacityChanged(int) ) ); - - QLabel* _ComponentLabel = new QLabel(tr("Component: ")); - QHBoxLayout* _ComponentWidgetLayout = new QHBoxLayout; - _ComponentWidgetLayout->setContentsMargins(4,4,4,4); - _ComponentWidgetLayout->addWidget(_ComponentLabel); - _ComponentWidgetLayout->addWidget(m_ComponentSlider); - QLabel* _ComponentValueLabel = new QLabel(); - _ComponentWidgetLayout->addWidget(_ComponentValueLabel); - connect(m_ComponentSlider, SIGNAL(valueChanged(int)), _ComponentValueLabel, SLOT(setNum(int))); - QWidget* _ComponentWidget = new QWidget; - _ComponentWidget->setLayout(_ComponentWidgetLayout); - - QWidgetAction* componentAction = new QWidgetAction(this); - componentAction->setDefaultWidget(_ComponentWidget); - QObject::connect( componentAction , SIGNAL( changed() ) - , this, SLOT( ComponentActionChanged() ) ); - multiComponentImageDataNodeDescriptor->AddAction(componentAction, false); - m_DescriptorActionList.push_back(std::make_pair(multiComponentImageDataNodeDescriptor,componentAction)); - if (diffusionImageDataNodeDescriptor!=nullptr) - { - diffusionImageDataNodeDescriptor->AddAction(componentAction, false); - m_DescriptorActionList.push_back(std::make_pair(diffusionImageDataNodeDescriptor,componentAction)); - } - - m_TextureInterpolation = new QAction(tr("Texture Interpolation"), this); - m_TextureInterpolation->setCheckable ( true ); - QObject::connect( m_TextureInterpolation, SIGNAL( changed() ) - , this, SLOT( TextureInterpolationChanged() ) ); - QObject::connect( m_TextureInterpolation, SIGNAL( toggled(bool) ) - , this, SLOT( TextureInterpolationToggled(bool) ) ); - imageDataNodeDescriptor->AddAction(m_TextureInterpolation, false); - m_DescriptorActionList.push_back(std::make_pair(imageDataNodeDescriptor,m_TextureInterpolation)); - if (diffusionImageDataNodeDescriptor!=nullptr) - { - diffusionImageDataNodeDescriptor->AddAction(m_TextureInterpolation, false); - m_DescriptorActionList.push_back(std::make_pair(diffusionImageDataNodeDescriptor,m_TextureInterpolation)); - } - if (segmentDataNodeDescriptor != nullptr) - { - segmentDataNodeDescriptor->AddAction(m_TextureInterpolation, false); - m_DescriptorActionList.push_back(std::make_pair(segmentDataNodeDescriptor, m_TextureInterpolation)); - } - - m_ColormapAction = new QAction(tr("Colormap"), this); - m_ColormapAction->setMenu(new QMenu); - QObject::connect( m_ColormapAction->menu(), SIGNAL( aboutToShow() ) - , this, SLOT( ColormapMenuAboutToShow() ) ); - imageDataNodeDescriptor->AddAction(m_ColormapAction, false); - m_DescriptorActionList.push_back(std::make_pair(imageDataNodeDescriptor, m_ColormapAction)); - if (diffusionImageDataNodeDescriptor!=nullptr) - { - diffusionImageDataNodeDescriptor->AddAction(m_ColormapAction, false); - m_DescriptorActionList.push_back(std::make_pair(diffusionImageDataNodeDescriptor, m_ColormapAction)); - } - - m_SurfaceRepresentation = new QAction(tr("Surface Representation"), this); - m_SurfaceRepresentation->setMenu(new QMenu(m_NodeTreeView)); - QObject::connect( m_SurfaceRepresentation->menu(), SIGNAL( aboutToShow() ) - , this, SLOT( SurfaceRepresentationMenuAboutToShow() ) ); - surfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentation, false); - m_DescriptorActionList.push_back(std::make_pair(surfaceDataNodeDescriptor, m_SurfaceRepresentation)); - - QAction* showOnlySelectedNodes - = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png") - , tr("Show only selected nodes"), this); - QObject::connect( showOnlySelectedNodes, SIGNAL( triggered(bool) ) - , this, SLOT( ShowOnlySelectedNodes(bool) ) ); - unknownDataNodeDescriptor->AddAction(showOnlySelectedNodes); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor, showOnlySelectedNodes)); - - QAction* toggleSelectedVisibility - = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png") - , tr("Toggle visibility"), this); - QObject::connect( toggleSelectedVisibility, SIGNAL( triggered(bool) ) - , this, SLOT( ToggleVisibilityOfSelectedNodes(bool) ) ); - unknownDataNodeDescriptor->AddAction(toggleSelectedVisibility); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,toggleSelectedVisibility)); - - QAction* actionShowInfoDialog - = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png") - , tr("Details..."), this); - QObject::connect( actionShowInfoDialog, SIGNAL( triggered(bool) ) - , this, SLOT( ShowInfoDialogForSelectedNodes(bool) ) ); - unknownDataNodeDescriptor->AddAction(actionShowInfoDialog); - m_DescriptorActionList.push_back(std::make_pair(unknownDataNodeDescriptor,actionShowInfoDialog)); - - QGridLayout* _DndFrameWidgetLayout = new QGridLayout; - _DndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0); - _DndFrameWidgetLayout->setContentsMargins(0,0,0,0); + QGridLayout* dndFrameWidgetLayout = new QGridLayout; + dndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0); + dndFrameWidgetLayout->setContentsMargins(0, 0, 0, 0); - m_DndFrameWidget = new QmitkDnDFrameWidget(m_Parent); - m_DndFrameWidget->setLayout(_DndFrameWidgetLayout); + m_DnDFrameWidget = new QmitkDnDFrameWidget(m_Parent); + m_DnDFrameWidget->setLayout(dndFrameWidgetLayout); QVBoxLayout* layout = new QVBoxLayout(parent); - layout->addWidget(m_DndFrameWidget); - layout->setContentsMargins(0,0,0,0); + layout->addWidget(m_DnDFrameWidget); + layout->setContentsMargins(0, 0, 0, 0); m_Parent->setLayout(layout); } void QmitkDataManagerView::SetFocus() { } -void QmitkDataManagerView::ContextMenuActionTriggered( bool ) +void QmitkDataManagerView::NodeChanged(const mitk::DataNode* /*node*/) { - QAction* action = qobject_cast ( sender() ); - - std::map::iterator it - = m_ConfElements.find( action ); - if( it == m_ConfElements.end() ) - { - MITK_WARN << "associated conf element for action " << action->text().toStdString() << " not found"; - return; - } - berry::IConfigurationElement::Pointer confElem = it->second; - mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); - - QString className = confElem->GetAttribute("class"); - QString smoothed = confElem->GetAttribute("smoothed"); - - contextMenuAction->SetDataStorage(this->GetDataStorage()); - - if(className == "QmitkCreatePolygonModelAction") - { - - if(smoothed == "false") - { - contextMenuAction->SetSmoothed(false); - } - else - { - contextMenuAction->SetSmoothed(true); - } - contextMenuAction->SetDecimated(m_SurfaceDecimation); - } - else if(className == "QmitkStatisticsAction") - { - contextMenuAction->SetFunctionality(this); - } - - contextMenuAction->Run( this->GetCurrentSelection() ); // run the action + // m_FilterModel->invalidate(); + // fix as proposed by R. Khlebnikov in the mitk-users mail from 02.09.2014 + QMetaObject::invokeMethod(m_FilterModel, "invalidate", Qt::QueuedConnection); } void QmitkDataManagerView::OnPreferencesChanged(const berry::IBerryPreferences* prefs) { if (m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() != prefs->GetBool("Place new nodes on top", true)) { m_NodeTreeModel->SetPlaceNewNodesOnTop(!m_NodeTreeModel->GetPlaceNewNodesOnTopFlag()); } bool hideHelperObjects = !prefs->GetBool("Show helper objects", false); if (m_FilterModel->HasFilterPredicate(m_HelperObjectFilterPredicate) != hideHelperObjects) { if (hideHelperObjects) { m_FilterModel->AddFilterPredicate(m_HelperObjectFilterPredicate); } else { m_FilterModel->RemoveFilterPredicate(m_HelperObjectFilterPredicate); } } bool hideNodesWithNoData = !prefs->GetBool("Show nodes containing no data", false); if (m_FilterModel->HasFilterPredicate(m_NodeWithNoDataFilterPredicate) != hideNodesWithNoData) { if (hideNodesWithNoData) { m_FilterModel->AddFilterPredicate(m_NodeWithNoDataFilterPredicate); } else { m_FilterModel->RemoveFilterPredicate(m_NodeWithNoDataFilterPredicate); } } m_GlobalReinitOnNodeDelete = prefs->GetBool("Call global reinit if node is deleted", true); m_GlobalReinitOnNodeVisibilityChanged = prefs->GetBool("Call global reinit if node visibility is changed", false); m_NodeTreeView->expandAll(); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); + m_DataNodeContextMenu->SetSurfaceDecimation(m_SurfaceDecimation); m_NodeTreeModel->SetAllowHierarchyChange(prefs->GetBool("Allow changing of parent node", false)); - this->GlobalReinit(); -} - -void QmitkDataManagerView::NodeTableViewContextMenuRequested( const QPoint & pos ) -{ - QModelIndex selectedProxy = m_NodeTreeView->indexAt ( pos ); - QModelIndex selected = m_FilterModel->mapToSource(selectedProxy); - mitk::DataNode::Pointer node = m_NodeTreeModel->GetNode(selected); - QList selectedNodes = this->GetCurrentSelection(); - - if(!selectedNodes.isEmpty()) - { - ColorActionChanged(); // update color button - - m_NodeMenu->clear(); - QList actions; - if(selectedNodes.size() == 1 ) - { - actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(node); - - for(QList::iterator it = actions.begin(); it != actions.end(); ++it) - { - (*it)->setData(QVariant::fromValue(node.GetPointer())); - } - } - else - actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(selectedNodes); - - if (!m_ShowInActions.isEmpty()) - { - QMenu* showInMenu = m_NodeMenu->addMenu(tr("Show In")); - showInMenu->addActions(m_ShowInActions); - } - m_NodeMenu->addActions(actions); - m_NodeMenu->popup(QCursor::pos()); - } -} - -void QmitkDataManagerView::OpacityChanged(int value) -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(node) - { - float opacity = static_cast(value)/100.0f; - node->SetFloatProperty("opacity", opacity); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } -} - -void QmitkDataManagerView::OpacityActionChanged() -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(node) - { - float opacity = 0.0; - if(node->GetFloatProperty("opacity", opacity)) - { - m_OpacitySlider->setValue(static_cast(opacity*100)); - } - } -} - -void QmitkDataManagerView::ComponentActionChanged() -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - mitk::IntProperty* componentProperty = nullptr; - int numComponents = 0; - if(node) - { - componentProperty = - dynamic_cast(node->GetProperty("Image.Displayed Component")); - mitk::Image* img = dynamic_cast(node->GetData()); - if (img != nullptr) - { - numComponents = img->GetPixelType().GetNumberOfComponents(); - } - } - if (componentProperty && numComponents > 1) - { - m_ComponentSlider->SetProperty(componentProperty); - m_ComponentSlider->setMinValue(0); - m_ComponentSlider->setMaxValue(numComponents-1); - } - else - { - m_ComponentSlider->SetProperty(static_cast(nullptr)); - } -} - -void QmitkDataManagerView::ColorChanged() -{ - bool color_selected = false; - QColor newColor; - - auto selected_indices = m_NodeTreeView->selectionModel()->selectedIndexes(); - for (auto& selected_index : selected_indices) - { - auto node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(selected_index)); - if(node) - { - float rgb[3]; - if (node->GetColor(rgb)) - { - if (!color_selected) - { - QColor initial(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); - newColor = QColorDialog::getColor(initial, nullptr, QString(tr("Change color"))); - - if ( newColor.isValid() ) - { - color_selected = true; - } - else - { - return; - } - } - - node->SetProperty("color", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); - if ( node->GetProperty("binaryimage.selectedcolor") ) - { - node->SetProperty("binaryimage.selectedcolor", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); - } - } - } - } - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkDataManagerView::ColorActionChanged() -{ - // Adapts color displayed in context menu item - auto selected_indices = m_NodeTreeView->selectionModel()->selectedIndexes(); - if (selected_indices.isEmpty()) - return; - - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(selected_indices.front())); - if(node) - { - float rgb[3]; - if (node->GetColor(rgb)) - { - QColor color(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); - QString styleSheet = QString("background-color: ") + color.name(QColor::HexRgb); - m_ColorButton->setAutoFillBackground(true); - m_ColorButton->setStyleSheet(styleSheet); - } - } -} - -void QmitkDataManagerView::TextureInterpolationChanged() -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(node) - { - bool textureInterpolation = false; - node->GetBoolProperty("texture interpolation", textureInterpolation); - m_TextureInterpolation->setChecked(textureInterpolation); - } -} - -void QmitkDataManagerView::TextureInterpolationToggled( bool checked ) -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(node) - { - node->SetBoolProperty("texture interpolation", checked); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } - -} - -void QmitkDataManagerView::ColormapActionToggled( bool /*checked*/ ) -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(!node) - return; - - mitk::LookupTableProperty::Pointer lookupTableProperty = - dynamic_cast(node->GetProperty("LookupTable")); - if (!lookupTableProperty) - return; - - QAction* senderAction = qobject_cast(QObject::sender()); - if(!senderAction) - return; - - std::string activatedItem = senderAction->text().toStdString(); - - mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); - if (!lookupTable) - return; - - lookupTable->SetType(activatedItem); - lookupTableProperty->SetValue(lookupTable); - mitk::RenderingModeProperty::Pointer renderingMode = - dynamic_cast(node->GetProperty("Image Rendering.Mode")); - renderingMode->SetValue(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkDataManagerView::ColormapMenuAboutToShow() -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(!node) - return; - - mitk::LookupTableProperty::Pointer lookupTableProperty = - dynamic_cast(node->GetProperty("LookupTable")); - if (!lookupTableProperty) - { - mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); - lookupTableProperty = mitk::LookupTableProperty::New(); - lookupTableProperty->SetLookupTable(mitkLut); - node->SetProperty("LookupTable", lookupTableProperty); - } - - mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); - if (!lookupTable) - return; - - m_ColormapAction->menu()->clear(); - QAction* tmp; - - int i = 0; - std::string lutType = lookupTable->typenameList[i]; - - while (lutType != "END_OF_ARRAY") - { - tmp = m_ColormapAction->menu()->addAction(QString::fromStdString(lutType)); - tmp->setCheckable(true); - - if (lutType == lookupTable->GetActiveTypeAsString()) - { - tmp->setChecked(true); - } - - QObject::connect(tmp, SIGNAL(triggered(bool)), this, SLOT(ColormapActionToggled(bool))); - - lutType = lookupTable->typenameList[++i]; - } -} - -void QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow() -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(!node) - return; - - mitk::EnumerationProperty* representationProp = - dynamic_cast (node->GetProperty("material.representation")); - if(!representationProp) - return; - - // clear menu - m_SurfaceRepresentation->menu()->clear(); - QAction* tmp; - - // create menu entries - for(mitk::EnumerationProperty::EnumConstIterator it=representationProp->Begin(); it!=representationProp->End() - ; it++) - { - tmp = m_SurfaceRepresentation->menu()->addAction(QString::fromStdString(it->second)); - tmp->setCheckable(true); - - if(it->second == representationProp->GetValueAsString()) - { - tmp->setChecked(true); - } - - QObject::connect( tmp, SIGNAL( triggered(bool) ) - , this, SLOT( SurfaceRepresentationActionToggled(bool) ) ); - } -} - -void QmitkDataManagerView::SurfaceRepresentationActionToggled( bool /*checked*/ ) -{ - mitk::DataNode* node = m_NodeTreeModel->GetNode(m_FilterModel->mapToSource(m_NodeTreeView->selectionModel()->currentIndex())); - if(!node) - return; - - mitk::EnumerationProperty* representationProp = - dynamic_cast (node->GetProperty("material.representation")); - if(!representationProp) - return; - - QAction* senderAction = qobject_cast ( QObject::sender() ); - - if(!senderAction) - return; - - std::string activatedItem = senderAction->text().toStdString(); - - if ( activatedItem != representationProp->GetValueAsString() ) - { - if ( representationProp->IsValidEnumerationValue( activatedItem ) ) - { - representationProp->SetValue( activatedItem ); - representationProp->InvokeEvent( itk::ModifiedEvent() ); - representationProp->Modified(); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } - } - -} - -void QmitkDataManagerView::ReinitSelectedNodes( bool ) -{ - auto renderWindow = this->GetRenderWindowPart(); - - if (nullptr == renderWindow) - renderWindow = this->OpenRenderWindowPart(false); - - if (nullptr == renderWindow) - return; - - auto dataStorage = this->GetDataStorage(); - - auto selectedNodesIncludedInBoundingBox = mitk::NodePredicateAnd::New( - mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))), - mitk::NodePredicateProperty::New("selected", mitk::BoolProperty::New(true))); - - auto nodes = dataStorage->GetSubset(selectedNodesIncludedInBoundingBox); - - if (nodes->empty()) - return; - - if (1 == nodes->Size()) // Special case: If exactly one ... - { - auto image = dynamic_cast(nodes->ElementAt(0)->GetData()); - - if (nullptr != image) // ... image is selected, reinit is expected to rectify askew images. - { - mitk::RenderingManager::GetInstance()->InitializeViews(image->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); - return; - } - } - - auto boundingGeometry = dataStorage->ComputeBoundingGeometry3D(nodes, "visible"); - - mitk::RenderingManager::GetInstance()->InitializeViews(boundingGeometry); -} - -void QmitkDataManagerView::RemoveSelectedNodes( bool ) -{ - QModelIndexList indexesOfSelectedRowsFiltered = m_NodeTreeView->selectionModel()->selectedRows(); - QModelIndexList indexesOfSelectedRows; - for (int i = 0; i < indexesOfSelectedRowsFiltered.size(); ++i) - { - indexesOfSelectedRows.push_back(m_FilterModel->mapToSource(indexesOfSelectedRowsFiltered[i])); - } - if(indexesOfSelectedRows.size() < 1) - { - return; - } - std::vector selectedNodes; - - mitk::DataNode::Pointer node = nullptr; - QString question = tr("Do you really want to remove "); - - for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() - ; it != indexesOfSelectedRows.end(); it++) - { - node = m_NodeTreeModel->GetNode(*it); - // if node is not defined or if the node contains geometry data do not remove it - if ( node.IsNotNull() /*& strcmp(node->GetData()->GetNameOfClass(), "PlaneGeometryData") != 0*/ ) - { - selectedNodes.push_back(node); - question.append(QString::fromStdString(node->GetName())); - question.append(", "); - } - } - // remove the last two characters = ", " - question = question.remove(question.size()-2, 2); - question.append(tr(" from data storage?")); - - QMessageBox::StandardButton answerButton = QMessageBox::question( m_Parent - , tr("DataManager") - , question - , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - - if(answerButton == QMessageBox::Yes) - { - for (std::vector::iterator it = selectedNodes.begin() - ; it != selectedNodes.end(); it++) - { - node = *it; - this->GetDataStorage()->Remove(node); - if (m_GlobalReinitOnNodeDelete) - this->GlobalReinit(false); - } - } -} - -void QmitkDataManagerView::MakeAllNodesInvisible( bool ) -{ - QList nodes = m_NodeTreeModel->GetNodeSet(); - - foreach(mitk::DataNode::Pointer node, nodes) - { - node->SetVisibility(false); - } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkDataManagerView::ShowOnlySelectedNodes( bool ) -{ - QList selectedNodes = this->GetCurrentSelection(); - QList allNodes = m_NodeTreeModel->GetNodeSet(); - - foreach(mitk::DataNode::Pointer node, allNodes) - { - node->SetVisibility(selectedNodes.contains(node)); - } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkDataManagerView::ToggleVisibilityOfSelectedNodes( bool ) -{ - QList selectedNodes = this->GetCurrentSelection(); - - bool isVisible = false; - foreach(mitk::DataNode::Pointer node, selectedNodes) - { - isVisible = false; - node->GetBoolProperty("visible", isVisible); - node->SetVisibility(!isVisible); - } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkDataManagerView::ShowInfoDialogForSelectedNodes( bool ) -{ - QList selectedNodes = this->GetCurrentSelection(); - - QmitkInfoDialog _QmitkInfoDialog(selectedNodes, this->m_Parent); - _QmitkInfoDialog.exec(); -} - -void QmitkDataManagerView::NodeChanged(const mitk::DataNode* /*node*/) -{ - // m_FilterModel->invalidate(); - // fix as proposed by R. Khlebnikov in the mitk-users mail from 02.09.2014 - QMetaObject::invokeMethod( m_FilterModel, "invalidate", Qt::QueuedConnection ); + GlobalReinitAction::Run(GetSite(), GetDataStorage()); } -QItemSelectionModel *QmitkDataManagerView::GetDataNodeSelectionModel() const -{ - return m_NodeTreeView->selectionModel(); -} - -void QmitkDataManagerView::GlobalReinit( bool ) -{ - mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); - - if (renderWindow == nullptr) - renderWindow = this->OpenRenderWindowPart(false); - - // no render window available - if (renderWindow == nullptr) return; - - mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); -} - -void QmitkDataManagerView::NodeTreeViewRowsRemoved ( - const QModelIndex & /*parent*/, int /*start*/, int /*end*/ ) -{ - m_CurrentRowCount = m_NodeTreeModel->rowCount(); -} -void QmitkDataManagerView::NodeTreeViewRowsInserted( const QModelIndex & parent, int, int ) +////////////////////////////////////////////////////////////////////////// +// Node tree modification +////////////////////////////////////////////////////////////////////////// +void QmitkDataManagerView::NodeTreeViewRowsInserted(const QModelIndex& parent, int /*start*/, int /*end*/) { QModelIndex viewIndex = m_FilterModel->mapFromSource(parent); m_NodeTreeView->setExpanded(viewIndex, true); // a new row was inserted - if( m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1 ) + if (m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1) { - this->OpenRenderWindowPart(); + OpenRenderWindowPart(); m_CurrentRowCount = m_NodeTreeModel->rowCount(); } } -void QmitkDataManagerView::NodeSelectionChanged( const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/ ) +void QmitkDataManagerView::NodeTreeViewRowsRemoved(const QModelIndex& /*parent*/, int /*start*/, int /*end*/) { - auto selectedNodes = this->GetCurrentSelection(); + m_CurrentRowCount = m_NodeTreeModel->rowCount(); +} + +void QmitkDataManagerView::NodeSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) +{ + auto selectedNodes = GetCurrentSelection(); + auto nodeSet = m_NodeTreeModel->GetNodeSet(); - for (auto node : m_NodeTreeModel->GetNodeSet()) + for (auto node : nodeSet) { if (node.IsNotNull()) + { node->SetSelected(selectedNodes.contains(node)); + } } } void QmitkDataManagerView::OnNodeVisibilityChanged() { if (m_GlobalReinitOnNodeVisibilityChanged) { - mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(GetDataStorage()); + GlobalReinitAction::Run(GetSite(), GetDataStorage()); } else { mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } -void QmitkDataManagerView::ShowIn(const QString &editorId) +void QmitkDataManagerView::ShowIn(const QString& editorId) { - berry::IWorkbenchPage::Pointer page = this->GetSite()->GetPage(); - berry::IEditorInput::Pointer input(new mitk::DataStorageEditorInput(this->GetDataStorageReference())); + berry::IWorkbenchPage::Pointer page = GetSite()->GetPage(); + berry::IEditorInput::Pointer input(new mitk::DataStorageEditorInput(GetDataStorageReference())); page->OpenEditor(input, editorId, false, berry::IWorkbenchPage::MATCH_ID); } -mitk::IRenderWindowPart* QmitkDataManagerView::OpenRenderWindowPart(bool activatedEditor) +QItemSelectionModel* QmitkDataManagerView::GetDataNodeSelectionModel() const +{ + return m_NodeTreeView->selectionModel(); +} + +mitk::IRenderWindowPart* QmitkDataManagerView::OpenRenderWindowPart(bool activatedEditor/* = true*/) { if (activatedEditor) { - return this->GetRenderWindowPart(QmitkAbstractView::ACTIVATE | QmitkAbstractView::OPEN); + return GetRenderWindowPart(QmitkAbstractView::ACTIVATE | QmitkAbstractView::OPEN); } else { - return this->GetRenderWindowPart(QmitkAbstractView::BRING_TO_FRONT | QmitkAbstractView::OPEN); + return GetRenderWindowPart(QmitkAbstractView::BRING_TO_FRONT | QmitkAbstractView::OPEN); } -} +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h index 2d2e5515aa..fc6920db54 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h +++ b/Plugins/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.h @@ -1,270 +1,149 @@ /*=================================================================== 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 QMITKDATAMANAGERVIEW_H_ #define QMITKDATAMANAGERVIEW_H_ -// BlueBerry includes +#include + +// mitk core +#include + +// berry plugin #include -/// Qmitk +// mitk gui qt common plugin #include -#include -/// Qt -#include +// mitk gui qt application +#include -#include +// qt +#include -// Forward declarations -class QMenu; +// forward declarations class QAction; -class QComboBox; -class QWidgetAction; -class QSlider; class QModelIndex; class QTreeView; -class QPushButton; -class QToolBar; -class QMenu; class QSignalMapper; class QmitkDnDFrameWidget; class QmitkDataStorageTreeModel; class QmitkDataManagerItemDelegate; -class QmitkNumberPropertySlider; class QmitkDataStorageFilterProxyModel; -/// -/// \ingroup org_mitk_gui_qt_datamanager_internal -/// -/// \brief A View class that can show all data tree nodes of a certain DataStorage -/// -/// \TODO: complete PACS support, in save dialog show regular filename -/// +/** +* @brief A view that shows all data nodes of the data storage in a qt tree view. +* +*/ class MITK_QT_DATAMANAGER QmitkDataManagerView : public QmitkAbstractView { Q_OBJECT public: - static const QString VIEW_ID; // = "org.mitk.extapp.defaultperspective" - /// - /// \brief Standard ctor. - /// + static const QString VIEW_ID; // = "org.mitk.views.datamanager" + QmitkDataManagerView(); - /// - /// \brief Standard dtor. - /// ~QmitkDataManagerView() override; -public slots: - /// - /// Invoked when the opacity slider changed - /// - void OpacityChanged(int value); - /// - /// Invoked when the opacity action changed - /// In this function the the opacity slider is set to the selected nodes opacity value - /// - void OpacityActionChanged(); - /// Invoked when the component action changed - /// In this function the the opacity slider is set to the selected nodes opacity value - /// - void ComponentActionChanged(); - /// - /// Invoked when the color button is pressed - /// - void ColorChanged(); - /// - /// Invoked when the color action changed - /// - void ColorActionChanged(); - /// - /// Invoked when the color button is pressed - /// - void TextureInterpolationChanged(); - /// - /// Invoked when the color action changed - /// - void TextureInterpolationToggled ( bool checked ); - /// - /// \brief Agreggates available colormaps - /// - void ColormapMenuAboutToShow (); - /// - /// \brief changes the active colormap - /// - void ColormapActionToggled (bool); - /// - /// SurfaceRepresentationActionToggled - /// - void SurfaceRepresentationMenuAboutToShow (); - /// - /// SurfaceRepresentationActionToggled - /// - void SurfaceRepresentationActionToggled ( bool checked ); - /// - /// \brief Shows a node context menu. - /// - void NodeTableViewContextMenuRequested( const QPoint & index ); - /// - /// \brief Invoked when an element should be removed. - /// - void RemoveSelectedNodes( bool checked = false ); - /// - /// \brief Invoked when an element should be reinitiliased. - /// - void ReinitSelectedNodes( bool checked = false ); - /// - /// \brief Invoked when the visibility of the selected nodes should be toggled. - /// - void MakeAllNodesInvisible ( bool checked = false ); - /// - /// \brief Makes all selected nodes visible, all other nodes invisible. - /// - void ShowOnlySelectedNodes ( bool checked = false ); - /// - /// \brief Invoked when the visibility of the selected nodes should be toggled. - /// - void ToggleVisibilityOfSelectedNodes ( bool checked = false ); - /// - /// \brief Invoked when infos of the selected nodes should be shown in a dialog. - /// - void ShowInfoDialogForSelectedNodes ( bool checked = false ); - /// - /// \brief Reinits everything. - /// - void GlobalReinit ( bool checked = false ); - /// - /// Invoked when the preferences were changed - /// - void OnPreferencesChanged(const berry::IBerryPreferences*) override; - /// - /// \brief will be toggled when a extension point context menu action is toggled - /// this is a proxy method which will load the corresponding extension class - /// and run IContextMenuAction - /// - void ContextMenuActionTriggered( bool ); +public Q_SLOTS: + // invoked when the berry preferences were changed + void OnPreferencesChanged(const berry::IBerryPreferences* prefs) override; + + ////////////////////////////////////////////////////////////////////////// + // Slots for Qt node tree signals + ////////////////////////////////////////////////////////////////////////// /// When rows are inserted auto expand them - void NodeTreeViewRowsInserted ( const QModelIndex & parent, int start, int end ); + void NodeTreeViewRowsInserted(const QModelIndex& parent, int start, int end); /// will setup m_CurrentRowCount - void NodeTreeViewRowsRemoved ( const QModelIndex & parent, int start, int end ); + void NodeTreeViewRowsRemoved(const QModelIndex& parent, int start, int end); /// Whenever the selection changes set the "selected" property respectively - void NodeSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected ); + void NodeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); void OnNodeVisibilityChanged(); /// Opens the editor with the given id using the current data storage void ShowIn(const QString& editorId); protected: - /// - /// \brief Create the view here. - /// void CreateQtPartControl(QWidget* parent) override; void SetFocus() override; - - /// - /// \brief Shows a file open dialog. - /// - void FileOpen( const char * fileName, mitk::DataNode* parentNode ); - /// /// React to node changes. Overridden from QmitkAbstractView. /// - void NodeChanged(const mitk::DataNode* /*node*/) override; + void NodeChanged(const mitk::DataNode* node) override; + protected: QWidget* m_Parent; - QmitkDnDFrameWidget* m_DndFrameWidget; + QmitkDnDFrameWidget* m_DnDFrameWidget; /// /// \brief A plain widget as the base pane. /// QmitkDataStorageTreeModel* m_NodeTreeModel; QmitkDataStorageFilterProxyModel* m_FilterModel; mitk::NodePredicateBase::Pointer m_HelperObjectFilterPredicate; mitk::NodePredicateBase::Pointer m_NodeWithNoDataFilterPredicate; /// - /// Holds the preferences for the datamanager. + /// Holds the preferences for the data manager. /// berry::IBerryPreferences::Pointer m_DataManagerPreferencesNode; /// - /// saves the configuration elements for the context menu actions from extension points - /// - std::map m_ConfElements; - /// /// \brief The Table view to show the selected nodes. /// QTreeView* m_NodeTreeView; /// /// \brief The context menu that shows up when right clicking on a node. /// - QMenu* m_NodeMenu; + QmitkDataNodeContextMenu* m_DataNodeContextMenu; /// /// \brief flag indicating whether a surface created from a selected decimation is decimated with vtkQuadricDecimation or not /// bool m_SurfaceDecimation; - - ///# A list of ALL actions for the Context Menu - using DescriptorActionListType = std::vector< std::pair< QmitkNodeDescriptor*, QAction* > >; - DescriptorActionListType m_DescriptorActionList; - - /// A Slider widget to change the opacity of a node - QSlider* m_OpacitySlider; - /// A Slider widget to change the rendered vector component of an image - QmitkNumberPropertySlider* m_ComponentSlider; - /// button to change the color of a node - QPushButton* m_ColorButton; - /// TextureInterpolation action - QAction* m_TextureInterpolation; - /// SurfaceRepresentation action - QAction* m_SurfaceRepresentation; - /// Lookuptable selection action - QAction* m_ColormapAction; - /// Maps "Show in" actions to editor ids QSignalMapper* m_ShowInMapper; /// A list of "Show in" actions QList m_ShowInActions; - /// saves the current amount of rows shown in the datamanager + /// saves the current amount of rows shown in the data manager size_t m_CurrentRowCount; /// if true, GlobalReinit() is called if a node is deleted - bool m_GlobalReinitOnNodeDelete; + bool m_GlobalReinitOnNodeDelete; bool m_GlobalReinitOnNodeVisibilityChanged; QmitkDataManagerItemDelegate* m_ItemDelegate; private: QItemSelectionModel* GetDataNodeSelectionModel() const override; /// Reopen multi widget editor if it has been closed mitk::IRenderWindowPart *OpenRenderWindowPart(bool activatedEditor = true); + }; -#endif /*QMITKDATAMANAGERVIEW_H_*/ +#endif // QMITKDATAMANAGERVIEW_H_ diff --git a/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp b/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp index fa6fb7f330..98bd6c0162 100644 --- a/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp +++ b/Plugins/org.mitk.gui.qt.datamanager/src/internal/QmitkNodeTableViewKeyFilter.cpp @@ -1,92 +1,92 @@ /*=================================================================== 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 "QmitkNodeTableViewKeyFilter.h" #include #include #include "../QmitkDataManagerView.h" #include "berryIPreferencesService.h" #include "berryPlatform.h" QmitkNodeTableViewKeyFilter::QmitkNodeTableViewKeyFilter( QObject* _DataManagerView ) : QObject(_DataManagerView) { m_PreferencesService = berry::Platform::GetPreferencesService(); } bool QmitkNodeTableViewKeyFilter::eventFilter( QObject *obj, QEvent *event ) { QmitkDataManagerView* _DataManagerView = qobject_cast(this->parent()); if (event->type() == QEvent::KeyPress && _DataManagerView) { berry::IPreferences::Pointer nodeTableKeyPrefs = m_PreferencesService->GetSystemPreferences()->Node("/DataManager/Hotkeys"); QKeySequence _MakeAllInvisible = QKeySequence(nodeTableKeyPrefs->Get("Make all nodes invisible", "Ctrl+, V")); QKeySequence _ToggleVisibility = QKeySequence(nodeTableKeyPrefs->Get("Toggle visibility of selected nodes", "V")); QKeySequence _DeleteSelectedNodes = QKeySequence(nodeTableKeyPrefs->Get("Delete selected nodes", "Del")); QKeySequence _Reinit = QKeySequence(nodeTableKeyPrefs->Get("Reinit selected nodes", "R")); QKeySequence _GlobalReinit = QKeySequence(nodeTableKeyPrefs->Get("Global Reinit", "Ctrl+, R")); QKeySequence _ShowInfo = QKeySequence(nodeTableKeyPrefs->Get("Show Node Information", "Ctrl+, I")); QKeyEvent *keyEvent = static_cast(event); QKeySequence _KeySequence = QKeySequence(keyEvent->modifiers(), keyEvent->key()); // if no modifier was pressed the sequence is now empty if(_KeySequence.isEmpty()) _KeySequence = QKeySequence(keyEvent->key()); if(_KeySequence == _MakeAllInvisible) { // trigger deletion of selected node(s) - _DataManagerView->MakeAllNodesInvisible(true); + _DataManagerView->OnMakeAllNodesInvisible(true); // return true: this means the delete key event is not send to the table return true; } else if(_KeySequence == _DeleteSelectedNodes) { // trigger deletion of selected node(s) - _DataManagerView->RemoveSelectedNodes(true); + _DataManagerView->OnRemoveSelectedNodes(true); // return true: this means the delete key event is not send to the table return true; } else if(_KeySequence == _ToggleVisibility) { // trigger deletion of selected node(s) - _DataManagerView->ToggleVisibilityOfSelectedNodes(true); + _DataManagerView->OnToggleVisibilityOfSelectedNodes(true); // return true: this means the delete key event is not send to the table return true; } else if(_KeySequence == _Reinit) { - _DataManagerView->ReinitSelectedNodes(true); + _DataManagerView->OnReinitSelectedNodes(true); return true; } else if(_KeySequence == _GlobalReinit) { - _DataManagerView->GlobalReinit(true); + _DataManagerView->OnGlobalReinit(true); return true; } else if(_KeySequence == _ShowInfo) { - _DataManagerView->ShowInfoDialogForSelectedNodes(true); + _DataManagerView->OnShowInfoDialogForSelectedNodes(true); return true; } } // standard event processing return QObject::eventFilter(obj, event); }