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