Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkTrackingSourcesCheckBoxPanelWidget.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 
14 
15 #include <QMessageBox>
16 
17 
19 : QWidget(parent), m_Controls(nullptr), m_SourceCheckboxes(nullptr), m_NavigationDatas(nullptr), m_SelectedIds(nullptr)
20 {
21  this->CreateQtPartControl( this );
22  m_SourceCheckboxes = new TrackingSourcesCheckboxes();
23 }
24 
26 {
27  delete m_SelectedIds;
28  delete m_SourceCheckboxes;
29  delete m_NavigationDatas;
30 }
31 
33 {
34  if (!m_Controls)
35  {
36  // create GUI widgets
37  m_Controls = new Ui::QmitkTrackingSourcesCheckBoxPanelWidgetControls;
38  m_Controls->setupUi(parent);
39 
40  this->CreateConnections();
41  }
42 }
43 
45 {
46  connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(toggled(bool)), this, SLOT(OnPerformActionClicked(bool)) ) ;
47  connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(clicked()), this, SLOT(OnPerformActionClicked()) ) ;
48 }
49 
50 
51 void QmitkTrackingSourcesCheckBoxPanelWidget::SetNavigationDatas(std::vector<mitk::NavigationData::Pointer>* navDatas)
52 {
53  if( navDatas != nullptr )
54  m_NavigationDatas = navDatas;
55 }
56 
57 
58 void QmitkTrackingSourcesCheckBoxPanelWidget::AddNavigationData(mitk::NavigationData::Pointer nd)
59 {
60  if(m_NavigationDatas == nullptr)
61  m_NavigationDatas = new std::vector<mitk::NavigationData::Pointer>();
62 
63  if( nd.IsNotNull() )
64  m_NavigationDatas->push_back(nd);
65 }
66 
68  return m_Controls->m_ActionButton->isChecked();
69 }
70 
71 
73 {
74  if(m_SelectedIds == nullptr)
75  m_SelectedIds = new std::vector<int>();
76  else
77  m_SelectedIds->clear();
78 
79  for (unsigned int i=0; i < m_SourceCheckboxes->size(); i++)
80  {
81  if(m_SourceCheckboxes->at(i)->isChecked())
82  m_SelectedIds->push_back(i);
83  }
84 
85  return m_SelectedIds;
86 }
87 
89 {
90  while(m_Controls->m_GridLayout->count() > 0)
91  {
92  QWidget* actWidget = m_Controls->m_GridLayout->itemAt(0)->widget();
93  m_Controls->m_GridLayout->removeWidget(actWidget);
94  delete actWidget;
95  }
96 
97  if(m_SourceCheckboxes != nullptr)
98  m_SourceCheckboxes->clear();
99 
100  if(m_NavigationDatas != nullptr)
101  m_NavigationDatas->clear();
102 
103 
104 }
105 
107 {
108  if(m_SelectedIds != nullptr && !m_SelectedIds->empty())
109  m_SelectedIds->clear();
110 }
111 
113 {
114  if( m_SourceCheckboxes != nullptr )
115  m_SourceCheckboxes->clear();
116 
117  if( m_NavigationDatas == nullptr )
118  return;
119 
120  QCheckBox* checkBox;
121 
122  int row = 0;
123  int column;
124 
125  for(unsigned int i=0; i < m_NavigationDatas->size(); i++) // puts a radiobutton for every tracking source output in a 2 columns QGridLayout
126  {
127  column = i % 4;
128  if( i>0 && i%4==0 )
129  row++;
130 
131  QString name(m_NavigationDatas->at(i).GetPointer()->GetName());
132 
133  checkBox = new QCheckBox(name, this);
134 
135  connect( checkBox, SIGNAL(toggled(bool)), this , SLOT(OnCheckboxClicked(bool)) );
136 
137  m_SourceCheckboxes->push_back(checkBox);
138  m_Controls->m_GridLayout->addWidget(checkBox,row,column);
139 
140  }
141 
142 }
143 
145 {
146  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
147  {
148  m_SourceCheckboxes->at(i)->setEnabled(enable);
149  }
150 }
151 
153 {
154  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
155  {
156  m_SourceCheckboxes->at(i)->setChecked(true);
157  }
158 }
159 
161 {
162  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
163  {
164  m_SourceCheckboxes->at(i)->setChecked(false);
165  }
166 }
167 
169 {
170  m_SourceCheckboxes->at(idx)->setChecked(true);
171 }
172 
174 {
175  m_SourceCheckboxes->at(idx)->setChecked(false);
176 }
177 
178 
180 {
181  QCheckBox* sender = qobject_cast< QCheckBox* > (QObject::sender());
182 
183  if( sender == nullptr )
184  throw std::invalid_argument("No sender found!");
185 
186  int idx = -1;
187 
188  for(unsigned int i=0 ;i < m_SourceCheckboxes->size(); i++)
189  {
190  if(sender == m_SourceCheckboxes->at(i))
191  { idx=i;
192  break;
193  }
194  }
195 
196  if(idx>-1)
197  {
198  if(checked)
199  emit Selected(idx);
200  else
201  emit Deselected(idx);
202  }
203 
204 }
205 
207 {
208  m_Controls->m_InfoLabel->setText(text);
209 }
210 
212 {
213  m_Controls->m_ActionButton->setText(text);
214 }
215 
216 
218 {
219  if(hide)
220  m_Controls->m_ActionButton->hide();
221  else
222  m_Controls->m_ActionButton->show();
223 }
224 
225 
227 {
228  if(checkable)
229  m_Controls->m_ActionButton->setCheckable(true);
230  else
231  m_Controls->m_ActionButton->setCheckable(false);
232 }
233 
235 {
236  if(this->GetSelectedTrackingSourcesIDs()->empty())
237  {
238  m_Controls->m_ActionButton->setChecked(false);
239  return;
240  }
241 
242  if(toggled)
243  {
244  bool invalidND = false;
245 
246  for(std::size_t i=0; i < this->GetSelectedTrackingSourcesIDs()->size(); ++i)
247  {
248  if(!(m_NavigationDatas->at(this->GetSelectedTrackingSourcesIDs()->at(i))->IsDataValid()))
249  invalidND = true;
250  }
251 
252  if(invalidND)
253  {
254  QMessageBox::warning(nullptr, "Invalid Tracking Data", "One or more instruments are in invalid tracking state! Requested action can not be performed!");
255  m_Controls->m_ActionButton->setChecked(false);
256  return;
257  }
258  emit PerformAction();
259  }
260  else
261  emit StopAction();
262 }
263 
265 {
266  if(this->GetSelectedTrackingSourcesIDs()->empty()){
267  m_Controls->m_ActionButton->setChecked(false);
268  return;
269  }
270 
271  emit Action();
272 }
void SelectCheckbox(unsigned int idx)
Selets the checkbox at the given position.
void PerformAction()
when a checkbox is deselected
Ui::QmitkTrackingSourcesCheckBoxPanelWidgetControls * m_Controls
gui widgets
void Action()
when action perform button is released
void StopAction()
when action perfom button is pressed
void AddNavigationData(mitk::NavigationData::Pointer nd)
Adds a ND.
void HideActionPerformButton(bool hide)
Hides or shows the action perfom button.
void SelectAll()
Selects all checkboxes in this widget.
void SetActionPerformButtonCheckable(bool checkable)
Sets whether the action perform button is checkable or not.
void OnCheckboxClicked(bool checked)
clearing checkboxes from panel
void Deselected(int id)
when a checkbox is selected
void DeselectAll()
Deselects all checkboxes in this widget.
void SetNavigationDatas(std::vector< mitk::NavigationData::Pointer > *navDatas)
Sets the ND for this widget.
const std::vector< int > * GetSelectedTrackingSourcesIDs()
Returns the selected tracking sources IDs.
void ClearPanel()
when action perfom button is clicked
void DeselectCheckbox(unsigned int idx)
Deselects the checkbox at the given position.
void EnableCheckboxes(bool enable)
Enables or disabless the checkboxes in this widget.
QmitkTrackingSourcesCheckBoxPanelWidget(QWidget *parent)
vector with checkboxes for all set NDs
void SetInfoText(QString text)
Sets this widget&#39;s info text.
void SetActionPerformButtonText(QString text)
Sets this widget&#39;s action perform button text.
void ClearSelectedIDs()
Clears the vector that holds the selected IDs.
bool IsActionButtonChecked()
Returns whether this widgets "perform action" button is checked.