Wt examples  3.2.1
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
TreeNode Class Reference

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

#include <TreeNode.h>

Inheritance diagram for TreeNode:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 TreeNode (const std::string labelText, Wt::TextFormat labelFormat, IconPair *labelIcon, Wt::WContainerWidget *parent=0)
 Construct a tree node with the given label.
void addChildNode (TreeNode *node)
 Adds a child node.
void removeChildNode (TreeNode *node)
 Removes a child node.
const std::vector< TreeNode * > & childNodes () const
 Returns the list of children.
void collapse ()
 Collapses this node.
void expand ()
 Expands this node.
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget (WContainerWidget *parent=0)
 WCompositeWidget (WWidget *implementation, WContainerWidget *parent)
virtual const std::string id () const
virtual void setPositionScheme (PositionScheme scheme)
virtual PositionScheme positionScheme () const
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
virtual WLength offset (Side s) const
virtual void resize (const WLength &width, const WLength &height)
virtual WLength width () const
virtual WLength height () const
virtual void setMinimumSize (const WLength &width, const WLength &height)
virtual WLength minimumWidth () const
virtual WLength minimumHeight () const
virtual void setMaximumSize (const WLength &width, const WLength &height)
virtual WLength maximumWidth () const
virtual WLength maximumHeight () const
virtual void setLineHeight (const WLength &height)
virtual WLength lineHeight () const
virtual void setFloatSide (Side s)
virtual Side floatSide () const
virtual void setClearSides (WFlags< Side > sides)
virtual WFlags< SideclearSides () const
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
virtual WLength margin (Side side) const
virtual void setHiddenKeepsGeometry (bool enabled)
virtual bool hiddenKeepsGeometry () const
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
virtual bool isHidden () const
virtual bool isVisible () const
virtual void setDisabled (bool disabled)
virtual bool isDisabled () const
virtual bool isEnabled () const
virtual void setPopup (bool popup)
virtual bool isPopup () const
virtual void setInline (bool isInline)
virtual bool isInline () const
virtual void setDecorationStyle (const WCssDecorationStyle &style)
virtual WCssDecorationStyledecorationStyle ()
virtual void setStyleClass (const WString &styleClass)
virtual WString styleClass () const
virtual void addStyleClass (const WString &styleClass, bool force=false)
virtual void removeStyleClass (const WString &styleClass, bool force=false)
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto)
virtual AlignmentFlag verticalAlignment () const
virtual WLength verticalAlignmentLength () const
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
virtual WString toolTip () const
virtual void refresh ()
virtual void setAttributeValue (const std::string &name, const WString &value)
virtual WString attributeValue (const std::string &name) const
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
virtual std::string javaScriptMember (const std::string &name) const
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
virtual void load ()
virtual bool loaded () const
virtual void setTabIndex (int index)
virtual int tabIndex () const
virtual void setId (const std::string &id)
virtual WWidgetfind (const std::string &name)
virtual void setSelectable (bool selectable)
virtual void doJavaScript (const std::string &js)
virtual void propagateSetEnabled (bool enabled)
virtual ~WWidget ()
WWidgetparent () const
void setWidth (const WLength &width)
void setHeight (const WLength &height)
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
std::string jsRef () const
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
virtual void stopAcceptDrops (const std::string &mimeType)
virtual void htmlText (std::ostream &out)
bool isRendered () const
void hide ()
void animateHide (const WAnimation &animation)
void show ()
void animateShow (const WAnimation &animation)
void enable ()
void disable ()
bool layoutSizeAware () const
 WObject (WObject *parent=0)
virtual ~WObject ()
void setObjectName (const std::string &name)
virtual std::string objectName () const
void resetLearnedSlots ()
void resetLearnedSlot (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)
virtual void removeChild (WObject *child)
const std::vector< WObject * > & children () const

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_ []

Additional Inherited Members

- Static Public Member Functions inherited from Wt::WCompositeWidget
static WString tr (const char *key)
- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax ()
void setImplementation (WWidget *widget)
WWidgetimplementation ()
virtual int boxPadding (Orientation orientation) const
virtual int boxBorder (Orientation orientation) const
void setLayoutSizeAware (bool sizeAware)
virtual void layoutSizeChanged (int width, int height)
 WWidget (WContainerWidget *parent=0)
virtual void dropEvent (WDropEvent dropEvent)
virtual WStatelessSlot * getStateless (Method method)

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 139 of file TreeNode.h.

{ Middle = 0, Last = 1 };

