NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXTREENODE_H
34 #define CXTREENODE_H
35 
36 #include <vector>
37 #include <boost/weak_ptr.hpp>
38 #include <boost/shared_ptr.hpp>
39 #include <QString>
40 #include <QObject>
41 #include "cxForwardDeclarations.h"
42 #include <QIcon>
43 #include <QVariant>
44 
45 namespace cx
46 {
47 
48 class TreeNode;
49 typedef boost::weak_ptr<TreeNode> TreeNodeWeakPtr;
50 typedef boost::shared_ptr<TreeNode> TreeNodePtr;
51 typedef boost::weak_ptr<class TreeRepository> TreeRepositoryWeakPtr;
52 typedef boost::shared_ptr<class TreeRepository> TreeRepositoryPtr;
53 
54 
55 class TreeNode : public QObject
56 {
57  Q_OBJECT
58 public:
59  virtual ~TreeNode() {}
60  virtual std::vector<TreeNodePtr> getChildren() const = 0;
61  virtual QString getUid() const = 0;
62  virtual QString getName() const = 0;
63  virtual QString getType() const = 0;
64  virtual TreeNodePtr getParent() const = 0;
65  virtual bool isVisibleNode() const = 0;
66  virtual void activate() = 0;
67  virtual QIcon getIcon() const = 0;
68  virtual QVariant getViewGroupVisibility(int index) const = 0;
69  virtual void setViewGroupVisibility(int index, bool value) = 0;
70  virtual QWidget* createPropertiesWidget() const = 0;
71  virtual QVariant getColor() const = 0;
72  virtual bool useColoredName() const = 0;
73  virtual QVariant getFont() const = 0;
74  virtual bool isDefaultExpanded() const = 0;
75 
76  virtual bool isRemovable() const = 0;
77  virtual void remove() = 0;
78 
79  virtual std::vector<TreeNodePtr> getVisibleChildren() const = 0;
80  virtual TreeNodePtr getVisibleParent() const = 0;
81 
82 signals:
83  void parentChanged(TreeNodePtr prev, TreeNodePtr next);
84  void changed();
85 };
86 
91 class CachedTreeNode : public TreeNode
92 {
93  Q_OBJECT
94 public:
95  explicit CachedTreeNode(TreeNodePtr base);
96  virtual ~CachedTreeNode() {}
97  virtual std::vector<TreeNodePtr> getChildren() const { return mBase->getChildren(); }
98  virtual QString getUid() const;
99  virtual QString getName() const { return mBase->getName(); }
100  virtual QString getType() const;
101  virtual TreeNodePtr getParent() const { return mBase->getParent(); }
102  virtual bool isVisibleNode() const { return mBase->isVisibleNode(); }
103  virtual void activate() { mBase->activate(); }
104  virtual QIcon getIcon() const { return mBase->getIcon(); }
105  virtual QVariant getViewGroupVisibility(int index) const { return mBase->getViewGroupVisibility(index); }
106  virtual void setViewGroupVisibility(int index, bool value) { mBase->setViewGroupVisibility(index, value); }
107  virtual QWidget* createPropertiesWidget() const { return mBase->createPropertiesWidget(); }
108  virtual QVariant getColor() const { return mBase->getColor(); }
109  virtual bool useColoredName() const { return mBase->useColoredName(); }
110  virtual QVariant getFont() const { return mBase->getFont(); }
111  virtual bool isDefaultExpanded() const { return mBase->isDefaultExpanded(); }
112 
113  virtual bool isRemovable() const { return mBase->isRemovable(); }
114  virtual void remove() { mBase->remove(); }
115 
116  virtual std::vector<TreeNodePtr> getVisibleChildren() const;
117  virtual TreeNodePtr getVisibleParent() const;
118 
119 private:
120  mutable QString mUid;
121  mutable QString mType;
122 // mutable std::vector<TreeNodeWeakPtr> mVisibleChildren;
123  mutable TreeNodeWeakPtr mVisibleParent;
124  void clearCache();
125 
126  TreeNodePtr mBase;
127 };
128 
129 } // namespace cx
130 
131 #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 TreeNodePtr getVisibleParent() const
Definition: cxTreeNode.cpp:70
virtual bool isRemovable() const =0
virtual QWidget * createPropertiesWidget() const =0
virtual ~TreeNode()
Definition: cxTreeNode.h:59
virtual QVariant getViewGroupVisibility(int index) const
Definition: cxTreeNode.h:105
virtual TreeNodePtr getParent() const
Definition: cxTreeNode.h:101
virtual QVariant getColor() const =0
virtual QVariant getFont() const
Definition: cxTreeNode.h:110
virtual QIcon getIcon() const =0
virtual QString getUid() const
Definition: cxTreeNode.cpp:51
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
virtual bool isRemovable() const
Definition: cxTreeNode.h:113
virtual QString getType() const =0
virtual ~CachedTreeNode()
Definition: cxTreeNode.h:96
virtual QWidget * createPropertiesWidget() const
Definition: cxTreeNode.h:107
virtual void setViewGroupVisibility(int index, bool value)=0
virtual QVariant getViewGroupVisibility(int index) const =0
virtual bool useColoredName() const
Definition: cxTreeNode.h:109
virtual void activate()=0
virtual QString getName() const
Definition: cxTreeNode.h:99
boost::weak_ptr< TreeNode > TreeNodeWeakPtr
virtual bool useColoredName() const =0
virtual std::vector< TreeNodePtr > getChildren() const
Definition: cxTreeNode.h:97
virtual void setViewGroupVisibility(int index, bool value)
Definition: cxTreeNode.h:106
virtual std::vector< TreeNodePtr > getChildren() const =0
virtual bool isVisibleNode() const =0
virtual std::vector< TreeNodePtr > getVisibleChildren() const
Definition: cxTreeNode.cpp:65
virtual QString getName() const =0
virtual QVariant getFont() const =0
virtual QIcon getIcon() const
Definition: cxTreeNode.h:104
virtual TreeNodePtr getParent() const =0
virtual void activate()
Definition: cxTreeNode.h:103
virtual bool isDefaultExpanded() const
Definition: cxTreeNode.h:111
virtual TreeNodePtr getVisibleParent() const =0
virtual bool isDefaultExpanded() const =0
virtual QVariant getColor() const
Definition: cxTreeNode.h:108
CachedTreeNode(TreeNodePtr base)
Definition: cxTreeNode.cpp:38
virtual QString getType() const
Definition: cxTreeNode.cpp:58
virtual bool isVisibleNode() const
Definition: cxTreeNode.h:102