Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNodeDescriptorManager.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 <memory>
19 #include <mitkNodePredicateAnd.h>
21 #include <mitkNodePredicateNot.h>
23 #include <mitkProperties.h>
24 
25 #include <QList>
26 #include <QSet>
27 
29 {
30  static QmitkNodeDescriptorManager _Instance;
31  return &_Instance;
32 }
33 
35 {
36  auto isImage = mitk::NodePredicateDataType::New("Image");
37  this->AddDescriptor(new QmitkNodeDescriptor(tr("Image"), QString(":/Qmitk/Images_48.png"), isImage, this));
38 
39  auto isMultiComponentImage =
40  mitk::NodePredicateAnd::New(isImage, mitk::NodePredicateProperty::New("Image.Displayed Component"));
42  tr("MultiComponentImage"), QString(": / Qmitk / Images_48.png"), isMultiComponentImage, this));
43 
44  auto isBinary = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true));
45  auto isBinaryImage = mitk::NodePredicateAnd::New(isBinary, isImage);
46  this->AddDescriptor(
47  new QmitkNodeDescriptor(tr("ImageMask"), QString(":/Qmitk/Binaerbilder_48.png"), isBinaryImage, this));
48 
49  auto isLabelSetImage = mitk::NodePredicateDataType::New("LabelSetImage");
50  this->AddDescriptor(
51  new QmitkNodeDescriptor(tr("LabelSetImage"), QString(":/Qmitk/LabelSetImage_48.png"), isLabelSetImage, this));
52 
53  auto isPointSet = mitk::NodePredicateDataType::New("PointSet");
54  this->AddDescriptor(new QmitkNodeDescriptor(tr("PointSet"), QString(":/Qmitk/PointSet_48.png"), isPointSet, this));
55 
56  auto isSurface = mitk::NodePredicateDataType::New("Surface");
57  this->AddDescriptor(new QmitkNodeDescriptor(tr("Surface"), QString(":/Qmitk/Surface_48.png"), isSurface, this));
58 
59  auto isNotBinary = mitk::NodePredicateNot::New(isBinary);
60  auto isNoneBinaryImage = mitk::NodePredicateAnd::New(isImage, isNotBinary);
61  this->AddDescriptor(
62  new QmitkNodeDescriptor(tr("NoneBinaryImage"), QString(":/Qmitk/Images_48.png"), isNoneBinaryImage, this));
63 }
64 
66 {
67  _Descriptor->setParent(this);
68  m_NodeDescriptors.push_back(_Descriptor);
69 }
70 
72 {
73  int index = m_NodeDescriptors.indexOf(_Descriptor);
74 
75  if (index != -1)
76  {
77  m_NodeDescriptors.removeAt(index);
78  _Descriptor->setParent(0);
79  delete _Descriptor;
80  }
81 }
82 
84 {
86 
87  for (QList<QmitkNodeDescriptor *>::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it)
88  {
89  if ((*it)->CheckNode(_Node))
90  _Descriptor = *it;
91  }
92 
93  return _Descriptor;
94 }
95 
97 {
98  QmitkNodeDescriptor *_Descriptor = 0;
99 
100  if (_ClassName == "Unknown")
101  {
103  }
104  else
105  {
106  for (QList<QmitkNodeDescriptor *>::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end();
107  ++it)
108  {
109  if ((*it)->GetNameOfClass() == _ClassName)
110  _Descriptor = *it;
111  }
112  }
113 
114  return _Descriptor;
115 }
116 QList<QAction *> QmitkNodeDescriptorManager::GetActions(const mitk::DataNode *_Node) const
117 {
118  QList<QAction *> actions = m_UnknownDataNodeDescriptor->GetBatchActions();
119  actions.append(m_UnknownDataNodeDescriptor->GetActions());
121 
122  for (QList<QmitkNodeDescriptor *>::const_iterator it = m_NodeDescriptors.begin(); it != m_NodeDescriptors.end(); ++it)
123  {
124  if ((*it)->CheckNode(_Node))
125  {
126  actions.append(lastDescriptor->GetSeparator());
127  lastDescriptor = *it;
128  actions.append(lastDescriptor->GetBatchActions());
129  actions.append(lastDescriptor->GetActions());
130  }
131  }
132 
133  return actions;
134 }
135 
136 QList<QAction *> QmitkNodeDescriptorManager::GetActions(const QList<mitk::DataNode::Pointer> &_Nodes) const
137 {
138  QList<QAction *> actions = m_UnknownDataNodeDescriptor->GetBatchActions();
139  QSet<QmitkNodeDescriptor *> nodeDescriptors;
140  QmitkNodeDescriptor *lastDescriptor;
141 
142  // find all descriptors for the nodes (unique)
143  foreach (mitk::DataNode::Pointer node, _Nodes)
144  {
145  lastDescriptor = this->GetDescriptor(node);
146  nodeDescriptors.insert(lastDescriptor);
147  }
148  // add all actions for the found descriptors
149  lastDescriptor = m_UnknownDataNodeDescriptor;
150  foreach (QmitkNodeDescriptor *descr, nodeDescriptors)
151  {
152  actions.append(lastDescriptor->GetSeparator());
153  lastDescriptor = descr;
154  actions.append(lastDescriptor->GetBatchActions());
155  }
156 
157  return actions;
158 }
159 
161  : m_UnknownDataNodeDescriptor(new QmitkNodeDescriptor("Unknown", QString(":/Qmitk/DataTypeUnknown_48.png"), 0, this))
162 {
163  this->Initialize();
164 }
165 
167 {
168  // delete m_UnknownDataNodeDescriptor;
169  // qDeleteAll(m_NodeDescriptors);
170 }
171 
173 {
175 }
QmitkNodeDescriptor * GetUnknownDataNodeDescriptor() const
static Pointer New()
QmitkNodeQmitkNodeDescriptor is Decorator class for the mitk::DataNode which enhances certain mitk::D...
virtual QAction * GetSeparator() const
virtual QList< QAction * > GetBatchActions() const
QmitkNodeDescriptorManager manages a set of QmitkNodeDescriptors.
static Pointer New()
void RemoveDescriptor(QmitkNodeDescriptor *_Descriptor)
static Pointer New(const mitk::NodePredicateBase *_arg)
QList< QmitkNodeDescriptor * > m_NodeDescriptors
QmitkNodeDescriptor * GetDescriptor(const mitk::DataNode *_Node) const
static Pointer New(const char *_arg)
static Pointer New(const char *_arg)
virtual QList< QAction * > GetActions() const
QList< QAction * > GetActions(const mitk::DataNode *_Node) const
void AddDescriptor(QmitkNodeDescriptor *_Descriptor)
QmitkNodeDescriptor * m_UnknownDataNodeDescriptor
static QmitkNodeDescriptorManager * GetInstance()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66