Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions
Wt::WTableView Class Reference

An MVC View widget for tabular data. More...

#include <Wt/WTableView>

Inheritance diagram for Wt::WTableView:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WTableView (WContainerWidget *parent=0)
 Constructor.
virtual WWidgetitemWidget (const WModelIndex &index) const
 Returns the widget that renders an item.
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)
 Sets the header height.
virtual void setColumnBorder (const WColor &color)
 Sets the column border color.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
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.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.
- Public Member Functions inherited from Wt::WAbstractItemView
WAbstractItemModelmodel () const
 Returns the model.
void setRootIndex (const WModelIndex &rootIndex)
 Sets the root index.
const WModelIndexrootIndex () const
 Returns the root index.
void setItemDelegate (WAbstractItemDelegate *delegate)
 Sets the default item delegate.
WAbstractItemDelegateitemDelegate () const
 Returns the default item delegate.
void setItemDelegateForColumn (int column, WAbstractItemDelegate *delegate)
 Sets the delegate for a column.
WAbstractItemDelegateitemDelegateForColumn (int column) const
 Returns the delegate that was set for a column.
WAbstractItemDelegateitemDelegate (const WModelIndex &index) const
 Returns the delegate for rendering an item.
WAbstractItemDelegateitemDelegate (int column) const
 Returns the delegate for a column.
void setHeaderItemDelegate (WAbstractItemDelegate *delegate)
 Sets the header item delegate.
WAbstractItemDelegateheaderItemDelegate () 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 headerAlignment (int column) const
 Returns the horizontal header alignment for a column (deprecated).
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.
WItemSelectionModelselectionModel () const
 Returns the selection model.
void setSelectedIndexes (const WModelIndexSet &indexes)
 Sets the selected items.
void select (const WModelIndex &index, SelectionFlag option=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).
const WLengthrowHeight () 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.
void setHeaderHeight (const WLength &height, bool multiLine)
 Sets the header height, and vertical alignment (deprecated). By default, the header text is a single line that is centered vertically.
const WLengthheaderHeight () const
 Returns the header height.
void setEditTriggers (WFlags< EditTrigger > editTriggers)
 Configures what actions should trigger editing.
WFlags< EditTriggereditTriggers () const
 Returns the editing triggers.
void setEditOptions (WFlags< EditOption > options)
 Configures editing options.
WFlags< EditOptioneditOptions () 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.
WValidator::State validateEditor (const WModelIndex &index)
 Validates the editor for the given index.
WValidator::State 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 an item is clicked.
Signal< WModelIndex,
WMouseEvent > & 
doubleClicked ()
 Signal emitted when an item is 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.
SignalselectionChanged ()
 Signal emitted when the selection is changed.
SignalpageChanged ()
 Signal emitted when page information was updated.
Signal< int, WLength > & columnResized ()
 Returns the signal emitted when a column is resized by the user.
int rowHeaderCount () const
 Returns the number of columns that are used as row headers.
void setColumn1Fixed (bool enable)
 Configures whether horizontal scrolling includes the first column (deprecated)
bool column1Fixed () const
 Returns whether horizontal scrolling includes the first column. (deprecated)
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget (WContainerWidget *parent=0)
 Creates a WCompositeWidget.
 WCompositeWidget (WWidget *implementation, WContainerWidget *parent)
 Creates a WCompositeWidget with given implementation.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
virtual void setPositionScheme (PositionScheme scheme)
 Sets the CSS position scheme.
virtual PositionScheme positionScheme () const
 Returns the CSS position scheme.
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
 Sets CSS offsets for a non-statically positioned widget.
virtual WLength offset (Side s) const
 Returns a CSS offset.
virtual WLength width () const
 Returns the width.
virtual WLength height () const
 Returns the height.
virtual void setMinimumSize (const WLength &width, const WLength &height)
 Sets a minimum size.
virtual WLength minimumWidth () const
 Returns the minimum width.
virtual WLength minimumHeight () const
 Returns the minimum height.
virtual void setMaximumSize (const WLength &width, const WLength &height)
 Sets a maximum size.
virtual WLength maximumWidth () const
 Returns the maximum width.
virtual WLength maximumHeight () const
 Returns the maximum height.
virtual void setLineHeight (const WLength &height)
 Sets the CSS line height for contained text.
virtual WLength lineHeight () const
 Returns the CSS line height for contained text.
