Wt: Wt::WTreeView Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
Wt::WTreeView Class Reference
Model/view system

A view class that displays a model as a tree or tree table. More...

`#include <Wt/WTreeView.h>`

Inheritance diagram for Wt::WTreeView:
[legend]

## Public Member Functions
| WTreeView ()
| Creates a new tree view.
void | setExpanded (const WModelIndex &, bool expanded)
| Expands or collapses a node.
bool | isExpanded (const WModelIndex &index) const
| Returns whether a node is expanded.
void | collapse (const WModelIndex &index)
| Collapses a node.
void | collapseAll ()
| Collapse all expanded nodes.
void | expand (const WModelIndex &index)
| Expands a node.
void | expandToDepth (int depth)
| Expands all nodes to a depth.
void | setRootIsDecorated (bool show)
| Sets whether toplevel items are decorated.
bool | rootIsDecorated () const
| Returns whether toplevel items are decorated.
virtual void | resize (const WLength &width, const WLength &height) override
| Resizes the widget.
Signal< WModelIndex > & | collapsed ()
| Signal emitted when a node is collapsed.
Signal< WModelIndex > & | expanded ()
| Signal emitted when a node is expanded.
virtual WWidget * | itemWidget (const WModelIndex &index) const override
| Returns the widget that renders an item.
virtual void | setModel (const std::shared_ptr< WAbstractItemModel > &model) override
| Sets the model.
virtual void | setColumnWidth (int column, const WLength &width) override
| Sets the column width.
virtual void | setAlternatingRowColors (bool enable) override
| Sets if alternating row colors are to be used.
virtual void | setRowHeight (const WLength &rowHeight) override
| Sets the row height.
virtual void | setHeaderHeight (const WLength &height) override
| Sets the header height.
virtual void | setColumnHidden (int column, bool hidden) override
| Changes the visibility of a column.
virtual void | setRowHeaderCount (int count) override
| Configures the number of columns that are used as row headers.
virtual int | pageCount () const override
| Returns the number of pages.
virtual int | pageSize () const override
| Returns the page size.
virtual int | currentPage () const override
| Returns the current page.
virtual void | setCurrentPage (int page) override
| Sets the current page.
virtual void | scrollTo (const WModelIndex &index, ScrollHint hint=ScrollHint::EnsureVisible) override
| Scrolls the view to an item.
virtual EventSignal< WScrollEvent > & | scrolled () override
| Signal emitted when scrolling.
virtual void | setId (const std::string &id) override
| Sets the CSS Id.
Public Member Functions inherited from Wt::WAbstractItemView
std::shared_ptr< WAbstractItemModel > | model () const
| Returns the model.
void | setRootIndex (const WModelIndex &rootIndex)
| Sets the root index.
const WModelIndex & | rootIndex () const
| Returns the root index.
void | setItemDelegate (const std::shared_ptr< WAbstractItemDelegate > &delegate)
| Sets the default item delegate.
std::shared_ptr< WAbstractItemDelegate > | itemDelegate () const
| Returns the default item delegate.
void | setItemDelegateForColumn (int column, const std::shared_ptr< WAbstractItemDelegate > &delegate)
| Sets the delegate for a column.
std::shared_ptr< WAbstractItemDelegate > | itemDelegateForColumn (int column) const
| Returns the delegate that was set for a column.
std::shared_ptr< WAbstractItemDelegate > | itemDelegate (const WModelIndex &index) const
| Returns the delegate for rendering an item.
std::shared_ptr< WAbstractItemDelegate > | itemDelegate (int column) const
| Returns the delegate for a column.
void | setHeaderItemDelegate (const std::shared_ptr< WAbstractItemDelegate > &delegate)
| Sets the header item delegate.
std::shared_ptr< WAbstractItemDelegate > | headerItemDelegate () const
| Returns the header item delegate.
virtual void | setColumnAlignment (int column, AlignmentFlag alignment)
| Sets the content alignment for a column.
virtual AlignmentFlag | columnAlignment (int column) const
| Returns the content alignment for a column.
virtual void | setHeaderAlignment (int column, WFlags< AlignmentFlag > alignment)
| Sets the header alignment for a column.
AlignmentFlag | horizontalHeaderAlignment (int column) const
| Returns the horizontal header alignment for a column.
AlignmentFlag | verticalHeaderAlignment (int column) const
| Returns the vertical header alignment for a column.
void | setHeaderWordWrap (int column, bool enabled)
| Configures header text wrapping.
virtual bool | alternatingRowColors () const
| Returns whether alternating row colors are used.
void | sortByColumn (int column, SortOrder order)
| Sorts the data according to a column.
int | sortColumn () const
| Returns the current sorting columm.
SortOrder | sortOrder () const
| Returns the current sorting order.
void | setSortingEnabled (bool enabled)
| Enables or disables sorting for all columns.
void | setSortingEnabled (int column, bool enabled)
| Enables or disables sorting for a single column.
bool | isSortingEnabled () const
| Returns whether sorting is enabled.
bool | isSortingEnabled (int column) const
| Returns whether sorting is enabled for a single column.
void | setColumnResizeEnabled (bool enabled)
| Enables interactive column resizing.
bool | isColumnResizeEnabled () const
| Returns whether column resizing is enabled.
void | setSelectionBehavior (SelectionBehavior behavior)
| Changes the selection behaviour.
SelectionBehavior | selectionBehavior () const
| Returns the selection behaviour.
void | setSelectionMode (SelectionMode mode)
| Sets the selection mode.
SelectionMode | selectionMode () const
| Returns the selection mode.
WItemSelectionModel * | selectionModel () const
| Returns the selection model.
void | setSelectedIndexes (const WModelIndexSet &indexes)
| Sets the selected items.
void | clearSelection ()
| Clears the selection.
void | select (const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
| Selects a single item.
bool | isSelected (const WModelIndex &index) const
| Returns wheter an item is selected.
WModelIndexSet | selectedIndexes () const
| Returns the set of selected items.
void | setDragEnabled (bool enable)
| Enables the selection to be dragged (drag & drop).
void | setDropsEnabled (bool enable)
| Enables drop operations (drag & drop).
void | setEnabledDropLocations (WFlags< DropLocation > droplocation)
| Enables drop operations (drag & drop).
WFlags< DropLocation > | enabledDropLocations () const
| Returns the enabled drop locations.
const WLength & | rowHeight () const
| Returns the row height.
WLength | columnWidth (int column) const
| Returns the column width.
bool | isColumnHidden (int column) const
| Returns if a column is hidden.
void | hideColumn (int column)
| Hides a column.
void | showColumn (int column)
| Shows a column.
const WLength & | headerHeight () const
| Returns the header height.
void | setEditTriggers (WFlags< EditTrigger > editTriggers)
| Configures what actions should trigger editing.
WFlags< EditTrigger > | editTriggers () const
| Returns the editing triggers.
void | setEditOptions (WFlags< EditOption > options)
| Configures editing options.
WFlags< EditOption > | editOptions () const
| Returns the editing options.
void | edit (const WModelIndex &index)
| Opens an editor for the given index.
void | closeEditor (const WModelIndex &index, bool saveData=true)
| Closes the editor for the given index.
void | closeEditors (bool saveData=true)
| Closes all open editors.
ValidationState | validateEditor (const WModelIndex &index)
| Validates the editor for the given index.
ValidationState | validateEditors ()
| Validates all editors.
bool | isEditing (const WModelIndex &index) const
| Returns whether an editor is open for a given index.
bool | isValid (const WModelIndex &index) const
| Returns whether an editor's state is valid.
Signal< WModelIndex, WMouseEvent > & | clicked ()
| Signal emitted when clicked.
Signal< WModelIndex, WMouseEvent > & | doubleClicked ()
| Signal emitted when double clicked.
Signal< WModelIndex, WMouseEvent > & | mouseWentDown ()
| Signal emitted when a mouse button is pressed down.
Signal< WModelIndex, WMouseEvent > & | mouseWentUp ()
| Signal emitted when the mouse button is released.
Signal< WModelIndex, WTouchEvent > & | touchStart ()
| Signal emitted when a finger is placed on the screen.
Signal< std::vector< WModelIndex >, WTouchEvent > & | touchStarted ()
| Signal emitted when one or more fingers are placed on the screen.
Signal< std::vector< WModelIndex >, WTouchEvent > & | touchMoved ()
| Signal emitted when one or more fingers are moved on the screen.
Signal< std::vector< WModelIndex >, WTouchEvent > & | touchEnded ()
| Signal emitted when one or more fingers are removed from the screen.
Signal & | selectionChanged ()
| Signal emitted when the selection is changed.
Signal & | pageChanged ()
| Signal emitted when page information was updated.
Signal< int, WLength > & | columnResized ()
| Returns the signal emitted when a column is resized by the user.
bool | sortEnabled ()
| Returns whether the view is sortable.
void | setHeaderClickSortEnabled (bool enabled)
| Alow to sort.
Signal< int, WMouseEvent > & | headerClicked ()
| Signal emitted when a header item is clicked.
Signal< int, WMouseEvent > & | headerDoubleClicked ()
| Signal emitted when a header item is double clicked.
Signal< int, WMouseEvent > & | headerMouseWentDown ()
| Signal emitted when a mouse button is pressed on a header item
Signal< int, WMouseEvent > & | headerMouseWentUp ()
| Signal emitted when a mouse button is released on a header item
int | rowHeaderCount () const
| Returns the number of columns that are used as row headers.
EventSignal< WKeyEvent > & | keyWentDown ()
| Event signal emitted when a keyboard key is pushed down.
EventSignal< WKeyEvent > & | keyPressed ()
| Event signal emitted when a "character" was entered.
EventSignal< WKeyEvent > & | keyWentUp ()
| Event signal emitted when a keyboard key is released.
Public Member Functions inherited from Wt::WCompositeWidget
| WCompositeWidget ()
| Creates a WCompositeWidget.
| WCompositeWidget (std::unique_ptr< WWidget > implementation)
| Creates a WCompositeWidget with given implementation.
virtual std::vector< WWidget * > | children () const override
| Returns child widgets.
virtual std::unique_ptr< WWidget > | removeWidget (WWidget *widget) override
| Removes a child widget.
virtual void | setObjectName (const std::string &name) override
| Sets an object name.
virtual std::string | objectName () const override
| Returns the object name.
virtual const std::string | id () const override
| Returns the (unique) identifier for this object.
virtual void | setPositionScheme (PositionScheme scheme) override
| Sets the CSS position scheme.
virtual PositionScheme | positionScheme () const override
| Returns the CSS position scheme.
virtual void | setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
| Sets CSS offsets for a non-statically positioned widget.
virtual WLength | offset (Side s) const override
| Returns a CSS offset.
virtual WLength | width () const override
| Returns the width.
virtual WLength | height () const override
| Returns the height.
virtual void | setMinimumSize (const WLength &width, const WLength &height) override
| Sets a minimum size.
virtual WLength | minimumWidth () const override
| Returns the minimum width.
virtual WLength | minimumHeight () const override
| Returns the minimum height.
virtual void | setMaximumSize (const WLength &width, const WLength &height) override
| Sets a maximum size.
virtual WLength | maximumWidth () const override
| Returns the maximum width.
virtual WLength | maximumHeight () const override
| Returns the maximum height.
virtual void | setLineHeight (const WLength &height) override
| Sets the CSS line height for contained text.
virtual WLength | lineHeight () const override
| Returns the CSS line height for contained text.
virtual void | setFloatSide (Side s) override
| Specifies a CSS float side.
virtual Side | floatSide () const override
| Returns the CSS float side.
virtual void | setClearSides (WFlags< Side > sides) override
| Sets the sides that should be cleared of floats.
virtual WFlags< Side > | clearSides () const override
| Returns the sides that should remain empty.
virtual void | setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
| Sets CSS margins around the widget.
virtual WLength | margin (Side side) const override
| Returns a CSS margin set.
virtual void | setHiddenKeepsGeometry (bool enabled) override
| Sets whether the widget keeps its geometry when hidden.
virtual bool | hiddenKeepsGeometry () const override
| Returns whether the widget keeps its geometry when hidden.
virtual void | setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
| Hides or shows the widget.
virtual bool | isHidden () const override
| Returns whether the widget is set hidden.
virtual bool | isVisible () const override
| Returns whether the widget is visible.
virtual void | setDisabled (bool disabled) override
| Sets whether the widget is disabled.
virtual bool | isDisabled () const override
| Returns whether the widget is set disabled.
virtual bool | isEnabled () const override
| Returns whether the widget is enabled.
virtual void | setPopup (bool popup) override
| Lets the widget overlay over other sibling widgets.
virtual bool | isPopup () const override
| Returns whether the widget is overlayed.
virtual void | setInline (bool isInline) override
| Sets whether the widget is displayed inline or as a block.
virtual bool | isInline () const override
| Returns whether the widget is displayed inline or as block.
virtual void | setDecorationStyle (const WCssDecorationStyle &style) override
| Sets a CSS decoration style.
virtual WCssDecorationStyle & | decorationStyle () override
| Returns the decoration style of this widget.
virtual void | setStyleClass (const WString &styleClass) override
| Sets (one or more) CSS style classes.
virtual WString | styleClass () const override
| Returns the CSS style class.
virtual void | addStyleClass (const WString &styleClass, bool force=false) override
| Adds a CSS style class.
virtual void | removeStyleClass (const WString &styleClass, bool force=false) override
| Removes a CSS style class.
virtual bool | hasStyleClass (const WString &styleClass) const override
| Returns whether the widget has a style class.
virtual void | setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto) override
| Sets the vertical alignment.
virtual AlignmentFlag | verticalAlignment () const override
| Returns the vertical alignment.
virtual WLength | verticalAlignmentLength () const override
| Returns the fixed vertical alignment that was set.
virtual void | setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
| Sets a tooltip.
virtual WString | toolTip () const override
| Returns the tooltip.
virtual void | setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
| Enable deferred tooltip.
virtual void | refresh () override
| Refresh the widget.
virtual void | setAttributeValue (const std::string &name, const WString &value) override
| Sets an attribute value.
virtual WString | attributeValue (const std::string &name) const override
| Returns an attribute value.
virtual void | setJavaScriptMember (const std::string &name, const std::string &value) override
| Sets a JavaScript member.
virtual std::string | javaScriptMember (const std::string &name) const override
| Returns the value of a JavaScript member.
virtual void | callJavaScriptMember (const std::string &name, const std::string &args) override
| Calls a JavaScript member.
virtual void | load () override
| Loads content just before the widget is used.
virtual bool | loaded () const override
| Returns whether this widget has been loaded.
virtual void | setCanReceiveFocus (bool enabled) override
| Sets whether the widget can receive focus.
virtual bool | canReceiveFocus () const override
| Returns whether the widget can receive focus.
virtual void | setFocus (bool focus) override
| Sets focus.
virtual bool | setFirstFocus () override
| Set focus on the widget's first descendant.
virtual bool | hasFocus () const override
| Returns whether the widget currently has the focus.
virtual void | setTabIndex (int index) override
| Sets the tab index.
virtual int | tabIndex () const override
| Returns the tab index.
virtual WWidget * | find (const std::string &name) override
| Finds a descendent widget by name.
virtual WWidget * | findById (const std::string &name) override
| Finds a descendent widget by id.
virtual void | setSelectable (bool selectable) override
| Sets as selectable.
virtual void | doJavaScript (const std::string &js) override
| Executes the given JavaScript statements when the widget is rendered or updated.
virtual void | propagateSetEnabled (bool enabled) override
| Propagates that a widget was enabled or disabled through children.
virtual bool | scrollVisibilityEnabled () const final override
| Returns whether scroll visibility detection is enabled for this widget.
virtual void | setScrollVisibilityEnabled (bool enabled) final override
| Sets whether scroll visibility detection is enabled for this widget.
virtual int | scrollVisibilityMargin () const final override
| Returns the margin around the viewport within which the widget is considered visible.
virtual void | setScrollVisibilityMargin (int margin) final override
| Sets the margin around the viewport within which the widget is considered visible.
virtual Signal< bool > & | scrollVisibilityChanged () final override
| Signal triggered when the scroll visibility of this widget changes.
virtual bool | isScrollVisible () const final override
| Returns whether this widget is currently considered scroll visible.
virtual void | setThemeStyleEnabled (bool enabled) final override
| Sets whether theme styling for a widget is enabled or disabled.
virtual bool | isThemeStyleEnabled () const final override
| Returns whether this widget is currently styled by the chosen theme.
template<typename Widget >
std::unique_ptr< Widget > | removeWidget (Widget *widget)
| Removes a child widget.
void | setFocus ()
| Sets focus.
Public Member Functions inherited from Wt::WWidget
virtual | ~WWidget ()
| Destructor.
WWidget * | parent () const
| Returns the parent widget.
template<typename Widget >
std::unique_ptr< Widget > | removeWidget (Widget *widget)
| Removes a child widget.
std::unique_ptr< WWidget > | removeFromParent ()
| Removes the widget from its parent.
void | setWidth (const WLength &width)
| Sets the width.
void | setHeight (const WLength &height)
| Sets the height.
virtual void | positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
| Positions a widget next to another widget.
virtual void | toggleStyleClass (const WString &styleClass, bool add, bool force=false)
| Toggles a CSS style class.
std::string | jsRef () const
| Returns a JavaScript expression to the corresponding DOM node.
void | setFocus ()
| Sets focus.
virtual void | acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
| Sets a mime type to be accepted for dropping.
virtual void | stopAcceptDrops (const std::string &mimeType)
| Indicates that a mime type is no longer accepted for dropping.
virtual void | htmlText (std::ostream &out)
| Streams the (X)HTML representation.
bool | isRendered () const
| Returns whether the widget is rendered.
void | hide ()
| Hides the widget.
void | animateHide (const WAnimation &animation)
| Hides the widget using an animation.
void | show ()
| Shows the widget.
void | animateShow (const WAnimation &animation)
| Shows the widget using an animation.
void | enable ()
| Enables the widget.
void | disable ()
| Disable thes widget.
bool | layoutSizeAware () const
| Returns whether the widget is layout size aware.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
void | resetLearnedSlots ()
| Resets learned stateless slot implementations.
template<class T >
void | resetLearnedSlot (void(T::*method)())
| Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)())
| Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)())
| Declares a slot to be stateless and learn client-side behaviour in advance.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.

