qt/widgets/layer/explorer/TreeItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9 
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21 * \file layer/explorer/TreeItem.cpp
22 */
23 
24 #include "TreeItem.h"
25 
26 te::qt::widgets::TreeItem::TreeItem(const std::string &type) :
27  m_type(type)
28 {
29  m_children.reset(new Queue);
30  m_parent = nullptr;
31 }
32 
34 {
35  while(m_children->getSize() > 0)
36  delete m_children->remove(0);
37 }
38 
40 {
41  m_parent = item;
42 }
43 
45 {
46  m_children->add(item);
47 
48  item->setParent(this);
49 }
50 
52 {
53  if(pos > m_children->getSize())
54  throw te::common::Exception("Index out of boundaries.");
55 
56  m_children->insert(item, (unsigned int) pos);
57 
58  item->setParent(this);
59 }
60 
62 {
63  if(pos >= m_children->getSize())
64  throw te::common::Exception("Index out of boundaries.");
65 
66  return m_children->getValue((unsigned int) pos);
67 }
68 
70 {
71  return m_parent;
72 }
73 
75 {
76  if(pos >= m_children->getSize())
77  throw te::common::Exception("Index out of boundaries.");
78 
79  return m_children->remove((unsigned int)pos);
80 }
81 
82 size_t te::qt::widgets::TreeItem::getChildrenCount(const std::string& type) const
83 {
84  if(type.empty())
85  return (size_t) m_children->getSize();
86 
87  std::vector<TreeItem*> items;
88 
89  getChildren(items, type);
90 
91  return items.size();
92 }
93 
94 void te::qt::widgets::TreeItem::getChildren(std::vector<TreeItem*>& items, const std::string& type) const
95 {
97 
98  items.clear();
99 
100  while(aux != nullptr)
101  {
102  if(aux->m_value->m_type == type || type.empty())
103  items.push_back(aux->m_value);
104 
105  aux = aux->m_next;
106  }
107 }
108 
109 
111 {
112  return (getChildrenCount("") != 0);
113 }
114 
116 {
117  return (m_parent == nullptr) ? -1 : (int) m_parent->m_children->position(this);
118 }
119 
121 {
122  return NONE;
123 }
124 
125 void te::qt::widgets::TreeItem::setVisible(const VISIBLE&, const bool&, const bool&)
126 {
127 }
128 
130 {
131  return m_type;
132 }
133 
135 {
136  return std::string();
137 }
138 
140 {
141  while(m_children->getSize() > 0)
142  delete m_children->remove(0);
143 }
144 
146 {
147  return Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled;
148 }
TreeItem * m_parent
Pointer to the parent.
TreeItem(const std::string &type)
Constructor.
bool hasChildren() const
Tells us if the item has children or not.
Defines an hierarquical structure.
void removeAllChilds()
Removes all children.
TreeItem * getChild(const size_t &pos) const
Returns the child located at pos.
Defines a hierarchical structure.
T m_value
Stored value.
Definition: GenericQueue.h:48
Struct that implements the generic queue.
Definition: GenericQueue.h:85
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
VISIBLE
Defines the visibility of an item.
int getPosition()
Returns the position of item in its parent&#39;s list of children.
TreeItem * getParent() const
Returns the item parent.
TreeItem * removeChild(const size_t &pos)
Removes the child located at pos from the children list.
virtual std::string getToolTip() const
Returns the item tooltip (for information purposes).
void setParent(TreeItem *item)
Updates the item parent.
virtual void insertChild(TreeItem *item, const size_t &pos)
Inserts a child item at the desired position.
Struct that represents a node in the Queue.
Definition: GenericQueue.h:46
size_t getChildrenCount(const std::string &type) const
Returns the number of children.
std::unique_ptr< Queue > m_children
Queue of items (children).
NodeT< T > * m_next
Pointer to the next node.
Definition: GenericQueue.h:49
void getChildren(std::vector< TreeItem * > &items, const std::string &type) const
Returns all children of a certain type.
virtual void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
std::string getType() const
Returns the type of the item.
virtual VISIBLE isVisible() const
Returns the visibilty state of the item.
virtual Qt::ItemFlags flags()
Returns the flags to be used by the model.