diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake b/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake index e2b7b6c54c..26f6530b64 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/files.cmake @@ -1,40 +1,43 @@ set(SRC_CPP_FILES QmitkSingleNodeSelectionWidget.cpp QmitkNodeSelectionDialog.cpp + QmitkAbstractNodeSelectionWidget.cpp + QmitkMultiNodeSelectionWidget.cpp ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkDataStorageViewerTestView.cpp ) set(UI_FILES src/internal/QmitkDataStorageViewerTestControls.ui src/QmitkSingleNodeSelectionWidget.ui + src/QmitkMultiNodeSelectionWidget.ui src/QmitkNodeSelectionDialog.ui ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkDataStorageViewerTestView.h src/QmitkSingleNodeSelectionWidget.h src/QmitkNodeSelectionDialog.h + src/QmitkAbstractNodeSelectionWidget.h + src/QmitkMultiNodeSelectionWidget.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 deleted file mode 100644 index 52dafde959..0000000000 Binary files a/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_lock.png and /dev/null 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 deleted file mode 100644 index 9c0b53c0fb..0000000000 Binary files a/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/icon_unlock.png and /dev/null 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 deleted file mode 100644 index 07e12fdc30..0000000000 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/resources/readme_icon.txt +++ /dev/null @@ -1,8 +0,0 @@ -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/QmitkAbstractNodeSelectionWidget.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkAbstractNodeSelectionWidget.cpp new file mode 100644 index 0000000000..669c0b128f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkAbstractNodeSelectionWidget.cpp @@ -0,0 +1,114 @@ +/*=================================================================== + +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 "QmitkAbstractNodeSelectionWidget.h" + +#include +#include + +QmitkAbstractNodeSelectionWidget::QmitkAbstractNodeSelectionWidget(QWidget* parent) : QWidget(parent), m_InvalidInfo("Error. Select data."), +m_EmptyInfo("Empty. Make a selection."), m_PopUpTitel("Select a data node"), m_PopUpHint(""), +m_IsOptional(false), m_SelectOnlyVisibleNodes(true) +{ +} + +void QmitkAbstractNodeSelectionWidget::SetDataStorage(mitk::DataStorage* dataStorage) +{ + if (m_DataStorage != dataStorage) + { + m_DataStorage = dataStorage; + } +}; + +void QmitkAbstractNodeSelectionWidget::SetNodePredicate(mitk::NodePredicateBase* nodePredicate) +{ + if (m_NodePredicate != nodePredicate) + { + m_NodePredicate = nodePredicate; + + this->OnNodePredicateChanged(nodePredicate); + this->UpdateInfo(); + } +}; + +mitk::NodePredicateBase* QmitkAbstractNodeSelectionWidget::GetNodePredicate() const +{ + return m_NodePredicate; +} + +QString QmitkAbstractNodeSelectionWidget::GetInvalidInfo() const +{ + return m_InvalidInfo; +}; + +QString QmitkAbstractNodeSelectionWidget::GetEmptyInfo() const +{ + return m_EmptyInfo; +}; + +QString QmitkAbstractNodeSelectionWidget::GetPopUpTitel() const +{ + return m_PopUpTitel; +}; + +QString QmitkAbstractNodeSelectionWidget::GetPopUpHint() const +{ + return m_PopUpHint; +}; + +bool QmitkAbstractNodeSelectionWidget::GetSelectionIsOptional() const +{ + return m_IsOptional; +}; + +bool QmitkAbstractNodeSelectionWidget::GetSelectOnlyVisibleNodes() const +{ + return m_SelectOnlyVisibleNodes; +}; + +void QmitkAbstractNodeSelectionWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) +{ + m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; +}; + +void QmitkAbstractNodeSelectionWidget::SetInvalidInfo(QString info) +{ + m_InvalidInfo = info; + this->UpdateInfo(); +}; + +void QmitkAbstractNodeSelectionWidget::SetEmptyInfo(QString info) +{ + m_EmptyInfo = info; + this->UpdateInfo(); +}; + +void QmitkAbstractNodeSelectionWidget::SetPopUpTitel(QString info) +{ + m_PopUpTitel = info; +}; + +void QmitkAbstractNodeSelectionWidget::SetPopUpHint(QString info) +{ + m_PopUpHint = info; +}; + +void QmitkAbstractNodeSelectionWidget::SetSelectionIsOptional(bool isOptional) +{ + m_IsOptional = isOptional; + this->UpdateInfo(); +}; diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkAbstractNodeSelectionWidget.h similarity index 66% copy from Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h copy to Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkAbstractNodeSelectionWidget.h index 06c08e00c7..dc920a7e2f 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkAbstractNodeSelectionWidget.h @@ -1,155 +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 QMITK_SINGLE_NODE_SELECTION_WIDGET_H -#define QMITK_SINGLE_NODE_SELECTION_WIDGET_H +#ifndef QMITK_ABSTRACT_NODE_SELECTION_WIDGET_H +#define QMITK_ABSTRACT_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 QmitkAbstractNodeSelectionWidget +* \brief Abstract base class for the selection of data from a data storage. */ -class DATASTORAGEVIEWERTEST_EXPORT QmitkSingleNodeSelectionWidget : public QWidget +class DATASTORAGEVIEWERTEST_EXPORT QmitkAbstractNodeSelectionWidget : public QWidget { Q_OBJECT public: - explicit QmitkSingleNodeSelectionWidget(QWidget* parent = nullptr); + explicit QmitkAbstractNodeSelectionWidget(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. + /** + * Sets the node predicate and updates the widget, according to the node predicate. + * Implement OnNodePredicateChange() for custom actualization of a derived widget class. * * @par nodePredicate A pointer to node predicate. */ void SetNodePredicate(mitk::NodePredicateBase* nodePredicate); mitk::NodePredicateBase* GetNodePredicate() const; - mitk::DataNode::Pointer GetSelectedNode() const; - QString GetInvalidInfo() const; + QString GetEmptyInfo() const; + QString GetPopUpTitel() const; + QString GetPopUpHint() 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: +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); + virtual 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); + virtual void SetCurrentSelection(NodeList selectedNodes) = 0; - /** 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, + /** 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 info text that should be displayed if no (valid) node is selected, + * but a selection is optional. + * The string can contain HTML code. if wanted*/ + void SetEmptyInfo(QString info); + + /** Set the caption of the popup that is displayed to alter the selection. + * The string can contain HTML code. if wanted*/ + void SetPopUpTitel(QString info); + + /** Set the hint text of the popup that is displayed to alter the selection. + * The string can contain HTML code. if wanted*/ + void SetPopUpHint(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: + /**Member is called if the display of the selected nodes should be updated.*/ + virtual void UpdateInfo() = 0; - bool eventFilter(QObject *obj, QEvent *ev) override; - void EditSelection(); - void UpdateInfo(); + /**Member is called if the predicate has changed. Thus the selection might change to.*/ + virtual void OnNodePredicateChanged(mitk::NodePredicateBase* newPredicate) = 0; mitk::WeakPointer m_DataStorage; mitk::NodePredicateBase::Pointer m_NodePredicate; - mitk::DataNode::Pointer m_SelectedNode; - QString m_InvalidInfo; + QString m_EmptyInfo; + QString m_PopUpTitel; + QString m_PopUpHint; + bool m_IsOptional; bool m_SelectOnlyVisibleNodes; - - Ui_QmitkSingleNodeSelectionWidget m_Controls; }; -#endif // QmitkSingleNodeSelectionWidget_H +#endif // QmitkAbstractNodeSelectionWidget_H diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.cpp new file mode 100644 index 0000000000..3aa47b76f4 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.cpp @@ -0,0 +1,163 @@ +/*=================================================================== + +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 "QmitkMultiNodeSelectionWidget.h" + +#include +#include +#include + +QmitkMultiNodeSelectionWidget::QmitkMultiNodeSelectionWidget(QWidget* parent) : QmitkAbstractNodeSelectionWidget(parent) +{ + m_Controls.setupUi(this); + + this->UpdateList(); + this->UpdateInfo(); + + connect(m_Controls.btnChange, SIGNAL(clicked(bool)), this, SLOT(OnEditSelection())); +} + +QmitkMultiNodeSelectionWidget::NodeList QmitkMultiNodeSelectionWidget::CompileEmitSelection() const +{ + NodeList result; + + for (int i = 0; i < m_Controls.list->count(); ++i) + { + QListWidgetItem* item = m_Controls.list->item(i); + + auto node = item->data(Qt::UserRole).value(); + result.append(node); + } + + + if (!m_SelectOnlyVisibleNodes) + { + for (auto node : m_CurrentSelection) + { + if (!result.contains(node)) + { + result.append(node); + } + } + } + + return result; +} + +void QmitkMultiNodeSelectionWidget::OnNodePredicateChanged(mitk::NodePredicateBase* /*newPredicate*/) +{ + this->UpdateInfo(); + this->UpdateList(); +}; + +QmitkMultiNodeSelectionWidget::NodeList QmitkMultiNodeSelectionWidget::GetSelectedNodes() const +{ + return m_CurrentSelection; +}; + +void QmitkMultiNodeSelectionWidget::OnEditSelection() +{ + QmitkNodeSelectionDialog* dialog = new QmitkNodeSelectionDialog(this, m_PopUpTitel, m_PopUpHint); + + dialog->SetDataStorage(m_DataStorage.Lock()); + dialog->SetNodePredicate(m_NodePredicate); + dialog->SetCurrentSelection(this->CompileEmitSelection()); + dialog->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); + dialog->SetSelectionMode(QAbstractItemView::MultiSelection); + + if (dialog->exec()) + { + auto lastEmission = this->CompileEmitSelection(); + + m_CurrentSelection = dialog->GetSelectedNodes(); + this->UpdateList(); + this->UpdateInfo(); + + auto newEmission = this->CompileEmitSelection(); + + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + } + } +}; + +void QmitkMultiNodeSelectionWidget::UpdateInfo() +{ + m_Controls.infoLabel->setVisible(m_Controls.list->count()==0); + + if (!m_Controls.list->count()) + { + if (m_IsOptional) + { + m_Controls.infoLabel->setText(m_EmptyInfo); + } + else + { + m_Controls.infoLabel->setText(m_InvalidInfo); + } + } +}; + +void QmitkMultiNodeSelectionWidget::UpdateList() +{ + m_Controls.list->clear(); + + for (auto node : m_CurrentSelection) + { + if (m_NodePredicate.IsNull() || m_NodePredicate->CheckNode(node)) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(QString::fromStdString(node->GetName())); + newItem->setData(Qt::UserRole, QVariant::fromValue(node)); + + m_Controls.list->addItem(newItem); + } + } +}; + +void QmitkMultiNodeSelectionWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) +{ + auto lastEmission = this->CompileEmitSelection(); + + m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; + + auto newEmission = this->CompileEmitSelection(); + + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + this->UpdateList(); + this->UpdateInfo(); + } +}; + +void QmitkMultiNodeSelectionWidget::SetCurrentSelection(NodeList selectedNodes) +{ + auto lastEmission = this->CompileEmitSelection(); + + m_CurrentSelection = selectedNodes; + this->UpdateList(); + + auto newEmission = this->CompileEmitSelection(); + + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + this->UpdateInfo(); + } +}; diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.h new file mode 100644 index 0000000000..8769378011 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.h @@ -0,0 +1,76 @@ +/*=================================================================== + +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_MULTI_NODE_SELECTION_WIDGET_H +#define QMITK_MULTI_NODE_SELECTION_WIDGET_H + +#include + +#include +#include +#include + +#include "org_mitk_gui_qt_datastorageviewertest_Export.h" + +#include "ui_QmitkMultiNodeSelectionWidget.h" + +#include + +class QmitkAbstractDataStorageModel; +class QAbstractItemVew; + +/** +* \class QmitkMultiNodeSelectionWidget +* \brief Widget that allows to show and edit the content of an mitk::IsoDoseLevel instance. +*/ +class DATASTORAGEVIEWERTEST_EXPORT QmitkMultiNodeSelectionWidget : public QmitkAbstractNodeSelectionWidget +{ + Q_OBJECT + +public: + explicit QmitkMultiNodeSelectionWidget(QWidget* parent = nullptr); + + using NodeList = QmitkAbstractNodeSelectionWidget::NodeList; + + NodeList GetSelectedNodes() 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(QList nodes); + + public Q_SLOTS: + virtual void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) override; + virtual void SetCurrentSelection(NodeList selectedNodes) override; + void OnEditSelection(); + +protected: + NodeList CompileEmitSelection() const; + + virtual void UpdateInfo() override; + virtual void UpdateList(); + + virtual void OnNodePredicateChanged(mitk::NodePredicateBase* newPredicate); + + NodeList m_CurrentSelection; + + Ui_QmitkMultiNodeSelectionWidget m_Controls; +}; +#endif // QmitkMultiNodeSelectionWidget_H diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.ui b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.ui new file mode 100644 index 0000000000..21aaad184c --- /dev/null +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkMultiNodeSelectionWidget.ui @@ -0,0 +1,66 @@ + + + QmitkMultiNodeSelectionWidget + + + + 0 + 0 + 391 + 265 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + + + + TextLabel + + + true + + + + + + + Change selection + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp index 23e1630830..d963a72005 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.cpp @@ -1,110 +1,144 @@ /*=================================================================== 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) +QmitkNodeSelectionDialog::QmitkNodeSelectionDialog(QWidget* parent, QString title, QString hint) : QDialog(parent), m_NodePredicate(nullptr), m_SelectOnlyVisibleNodes(false) { m_Controls.setupUi(this); AddPanel(new QmitkDataStorageListViewWidget(this),"Test"); + m_Controls.tabWidget->setCurrentIndex(0); + this->setWindowTitle(title); + this->setToolTip(hint); + + m_Controls.hint->setText(hint); + m_Controls.hint->setVisible(!hint.isEmpty()); + + connect(m_Controls.buttonBox, SIGNAL(accepted()), this, SLOT(OnOK())); + connect(m_Controls.buttonBox, SIGNAL(rejected()), this, SLOT(OnCancel())); } 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) { + m_SelectedNodes = 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); + view->SetSelectionMode(m_SelectionMode); auto tabPanel = new QWidget(); tabPanel->setObjectName(QString("tab_")+name); - m_Controls.tabWidget->addTab(tabPanel, name); + m_Controls.tabWidget->insertTab(0, 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); }; +void QmitkNodeSelectionDialog::OnOK() +{ + this->accept(); +}; + +void QmitkNodeSelectionDialog::OnCancel() +{ + this->reject(); +}; + +void QmitkNodeSelectionDialog::SetSelectionMode(SelectionMode mode) +{ + m_SelectionMode = mode; + for (auto panel : m_Panels) + { + panel->SetSelectionMode(mode); + } +}; + +QmitkNodeSelectionDialog::SelectionMode QmitkNodeSelectionDialog::GetSelectionMode() const +{ + return m_SelectionMode; +} diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h index 6f3addc784..efea9b59a2 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.h @@ -1,119 +1,127 @@ /*=================================================================== 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); + explicit QmitkNodeSelectionDialog(QWidget* parent = nullptr, QString caption = "", QString hint = ""); /* * @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; + using SelectionMode = QAbstractItemView::SelectionMode; + void SetSelectionMode(SelectionMode mode); + SelectionMode GetSelectionMode() 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); + void OnOK(); + void OnCancel(); protected: void AddPanel(QmitkAbstractDataStorageViewWidget*, QString name); mitk::WeakPointer m_DataStorage; mitk::NodePredicateBase::Pointer m_NodePredicate; bool m_SelectOnlyVisibleNodes; NodeList m_SelectedNodes; + SelectionMode m_SelectionMode; + 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 index e9158dc959..5751b36277 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.ui +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkNodeSelectionDialog.ui @@ -1,66 +1,76 @@ QmitkNodeSelectionDialog 0 0 589 790 Dialog true true - 0 + 5 0 0 0 0 + + + + + + + true + + + 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 index 8f6e0c0883..c43c6f3906 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.cpp +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.cpp @@ -1,190 +1,184 @@ /*=================================================================== 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 +#include -QmitkSingleNodeSelectionWidget::QmitkSingleNodeSelectionWidget(QWidget* parent) : QWidget(parent), m_InvalidInfo("Error. Select data."), m_IsOptional(false), m_SelectOnlyVisibleNodes(false) +QmitkSingleNodeSelectionWidget::QmitkSingleNodeSelectionWidget(QWidget* parent) : QmitkAbstractNodeSelectionWidget(parent) { m_Controls.setupUi(this); - m_Controls.btnLock->setChecked(false); this->UpdateInfo(); m_Controls.nodeInfo->installEventFilter(this); - - connect(m_Controls.btnLock, &QPushButton::clicked, this, &QmitkSingleNodeSelectionWidget::OnLock); + m_Controls.nodeInfo->setVisible(true); } -void QmitkSingleNodeSelectionWidget::SetDataStorage(mitk::DataStorage* dataStorage) +mitk::DataNode::Pointer QmitkSingleNodeSelectionWidget::ExtractCurrentValidSelection(const NodeList& nodes) const { - if (m_DataStorage != dataStorage) - { - m_DataStorage = dataStorage; - } -}; + mitk::DataNode::Pointer result = nullptr; -void QmitkSingleNodeSelectionWidget::SetNodePredicate(mitk::NodePredicateBase* nodePredicate) -{ - if (m_NodePredicate != nodePredicate) + for (auto node : nodes) { - m_NodePredicate = nodePredicate; + bool valid = true; + if (m_NodePredicate.IsNotNull()) + { + valid = m_NodePredicate->CheckNode(node); + } + if (valid) + { + result = node; + break; + } } -}; -mitk::NodePredicateBase* QmitkSingleNodeSelectionWidget::GetNodePredicate() const -{ - return m_NodePredicate; + return result; } -mitk::DataNode::Pointer QmitkSingleNodeSelectionWidget::GetSelectedNode() const +QmitkSingleNodeSelectionWidget::NodeList QmitkSingleNodeSelectionWidget::CompileEmitSelection() const { - return m_SelectedNode; -}; + NodeList result; -QString QmitkSingleNodeSelectionWidget::GetInvalidInfo() const -{ - return m_InvalidInfo; -}; + if (!m_SelectOnlyVisibleNodes) + { + result = m_ExternalSelection; + } + + if (m_SelectedNode.IsNotNull() && !result.contains(m_SelectedNode)) + { + result.append(m_SelectedNode); + } + + return result; +} -bool QmitkSingleNodeSelectionWidget::GetSelectionIsOptional() const +void QmitkSingleNodeSelectionWidget::OnNodePredicateChanged(mitk::NodePredicateBase* /*newPredicate*/) { - return m_IsOptional; + m_SelectedNode = this->ExtractCurrentValidSelection(m_ExternalSelection); }; -void QmitkSingleNodeSelectionWidget::OnLock(bool locked) +mitk::DataNode::Pointer QmitkSingleNodeSelectionWidget::GetSelectedNode() const { + return m_SelectedNode; }; bool QmitkSingleNodeSelectionWidget::eventFilter(QObject *obj, QEvent *ev) { if (obj == m_Controls.nodeInfo) { if (ev->type() == QEvent::MouseButtonRelease) { this->EditSelection(); + return true; } - - return true; } return false; } void QmitkSingleNodeSelectionWidget::EditSelection() { - QmitkNodeSelectionDialog* dialog = new QmitkNodeSelectionDialog(this); + QmitkNodeSelectionDialog* dialog = new QmitkNodeSelectionDialog(this, m_PopUpTitel, m_PopUpHint); dialog->SetDataStorage(m_DataStorage.Lock()); dialog->SetNodePredicate(m_NodePredicate); NodeList list; - list.append(m_SelectedNode); + if (m_SelectedNode.IsNotNull()) + { + list.append(m_SelectedNode); + } dialog->SetCurrentSelection(list); dialog->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); + dialog->SetSelectionMode(QAbstractItemView::SingleSelection); if (dialog->exec()) { + auto lastEmission = this->CompileEmitSelection(); + auto nodes = dialog->GetSelectedNodes(); if (nodes.empty()) { m_SelectedNode = nullptr; } else { m_SelectedNode = nodes.first(); } - this->UpdateInfo(); - emit CurrentSelectionChanged(nodes); + auto newEmission = this->CompileEmitSelection(); + + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + this->UpdateInfo(); + } } }; void QmitkSingleNodeSelectionWidget::UpdateInfo() { if (m_SelectedNode.IsNull()) { if (m_IsOptional) { - m_Controls.nodeInfo->setText("Empty"); + m_Controls.nodeInfo->setText(m_EmptyInfo); } else { m_Controls.nodeInfo->setText(m_InvalidInfo); } } else { - m_Controls.nodeInfo->setText(QString::fromStdString(m_SelectedNode->GetName())); + auto name = m_SelectedNode->GetName(); + m_Controls.nodeInfo->setText(QString::fromStdString(name)); } }; void QmitkSingleNodeSelectionWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) { - m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; -}; + auto lastEmission = this->CompileEmitSelection(); -void QmitkSingleNodeSelectionWidget::SetCurrentSelection(NodeList selectedNodes) -{ - if (!m_Controls.btnLock->isChecked()) - { - mitk::DataNode::Pointer newSelected = nullptr; - NodeList list; - bool changed = false; - - if (!selectedNodes.empty() && m_SelectedNode != selectedNodes.first()) - { - newSelected = selectedNodes.first(); - list.append(m_SelectedNode); - changed = true; - } - else if(selectedNodes.empty() && m_SelectedNode != nullptr) - { - newSelected = nullptr; - changed = true; - } + m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; - if (changed) - { - emit CurrentSelectionChanged(list); - m_SelectedNode = newSelected; - this->UpdateInfo(); - } + auto newEmission = this->CompileEmitSelection(); + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + this->UpdateInfo(); } }; -void QmitkSingleNodeSelectionWidget::SetSelectionLock(bool locked) +void QmitkSingleNodeSelectionWidget::SetCurrentSelection(NodeList selectedNodes) { - m_Controls.btnLock->setChecked(locked); -}; + auto lastEmission = this->CompileEmitSelection(); -void QmitkSingleNodeSelectionWidget::SetSelectionUnlock(bool unlocked) -{ - m_Controls.btnLock->setChecked(!unlocked); -}; + m_ExternalSelection = selectedNodes; + m_SelectedNode = this->ExtractCurrentValidSelection(selectedNodes); -void QmitkSingleNodeSelectionWidget::SetInvalidInfo(QString info) -{ - m_InvalidInfo = info; -}; + auto newEmission = this->CompileEmitSelection(); -void QmitkSingleNodeSelectionWidget::SetSelectionIsOptional(bool isOptional) -{ - m_IsOptional = isOptional; + if (!EqualNodeSelections(lastEmission, newEmission)) + { + emit CurrentSelectionChanged(newEmission); + this->UpdateInfo(); + } }; diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h index 06c08e00c7..892389b0f3 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.h @@ -1,155 +1,78 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef 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 +#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 +class DATASTORAGEVIEWERTEST_EXPORT QmitkSingleNodeSelectionWidget : public QmitkAbstractNodeSelectionWidget { 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; - + using NodeList = QmitkAbstractNodeSelectionWidget::NodeList; + 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); +public Q_SLOTS: + virtual void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) override; + virtual void SetCurrentSelection(NodeList selectedNodes) override; protected: + mitk::DataNode::Pointer ExtractCurrentValidSelection(const NodeList& nodes) const; + NodeList CompileEmitSelection() const; - bool eventFilter(QObject *obj, QEvent *ev) override; + virtual bool eventFilter(QObject *obj, QEvent *ev) override; void EditSelection(); - void UpdateInfo(); + virtual void UpdateInfo() override; - mitk::WeakPointer m_DataStorage; - mitk::NodePredicateBase::Pointer m_NodePredicate; + virtual void OnNodePredicateChanged(mitk::NodePredicateBase* newPredicate); + NodeList m_ExternalSelection; 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 index 6b2baba12f..72336df586 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.ui +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/QmitkSingleNodeSelectionWidget.ui @@ -1,88 +1,49 @@ QmitkSingleNodeSelectionWidget 0 0 391 40 Form 0 0 0 0 0 QFrame::Box QFrame::Sunken NodeName - - - - - 0 - 0 - - - - - 40 - 40 - - - - - - - - - - - :/org.mitk.gui.qt.datastorageviewertest/resources/icon_unlock.png - :/org.mitk.gui.qt.datastorageviewertest/resources/icon_lock.png:/org.mitk.gui.qt.datastorageviewertest/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 a5845c4230..66866a9712 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestControls.ui @@ -1,118 +1,158 @@ QmitkDataStorageViewerTestControls 0 0 - 493 - 412 + 945 + 728 0 0 Data storage viewer test - - - - - - - - - - Set as selection provider - - - - - - - - - - Set as selection listener - - - - - - - Set as selection listener - - - - - - - Set as selection provider - - - - - - + + + + + + + + + + + Set as selection provider + + + + + + + Set as selection provider + + + + + + + Set as selection listener + + + + + + + Set as selection listener + + + + 0 40 - + + + + Set as selection provider - + Set as selection listner - + - Change Only visible + Only valid nodes - + Allow only images - + Is Optional + + + + Set as selection provider + + + + + + + Set as selection listner + + + + + + + Only valid nodes + + + + + + + Allow only images + + + + + + + Is Optional + + + QmitkSingleNodeSelectionWidget QWidget
QmitkSingleNodeSelectionWidget.h
1
+ + QmitkMultiNodeSelectionWidget + QWidget +
QmitkMultiNodeSelectionWidget.h
+ 1 +
diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp index 4eb5a980b8..dbe3bd1cc8 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp @@ -1,175 +1,247 @@ /*=================================================================== 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. ===================================================================*/ // data storage viewer test plugin #include "QmitkDataStorageViewerTestView.h" +#include "mitkNodePredicateDataType.h" + // berry #include // qt #include const std::string QmitkDataStorageViewerTestView::VIEW_ID = "org.mitk.views.datastorageviewertest"; void QmitkDataStorageViewerTestView::SetFocus() { // nothing here } void QmitkDataStorageViewerTestView::CreateQtPartControl(QWidget* parent) { // create GUI widgets m_Controls.setupUi(parent); m_DataStorageDefaultListModel = new QmitkDataStorageDefaultListModel(this); m_DataStorageDefaultListModel->SetDataStorage(GetDataStorage()); m_Controls.selectionListView->setSelectionMode(QAbstractItemView::ExtendedSelection); m_Controls.selectionListView->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.selectionListView->setAlternatingRowColors(true); m_Controls.selectionListView->setModel(m_DataStorageDefaultListModel); m_DataStorageDefaultListModel2 = new QmitkDataStorageDefaultListModel(this); m_DataStorageDefaultListModel2->SetDataStorage(GetDataStorage()); m_Controls.selectionListView2->setSelectionMode(QAbstractItemView::ExtendedSelection); m_Controls.selectionListView2->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.selectionListView2->setAlternatingRowColors(true); m_Controls.selectionListView2->setModel(m_DataStorageDefaultListModel2); m_Controls.singleSlot->SetDataStorage(GetDataStorage()); + m_Controls.singleSlot->SetEmptyInfo(QString("EmptyInfo: Set this to display info in empty state")); + m_Controls.singleSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states")); + m_Controls.singleSlot->SetPopUpTitel(QString("This is the definable caption. Choose your data now!")); + m_Controls.singleSlot->SetPopUpHint(QString("I am an optional hint, that can be set by the developer

If not set the widget is invisible.")); + m_Controls.multiSlot->SetDataStorage(GetDataStorage()); + m_Controls.multiSlot->SetEmptyInfo(QString("EmptyInfo: Set this to display info in empty state")); + m_Controls.multiSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states")); + m_Controls.multiSlot->SetPopUpTitel(QString("This is the definable caption. Choose your data now!")); + m_Controls.multiSlot->SetPopUpHint(QString("I am an optional hint, that can be set by the developer

If not set the widget is invisible.")); m_ModelViewSelectionConnector = std::make_unique(); try { m_ModelViewSelectionConnector->SetView(m_Controls.selectionListView); } catch (mitk::Exception& e) { mitkReThrow(e) << "Cannot connect the model-view pair signals and slots."; } m_SelectionServiceConnector = std::make_unique(); m_ModelViewSelectionConnector2 = std::make_unique(); try { m_ModelViewSelectionConnector2->SetView(m_Controls.selectionListView2); } catch (mitk::Exception& e) { mitkReThrow(e) << "Cannot connect the model-view pair signals and slots."; } m_SelectionServiceConnector2 = std::make_unique(); m_SelectionServiceConnector3 = std::make_unique(); + m_SelectionServiceConnector4 = std::make_unique(); connect(m_Controls.selectionProviderCheckBox, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider1(bool))); connect(m_Controls.selectionProviderCheckBox2, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider2(bool))); connect(m_Controls.selectionListenerCheckBox, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener1(bool))); connect(m_Controls.selectionListenerCheckBox2, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener2(bool))); connect(m_Controls.selectionProviderCheckBox3, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider3(bool))); connect(m_Controls.selectionListenerCheckBox3, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener3(bool))); connect(m_Controls.checkOnlyVisible, SIGNAL(toggled(bool)), m_Controls.singleSlot, SLOT(SetSelectOnlyVisibleNodes(bool))); connect(m_Controls.checkOptional, SIGNAL(toggled(bool)), m_Controls.singleSlot, SLOT(SetSelectionIsOptional(bool))); + connect(m_Controls.checkOnlyImages, SIGNAL(toggled(bool)), this, SLOT(OnOnlyImages(bool))); + + connect(m_Controls.selectionProviderCheckBox4, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider4(bool))); + connect(m_Controls.selectionListenerCheckBox4, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener4(bool))); + + connect(m_Controls.checkOnlyVisible_2, SIGNAL(toggled(bool)), m_Controls.multiSlot, SLOT(SetSelectOnlyVisibleNodes(bool))); + connect(m_Controls.checkOptional_2, SIGNAL(toggled(bool)), m_Controls.multiSlot, SLOT(SetSelectionIsOptional(bool))); + connect(m_Controls.checkOnlyImages_2, SIGNAL(toggled(bool)), this, SLOT(OnOnlyImages2(bool))); } void QmitkDataStorageViewerTestView::SetAsSelectionProvider1(bool checked) { if (checked) { m_SelectionServiceConnector->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_ModelViewSelectionConnector.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector->RemoveAsSelectionProvider(); disconnect(m_ModelViewSelectionConnector.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener1(bool checked) { if (checked) { m_SelectionServiceConnector->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector.get(), SLOT(SetCurrentSelection(QList))); } else { m_SelectionServiceConnector->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector.get(), SLOT(SetCurrentSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionProvider2(bool checked) { if (checked) { m_SelectionServiceConnector2->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_ModelViewSelectionConnector2.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector2.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector2->RemoveAsSelectionProvider(); disconnect(m_ModelViewSelectionConnector2.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector2.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener2(bool checked) { if (checked) { m_SelectionServiceConnector2->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector2.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector2.get(), SLOT(SetCurrentSelection(QList))); } else { m_SelectionServiceConnector2->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector2.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector2.get(), SLOT(SetCurrentSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionProvider3(bool checked) { if (checked) { m_SelectionServiceConnector3->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); - connect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); + connect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector3.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector3->RemoveAsSelectionProvider(); - disconnect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); + disconnect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector3.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener3(bool checked) { if (checked) { m_SelectionServiceConnector3->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector3.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.singleSlot, &QmitkSingleNodeSelectionWidget::SetCurrentSelection); } else { m_SelectionServiceConnector3->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector3.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.singleSlot, &QmitkSingleNodeSelectionWidget::SetCurrentSelection); } -} \ No newline at end of file +} + +void QmitkDataStorageViewerTestView::SetAsSelectionProvider4(bool checked) +{ + if (checked) + { + m_SelectionServiceConnector4->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); + connect(m_Controls.multiSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector4.get(), SLOT(ChangeServiceSelection(QList))); + } + else + { + m_SelectionServiceConnector4->RemoveAsSelectionProvider(); + disconnect(m_Controls.multiSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector4.get(), SLOT(ChangeServiceSelection(QList))); + } +} + +void QmitkDataStorageViewerTestView::SetAsSelectionListener4(bool checked) +{ + if (checked) + { + m_SelectionServiceConnector4->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); + connect(m_SelectionServiceConnector4.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.multiSlot, &QmitkMultiNodeSelectionWidget::SetCurrentSelection); + } + else + { + m_SelectionServiceConnector4->RemovePostSelectionListener(); + disconnect(m_SelectionServiceConnector4.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.multiSlot, &QmitkMultiNodeSelectionWidget::SetCurrentSelection); + } +} + +void QmitkDataStorageViewerTestView::OnOnlyImages(bool checked) +{ + if (checked) + { + m_Controls.singleSlot->SetNodePredicate(mitk::NodePredicateDataType::New("Image")); + } + else + { + m_Controls.singleSlot->SetNodePredicate(nullptr); + } +}; + +void QmitkDataStorageViewerTestView::OnOnlyImages2(bool checked) +{ + if (checked) + { + m_Controls.multiSlot->SetNodePredicate(mitk::NodePredicateDataType::New("Image")); + } + else + { + m_Controls.multiSlot->SetNodePredicate(nullptr); + } +}; diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.h b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.h index 24ba825f22..ce4042ae3e 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.h +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.h @@ -1,71 +1,77 @@ /*=================================================================== 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 QMITKDATASTORAGEVIEWERTESTVIEW_H #define QMITKDATASTORAGEVIEWERTESTVIEW_H // mitk gui qt common plugin #include #include "QmitkModelViewSelectionConnector.h" #include "QmitkSelectionServiceConnector.h" // data storage viewer test plugin #include "ui_QmitkDataStorageViewerTestControls.h" // qt widgets module #include "QmitkDataStorageDefaultListModel.h" /** * @brief DataStorageViewerTestView */ class QmitkDataStorageViewerTestView : public QmitkAbstractView { Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void SetFocus() override; virtual void CreateQtPartControl(QWidget* parent) override; private Q_SLOTS: void SetAsSelectionProvider1(bool checked); void SetAsSelectionProvider2(bool checked); void SetAsSelectionProvider3(bool checked); + void SetAsSelectionProvider4(bool checked); void SetAsSelectionListener1(bool checked); void SetAsSelectionListener2(bool checked); void SetAsSelectionListener3(bool checked); + void SetAsSelectionListener4(bool checked); + + void OnOnlyImages(bool checked); + void OnOnlyImages2(bool checked); private: Ui::QmitkDataStorageViewerTestControls m_Controls; QmitkDataStorageDefaultListModel* m_DataStorageDefaultListModel; QmitkDataStorageDefaultListModel* m_DataStorageDefaultListModel2; std::unique_ptr m_ModelViewSelectionConnector; std::unique_ptr m_SelectionServiceConnector; std::unique_ptr m_ModelViewSelectionConnector2; std::unique_ptr m_SelectionServiceConnector2; std::unique_ptr m_SelectionServiceConnector3; + std::unique_ptr m_SelectionServiceConnector4; }; #endif // QMITKDATASTORAGEVIEWERTESTVIEW_H