diff --git a/Plugins/org.blueberry.ui.qt/src/berryQtSelectionProvider.h b/Plugins/org.blueberry.ui.qt/src/berryQtSelectionProvider.h index 263bab14ea..436df2d6f9 100644 --- a/Plugins/org.blueberry.ui.qt/src/berryQtSelectionProvider.h +++ b/Plugins/org.blueberry.ui.qt/src/berryQtSelectionProvider.h @@ -1,70 +1,70 @@ /*=================================================================== BlueBerry Platform 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 BERRYQTSELECTIONPROVIDER_H_ #define BERRYQTSELECTIONPROVIDER_H_ #include #include #include #include #include namespace berry { class BERRY_UI_QT QtSelectionProvider: public QObject, public ISelectionProvider { Q_OBJECT public: berryObjectMacro(QtSelectionProvider); QtSelectionProvider(); void AddSelectionChangedListener(ISelectionChangedListener* listener) override; void RemoveSelectionChangedListener(ISelectionChangedListener* listener) override; ISelection::ConstPointer GetSelection() const override; - void SetSelection(const ISelection::ConstPointer& selection) override; + virtual void SetSelection(const ISelection::ConstPointer& selection) override; virtual void SetSelection(const ISelection::ConstPointer& selection, QItemSelectionModel::SelectionFlags); QItemSelection GetQItemSelection() const; void SetQItemSelection(const QItemSelection& selection); QItemSelectionModel* GetItemSelectionModel() const; void SetItemSelectionModel(QItemSelectionModel* combo); protected: ISelectionChangedListener::Events selectionEvents; QItemSelectionModel* qSelectionModel; protected slots: virtual void FireSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); }; } #endif /* BERRYQTSELECTIONPROVIDER_H_ */ diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.cpp b/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.cpp index d94561685a..2d953ff82d 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.cpp @@ -1,85 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkDataNodeSelectionProvider.h" #include "QmitkCustomVariants.h" #include "QmitkEnums.h" #include "internal/QmitkDataNodeSelection.h" QmitkDataNodeSelectionProvider::QmitkDataNodeSelectionProvider() : berry::QtSelectionProvider() { } berry::ISelection::ConstPointer QmitkDataNodeSelectionProvider::GetSelection() const { return this->GetDataNodeSelection(); } -void QmitkDataNodeSelectionProvider::SetSelection(berry::ISelection::ConstPointer selection, +void QmitkDataNodeSelectionProvider::SetSelection(const berry::ISelection::ConstPointer& selection, QItemSelectionModel::SelectionFlags flags) { if (!qSelectionModel) return; mitk::DataNodeSelection::ConstPointer dataNodeSelection = selection.Cast(); if (dataNodeSelection) { const QAbstractItemModel* model = qSelectionModel->model(); QItemSelection newSelection; const std::list selectedNodes = dataNodeSelection->GetSelectedDataNodes(); for (auto i = selectedNodes.begin(); i != selectedNodes.end(); ++i) { QModelIndexList matched = model->match(model->index(0, 0), QmitkDataNodeRawPointerRole, QVariant::fromValue(i->GetPointer()), 1, Qt::MatchRecursive); if (!matched.empty()) { newSelection.select(matched.front(), matched.front()); } } qSelectionModel->select(newSelection, flags); } else { QtSelectionProvider::SetSelection(selection, flags); } } mitk::DataNodeSelection::ConstPointer QmitkDataNodeSelectionProvider::GetDataNodeSelection() const { if (qSelectionModel) { mitk::DataNodeSelection::ConstPointer sel(new QmitkDataNodeSelection( qSelectionModel->selection())); return sel; } return mitk::DataNodeSelection::ConstPointer(nullptr); } void QmitkDataNodeSelectionProvider::FireSelectionChanged( const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) { berry::ISelection::ConstPointer sel(this->GetDataNodeSelection()); berry::SelectionChangedEvent::Pointer event(new berry::SelectionChangedEvent( berry::ISelectionProvider::Pointer(this), sel)); selectionEvents.selectionChanged(event); } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.h b/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.h index 032253961d..ea1d07b379 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.h +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkDataNodeSelectionProvider.h @@ -1,61 +1,61 @@ /*=================================================================== 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 QMITKDATATREENODESELECTIONPROVIDER_H_ #define QMITKDATATREENODESELECTIONPROVIDER_H_ #include #include #include /** * \ingroup org_mitk_gui_qt_common * * \brief A BlueBerry selection provider for mitk::DataNode selections. * * This class works together with a Qt item selection model which holds the actual * selection. The underlying Qt model must support the data role \e QmitkDataNodeRole * and return a mitk::DataNode::Pointer object for each QModelIndex in the selection. * * You can set a Qt item selection model using QtSelectionProvider::SetItemSelectionModel(). */ class MITK_QT_COMMON QmitkDataNodeSelectionProvider : public berry::QtSelectionProvider { public: berryObjectMacro(QmitkDataNodeSelectionProvider); QmitkDataNodeSelectionProvider(); /** * This method will always return a mitk::DataNodeSelection object. */ berry::ISelection::ConstPointer GetSelection() const override; using QtSelectionProvider::SetSelection; - void SetSelection(berry::ISelection::ConstPointer selection, QItemSelectionModel::SelectionFlags flags); + virtual void SetSelection(const berry::ISelection::ConstPointer& selection, QItemSelectionModel::SelectionFlags flags) override; protected: mitk::DataNodeSelection::ConstPointer GetDataNodeSelection() const; virtual void FireSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override; }; #endif /* QMITKDATATREENODESELECTIONPROVIDER_H_ */