Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
18 
19 #include <QMessageBox>
20 
21 
23 : QWidget(parent), m_Controls(NULL), m_SourceCheckboxes(NULL), m_NavigationDatas(NULL), m_SelectedIds(NULL)
24 {
25  this->CreateQtPartControl( this );
26  m_SourceCheckboxes = new TrackingSourcesCheckboxes();
27 }
28 
30 {
31  delete m_SelectedIds;
32  delete m_SourceCheckboxes;
33  delete m_NavigationDatas;
34 }
35 
37 {
38  if (!m_Controls)
39  {
40  // create GUI widgets
41  m_Controls = new Ui::QmitkTrackingSourcesCheckBoxPanelWidgetControls;
42  m_Controls->setupUi(parent);
43 
44  this->CreateConnections();
45  }
46 }
47 
49 {
50  connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(toggled(bool)), this, SLOT(OnPerformActionClicked(bool)) ) ;
51  connect( (QPushButton*) m_Controls->m_ActionButton, SIGNAL(clicked()), this, SLOT(OnPerformActionClicked()) ) ;
52 }
53 
54 
55 void QmitkTrackingSourcesCheckBoxPanelWidget::SetNavigationDatas(std::vector<mitk::NavigationData::Pointer>* navDatas)
56 {
57  if( navDatas != NULL )
58  m_NavigationDatas = navDatas;
59 }
60 
61 
63 {
64  if(m_NavigationDatas == NULL)
65  m_NavigationDatas = new std::vector<mitk::NavigationData::Pointer>();
66 
67  if( nd.IsNotNull() )
68  m_NavigationDatas->push_back(nd);
69 }
70 
72  return m_Controls->m_ActionButton->isChecked();
73 }
74 
75 
77 {
78  if(m_SelectedIds == NULL)
79  m_SelectedIds = new std::vector<int>();
80  else
81  m_SelectedIds->clear();
82 
83  for (unsigned int i=0; i < m_SourceCheckboxes->size(); i++)
84  {
85  if(m_SourceCheckboxes->at(i)->isChecked())
86  m_SelectedIds->push_back(i);
87  }
88 
89  return m_SelectedIds;
90 }
91 
93 {
94  while(m_Controls->m_GridLayout->count() > 0)
95  {
96  QWidget* actWidget = m_Controls->m_GridLayout->itemAt(0)->widget();
97  m_Controls->m_GridLayout->removeWidget(actWidget);
98  delete actWidget;
99  }
100 
101  if(m_SourceCheckboxes != NULL)
102  m_SourceCheckboxes->clear();
103 
104  if(m_NavigationDatas != NULL)
105  m_NavigationDatas->clear();
106 
107 
108 }
109 
111 {
112  if(m_SelectedIds != NULL && !m_SelectedIds->empty())
113  m_SelectedIds->clear();
114 }
115 
117 {
118  if( m_SourceCheckboxes != NULL )
119  m_SourceCheckboxes->clear();
120 
121  if( m_NavigationDatas == NULL )
122  return;
123 
124  QCheckBox* checkBox;
125 
126  int row = 0;
127  int column;
128 
129  for(unsigned int i=0; i < m_NavigationDatas->size(); i++) // puts a radiobutton for every tracking source output in a 2 columns QGridLayout
130  {
131  column = i % 4;
132  if( i>0 && i%4==0 )
133  row++;
134 
135  QString name(m_NavigationDatas->at(i).GetPointer()->GetName());
136 
137  checkBox = new QCheckBox(name, this);
138 
139  connect( checkBox, SIGNAL(toggled(bool)), this , SLOT(OnCheckboxClicked(bool)) );
140 
141  m_SourceCheckboxes->push_back(checkBox);
142  m_Controls->m_GridLayout->addWidget(checkBox,row,column);
143 
144  }
145 
146 }
147 
149 {
150  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
151  {
152  m_SourceCheckboxes->at(i)->setEnabled(enable);
153  }
154 }
155 
157 {
158  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
159  {
160  m_SourceCheckboxes->at(i)->setChecked(true);
161  }
162 }
163 
165 {
166  for(unsigned int i=0; i< m_SourceCheckboxes->size(); i++)
167  {
168  m_SourceCheckboxes->at(i)->setChecked(false);
169  }
170 }
171 
173 {
174  m_SourceCheckboxes->at(idx)->setChecked(true);
175 }
176 
178 {
179  m_SourceCheckboxes->at(idx)->setChecked(false);
180 }
181 
182 
184 {
185  QCheckBox* sender = qobject_cast< QCheckBox* > (QObject::sender());
186 
187  if( sender == NULL )
188  throw std::invalid_argument("No sender found!");
189 
190  int idx = -1;
191 
192  for(unsigned int i=0 ;i < m_SourceCheckboxes->size(); i++)
193  {
194  if(sender == m_SourceCheckboxes->at(i))
195  { idx=i;
196  break;
197  }
198  }
199 
200  if(idx>-1)
201  {
202  if(checked)
203  emit Selected(idx);
204  else
205  emit Deselected(idx);
206  }
207 
208 }
209 
211 {
212  m_Controls->m_InfoLabel->setText(text);
213 }
214 
216 {
217  m_Controls->m_ActionButton->setText(text);
218 }
219 
220 
222 {
223  if(hide)
224  m_Controls->m_ActionButton->hide();
225  else
226  m_Controls->m_ActionButton->show();
227 }
228 
229 
231 {
232  if(checkable)
233  m_Controls->m_ActionButton->setCheckable(true);
234  else
235  m_Controls->m_ActionButton->setCheckable(false);
236 }
237 
239 {
240  if(this->GetSelectedTrackingSourcesIDs()->empty())
241  {
242  m_Controls->m_ActionButton->setChecked(false);
243  return;
244  }
245 
246  if(toggled)
247  {
248  bool invalidND = false;
249 
250  for(int i=0; i < this->GetSelectedTrackingSourcesIDs()->size(); ++i)
251  {
252  if(!(m_NavigationDatas->at(this->GetSelectedTrackingSourcesIDs()->at(i))->IsDataValid()))
253  invalidND = true;
254  }
255 
256  if(invalidND)
257  {
258  QMessageBox::warning(NULL, "Invalid Tracking Data", "One or more instruments are in invalid tracking state! Requested action can not be performed!");
259  m_Controls->m_ActionButton->setChecked(false);
260  return;
261  }
262  emit PerformAction();
263  }
264  else
265  emit StopAction();
266 }
267 
269 {
270  if(this->GetSelectedTrackingSourcesIDs()->empty()){
271  m_Controls->m_ActionButton->setChecked(false);
272  return;
273  }
274 
275  emit Action();
276 }
void SelectCheckbox(unsigned int idx)
Selets the checkbox at the given position.
itk::SmartPointer< Self > Pointer
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's info text.
void SetActionPerformButtonText(QString text)
Sets this widget'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.