Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxTreeNodeImpl.h"
33 #include "cxTreeRepository.h"
34 #include "cxLogger.h"
35 #include <QIcon>
36 #include <QPainter>
37 
38 
39 namespace cx
40 {
41 
42 
44  mRepository(repo)
45 {
46 
47 }
48 
49 std::vector<TreeNodePtr> TreeNodeImpl::getChildren() const
50 {
51  // implement as inverse of getParent()
52  std::vector<TreeNodePtr> retval;
53  std::vector<TreeNodePtr> all = this->repo()->getNodes();
54  for (unsigned i=0; i<all.size(); ++i)
55  {
56  TreeNodePtr p = all[i]->getParent();
57  if (p && (p->getUid() == this->getUid()))
58  retval.push_back(all[i]);
59 // CX_LOG_CHANNEL_DEBUG("CA") << QString(" - data node %1 children: %2").arg(this->getName()).arg(retval.size());
60  }
61  return retval;
62 }
63 
64 //TreeNodePtr TreeNodeImpl::getParent() const
65 //{
66 // if (!this->isVisibleNode())
67 // return TreeNodePtr();
68 // CX_LOG_CHANNEL_DEBUG("CA") << "===== TreeNodeImpl::getParent() " << this->getName();
69 // TreeNodePtr parent = this->getParentIgnoreVisiblity();
70 // CX_LOG_CHANNEL_DEBUG("CA") << " parent= " << ((parent.get()!=NULL)?parent->getName():"NULL");
71 // while (parent && !parent->isVisibleNode())
72 // {
73 // parent = parent->getParent();
74 // CX_LOG_CHANNEL_DEBUG("CA") << " parent= " << ((parent.get()!=NULL)?parent->getName():"NULL");
75 // }
76 // CX_LOG_CHANNEL_DEBUG("CA") << " parent end= " << ((parent.get()!=NULL)?parent->getName():"NULL");
77 // return parent;
79 //}
80 
81 std::vector<TreeNodePtr> TreeNodeImpl::getVisibleChildren() const
82 {
83  // implement as inverse of getParent()
84  std::vector<TreeNodePtr> retval;
85  std::vector<TreeNodePtr> all = this->repo()->getNodes();
86  for (unsigned i=0; i<all.size(); ++i)
87  {
88  TreeNodePtr vp = all[i]->getVisibleParent();
89  if (vp && (vp->getUid() == this->getUid()))
90  retval.push_back(all[i]);
91  }
92  return retval;
93 }
94 
96 {
97  if (!this->isVisibleNode())
98  return TreeNodePtr();
99  TreeNodePtr parent = this->getParent();
100  while (parent && !parent->isVisibleNode())
101  {
102  parent = parent->getParent();
103  }
104  return parent;
105 }
106 
107 
109 {
110  bool isKnown = this->repo()->getAllNodeTypes().contains(this->getType());
111  bool isVisible = this->repo()->getVisibleNodeTypes().contains(this->getType());
112 // CX_LOG_CHANNEL_DEBUG("CA") << "TreeNodeImpl::isVisibleNode() name=" << this->getName()
113 // << " isKnown=" << isKnown
114 // << " isVisible=" << isVisible;
115  return !isKnown || isVisible;
116 }
117 
119 {
120  return this->repo()->getServices();
121 }
122 
124 {
125  return mRepository.lock();
126 }
127 
129 {
130  return mRepository.lock();
131 }
132 
133 QIcon TreeNodeImpl::addBackgroundColorToIcon(QIcon input, QColor color) const
134 {
135  QPixmap org = input.pixmap(input.actualSize(QSize(1000,1000)));
136  QImage image(org.size(), QImage::Format_RGBA8888);
137  QPainter painter(&image);
138  painter.fillRect(image.rect(), color);
139  painter.drawPixmap(0,0,org);
140  return QIcon(QPixmap::fromImage(image));
141 }
142 
143 } // namespace cx
144 
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:62
virtual bool isVisibleNode() const
TreeNodeImpl(TreeRepositoryWeakPtr repo)
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
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