Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkNodeDescriptor.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 
13 #include "QmitkNodeDescriptor.h"
14 #include <memory>
15 #include <mitkNodePredicateAnd.h>
18 #include <mitkProperties.h>
19 
20 QmitkNodeDescriptor::QmitkNodeDescriptor(const QString &_ClassName,
21  const QString &_PathToIcon,
22  mitk::NodePredicateBase *_Predicate,
23  QObject *parent)
24  : QmitkNodeDescriptor(_ClassName, QIcon(_PathToIcon), _Predicate, parent)
25 {
26 }
27 
28 QmitkNodeDescriptor::QmitkNodeDescriptor(const QString &_ClassName,
29  const QIcon &_Icon,
30  mitk::NodePredicateBase *_Predicate,
31  QObject *parent)
32  : QObject(parent),
33  m_ClassName(_ClassName),
34  m_Icon(_Icon),
35  m_Predicate(_Predicate),
36  m_Separator(new QAction(this))
37 {
38  m_Separator->setSeparator(true);
39 }
40 
42 {
43  return m_ClassName;
44 }
45 
47 {
48  return m_Icon;
49 }
50 
51 QList<QAction *> QmitkNodeDescriptor::GetActions() const
52 {
53  return m_Actions;
54 }
55 
57 {
58  if (m_Predicate.IsNotNull())
59  return m_Predicate->CheckNode(node);
60  return false;
61 }
62 
63 void QmitkNodeDescriptor::AddAction(QAction *action, bool isBatchAction)
64 {
65  if (!action)
66  return;
67 
68  if (isBatchAction)
69  m_BatchActions.push_back(action);
70  else
71  m_Actions.push_back(action);
72  QObject::connect(action, SIGNAL(destroyed(QObject *)), this, SLOT(ActionDestroyed(QObject *)));
73 }
74 
75 void QmitkNodeDescriptor::RemoveAction(QAction *_Action)
76 {
77  int index = m_Actions.indexOf(_Action);
78  int indexOfWidgetAction = m_BatchActions.indexOf(_Action);
79 
80  if (index != -1)
81  {
82  m_Actions.removeAt(index);
83  }
84  else if (indexOfWidgetAction != -1)
85  {
86  m_BatchActions.removeAt(indexOfWidgetAction);
87  }
88 
89  if (_Action != nullptr)
90  {
91  QObject::disconnect(_Action, SIGNAL(destroyed(QObject *)), this, SLOT(ActionDestroyed(QObject *)));
92  }
93 }
94 
96 {
97  // all children are destroyed here by Qt
98 }
99 
101 {
102  return m_Separator;
103 }
104 
105 QList<QAction *> QmitkNodeDescriptor::GetBatchActions() const
106 {
107  return m_BatchActions;
108 }
109 
110 void QmitkNodeDescriptor::ActionDestroyed(QObject *obj /*= 0 */)
111 {
112  this->RemoveAction(qobject_cast<QAction *>(obj));
113 }
virtual QAction * GetSeparator() const
Decorator class for mitk::DataNode.
virtual QList< QAction * > GetBatchActions() const
virtual void RemoveAction(QAction *_Action)
void ActionDestroyed(QObject *obj=nullptr)
Called when an action was destroyed.
QList< QAction * > m_Actions
mitk::NodePredicateBase::Pointer m_Predicate
QmitkNodeDescriptor(const QString &_ClassName, const QString &_PathToIcon, mitk::NodePredicateBase *_Predicate, QObject *parent)
virtual QString GetNameOfClass() const
virtual QList< QAction * > GetActions() const
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
QList< QAction * > m_BatchActions
virtual QIcon GetIcon(const mitk::DataNode *node) const
virtual void AddAction(QAction *action, bool isBatchAction=true)
virtual bool CheckNode(const mitk::DataNode *node) const
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57