A view class that displays a model as a tree or tree table. More...
#include <Wt/WTreeView>
Public Member Functions | |
WTreeView (WContainerWidget *parent=0) | |
Creates a new tree view. | |
void | setColumnFormat (int column, const WString &format) |
Sets the column format string (deprecated). | |
WString | columnFormat (int column) const |
Returns the column format string (deprecated). | |
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 | 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) |
Resizes the widget. | |
Signal< WModelIndex > & | collapsed () |
Signal emitted when a node is collapsed. | |
Signal< WModelIndex > & | expanded () |
Signal emitted when a node is expanded. | |
virtual void | setModel (WAbstractItemModel *model) |
Sets the model. | |
virtual void | setColumnWidth (int column, const WLength &width) |
Sets the column width. | |
virtual void | setAlternatingRowColors (bool enable) |
Sets if alternating row colors are to be used. | |
virtual void | setRowHeight (const WLength &rowHeight) |
Sets the row height. | |
virtual void | setHeaderHeight (const WLength &height, bool multiLine=false) |
Sets the header height. | |
virtual void | setColumnBorder (const WColor &color) |
Sets the column border color. | |
virtual void | setColumnHidden (int column, bool hidden) |
Changes the visibility of a column. | |
virtual void | setRowHeaderCount (int count) |
Configures the number of columns that are used as row headers. | |
virtual int | pageCount () const |
Returns the number of pages. | |
virtual int | pageSize () const |
Returns the page size. | |
virtual int | currentPage () const |
Returns the current page. | |
virtual void | setCurrentPage (int page) |
Sets the current page. | |
virtual void | scrollTo (const WModelIndex &index, ScrollHint hint=EnsureVisible) |
Scrolls the view to an item. | |
Protected Member Functions | |
virtual void | enableAjax () |
Progresses to an Ajax-enabled widget. |
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::ItemIsEditable 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, whith 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 ItemIsDragEnabled 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 ItemIsDropEnabled 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 Wt::WAbstractItemModel *model = ... // Create the WTreeView Wt::WTreeView *gitView = new Wt::WTreeView(); gitView->resize(300, Wt::WLength::Auto); gitView->setSortingEnabled(false); gitView->setModel(model); gitView->setSelectionMode(SingleSelection);
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.
The treeview is styled by the current CSS theme. The look can be overridden using the Wt-treeview
CSS class and the following selectors.
Selectors that apply to the body
.Wt-treeview .Wt-pagingbar : paging bar
Selectors that apply to the header:
.Wt-treeview .Wt-headerdiv : header (background) .Wt-treeview .Wt-header .Wt-label : header label .Wt-treeview .Wt-tv-rh : column resize handle .Wt-treeview .Wt-tv-sh-none : column sort handle, no sorting .Wt-treeview .Wt-tv-sh-up : column sort handle, sort up .Wt-treeview .Wt-tv-sh-down : column sort handle, sort down .Wt-treeview .Wt-tv-br : header border
Selectors that apply to the tree decoration:
.Wt-treeview .Wt-trunk : vertical line, trunk .Wt-treeview .Wt-end : vertical line, last item .Wt-treeview .Wt-collapse : collapse icon .Wt-treeview .Wt-expand : expand icon .Wt-treeview .Wt-noexpand : leaf icon
Selectors that apply to the table contents:
.Wt-treeview .Wt-spacer : spacer for non-loaded content .Wt-treeview .Wt-selected : selected item .Wt-treeview .Wt-drop-site : possible drop site
Selectors that apply to the table borders (which must be 1 pixel wide)
.Wt-treeview .Wt-tv-row .Wt-tv-c : border-right property of cells .Wt-treeview .Wt-header .Wt-tv-row, .Wt-treeview .Wt-tv-node .Wt-tv-row : border-left property of cells
A snapshot of the WTreeView:
WTreeView example (default)
WTreeView example (polished)
void Wt::WTreeView::collapse | ( | const WModelIndex & | index ) |
Collapses a node.
Signal<WModelIndex>& Wt::WTreeView::collapsed | ( | ) |
Signal emitted when a node is collapsed.
WString Wt::WTreeView::columnFormat | ( | int | column ) | const |
Returns the column format string (deprecated).
virtual int Wt::WTreeView::currentPage | ( | ) | const [virtual] |
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).
Implements Wt::WAbstractItemView.
virtual void Wt::WTreeView::enableAjax | ( | ) | [protected, virtual] |
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.
Reimplemented from Wt::WCompositeWidget.
void Wt::WTreeView::expand | ( | const WModelIndex & | index ) |
Expands a node.
Signal<WModelIndex>& Wt::WTreeView::expanded | ( | ) |
Signal emitted when a node is expanded.
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.
bool Wt::WTreeView::isExpanded | ( | const WModelIndex & | index ) | const |
Returns whether a node is expanded.
virtual int Wt::WTreeView::pageCount | ( | ) | const [virtual] |
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.
Implements Wt::WAbstractItemView.
virtual int Wt::WTreeView::pageSize | ( | ) | const [virtual] |
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.
Implements Wt::WAbstractItemView.
Resizes the widget.
Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength::isAuto().
This applies to CSS-based layout, and only block widgets can be given a size reliably.
When inserted in a layout manager, the widget may be informed about its current size using setLayoutSizeAware(). If you have defined a "wtResize()"
JavaScript method for the widget, then this method will also be called. operation.
Reimplemented from Wt::WCompositeWidget.
bool Wt::WTreeView::rootIsDecorated | ( | ) | const |
Returns whether toplevel items are decorated.
virtual void Wt::WTreeView::scrollTo | ( | const WModelIndex & | index, |
ScrollHint | hint = EnsureVisible |
||
) | [virtual] |
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).
Implements Wt::WAbstractItemView.
virtual void Wt::WTreeView::setAlternatingRowColors | ( | bool | enable ) | [virtual] |
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.
virtual void Wt::WTreeView::setColumnBorder | ( | const WColor & | color ) | [virtual] |
Sets the column border color.
The default border color is defined by the CSS theme.
Implements Wt::WAbstractItemView.
void Wt::WTreeView::setColumnFormat | ( | int | column, |
const WString & | format | ||
) |
Sets the column format string (deprecated).
The DisplayRole data for that column is converted to a string using asString(), with the given format.
The default value is "".
virtual void Wt::WTreeView::setColumnHidden | ( | int | column, |
bool | hide | ||
) | [virtual] |
Changes the visibility of a column.
Reimplemented from Wt::WAbstractItemView.
virtual void Wt::WTreeView::setColumnWidth | ( | int | column, |
const WLength & | width | ||
) | [virtual] |
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.
Implements Wt::WAbstractItemView.
virtual void Wt::WTreeView::setCurrentPage | ( | int | page ) | [virtual] |
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.
Implements Wt::WAbstractItemView.
void Wt::WTreeView::setExpanded | ( | const WModelIndex & | , |
bool | expanded | ||
) |
Expands or collapses a node.
virtual void Wt::WTreeView::setHeaderHeight | ( | const WLength & | height, |
bool | multiLine = false |
||
) | [virtual] |
Sets the header height.
Use this method to change the header height. By default, the header text is a single line that is centered vertically.
By enabling multi-line headers, the header text will be aligned to the top and wrap as needed. In that case, additional contents may be displayed in the header, provided by createExtraHeaderWidget().
The default value is a single line of 20 pixels.
Reimplemented from Wt::WAbstractItemView.
virtual void Wt::WTreeView::setModel | ( | WAbstractItemModel * | model ) | [virtual] |
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
.
Ownership of the model is not transferred (and thus the previously set model is not deleted). A model may not be deleted as long as a view exists for it.
Reimplemented from Wt::WAbstractItemView.
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.
virtual void Wt::WTreeView::setRowHeaderCount | ( | int | count ) | [virtual] |
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 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.
Reimplemented from Wt::WAbstractItemView.
virtual void Wt::WTreeView::setRowHeight | ( | const WLength & | rowHeight ) | [virtual] |
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.
Reimplemented from Wt::WAbstractItemView.