CustusX  2021.04.21-dev+develop.337f9
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
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
boost::shared_ptr< TreeNode > TreeNodePtr
virtual std::vector< TreeNodePtr > getVisibleChildren() const =0
void changed()
void parentChanged(TreeNodePtr prev, TreeNodePtr next)
virtual QString getUid() const =0
virtual bool isRemovable() const =0
virtual ~TreeNode()
Definition: cxTreeNode.h:38
virtual QVariant getViewGroupVisibility(int index) const
Definition: cxTreeNode.h:84
virtual TreeNodePtr getParent() const
Definition: cxTreeNode.h:80
virtual QVariant getColor() const =0
virtual QVariant getFont() const
Definition: cxTreeNode.h:89
virtual QIcon getIcon() const =0
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const
Definition: cxTreeNode.h:86
virtual bool isRemovable() const
Definition: cxTreeNode.h:92
virtual QString getType() const =0
virtual ~CachedTreeNode()
Definition: cxTreeNode.h:75
virtual void setViewGroupVisibility(int index, bool value)=0
virtual QVariant getViewGroupVisibility(int index) const =0
virtual bool useColoredName() const
Definition: cxTreeNode.h:88
virtual void activate()=0
virtual QString getName() const
Definition: cxTreeNode.h:78
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const =0
boost::weak_ptr< TreeNode > TreeNodeWeakPtr
virtual bool useColoredName() const =0
virtual std::vector< TreeNodePtr > getChildren() const
Definition: cxTreeNode.h:76
virtual void setViewGroupVisibility(int index, bool value)
Definition: cxTreeNode.h:85
virtual std::vector< TreeNodePtr > getChildren() const =0
virtual bool isVisibleNode() const =0
virtual QString getName() const =0
virtual QVariant getFont() const =0
virtual QIcon getIcon() const
Definition: cxTreeNode.h:83
virtual TreeNodePtr getParent() const =0
virtual void activate()
Definition: cxTreeNode.h:82
virtual bool isDefaultExpanded() const
Definition: cxTreeNode.h:90
virtual TreeNodePtr getVisibleParent() const =0
virtual bool isDefaultExpanded() const =0
virtual QVariant getColor() const
Definition: cxTreeNode.h:87
Namespace for all CustusX production code.
virtual bool isVisibleNode() const
Definition: cxTreeNode.h:81