Wt  3.2.2
Public Member Functions
Wt::WBatchEditProxyModel Class Reference

A proxy model for Wt's item models that provides batch editing. More...

#include <Wt/WBatchEditProxyModel>

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

List of all members.

Public Member Functions

 WBatchEditProxyModel (WObject *parent=0)
 Constructor.
virtual ~WBatchEditProxyModel ()
 Destructor.
bool isDirty () const
 Returns whether changes have not yet been committed.
void commitAll ()
 Commits changes.
void revertAll ()
 Reverts changes.
void setNewRowData (int column, const boost::any &data, int role=DisplayRole)
 Sets default data for a newly inserted row.
void setNewRowFlags (int column, WFlags< ItemFlag > flags)
 Sets the item flags for items in a newly inserted row.
void setDirtyIndication (int role, const boost::any &data)
 Configures data used to indicate a modified item.
virtual WModelIndex mapFromSource (const WModelIndex &sourceIndex) const
 Maps a source model index to the proxy model.
virtual WModelIndex mapToSource (const WModelIndex &proxyIndex) const
 Maps a proxy model index to the source model.
virtual void setSourceModel (WAbstractItemModel *sourceModel)
 Sets the source model.
virtual int columnCount (const WModelIndex &parent=WModelIndex()) const
 Returns the number of columns.
virtual int rowCount (const WModelIndex &parent=WModelIndex()) const
 Returns the number of rows.
virtual WModelIndex parent (const WModelIndex &index) const
 Returns the parent for a model index.
virtual WModelIndex index (int row, int column, const WModelIndex &parent=WModelIndex()) const
 Returns the child index for the given row and column.
virtual boost::any data (const WModelIndex &index, int role=DisplayRole) const
 Returns data at a specific model index.
virtual bool setData (const WModelIndex &index, const boost::any &value, int role=EditRole)
 Sets item data.
virtual WFlags< ItemFlagflags (const WModelIndex &index) const
 Returns the flags for an item.
virtual boost::any headerData (int section, Orientation orientation=Horizontal, int role=DisplayRole) const
 Returns the row or column header data.
virtual bool insertRows (int row, int count, const WModelIndex &parent=WModelIndex())
 Inserts one or more rows.
virtual bool removeRows (int row, int count, const WModelIndex &parent=WModelIndex())
 Removes rows.
virtual bool insertColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Inserts one or more columns.
virtual bool removeColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Removes columns.
virtual void sort (int column, SortOrder order=AscendingOrder)
 Sorts the model according to a particular column.

Detailed Description

A proxy model for Wt's item models that provides batch editing.

This proxy model presents data from a source model, and caches any editing operation without affecting the underlying source model, until commitAll() or revertAll() is called. In this way, you can commit all the editing in batch to the underlying source model, only when the user confirms the changes.

All editing operations are supported:

The model supports both simple tabular models, as well as hierarchical (tree-like / treetable-like) models, with children under items in the first column.

Default values for a newly inserted row can be set using setNewRowData() and flags for its items using setNewRowFlags().


Member Function Documentation

int Wt::WBatchEditProxyModel::columnCount ( const WModelIndex parent = WModelIndex()) const [virtual]

Returns the number of columns.

This returns the number of columns at index parent.

See also:
rowCount()

Implements Wt::WAbstractItemModel.

void Wt::WBatchEditProxyModel::commitAll ( )

Commits changes.

This commits all changes to the source model.

See also:
revertAll()
boost::any Wt::WBatchEditProxyModel::data ( const WModelIndex index,
int  role = DisplayRole 
) const [virtual]

Returns data at a specific model index.

Return data for a given role at a given index.

You should check the role to decide what data to return. Usually a View class will ask for data for several roles which affect not only the contents (Wt::DisplayRole) but also icons (Wt::DecorationRole), URLs (Wt::LinkRole), and other visual aspects. If your item does not specify data for a particular role, it should simply return a boost::any().

See also:
flags(), headerData(), setData()

Implements Wt::WAbstractItemModel.

WFlags< ItemFlag > Wt::WBatchEditProxyModel::flags ( const WModelIndex index) const [virtual]

Returns the flags for an item.

The default implementation returns ItemIsSelectable.

See also:
Wt::ItemFlag

Reimplemented from Wt::WAbstractItemModel.

boost::any Wt::WBatchEditProxyModel::headerData ( int  section,
Orientation  orientation = Horizontal,
int  role = DisplayRole 
) const [virtual]

Returns the row or column header data.

When orientation is Horizontal, section is a column number, when orientation is Vertical, section is a row number.

See also:
data(), setHeaderData()

Reimplemented from Wt::WAbstractItemModel.

WModelIndex Wt::WBatchEditProxyModel::index ( int  row,
int  column,
const WModelIndex parent = WModelIndex() 
) const [virtual]

Returns the child index for the given row and column.

When implementing this method, you can use createIndex() to create an index that corresponds to the item at row and column within parent.

If the location is invalid (out of bounds at the parent), then an invalid index must be returned.

See also:
parent()

Implements Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::insertColumns ( int  column,
int  count,
const WModelIndex parent = WModelIndex() 
) [virtual]

Inserts one or more columns.

In models that support column insertion, this inserts count columns, starting at column, and returns true if the operation was successful. The new columns are inserted under parent.

