Wt examples  4.15.0
Loading...
Searching...
No Matches
DemoTreeList Class Reference

A demonstration of the treelist. More...

#include <DemoTreeList.h>

Inheritance diagram for DemoTreeList:
[legend]

Public Member Functions

 DemoTreeList ()
 Create a DemoTreeList.
Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 ~WContainerWidget ()
void setLayout (std::unique_ptr< WLayout > layout)
Layout * setLayout (std::unique_ptr< Layout > layout)
WLayout * layout () 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< WWidget > removeWidget (WWidget *widget) override
virtual void clear ()
virtual int indexOf (WWidget *widget) const
virtual WWidget * widget (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< AlignmentFlag > contentAlignment () 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
std::unique_ptr< Widget > removeWidget (Widget *widget)
Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
EventSignal< WKeyEvent > & keyWentDown ()
EventSignal< WKeyEvent > & keyPressed ()
EventSignal< WKeyEvent > & keyWentUp ()
EventSignal & enterPressed ()
EventSignal & escapePressed ()
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
Signal & childrenChanged ()
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
void anchorAt (WWidget *widget, Orientation orientation=Orientation::Vertical) 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 isPopup () const override
std::string positionAnchorName () const override
void becomePositionAnchor () override
void setPositionAnchor (const std::string &anchorName) override
void setPositionAnchor (WWidget *anchor) override
std::string positionAnchor () 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()) 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
void showToolTipOnHover (bool enable)
void showToolTip ()
void hideToolTip ()
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 WWidget * find (const std::string &name) override
virtual WWidget * findById (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)
bool resendFormData () override
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
EventSignal & blurred ()
EventSignal & focussed ()
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
void setFocus ()
Public Member Functions inherited from Wt::WWidget
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, WFlags< Orientation > adjustOrientations=AllOrientations)
bool isPositionAnchor () const
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)
virtual void htmlText (std::ostream &out, WStringStream &js)
bool isRendered () const
void hide ()
void animateHide (const WAnimation &animation)
void show ()
void animateShow (const WAnimation &animation)
void enable ()
void disable ()
bool layoutSizeAware () const
virtual void scheduleThemeStyleApply (std::shared_ptr< Wt::WTheme > theme, WWidget *child, int role)
virtual void applyThemeStyles ()
Public Member Functions inherited from Wt::WObject
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)
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 addFolder ()
 Add a folder.
void removeFolder ()
 Remove a folder.
TreeNode * makeTreeFolder (const std::string name, TreeNode *parent)
 Create a "folder" node, and insert in the given parent.
std::unique_ptr< TreeNode > makeTreeFolder (const std::string name)
 Create a "folder" root.
TreeNode * makeTreeFile (const std::string name, TreeNode *parent)
 Create a "file" node, and insert in the given parent.
std::unique_ptr< TreeNode > makeTreeFile (const std::string name)
 Create a "file" root.

Private Attributes

TreeNode * tree_
TreeNode * testFolder_
int testCount_
WPushButton * addFolderButton_
WPushButton * removeFolderButton_

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 void setDefaultNativeControl (bool enabled)
static bool defaultNativeControl ()
Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
Static Public Attributes inherited from Wt::WInteractWidget
static const std::string noDefault
Protected Member Functions inherited from Wt::WInteractWidget
void render (WFlags< RenderFlag > flags) override
virtual void propagateSetEnabled (bool enabled) override
Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
virtual WStatelessSlot * getStateless (Method method) 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 29 of file DemoTreeList.h.

Constructor & Destructor Documentation

◆ DemoTreeList()

DemoTreeList::DemoTreeList ( )

Create a DemoTreeList.

Definition at line 19 of file DemoTreeList.C.

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

Member Function Documentation

◆ addFolder()

void DemoTreeList::addFolder ( )
private

Add a folder.

Definition at line 101 of file DemoTreeList.C.

102{
103 TreeNode *node
104 = makeTreeFolder("Folder " + std::to_string(++testCount_), testFolder_);
105 makeTreeFile("File " + std::to_string(testCount_), node);
106
107 removeFolderButton_->enable();
108}

◆ makeTreeFile() [1/2]

std::unique_ptr< TreeNode > DemoTreeList::makeTreeFile ( const std::string name)
private

Create a "file" root.

Definition at line 167 of file DemoTreeList.C.

168{
169 auto labelIcon
170 = std::make_unique<IconPair>("icons/document.png", "icons/yellow-folder-open.png",
171 false);
172 auto node =
173 std::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
174
175 return node;
176}

◆ makeTreeFile() [2/2]

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

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

Definition at line 152 of file DemoTreeList.C.

154{
155 auto labelIcon
156 = std::make_unique<IconPair>("icons/document.png", "icons/yellow-folder-open.png",
157 false);
158
159 auto node = std::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
160 auto node_ = node.get();
161 if (parent)
162 parent->addChildNode(std::move(node));
163
164 return node_;
165}
WWidget * parent() const

◆ makeTreeFolder() [1/2]

std::unique_ptr< TreeNode > DemoTreeList::makeTreeFolder ( const std::string name)
private

Create a "folder" root.

Definition at line 140 of file DemoTreeList.C.

141{
142 auto labelIcon = std::make_unique<IconPair>(
143 "icons/yellow-folder-closed.png",
144 "icons/yellow-folder-open.png",
145 false);
146 auto node =
147 std::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
148
149 return node;
150}

◆ makeTreeFolder() [2/2]

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

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

Definition at line 125 of file DemoTreeList.C.

126{
127 auto labelIcon = std::make_unique<IconPair>(
128 "icons/yellow-folder-closed.png",
129 "icons/yellow-folder-open.png",
130 false);
131
132 auto node =
133 std::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
134 auto node_ = node.get();
135 parent->addChildNode(std::move(node));
136
137 return node_;
138}

◆ removeFolder()

void DemoTreeList::removeFolder ( )
private

Remove a folder.

Definition at line 110 of file DemoTreeList.C.

111{
112 int numFolders = testFolder_->childNodes().size();
113
114 if (numFolders > 0) {
115 int c = rand() % numFolders;
116
117 TreeNode *child = testFolder_->childNodes()[c];
118 testFolder_->removeChildNode(child, c);
119
120 if (numFolders == 1)
121 removeFolderButton_->disable();
122 }
123}

Member Data Documentation

◆ addFolderButton_

WPushButton* DemoTreeList::addFolderButton_
private

Definition at line 41 of file DemoTreeList.h.

◆ removeFolderButton_

WPushButton* DemoTreeList::removeFolderButton_
private

Definition at line 42 of file DemoTreeList.h.

◆ testCount_

int DemoTreeList::testCount_
private

Definition at line 39 of file DemoTreeList.h.

◆ testFolder_

TreeNode* DemoTreeList::testFolder_
private

Definition at line 38 of file DemoTreeList.h.

◆ tree_

TreeNode* DemoTreeList::tree_
private

Definition at line 37 of file DemoTreeList.h.


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