Constructor & Destructor Documentation

TreeNode::TreeNode ( const std::string  labelText,
Wt::TextFormat  labelFormat,
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 26 of file TreeNode.C.

labelIcon_(labelIcon)
{
// pre-learned stateless implementations ...
// ... or auto-learned stateless implementations
// which do not need undo functions
//implementStateless(&TreeNode::expand);
//implementStateless(&TreeNode::collapse);
labelText_ = new Wt::WText(labelText);
labelText_->setTextFormat(labelFormat);
labelText_->setStyleClass("treenodelabel");
childCountLabel_->setStyleClass("treenodechildcount");
if (labelIcon_) {
}
} //

Member Function Documentation

void TreeNode::addChildNode ( TreeNode node)

Adds a child node.

Definition at line 86 of file TreeNode.C.

{
childNodes_.push_back(node);
node->parentNode_ = this;
}
void TreeNode::adjustExpandIcon ( )
private

Adjust the expand icon.

Definition at line 178 of file TreeNode.C.

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

Returns the list of children.

Definition at line 82 of file TreeNode.h.

{ return childNodes_; }
void TreeNode::childNodesChanged ( )
private

Rerender when children have changed.

Definition at line 107 of file TreeNode.C.

{
for (unsigned i = 0; i < childNodes_.size(); ++i)
if (childNodes_.size())
->setText("(" + boost::lexical_cast<std::string>(childNodes_.size())
+ ")");
else
} //
void TreeNode::collapse ( )

Collapses this node.

Definition at line 124 of file TreeNode.C.

void TreeNode::expand ( )

Expands this node.

Definition at line 134 of file TreeNode.C.

{
/*
* collapse all children
*/
for (unsigned i = 0; i < childNodes_.size(); ++i)
} //
bool TreeNode::isLastChildNode ( ) const
private

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

Definition at line 78 of file TreeNode.C.

{
if (parentNode_) {
return parentNode_->childNodes_.back() == this;
} else
return true;
}
void TreeNode::removeChildNode ( TreeNode node)

Removes a child node.

Definition at line 96 of file TreeNode.C.

{
childNodes_.erase(std::find(childNodes_.begin(), childNodes_.end(), node));
node->parentNode_ = 0;
} //
void TreeNode::undoCollapse ( )
private

Undo function for prelearning collapse()

Definition at line 150 of file TreeNode.C.

{
if (!wasCollapsed_) {
// re-expand
}
}
void TreeNode::undoExpand ( )
private

Undo function for prelearning expand()

Definition at line 161 of file TreeNode.C.

{
// re-collapse
}
/*
* undo collapse of children
*/
for (unsigned i = 0; i < childNodes_.size(); ++i)
} //

Member Data Documentation

Wt::WText* TreeNode::childCountLabel_
private

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

Definition at line 115 of file TreeNode.h.

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

List of child nodes.

Definition at line 94 of file TreeNode.h.

Wt::WContainerWidget* TreeNode::expandedContent_
private

The container in which the children are managed.

Definition at line 118 of file TreeNode.h.

IconPair* TreeNode::expandIcon_
private

The icon for expanding or collapsing.

Definition at line 103 of file TreeNode.h.

std::string TreeNode::imageLine_
staticprivate
Initial value:
{ "icons/line-middle.gif",
"icons/line-last.gif" }

Definition at line 141 of file TreeNode.h.

std::string TreeNode::imageMin_
staticprivate
Initial value:
{ "icons/nav-minus-line-middle.gif",
"icons/nav-minus-line-last.gif" }

Definition at line 143 of file TreeNode.h.

std::string TreeNode::imagePlus_
staticprivate
Initial value:
{ "icons/nav-plus-line-middle.gif",
"icons/nav-plus-line-last.gif" }

Definition at line 142 of file TreeNode.h.

IconPair* TreeNode::labelIcon_
private

The icon next to the label.

Definition at line 109 of file TreeNode.h.

Wt::WText* TreeNode::labelText_
private

The label.

Definition at line 112 of file TreeNode.h.

Wt::WTable* TreeNode::layout_
private

Layout (2x2 table).

Definition at line 100 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 106 of file TreeNode.h.

TreeNode* TreeNode::parentNode_
private

The parent node.

Definition at line 97 of file TreeNode.h.

bool TreeNode::wasCollapsed_
private

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

Definition at line 130 of file TreeNode.h.


The documentation for this class was generated from the following files:

Generated on Mon May 28 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1