Public Member Functions | Protected Member Functions

Wt::WAbstractProxyModel Class Reference
[Model/view system]

An abstract proxy model for Wt's item models. More...

#include <Wt/WAbstractProxyModel>

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

List of all members.

Public Member Functions

 WAbstractProxyModel (WObject *parent=0)
 Constructor.
virtual WModelIndex mapFromSource (const WModelIndex &sourceIndex) const =0
 Maps a source model index to the proxy model.
virtual WModelIndex mapToSource (const WModelIndex &proxyIndex) const =0
 Maps a proxy model index to the source model.
virtual void setSourceModel (WAbstractItemModel *sourceModel)
 Sets the source model.
WAbstractItemModelsourceModel () const
 Returns the source model.
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 data at the given model index.
virtual WFlags< ItemFlagflags (const WModelIndex &index) const
 Returns the flags for an item.
virtual bool insertColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Inserts one or more columns.
virtual bool insertRows (int row, int count, const WModelIndex &parent=WModelIndex())
 Inserts one or more rows.
virtual bool removeColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Removes columns.
virtual bool removeRows (int row, int count, const WModelIndex &parent=WModelIndex())
 Removes rows.
virtual std::string mimeType () const
 Returns a mime-type for dragging a set of indexes.
virtual std::vector< std::string > acceptDropMimeTypes () const
 Returns a list of mime-types that could be accepted for a drop event.
virtual void dropEvent (const WDropEvent &e, DropAction action, int row, int column, const WModelIndex &parent)
 Handles a drop event.
virtual void * toRawIndex (const WModelIndex &index) const
 Converts a model index to a raw pointer that remains valid while the model's layout is changed.
virtual WModelIndex fromRawIndex (void *rawIndex) const
 Converts a raw pointer to a model index.

Protected Member Functions

WModelIndex createSourceIndex (int row, int column, void *ptr) const
 Create a source model index.

Detailed Description

An abstract proxy model for Wt's item models.

A proxy model does not store data, but presents data from a source model in another way. It may provide filtering, sorting, or other computed changes to the source model. A proxy model may be a fully functional model, that also allows modification of the underlying model.

This abstract proxy model may be used as a starting point for implementing a custom proxy model, when WSortFilterProxyModel is not adequate. It implements data access and manipulation using the a virtual mapping method (mapToSource()) to access and manipulate the underlying sourceModel().


Member Function Documentation

std::vector< std::string > Wt::WAbstractProxyModel::acceptDropMimeTypes (  ) const [virtual]

Returns a list of mime-types that could be accepted for a drop event.

The default implementation only accepts drag&drop support between abstract item models.

See also:
mimeType()

Reimplemented from Wt::WAbstractItemModel.

WModelIndex Wt::WAbstractProxyModel::createSourceIndex ( int  row,
int  column,
void *  ptr 
) const [protected]

Create a source model index.

This is a utility function that allows you to create indexes in the source model. In this way, you can reuse the internal pointers of the source model in proxy model indexes, and convert a proxy model index back to the source model index using this method.

boost::any Wt::WAbstractProxyModel::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.

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

Implements Wt::WAbstractItemModel.

void Wt::WAbstractProxyModel::dropEvent ( const WDropEvent e,
DropAction  action,
int  row,
int  column,
const WModelIndex parent 
) [virtual]

Handles a drop event.

The default implementation only handles generic drag&drop between abstract item models. Source item data is copied (but not the source item's flags).

The location in the model is indicated by the row and column within the parent index. If row is -1, then the item is appended to the parent. Otherwise, the item is inserted at or copied over the indicated item (and subsequent rows). When action is a MoveAction, the original items are deleted from the source model.

You may want to reimplement this method if you want to handle other mime-type data, or if you want to refine how the drop event of an item selection must be interpreted.

Note:
Currently, only row selections are handled by the default implementation.
See also:
mimeType(), WItemSelectionModel

Reimplemented from Wt::WAbstractItemModel.

WFlags< ItemFlag > Wt::WAbstractProxyModel::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.

WModelIndex Wt::WAbstractProxyModel::fromRawIndex ( void *  rawIndex ) const [virtual]

Converts a raw pointer to a model index.

Use this method to create model index from temporary raw pointers. It is the reciproce method of toRawIndex().

You can return an invalid modelindex if the rawIndex no longer points to a valid item because of the layout change.

See also:
toRawIndex()

Reimplemented from Wt::WAbstractItemModel.

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

Inserts one or more columns.

Returns true if the operation was successful.

The default implementation returns false. If you reimplement this method, then you must call beginInsertColumns() and endInsertColumns() before and after the operation.

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

Reimplemented from Wt::WAbstractItemModel.

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

Inserts one or more rows.

Returns true if the operation was successful. If you reimplement this method, then you must call beginInsertRows() and endInsertRows() before and after the operation.

The default implementation returns false.

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

Reimplemented from Wt::WAbstractItemModel.

virtual WModelIndex Wt::WAbstractProxyModel::mapFromSource ( const WModelIndex sourceIndex ) const [pure 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()

Implemented in Wt::WAggregateProxyModel, and Wt::WSortFilterProxyModel.

virtual WModelIndex Wt::WAbstractProxyModel::mapToSource ( const WModelIndex proxyIndex ) const [pure 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()

Implemented in Wt::WAggregateProxyModel, and Wt::WSortFilterProxyModel.

std::string Wt::WAbstractProxyModel::mimeType (  ) const [virtual]

Returns a mime-type for dragging a set of indexes.

This method returns a mime-type that describes dragging of a selection of items.

The drop event will indicate a selection model for this abstract item model as source.

The default implementation returns a mime-type for generic drag&drop support between abstract item models.

See also:
acceptDropMimeTypes()

Reimplemented from Wt::WAbstractItemModel.

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

Removes columns.

Returns true if the operation was successful.

The default implementation returns false. If you reimplement this method, then you must call beginRemoveColumns() and endRemoveColumns() before and after the operation.

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

Reimplemented from Wt::WAbstractItemModel.

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

Removes rows.

Returns true if the operation was successful.

The default implementation returns false. If you reimplement this method, then you must call beginRemoveRows() and endRemoveRows() before and after the operation.

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

Reimplemented from Wt::WAbstractItemModel.

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

Sets data at the given model index.

Returns true if the operation was successful.

The default implementation returns false. If you reimplement this method, you must emit the dataChanged() signal after data was changed.

See also:
data()

Reimplemented from Wt::WAbstractItemModel.

void Wt::WAbstractProxyModel::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 in Wt::WAggregateProxyModel, and Wt::WSortFilterProxyModel.

WAbstractItemModel* Wt::WAbstractProxyModel::sourceModel (  ) const [inline]

Returns the source model.

See also:
setSourceModel()
void * Wt::WAbstractProxyModel::toRawIndex ( const WModelIndex index ) const [virtual]

Converts a model index to a raw pointer that remains valid while the model's layout is changed.

Use this method to temporarily save model indexes while the model's layout is changed by for example a sorting operation.

The default implementation returns 0, which indicates that the index cannot be converted to a raw pointer. If you reimplement this method, you also need to reimplemnt fromRawIndex().

See also:
layoutAboutToBeChanged, sort(), fromRawIndex()

Reimplemented from Wt::WAbstractItemModel.


Generated on Sat Dec 4 2010 06:32:34 for Wt by doxygen 1.7.2