MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkUSNavigationCalibrationsDataModel.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
17
18#include <QBrush>
19#include <QColor>
20#include <QIcon>
21#include <QFont>
22
24 : QAbstractTableModel(parent),
25 m_ListenerDeviceChanged(this, &QmitkUSNavigationCalibrationsDataModel::OnDeviceChanged)
26 {
27 }
28
30 {
31 if ( m_CombinedModality.IsNotNull() )
32 {
33 m_CombinedModality->GetUltrasoundDevice()->RemovePropertyChangedListener(m_ListenerDeviceChanged);
34 }
35 }
36
37 void QmitkUSNavigationCalibrationsDataModel::SetCombinedModality(mitk::AbstractUltrasoundTrackerDevice::Pointer combinedModality)
38 {
39 if ( m_CombinedModality.IsNotNull() && m_CombinedModality->GetUltrasoundDevice().IsNotNull() )
40 {
41 m_CombinedModality->GetUltrasoundDevice()->RemovePropertyChangedListener(m_ListenerDeviceChanged);
42 }
43
44 m_CombinedModality = combinedModality;
45 if ( m_CombinedModality.IsNotNull() )
46 {
47 m_ControlInterfaceBMode = m_CombinedModality->GetControlInterfaceBMode();
48
49 // make sure that the combined modality is active as this may be
50 // necessary to get the available depths
51 if ( m_CombinedModality->GetUltrasoundDevice()->GetDeviceState() < mitk::USDevice::State_Connected ) { m_CombinedModality->GetUltrasoundDevice()->Connect(); }
52 if ( m_CombinedModality->GetUltrasoundDevice()->GetDeviceState() == mitk::USDevice::State_Connected ) { m_CombinedModality->GetUltrasoundDevice()->Activate(); }
53
54 if ( m_CombinedModality->GetUltrasoundDevice().IsNotNull() )
55 {
56 m_CombinedModality->GetUltrasoundDevice()->AddPropertyChangedListener(m_ListenerDeviceChanged);
57 }
58 }
59
60 // as the combined modality was changed, an old table model
61 // would not be valid anymore
62 this->beginResetModel();
63 this->endResetModel();
64 }
65
66 void QmitkUSNavigationCalibrationsDataModel::OnDeviceChanged(const std::string&, const std::string&)
67 {
68 this->beginResetModel();
69 this->endResetModel();
70 }
71
73 int QmitkUSNavigationCalibrationsDataModel::rowCount ( const QModelIndex & ) const
74 {
75 if ( m_ControlInterfaceBMode.IsNull() )
76 {
77 return 1; // only one default depth can be assumed
78 }
79 else
80 {
81 return m_ControlInterfaceBMode->GetScanningDepthValues().size();
82 }
83 }
84
87 {
88 return 3;
89 }
90
92 QVariant QmitkUSNavigationCalibrationsDataModel::headerData ( int section, Qt::Orientation orientation, int role ) const
93 {
94 if ( role != Qt::DisplayRole ) { return QVariant(QVariant::Invalid); }
95
96 if ( orientation == Qt::Horizontal )
97 {
98 switch ( section )
99 {
100 case 0: return QVariant("Depth");
101 case 1: return QVariant("Calibrated");
102 case 2: return QVariant("");
103 }
104 }
105
106 return QVariant(QVariant::Invalid);
107 }
108
110 Qt::ItemFlags QmitkUSNavigationCalibrationsDataModel::flags ( const QModelIndex & ) const
111 {
112 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
113 }
114
116 QVariant QmitkUSNavigationCalibrationsDataModel::data ( const QModelIndex & index, int role ) const
117 {
118 if ( m_CombinedModality.IsNull() ) { return QVariant(QVariant::Invalid); }
119
120 std::vector<double> scanningDepthValues = m_ControlInterfaceBMode.IsNull() ?
121 std::vector<double>(1,0) : m_ControlInterfaceBMode->GetScanningDepthValues();
122
123 // make sure that row and column index fit data borders
124 if (index.row() >= this->rowCount()
125 || index.column() >= this->columnCount())
126 {
127 return QVariant(QVariant::Invalid);
128 }
129
130 double currentDepth = 0;
131 if ( m_ControlInterfaceBMode.IsNotNull() ) { currentDepth = m_ControlInterfaceBMode->GetScanningDepth(); }
132
133 bool isCalibratedForCurrentDepth =
134 m_CombinedModality->GetCalibration(QString::number(scanningDepthValues.at(index.row())).toStdString()).IsNotNull();
135
136 switch (role)
137 {
138 case Qt::BackgroundRole:
139 {
140 if ( isCalibratedForCurrentDepth )
141 {
142 return QVariant(QBrush(QColor(125, 255, 125)));
143 }
144 else
145 {
146 return QVariant(QBrush(QColor(255, 125, 125)));
147 }
148 }
149
150 case Qt::FontRole:
151 {
152 if ( scanningDepthValues.at(index.row()) == currentDepth )
153 {
154 QFont qFont;
155 qFont.setBold(true);
156 return qFont;
157 }
158 else
159 {
160 return QVariant::Invalid;
161 }
162 }
163
164 case Qt::DecorationRole:
165 {
166 if ( index.column() == 2 )
167 {
168 if ( isCalibratedForCurrentDepth )
169 {
170 return QIcon(":/USNavigation/process-stop.png");
171 }
172 }
173 break;
174 }
175
176 case Qt::EditRole:
177 case Qt::DisplayRole:
178 {
179 switch ( index.column() )
180 {
181 case 0:
182 {
183 return QVariant::fromValue<double>(scanningDepthValues.at(index.row()));
184 }
185 case 1:
186 {
187 if ( m_ControlInterfaceBMode.IsNull() )
188 {
189 // use the current zoom level (which is assumed to be the only one),
190 // when no b mode controls are available
191 return QVariant(m_CombinedModality->GetCalibration().IsNotNull());
192 }
193 else
194 {
195 return QVariant(isCalibratedForCurrentDepth);
196 }
197 }
198 case 2:
199 {
200 return QVariant("");
201 }
202 }
203 break;
204 }
205
206 case Qt::ToolTipRole:
207 {
208 if ( index.column() == 2 && isCalibratedForCurrentDepth )
209 {
210 return QVariant(QString("Remove calibration for depth ") + QString::number(scanningDepthValues.at(index.row())) + " on mouse click.");
211 }
212 break;
213 }
214 }
215
216 return QVariant(QVariant::Invalid);
217 }
218
220bool QmitkUSNavigationCalibrationsDataModel::setData ( const QModelIndex & index, const QVariant & value, int )
221{
222 if ( m_CombinedModality.IsNull() || index.column() != 2 || value != false )
223 return false;
224
225 if ( m_ControlInterfaceBMode.IsNull() )
226 {
227 m_CombinedModality->RemoveCalibration();
228 }
229 else
230 {
231 m_CombinedModality->RemoveCalibration(QString::number(m_ControlInterfaceBMode->GetScanningDepthValues().at(index.row())).toStdString());
232 }
233
234 emit dataChanged(this->index(index.row(), 0), this->index(index.row(), 1));
235 return true;
236}
237
241bool QmitkUSNavigationCalibrationsDataModel::removeRows ( int, int, const QModelIndex&, bool )
242{
243 return false;
244}
void OnDeviceChanged(const std::string &, const std::string &)
Qt::ItemFlags flags(const QModelIndex &index) const override
Return selectable and enabled for column 1 (size); selectable, enabled and editable for every other c...
void SetCombinedModality(itk::SmartPointer< mitk::AbstractUltrasoundTrackerDevice > combinedModality)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return number of rows of the model.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Return names for the columns, numbers for the rows and invalid for DisplayRole.
virtual bool removeRows(int row, int count, const QModelIndex &parent, bool removeFromDataStorage)
Remove given rows from the model.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Return number of columns (3) of the model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Return model data of the selected cell.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Set model data for the selected cell.