Wt examples  4.10.4
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 
13 class IconPair;
14 
15 using namespace Wt;
16 
17 namespace Wt {
18  class WTable;
19  class WImage;
20 }
21 
26 
57 class TreeNode : public WCompositeWidget
58 {
59 public:
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 
94 private:
96  std::vector<TreeNode *> childNodes_;
97 
100 
103 
106 
109 
112 
115 
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
std::vector< TreeNode * > childNodes_
List of child nodes.
Definition: TreeNode.h:96
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
WContainerWidget * expandedContent_
The container in which the children are managed.
Definition: TreeNode.h:117
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
TreeNode * parentNode_
The parent node.
Definition: TreeNode.h:99
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
Definition: TreeNode.h:84
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
TextFormat