NorMIT-nav  22.09
An IGT application
cxTreeNodeImpl.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 "cxTreeNodeImpl.h"
12 #include "cxTreeRepository.h"
13 #include "cxLogger.h"
14 #include <QIcon>
15 #include <QPainter>
16 
17 
18 namespace cx
19 {
20 
21 
23  mRepository(repo)
24 {
25 
26 }
27 
28 std::vector<TreeNodePtr> TreeNodeImpl::getChildren() const
29 {
30  // implement as inverse of getParent()
31  std::vector<TreeNodePtr> retval;
32  std::vector<TreeNodePtr> all = this->repo()->getNodes();
33  for (unsigned i=0; i<all.size(); ++i)
34  {
35  TreeNodePtr p = all[i]->getParent();
36  if (p && (p->getUid() == this->getUid()))
37  retval.push_back(all[i]);
38 // CX_LOG_CHANNEL_DEBUG("CA") << QString(" - data node %1 children: %2").arg(this->getName()).arg(retval.size());
39  }
40  return retval;
41 }
42 
43 //TreeNodePtr TreeNodeImpl::getParent() const
44 //{
45 // if (!this->isVisibleNode())
46 // return TreeNodePtr();
47 // CX_LOG_CHANNEL_DEBUG("CA") << "===== TreeNodeImpl::getParent() " << this->getName();
48 // TreeNodePtr parent = this->getParentIgnoreVisiblity();
49 // CX_LOG_CHANNEL_DEBUG("CA") << " parent= " << ((parent.get()!=NULL)?parent->getName():"NULL");
50 // while (parent && !parent->isVisibleNode())
51 // {
52 // parent = parent->getParent();
53 // CX_LOG_CHANNEL_DEBUG("CA") << " parent= " << ((parent.get()!=NULL)?parent->getName():"NULL");
54 // }
55 // CX_LOG_CHANNEL_DEBUG("CA") << " parent end= " << ((parent.get()!=NULL)?parent->getName():"NULL");
56 // return parent;
58 //}
59 
60 std::vector<TreeNodePtr> TreeNodeImpl::getVisibleChildren() const
61 {
62  // implement as inverse of getParent()
63  std::vector<TreeNodePtr> retval;
64  std::vector<TreeNodePtr> all = this->repo()->getNodes();
65  for (unsigned i=0; i<all.size(); ++i)
66  {
67  TreeNodePtr vp = all[i]->getVisibleParent();
68  if (vp && (vp->getUid() == this->getUid()))
69  retval.push_back(all[i]);
70  }
71  return retval;
72 }
73 
75 {
76  if (!this->isVisibleNode())
77  return TreeNodePtr();
78  TreeNodePtr parent = this->getParent();
79  while (parent && !parent->isVisibleNode())
80  {
81  parent = parent->getParent();
82  }
83  return parent;
84 }
85 
86 
88 {
89  bool isKnown = this->repo()->getAllNodeTypes().contains(this->getType());
90  bool isVisible = this->repo()->getVisibleNodeTypes().contains(this->getType());
91 // CX_LOG_CHANNEL_DEBUG("CA") << "TreeNodeImpl::isVisibleNode() name=" << this->getName()
92 // << " isKnown=" << isKnown
93 // << " isVisible=" << isVisible;
94  return !isKnown || isVisible;
95 }
96 
98 {
99  return this->repo()->getServices();
100 }
101 
103 {
104  return mRepository.lock();
105 }
106 
108 {
109  return mRepository.lock();
110 }
111 
112 QIcon TreeNodeImpl::addBackgroundColorToIcon(QIcon input, QColor color) const
113 {
114  QPixmap org = input.pixmap(input.actualSize(QSize(1000,1000)));
115  QImage image(org.size(), QImage::Format_RGBA8888);
116  QPainter painter(&image);
117  painter.fillRect(image.rect(), color);
118  painter.drawPixmap(0,0,org);
119  return QIcon(QPixmap::fromImage(image));
120 }
121 
122 } // namespace cx
123 
cx::TreeNodeImpl::mRepository
TreeRepositoryWeakPtr mRepository
Definition: cxTreeNodeImpl.h:51
cxLogger.h
cx::TreeNodeImpl::getVisibleChildren
virtual std::vector< TreeNodePtr > getVisibleChildren() const
Definition: cxTreeNodeImpl.cpp:60
cxTreeRepository.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::TreeNode::getParent
virtual TreeNodePtr getParent() const =0
cxTreeNodeImpl.h
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::TreeNodeImpl::getChildren
virtual std::vector< TreeNodePtr > getChildren() const
Definition: cxTreeNodeImpl.cpp:28
cx::TreeNodeImpl::getVisibleParent
virtual TreeNodePtr getVisibleParent() const
Definition: cxTreeNodeImpl.cpp:74
cx::TreeNodeImpl::TreeNodeImpl
TreeNodeImpl(TreeRepositoryWeakPtr repo)
Definition: cxTreeNodeImpl.cpp:22
cx::TreeNode::getType
virtual QString getType() const =0
cx::TreeNodeImpl::isVisibleNode
virtual bool isVisibleNode() const
Definition: cxTreeNodeImpl.cpp:87
cx::TreeRepositoryPtr
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
Definition: cxTreeItemModel.h:22
cx::TreeNodePtr
boost::shared_ptr< TreeNode > TreeNodePtr
Definition: cxDataTreeNode.h:22
cx::TreeNodeImpl::getServices
VisServicesPtr getServices() const
Definition: cxTreeNodeImpl.cpp:97
cx::TreeNodeImpl::addBackgroundColorToIcon
QIcon addBackgroundColorToIcon(QIcon input, QColor color) const
Definition: cxTreeNodeImpl.cpp:112
cx::TreeNodeImpl::repo
TreeRepositoryPtr repo()
Definition: cxTreeNodeImpl.cpp:102
cx::TreeRepositoryWeakPtr
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30