8 #include <Wt/WTableCell.h> 11 #include <Wt/WCssDecorationStyle.h> 20 "icons/line-last.gif" };
22 "icons/nav-plus-line-last.gif" };
24 "icons/nav-minus-line-last.gif" };
28 std::unique_ptr<IconPair> labelIcon)
31 labelIcon_(labelIcon.get())
42 auto layout = cpp14::make_unique<WTable>();
56 auto expandedContent = cpp14::make_unique<WContainerWidget>();
58 expandedContent_->
hide();
60 labelText_ = cpp14::make_unique<WText>(labelText);
64 auto childCountLabel = cpp14::make_unique<WText>();
66 childCountLabel_->
setMargin(7, Side::Left);
67 childCountLabel_->setStyleClass(
"treenodechildcount");
69 layout_->elementAt(0, 0)->addWidget(std::move(expandIcon));
70 layout_->elementAt(0, 0)->addWidget(std::move(noExpandIcon));
73 layout_->elementAt(0, 1)->addWidget(std::move(labelIcon));
76 layout_->elementAt(0, 1)->addWidget(std::move(
labelText_));
77 layout_->elementAt(0, 1)->addWidget(std::move(childCountLabel));
79 layout_->elementAt(1, 1)->addWidget(std::move(expandedContent));
81 layout_->elementAt(0, 0)->setContentAlignment(AlignmentFlag::Top);
82 layout_->elementAt(0, 1)->setContentAlignment(AlignmentFlag::Middle);
99 node->parentNode_ =
this;
120 node->adjustExpandIcon();
124 if (childNodes_.size())
126 ->setText(
"(" + std::to_string(childNodes_.size())
185 node->undoCollapse();
207 Orientation::Vertical);
210 Orientation::Vertical);
WContainerWidget * expandedContent_
The container in which the children are managed.
void undoExpand()
Undo function for prelearning expand()
TreeNode(const std::string labelText, TextFormat labelFormat, std::unique_ptr< IconPair > labelIcon)
Construct a tree node with the given label.
void undoCollapse()
Undo function for prelearning collapse()
void expand()
Expands this node.
ImageIndex
Two sets of images, for a normal node, and for the last node.
TreeNode * parentNode_
The parent node.
WImage * icon1() const
Get the first icon image.
void setState(int num)
Set which icon should be visible.
WStatelessSlot * implementStateless(void(T::*method)())
void setBackgroundImage(const WLink &link, WFlags< Orientation > repeat=Orientation::Horizontal|Orientation::Vertical, WFlags< Side > sides=None)
WImage * icon2() const
Get the second icon image.
bool setText(const WString &text)
WText * childCountLabel_
The children count '(x)' for x children.
std::vector< TreeNode * > childNodes_
List of child nodes.
static std::string imageMin_[]
IconPair * labelIcon_
The icon next to the label.
WTableCell * elementAt(int row, int column)
bool isLastChildNode() const
Returns if is the last child within its parent (is rendered differently)
bool wasCollapsed_
Was collapsed (for undo of prelearned collapse() and expand() slots.
IconPair * expandIcon_
The icon for expanding or collapsing.
static std::string imageLine_[]
void removeChildNode(TreeNode *node, int index)
Removes a child node.
void childNodesChanged()
Rerender when children have changed.
static std::string imagePlus_[]
void addChildNode(std::unique_ptr< TreeNode > node)
Adds a child node.
WTable * layout_
Layout (2x2 table).
void adjustExpandIcon()
Adjust the expand icon.
WImage * noExpandIcon_
The single image shown instead of the expand/collapse icon when no children.
std::unique_ptr< WText > labelText_
The label.
Example implementation of a single tree list node.
void collapse()
Collapses this node.