TreeNode Class Reference
[Treelist example]

Example implementation of a single tree list node. More...

#include <TreeNode.h>

Inheritance diagram for TreeNode:

Inheritance graph
[legend]

List of all members.

Public Slots

void collapse ()
 Collapse this node.
void expand ()
 Expand this node.

Public Member Functions

 TreeNode (const std::wstring labelText, Wt::WText::Formatting labelFormatting, IconPair *labelIcon, Wt::WContainerWidget *parent=0)
 Construct a tree node with the given label.
void addChildNode (TreeNode *node)
 Add a child node.
void removeChildNode (TreeNode *node)
 Remove a child node.
const std::vector
< TreeNode * > & 
childNodes () const
 Get the list of children.

Private Types

enum  ImageIndex { Middle = 0, Last = 1 }
 Two sets of images, for a normal node, and for the last node. More...

Private Member Functions

void adjustExpandIcon ()
 Adjust the expand icon.
bool isLastChildNode () const
 Returns if is the last child within its parent (is rendered differently).
void childNodesChanged ()
 Rerender when children have changed.
void undoCollapse ()
 Undo function for prelearning collapse().
void undoExpand ()
 Undo function for prelearning expand().

Private Attributes

std::vector< TreeNode * > childNodes_
 List of child nodes.
TreeNodeparentNode_
 The parent node.
Wt::WTablelayout_
 Layout (2x2 table).
IconPairexpandIcon_
 The icon for expanding or collapsing.
Wt::WImagenoExpandIcon_
 The single image shown instead of the expand/collapse icon when no children.
IconPairlabelIcon_
 The icon next to the label.
Wt::WTextlabelText_
 The label.
Wt::WTextchildCountLabel_
 The children count '(x)' for x children.
Wt::WContainerWidgetexpandedContent_
 The container in which the children are managed.
bool wasCollapsed_
 Was collapsed (for undo of prelearned collapse() and expand() slots.

Static Private Attributes

static std::string imageLine_ []
static std::string imagePlus_ []
static std::string imageMin_ []


Detailed Description

Example implementation of a single tree list node.

This is an example of a basic treelist implementation. As of version 1.1.8, a more flexible treenode implementation is included as part of the library: WTreeNode.

A tree list is constructed by nesting TreeNode objects in a tree hierarchy.

A TreeNode has a label, and optionally a two-state label icon, which defines a different image depending on the state of the node (expanded or collapsed). When the node has any children, a child count is also indicated.

Next to the icons, two style classes determine the look of a TreeNode: the label has style "treenodelabel", and the child count has as style "treenodechildcount".

Use CSS nested selectors to apply different styles to different treenodes. For example, to style the treenode with style class "mynode":

The behaviour of the tree node is to collapse all children when the node is expanded (this is similar to how most tree node implementations work).

The widget uses a number of images which must be available in an "icons/" folder (see the Wt treelist examples).

This widget is part of the Wt treelist example.

Definition at line 55 of file TreeNode.h.


Member Enumeration Documentation

enum TreeNode::ImageIndex [private]

Two sets of images, for a normal node, and for the last node.

Enumerator:
Middle 
Last 

Definition at line 140 of file TreeNode.h.


Constructor & Destructor Documentation

TreeNode::TreeNode ( const std::wstring  labelText,
Wt::WText::Formatting  labelFormatting,
IconPair labelIcon,
Wt::WContainerWidget parent = 0 
)

Construct a tree node with the given label.

The label is formatted in a WText with the given formatting. The labelIcon (if not 0) will appear next to the label and its state will reflect the expand/collapse state of the node.

Optionally, a userContent widget may be associated with the node. When expanded, this widget will be shown below the widget, but above any of the children nodes.

Definition at line 25 of file TreeNode.C.


Member Function Documentation

void TreeNode::addChildNode ( TreeNode node  ) 

Add a child node.

Definition at line 85 of file TreeNode.C.

void TreeNode::removeChildNode ( TreeNode node  ) 

Remove a child node.

Definition at line 95 of file TreeNode.C.

const std::vector<TreeNode *>& TreeNode::childNodes (  )  const [inline]

Get the list of children.

Definition at line 82 of file TreeNode.h.

void TreeNode::collapse (  )  [slot]

Collapse this node.

Definition at line 123 of file TreeNode.C.

void TreeNode::expand (  )  [slot]

Expand this node.

Definition at line 133 of file TreeNode.C.

void TreeNode::adjustExpandIcon (  )  [private]

Adjust the expand icon.

Definition at line 177 of file TreeNode.C.

bool TreeNode::isLastChildNode (  )  const [private]

Returns if is the last child within its parent (is rendered differently).

Definition at line 77 of file TreeNode.C.

void TreeNode::childNodesChanged (  )  [private]

Rerender when children have changed.

Definition at line 106 of file TreeNode.C.

void TreeNode::undoCollapse (  )  [private]

Undo function for prelearning collapse().

Definition at line 149 of file TreeNode.C.

void TreeNode::undoExpand (  )  [private]

Undo function for prelearning expand().

Definition at line 160 of file TreeNode.C.


Member Data Documentation

std::vector<TreeNode *> TreeNode::childNodes_ [private]

List of child nodes.

Definition at line 95 of file TreeNode.h.

TreeNode* TreeNode::parentNode_ [private]

The parent node.

Definition at line 98 of file TreeNode.h.

Wt::WTable* TreeNode::layout_ [private]

Layout (2x2 table).

Definition at line 101 of file TreeNode.h.

IconPair* TreeNode::expandIcon_ [private]

The icon for expanding or collapsing.

Definition at line 104 of file TreeNode.h.

Wt::WImage* TreeNode::noExpandIcon_ [private]

The single image shown instead of the expand/collapse icon when no children.

Definition at line 107 of file TreeNode.h.

IconPair* TreeNode::labelIcon_ [private]

The icon next to the label.

Definition at line 110 of file TreeNode.h.

Wt::WText* TreeNode::labelText_ [private]

The label.

Definition at line 113 of file TreeNode.h.

Wt::WText* TreeNode::childCountLabel_ [private]

The children count '(x)' for x children.

Definition at line 116 of file TreeNode.h.

Wt::WContainerWidget* TreeNode::expandedContent_ [private]

The container in which the children are managed.

Definition at line 119 of file TreeNode.h.

bool TreeNode::wasCollapsed_ [private]

Was collapsed (for undo of prelearned collapse() and expand() slots.

Definition at line 131 of file TreeNode.h.

std::string TreeNode::imageLine_ [static, private]

Initial value:

 { "icons/line-middle.gif",
                                        "icons/line-last.gif" }

Definition at line 142 of file TreeNode.h.

std::string TreeNode::imagePlus_ [static, private]

Initial value:

 { "icons/nav-plus-line-middle.gif",
                                        "icons/nav-plus-line-last.gif" }

Definition at line 143 of file TreeNode.h.

std::string TreeNode::imageMin_ [static, private]

Initial value:

 { "icons/nav-minus-line-middle.gif",
                                       "icons/nav-minus-line-last.gif" }

Definition at line 144 of file TreeNode.h.


The documentation for this class was generated from the following files:
Generated on Fri Jul 25 17:06:04 2008 for Wt by doxygen 1.5.3