Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFunctionalityComponentContainer.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 #include "ui_QmitkFunctionalityComponentContainerControls.h"
19 
20 #include "mitkDataTreeFilterFunctions.h"
21 #include "mitkProperties.h"
25 
26 #include <itkCommand.h>
27 #include <qcombobox.h>
28 #include <qgroupbox.h>
29 #include <qlabel.h>
30 #include <qlayout.h>
31 #include <qtabwidget.h>
32 
33 #include <qwidget.h>
34 #include <vector>
35 
36 #include <QBoxLayout>
37 
38 const QSizePolicy preferred(QSizePolicy::Preferred, QSizePolicy::Preferred);
39 
41  const char *parentName,
42  bool updateSelector,
43  bool showSelector)
44  : QmitkBaseFunctionalityComponent(parent, parentName),
45  m_UpdateSelector(updateSelector),
46  m_ShowSelector(showSelector),
47  m_GUI(NULL),
48  m_Active(false),
49  m_SelectedItem(NULL),
50  m_FunctionalityComponentContainerGUI(NULL),
51  m_Parent(parent),
52  m_ComponentName("ComponentContainer"),
53  m_Spacer(NULL),
54  m_BackButton(NULL),
55  m_NextButton(NULL),
56  m_MaximumWidgedStackSize(-1)
57 {
58  SetAvailability(true);
59 }
60 
62 {
63 }
64 
66 {
67  m_ComponentName = name;
68 }
69 
71 {
72  return m_ComponentName;
73 }
74 
76 {
77  GetImageContent()->setShown(show);
78 }
79 
81 {
82  return (QGroupBox *)m_FunctionalityComponentContainerGUI->m_ImageContent;
83 }
84 
86 {
87  return m_GUI;
88 }
89 
91 {
92  return m_ParentMitkImage;
93 }
94 
96 {
97  if (m_FunctionalityComponentContainerGUI)
98  {
99  return m_FunctionalityComponentContainerGUI->m_TreeNodeSelector;
100  }
101  else
102  return NULL;
103 }
104 
106 {
107  return m_MulitWidget;
108 }
109 
111 {
112  if (IsActivated())
113  {
114  TreeChanged();
115  }
116  else
117  TreeChanged();
118 }
119 
121 {
123 
124  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
125  {
126  m_AddedChildList[i]->TreeChanged();
127  }
128 }
129 
131 {
132 }
133 
135 {
136  if (m_FunctionalityComponentContainerGUI)
137  {
138  connect((QObject *)(m_FunctionalityComponentContainerGUI->m_TreeNodeSelector),
139  SIGNAL(OnSelectionChanged(const mitk::DataNode *)),
140  (QObject *)this,
141  SLOT(ImageSelected(const mitk::DataNode *)));
142  connect((QObject *)(m_FunctionalityComponentContainerGUI->m_ContainerBorder),
143  SIGNAL(toggled(bool)),
144  (QObject *)this,
145  SLOT(SetContentContainerVisibility(bool)));
146  }
147 }
148 
150 {
151  m_DataStorage = dataStorage;
152 }
153 
155 {
156  return m_DataStorage;
157 }
158 
160 {
161  if (m_FunctionalityComponentContainerGUI != NULL)
162  {
163  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
164  {
165  QmitkBaseFunctionalityComponent *functionalityComponent =
166  dynamic_cast<QmitkBaseFunctionalityComponent *>(m_AddedChildList[i]);
167  if (functionalityComponent != NULL)
168  {
169  functionalityComponent->DataStorageChanged(ds);
170  }
171  }
172  }
173 
174  if (m_FunctionalityComponentContainerGUI)
175  {
176  if (!m_FunctionalityComponentContainerGUI->m_TreeNodeSelector)
177  return;
178  if (!m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->GetSelectedNode())
179  return;
180  if (!m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->GetSelectedNode()->GetData())
181  return;
182  m_ParentMitkImage = static_cast<mitk::Image *>(
183  m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->GetSelectedNode()->GetData());
184 
185  if (m_FunctionalityComponentContainerGUI != NULL)
186  {
187  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
188  {
189  QmitkBaseFunctionalityComponent *functionalityComponent =
190  dynamic_cast<QmitkBaseFunctionalityComponent *>(m_AddedChildList[i]);
191  if (functionalityComponent != NULL)
192  {
193  if (!m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->GetSelectedNode()->GetData())
194  return;
195  functionalityComponent->m_ParentMitkImage = static_cast<mitk::Image *>(
196  m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->GetSelectedNode()->GetData());
197  }
198  }
199  }
200  }
201 }
202 
204 {
205  if (m_FunctionalityComponentContainerGUI != NULL)
206  {
207  mitk::DataNode::Pointer selectedItem = const_cast<mitk::DataNode *>(item);
208  GetTreeNodeSelector()->SetSelectedNode(selectedItem);
209 
210  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
211  {
212  QmitkBaseFunctionalityComponent *functionalityComponent =
213  dynamic_cast<QmitkBaseFunctionalityComponent *>(m_AddedChildList[i]);
214  if (functionalityComponent != NULL)
215  functionalityComponent->ImageSelected(item);
216  }
217  }
218 
219  if (m_FunctionalityComponentContainerGUI)
220  {
221  m_ParentMitkImage = static_cast<mitk::Image *>(item->GetData());
222 
223  if (m_FunctionalityComponentContainerGUI != NULL)
224  {
225  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
226  {
227  QmitkBaseFunctionalityComponent *functionalityComponent =
228  dynamic_cast<QmitkBaseFunctionalityComponent *>(m_AddedChildList[i]);
229  if (functionalityComponent != NULL)
230  {
231  functionalityComponent->m_ParentMitkImage = static_cast<mitk::Image *>(item->GetData());
232  }
233  }
234  }
235  }
236  TreeChanged();
237 }
238 
240 {
241  if (m_FunctionalityComponentContainerGUI == NULL)
242  {
243  m_GUI = new QWidget;
244  m_FunctionalityComponentContainerGUI = new Ui::QmitkFunctionalityComponentContainerGUI;
245  m_FunctionalityComponentContainerGUI->setupUi(m_GUI);
246 
247  this->SetDataStorage(dataStorage);
248 
249  m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->SetDataStorage(dataStorage);
250  m_FunctionalityComponentContainerGUI->m_TreeNodeSelector->SetPredicate(mitk::NodePredicateDataType::New("Image"));
251 
252  m_FunctionalityComponentContainerGUI->m_WidgetStack->setCurrentIndex(0);
253  }
254  this->CreateConnections();
255 }
256 
258 {
259  return m_FunctionalityComponentContainerGUI->m_ImageContent;
260 }
261 
263 {
264  return m_FunctionalityComponentContainerGUI->m_ContainerBorder;
265 }
266 
268 {
269  if (GetMainCheckBoxContainer() != NULL)
270  {
271  if (GetMainCheckBoxContainer()->isChecked())
272  {
273  Activated();
274  }
275  else
276  {
277  Deactivated();
278  }
279  }
280  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
281  {
282  if (m_AddedChildList[i]->GetContentContainer() != NULL)
283  {
284  m_AddedChildList[i]->GetContentContainer()->setShown(GetMainCheckBoxContainer()->isChecked());
285  }
286  if (m_AddedChildList[i]->GetMainCheckBoxContainer() != NULL)
287  {
288  m_AddedChildList[i]->GetMainCheckBoxContainer()->setChecked(GetMainCheckBoxContainer()->isChecked());
289  }
290  m_AddedChildList[i]->SetContentContainerVisibility(GetMainCheckBoxContainer()->isChecked());
291  }
292 }
293 
295 {
296  if (m_GUI)
297  {
298  m_FunctionalityComponentContainerGUI->m_ImageContent->setShown(visibility);
299  }
300  m_ShowSelector = visibility;
301 }
302 
304 {
305  TreeChanged();
306  QmitkBaseFunctionalityComponent::Activated();
307  m_Active = true;
308  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
309  {
310  m_AddedChildList[i]->Activated();
311  }
312 }
313 
315 {
316  QmitkBaseFunctionalityComponent::Deactivated();
317  m_Active = false;
318  for (unsigned int i = 0; i < m_AddedChildList.size(); i++)
319  {
320  m_AddedChildList[i]->Deactivated();
321  }
322 }
323 
325 {
326  if (component != NULL)
327  {
328  QWidget *componentWidget = component->CreateControlWidget(m_GUI);
329  AddComponentListener(component);
330  m_GUI->layout()->addWidget(componentWidget);
331  component->CreateConnections();
332  if (m_Spacer != NULL)
333  {
334  m_GUI->layout()->removeItem(m_Spacer);
335  }
336  QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
337  m_Spacer = spacer;
338  m_GUI->layout()->addItem(m_Spacer);
339  m_GUI->repaint();
340  }
341 }
342 
344 {
345  return m_NextButton;
346 }
347 
349 {
350  return m_BackButton;
351 }
352 
354  QString label,
355  int stackPage)
356 {
357  if (component != NULL)
358  {
359  QWidget *visibleWidget = m_FunctionalityComponentContainerGUI->m_WidgetStack->currentWidget();
360  int idVisibleWidget = m_FunctionalityComponentContainerGUI->m_WidgetStack->indexOf(visibleWidget);
361  if (idVisibleWidget > m_MaximumWidgedStackSize)
362  {
363  m_MaximumWidgedStackSize = idVisibleWidget;
364  }
365  if (m_MaximumWidgedStackSize < stackPage)
366  {
367  QWidget *w = new QWidget(m_FunctionalityComponentContainerGUI->m_WidgetStack);
368  m_FunctionalityComponentContainerGUI->m_WidgetStack->insertTab(stackPage, w, label);
369  m_MaximumWidgedStackSize++;
370  m_FunctionalityComponentContainerGUI->m_WidgetStack->setCurrentIndex(stackPage);
371  visibleWidget = m_FunctionalityComponentContainerGUI->m_WidgetStack->currentWidget();
372  idVisibleWidget = m_FunctionalityComponentContainerGUI->m_WidgetStack->indexOf(visibleWidget);
373  new QVBoxLayout(visibleWidget);
374  }
375 
376  QLayout *layout;
377  if (m_FunctionalityComponentContainerGUI->m_WidgetStack->layout() == 0)
378  {
379  layout = new QVBoxLayout((QWidget *)(m_FunctionalityComponentContainerGUI->m_WidgetStack));
380  }
381  else
382  {
383  layout = m_FunctionalityComponentContainerGUI->m_WidgetStack->layout();
384  }
385 
386  component->CreateQtPartControl(m_FunctionalityComponentContainerGUI->m_WidgetStack->currentWidget(),
387  this->m_DataStorage);
388  QWidget *componentWidget = component->GetGUI();
389  AddComponentListener(component);
390  m_FunctionalityComponentContainerGUI->m_WidgetStack->setCurrentIndex(stackPage);
391  QWidget *theCurrentWidget = m_FunctionalityComponentContainerGUI->m_WidgetStack->currentWidget();
392  QLayout *theCurrentLayout = theCurrentWidget->layout();
393  theCurrentLayout->addWidget(componentWidget);
394 
395  m_FunctionalityComponentContainerGUI->m_WidgetStack->setShown(true);
396  m_FunctionalityComponentContainerGUI->m_WidgetStack->updateGeometry();
397  m_FunctionalityComponentContainerGUI->m_WidgetStack->layout()->activate();
398  componentWidget->setShown(true);
399  component->CreateConnections();
400 
401  m_GUI->repaint();
402  }
403 }
404 
406 {
407  QWidget *funcWidget = (QWidget *)m_FunctionalityComponentContainerGUI;
408  QLayout *functionalityLayout = funcWidget->layout();
409  QBoxLayout *buttonLayout = new QHBoxLayout(funcWidget);
410  if (QBoxLayout *boxLayout = dynamic_cast<QBoxLayout *>(functionalityLayout))
411  {
412  boxLayout->addLayout(buttonLayout);
413  }
414  if (m_BackButton == NULL)
415  {
416  m_BackButton = new QPushButton("<<", (QWidget *)(m_FunctionalityComponentContainerGUI));
417  }
418  if (m_NextButton == NULL)
419  {
420  m_NextButton = new QPushButton(">>", (QWidget *)(m_FunctionalityComponentContainerGUI));
421  }
422  buttonLayout->addWidget(m_BackButton);
423  buttonLayout->addWidget(m_NextButton);
424  m_BackButton->setShown(true);
425  m_NextButton->setShown(true);
426  m_GUI->layout()->activate();
427  m_GUI->repaint();
428 
429  m_FunctionalityComponentContainerGUI->m_WidgetStack->setCurrentIndex(1);
430  SetWizardText("");
431  GetImageContent()->updateGeometry();
432  if (m_Spacer != NULL)
433  {
434  m_GUI->layout()->removeItem(m_Spacer);
435  }
436  QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
437  m_Spacer = spacer;
438  m_GUI->layout()->addItem(m_Spacer);
439  m_GUI->updateGeometry();
440  m_GUI->repaint();
441 }
442 
444 {
445  GetImageContent()->updateGeometry();
446  GetImageContent()->repaint();
447  m_GUI->updateGeometry();
448  m_GUI->layout()->activate();
449  m_GUI->repaint();
450 }
451 
452 Ui::QmitkFunctionalityComponentContainerGUI *
454 {
455  return m_FunctionalityComponentContainerGUI;
456 }
void SetSelectedNode(mitk::DataNode::Pointer item)
Slot for signal when user wants to set a node as current selected node.
virtual void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
Method to set the DataStorage.
Ui::QmitkFunctionalityComponentContainerGUI * GetFunctionalityComponentContainerGUI()
also the Graphical User Interface for the component, like m_GUI, but with its specific type ...
virtual void DataStorageChanged(mitk::DataStorage::Pointer ds)
virtual QmitkDataStorageComboBox * GetTreeNodeSelector()
Displays all or a subset (defined by a predicate) of nodes of the Data Storage.
void ImageSelected(const mitk::DataNode *item)
Slot method that will be called if TreeNodeSelector widget was activated.
virtual QGroupBox * GetImageContent()
Method to return the group-box that contains the tree-node-selector.
virtual void SetComponentName(QString name)
Method to set the Name of the FunctionalityComponent.
virtual void CreateQtPartControl(QWidget *parent, mitk::DataStorage::Pointer dataStorage)
Method to create the GUI-Object.
QPushButton * GetNextButton()
Method to return the NextButton to switch to the next widgetStackPage.
virtual void UpdateDataTreeComboBoxes()
Method to update the content of all DataTreeComboBoxes.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
const QSizePolicy preferred(QSizePolicy::Preferred, QSizePolicy::Preferred)
virtual void SetSelectorVisibility(bool visibility)
Method to set the Image Selector visible or invisible.
virtual QString GetComponentName()
Method to get the Name of the FunctionalityComponent.
virtual mitk::Image * GetParentMitkImage()
Method to return the Image Selected in the Container Combo Box.
virtual void AddComponent(QmitkFunctionalityComponentContainer *componentContainer)
method to add components into this component.
bool m_ShowSelector
Attribute to decide whether the selector shall be shown or not.
virtual void SetShowTreeNodeSelector(bool show)
Method to set the Tree-Node-Selector visible or not as his parent group-box is set shown or not...
virtual QGroupBox * GetMainCheckBoxContainer()
Method to return the outermost checkable ComboBox that is to decide whether the content shall be show...
void SetWizardText(const QString &text)
Method to create a textLabel at the Top of the wizard where a description can be created.
Image class for storing images.
Definition: mitkImage.h:76
QPushButton * GetBackButton()
Method to return the BackButton to switch to the last widgetStackPage.
virtual QGroupBox * GetContentContainer()
Method to return the ComboBox that includes all GUI-elements instead of the outermost checkable Check...
QmitkFunctionalityComponentContainer(QObject *parent=0, const char *parentName=0, bool updateSelector=true, bool showSelector=true)
Standard-Constructor.
static Pointer New(const char *_arg)
QWidget * GetGUI()
Method to get the GUI of this component.
virtual void SetContentContainerVisibility(bool)
Method to set the "GetContentContainer"-visible or not, addicted to the visibility of a parent-compon...
virtual void CreateConnections()
Method to create all Signale-Slot-Connections.
virtual mitk::DataStorage::Pointer GetDataStorage()
Method to get the DataStorage.
void CreateNavigationButtons()
Method to create the forward and backward -buttons to navigate through the wizard.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66