Fraxinus  2023.01.05-dev+develop.0da12
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 
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
boost::shared_ptr< TreeNode > TreeNodePtr
virtual QString getUid() const =0
VisServicesPtr getServices() const
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
virtual bool isVisibleNode() const
TreeNodeImpl(TreeRepositoryWeakPtr repo)
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:30
TreeRepositoryPtr repo()
virtual QString getType() const =0
virtual std::vector< TreeNodePtr > getVisibleChildren() const
TreeRepositoryWeakPtr mRepository
QIcon addBackgroundColorToIcon(QIcon input, QColor color) const
virtual TreeNodePtr getVisibleParent() const
virtual TreeNodePtr getParent() const =0
virtual std::vector< TreeNodePtr > getChildren() const
Namespace for all CustusX production code.