diff --git a/Modules/QtWidgets/files.cmake b/Modules/QtWidgets/files.cmake index 7ed16516ea..c59be06a5c 100644 --- a/Modules/QtWidgets/files.cmake +++ b/Modules/QtWidgets/files.cmake @@ -1,89 +1,96 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES QmitkAbstractDataStorageModel.cpp QmitkApplicationCursor.cpp QmitkDataStorageComboBox.cpp QmitkDataStorageDefaultListModel.cpp QmitkDataStorageListModel.cpp QmitkDataStorageTableModel.cpp QmitkDataStorageTreeModel.cpp QmitkFileReaderOptionsDialog.cpp QmitkFileReaderWriterOptionsWidget.cpp QmitkFileWriterOptionsDialog.cpp QmitkIOUtil.cpp QmitkLevelWindowPresetDefinitionDialog.cpp QmitkLevelWindowRangeChangeDialog.cpp QmitkLevelWindowWidgetContextMenu.cpp QmitkLevelWindowWidget.cpp QmitkLineEditLevelWindowWidget.cpp QmitkMemoryUsageIndicatorView.cpp QmitkMimeTypes.cpp QmitkNodeDescriptor.cpp -QmitkColoredNodeDescriptor.cpp + QmitkColoredNodeDescriptor.cpp QmitkNodeDescriptorManager.cpp QmitkRenderWindowMenu.cpp QmitkProgressBar.cpp QmitkPropertiesTableEditor.cpp QmitkPropertiesTableModel.cpp QmitkPropertyDelegate.cpp QmitkRegisterClasses.cpp QmitkRenderingManager.cpp QmitkRenderingManagerFactory.cpp QmitkRenderWindow.cpp QmitkServiceListWidget.cpp QmitkSliderLevelWindowWidget.cpp QmitkStdMultiWidget.cpp QmitkMouseModeSwitcher.cpp QmitkDataStorageFilterProxyModel.cpp QmitkDataStorageComboBoxWithSelectNone.cpp QmitkPropertyItem.cpp QmitkPropertyItemDelegate.cpp QmitkPropertyItemModel.cpp + QmitkAbstractDataStorageViewWidget.cpp + QmitkDataStorageListViewWidget.cpp + QmitkModelViewSelectionConnector.cpp ) set(MOC_H_FILES include/QmitkAbstractDataStorageModel.h include/QmitkDataStorageComboBox.h include/QmitkDataStorageTableModel.h include/QmitkDataStorageTreeModel.h include/QmitkFileReaderOptionsDialog.h include/QmitkFileReaderWriterOptionsWidget.h include/QmitkFileWriterOptionsDialog.h include/QmitkLevelWindowPresetDefinitionDialog.h include/QmitkLevelWindowRangeChangeDialog.h include/QmitkLevelWindowWidgetContextMenu.h include/QmitkLevelWindowWidget.h include/QmitkLineEditLevelWindowWidget.h include/QmitkMemoryUsageIndicatorView.h include/QmitkNodeDescriptor.h include/QmitkColoredNodeDescriptor.h include/QmitkNodeDescriptorManager.h include/QmitkRenderWindowMenu.h include/QmitkProgressBar.h include/QmitkPropertiesTableEditor.h include/QmitkPropertyDelegate.h include/QmitkRenderingManager.h include/QmitkRenderWindow.h include/QmitkServiceListWidget.h include/QmitkSliderLevelWindowWidget.h include/QmitkStdMultiWidget.h include/QmitkMouseModeSwitcher.h include/QmitkDataStorageComboBoxWithSelectNone.h include/QmitkPropertyItemDelegate.h include/QmitkPropertyItemModel.h + include/QmitkDataStorageListViewWidget.h + include/QmitkAbstractDataStorageViewWidget.h + include/QmitkModelViewSelectionConnector.h ) set(UI_FILES src/QmitkFileReaderOptionsDialog.ui src/QmitkFileWriterOptionsDialog.ui src/QmitkLevelWindowPresetDefinition.ui src/QmitkLevelWindowWidget.ui src/QmitkLevelWindowRangeChange.ui src/QmitkMemoryUsageIndicator.ui src/QmitkServiceListWidgetControls.ui + src/QmitkDataStorageListViewWidget.ui ) set(QRC_FILES resource/Qmitk.qrc ) diff --git a/Modules/QtWidgets/include/QmitkAbstractDataStorageViewWidget.h b/Modules/QtWidgets/include/QmitkAbstractDataStorageViewWidget.h new file mode 100644 index 0000000000..6b8b77c269 --- /dev/null +++ b/Modules/QtWidgets/include/QmitkAbstractDataStorageViewWidget.h @@ -0,0 +1,132 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +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 QMITKABSTRACTDATASTORAGEVIEWWIDGET_H +#define QMITKABSTRACTDATASTORAGEVIEWWIDGET_H + +#include + +#include + +// mitk core +#include +#include + +// qt +#include + +class QAbstractItemVew; + +/* +* @brief This abstract class extends the 'QAbstractItemModel' to accept an 'mitk::DataStorage' and a 'mitk::NodePredicateBase'., +* It registers itself as a node event listener of the data storage. +* The 'QmitkAbstractDataStorageViewWidget' provides three empty functions, 'NodeAdded', 'NodeChanged' and 'NodeRemoved', that +* may be implemented by the subclasses. These functions allow to react to the 'AddNodeEvent', 'ChangedNodeEvent' and +* 'RemoveNodeEvent' of the data storage. This might be useful to force an update on the custom view to correctly +* represent the content of the data storage. +* +* A concrete implementations of this class is used to store the temporarily shown data nodes of the data storage. +* These nodes may be a subset of all the nodes inside the data storage, if a specific node predicate is set. +* +* A model that implements this class has to return mitk::DataNode::Pointer objects for model indexes when the +* role is QmitkDataNodeRole. +*/ +class MITKQTWIDGETS_EXPORT QmitkAbstractDataStorageViewWidget : public QWidget +{ + Q_OBJECT + +public: + virtual ~QmitkAbstractDataStorageViewWidget(); + + /* + * @brief Sets the data storage that will be used /monitored by widget. + * + * @par dataStorage A pointer to the data storage to set. + */ + void SetDataStorage(mitk::DataStorage* dataStorage); + + /* + * @brief Sets the node predicate and updates the widget, according to the node predicate. + * + * @par nodePredicate A pointer to node predicate. + */ + virtual void SetNodePredicate(mitk::NodePredicateBase* nodePredicate); + + mitk::NodePredicateBase* GetNodePredicate() const; + + using NodeList = QList; + + NodeList GetSelectedNodes() const; + + virtual QAbstractItemView* GetView() = 0; + virtual QAbstractItemView* GetView() const = 0; + + bool GetSelectOnlyVisibleNodes() const; + +Q_SIGNALS: + /* + * @brief A signal that will be emitted if the selected node has changed. + * + * @par nodes A list of data nodes that are newly selected. + */ + void CurrentSelectionChanged(NodeList nodes); + + public Q_SLOTS: + /* + * @brief Change the selection modus of the item view's selection model. + * + * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view. + * An outgoing selection can then at most contain the filtered nodes. + * If false, the incoming non-visible selection will be stored and later added to the outgoing selection, + * to include the original selection that could not be modified. + * The part of the original selection, that is non-visible are the nodes that are not + * + * @par selectOnlyVisibleNodes The bool value to define the selection modus. + */ + void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes); + + /* + * @brief Transform a list of data nodes into a model selection and set this as a new selection of the + * selection model of the private member item view. + * + * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If + * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case + * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable + * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection + * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes'). + * + * @par nodes A list of data nodes that should be newly selected. + */ + void SetCurrentSelection(NodeList selectedNodes); + +protected Q_SLOTS: + void OnSelectionChanged(NodeList selectedNodes); + +protected: + /** Helper function is called if data storage or predicate is changed to (re) inizialze the widget correctly. + Implement the function in derived classes.*/ + virtual void Initialize() = 0; + + mitk::WeakPointer m_DataStorage; + mitk::NodePredicateBase::Pointer m_NodePredicate; + + std::unique_ptr m_Connector; + + QmitkAbstractDataStorageViewWidget(QWidget* parent = nullptr); + +}; + +#endif // QMITKABSTRACTDATASTORAGEMODEL_H diff --git a/Modules/QtWidgets/include/QmitkDataStorageListViewWidget.h b/Modules/QtWidgets/include/QmitkDataStorageListViewWidget.h new file mode 100644 index 0000000000..d5897e3b5c --- /dev/null +++ b/Modules/QtWidgets/include/QmitkDataStorageListViewWidget.h @@ -0,0 +1,57 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +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 QMITKDATASTORAGELISTVIEWWIDGET_H +#define QMITKDATASTORAGELISTVIEWWIDGET_H + +#include + +#include + +#include "ui_QmitkDataStorageListViewWidget.h" + +/* +* @brief This abstract class extends the 'QAbstractItemModel' to accept an 'mitk::DataStorage' and a 'mitk::NodePredicateBase'., +* It registers itself as a node event listener of the data storage. +* The 'QmitkDataStorageListViewWidget' provides three empty functions, 'NodeAdded', 'NodeChanged' and 'NodeRemoved', that +* may be implemented by the subclasses. These functions allow to react to the 'AddNodeEvent', 'ChangedNodeEvent' and +* 'RemoveNodeEvent' of the data storage. This might be useful to force an update on the custom view to correctly +* represent the content of the data storage. +* +* A concrete implementations of this class is used to store the temporarily shown data nodes of the data storage. +* These nodes may be a subset of all the nodes inside the data storage, if a specific node predicate is set. +* +* A model that implements this class has to return mitk::DataNode::Pointer objects for model indexes when the +* role is QmitkDataNodeRole. +*/ +class MITKQTWIDGETS_EXPORT QmitkDataStorageListViewWidget : public QmitkAbstractDataStorageViewWidget +{ + +public: + QmitkDataStorageListViewWidget(QWidget* parent = nullptr); + + virtual QAbstractItemView* GetView() override; + virtual QAbstractItemView* GetView() const override; + +protected: + virtual void Initialize() override; + + QmitkAbstractDataStorageModel* m_StorageModel; + + Ui_QmitkDataStorageListViewWidget m_Controls; +}; + +#endif // QMITKABSTRACTDATASTORAGEMODEL_H diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.h b/Modules/QtWidgets/include/QmitkModelViewSelectionConnector.h similarity index 94% rename from Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.h rename to Modules/QtWidgets/include/QmitkModelViewSelectionConnector.h index 8a8149e056..380ff2f443 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.h +++ b/Modules/QtWidgets/include/QmitkModelViewSelectionConnector.h @@ -1,148 +1,156 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. 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 QMITKMODELVIEWSELECTIONCONNECTOR_H #define QMITKMODELVIEWSELECTIONCONNECTOR_H -#include +#include // qt widgets module #include // qt #include -/* +/** * @brief The 'QmitkModelViewSelectionConnector' is used to handle the selections of a model-view-pair. * * The class accepts a view and a model, which are used to react to selection changes. This class is able to propagate selection changes * to and receive from its surrounding class. * * The model-view-pair can be added as a selection listener to a selection service. This should be done by using 'AddPostSelectionListener' * with the existing selection service of the surrounding 'QmitkAbstractView'. * The model-view-pair can be set as a selection provider. This should be done by using 'SetAsSelectionProvider' with the existing * selection provider of the surrounding 'QmitkAbstractView'. * * The 'QmitkModelViewSelectionConnector' offers a public slot and signal that can be used to set / propagate the selected * nodes in the current view: * The 'SetCurrentSelection'-slot finds the indices of the given selected nodes in its internal data storage model and * changes the selection of the accordingly. * The 'CurrentSelectionChanged'-signal sends a list of selected nodes to it's environment. * The 'CurrentSelectionChanged'-signal is emitted by the 'ChangeModelSelection'-function, which transforms the internal item view's * selection into a data node list. The 'ChangeModelSelection'-function is called whenever the selection of the item view's * selection model changes. */ -class MITK_QT_COMMON QmitkModelViewSelectionConnector : public QObject +class MITKQTWIDGETS_EXPORT QmitkModelViewSelectionConnector : public QObject { Q_OBJECT public: QmitkModelViewSelectionConnector(); - /* + /** * @brief Set the view whose selection model is used to propagate or receive selection changes. Use the view's data model * to transform selected nodes into model indexes and vice versa. * * @pre The view's data model needs to be a 'QmitkAbstractDataStorageModel'. If so, the data model is received from * the view and stored as a private member. * The data model must return 'mitk::DataNode::Pointer' objects for model indexes if the role is 'QmitkDataNodeRole'. * @throw mitk::Exception, if the view is invalid or the view's data model is not a valid 'QmitkAbstractDataStorageModel'. * * @par view The view to set. */ void SetView(QAbstractItemView* view); + /** + * @brief Retrieve the currently selected nodes (equals the last CurrentSelectionChanged values). + */ + QList GetSelectedNodes() const; + + bool GetSelectOnlyVisibleNodes() const; + Q_SIGNALS: - /* + /** * @brief A signal that will be emitted by the 'ChangeModelSelection'-function. This happens if the selection model * of the private member item view has changed. * * @par nodes A list of data nodes that are newly selected. */ void CurrentSelectionChanged(QList nodes); public Q_SLOTS: - /* + /** * @brief Change the selection modus of the item view's selection model. * * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view. * An outgoing selection can then at most contain the filtered nodes. * If false, the incoming non-visible selection will be stored and later added to the outgoing selection, * to include the original selection that could not be modified. * The part of the original selection, that is non-visible are the nodes that are not * * @par selectOnlyVisibleNodes The bool value to define the selection modus. */ void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes); - /* + + /** * @brief Transform a list of data nodes into a model selection and set this as a new selection of the * selection model of the private member item view. * * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes'). * * @par nodes A list of data nodes that should be newly selected. */ void SetCurrentSelection(QList selectedNodes); private Q_SLOTS: - /* + /** * @brief Transform a model selection into a data node list and emit the 'CurrentSelectionChanged'-signal. * * The function adds the selected nodes from the original selection that could not be modified, if * 'm_SelectOnlyVisibleNodes' is false. * This slot is internally connected to the 'selectionChanged'-signal of the selection model of the private member item view. * * @par selected The newly selected items. * @par deselected The newly deselected items. */ void ChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected); private: QmitkAbstractDataStorageModel* m_Model; QAbstractItemView* m_View; bool m_SelectOnlyVisibleNodes; QList m_NonVisibleSelection; /* * @brief Retrieve the currently selected nodes from the selection model of the private member item view by * transforming the selection indexes into a data node list. * * In order to transform the indices into data nodes, the private data storage model must return * 'mitk::DataNode::Pointer' objects for model indexes if the role is QmitkDataNodeRole. */ - QList GetSelectedNodes() const; + QList GetInternalSelectedNodes() const; /* * @brief Filter the list of given nodes such that only those nodes are used that are valid * when using the data storage model's node predicate. * If no node predicate was set or the data storage model is invalid, the input list * of given nodes is returned. */ QList FilterNodeList(const QList& nodes) const; /* * @brief Return true, if the nodes in the list of given selected nodes are equal to the * currently selected nodes from the selection model of the private member item view. */ bool IsEqualToCurrentSelection(QList& selectedNodes) const; }; #endif // QMITKMODELVIEWSELECTIONCONNECTOR_H diff --git a/Modules/QtWidgets/src/QmitkAbstractDataStorageViewWidget.cpp b/Modules/QtWidgets/src/QmitkAbstractDataStorageViewWidget.cpp new file mode 100644 index 0000000000..316e60cb1f --- /dev/null +++ b/Modules/QtWidgets/src/QmitkAbstractDataStorageViewWidget.cpp @@ -0,0 +1,83 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +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 + +QmitkAbstractDataStorageViewWidget::QmitkAbstractDataStorageViewWidget(QWidget* parent/* = nullptr*/) + : QWidget(parent) + , m_NodePredicate(nullptr) +{ + m_Connector = std::make_unique(); + + connect(m_Connector.get(), &QmitkModelViewSelectionConnector::CurrentSelectionChanged, this, &QmitkAbstractDataStorageViewWidget::OnSelectionChanged); +} + +QmitkAbstractDataStorageViewWidget::~QmitkAbstractDataStorageViewWidget() +{ +} + +void QmitkAbstractDataStorageViewWidget::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + m_DataStorage = dataStorage; + + if (!m_DataStorage.IsExpired()) + { + this->Initialize(); + } + } +} + +void QmitkAbstractDataStorageViewWidget::SetNodePredicate(mitk::NodePredicateBase* nodePredicate) +{ + if (m_NodePredicate != nodePredicate) + { + m_NodePredicate = nodePredicate; + + this->Initialize(); + } +} + +mitk::NodePredicateBase* QmitkAbstractDataStorageViewWidget::GetNodePredicate() const +{ + return m_NodePredicate; +} + +QmitkAbstractDataStorageViewWidget::NodeList QmitkAbstractDataStorageViewWidget::GetSelectedNodes() const +{ + return m_Connector->GetSelectedNodes(); +}; + +bool QmitkAbstractDataStorageViewWidget::GetSelectOnlyVisibleNodes() const +{ + return m_Connector->GetSelectOnlyVisibleNodes(); +}; + +void QmitkAbstractDataStorageViewWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) +{ + m_Connector->SetSelectOnlyVisibleNodes(selectOnlyVisibleNodes); +}; + +void QmitkAbstractDataStorageViewWidget::SetCurrentSelection(NodeList selectedNodes) +{ + m_Connector->SetCurrentSelection(selectedNodes); +}; + +void QmitkAbstractDataStorageViewWidget::OnSelectionChanged(NodeList selectedNodes) +{ + emit CurrentSelectionChanged(selectedNodes); +}; diff --git a/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.cpp b/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.cpp new file mode 100644 index 0000000000..350fb88a93 --- /dev/null +++ b/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.cpp @@ -0,0 +1,44 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +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 + +QmitkDataStorageListViewWidget::QmitkDataStorageListViewWidget(QWidget* parent/* = nullptr*/) + : QmitkAbstractDataStorageViewWidget(parent) +{ + m_Controls.setupUi(this); + m_StorageModel = new QmitkDataStorageDefaultListModel(this); +} + +QAbstractItemView* QmitkDataStorageListViewWidget::GetView() +{ + return m_Controls.view; +}; + +QAbstractItemView* QmitkDataStorageListViewWidget::GetView() const +{ + return m_Controls.view; +}; + +void QmitkDataStorageListViewWidget::Initialize() +{ + m_StorageModel->SetDataStorage(m_DataStorage.Lock()); + m_StorageModel->SetNodePredicate(m_NodePredicate); + + m_Controls.view->setModel(m_StorageModel); +} diff --git a/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.ui b/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.ui new file mode 100644 index 0000000000..4c9d3ca363 --- /dev/null +++ b/Modules/QtWidgets/src/QmitkDataStorageListViewWidget.ui @@ -0,0 +1,36 @@ + + + QmitkDataStorageListViewWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.cpp b/Modules/QtWidgets/src/QmitkModelViewSelectionConnector.cpp similarity index 93% rename from Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.cpp rename to Modules/QtWidgets/src/QmitkModelViewSelectionConnector.cpp index f5a0ccbee4..d631536588 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkModelViewSelectionConnector.cpp +++ b/Modules/QtWidgets/src/QmitkModelViewSelectionConnector.cpp @@ -1,184 +1,191 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. 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. ===================================================================*/ // mitk gui qt common plugin #include "QmitkModelViewSelectionConnector.h" -#include "internal/QmitkDataNodeSelection.h" // qt widgets module #include "QmitkCustomVariants.h" #include "QmitkEnums.h" -// blueberry ui qt plugin -#include - QmitkModelViewSelectionConnector::QmitkModelViewSelectionConnector() : m_Model(nullptr) , m_View(nullptr) , m_SelectOnlyVisibleNodes(false) { // nothing here } void QmitkModelViewSelectionConnector::SetView(QAbstractItemView* view) { if (nullptr != m_View) { disconnect(m_View->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(ChangeModelSelection(const QItemSelection&, const QItemSelection&))); } // reset model-view pair and check for valid function argument m_View = nullptr; m_Model = nullptr; if (nullptr == view) { mitkThrow() << "Invalid item view. To use the model-view selection connector please specify a valid 'QAbstractItemView'."; } if (nullptr == dynamic_cast(view->model())) { mitkThrow() << "Invalid data model. To use the model-view selection connector please set a valid 'QmitkAbstractDataStorageModel' for the given item view."; } // a valid item view and a valid data model was found m_View = view; m_Model = dynamic_cast(m_View->model()); connect(m_View->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), SLOT(ChangeModelSelection(const QItemSelection&, const QItemSelection&))); } void QmitkModelViewSelectionConnector::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) { m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; } void QmitkModelViewSelectionConnector::SetCurrentSelection(QList selectedNodes) { if (nullptr == m_Model || nullptr == m_View) { return; } // filter input nodes and return the modified input node list QList filteredNodes = FilterNodeList(selectedNodes); bool equal = IsEqualToCurrentSelection(filteredNodes); if (equal) { return; } if (!m_SelectOnlyVisibleNodes) { // store the unmodified selection m_NonVisibleSelection = selectedNodes; // remove the nodes in the original selection that are already contained in the filtered input node list // this will keep the selection of the original nodes that are not presented by the current view unmodified, but allows to change the selection of the filtered nodes // later, the nodes of the 'm_NonVisibleSelection' member have to be added again to the list of selected (filtered) nodes, if a selection is sent from the current view (see 'ModelSelectionChanged') auto lambda = [&filteredNodes](mitk::DataNode::Pointer original) { return filteredNodes.contains(original); }; m_NonVisibleSelection.erase(std::remove_if(m_NonVisibleSelection.begin(), m_NonVisibleSelection.end(), lambda), m_NonVisibleSelection.end()); } // create new selection by retrieving the corresponding indices of the (filtered) nodes QItemSelection newCurrentSelection; for (const auto& node : filteredNodes) { QModelIndexList matched = m_Model->match(m_Model->index(0, 0), QmitkDataNodeRole, QVariant::fromValue(node), 1, Qt::MatchRecursive); if (!matched.empty()) { newCurrentSelection.select(matched.front(), matched.front()); } } m_View->selectionModel()->select(newCurrentSelection, QItemSelectionModel::ClearAndSelect); } void QmitkModelViewSelectionConnector::ChangeModelSelection(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) { - QList nodes = GetSelectedNodes(); + emit CurrentSelectionChanged(GetSelectedNodes()); +} + +bool QmitkModelViewSelectionConnector::GetSelectOnlyVisibleNodes() const +{ + return m_SelectOnlyVisibleNodes; +} + +QList QmitkModelViewSelectionConnector::GetSelectedNodes() const +{ + auto nodes = GetInternalSelectedNodes(); if (!m_SelectOnlyVisibleNodes) { // add the non-visible nodes from the original selection nodes.append(m_NonVisibleSelection); } - emit CurrentSelectionChanged(nodes); + + return nodes; } -QList QmitkModelViewSelectionConnector::GetSelectedNodes() const +QList QmitkModelViewSelectionConnector::GetInternalSelectedNodes() const { if (nullptr == m_Model || nullptr == m_View) { return QList(); } QList nodes; QModelIndexList selectedIndexes = m_View->selectionModel()->selectedIndexes(); for (const auto& index : selectedIndexes) { QVariant qvariantDataNode = m_Model->data(index, QmitkDataNodeRole); if (qvariantDataNode.canConvert()) { nodes.push_back(qvariantDataNode.value()); } } return nodes; } QList QmitkModelViewSelectionConnector::FilterNodeList(const QList& nodes) const { if (nodes.isEmpty()) { return QList(); } if (nullptr == m_Model) { return nodes; } mitk::NodePredicateBase* nodePredicate = m_Model->GetNodePredicate(); if (nullptr == nodePredicate) { // no filter set return nodes; } QList result; for (const auto& node : nodes) { if (true == nodePredicate->CheckNode(node)) { result.push_back(node); } } return result; } bool QmitkModelViewSelectionConnector::IsEqualToCurrentSelection(QList& selectedNodes) const { // get the currently selected nodes from the model - QList currentlySelectedNodes = GetSelectedNodes(); + QList currentlySelectedNodes = GetInternalSelectedNodes(); if (currentlySelectedNodes.size() == selectedNodes.size()) { // lambda to compare node pointer inside both lists auto lambda = [](mitk::DataNode::Pointer lhs, mitk::DataNode::Pointer rhs) { return lhs == rhs; }; return std::is_permutation(selectedNodes.begin(), selectedNodes.end(), currentlySelectedNodes.begin(), currentlySelectedNodes.end(), lambda); } return false; } diff --git a/Plugins/org.mitk.gui.qt.common/files.cmake b/Plugins/org.mitk.gui.qt.common/files.cmake index a33682f411..29fa6356e3 100755 --- a/Plugins/org.mitk.gui.qt.common/files.cmake +++ b/Plugins/org.mitk.gui.qt.common/files.cmake @@ -1,42 +1,40 @@ set(SRC_CPP_FILES QmitkAbstractRenderEditor.cpp QmitkAbstractView.cpp QmitkDataNodeSelectionProvider.cpp QmitkDnDFrameWidget.cpp - QmitkModelViewSelectionConnector.cpp QmitkSelectionServiceConnector.cpp QmitkSliceNavigationListener.cpp ) set(INTERNAL_CPP_FILES QmitkCommonActivator.cpp QmitkDataNodeItemModel.cpp QmitkDataNodeSelection.cpp QmitkViewCoordinator.cpp ) set(MOC_H_FILES src/QmitkAbstractRenderEditor.h src/QmitkDnDFrameWidget.h - src/QmitkModelViewSelectionConnector.h src/QmitkSelectionServiceConnector.h src/QmitkSliceNavigationListener.h src/internal/QmitkCommonActivator.h ) set(CACHED_RESOURCE_FILES ) set(QRC_FILES ) 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.datastorageviewertest/files.cmake b/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake index 7346b84a06..e2b7b6c54c 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake @@ -1,32 +1,40 @@ set(SRC_CPP_FILES + QmitkSingleNodeSelectionWidget.cpp + QmitkNodeSelectionDialog.cpp ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkDataStorageViewerTestView.cpp ) set(UI_FILES src/internal/QmitkDataStorageViewerTestControls.ui + src/QmitkSingleNodeSelectionWidget.ui + src/QmitkNodeSelectionDialog.ui ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkDataStorageViewerTestView.h + src/QmitkSingleNodeSelectionWidget.h + src/QmitkNodeSelectionDialog.h ) set(CACHED_RESOURCE_FILES resources/DataStorageViewer_48.png + resources/icon_lock.png + resources/icon_unlock.png plugin.xml ) set(QRC_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.datastorageviewertest/resources/icon_lock.png b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_lock.png new file mode 100644 index 0000000000..52dafde959 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_lock.png differ diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_unlock.png b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_unlock.png new file mode 100644 index 0000000000..9c0b53c0fb Binary files /dev/null and b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_unlock.png differ diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/readme_icon.txt b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/readme_icon.txt new file mode 100644 index 0000000000..07e12fdc30 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/readme_icon.txt @@ -0,0 +1,8 @@ +The icons icon_lock.png and icon_unlock.png are based on: + +Crystal Clear action exit.svg Image:Crystal Clear action lock1.png +Crystal Clear icon by Everaldo Coelho and YellowIcon. + +Distriubted over Wikimedia commons under LGPL. + +Thank you very much. diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp new file mode 100644 index 0000000000..23e1630830 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp @@ -0,0 +1,110 @@ +/*=================================================================== + +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 "QmitkNodeSelectionDialog.h" + +#include + +QmitkNodeSelectionDialog::QmitkNodeSelectionDialog(QWidget* parent) : QDialog(parent), m_NodePredicate(nullptr), m_SelectOnlyVisibleNodes(false) +{ + m_Controls.setupUi(this); + AddPanel(new QmitkDataStorageListViewWidget(this),"Test"); +} + +void QmitkNodeSelectionDialog::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + m_DataStorage = dataStorage; + + if (!m_DataStorage.IsExpired()) + { + for (auto panel : m_Panels) + { + panel->SetDataStorage(dataStorage); + } + } + } +}; + +void QmitkNodeSelectionDialog::SetNodePredicate(mitk::NodePredicateBase* nodePredicate) +{ + if (m_NodePredicate != nodePredicate) + { + m_NodePredicate = nodePredicate; + + for (auto panel : m_Panels) + { + panel->SetNodePredicate(m_NodePredicate); + } + } +}; + +mitk::NodePredicateBase* QmitkNodeSelectionDialog::GetNodePredicate() const +{ + return m_NodePredicate; +} + +QmitkNodeSelectionDialog::NodeList QmitkNodeSelectionDialog::GetSelectedNodes() const +{ + return m_SelectedNodes; +}; + +void QmitkNodeSelectionDialog::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) +{ + if (m_SelectOnlyVisibleNodes != selectOnlyVisibleNodes) + { + m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; + + for (auto panel : m_Panels) + { + panel->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); + } + } +}; + +void QmitkNodeSelectionDialog::SetCurrentSelection(NodeList selectedNodes) +{ + for (auto panel : m_Panels) + { + panel->SetCurrentSelection(selectedNodes); + } +}; + +void QmitkNodeSelectionDialog::OnSelectionChanged(NodeList selectedNodes) +{ + SetCurrentSelection(selectedNodes); + emit CurrentSelectionChanged(selectedNodes); +}; + +void QmitkNodeSelectionDialog::AddPanel(QmitkAbstractDataStorageViewWidget* view, QString name) +{ + view->setParent(this); + + auto tabPanel = new QWidget(); + tabPanel->setObjectName(QString("tab_")+name); + m_Controls.tabWidget->addTab(tabPanel, name); + + auto verticalLayout = new QVBoxLayout(tabPanel); + verticalLayout->setSpacing(0); + verticalLayout->setContentsMargins(0, 0, 0, 0); + verticalLayout->addWidget(view); + + m_Panels.push_back(view); + connect(view, &QmitkAbstractDataStorageViewWidget::CurrentSelectionChanged, this, &QmitkNodeSelectionDialog::OnSelectionChanged); +}; + diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h new file mode 100644 index 0000000000..6f3addc784 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h @@ -0,0 +1,119 @@ +/*=================================================================== + +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 QMITK_NODE_SELECTION_DIALOG_H +#define QMITK_NODE_SELECTION_DIALOG_H + + +#include +#include +#include + +#include + +#include "org_mitk_gui_qt_datastorageviewertest_Export.h" + +#include "ui_QmitkNodeSelectionDialog.h" + +#include + +/** +* \class QmitkNodeSelectionDialog +* \brief Widget that allows to show and edit the content of an mitk::IsoDoseLevel instance. +*/ +class DATASTORAGEVIEWERTEST_EXPORT QmitkNodeSelectionDialog : public QDialog +{ + Q_OBJECT + +public: + explicit QmitkNodeSelectionDialog(QWidget* parent = nullptr); + + /* + * @brief Sets the data storage that will be used /monitored by widget. + * + * @par dataStorage A pointer to the data storage to set. + */ + void SetDataStorage(mitk::DataStorage* dataStorage); + + /* + * @brief Sets the node predicate and updates the widget, according to the node predicate. + * + * @par nodePredicate A pointer to node predicate. + */ + virtual void SetNodePredicate(mitk::NodePredicateBase* nodePredicate); + + mitk::NodePredicateBase* GetNodePredicate() const; + + using NodeList = QList; + + NodeList GetSelectedNodes() const; + + bool GetSelectOnlyVisibleNodes() const; + +Q_SIGNALS: + /* + * @brief A signal that will be emitted if the selected node has changed. + * + * @par nodes A list of data nodes that are newly selected. + */ + void CurrentSelectionChanged(NodeList nodes); + + public Q_SLOTS: + /* + * @brief Change the selection modus of the item view's selection model. + * + * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view. + * An outgoing selection can then at most contain the filtered nodes. + * If false, the incoming non-visible selection will be stored and later added to the outgoing selection, + * to include the original selection that could not be modified. + * The part of the original selection, that is non-visible are the nodes that are not + * + * @par selectOnlyVisibleNodes The bool value to define the selection modus. + */ + void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes); + + /* + * @brief Transform a list of data nodes into a model selection and set this as a new selection of the + * selection model of the private member item view. + * + * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If + * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case + * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable + * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection + * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes'). + * + * @par nodes A list of data nodes that should be newly selected. + */ + void SetCurrentSelection(NodeList selectedNodes); + +protected Q_SLOTS: + void OnSelectionChanged(NodeList selectedNodes); + +protected: + void AddPanel(QmitkAbstractDataStorageViewWidget*, QString name); + + mitk::WeakPointer m_DataStorage; + mitk::NodePredicateBase::Pointer m_NodePredicate; + bool m_SelectOnlyVisibleNodes; + NodeList m_SelectedNodes; + + using PanelVectorType = std::vector; + PanelVectorType m_Panels; + + Ui_QmitkNodeSelectionDialog m_Controls; +}; +#endif // QmitkNodeSelectionDialog_H diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.ui b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.ui new file mode 100644 index 0000000000..e9158dc959 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.ui @@ -0,0 +1,66 @@ + + + QmitkNodeSelectionDialog + + + + 0 + 0 + 589 + 790 + + + + Dialog + + + true + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Favorites + + + + + History + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.cpp new file mode 100644 index 0000000000..8e8b0ef04f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.cpp @@ -0,0 +1,164 @@ +/*=================================================================== + +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 "QmitkSingleNodeSelectionWidget.h" + +#include + +QmitkSingleNodeSelectionWidget::QmitkSingleNodeSelectionWidget(QWidget* parent) : QWidget(parent), m_InvalidInfo("Error. Select data."), m_IsOptional(false), m_SelectOnlyVisibleNodes(false) +{ + m_Controls.setupUi(this); + + m_Controls.btnLock->setChecked(false); + m_Controls.nodeInfo->setHtml(m_InvalidInfo); + + connect(m_Controls.btnLock, &QPushButton::clicked, this, &QmitkSingleNodeSelectionWidget::OnLock); +} + +void QmitkSingleNodeSelectionWidget::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + m_DataStorage = dataStorage; + } +}; + +void QmitkSingleNodeSelectionWidget::SetNodePredicate(mitk::NodePredicateBase* nodePredicate) +{ + if (m_NodePredicate != nodePredicate) + { + m_NodePredicate = nodePredicate; + } +}; + +mitk::NodePredicateBase* QmitkSingleNodeSelectionWidget::GetNodePredicate() const +{ + return m_NodePredicate; +} + +mitk::DataNode::Pointer QmitkSingleNodeSelectionWidget::GetSelectedNode() const +{ + return m_SelectedNode; +}; + +QString QmitkSingleNodeSelectionWidget::GetInvalidInfo() const +{ + return m_InvalidInfo; +}; + +bool QmitkSingleNodeSelectionWidget::GetSelectionIsOptional() const +{ + return m_IsOptional; +}; + +void QmitkSingleNodeSelectionWidget::OnLock(bool locked) +{ +}; + +bool QmitkSingleNodeSelectionWidget::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == m_Controls.nodeInfo) + { + if (ev->type() == QEvent::MouseButtonRelease) + { + this->EditSelection(); + } + + return true; + } + + return false; +} + +void QmitkSingleNodeSelectionWidget::EditSelection() +{ + QmitkNodeSelectionDialog* dialog = new QmitkNodeSelectionDialog(this); + + dialog->SetDataStorage(m_DataStorage.Lock()); + dialog->SetNodePredicate(m_NodePredicate); + NodeList list; + list.append(m_SelectedNode); + dialog->SetCurrentSelection(list); + dialog->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); + + if (dialog->exec()) + { + auto nodes = dialog->GetSelectedNodes(); + if (nodes.empty()) + { + m_SelectedNode = nullptr; + } + else + { + m_SelectedNode = nodes.first(); + } + + this->UpdateInfo(); + emit CurrentSelectionChanged(nodes); + } +}; + +void QmitkSingleNodeSelectionWidget::UpdateInfo() +{ + +}; + +void QmitkSingleNodeSelectionWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) +{ + m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; +}; + +void QmitkSingleNodeSelectionWidget::SetCurrentSelection(NodeList selectedNodes) +{ + if (!m_Controls.btnLock->isChecked()) + { + if (!selectedNodes.empty() && m_SelectedNode != selectedNodes.first()) + { + m_SelectedNode = selectedNodes.first(); + NodeList list; + list.append(m_SelectedNode); + emit CurrentSelectionChanged(list); + } + else if(selectedNodes.empty() && m_SelectedNode != nullptr) + { + m_SelectedNode = nullptr; + NodeList list; + emit CurrentSelectionChanged(list); + } + this->UpdateInfo(); + } +}; + +void QmitkSingleNodeSelectionWidget::SetSelectionLock(bool locked) +{ + m_Controls.btnLock->setChecked(locked); +}; + +void QmitkSingleNodeSelectionWidget::SetSelectionUnlock(bool unlocked) +{ + m_Controls.btnLock->setChecked(!unlocked); +}; + +void QmitkSingleNodeSelectionWidget::SetInvalidInfo(QString info) +{ + m_InvalidInfo = info; +}; + +void QmitkSingleNodeSelectionWidget::SetSelectionIsOptional(bool isOptional) +{ + m_IsOptional = isOptional; +}; diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h new file mode 100644 index 0000000000..06c08e00c7 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h @@ -0,0 +1,155 @@ +/*=================================================================== + +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 QMITK_SINGLE_NODE_SELECTION_WIDGET_H +#define QMITK_SINGLE_NODE_SELECTION_WIDGET_H + +#include + +#include +#include +#include + +#include "org_mitk_gui_qt_datastorageviewertest_Export.h" + +#include "ui_QmitkSingleNodeSelectionWidget.h" + +#include + +class QmitkAbstractDataStorageModel; +class QAbstractItemVew; + +/** +* \class QmitkSingleNodeSelectionWidget +* \brief Widget that allows to show and edit the content of an mitk::IsoDoseLevel instance. +*/ +class DATASTORAGEVIEWERTEST_EXPORT QmitkSingleNodeSelectionWidget : public QWidget +{ + Q_OBJECT + +public: + explicit QmitkSingleNodeSelectionWidget(QWidget* parent = nullptr); + + /* + * @brief Sets the data storage that will be used /monitored by widget. + * + * @par dataStorage A pointer to the data storage to set. + */ + void SetDataStorage(mitk::DataStorage* dataStorage); + + /* + * @brief Sets the node predicate and updates the widget, according to the node predicate. + * + * @par nodePredicate A pointer to node predicate. + */ + void SetNodePredicate(mitk::NodePredicateBase* nodePredicate); + + mitk::NodePredicateBase* GetNodePredicate() const; + + mitk::DataNode::Pointer GetSelectedNode() const; + + QString GetInvalidInfo() const; + + bool GetSelectionIsOptional() const; + + bool GetSelectOnlyVisibleNodes() const; + + using NodeList = QList; + +Q_SIGNALS: + /* + * @brief A signal that will be emitted if the selected node has changed. + * + * @par nodes A list of data nodes that are newly selected. + */ + void CurrentSelectionChanged(QList nodes); + + bool SelectionLock(bool lock); + + bool SelectionUnlock(bool unlock); + + void InvalidInfo(QString info); + + /** Set the widget into an optional mode. Optional means that the selection of no valid + node does not mean an invalid state. Thus no node is a valid "node" selection too.*/ + void SelectionIsOptional(bool isOptional); + + public Q_SLOTS: + /* + * @brief Change the selection modus of the item view's selection model. + * + * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view. + * An outgoing selection can then at most contain the filtered nodes. + * If false, the incoming non-visible selection will be stored and later added to the outgoing selection, + * to include the original selection that could not be modified. + * The part of the original selection, that is non-visible are the nodes that are not + * + * @par selectOnlyVisibleNodes The bool value to define the selection modus. + */ + void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes); + + /* + * @brief Transform a list of data nodes into a model selection and set this as a new selection of the + * selection model of the private member item view. + * + * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If + * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case + * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable + * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection + * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes'). + * + * @par nodes A list of data nodes that should be newly selected. + */ + void SetCurrentSelection(NodeList selectedNodes); + + /** Slot can be used to lock the selection. If the selection is locked + SetCurrentSelection will be ignored and the selection stays untouched.*/ + void SetSelectionLock(bool locked); + /** Slot can be used to unlock the selection. If the selection is locked + SetCurrentSelection will be ignored and the selection stays untouched.*/ + void SetSelectionUnlock(bool unlocked); + + /** Set the info text that should be displayed if no valid node is selected, + * but a selection is mandatory. + * The string can contain HTML code. if wanted*/ + void SetInvalidInfo(QString info); + + /** Set the widget into an optional mode. Optional means that the selection of no valid + node does not mean an invalid state. Thus no node is a valid "node" selection too.*/ + void SetSelectionIsOptional(bool isOptional); + +protected Q_SLOTS: + void OnLock(bool locked); + +protected: + + bool eventFilter(QObject *obj, QEvent *ev) override; + void EditSelection(); + void UpdateInfo(); + + mitk::WeakPointer m_DataStorage; + mitk::NodePredicateBase::Pointer m_NodePredicate; + + mitk::DataNode::Pointer m_SelectedNode; + + QString m_InvalidInfo; + bool m_IsOptional; + bool m_SelectOnlyVisibleNodes; + + Ui_QmitkSingleNodeSelectionWidget m_Controls; +}; +#endif // QmitkSingleNodeSelectionWidget_H diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.ui b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.ui new file mode 100644 index 0000000000..3389b4b90d --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.ui @@ -0,0 +1,110 @@ + + + QmitkSingleNodeSelectionWidget + + + + 0 + 0 + 391 + 40 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 16777215 + 70 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">NodeName</span></p></body></html> + + + + + + + + 0 + 0 + + + + + 40 + 40 + + + + Color of the iso dose level + + + + + + + ../resources/icon_unlock.png + ../resources/icon_lock.png../resources/icon_unlock.png + + + + 34 + 34 + + + + true + + + false + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui index 53f33becde..04d4c4ad16 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui @@ -1,48 +1,79 @@ QmitkDataStorageViewerTestControls 0 0 - 386 + 451 572 0 0 Data storage viewer test + + + + Set as selection provider + + + + + + + Set as selection provider + + + - - + + - Set as selection provider + Set as selection listner - - + + + + + 0 + 40 + + + + + + Set as selection provider - + + + QmitkSingleNodeSelectionWidget + QWidget +
QmitkSingleNodeSelectionWidget.h
+ 1 +
+