NorMIT-nav  22.09
An IGT application
cxTreeNode.cpp
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 #include "cxTreeNode.h"
12 
13 
14 namespace cx
15 {
16 
18 {
19  connect(mBase.get(), &TreeNode::changed, this, &CachedTreeNode::clearCache);
20  connect(mBase.get(), &TreeNode::changed, this, &TreeNode::changed);
21  mVisibleChildrenSet = false;
22 }
23 
24 void CachedTreeNode::clearCache()
25 {
26  mUid = QString();
27  mType = QString();
28  mVisibleParent.reset();
29  mVisibleChildren.clear();
30  mVisibleChildrenSet = false;
31 }
32 
33 QString CachedTreeNode::getUid() const
34 {
35  if (mUid.isEmpty())
36  mUid = mBase->getUid();
37  return mUid;
38 }
39 
40 QString CachedTreeNode::getType() const
41 {
42  if (mType.isEmpty())
43  mType = mBase->getType();
44  return mType;
45 }
46 
47 std::vector<TreeNodePtr> CachedTreeNode::getVisibleChildren() const
48 {
49 // return mBase->getVisibleChildren();
50  if (!mVisibleChildrenSet)
51  {
52  std::vector<TreeNodePtr> children = mBase->getVisibleChildren();
53 
54  mVisibleChildren = std::vector<TreeNodeWeakPtr>(children.begin(), children.end());
55  mVisibleChildrenSet = true;
56  }
57 
58  std::vector<TreeNodePtr> retval(mVisibleChildren.size());
59  for (unsigned i=0; i< retval.size(); ++i)
60  retval[i] = mVisibleChildren[i].lock();
61  return retval;
62 }
63 
65 {
66 // return mBase->getVisibleParent();
67  if (!mVisibleParent.lock())
68  mVisibleParent = mBase->getVisibleParent();
69  return mVisibleParent.lock();
70 }
71 
72 
73 } // namespace cx
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::CachedTreeNode::CachedTreeNode
CachedTreeNode(TreeNodePtr base)
Definition: cxTreeNode.cpp:17
cx::TreeNode::changed
void changed()
cx::TreeNodePtr
boost::shared_ptr< TreeNode > TreeNodePtr
Definition: cxDataTreeNode.h:22
cx::CachedTreeNode::getUid
virtual QString getUid() const
Definition: cxTreeNode.cpp:33
cx::CachedTreeNode::getVisibleParent
virtual TreeNodePtr getVisibleParent() const
Definition: cxTreeNode.cpp:64
cx::CachedTreeNode::getType
virtual QString getType() const
Definition: cxTreeNode.cpp:40
cxTreeNode.h
cx::CachedTreeNode::getVisibleChildren
virtual std::vector< TreeNodePtr > getVisibleChildren() const
Definition: cxTreeNode.cpp:47