## Protected Member Functions
virtual void | render (WFlags< RenderFlag > flags) override
| Renders the widget.
virtual void | enableAjax () override
| Progresses to an Ajax-enabled widget.
Protected Member Functions inherited from Wt::WAbstractItemView
| WAbstractItemView ()
| Creates a new item view.
virtual void | dropEvent (const WDropEvent &event, const WModelIndex &target)
| Handles a drop event (drag & drop).
virtual void | dropEvent (const WDropEvent &event, const WModelIndex &index, Wt::Side side)
| Handles a drop event (drag & drop).
virtual std::unique_ptr< WWidget > | createExtraHeaderWidget (int column)
| Create an extra widget in the header.
WWidget * | extraHeaderWidget (int column)
| Returns the extra header widget.
virtual std::unique_ptr< WWidget > | createPageNavigationBar ()
| Returns a page navigation widget.
virtual void | handleClick (const WModelIndex &index, const WMouseEvent &event)
| Handles a click event.
virtual void | handleDoubleClick (const WModelIndex &index, const WMouseEvent &event)
| Handles a double click event.
virtual void | handleMouseDown (const WModelIndex &index, const WMouseEvent &event)
| Handles a mouse down event.
virtual void | handleMouseUp (const WModelIndex &index, const WMouseEvent &event)
| Handles a mouse up event.
virtual void | handleTouchSelect (const std::vector< WModelIndex > &indices, const WTouchEvent &event)
| Handles a touch select event.
virtual void | handleTouchStart (const std::vector< WModelIndex > &indices, const WTouchEvent &event)
| Handles a touch started event.
virtual void | handleTouchMove (const std::vector< WModelIndex > &indices, const WTouchEvent &event)
| Handles a touch moved event.
virtual void | handleTouchEnd (const std::vector< WModelIndex > &indices, const WTouchEvent &event)
| Handles a touch ended event.
virtual void | dropEvent (WDropEvent dropEvent)
| Handles a drop event.
Protected Member Functions inherited from Wt::WCompositeWidget
void | setImplementation (std::unique_ptr< WWidget > widget)
| Set the implementation widget.
template<typename Widget >
Widget * | setImplementation (std::unique_ptr< Widget > widget)
| Sets the implementation widget, returning a raw pointer.
template<typename W , typename... Args>
W * | setNewImplementation (Args &&... args)
| Creates the implementation widget and sets it, returning a raw pointer.
WWidget * | implementation ()
| Get the implementation widget.
virtual int | boxPadding (Orientation orientation) const override
| Returns the widget's built-in padding.
virtual int | boxBorder (Orientation orientation) const override
| Returns the widget's built-in border width.
Protected Member Functions inherited from Wt::WWidget
void | setLayoutSizeAware (bool sizeAware)
| Sets the widget to be aware of its size set by a layout manager.
virtual void | layoutSizeChanged (int width, int height)
| Virtual method that indicates a size change.
| WWidget ()
| Creates a widget.
void | scheduleRender (WFlags< RepaintFlag > flags=None)
| Schedules rerendering of the widget.
virtual WStatelessSlot * | getStateless (Method method) override
| On-demand stateless slot implementation.
Protected Member Functions inherited from Wt::WObject

