#include <Wt/WTreeView>
Public Member Functions | |
WTreeView (WContainerWidget *parent) | |
Create a new tree view. | |
~WTreeView () | |
Destructor. | |
void | setModel (WAbstractItemModel *model) |
Set the model. | |
WAbstractItemModel * | model () const |
Returns the model. | |
void | setRootIndex (const WModelIndex &rootIndex) |
Set the root index. | |
const WModelIndex & | rootIndex () const |
Returns the root index. | |
void | setHeaderHeight (const WLength &height) |
Set the row height. | |
const WLength & | headerHeight () const |
Return the header height. | |
void | setRowHeight (const WLength &rowHeight) |
Set the row height. | |
const WLength & | rowHeight () const |
Return the row height. | |
void | setColumnWidth (int column, const WLength &width) |
Set the column width. | |
WLength | columnWidth (int column) const |
Returns the column width. | |
void | setColumnAlignment (int column, HorizontalAlignment alignment) |
Set the content alignment for a column. | |
HorizontalAlignment | columnAlignment (int column) const |
Returns the content alignment for a column. | |
void | setImagePack (const std::string &uri) |
Sets the base urls for icons. | |
std::string | imagePack () const |
Returns the base url for icons. | |
void | setExpanded (const WModelIndex &, bool expanded) |
Expand or collapse a node. | |
bool | isExpanded (const WModelIndex &index) const |
Returns whether a node is expanded. | |
void | collapse (const WModelIndex &index) |
Collapse a node. | |
void | expand (const WModelIndex &index) |
Expand a node. | |
void | setAlternatingRowColors (bool enable) |
Set if alternating row colors are to be used. | |
bool | alternatingRowColors () const |
Returns whether alternating row colors are used. | |
void | setRootIsDecorated (bool show) |
Set whether toplevel items are decorated. | |
bool | rootIsDecorated () const |
Returns whether toplevel items are decorated. | |
void | sortByColumn (int column, SortOrder order) |
Sort the data according to a column. | |
void | setSortingEnabled (bool enabled) |
Enable sorting. | |
bool | isSortingEnabled () const |
Returns whether sorting is enabled. | |
void | setSelectionBehavior (SelectionBehavior behavior) |
Change the selection behaviour. | |
SelectionBehavior | selectionBehavior () const |
Returns the selection behaviour. | |
void | setSelectionMode (SelectionMode mode) |
Set the selection mode. | |
SelectionMode | selectionMode () const |
Returns the selection mode. | |
void | setSelectedIndexes (const WModelIndexSet &indexes) |
Sets the selected items. | |
void | select (const WModelIndex &index, SelectionFlag option=Select) |
Select a single item. | |
bool | isSelected (const WModelIndex &index) const |
Returns wheter an item is selected. | |
WModelIndexSet | selectedIndexes () const |
Returns the set of selected items. | |
virtual void | resize (const WLength &width, const WLength &height) |
Resize the widget. | |
virtual void | load () |
Load content just before the widget's content is rendered. | |
Public Attributes | |
Signal< WModelIndex > | collapsed |
Signal emitted when a node is collapsed. | |
Signal< WModelIndex > | expanded |
Signal emitted when a node is expanded. | |
Signal< WModelIndex > | clicked |
Signal emitted when an item is clicked. | |
Signal< WModelIndex > | doubleClicked |
Signal emitted when an item is double clicked. | |
Signal< void > | selectionChanged |
Signal emitted when the selection is changed. |
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. Data of all predefined roles is displayed (see also ItemDataRole), including text, icons, checkboxes, and tooltips .
By default, all but the first columns are given a width of 150px, and the first column takes the remaining size. This can be changed through the API (setColumnWidth(), and also by the user using handles provided in the header.
If the model supports sorting (WAbstractItemModel::sort()), 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 also react to mouse click events on any item, by connecting to one of the clicked or doubleClicked signals.
void Wt::WTreeView::setModel | ( | WAbstractItemModel * | model | ) |
Set the model.
The view will render the data in the given model. Changes to the model are reflected in the view.
When resetting a model, all nodes are initially collapsed, the selection is cleared, and the root index corresponds to the model's top level node (see setRootIndex()).
The initial model is 0.
Ownership of the model is not transferred (and thus the previously set model is not deleted).
WAbstractItemModel* Wt::WTreeView::model | ( | ) | const [inline] |
void Wt::WTreeView::setRootIndex | ( | const WModelIndex & | rootIndex | ) |
Set the root index.
The root index is the model index that is considered the root node. This node itself is not rendered, but all its children are the top level nodes.
The default value is WModelIndex(), corresponding to the invisible root.
const WModelIndex& Wt::WTreeView::rootIndex | ( | ) | const [inline] |
void Wt::WTreeView::setHeaderHeight | ( | const WLength & | height | ) |
Set the row height.
The view assumes that all rows are of the same height. Use this method to set the height.
The default value is 20 pixels.
const WLength& Wt::WTreeView::headerHeight | ( | ) | const [inline] |
void Wt::WTreeView::setRowHeight | ( | const WLength & | rowHeight | ) |
Set the row height.
The view assumes that all rows are of the same height. Use this method to set the height.
The default value is 20 pixels.
void Wt::WTreeView::setColumnWidth | ( | int | column, | |
const WLength & | width | |||
) |
Set the column width.
You can specify the column width for all columns, except for the first column.
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.
WLength Wt::WTreeView::columnWidth | ( | int | column | ) | const |
void Wt::WTreeView::setColumnAlignment | ( | int | column, | |
HorizontalAlignment | alignment | |||
) |
Set the content alignment for a column.
The default value is AlignLeft.
HorizontalAlignment Wt::WTreeView::columnAlignment | ( | int | column | ) | const |
void Wt::WTreeView::setImagePack | ( | const std::string & | uri | ) |
Sets the base urls for icons.
This widget relies on several icons that are distributed together with Wt for drawing icons, lines, and backgrounds.
The default location for the image pack is resourcesURL.
The default value for resourcesURL is "resources/". This value may be overridden with a URL that points to a folder where these files are located, by configuring the resourcesURL property in your Wt configuration file.
std::string Wt::WTreeView::imagePack | ( | ) | const [inline] |
void Wt::WTreeView::setExpanded | ( | const WModelIndex & | , | |
bool | expanded | |||
) |
bool Wt::WTreeView::isExpanded | ( | const WModelIndex & | index | ) | const |
void Wt::WTreeView::collapse | ( | const WModelIndex & | index | ) |
void Wt::WTreeView::expand | ( | const WModelIndex & | index | ) |
void Wt::WTreeView::setAlternatingRowColors | ( | bool | enable | ) |
Set if alternating row colors are to be used.
Configure whether rows get an alternating background color. These are implemented by using a background image on the root node, like:
Sample image use for alternating row colors
The default value is false.
bool Wt::WTreeView::alternatingRowColors | ( | ) | const [inline] |
void Wt::WTreeView::setRootIsDecorated | ( | bool | show | ) |
Set 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.
bool Wt::WTreeView::rootIsDecorated | ( | ) | const [inline] |
void Wt::WTreeView::sortByColumn | ( | int | column, | |
SortOrder | order | |||
) |
Sort the data according to a column.
Sorts the data according to data in column column and sort order order.
void Wt::WTreeView::setSortingEnabled | ( | bool | enabled | ) |
Enable sorting.
Enable or disable sorting by the user.
Sorting is enabled by default.
bool Wt::WTreeView::isSortingEnabled | ( | ) | const [inline] |
void Wt::WTreeView::setSelectionBehavior | ( | SelectionBehavior | behavior | ) |
Change the selection behaviour.
By default, selection operates on rows (SelectRows), in which case model indexes will always be in the first column (column 0).
Alternatively, you can allow selection for individual items (SelectItems).
SelectionBehavior Wt::WTreeView::selectionBehavior | ( | ) | const [inline] |
void Wt::WTreeView::setSelectionMode | ( | SelectionMode | mode | ) |
Set the selection mode.
By default selection is disabled (NoSelection ).
SelectionMode Wt::WTreeView::selectionMode | ( | ) | const [inline] |
void Wt::WTreeView::setSelectedIndexes | ( | const WModelIndexSet & | indexes | ) |
void Wt::WTreeView::select | ( | const WModelIndex & | index, | |
SelectionFlag | option = Select | |||
) |
bool Wt::WTreeView::isSelected | ( | const WModelIndex & | index | ) | const |
WModelIndexSet Wt::WTreeView::selectedIndexes | ( | ) | const [inline] |
Returns the set of selected items.
The model indexes are returned as a set, topologically ordered (in the order they appear in the view).
Resize 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.
Reimplemented from Wt::WCompositeWidget.
virtual void Wt::WTreeView::load | ( | ) | [virtual] |
Load content just before the widget's content is rendered.
As soon as a widget is inserted into the widget hierarchy, it is rendered. Visible widgets are rendered immediately, and invisible widgets in the back-ground. This method is called when the widget is directly or indirectly inserted into the widget tree.
The default implementation simply propagates the load signal to its children. You may want to override this method to load resource-intensive content only when the widget is loaded into the browser.
Reimplemented from Wt::WCompositeWidget.
Signal emitted when the selection is changed.