This abstract class describes a basic item to be organized in a tree-oriented way. More...
#include <TreeItem.h>
Public Types | |
typedef std::list< TreeItemPtr > ::const_iterator | const_iterator |
typedef std::list< TreeItemPtr > ::iterator | iterator |
Public Member Functions | |
void | add (const TreeItemPtr &childItem) |
It adds (appends) the item to the end of the children's list. More... | |
void | attach () |
Increases the number of references to this object. More... | |
const_iterator | begin () const |
It returns the constant iterator associated to the first child of this item. More... | |
iterator | begin () |
It returns the iterator associated to the first child of this item. More... | |
void | detach () |
Decreases the number of references to this object. Destroy it if there are no more references to it. More... | |
void | disconnect () |
It disconnects this item from its parent, if it has one. More... | |
const_iterator | end () const |
It returns the constant iterator that refers to one past the end of the children of this item. More... | |
iterator | end () |
It returns the iterator that refers to one past the children of this item. More... | |
const TreeItemPtr & | getChild (std::size_t i) const |
It returns the n-th child. More... | |
const std::list< TreeItemPtr > & | getChildren () const |
It returns the children of this tree item. More... | |
std::size_t | getChildrenCount () const |
It returns the number of children of this node. More... | |
void | getDescendantsCount (std::size_t &count) const |
It returns the number of nodes that descends from this node. More... | |
std::size_t | getIndex () const |
It returns the index of this item in the list of children of its parent item. More... | |
TreeItem * | getParent () const |
It returns a pointer to the parent of this node. More... | |
bool | hasChildren () const |
It returns true if the item has descendants. More... | |
void | insert (std::size_t i, const TreeItemPtr &childItem) |
It inserts an item in the informed position. More... | |
bool | isSibling (const TreeItem *item) const |
It checks if the given layer is sibling of this one. More... | |
const TreeItemPtr & | operator[] (std::size_t i) const |
It returns the n-th child. More... | |
int | refCount () |
Returns the number of references to this object. More... | |
TreeItemPtr | remove (std::size_t i) |
It removes the i-th child. More... | |
std::list< TreeItemPtr > | remove (std::size_t i, std::size_t count) |
It removes from the given position a certain number of items as children of this item. The items to be removed will be disconnected from this item. More... | |
TreeItemPtr | replace (std::size_t i, const TreeItemPtr &childItem) |
It replaces the child item at the given position by the new one. The replaced item will be disconnected from this item. More... | |
void | swap (const TreeItemPtr &firstChild, const TreeItemPtr &secondChild) |
It swaps the position of the given children. More... | |
void | swap (const TreeItemPtr &sibling) |
It swaps this item with its sibling in their parent node. More... | |
TreeItem (TreeItem *parent=0) | |
It initializes a new item having a parent. More... | |
TreeItem (const TreeItemPtr &parent) | |
It initializes a new item having a parent. More... | |
virtual | ~TreeItem () |
Virtual destructor. More... | |
Static Public Attributes | |
static const std::size_t | npos |
A value to indicate no match. More... | |
Protected Member Functions | |
void | setParent (TreeItem *parent) |
It sets the parent of this item to the specified one. Don't use this method if you are not sure how to handle all the pointers involved in this operation. More... | |
Protected Attributes | |
std::list< TreeItemPtr > | m_children |
Pointers to the items that are children. More... | |
TreeItem * | m_parent |
A pointer to the parent node. More... | |
This abstract class describes a basic item to be organized in a tree-oriented way.
A tree item can have several descendants (children) and only one parent. This data structure will clear all the memory used by the items.
This implementation is based in the counted pattern, allowing to share the ownership of the items.
Definition at line 62 of file TreeItem.h.
typedef std::list<TreeItemPtr>::const_iterator te::common::TreeItem::const_iterator |
Definition at line 67 of file TreeItem.h.
typedef std::list<TreeItemPtr>::iterator te::common::TreeItem::iterator |
Definition at line 66 of file TreeItem.h.
|
explicit |
It initializes a new item having a parent.
Its parent will have this new item attached as its child automatically.
parent | The parent item of this new item. |
Definition at line 35 of file TreeItem.cpp.
References m_children, and m_parent.
|
explicit |
It initializes a new item having a parent.
Its parent will have this new item attached as its child automatically.
parent | The parent item of this new item. |
Definition at line 42 of file TreeItem.cpp.
|
virtual |
Virtual destructor.
Definition at line 48 of file TreeItem.cpp.
void te::common::TreeItem::add | ( | const TreeItemPtr & | childItem | ) |
It adds (appends) the item to the end of the children's list.
If the child item already has a parent, it will be disconnected from it and will be attached to this one.
childItem | The item to be added as a child of this item. |
The children's list will be increased with one element.
Definition at line 91 of file TreeItem.cpp.
|
inlineinherited |
Increases the number of references to this object.
Definition at line 88 of file Counted.h.
References te::common::Counted::m_refCount.
Referenced by te::common::intrusive_ptr_add_ref().
te::common::TreeItem::const_iterator te::common::TreeItem::begin | ( | ) | const |
It returns the constant iterator associated to the first child of this item.
Definition at line 266 of file TreeItem.cpp.
te::common::TreeItem::iterator te::common::TreeItem::begin | ( | ) |
It returns the iterator associated to the first child of this item.
Definition at line 271 of file TreeItem.cpp.
|
inlineinherited |
Decreases the number of references to this object. Destroy it if there are no more references to it.
Definition at line 93 of file Counted.h.
References te::common::Counted::m_refCount.
Referenced by te::common::intrusive_ptr_release().
void te::common::TreeItem::disconnect | ( | ) |
It disconnects this item from its parent, if it has one.
Definition at line 199 of file TreeItem.cpp.
te::common::TreeItem::const_iterator te::common::TreeItem::end | ( | ) | const |
It returns the constant iterator that refers to one past the end of the children of this item.
Definition at line 276 of file TreeItem.cpp.
te::common::TreeItem::iterator te::common::TreeItem::end | ( | ) |
It returns the iterator that refers to one past the children of this item.
Definition at line 281 of file TreeItem.cpp.
const te::common::TreeItemPtr & te::common::TreeItem::getChild | ( | std::size_t | i | ) | const |
It returns the n-th child.
i | The child index. |
Definition at line 75 of file TreeItem.cpp.
Referenced by te::qt::widgets::MapDisplay::draw(), FolderLayerWriter(), and te::map::AbstractLayer::updateVisibilityOfAncestors().
const std::list< te::common::TreeItemPtr > & te::common::TreeItem::getChildren | ( | ) | const |
It returns the children of this tree item.
Definition at line 70 of file TreeItem.cpp.
Referenced by te::qt::af::XMLFormatter::format().
std::size_t te::common::TreeItem::getChildrenCount | ( | ) | const |
It returns the number of children of this node.
Definition at line 183 of file TreeItem.cpp.
Referenced by te::qt::widgets::MapDisplay::draw(), FolderLayerWriter(), and te::map::AbstractLayer::updateVisibilityOfAncestors().
void te::common::TreeItem::getDescendantsCount | ( | std::size_t & | count | ) | const |
It returns the number of nodes that descends from this node.
count | The number of nodes that descends from this node. |
Definition at line 188 of file TreeItem.cpp.
std::size_t te::common::TreeItem::getIndex | ( | ) | const |
It returns the index of this item in the list of children of its parent item.
Definition at line 218 of file TreeItem.cpp.
te::common::TreeItem * te::common::TreeItem::getParent | ( | ) | const |
It returns a pointer to the parent of this node.
Definition at line 65 of file TreeItem.cpp.
Referenced by te::map::AbstractLayer::getAncestors(), isSibling(), and te::map::AbstractLayer::updateVisibilityOfAncestors().
bool te::common::TreeItem::hasChildren | ( | ) | const |
It returns true if the item has descendants.
Definition at line 60 of file TreeItem.cpp.
Referenced by te::map::AbstractLayer::getDescendants().
void te::common::TreeItem::insert | ( | std::size_t | i, |
const TreeItemPtr & | childItem | ||
) |
It inserts an item in the informed position.
If the item has a parent, it will be disconnected from it and will be attached to this one.
i | The position where the item will be inserted. |
item | The item to be inserted. |
The children's list will be increased with one element.
Definition at line 100 of file TreeItem.cpp.
bool te::common::TreeItem::isSibling | ( | const TreeItem * | item | ) | const |
It checks if the given layer is sibling of this one.
layer | The layer to be compared to. |
Definition at line 178 of file TreeItem.cpp.
References getParent().
const te::common::TreeItemPtr & te::common::TreeItem::operator[] | ( | std::size_t | i | ) | const |
It returns the n-th child.
i | The child index. |
Definition at line 86 of file TreeItem.cpp.
|
inlineinherited |
Returns the number of references to this object.
Definition at line 99 of file Counted.h.
References te::common::Counted::m_refCount.
te::common::TreeItemPtr te::common::TreeItem::remove | ( | std::size_t | i | ) |
It removes the i-th child.
i | The position of the item to be removed. |
The children's list will be decreased by one element.
Definition at line 116 of file TreeItem.cpp.
Referenced by te::qt::af::Project::remove(), and te::qt::widgets::LayerTreeModel::removeLayerFromParentChildrenList().
std::list< te::common::TreeItemPtr > te::common::TreeItem::remove | ( | std::size_t | i, |
std::size_t | count | ||
) |
It removes from the given position a certain number of items as children of this item. The items to be removed will be disconnected from this item.
i | The position from where the items will be removed. |
count | The number of items to be removed (> 0). |
Definition at line 135 of file TreeItem.cpp.
te::common::TreeItemPtr te::common::TreeItem::replace | ( | std::size_t | i, |
const TreeItemPtr & | childItem | ||
) |
It replaces the child item at the given position by the new one. The replaced item will be disconnected from this item.
i | The item position where the replace operation will be taken. |
childItem | The new child item that will replace the item in the i-th position. |
Definition at line 165 of file TreeItem.cpp.
References insert().
|
protected |
It sets the parent of this item to the specified one. Don't use this method if you are not sure how to handle all the pointers involved in this operation.
parent | The item to be set as parent of this item. |
Definition at line 286 of file TreeItem.cpp.
References m_children.
void te::common::TreeItem::swap | ( | const TreeItemPtr & | firstChild, |
const TreeItemPtr & | secondChild | ||
) |
It swaps the position of the given children.
firstChild | One of the children. |
secondChild | The other child. |
Definition at line 240 of file TreeItem.cpp.
void te::common::TreeItem::swap | ( | const TreeItemPtr & | sibling | ) |
It swaps this item with its sibling in their parent node.
sibling | The sibling to swap. |
Definition at line 259 of file TreeItem.cpp.
|
protected |
Pointers to the items that are children.
Definition at line 290 of file TreeItem.h.
Referenced by setParent(), and TreeItem().
|
protected |
|
static |
A value to indicate no match.
Definition at line 285 of file TreeItem.h.