virtual void setFloatSide (Side s)
 Specifies a CSS float side.
virtual Side floatSide () const
 Returns the CSS float side.
virtual void setClearSides (WFlags< Side > sides)
 Sets the sides that should be cleared of floats.
virtual WFlags< SideclearSides () const
 Returns the sides that should remain empty.
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
 Sets CSS margins around the widget.
virtual WLength margin (Side side) const
 Returns a CSS margin set.
virtual void setHiddenKeepsGeometry (bool enabled)
 Sets whether the widget keeps its geometry when hidden.
virtual bool hiddenKeepsGeometry () const
 Returns whether the widget keeps its geometry when hidden.
virtual bool isHidden () const
 Returns whether the widget is set hidden.
virtual bool isVisible () const
 Returns whether the widget is visible.
virtual void setDisabled (bool disabled)
 Sets whether the widget is disabled.
virtual bool isDisabled () const
 Returns whether the widget is set disabled.
virtual bool isEnabled () const
 Returns whether the widget is enabled.
virtual void setPopup (bool popup)
 Lets the widget overlay over other sibling widgets.
virtual bool isPopup () const
 Returns whether the widget is overlayed.
virtual void setInline (bool isInline)
 Sets whether the widget is displayed inline or as a block.
virtual bool isInline () const
 Returns whether the widget is displayed inline or as block.
virtual void setDecorationStyle (const WCssDecorationStyle &style)
 Sets a CSS decoration style.
virtual WCssDecorationStyledecorationStyle ()
 Returns the decoration style of this widget.
virtual void setStyleClass (const WString &styleClass)
 Sets (one or more) CSS style classes.
virtual WString styleClass () const
 Returns the CSS style class.
virtual void addStyleClass (const WString &styleClass, bool force=false)
 Adds a CSS style class.
virtual void removeStyleClass (const WString &styleClass, bool force=false)
 Removes a CSS style class.
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto)
 Sets the vertical alignment.
virtual AlignmentFlag verticalAlignment () const
 Returns the vertical alignment.
virtual WLength verticalAlignmentLength () const
 Returns the fixed vertical alignment that was set.
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
 Sets a tooltip.
virtual WString toolTip () const
 Returns the tooltip.
virtual void refresh ()
 Refresh the widget.
virtual void setAttributeValue (const std::string &name, const WString &value)
 Sets an attribute value.
virtual WString attributeValue (const std::string &name) const
 Returns an attribute value.
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
 Sets a JavaScript member.
virtual std::string javaScriptMember (const std::string &name) const
 Returns the value of a JavaScript member.
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
 Calls a JavaScript member.
virtual void load ()
 Loads content just before the widget is used.
virtual bool loaded () const
 Returns whether this widget has been loaded.
virtual void setTabIndex (int index)
 Sets the tab index.
virtual int tabIndex () const
 Returns the tab index.
virtual void setId (const std::string &id)
 Sets the CSS Id.
virtual WWidgetfind (const std::string &name)
 Finds a descendent widget by name.
virtual void setSelectable (bool selectable)
 Sets as selectable.
virtual void doJavaScript (const std::string &js)
 Executes the given JavaScript statements when the widget is rendered or updated.
virtual void propagateSetEnabled (bool enabled)
 Propagates that a widget was enabled or disabled through children.
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 Destructor.
WWidgetparent () const
 Returns the parent widget.
void setWidth (const WLength &width)
 Sets the width.
void setHeight (const WLength &height)
 Sets the height.
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
 Positions a widget next to another widget.
std::string jsRef () const
 Returns a JavaScript expression to the corresponding DOM node.
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
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
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.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.
virtual void removeChild (WObject *child)
 Removes a child object.
const std::vector< WObject * > & children () const
 Returns the children.

Additional Inherited Members

- Public Types inherited from Wt::WAbstractItemView
enum  EditTrigger { NoEditTrigger = 0x0, SingleClicked = 0x1, DoubleClicked = 0x2, SelectedClicked = 0x4 }
 Enumeration that specifies the user action that triggers editing. More...
enum  EditOption { SingleEditor = 0x1, MultipleEditors = 0x2, SaveWhenClosed = 0x4, LeaveEditorsOpen = 0x8 }
 Enumeration that specifies editing options. More...
enum  ScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
 Enumeration that specifies a scrolling option. More...
