Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDataNodeSelectionProvider.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "QmitkCustomVariants.h"
20 #include "QmitkEnums.h"
21 
22 #include "internal/QmitkDataNodeSelection.h"
23 
25  : berry::QtSelectionProvider()
26 {
27 
28 }
29 
31 {
32  return this->GetDataNodeSelection();
33 }
34 
36  QItemSelectionModel::SelectionFlags flags)
37 {
38  if (!qSelectionModel) return;
39 
40  mitk::DataNodeSelection::ConstPointer dataNodeSelection = selection.Cast<const mitk::DataNodeSelection>();
41  if (dataNodeSelection)
42  {
43  const QAbstractItemModel* model = qSelectionModel->model();
44 
45  QItemSelection newSelection;
46  const std::list<mitk::DataNode::Pointer> selectedNodes = dataNodeSelection->GetSelectedDataNodes();
47  for (auto i = selectedNodes.begin();
48  i != selectedNodes.end(); ++i)
49  {
50  QModelIndexList matched = model->match(model->index(0, 0), QmitkDataNodeRawPointerRole,
51  QVariant::fromValue<mitk::DataNode*>(i->GetPointer()), 1, Qt::MatchRecursive);
52  if (!matched.empty())
53  {
54  newSelection.select(matched.front(), matched.front());
55  }
56  }
57  qSelectionModel->select(newSelection, flags);
58  }
59  else
60  {
61  QtSelectionProvider::SetSelection(selection, flags);
62  }
63 }
64 
67 {
68  if (qSelectionModel)
69  {
70  mitk::DataNodeSelection::ConstPointer sel(new QmitkDataNodeSelection(
71  qSelectionModel->selection()));
72  return sel;
73  }
74 
76 }
77 
79  const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
80 {
85 }
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:89
QItemSelectionModel * qSelectionModel
berry::ISelection::ConstPointer GetSelection() const override
ISelectionChangedListener::Events selectionEvents
mitk::DataNodeSelection::ConstPointer GetDataNodeSelection() const
virtual void FireSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
void SetSelection(berry::ISelection::ConstPointer selection, QItemSelectionModel::SelectionFlags flags)
SmartPointer< Other > Cast() const
Message1< const SelectionChangedEvent::Pointer & > selectionChanged