## Additional Inherited Members
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.
Static Public Member Functions inherited from Wt::WWidget
static WString | tr (const char *key)
| Short hand for WString::tr()
Static Public Member Functions inherited from Wt::WObject
Static Public Attributes inherited from Wt::WWidget
Protected Types inherited from Wt::WAbstractItemView
Protected Types inherited from Wt::WWidget
Protected Attributes inherited from Wt::WAbstractItemView
Static Protected Attributes inherited from Wt::WWidget

## Detailed Description

A view class that displays a model as a tree or tree table.

The view displays data from a WAbstractItemModel in a tree or tree table. It provides incremental rendering, allowing the display of data models of any size efficiently, without excessive use of client- or serverside resources.

The rendering (and editing) of items is handled by a WAbstractItemDelegate, by default it uses WItemDelegate which renders data of all predefined roles (see also Wt::ItemDataRole), including text, icons, checkboxes, and tooltips.

The view may support editing of items, if the model indicates support (see the Wt::ItemFlag::Editable flag). You can define triggers that initiate editing of an item using setEditTriggers(). The actual editing is provided by the item delegate (you can set an appropriate delegate for one column using setItemDelegateForColumn()). Using setEditOptions() you can customize if and how the view deals with multiple editors.

By default, all but the first columns are given a width of 150px, and the first column takes the remaining size. Note that this may have as consequence that the first column's size is reduced to 0. Column widths of all columns, including the first column, can be set through the API method setColumnWidth(), and also by the user using handles provided in the header.

