Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryQtSelectionProvider.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
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 
17 #include "berryLog.h"
18 
20 
21 #include "berryQtItemSelection.h"
22 #include "berryQModelIndexObject.h"
23 
24 namespace berry {
25 
26 QtSelectionProvider::QtSelectionProvider() : qSelectionModel(nullptr)
27 {
28 
29 }
30 
32 {
34 }
35 
37 {
39 }
40 
42 {
43  if (qSelectionModel)
44  {
45  ISelection::Pointer qsel(new QtItemSelection(qSelectionModel->selection()));
46  return qsel;
47  }
48 
49  return ISelection::ConstPointer(nullptr);
50 }
51 
53 {
54  this->SetSelection(selection, QItemSelectionModel::ClearAndSelect);
55 }
56 
58  QItemSelectionModel::SelectionFlags flags)
59 {
60  if (!qSelectionModel) return;
61 
62  if (QtItemSelection::ConstPointer qsel = selection.Cast<const QtItemSelection>())
63  {
64  qSelectionModel->select(qsel->GetQItemSelection(), flags);
65  }
66 }
67 
69 {
70  if (qSelectionModel)
71  return qSelectionModel->selection();
72 
73  return QItemSelection();
74 }
75 
76 void QtSelectionProvider::SetQItemSelection(const QItemSelection& selection)
77 {
78  if (qSelectionModel)
79  qSelectionModel->select(selection, QItemSelectionModel::Select);
80 }
81 
82 QItemSelectionModel* QtSelectionProvider::GetItemSelectionModel() const
83 {
84  return qSelectionModel;
85 }
86 
87 void QtSelectionProvider::SetItemSelectionModel(QItemSelectionModel* selModel)
88 {
89  if (qSelectionModel)
90  {
91  qSelectionModel->disconnect(this);
92  }
93 
94  qSelectionModel = selModel;
95 
96  if (qSelectionModel)
97  {
98  this->connect(qSelectionModel, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(FireSelectionChanged(const QItemSelection&, const QItemSelection&)));
99  }
100 }
101 
102 void QtSelectionProvider::FireSelectionChanged(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
103 {
107 }
108 
109 }
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:89
QItemSelectionModel * qSelectionModel
QItemSelection GetQItemSelection() const
ISelection::ConstPointer GetSelection() const override
void AddSelectionChangedListener(ISelectionChangedListener *listener) override
void SetItemSelectionModel(QItemSelectionModel *combo)
void RemoveListener(ISelectionChangedListener *listener)
ISelectionChangedListener::Events selectionEvents
void SetSelection(const ISelection::ConstPointer &selection) override
void SetQItemSelection(const QItemSelection &selection)
virtual void FireSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
QItemSelectionModel * GetItemSelectionModel() const
void AddListener(ISelectionChangedListener *listener)
SmartPointer< Other > Cast() const
void RemoveSelectionChangedListener(ISelectionChangedListener *listener) override
Message1< const SelectionChangedEvent::Pointer & > selectionChanged