Medical Imaging Interaction Toolkit  2018.4.99-936b789b
Medical Imaging Interaction Toolkit
berryQtSelectionProvider.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "berryLog.h"
14 
16 
17 #include "berryQtItemSelection.h"
18 #include "berryQModelIndexObject.h"
19 
20 namespace berry {
21 
22 QtSelectionProvider::QtSelectionProvider() : qSelectionModel(nullptr)
23 {
24 
25 }
26 
28 {
30 }
31 
33 {
35 }
36 
38 {
39  if (qSelectionModel)
40  {
41  ISelection::Pointer qsel(new QtItemSelection(qSelectionModel->selection()));
42  return qsel;
43  }
44 
45  return ISelection::ConstPointer(nullptr);
46 }
47 
49 {
50  this->SetSelection(selection, QItemSelectionModel::ClearAndSelect);
51 }
52 
54  QItemSelectionModel::SelectionFlags flags)
55 {
56  if (!qSelectionModel) return;
57 
58  if (QtItemSelection::ConstPointer qsel = selection.Cast<const QtItemSelection>())
59  {
60  qSelectionModel->select(qsel->GetQItemSelection(), flags);
61  }
62 }
63 
65 {
66  if (qSelectionModel)
67  return qSelectionModel->selection();
68 
69  return QItemSelection();
70 }
71 
72 void QtSelectionProvider::SetQItemSelection(const QItemSelection& selection)
73 {
74  if (qSelectionModel)
75  qSelectionModel->select(selection, QItemSelectionModel::Select);
76 }
77 
78 QItemSelectionModel* QtSelectionProvider::GetItemSelectionModel() const
79 {
80  return qSelectionModel;
81 }
82 
83 void QtSelectionProvider::SetItemSelectionModel(QItemSelectionModel* selModel)
84 {
85  if (qSelectionModel)
86  {
87  qSelectionModel->disconnect(this);
88  }
89 
90  qSelectionModel = selModel;
91 
92  if (qSelectionModel)
93  {
94  this->connect(qSelectionModel, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(FireSelectionChanged(const QItemSelection&, const QItemSelection&)));
95  }
96 }
97 
98 void QtSelectionProvider::FireSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
99 {
103 }
104 
105 }
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:83
QItemSelectionModel * qSelectionModel
ISelection::ConstPointer GetSelection() const override
QItemSelection GetQItemSelection() const
void AddSelectionChangedListener(ISelectionChangedListener *listener) override
SmartPointer< Other > Cast() const
void SetItemSelectionModel(QItemSelectionModel *combo)
void RemoveListener(ISelectionChangedListener *listener)
ISelectionChangedListener::Events selectionEvents
QItemSelectionModel * GetItemSelectionModel() const
void SetSelection(const ISelection::ConstPointer &selection) override
void SetQItemSelection(const QItemSelection &selection)
virtual void FireSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void AddListener(ISelectionChangedListener *listener)
void RemoveSelectionChangedListener(ISelectionChangedListener *listener) override
Message1< const SelectionChangedEvent::Pointer & > selectionChanged