A string object that is displayable in a tree structure. A node can have children, see methods children(), open(), and close(). More...
#include <treeviewer.h>
Public Types | |
typedef std::list< TreeViewerNode > | ChildrenList |
Holds children. | |
typedef std::vector< std::pair < TreeViewerNode *, int > > | FlatForm |
Holds child*'s and depth. | |
Public Member Functions | |
TreeViewerNode & | addChild (std::string const &name) |
Take ownership of a new tree viewer node. Append it to the list of children. | |
void | adoptInfo (TreeViewerNodeInfo *p) |
Take ownership of node info. Delete any previous node info. | |
ChildrenList & | children () |
List of child nodes. | |
ChildrenList const & | children () const |
List of child nodes. | |
void | close (bool childrenToo=true) |
Mark this and optionally all child nodes as closed. | |
void | flatten (FlatForm &output, int depth=0) |
Appends this node to a flattend version of the TreeViewerNode structure. A flat version does not contain the nested tree structure, per se, but does have an indication of the depth of the nodes in the tree to aid in the display thereof. | |
bool | hasChildren () const |
Return true if this node has children. | |
virtual int | height () const |
Get height of self plus children. | |
bool | highlighted () const |
TreeViewerNodeInfo * | info () |
Return any user supplied information associated with this node. | |
std::string const & | name () const |
Get this node's name. | |
void | open (bool childrenToo=true) |
Mark this and optionally all child nodes as closed. | |
bool | opened () const |
Return true if the children should be displayed. | |
void | setHighlighted () |
Force this node to be displayed in highlighted text. | |
void | setName (std::string const &n) |
Set the node name. | |
TreeViewerNode () | |
TreeViewerNode (std::string const &name) | |
virtual | ~TreeViewerNode () |
Private Attributes | |
ChildrenList | children_ |
bool | highlighted_ |
TreeViewerNodeInfo * | info_ |
std::string | name_ |
bool | opened_ |
A string object that is displayable in a tree structure. A node can have children, see methods children(), open(), and close().
There is no flag in the data that indicates what kind of tree viewer node you have, but you can use dynamic cast to see if a given node is a container or not.
Upon destruction, the children are also deleted.
Note that no child in the children list will be null (unless there is a major bug).
TreeViewerNodes are meant for raw data storage and do not have features needed to animate the nodes on the screen.
The nodes can have associated information that can be used to perform command handling. See adoptInfo() below and TreeViewerNodeInfo above.
Definition at line 69 of file treeviewer.h.
typedef std::list<TreeViewerNode> ChildrenList |
Holds children.
Definition at line 90 of file treeviewer.h.
typedef std::vector<std::pair<TreeViewerNode*, int> > FlatForm |
Holds child*'s and depth.
Definition at line 91 of file treeviewer.h.
TreeViewerNode | ( | std::string const & | name | ) |
Definition at line 296 of file treeviewer.h.
TreeViewerNode | ( | ) |
Definition at line 307 of file treeviewer.h.
~TreeViewerNode | ( | ) | [virtual] |
Definition at line 429 of file treeviewer.h.
TreeViewerNode & addChild | ( | std::string const & | name | ) |
Take ownership of a new tree viewer node. Append it to the list of children.
Definition at line 339 of file treeviewer.h.
void adoptInfo | ( | TreeViewerNodeInfo * | p | ) |
Take ownership of node info. Delete any previous node info.
Definition at line 417 of file treeviewer.h.
TreeViewerNode::ChildrenList & children | ( | ) |
List of child nodes.
Definition at line 357 of file treeviewer.h.
TreeViewerNode::ChildrenList const & children | ( | ) | const |
List of child nodes.
Definition at line 349 of file treeviewer.h.
void close | ( | bool | childrenToo = true |
) |
Mark this and optionally all child nodes as closed.
Definition at line 66 of file treeviewer.cxx.
void flatten | ( | FlatForm & | output, | |
int | depth = 0 | |||
) |
Appends this node to a flattend version of the TreeViewerNode structure. A flat version does not contain the nested tree structure, per se, but does have an indication of the depth of the nodes in the tree to aid in the display thereof.
Definition at line 109 of file treeviewer.cxx.
bool hasChildren | ( | ) | const |
Return true if this node has children.
Definition at line 367 of file treeviewer.h.
int height | ( | ) | const [virtual] |
Get height of self plus children.
Definition at line 46 of file treeviewer.cxx.
bool highlighted | ( | ) | const |
Definition at line 145 of file treeviewer.h.
TreeViewerNodeInfo * info | ( | ) |
Return any user supplied information associated with this node.
Definition at line 441 of file treeviewer.h.
std::string const & name | ( | ) | const |
Get this node's name.
Definition at line 329 of file treeviewer.h.
void open | ( | bool | childrenToo = true |
) |
Mark this and optionally all child nodes as closed.
Definition at line 88 of file treeviewer.cxx.
bool opened | ( | ) | const |
Return true if the children should be displayed.
Definition at line 377 of file treeviewer.h.
void setHighlighted | ( | ) |
Force this node to be displayed in highlighted text.
Definition at line 470 of file treeviewer.h.
void setName | ( | std::string const & | n | ) |
Set the node name.
Definition at line 319 of file treeviewer.h.
ChildrenList children_ [private] |
Definition at line 95 of file treeviewer.h.
bool highlighted_ [private] |
Definition at line 104 of file treeviewer.h.
TreeViewerNodeInfo* info_ [private] |
Definition at line 102 of file treeviewer.h.
std::string name_ [private] |
Definition at line 100 of file treeviewer.h.
bool opened_ [private] |
Definition at line 97 of file treeviewer.h.