Wt examples  4.10.0
Loading...
Searching...
No Matches
TreeNode.h
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7#ifndef TREENODE_H_
8#define TREENODE_H_
9
10#include <Wt/WCompositeWidget.h>
11#include <Wt/WText.h>
12
13class IconPair;
14
15using namespace Wt;
16
17namespace Wt {
18 class WTable;
19 class WImage;
20}
21
26
57class TreeNode : public WCompositeWidget
58{
59public:
70 TreeNode(const std::string labelText,
71 TextFormat labelFormat,
72 std::unique_ptr<IconPair> labelIcon);
73
76 void addChildNode(std::unique_ptr<TreeNode> node);
77
80 void removeChildNode(TreeNode *node, int index);
81
84 const std::vector<TreeNode *>& childNodes() const { return childNodes_; }
85
88 void collapse();
89
92 void expand();
93
94private:
96 std::vector<TreeNode *> childNodes_;
97
100
102 WTable *layout_;
103
106
109
112
115
117 WContainerWidget *expandedContent_;
118
120 void adjustExpandIcon();
121
123 bool isLastChildNode() const;
124
126 void childNodesChanged();
127
130
132 void undoCollapse();
133
135 void undoExpand();
136
138 enum ImageIndex { Middle = 0, Last = 1 };
139
140 static std::string imageLine_[];
141 static std::string imagePlus_[];
142 static std::string imageMin_[];
143}; //
144
147#endif // WTREENODE_H_
An icon pair (identical to WIconPair)
Definition IconPair.h:37
Example implementation of a single tree list node.
Definition TreeNode.h:58
void undoCollapse()
Undo function for prelearning collapse()
Definition TreeNode.C:144
void removeChildNode(TreeNode *node, int index)
Removes a child node.
Definition TreeNode.C:91
std::vector< TreeNode * > childNodes_
List of child nodes.
Definition TreeNode.h:96
void undoExpand()
Undo function for prelearning expand()
Definition TreeNode.C:155
void childNodesChanged()
Rerender when children have changed.
Definition TreeNode.C:102
static std::string imageLine_[]
Definition TreeNode.h:140
IconPair * expandIcon_
The icon for expanding or collapsing.
Definition TreeNode.h:105
bool wasCollapsed_
Was collapsed (for undo of prelearned collapse() and expand() slots.
Definition TreeNode.h:129
WTable * layout_
Layout (2x2 table).
Definition TreeNode.h:102
static std::string imagePlus_[]
Definition TreeNode.h:141
void collapse()
Collapses this node.
Definition TreeNode.C:118
bool isLastChildNode() const
Returns if is the last child within its parent (is rendered differently)
Definition TreeNode.C:73
WContainerWidget * expandedContent_
The container in which the children are managed.
Definition TreeNode.h:117
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
Definition TreeNode.h:84
ImageIndex
Two sets of images, for a normal node, and for the last node.
Definition TreeNode.h:138
WText * childCountLabel_
The children count '(x)' for x children.
Definition TreeNode.h:114
static std::string imageMin_[]
Definition TreeNode.h:142
void expand()
Expands this node.
Definition TreeNode.C:128
void addChildNode(std::unique_ptr< TreeNode > node)
Adds a child node.
Definition TreeNode.C:81
TreeNode * parentNode_
The parent node.
Definition TreeNode.h:99
void adjustExpandIcon()
Adjust the expand icon.
Definition TreeNode.C:172
IconPair * labelIcon_
The icon next to the label.
Definition TreeNode.h:111
WImage * noExpandIcon_
The single image shown instead of the expand/collapse icon when no children.
Definition TreeNode.h:108