Wt examples  3.7.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DemoTreeList Class Reference

A demonstration of the treelist. More...

#include <DemoTreeList.h>

Inheritance diagram for DemoTreeList:
Inheritance graph
[legend]

Public Member Functions

 DemoTreeList (Wt::WContainerWidget *parent)
 Create a DemoTreeList. More...
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 
 ~WContainerWidget ()
 
void setLayout (std::unique_ptr< WLayout > layout)
 
Layout * setLayout (std::unique_ptr< Layout > layout)
 
WLayoutlayout () const
 
virtual void addWidget (std::unique_ptr< WWidget > widget)
 
Widget * addWidget (std::unique_ptr< Widget > widget)
 
Widget * addNew (Args &&...args)
 
virtual void insertBefore (std::unique_ptr< WWidget > widget, WWidget *before)
 
Widget * insertBefore (std::unique_ptr< Widget > widget, WWidget *before)
 
virtual void insertWidget (int index, std::unique_ptr< WWidget > widget)
 
Widget * insertWidget (int index, std::unique_ptr< Widget > widget)
 
Widget * insertNew (int index, Args &&...args)
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
virtual void clear ()
 
virtual int indexOf (WWidget *widget) const
 
virtual WWidgetwidget (int index) const
 
virtual int count () const
 
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
 
void setPadding (const WLength &padding, WFlags< Side > sides=AllSides)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Orientation::Horizontal|Orientation::Vertical))
 
void setList (bool list, bool ordered=false)
 
bool isList () const
 
bool isUnorderedList () const
 
bool isOrderedList () const
 
EventSignal< WScrollEvent > & scrolled ()
 
int scrollTop () const
 
int scrollLeft () const
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
EventSignal< WKeyEvent > & keyWentDown ()
 
EventSignal< WKeyEvent > & keyPressed ()
 
EventSignal< WKeyEvent > & keyWentUp ()
 
EventSignalenterPressed ()
 
EventSignalescapePressed ()
 
EventSignal< WMouseEvent > & clicked ()
 
EventSignal< WMouseEvent > & doubleClicked ()
 
EventSignal< WMouseEvent > & mouseWentDown ()
 
EventSignal< WMouseEvent > & mouseWentUp ()
 
EventSignal< WMouseEvent > & mouseWentOut ()
 
EventSignal< WMouseEvent > & mouseWentOver ()
 
EventSignal< WMouseEvent > & mouseMoved ()
 
EventSignal< WMouseEvent > & mouseDragged ()
 
EventSignal< WMouseEvent > & mouseWheel ()
 
EventSignal< WTouchEvent > & touchStarted ()
 
EventSignal< WTouchEvent > & touchEnded ()
 
EventSignal< WTouchEvent > & touchMoved ()
 
EventSignal< WGestureEvent > & gestureStarted ()
 
EventSignal< WGestureEvent > & gestureChanged ()
 
EventSignal< WGestureEvent > & gestureEnded ()
 
void setDraggable (const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget *> children () const override
 
SignalchildrenChanged ()
 
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< SideclearSides () 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 isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () 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()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const 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 bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
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 void setObjectName (const std::string &name) override
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
std::unique_ptr< WWidgetremoveFromParent ()
 
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
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
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)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 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 Member Functions

void addMap ()
 Add a map. More...
 
void removeMap ()
 Remove a map. More...
 
TreeNodemakeTreeMap (const std::string name, TreeNode *parent)
 Create a "map" node, and insert in the given parent. More...
 
TreeNodemakeTreeFile (const std::string name, TreeNode *parent)
 Create a "file" node, and insert in the given parent. More...
 

Private Attributes

TreeNodetree_
 
TreeNodetestMap_
 
int testCount_
 
Wt::WPushButtonaddMapButton_
 
Wt::WPushButtonremoveMapButton_
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter='\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
virtual void render (WFlags< RenderFlag > flags) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

Detailed Description

A demonstration of the treelist.

This is the main class for the treelist example.

Definition at line 27 of file DemoTreeList.h.

Constructor & Destructor Documentation

◆ DemoTreeList()

DemoTreeList::DemoTreeList ( Wt::WContainerWidget parent)

Create a DemoTreeList.

