Loading...
Searching...
No Matches
TreeItem.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5TerraLib is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 3 of the License,
8or (at your option) any later version.
9
10TerraLib is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with TerraLib. See COPYING. If not, write to
17TerraLib Team at <terralib-team@terralib.org>.
18*/
19
20/*!
21 * \file layer/explorer/TreeItem.h
22 *
23 * \brief Defines an hierarquical structure.
24 */
25
26#ifndef __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_TREEITEM_H
27#define __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_TREEITEM_H
28
29#include "../../Config.h"
30
31// TerraLib
32#include "../../../../common/Exception.h"
33#include "../../../../common/GenericQueue.h"
34
35// Qt
36#include <qnamespace.h>
37#include <QString>
38
39// STL
40#include <memory>
41#include <vector>
42
43// Forward declarations
44namespace te
45{
46 namespace qt
47 {
48 namespace widgets
49 {
50 class TreeItem;
52
53 /*!
54 * \enum VISIBLE
55 *
56 * \brief Defines the visibility of an item.
57 */
59 {
60 NONE, //!< Not visible.
61 TOTALLY, //!< Visible.
62 PARTIALLY //!< Partially visible.
63 };
64
65 /*!
66 * \class TreeItem
67 *
68 * \brief Defines a hierarchical structure.
69 *
70 * \ingroup widgets
71 */
73 {
74 public:
75 /*!
76 * \name Instantiation Methods
77 *
78 * Methods related to creation and destruction of the object.
79 */
80 //@{
81
82 /*!
83 * \brief Constructor.
84 *
85 * \param type The type of the item.
86 */
87 TreeItem(const std::string& type);
88
89 /*!
90 * \brief Destructor.
91 */
92 virtual ~TreeItem();
93 //@}
94
95 /*!
96 * \brief Updates the item parent.
97 *
98 * \param item The new parent.
99 */
100 void setParent(TreeItem* item);
101
102 /*!
103 * \brief Adds a child to the item. The child is added to the end of the list.
104 *
105 * \param item The child to be inserted.
106 */
107 virtual void addChild(TreeItem* item);
108
109 /*!
110 * \brief Inserts a child item at the desired position.
111 *
112 * \param item The child to be inserted.
113 *
114 * \param pos The position of the child in the children list.
115 *
116 * \exception If \a pos is greater than the children list size, a te::common::Exception will be raised.
117 */
118 virtual void insertChild(TreeItem* item, const size_t& pos) ;
119
120 /*!
121 * \brief Returns the child located at \a pos.
122 *
123 * \param pos The position of the desired child at the children list.
124 *
125 * \return The child item located at \a pos.
126 *
127 * \exception If \a pos is greater or equal than the children list size, a te::common::Exception will be raised.
128 */
129 TreeItem* getChild(const size_t& pos) const ;
130
131 /*!
132 * \brief Returns the item parent.
133 *
134 * \return A pointer to the parent.
135 */
137
138 /*!
139 * \brief Removes the child located at \a pos from the children list.
140 *
141 * \param pos The position of the desired child at the children list.
142 *
143 * \return The removed item.
144 *
145 * \exception If \a pos is greater or equal than the children list size, a te::common::Exception will be raised.
146 */
147 TreeItem* removeChild(const size_t& pos) ;
148
149 /*!
150 * \brief Returns the number of children.
151 *
152 * The \a type, defines the type of children we want to considere in the operation. If an empty string is given as
153 * argument, all kinds of children will be considered.
154 *
155 * \param type The type of children we want to calculate the number.
156 *
157 * \return Number of children of type \a type.
158 */
159 size_t getChildrenCount(const std::string& type) const;
160
161 /*!
162 * \brief Returns all children of a certain type.
163 * \param[out] items The set of items founded.
164 * \param type The type of items that we are searching for.
165 */
166 void getChildren(std::vector<TreeItem*>& items, const std::string& type) const;
167
168 /*!
169 * \brief Tells us if the item has children or not.
170 *
171 * \return \a True if children list is not empty and false otherwise.
172 */
173 bool hasChildren() const;
174
175 /*!
176 * \brief Returns the label of the item to be presented in a Qt view.
177 *
178 * \return The item label, to be presented in a Qt view.
179 */
180 virtual std::string getAsString() const = 0;
181
182 /*!
183 * \brief Returns the position of item in its parent's list of children.
184 *
185 * \return The position of item in its parent's list of children.
186 */
188
189 /*!
190 * \brief Returns the visibilty state of the item.
191 *
192 * \return The state of visibilty of the item.
193 */
194 virtual VISIBLE isVisible() const;
195
196 /*!
197 * \brief Updates the visibilty state of the item.
198 *
199 * \param visible The new visibility state.
200 *
201 * \param updateAncestors Updates also ancestors states.
202 *
203 * \param updateDescendents Updates also descendents states.
204 */
205 virtual void setVisible(const VISIBLE& visible, const bool& updateAncestors = false, const bool& updateDescendents = false);
206
207 /*!
208 * \brief Returns the type of the item.
209 *
210 * \return Type of the item.
211 */
212 std::string getType() const;
213
214 /*!
215 * \brief Returns the item tooltip (for information purposes).
216 *
217 * \return The item tooltip.
218 */
219 virtual std::string getToolTip() const;
220
221 /*!
222 * \brief Removes all children.
223 */
225
226 /*!
227 * \brief Returns the flags to be used by the model.
228 *
229 * \return Qt flags. By default itens are enabled, editable and selectable. If you want to change the flags reimplement this method
230 * in a subclass.
231 */
232 virtual Qt::ItemFlags flags();
233
234 protected:
235
236 std::string m_type; //!< Item type.
237 std::unique_ptr<Queue> m_children; //!< Queue of items (children).
238 TreeItem* m_parent; //!< Pointer to the parent.
239 };
240 }
241 }
242}
243
244
245#endif //__TERRALIB_QT_WIDGETS_LAYER_INTERNAL_TREEITEM_H
Defines a hierarchical structure.
Definition: TreeItem.h:73
virtual void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
virtual void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
TreeItem * getParent() const
Returns the item parent.
virtual VISIBLE isVisible() const
Returns the visibilty state of the item.
std::string m_type
Item type.
Definition: TreeItem.h:236
void getChildren(std::vector< TreeItem * > &items, const std::string &type) const
Returns all children of a certain type.
virtual std::string getToolTip() const
Returns the item tooltip (for information purposes).
size_t getChildrenCount(const std::string &type) const
Returns the number of children.
std::string getType() const
Returns the type of the item.
TreeItem * removeChild(const size_t &pos)
Removes the child located at pos from the children list.
virtual Qt::ItemFlags flags()
Returns the flags to be used by the model.
std::unique_ptr< Queue > m_children
Queue of items (children).
Definition: TreeItem.h:237
virtual void insertChild(TreeItem *item, const size_t &pos)
Inserts a child item at the desired position.
TreeItem * m_parent
Pointer to the parent.
Definition: TreeItem.h:238
bool hasChildren() const
Tells us if the item has children or not.
TreeItem(const std::string &type)
Constructor.
virtual std::string getAsString() const =0
Returns the label of the item to be presented in a Qt view.
int getPosition()
Returns the position of item in its parent's list of children.
void setParent(TreeItem *item)
Updates the item parent.
virtual ~TreeItem()
Destructor.
TreeItem * getChild(const size_t &pos) const
Returns the child located at pos.
void removeAllChilds()
Removes all children.
VISIBLE
Defines the visibility of an item.
Definition: TreeItem.h:59
@ NONE
Not visible.
Definition: TreeItem.h:60
@ PARTIALLY
Partially visible.
Definition: TreeItem.h:62
@ TOTALLY
Visible.
Definition: TreeItem.h:61
te::common::QueueT< TreeItem * > Queue
Definition: TreeItem.h:51
TerraLib.
Struct that implements the generic queue.
Definition: GenericQueue.h:86
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63