Optionally, the treeview may be configured so that the first column is always visible while scrolling through the other columns, which may be convenient if you wish to display a model with many columns. Use setColumn1Fixed() to enable this behaviour.

If the model supports sorting (WAbstractItemModel::sort()), such as the WStandardItemModel, then you can enable sorting buttons in the header, using setSortingEnabled().

You can allow selection on row or item level (using setSelectionBehavior()), and selection of single or multiple items (using setSelectionMode()), and listen for changes in the selection using the selectionChanged() signal.

You may enable drag & drop support for this view, with awareness of the items in the model. When enabling dragging (see setDragEnabled()), the current selection may be dragged, but only when all items in the selection indicate support for dragging (controlled by the ItemFlag::DragEnabled flag), and if the model indicates a mime-type (controlled by WAbstractItemModel::mimeType()). Likewise, by enabling support for dropping (see setDropsEnabled()), the treeview may receive a drop event on a particular item, at least if the item indicates support for drops (controlled by the ItemFlag::DropEnabled flag).

You may also react to mouse click events on any item, by connecting to one of the clicked() or doubleClicked() signals.

Usage example:

// WTreeView will display the data of a model
std::shared_ptr<Wt::WAbstractItemModel> model = ...
// Create the WTreeView
auto gitView = std::make_unique<Wt::WTreeView>();
gitView->resize(300, Wt::WLength::Auto);
gitView->setSortingEnabled(false);
gitView->setModel(model);
gitView->setSelectionMode(SelectionMode::Single);
Wt::WAbstractItemView::model
std::shared_ptr< WAbstractItemModel > model() const
Returns the model.
Definition WAbstractItemView.h:105
Wt::WLength::Auto
static WLength Auto
An 'auto' length.
Definition WLength.h:65
Wt::SelectionMode::Single
@ Single
Single selection only.