Definition at line 20 of file DemoTreeList.C.

21  : WContainerWidget(parent),
22  testCount_(0)
23 {
24  addWidget
25  (new WText("<h2>Wt Tree List example</h2>"
26  "<p>This is a simple demo of a treelist, implemented using"
27  " <a href='http://witty.sourceforge.net/'>Wt</a>.</p>"
28  "<p>The leafs of the tree contain the source code of the "
29  "tree-list in the classes <b>TreeNode</b> and "
30  "<b>IconPair</b>, as well as the implementation of this "
31  "demo itself in the class <b>DemoTreeList</b>.</p>"));
32 
33  tree_ = makeTreeMap("Examples", 0);
35 
36  TreeNode *treelist = makeTreeMap("Tree List", tree_);
37  TreeNode *wstateicon = makeTreeMap("class IconPair", treelist);
38  makeTreeFile("<a href=\"IconPair.h\">IconPair.h</a>", wstateicon);
39  makeTreeFile("<a href=\"IconPair.C\">IconPair.C</a>", wstateicon);
40  TreeNode *wtreenode = makeTreeMap("class TreeNode", treelist);
41  makeTreeFile("<a href=\"TreeNode.h\">TreeNode.h</a>", wtreenode);
42  makeTreeFile("<a href=\"TreeNode.C\">TreeNode.C</a>", wtreenode);
43  TreeNode *demotreelist = makeTreeMap("class DemoTreeList", treelist);
44  makeTreeFile("<a href=\"DemoTreeList.h\">DemoTreeList.h</a>", demotreelist);
45  makeTreeFile("<a href=\"DemoTreeList.C\">DemoTreeList.C</a>", demotreelist);
46 
47  testMap_ = makeTreeMap("Test map", tree_);
48 
49  /*
50  * Buttons to dynamically demonstrate changing the tree contents.
51  */
52  addWidget
53  (new WText("<p>Use the following buttons to change the tree "
54  "contents:</p>"));
55 
57  = new WPushButton("Add map", this);
58  addMapButton_->clicked().connect(this, &DemoTreeList::addMap);
59 
61  = new WPushButton("Remove map", this);
64 
65  addWidget
66  (new WText("<p>Remarks:"
67  "<ul>"
68  "<li><p>This is not the instantiation of a pre-defined "
69  "tree list component, but the full implementation of such "
70  "a component, in about 350 lines of C++ code !</p> "
71  "<p>In comparison, the <a href='http://myfaces.apache.org'> "
72  "Apache MyFaces</a> JSF implementation of tree2, with similar "
73  "functionality, uses about 2400 lines of Java, and 140 lines "
74  "of JavaScript code.</p></li>"
75  "<li><p>Once loaded, the tree list does not require any "
76  "interaction with the server for handling the click events on "
77  "the <img src='icons/nav-plus-line-middle.gif' /> and "
78  "<img src='icons/nav-minus-line-middle.gif' /> icons, "
79  "because these events have been connected to slots using "
80  "STATIC connections. Such connections are converted to the "
81  "appropriate JavaScript code that is inserted into the page. "
82  "Still, the events are signaled to the server to update the "
83  "application state.</p></li>"
84  "<li><p>In contrast, the buttons for manipulating the tree "
85  "contents use DYNAMIC connections, and thus the update "
86  "is computed at server-side, and communicated back to the "
87  "browser (by default using AJAX).</p></li>"
88  "<li><p>When loading a page, only visible widgets (that are not "
89  "<b>setHidden(true)</b>) are transmitted. "
90  "The remaining widgets are loaded in the background after "
91  "rendering the page. "
92  "As a result the application is loaded as fast as possible.</p>"
93  "</li>"
94  "<li><p>The browser reload button is supported and behaves as "
95  "expected: the page is reloaded from the server. Again, "
96  "only visible widgets are transmitted immediately.</p> "
97  "<p>(For the curious, this is the way to see the actual "
98  "HTML/JavaScript code !)</p></li>"
99  "</ul></p>"));
100 }
Wt::WPushButton * addMapButton_
Definition: DemoTreeList.h:39
EventSignal< WMouseEvent > & clicked()
void disable()
TreeNode * makeTreeMap(const std::string name, TreeNode *parent)
Create a "map" node, and insert in the given parent.
Definition: DemoTreeList.C:129
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
void removeMap()
Remove a map.
Definition: DemoTreeList.C:113
void addMap()
Add a map.
Definition: DemoTreeList.C:102
TreeNode * tree_
Definition: DemoTreeList.h:35
virtual void addWidget(std::unique_ptr< WWidget > widget)
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Definition: DemoTreeList.C:143
Example implementation of a single tree list node.
Definition: TreeNode.h:55

