Wt 3.1.10
Public Types | Public Member Functions
Wt::WTree Class Reference

A widget that represents a navigatable tree. More...

#include <Wt/WTree>

Inheritance diagram for Wt::WTree:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::set< WTreeNode * > WTreeNodeSet
 Typedef for a set of WTreeNode's.

Public Member Functions

 WTree (WContainerWidget *parent=0)
 Creates a new tree.
void setTreeRoot (WTreeNode *root)
 Sets the tree root node.
WTreeNodetreeRoot () const
 Returns the root node.
void setSelectionMode (SelectionMode mode)
 Sets the selection mode.
SelectionMode selectionMode () const
 Returns the selection mode.
const WTreeNodeSetselectedNodes () const
 Returns the set of selected tree nodes.
void select (const WTreeNodeSet &nodes)
 Sets a selection of tree nodes.
void select (WTreeNode *node, bool selected=true)
 Selects or unselect the given node.
bool isSelected (WTreeNode *node) const
 Returns if the given node is currently selected.
void clearSelection ()
 Clears the current selection.
SignalitemSelectionChanged ()
 Signal that is emitted when the selection changes.

Detailed Description

A widget that represents a navigatable tree.

WTree provides a tree widget, and coordinates selection functionality.

Unlike the MVC-based WTreeView, the tree renders a widget hierarchy, rather than a hierarhical standard model. This provides extra flexibility (as any widget can be used as contents), at the cost of server-side, client-side and bandwidth resources (especially for large tree tables).

The tree is implemented as a hierarchy of WTreeNode widgets.

Selection is rendered by calling WTreeNode::renderSelected(bool). Only tree nodes that are selectable may participate in the selection.

Usage example:

 Wt::WIconPair *folderIcon = new Wt::WIconPair("icons/yellow-folder-closed.png",
                                               "icons/yellow-folder-open.png", false);

 Wt::WTree *tree = new Wt::WTree();
 tree->setSelectionMode(Wt::SingleSelection);

 Wt::WTreeNode *root = new Wt::WTreeNode("Tree root", folderIcon);
 root->setStyleClass("example-tree");
 tree->setTreeRoot(root);
 root->label()->setTextFormat(Wt::PlainText);
 root->setImagePack("resources/");
 root->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
 root->addChildNode(new Wt::WTreeNode("one"));
 root->addChildNode(new Wt::WTreeNode("two"));

 Wt::WTreeNode *three = new Wt::WTreeNode("three");
 three->addChildNode(new WTreeNode("three: one"));
 three->addChildNode(new WTreeNode("three: two"));
 root->addChildNode(three);

 root->expand();

CSS

The tree is styled by the current CSS theme. The look can be overridden using the Wt-tree CSS class. The style selectors that affect the rendering of the decoration of the nodes are indicated in the documentation for WTreeNode. In addition, the following selector may be used to style the header:

.Wt-tree .Wt-selected : selected item

A screenshot of the tree:

WTree-default-1.png
An example WTree (default)
WTree-polished-1.png
An example WTree (polished)
See also:
WTreeNode, WTreeTable, WTreeView

Member Function Documentation

void Wt::WTree::setSelectionMode ( SelectionMode  mode)

Sets the selection mode.

The default selection mode is Wt::NoSelection.

void Wt::WTree::setTreeRoot ( WTreeNode root)

Sets the tree root node.

See also:
treeRoot()
WTreeNode* Wt::WTree::treeRoot ( ) const

Returns the root node.

See also:
setTreeRoot(WTreeNode *)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Sat Dec 24 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4