### Graceful degradation

The view provides a virtual scrolling behavior which relies on Ajax availability. When Ajax is not available, a page navigation bar is used instead, see createPageNavigationBar(). In that case, the widget needs to be given an explicit height using resize() which determines the number of rows that are displayed at a time.

A snapshot of the WTreeView:

WTreeView example (default)
WTreeView example (polished)

## Member Function Documentation

## ◆ collapse()

void Wt::WTreeView::collapse | ( | const WModelIndex & | index | ) |

Collapses a node.

See also
  setExpanded(), expand()

Note
  until 3.3.4, selection was removed from within nodes that were collapsed. This (inconsistent) behavior has been removed in 3.3.4.

## ◆ collapseAll()

void Wt::WTreeView::collapseAll | ( |  | ) |

Collapse all expanded nodes.

See also
  collapse(), expand()

## ◆ collapsed()

Signal< WModelIndex > & Wt::WTreeView::collapsed | ( |  | ) |

Signal emitted when a node is collapsed.

See also
  setExpanded(), expanded()

## ◆ currentPage()

virtual int Wt::WTreeView::currentPage | ( |  | ) | const
| overridevirtual

Returns the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the current page (between 0 and pageCount() - 1).

See also
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

## ◆ enableAjax()

virtual void Wt::WTreeView::enableAjax | ( |  | ) |
| overrideprotectedvirtual