Member Function Documentation

◆ addMap()

void DemoTreeList::addMap ( )
private

Add a map.

Definition at line 102 of file DemoTreeList.C.

103 {
104  TreeNode *node
105  = makeTreeMap("Map " + boost::lexical_cast<std::string>(++testCount_),
106  testMap_);
107  makeTreeFile("File " + boost::lexical_cast<std::string>(testCount_),
108  node);
109 
111 }
TreeNode * makeTreeMap(const std::string name, TreeNode *parent)
Create a "map" node, and insert in the given parent.
Definition: DemoTreeList.C:129
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
void enable()
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Definition: DemoTreeList.C:143
Example implementation of a single tree list node.
Definition: TreeNode.h:55

◆ makeTreeFile()

TreeNode * DemoTreeList::makeTreeFile ( const std::string  name,
TreeNode parent 
)
private

Create a "file" node, and insert in the given parent.

Definition at line 143 of file DemoTreeList.C.

145 {
146  IconPair *labelIcon
147  = new IconPair("icons/document.png", "icons/yellow-folder-open.png",
148  false);
149 
150  TreeNode *node = new TreeNode(name, XHTMLText, labelIcon, 0);
151  if (parent)
152  parent->addChildNode(node);
153 
154  return node;
155 }
An icon pair (identical to WIconPair)
Definition: IconPair.h:34
void addChildNode(TreeNode *node)
Adds a child node.
Definition: TreeNode.C:86
Example implementation of a single tree list node.
Definition: TreeNode.h:55

◆ makeTreeMap()

TreeNode * DemoTreeList::makeTreeMap ( const std::string  name,
TreeNode parent 
)
private

Create a "map" node, and insert in the given parent.

Definition at line 129 of file DemoTreeList.C.

130 {
131  IconPair *labelIcon
132  = new IconPair("icons/yellow-folder-closed.png",
133  "icons/yellow-folder-open.png",
134  false);
135 
136  TreeNode *node = new TreeNode(name, PlainText, labelIcon, 0);
137  if (parent)
138  parent->addChildNode(node);
139 
140  return node;
141 }
An icon pair (identical to WIconPair)
Definition: IconPair.h:34
void addChildNode(TreeNode *node)
Adds a child node.
Definition: TreeNode.C:86
Example implementation of a single tree list node.
Definition: TreeNode.h:55

◆ removeMap()

void DemoTreeList::removeMap ( )
private

Remove a map.

Definition at line 113 of file DemoTreeList.C.

114 {
115  int numMaps = testMap_->childNodes().size();
116 
117  if (numMaps > 0) {
118  int c = rand() % numMaps;
119 
120  TreeNode *child = testMap_->childNodes()[c];
121  testMap_->removeChildNode(child);
122  delete child;
123 
124  if (numMaps == 1)
126  }
127 }
void disable()
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
Definition: TreeNode.h:82
void removeChildNode(TreeNode *node)
Removes a child node.
Definition: TreeNode.C:96
Example implementation of a single tree list node.
Definition: TreeNode.h:55

Member Data Documentation

◆ addMapButton_

Wt::WPushButton* DemoTreeList::addMapButton_
private

Definition at line 39 of file DemoTreeList.h.

◆ removeMapButton_

Wt::WPushButton* DemoTreeList::removeMapButton_
private

Definition at line 40 of file DemoTreeList.h.

◆ testCount_

int DemoTreeList::testCount_
private

Definition at line 37 of file DemoTreeList.h.

◆ testMap_

TreeNode* DemoTreeList::testMap_
private

Definition at line 36 of file DemoTreeList.h.

◆ tree_

TreeNode* DemoTreeList::tree_
private

Definition at line 35 of file DemoTreeList.h.


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

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13