Wt examples
3.7.1
|
Example implementation of a single tree list node. More...
#include <TreeNode.h>
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. More... | |
void | addChildNode (TreeNode *node) |
Adds a child node. More... | |
void | removeChildNode (TreeNode *node) |
Removes a child node. More... | |
const std::vector< TreeNode * > & | childNodes () const |
Returns the list of children. More... | |
void | collapse () |
Collapses this node. More... | |
void | expand () |
Expands this node. More... | |
![]() | |
WCompositeWidget () | |
WCompositeWidget (std::unique_ptr< WWidget > implementation) | |
virtual std::vector< WWidget *> | children () const override |
virtual std::unique_ptr< WWidget > | removeWidget (WWidget *widget) override |
virtual void | setObjectName (const std::string &name) override |
virtual std::string | objectName () const override |
virtual const std::string | id () const override |
virtual void | setPositionScheme (PositionScheme scheme) override |
virtual PositionScheme | positionScheme () const override |
virtual void | setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override |
virtual WLength | offset (Side s) const override |
virtual void | resize (const WLength &width, const WLength &height) override |
virtual WLength | width () const override |
virtual WLength | height () const override |
virtual void | setMinimumSize (const WLength &width, const WLength &height) override |
virtual WLength | minimumWidth () const override |
virtual WLength | minimumHeight () const override |
virtual void | setMaximumSize (const WLength &width, const WLength &height) override |
virtual WLength | maximumWidth () const override |
virtual WLength | maximumHeight () const override |
virtual void | setLineHeight (const WLength &height) override |
virtual WLength | lineHeight () const override |
virtual void | setFloatSide (Side s) override |
virtual Side | floatSide () const override |
virtual void | setClearSides (WFlags< Side > sides) override |
virtual WFlags< Side > | clearSides () const override |
virtual void | setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override |
virtual WLength | margin (Side side) const override |
virtual void | setHiddenKeepsGeometry (bool enabled) override |
virtual bool | hiddenKeepsGeometry () const override |
virtual void | setHidden (bool hidden, const WAnimation &animation=WAnimation()) override |
virtual bool | isHidden () const override |
virtual bool | isVisible () const override |
virtual void | setDisabled (bool disabled) override |
virtual bool | isDisabled () const override |
virtual bool | isEnabled () const override |
virtual void | setPopup (bool popup) override |
virtual bool | isPopup () const override |
virtual void | setInline (bool isInline) override |
virtual bool | isInline () const override |
virtual void | setDecorationStyle (const WCssDecorationStyle &style) override |
virtual WCssDecorationStyle & | decorationStyle () override |
virtual void | setStyleClass (const WString &styleClass) override |
virtual WString | styleClass () const override |
virtual void | addStyleClass (const WString &styleClass, bool force=false) override |
virtual void | removeStyleClass (const WString &styleClass, bool force=false) override |
virtual bool | hasStyleClass (const WString &styleClass) const override |
virtual void | setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto) override |
virtual AlignmentFlag | verticalAlignment () const override |
virtual WLength | verticalAlignmentLength () const override |
virtual void | setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override |
virtual WString | toolTip () const override |
virtual void | setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override |
virtual void | refresh () override |
virtual void | setAttributeValue (const std::string &name, const WString &value) override |
virtual WString | attributeValue (const std::string &name) const override |
virtual void | setJavaScriptMember (const std::string &name, const std::string &value) override |
virtual std::string | javaScriptMember (const std::string &name) const override |
virtual void | callJavaScriptMember (const std::string &name, const std::string &args) override |
virtual void | load () override |
virtual bool | loaded () const override |
virtual void | setCanReceiveFocus (bool enabled) override |
virtual bool | canReceiveFocus () const override |
virtual void | setFocus (bool focus) override |
virtual bool | setFirstFocus () override |
virtual bool | hasFocus () const override |
virtual void | setTabIndex (int index) override |
virtual int | tabIndex () const override |
virtual void | setId (const std::string &id) override |
virtual WWidget * | find (const std::string &name) override |
virtual WWidget * | findById (const std::string &name) override |
virtual void | setSelectable (bool selectable) override |
virtual void | doJavaScript (const std::string &js) override |
virtual void | propagateSetEnabled (bool enabled) override |
virtual bool | scrollVisibilityEnabled () const final override |
virtual void | setScrollVisibilityEnabled (bool enabled) final override |
virtual int | scrollVisibilityMargin () const final override |
virtual void | setScrollVisibilityMargin (int margin) final override |
virtual Signal< bool > & | scrollVisibilityChanged () final override |
virtual bool | isScrollVisible () const final override |
virtual void | setThemeStyleEnabled (bool enabled) final override |
virtual bool | isThemeStyleEnabled () const final override |
![]() | |
virtual | ~WWidget () |
WWidget * | parent () const |
std::unique_ptr< Widget > | removeWidget (Widget *widget) |
std::unique_ptr< WWidget > | removeFromParent () |
void | setWidth (const WLength &width) |
void | setHeight (const WLength &height) |
virtual void | positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical) |
virtual void | toggleStyleClass (const WString &styleClass, bool add, bool force=false) |
std::string | jsRef () const |
void | setFocus () |
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 |
![]() | |
void | addChild (std::unique_ptr< WObject > child) |
Child * | addChild (std::unique_ptr< Child > child) |
std::unique_ptr< WObject > | removeChild (WObject *child) |
std::unique_ptr< Child > | removeChild (Child *child) |
void | resetLearnedSlots () |
void | resetLearnedSlot (void(T::*method)()) |
WStatelessSlot * | implementStateless (void(T::*method)()) |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
void | isNotStateless () |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
![]() | |
observable () noexcept | |
virtual | ~observable () |
auto | bindSafe (void(C::*method)(Args...)) noexcept |
auto | bindSafe (void(C::*method)(Args...) const) const noexcept |
auto | bindSafe (const Function &function) noexcept |
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. More... | |
bool | isLastChildNode () const |
Returns if is the last child within its parent (is rendered differently) More... | |
void | childNodesChanged () |
Rerender when children have changed. More... | |
void | undoCollapse () |
Undo function for prelearning collapse() More... | |
void | undoExpand () |
Undo function for prelearning expand() More... | |
Private Attributes | |
std::vector< TreeNode * > | childNodes_ |
List of child nodes. More... | |
TreeNode * | parentNode_ |
The parent node. More... | |
Wt::WTable * | layout_ |
Layout (2x2 table). More... | |
IconPair * | expandIcon_ |
The icon for expanding or collapsing. More... | |
Wt::WImage * | noExpandIcon_ |
The single image shown instead of the expand/collapse icon when no children. More... | |
IconPair * | labelIcon_ |
The icon next to the label. More... | |
Wt::WText * | labelText_ |
The label. More... | |
Wt::WText * | childCountLabel_ |
The children count '(x)' for x children. More... | |
Wt::WContainerWidget * | expandedContent_ |
The container in which the children are managed. More... | |
bool | wasCollapsed_ |
Was collapsed (for undo of prelearned collapse() and expand() slots. More... | |
Static Private Attributes | |
static std::string | imageLine_ [] |
static std::string | imagePlus_ [] |
static std::string | imageMin_ [] |
Additional Inherited Members | |
![]() | |
typedef void(WObject::* | Method) () |
![]() | |
static WString | tr (const char *key) |
![]() | |
virtual void | enableAjax () override |
void | setImplementation (std::unique_ptr< WWidget > widget) |
Widget * | setImplementation (std::unique_ptr< Widget > widget) |
W * | setNewImplementation (Args &&... args) |
WWidget * | implementation () |
virtual int | boxPadding (Orientation orientation) const override |
virtual int | boxBorder (Orientation orientation) const override |
virtual void | render (WFlags< RenderFlag > flags) override |
![]() | |
void | setLayoutSizeAware (bool sizeAware) |
virtual void | layoutSizeChanged (int width, int height) |
WWidget () | |
virtual void | dropEvent (WDropEvent dropEvent) |
void | scheduleRender (WFlags< RepaintFlag > flags=None) |
virtual WStatelessSlot * | getStateless (Method method) override |
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.
|
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.
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.
void TreeNode::addChildNode | ( | TreeNode * | node | ) |
Adds a child node.
Definition at line 86 of file TreeNode.C.
|
private |
Adjust the expand icon.
Definition at line 178 of file TreeNode.C.
|
inline |
Returns the list of children.
Definition at line 82 of file TreeNode.h.
|
private |
Rerender when children have changed.
Definition at line 107 of file TreeNode.C.
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.
|
private |
Returns if is the last child within its parent (is rendered differently)
Definition at line 78 of file TreeNode.C.
void TreeNode::removeChildNode | ( | TreeNode * | node | ) |
Removes a child node.
Definition at line 96 of file TreeNode.C.
|
private |
Undo function for prelearning collapse()
Definition at line 150 of file TreeNode.C.
|
private |
Undo function for prelearning expand()
Definition at line 161 of file TreeNode.C.
|
private |
The children count '(x)' for x children.
Definition at line 115 of file TreeNode.h.
|
private |
List of child nodes.
Definition at line 94 of file TreeNode.h.
|
private |
The container in which the children are managed.
Definition at line 118 of file TreeNode.h.
|
private |
The icon for expanding or collapsing.
Definition at line 103 of file TreeNode.h.
|
staticprivate |
Definition at line 141 of file TreeNode.h.
|
staticprivate |
Definition at line 143 of file TreeNode.h.
|
staticprivate |
Definition at line 142 of file TreeNode.h.
|
private |
The icon next to the label.
Definition at line 109 of file TreeNode.h.
|
private |
The label.
Definition at line 112 of file TreeNode.h.
|
private |
Layout (2x2 table).
Definition at line 100 of file TreeNode.h.
|
private |
The single image shown instead of the expand/collapse icon when no children.
Definition at line 106 of file TreeNode.h.
|
private |
The parent node.
Definition at line 97 of file TreeNode.h.
|
private |
Was collapsed (for undo of prelearned collapse() and expand() slots.
Definition at line 130 of file TreeNode.h.