Progresses to an Ajax-enabled widget.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

See also
  WApplication::enableAjax()

Reimplemented from Wt::WAbstractItemView.

## ◆ expand()

void Wt::WTreeView::expand | ( | const WModelIndex & | index | ) |

Expands a node.

See also
  setExpanded(), collapse()

## ◆ expanded()

Signal< WModelIndex > & Wt::WTreeView::expanded | ( |  | ) |

Signal emitted when a node is expanded.

See also
  setExpanded(), collapsed()

## ◆ expandToDepth()

void Wt::WTreeView::expandToDepth | ( | int | depth | ) |

Expands all nodes to a depth.

Expands all nodes to the given `depth`. A depth of 1 corresponds to the top level nodes.

See also
  expand()

## ◆ isExpanded()

bool Wt::WTreeView::isExpanded | ( | const WModelIndex & | index | ) | const

Returns whether a node is expanded.

See also
  setExpanded()

## ◆ itemWidget()

virtual WWidget * Wt::WTreeView::itemWidget | ( | const WModelIndex & | index | ) | const
| overridevirtual

Returns the widget that renders an item.

This returns the widget that renders the given item. This may return 0 if the item is currently not rendered.

This widget has been created by an item delegate, and usually an item delegate is involved when updating it.

Implements Wt::WAbstractItemView.

