NorMIT-nav  22.09
An IGT application
cxTreeNode.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXTREENODE_H
13 #define CXTREENODE_H
14 
15 #include <vector>
16 #include <boost/weak_ptr.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <QString>
19 #include <QObject>
20 #include "cxForwardDeclarations.h"
21 #include <QIcon>
22 #include <QVariant>
23 
24 namespace cx
25 {
26 
27 class TreeNode;
28 typedef boost::weak_ptr<TreeNode> TreeNodeWeakPtr;
29 typedef boost::shared_ptr<TreeNode> TreeNodePtr;
30 typedef boost::weak_ptr<class TreeRepository> TreeRepositoryWeakPtr;
31 typedef boost::shared_ptr<class TreeRepository> TreeRepositoryPtr;
32 
33 
34 class TreeNode : public QObject
35 {
36  Q_OBJECT
37 public:
38  virtual ~TreeNode() {}
39  virtual std::vector<TreeNodePtr> getChildren() const = 0;
40  virtual QString getUid() const = 0;
41  virtual QString getName() const = 0;
42  virtual QString getType() const = 0;
43  virtual TreeNodePtr getParent() const = 0;
44  virtual bool isVisibleNode() const = 0;
45  virtual void activate() = 0;
46  virtual QIcon getIcon() const = 0;
47  virtual QVariant getViewGroupVisibility(int index) const = 0;
48  virtual void setViewGroupVisibility(int index, bool value) = 0;
49  virtual boost::shared_ptr<QWidget> createPropertiesWidget() const = 0;
50  virtual QVariant getColor() const = 0;
51  virtual bool useColoredName() const = 0;
52  virtual QVariant getFont() const = 0;
53  virtual bool isDefaultExpanded() const = 0;
54 
55  virtual bool isRemovable() const = 0;
56  virtual void remove() = 0;
57 
58  virtual std::vector<TreeNodePtr> getVisibleChildren() const = 0;
59  virtual TreeNodePtr getVisibleParent() const = 0;
60 
61 signals:
62  void parentChanged(TreeNodePtr prev, TreeNodePtr next);
63  void changed();
64 };
65 
70 class CachedTreeNode : public TreeNode
71 {
72  Q_OBJECT
73 public:
74  explicit CachedTreeNode(TreeNodePtr base);
75  virtual ~CachedTreeNode() {}
76  virtual std::vector<TreeNodePtr> getChildren() const { return mBase->getChildren(); }
77  virtual QString getUid() const;
78  virtual QString getName() const { return mBase->getName(); }
79  virtual QString getType() const;
80  virtual TreeNodePtr getParent() const { return mBase->getParent(); }
81  virtual bool isVisibleNode() const { return mBase->isVisibleNode(); }
82  virtual void activate() { mBase->activate(); }
83  virtual QIcon getIcon() const { return mBase->getIcon(); }
84  virtual QVariant getViewGroupVisibility(int index) const { return mBase->getViewGroupVisibility(index); }
85  virtual void setViewGroupVisibility(int index, bool value) { mBase->setViewGroupVisibility(index, value); }
86  virtual boost::shared_ptr<QWidget> createPropertiesWidget() const { return mBase->createPropertiesWidget(); }
87  virtual QVariant getColor() const { return mBase->getColor(); }
88  virtual bool useColoredName() const { return mBase->useColoredName(); }
89  virtual QVariant getFont() const { return mBase->getFont(); }
90  virtual bool isDefaultExpanded() const { return mBase->isDefaultExpanded(); }
91 
92  virtual bool isRemovable() const { return mBase->isRemovable(); }
93  virtual void remove() { mBase->remove(); }
94 
95  virtual std::vector<TreeNodePtr> getVisibleChildren() const;
96  virtual TreeNodePtr getVisibleParent() const;
97 
98 private:
99  mutable QString mUid;
100  mutable QString mType;
101  mutable std::vector<TreeNodeWeakPtr> mVisibleChildren;
102  mutable bool mVisibleChildrenSet;
103  mutable TreeNodeWeakPtr mVisibleParent;
104  void clearCache();
105 
106  TreeNodePtr mBase;
107 };
108 
109 } // namespace cx
110 
111 #endif // CXTREENODE_H
cx::CachedTreeNode::isDefaultExpanded
virtual bool isDefaultExpanded() const
Definition: cxTreeNode.h:90
cx::CachedTreeNode::activate
virtual void activate()
Definition: cxTreeNode.h:82
cx::TreeNode::isRemovable
virtual bool isRemovable() const =0
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::TreeNode::remove
virtual void remove()=0
cx::TreeNode::isDefaultExpanded
virtual bool isDefaultExpanded() const =0
cxForwardDeclarations.h
cx::CachedTreeNode::CachedTreeNode
CachedTreeNode(TreeNodePtr base)
Definition: cxTreeNode.cpp:17
cx::TreeNode::getParent
virtual TreeNodePtr getParent() const =0
cx::TreeNode::getColor
virtual QVariant getColor() const =0
cx::TreeNode::activate
virtual void activate()=0
cx::TreeNode::getVisibleParent
virtual TreeNodePtr getVisibleParent() const =0
cx::CachedTreeNode::getViewGroupVisibility
virtual QVariant getViewGroupVisibility(int index) const
Definition: cxTreeNode.h:84
cx::TreeNode::getVisibleChildren
virtual std::vector< TreeNodePtr > getVisibleChildren() const =0
cx::TreeNode::changed
void changed()
cx::CachedTreeNode::useColoredName
virtual bool useColoredName() const
Definition: cxTreeNode.h:88
cx::TreeNode
Definition: cxTreeNode.h:34
cx::CachedTreeNode::getColor
virtual QVariant getColor() const
Definition: cxTreeNode.h:87
cx::CachedTreeNode::getParent
virtual TreeNodePtr getParent() const
Definition: cxTreeNode.h:80
cx::CachedTreeNode::getChildren
virtual std::vector< TreeNodePtr > getChildren() const
Definition: cxTreeNode.h:76
cx::TreeNode::getType
virtual QString getType() const =0
cx::CachedTreeNode::getName
virtual QString getName() const
Definition: cxTreeNode.h:78
cx::TreeNode::getIcon
virtual QIcon getIcon() const =0
cx::CachedTreeNode::isRemovable
virtual bool isRemovable() const
Definition: cxTreeNode.h:92
cx::TreeNode::createPropertiesWidget
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const =0
cx::TreeRepositoryPtr
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
Definition: cxTreeItemModel.h:22
cx::CachedTreeNode::createPropertiesWidget
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const
Definition: cxTreeNode.h:86
cx::CachedTreeNode::remove
virtual void remove()
Definition: cxTreeNode.h:93
cx::CachedTreeNode::setViewGroupVisibility
virtual void setViewGroupVisibility(int index, bool value)
Definition: cxTreeNode.h:85
cx::TreeNodeWeakPtr
boost::weak_ptr< TreeNode > TreeNodeWeakPtr
Definition: cxDataTreeNode.h:20
cx::TreeNodePtr
boost::shared_ptr< TreeNode > TreeNodePtr
Definition: cxDataTreeNode.h:22
cx::TreeNode::useColoredName
virtual bool useColoredName() const =0
cx::CachedTreeNode
Definition: cxTreeNode.h:70
cx::TreeNode::getChildren
virtual std::vector< TreeNodePtr > getChildren() const =0
cx::CachedTreeNode::getUid
virtual QString getUid() const
Definition: cxTreeNode.cpp:33
cx::CachedTreeNode::isVisibleNode
virtual bool isVisibleNode() const
Definition: cxTreeNode.h:81
cx::TreeNode::setViewGroupVisibility
virtual void setViewGroupVisibility(int index, bool value)=0
cx::CachedTreeNode::getVisibleParent
virtual TreeNodePtr getVisibleParent() const
Definition: cxTreeNode.cpp:64
cx::CachedTreeNode::getType
virtual QString getType() const
Definition: cxTreeNode.cpp:40
cx::TreeNode::~TreeNode
virtual ~TreeNode()
Definition: cxTreeNode.h:38
cx::TreeNode::getFont
virtual QVariant getFont() const =0
cx::TreeNode::isVisibleNode
virtual bool isVisibleNode() const =0
cx::TreeNode::parentChanged
void parentChanged(TreeNodePtr prev, TreeNodePtr next)
cx::CachedTreeNode::getFont
virtual QVariant getFont() const
Definition: cxTreeNode.h:89
cx::TreeNode::getViewGroupVisibility
virtual QVariant getViewGroupVisibility(int index) const =0
cx::TreeNode::getName
virtual QString getName() const =0
cx::CachedTreeNode::getVisibleChildren
virtual std::vector< TreeNodePtr > getVisibleChildren() const
Definition: cxTreeNode.cpp:47
cx::CachedTreeNode::getIcon
virtual QIcon getIcon() const
Definition: cxTreeNode.h:83
cx::TreeRepositoryWeakPtr
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
cx::CachedTreeNode::~CachedTreeNode
virtual ~CachedTreeNode()
Definition: cxTreeNode.h:75
cx::TreeNode::getUid
virtual QString getUid() const =0