MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkUSZoneManagementWidget.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============================================================================*/
13#include "ui_QmitkUSZoneManagementWidget.h"
14
17
19#include "usModuleRegistry.h"
20#include "usModule.h"
21//#include "mitkGlobalInteraction.h"
22#include "mitkSurface.h"
23
24#include <QLatin1Char>
25
27QWidget(parent), m_ZonesDataModel(new QmitkUSZonesDataModel(this)),
28m_Interactor(mitk::USZonesInteractor::New()),
29m_StateMachineFileName("USZoneInteractions.xml"),
30ui(new Ui::QmitkUSZoneManagementWidget), m_CurMaxNumOfZones(0)
31{
32 ui->setupUi(this);
33
34 ui->CurrentZonesTable->setModel(m_ZonesDataModel);
35 ui->CurrentZonesTable->setItemDelegateForColumn(2, new QmitkUSZoneManagementColorDialogDelegate(this));
36
37 connect(ui->CurrentZonesTable->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
38 this, SLOT(OnSelectionChanged(const QItemSelection&, const QItemSelection&)));
39 connect(m_ZonesDataModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
40 this, SLOT(OnRowInsertion(QModelIndex, int, int)));
41 connect(m_ZonesDataModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
42 this, SLOT(OnDataChanged(const QModelIndex&, const QModelIndex&)));
43
44 // load state machine and event config for data interactor
45 m_Interactor->LoadStateMachine(m_StateMachineFileName, us::ModuleRegistry::GetModule("MitkUS"));
46 m_Interactor->SetEventConfig("globalConfig.xml");
47}
48
50{
51 delete ui;
52
53 if (m_DataStorage.IsNotNull() && m_BaseNode.IsNotNull()) { m_DataStorage->Remove(m_BaseNode); }
54}
55
57{
58 m_StateMachineFileName = filename;
59 m_Interactor->LoadStateMachine(filename, us::ModuleRegistry::GetModule("MitkUS"));
60}
61
62void QmitkUSZoneManagementWidget::SetDataStorage(mitk::DataStorage::Pointer dataStorage, const char* baseNodeName)
63{
64 if (dataStorage.IsNull())
65 {
66 MITK_ERROR("QWidget")("QmitkUSZoneManagementWidget")
67 << "DataStorage must not be null.";
68 mitkThrow() << "DataStorage must not be null.";
69 }
70
71 mitk::DataNode::Pointer baseNode = dataStorage->GetNamedNode(baseNodeName);
72 if (baseNode.IsNull())
73 {
74 baseNode = mitk::DataNode::New();
75 baseNode->SetName(baseNodeName);
76 dataStorage->Add(baseNode);
77 }
78
79 baseNode->SetData(mitk::Surface::New());
80
81 m_ZonesDataModel->SetDataStorage(dataStorage, baseNode);
82
83 m_BaseNode = baseNode;
84 m_DataStorage = dataStorage;
85}
86
87void QmitkUSZoneManagementWidget::SetDataStorage(mitk::DataStorage::Pointer dataStorage, mitk::DataNode::Pointer baseNode)
88{
89 if (dataStorage.IsNull() || baseNode.IsNull())
90 {
91 MITK_ERROR("QWidget")("QmitkUSZoneManagementWidget")
92 << "DataStorage and BaseNode must not be null.";
93 mitkThrow() << "DataStorage and BaseNode must not be null.";
94 }
95
96 if (!baseNode->GetData()) { baseNode->SetData(mitk::Surface::New()); }
97
98 m_ZonesDataModel->SetDataStorage(dataStorage, baseNode);
99
100 m_BaseNode = baseNode;
101 m_DataStorage = dataStorage;
102}
103
104mitk::DataStorage::SetOfObjects::ConstPointer QmitkUSZoneManagementWidget::GetZoneNodes()
105{
106 if (m_DataStorage.IsNotNull() && m_BaseNode.IsNotNull())
107 {
108 return m_DataStorage->GetDerivations(m_BaseNode);
109 }
110 else
111 {
112 MITK_WARN("QWidget")("QmitkUSZoneManagementWidget")
113 << "Data storage or base node is null. Returning empty zone nodes set.";
114 return mitk::DataStorage::SetOfObjects::New().GetPointer();
115 }
116}
117
119{
120 QItemSelectionModel* selectionModel = ui->CurrentZonesTable->selectionModel();
121 if (!selectionModel->hasSelection())
122 {
123 MITK_WARN("QWidget")("QmitkUSZoneManagementWidget")
124 << "RemoveSelectedRows() called without any row being selected.";
125 return;
126 }
127
128 QModelIndexList selectedRows = selectionModel->selectedRows();
129
130 // sorted indices are assumed
131 QListIterator<QModelIndex> i(selectedRows);
132 i.toBack();
133 while (i.hasPrevious())
134 {
135 m_ZonesDataModel->removeRow(i.previous().row());
136 }
137
138 emit ZoneRemoved();
139}
140
142{
143 if (m_DataStorage.IsNull())
144 {
145 MITK_ERROR("QWidget")("QmitkUSZoneManagementWidget")
146 << "DataStorage must be set before adding the first zone.";
147 mitkThrow() << "DataStorage must be set before adding the first zone.";
148 }
149
150 // workaround for bug 16407
151 m_Interactor = mitk::USZonesInteractor::New();
152 m_Interactor->LoadStateMachine(m_StateMachineFileName, us::ModuleRegistry::GetModule("MitkUS"));
153 m_Interactor->SetEventConfig("globalConfig.xml");
154
155 mitk::DataNode::Pointer dataNode = mitk::DataNode::New();
156 // zone number is added to zone name (padding one zero)
157 dataNode->SetName((QString("Zone ") + QString("%1").arg(m_CurMaxNumOfZones + 1, 2, 10, QLatin1Char('0'))).toStdString());
158 dataNode->SetColor(0.9, 0.9, 0);
159 m_DataStorage->Add(dataNode, m_BaseNode);
160 m_Interactor->SetDataNode(dataNode);
161}
162
164{
165 if (m_DataStorage.IsNull())
166 {
167 MITK_ERROR("QWidget")("QmitkUSZoneManagementWidget")
168 << "DataStorage must be set before aborting adding a zone.";
169 mitkThrow() << "DataStorage must be set before aborting adding a zone.";
170 }
171
172 m_DataStorage->Remove(m_Interactor->GetDataNode());
173}
174
176{
177 // remove all zone nodes from the data storage
178 if (m_DataStorage.IsNotNull() && m_BaseNode.IsNotNull())
179 {
180 m_DataStorage->Remove(m_DataStorage->GetDerivations(m_BaseNode));
181 }
182
183 m_CurMaxNumOfZones = 0;
184}
185
186void QmitkUSZoneManagementWidget::OnSelectionChanged(const QItemSelection & selected, const QItemSelection & /*deselected*/)
187{
188 bool somethingSelected = !selected.empty() && m_ZonesDataModel->rowCount() > 0;
189 ui->ZoneSizeLabel->setEnabled(somethingSelected);
190 ui->ZoneSizeSlider->setEnabled(somethingSelected);
191 ui->DeleteZoneButton->setEnabled(somethingSelected);
192
193 if (somethingSelected)
194 {
195 ui->ZoneSizeSlider->setValue(
196 m_ZonesDataModel->data(m_ZonesDataModel->index(selected.at(0).top(), 1)).toInt());
197 }
198}
199
201{
202 QItemSelectionModel* selection = ui->CurrentZonesTable->selectionModel();
203 if (!selection->hasSelection()) { return; }
204
205 m_ZonesDataModel->setData(m_ZonesDataModel->index(selection->selectedRows().at(0).row(), 1), value);
206}
207
208void QmitkUSZoneManagementWidget::OnRowInsertion(const QModelIndex & /*parent*/, int /*start*/, int end)
209{
210 // increase zone number for unique names for every zone
211 m_CurMaxNumOfZones++;
212
213 ui->CurrentZonesTable->selectRow(end);
214 emit ZoneAdded();
215}
216
217void QmitkUSZoneManagementWidget::OnDataChanged(const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/)
218{
219 QItemSelectionModel* selection = ui->CurrentZonesTable->selectionModel();
220 if (!selection->hasSelection() || selection->selectedRows().size() < 1) { return; }
221
222 if (selection->selectedRows().at(0) == topLeft)
223 {
224 ui->ZoneSizeSlider->setValue(
225 m_ZonesDataModel->data(m_ZonesDataModel->index(topLeft.row(), 1)).toInt());
226 }
227}
QStyledItemDelegate that provides a QColorDialog as editor.
Shows a table of the zone nodes and allows to change properties and add and delete zone nodes.
void ZoneRemoved()
Emitted whenever a new zone was removed from the data mode.
void OnRowInsertion(const QModelIndex &parent, int start, int end)
Updates maximum number of added zones and selects the last row of the table. It is called every time ...
void OnZoneSizeSliderValueChanged(int value)
Updates zone radius according to the value of the zone size slider.
mitk::DataStorage::Pointer m_DataStorage
mitk::DataStorage::SetOfObjects::ConstPointer GetZoneNodes()
Get all zone nodes from the data storage.
void SetStateMachineFilename(const std::string &filename)
Sets the state machine file for being used by the mitk::USZonesInteractor.
void OnDataChanged(const QModelIndex &topLeft, const QModelIndex &)
Updates the zone size slider when data was changed. It is called every time a row was changed in the ...
void RemoveSelectedRows()
Removes all rows from the data model which are selected in the table.
QmitkUSZoneManagementWidget(QWidget *parent=nullptr)
void SetDataStorage(mitk::DataStorage::Pointer dataStorage, const char *baseNodeName="Zones")
Setter for the DataStorage where the zone nodes will be stored. The nodes will be derivates of the no...
void OnAbortAddingZone()
Aborts the creation of a new zone and deletes the corresponding node.
void OnSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void OnStartAddingZone()
Creates a new zone node and activates the data interactor on this node. This slot has to be called wh...
void ZoneAdded()
Emitted whenever a new zone was added to the data model.
itk::SmartPointer< mitk::USZonesInteractor > m_Interactor
void OnResetZones()
Removes all nodes from the data model.
Implementation of the QAbstractTableModel for ultrasound risk zones. This class manages the data mode...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Return model data of the selected cell.
void SetDataStorage(mitk::DataStorage::Pointer dataStorage, mitk::DataNode::Pointer baseNode)
Set data storage and base node for the zone nodes of this model. The node event listeners will only r...
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Set model data for the selected cell.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return number of rows of the model.
IGT Exceptions.