## ◆ pageCount()

virtual int Wt::WTreeView::pageCount | ( |  | ) | const
| overridevirtual

Returns the number of pages.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of pages currently shown.

See also
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

## ◆ pageSize()

virtual int Wt::WTreeView::pageSize | ( |  | ) | const
| overridevirtual

Returns the page size.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of items per page.

See also
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

## ◆ render()

virtual void Wt::WTreeView::render | ( | WFlags< RenderFlag > | flags | ) |
| overrideprotectedvirtual

Renders the widget.

This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

Reimplemented from Wt::WCompositeWidget.

## ◆ resize()

virtual void Wt::WTreeView::resize | ( | const WLength & | width,
|  | const WLength & | height )
| overridevirtual

Resizes the widget.

Specifies a fixed size for this widget, setting CSS `width` and `height` properties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.

When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether they widget is a block or inline widget:

- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).

When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using setLayoutSizeAware(). If you have defined a `"wtResize()"` JavaScript method for the widget, then this method will also be called.

The default width and height of a widget is WLength::Auto.

See also
  width(), height()

Reimplemented from Wt::WCompositeWidget.

## ◆ rootIsDecorated()

bool Wt::WTreeView::rootIsDecorated | ( |  | ) | const

Returns whether toplevel items are decorated.

See also
  setRootIsDecorated()

## ◆ scrolled()

virtual EventSignal< WScrollEvent > & Wt::WTreeView::scrolled | ( |  | ) |
| overridevirtual

Signal emitted when scrolling.

Note
  Works only if ajax is available.

Implements Wt::WAbstractItemView.

## ◆ scrollTo()

virtual void Wt::WTreeView::scrollTo | ( | const WModelIndex & | index,
|  | ScrollHint | hint = ScrollHint::EnsureVisible )
| overridevirtual

Scrolls the view to an item.

Scrolls the view to ensure that the item which represents the provided `index` is visible. A `hint` may indicate how the item should appear in the viewport (if possible).

Note
  Currently only implemented to scroll to the correct row, not taking into account the column.

Implements Wt::WAbstractItemView.