- Protected Member Functions inherited from Wt::WAbstractItemView
 WAbstractItemView (WContainerWidget *parent=0)
 Creates a new item view.
virtual void dropEvent (const WDropEvent &event, const WModelIndex &target)
 Handles a drop event (drag & drop).
virtual WWidgetcreateExtraHeaderWidget (int column)
 Create an extra widget in the header.
WWidgetextraHeaderWidget (int column)
 Returns the extra header widget.
virtual WWidgetcreatePageNavigationBar ()
 Returns a page navigation widget.
- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.
void setImplementation (WWidget *widget)
 Set the implementation widget.
WWidgetimplementation ()
 Get the implementation widget.
virtual int boxPadding (Orientation orientation) const
 Returns the widget's built-in padding.
virtual int boxBorder (Orientation orientation) const
 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 (WContainerWidget *parent=0)
 Creates a widget.
virtual void dropEvent (WDropEvent dropEvent)
 Handles a drop event.
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.

Detailed Description

An MVC View widget for tabular data.

The view displays data from a WAbstractItemModel in a table. It provides incremental rendering, 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 provides virtual scrolling in both horizontal and vertical directions, and can therefore be used to display large data models (with large number of columns and rows).

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 columns are given a width of 150px. Column widths of all columns can be set through the API method setColumnWidth(), and also by the user using handles provided in the header.

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 view 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.

CSS

The tableview is styled by the current CSS theme. The look can be overridden using the Wt-tableview CSS class and the following selectors.

Selectors that apply to the body:

 .Wt-tableview .Wt-tv-contents : the main div used when javascript is available
 .Wt-tableview .Wt-plaintable  : the main table used when no javascript is 
                                 available
 .Wt-tableview .Wt-pagingbar   : the paging bar

Selectors that apply to the header:

 .Wt-tableview .Wt-header      : header background div
 .Wt-tableview .Wt-headertable : div in the .Wt-header div to enable the 
                                 header scrolling
 .Wt-tableview .Wt-label       : header label
 .Wt-tableview .Wt-tv-rh       : column resize handle
 .Wt-tableview .Wt-tv-sh-up    : column sort handle, no sorting
 .Wt-tableview .Wt-tv-sh-none  : column sort handle, sort up
 .Wt-tableview .Wt-tv-sh-down  : column sort handle, sort down
 .Wt-tableview .Wt-tv-br             : header border

Selectors that apply to the table contents:

 .Wt-tableview .Wt-spacer      : spacer for non-loaded content
 .Wt-tableview .Wt-selected    : selected item
 .Wt-tableview .Wt-drop-site   : possible drop site
 .Wt-tableview .Wt-tv-c        : cell style

Member Function Documentation

int Wt::WTableView::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).

See also:
createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

WWidget * Wt::WTableView::itemWidget ( const WModelIndex index) const
virtual

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.

int Wt::WTableView::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.

See also:
createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

int Wt::WTableView::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.

See also:
createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

void Wt::WTableView::resize ( const WLength width,
const WLength height 
)
virtual

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.

See also:
width(), height()

Reimplemented from Wt::WCompositeWidget.

void Wt::WTableView::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).

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

Implements Wt::WAbstractItemView.

void Wt::WTableView::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.

void Wt::WTableView::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::WTableView::setColumnHidden ( int  column,
bool  hide 
)
virtual

Changes the visibility of a column.

See also:
isColumnHidden()

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setColumnWidth ( int  column,
const WLength width 
)
virtual

Sets the column width.

The default column width is 150 pixels.

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

Implements Wt::WAbstractItemView.

void Wt::WTableView::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.

See also:
createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

void Wt::WTableView::setHeaderHeight ( const WLength height)
virtual

Sets the header height.

The default value is 20 pixels.

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setHidden ( bool  hidden,
const WAnimation animation = WAnimation() 
)
virtual

Hides or shows the widget.

Hides or show the widget (including all its descendant widgets). When setting hidden = false, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked using isVisible().

Reimplemented from Wt::WCompositeWidget.

void Wt::WTableView::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.

See also:
setRootIndex()

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::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(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.

void Wt::WTableView::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.

Note:
The height must be specified in WLength::Pixel units.
See also:
setColumnWidth()

Reimplemented from Wt::WAbstractItemView.


Generated on Sun May 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1