The default implementation returns false.

The model implementation must call beginInsertColumns() and endInsertColumns() before and after the operation whenever its geometry is changed by inserting columns. This emits signals for views to properly react to these changes.

See also:
insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()

Reimplemented from Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::insertRows ( int  row,
int  count,
const WModelIndex parent = WModelIndex() 
) [virtual]

Inserts one or more rows.

In models that support row insertion, this inserts count rows, starting at row, and returns true if the operation was successful. The new rows are inserted under parent.

If parent had no children, then a single column is added with count rows.

The default implementation returns false.

The model implementation must call beginInsertRows() and endInsertRows() before and after the operation whenever its geometry is changed by inserting rows. This emits signals for views to properly react to these changes.

See also:
insertColumns(), removeRows(), beginInsertRows(), endInsertRows()

Reimplemented from Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::isDirty ( ) const

Returns whether changes have not yet been committed.

Returns whether have been made to the proxy model, which could be committed using commitAll() or reverted using revertAll().

WModelIndex Wt::WBatchEditProxyModel::mapFromSource ( const WModelIndex sourceIndex) const [virtual]

Maps a source model index to the proxy model.

This method returns a model index in the proxy model that corresponds to the model index sourceIndex in the source model. This method must only be implemented for source model indexes that are mapped and thus are the result of mapToSource().

See also:
mapToSource()

Implements Wt::WAbstractProxyModel.

WModelIndex Wt::WBatchEditProxyModel::mapToSource ( const WModelIndex proxyIndex) const [virtual]

Maps a proxy model index to the source model.

This method returns a model index in the source model that corresponds to the proxy model index proxyIndex.

See also:
mapFromSource()

Implements Wt::WAbstractProxyModel.

WModelIndex Wt::WBatchEditProxyModel::parent ( const WModelIndex index) const [virtual]

Returns the parent for a model index.

An implementation should use createIndex() to create a model index that corresponds to the parent of a given index.

Note that the index itself may be stale (referencing a row/column within the parent that is outside the model geometry), but its parent (identified by the WModelIndex::internalPointer()) is referencing an existing parent. A stale index can only be used while the model geometry is being updated, i.e. during the emission of the corresponding [rows/columns](Being)[Removed/Inserted]() signals.

See also:
index()

Implements Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::removeColumns ( int  column,
int  count,
const WModelIndex parent = WModelIndex() 
) [virtual]

Removes columns.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must call beginRemoveColumns() and endRemoveColumns() before and after the operation whenever its geometry is changed by removing columns. This emits signals for views to properly react to these changes.

See also:
removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()

Reimplemented from Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::removeRows ( int  row,
int  count,
const WModelIndex parent = WModelIndex() 
) [virtual]

Removes rows.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must call beginRemoveRows() and endRemoveRows() before and after the operation whenever its geometry is changed by removing rows. This emits signals for views to properly react to these changes.

See also:
removeColumns(), insertRows(), beginRemoveRows(), endRemoveRows()

Reimplemented from Wt::WAbstractItemModel.

void Wt::WBatchEditProxyModel::revertAll ( )

Reverts changes.

This reverts all changes.

See also:
commitAll()
int Wt::WBatchEditProxyModel::rowCount ( const WModelIndex parent = WModelIndex()) const [virtual]

Returns the number of rows.

This returns the number of rows at index parent.

See also:
columnCount()

Implements Wt::WAbstractItemModel.

bool Wt::WBatchEditProxyModel::setData ( const WModelIndex index,
const boost::any &  value,
int  role = EditRole 
) [virtual]

Sets item data.

The default implementation will copy Wt::EditRole data to Wt::DisplayRole. You may want to specialize the model to provide a more specialized editing behaviour.

Reimplemented from Wt::WAbstractItemModel.

void Wt::WBatchEditProxyModel::setDirtyIndication ( int  role,
const boost::any &  data 
)

Configures data used to indicate a modified item.

This sets data for item data role role to be returned by data() for an item that is dirty (e.g. because it belongs to a newly inserted row/column, or because new data has been set for it.

When role is Wt::StyleClassRole, the style class is appended to any style already returned by the source model or set by setNewRowData().

By default there is no dirty indication.

void Wt::WBatchEditProxyModel::setNewRowData ( int  column,
const boost::any &  data,
int  role = DisplayRole 
)

Sets default data for a newly inserted row.

You can use this method to initialize data for a newly inserted row.

void Wt::WBatchEditProxyModel::setNewRowFlags ( int  column,
WFlags< ItemFlag flags 
)

Sets the item flags for items in a newly inserted row.

By default, flags() will return ItemIsSelectable.

void Wt::WBatchEditProxyModel::setSourceModel ( WAbstractItemModel sourceModel) [virtual]

Sets the source model.

The source model provides the actual data for the proxy model.

Ownership of the source model is not transferred.

Reimplemented from Wt::WAbstractProxyModel.

void Wt::WBatchEditProxyModel::sort ( int  column,
SortOrder  order = AscendingOrder 
) [virtual]

Sorts the model according to a particular column.

If the model supports sorting, then it should emit the layoutAboutToBeChanged() signal, rearrange its items, and afterwards emit the layoutChanged() signal.

See also:
layoutAboutToBeChanged(), layoutChanged()

Reimplemented from Wt::WAbstractItemModel.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Jul 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1