## ◆ setAlternatingRowColors()

virtual void Wt::WTreeView::setAlternatingRowColors | ( | bool | enable | ) |
| overridevirtual

Sets if alternating row colors are to be used.

Configure whether rows get alternating background colors, defined by the current CSS theme.

The default value is `false`.

Reimplemented from Wt::WAbstractItemView.

## ◆ setColumnHidden()

virtual void Wt::WTreeView::setColumnHidden | ( | int | column,
|  | bool | hide )
| overridevirtual

Changes the visibility of a column.

See also
  isColumnHidden()

Reimplemented from Wt::WAbstractItemView.

## ◆ setColumnWidth()

virtual void Wt::WTreeView::setColumnWidth | ( | int | column,
|  | const WLength & | width )
| overridevirtual

Sets the column width.

For a model with columnCount() == `N`, the initial width of columns 1..`N` is set to 150 pixels, and column 0 will take all remaining space.

Note
  The actual space occupied by each column is the column width augmented by 7 pixels for internal padding and a border.

See also
  setRowHeight()

Implements Wt::WAbstractItemView.

## ◆ setCurrentPage()

virtual void Wt::WTreeView::setCurrentPage | ( | int | page | ) |
| overridevirtual

Sets the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This method can be used to change the current page.

See also
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

## ◆ setExpanded()

void Wt::WTreeView::setExpanded | ( | const WModelIndex & | ,
|  | bool | expanded )

Expands or collapses a node.

See also
  expand(), collapse()

## ◆ setHeaderHeight()

virtual void Wt::WTreeView::setHeaderHeight | ( | const WLength & | height | ) |
| overridevirtual

Sets the header height.

The default value is 20 pixels.

Note
  The height must be specified in LengthUnit::Pixel units.

Reimplemented from Wt::WAbstractItemView.

## ◆ setId()

virtual void Wt::WTreeView::setId | ( | const std::string & | id | ) |
| overridevirtual

Sets the CSS Id.

Sets a custom Id. Note that the Id must be unique across the whole widget tree, can only be set right after construction and cannot be changed. This is mostly useful for in tests using a test plan that manipulates DOM elements by Id.

By default, auto-generated id's are used.

Note
  An id must start with a letter ([A-Za-z]), followed by one or more letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Warning
  We recommend that you leave the id of a widget unchanged. Wt uses the id to identify widgets in the JavaScript it generates, and this can often leads to bugs. If you do change the id, only change the id right after widget construction. However, usually there's a more preferable alternative, like setting the object name (WObject::setObjectName), or adding style classes (WWidget::addStyleClass).

See also
  WObject::id()

Reimplemented from Wt::WCompositeWidget.

## ◆ setModel()

virtual void Wt::WTreeView::setModel | ( | const std::shared_ptr< WAbstractItemModel > & | model | ) |
| overridevirtual

Sets the model.

The View will display data of the given `model` and changes in the model are reflected by the View.

The initial model is `0`.

See also
  setRootIndex()

Reimplemented from Wt::WAbstractItemView.

## ◆ setRootIsDecorated()

void Wt::WTreeView::setRootIsDecorated | ( | bool | show | ) |

Sets whether toplevel items are decorated.

By default, top level nodes have expand/collapse and other lines to display their linkage and offspring, like any node.

By setting `show` to `false`, you can hide these decorations for root nodes, and in this way mimic a plain list. You could also consider using a WTableView instead.

## ◆ setRowHeaderCount()

virtual void Wt::WTreeView::setRowHeaderCount | ( | int | count | ) |
| overridevirtual

Configures the number of columns that are used as row headers.

An item view does not use the vertical header data from the model in any way, but instead you can configure data in the first column(s) to be used as a row headers.

These columns will not scroll horizontally together with the rest of the model.

The default value is 0.

Note
  Currently, this property must be set before any other settings of the view and only a value of 0 or 1 is supported.

Reimplemented from Wt::WAbstractItemView.

## ◆ setRowHeight()

virtual void Wt::WTreeView::setRowHeight | ( | const WLength & | rowHeight | ) |
| overridevirtual

Sets the row height.

The view renders all rows with a same height. This method configures this row height.

The default value is 20 pixels.

Note
  The height must be specified in LengthUnit::Pixel units.

See also
  setColumnWidth()

Reimplemented from Wt::WAbstractItemView.