Wt: Wt::WAbstractProxyModel Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Types | Protected Member Functions | List of all members
Wt::WAbstractProxyModel Class Referenceabstract
Model/view system

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

`#include <Wt/WAbstractProxyModel.h>`

Inheritance diagram for Wt::WAbstractProxyModel:
[legend]

## Classes
struct | BaseItem
| A base class for an item modeling a source index parent. More...

## Public Member Functions
| WAbstractProxyModel ()
| 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 (const std::shared_ptr< WAbstractItemModel > &sourceModel)
| Sets the source model.
std::shared_ptr< WAbstractItemModel > | sourceModel () const
| Returns the source model.
virtual cpp17::any | data (const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const override
| Returns the data at a specific model index.
virtual cpp17::any | headerData (int section, Orientation orientation=Orientation::Horizontal, ItemDataRole role=ItemDataRole::Display) const override
| Returns the row or column header data.
virtual bool | setData (const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
| Sets the data at the given model index.
virtual bool | setItemData (const WModelIndex &index, const DataMap &values) override
| Sets the data at the given model index.
virtual WFlags< ItemFlag > | flags (const WModelIndex &index) const override
| Returns the flags for an item.
virtual WFlags< HeaderFlag > | headerFlags (int section, Orientation orientation=Orientation::Horizontal) const override
| Returns the flags for a header.
virtual bool | insertColumns (int column, int count, const WModelIndex &parent=WModelIndex()) override
| Inserts one or more columns.
virtual bool | removeColumns (int column, int count, const WModelIndex &parent=WModelIndex()) override
| Removes columns.
virtual std::string | mimeType () const override
| Returns a mime-type for dragging a set of indexes.
virtual std::vector< std::string > | acceptDropMimeTypes () const override
| 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) override
| Handles a drop event.
virtual void * | toRawIndex (const WModelIndex &index) const override
| Converts a model index to a raw pointer that remains valid while the model's layout is changed.
virtual WModelIndex | fromRawIndex (void *rawIndex) const override
| Converts a raw pointer to a model index.
bool | setData (int row, int column, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit, const WModelIndex &parent=WModelIndex())
| Sets data at the given row and column.
cpp17::any | data (int row, int column, ItemDataRole role=ItemDataRole::Display, const WModelIndex &parent=WModelIndex()) const
| Returns the data item at the given column and row.
virtual bool | setHeaderData (int section, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
| Sets header data for a column or row.
bool | setHeaderData (int section, const cpp17::any &value)
| Sets column header data.
Public Member Functions inherited from Wt::WAbstractItemModel
| WAbstractItemModel ()
| Creates a new data model.
virtual int | columnCount (const WModelIndex &parent=WModelIndex()) const =0
| Returns the number of columns.
virtual int | rowCount (const WModelIndex &parent=WModelIndex()) const =0
| Returns the number of rows.
virtual bool | hasChildren (const WModelIndex &index) const
| Returns if there are children at an index.
virtual WModelIndex | parent (const WModelIndex &index) const =0
| Returns the parent for a model index.
virtual DataMap | itemData (const WModelIndex &index) const
| Returns all data at a specific index.
virtual WModelIndex | index (int row, int column, const WModelIndex &parent=WModelIndex()) const =0
| Returns the child index for the given row and column.
virtual WModelIndexList | match (const WModelIndex &start, ItemDataRole role, const cpp17::any &value, int hits=-1, WFlags< MatchFlag > flags=WFlags< MatchFlag >(MatchFlag::StartsWith|MatchFlag::Wrap)) const
| Returns an index list for data items that match.
cpp17::any | data (int row, int column, ItemDataRole role=ItemDataRole::Display, const WModelIndex &parent=WModelIndex()) const
| Returns the data item at the given column and row.
virtual bool | hasIndex (int row, int column, const WModelIndex &parent=WModelIndex()) const
| Returns if an index at the given position is valid (i.e. falls within the column-row bounds).
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.
bool | setHeaderData (int section, const cpp17::any &value)
| Sets column header data.
virtual void | sort (int column, SortOrder order=SortOrder::Ascending)
| Sorts the model according to a particular column.
virtual void | expandColumn (int column)
| Expands a column.
virtual void | collapseColumn (int column)
| Collapses a column.
virtual void | dropEvent (const WDropEvent &e, DropAction action, const WModelIndex &index, Wt::Side side)
| Handles a drop event.
bool | insertColumn (int column, const WModelIndex &parent=WModelIndex())
| Inserts one column.
bool | insertRow (int row, const WModelIndex &parent=WModelIndex())
| Inserts one row.
bool | removeColumn (int column, const WModelIndex &parent=WModelIndex())
| Removes one column.
bool | removeRow (int row, const WModelIndex &parent=WModelIndex())
| Removes one row.
bool | setData (int row, int column, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit, const WModelIndex &parent=WModelIndex())
| Sets data at the given row and column.
virtual Signal< WModelIndex, int, int > & | columnsAboutToBeInserted ()
| Signal emitted before a number of columns will be inserted.
virtual Signal< WModelIndex, int, int > & | columnsAboutToBeRemoved ()
| Signal emitted before a number of columns will be removed.
virtual Signal< WModelIndex, int, int > & | columnsInserted ()
| Signal emitted after a number of columns were inserted.
virtual Signal< WModelIndex, int, int > & | columnsRemoved ()
| Signal emitted after a number of columns were removed.
virtual Signal< WModelIndex, int, int > & | rowsAboutToBeInserted ()
| Signal emitted before a number of rows will be inserted.
virtual Signal< WModelIndex, int, int > & | rowsAboutToBeRemoved ()
| Signal emitted before a number of rows will be removed.
virtual Signal< WModelIndex, int, int > & | rowsInserted ()
| Signal emitted after a number of rows were inserted.
virtual Signal< WModelIndex, int, int > & | rowsRemoved ()
| Signal emitted after a number of rows were removed.
virtual Signal< WModelIndex, WModelIndex > & | dataChanged ()
| Signal emitted when some data was changed.
virtual Signal< Orientation, int, int > & | headerDataChanged ()
| Signal emitted when some header data was changed.
virtual Signal & | layoutAboutToBeChanged ()
| Signal emitted when the layout is about to be changed.
virtual Signal & | layoutChanged ()
| Signal emitted when the layout is changed.
virtual Signal & | modelReset ()
| Signal emitted when the model was reset.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
virtual 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.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.

## Protected Types
typedef std::map< WModelIndex, BaseItem * > | ItemMap
| A map for items.

## Protected Member Functions
WModelIndex | createSourceIndex (int row, int column, void *ptr) const
| Create a source model index.
void | startShiftModelIndexes (const WModelIndex &sourceParent, int start, int count, ItemMap &items)
| Utility methods to shift items in an item map.
Protected Member Functions inherited from Wt::WAbstractItemModel
void | reset ()
| Resets the model and invalidate any data.
WModelIndex | createIndex (int row, int column, void *ptr) const
| Creates a model index for the given row and column.
WModelIndex | createIndex (int row, int column, ::uint64_t id) const
| Creates a model index for the given row and column.
void | beginInsertColumns (const WModelIndex &parent, int first, int last)
| Method to be called before inserting columns.
void | beginInsertRows (const WModelIndex &parent, int first, int last)
| Method to be called before inserting rows.
void | beginRemoveColumns (const WModelIndex &parent, int first, int last)
| Method to be called before removing columns.
void | beginRemoveRows (const WModelIndex &parent, int first, int last)
| Method to be called before removing rows.
void | endInsertColumns ()
| Method to be called after inserting columns.
void | endInsertRows ()
| Method to be called after inserting rows.
void | endRemoveColumns ()
| Method to be called after removing columns.
void | endRemoveRows ()
| Method to be called after removing rows.
virtual void | copyData (const WModelIndex &sIndex, const WModelIndex &dIndex)
| Copy data to an index in this model.
Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * | getStateless (Method method)
| On-demand stateless slot implementation.

## Additional Inherited Members
Public Types inherited from Wt::WAbstractItemModel
typedef std::map< ItemDataRole, cpp17::any > | DataMap
| Data map.
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.
Static Public Member Functions inherited from Wt::WObject

## 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 Typedef Documentation

## ◆ ItemMap

std::map<WModelIndex, BaseItem *> Wt::WAbstractProxyModel::ItemMap
| protected

A map for items.

See also
  BaseItem

## Member Function Documentation

## ◆ acceptDropMimeTypes()

virtual std::vector< std::string > Wt::WAbstractProxyModel::acceptDropMimeTypes | ( |  | ) | const
| overridevirtual

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

The default proxy implementation calls sourceModel()->acceptDropMimeTypes()

Reimplemented from Wt::WAbstractItemModel.

## ◆ createSourceIndex()

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.

## ◆ data() [1/2]

virtual cpp17::any Wt::WAbstractProxyModel::data | ( | const WModelIndex & | index,
|  | ItemDataRole | role = ItemDataRole::Display ) const
| overridevirtual

Returns the data at a specific model index.

The default proxy implementation translates the index to the source model, and calls sourceModel()->data() with this index.

Implements Wt::WAbstractItemModel.

Reimplemented in Wt::WBatchEditProxyModel.

## ◆ data() [2/2]

cpp17::any Wt::WAbstractItemModel::data | ( | int | row,
|  | int | column,
|  | ItemDataRole | role = ItemDataRole::Display,
|  | const WModelIndex & | parent = WModelIndex() ) const

Returns the data item at the given column and row.

This is a convenience method, and is equivalent to:

index(row, column, parent).data(role)
Wt::WAbstractItemModel::index
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const =0
Returns the child index for the given row and column.
Wt::WAbstractItemModel::parent
virtual WModelIndex parent(const WModelIndex &index) const =0
Returns the parent for a model index.
Wt::WModelIndex::data
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const
Returns data in the model at this index.

See also
  index(), data()

## ◆ dropEvent()

virtual void Wt::WAbstractProxyModel::dropEvent | ( | const WDropEvent & | e,
|  | DropAction | action,
|  | int | row,
|  | int | column,
|  | const WModelIndex & | parent )
| overridevirtual

Handles a drop event.

The default proxy implementation maps the given row and parent to the row and parent in the source model, and forwards the dropEvent call to the source model.

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WReadOnlyProxyModel.

## ◆ flags()

virtual WFlags< ItemFlag > Wt::WAbstractProxyModel::flags | ( | const WModelIndex & | index | ) | const
| overridevirtual

Returns the flags for an item.

The default proxy implementation calls sourceModel()->flags(mapToSource(index))

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WBatchEditProxyModel.

## ◆ fromRawIndex()

virtual WModelIndex Wt::WAbstractProxyModel::fromRawIndex | ( | void * | rawIndex | ) | const
| overridevirtual

Converts a raw pointer to a model index.

The default proxy implementation calls mapFromSource(sourceModel()->fromRawIndex(rawIndex))

Reimplemented from Wt::WAbstractItemModel.

## ◆ headerData()

virtual cpp17::any Wt::WAbstractProxyModel::headerData | ( | int | section,
|  | Orientation | orientation = Orientation::Horizontal,
|  | ItemDataRole | role = ItemDataRole::Display ) const
| overridevirtual

Returns the row or column header data.

The default proxy implementation constructs a dummy WModelIndex with the row set to 0 and column set to `section` if the orientation is Wt::Orientation::Horizontal, or with the row set to `section` and the column set to 0 if the orientation is Wt::Orientation::Vertical.

The resulting section that is forwarded to sourceModel()->headerData() depends on how the WModelIndex is transformed with mapToSource().

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, and Wt::WSortFilterProxyModel.

## ◆ headerFlags()

virtual WFlags< HeaderFlag > Wt::WAbstractProxyModel::headerFlags | ( | int | section,
|  | Orientation | orientation = Orientation::Horizontal ) const
| overridevirtual

Returns the flags for a header.

The default proxy implementation constructs a dummy WModelIndex with the row set to 0 and column set to `section` if the orientation is Wt::Orientation::Horizontal, or with the row set to `section` and the column set to 0 if the orientation is Wt::Orientation::Vertical.

The resulting section that is forwarded to sourceModel()->headerFlags() depends on how the WModelIndex is transformed with mapToSource().

Reimplemented from Wt::WAbstractItemModel.

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

## ◆ insertColumns()

virtual bool Wt::WAbstractProxyModel::insertColumns | ( | int | column,
|  | int | count,
|  | const WModelIndex & | parent = WModelIndex() )
| overridevirtual

Inserts one or more columns.

The default proxy implementation calls sourceModel()->insertColumns(column, count, parent)

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, and Wt::WReadOnlyProxyModel.

## ◆ mapFromSource()

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, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WReadOnlyProxyModel, and Wt::WSortFilterProxyModel.

## ◆ mapToSource()

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, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WReadOnlyProxyModel, and Wt::WSortFilterProxyModel.

## ◆ mimeType()

virtual std::string Wt::WAbstractProxyModel::mimeType | ( |  | ) | const
| overridevirtual

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

The default proxy implementation calls sourceModel()->mimeType()

Reimplemented from Wt::WAbstractItemModel.

## ◆ removeColumns()

virtual bool Wt::WAbstractProxyModel::removeColumns | ( | int | column,
|  | int | count,
|  | const WModelIndex & | parent = WModelIndex() )
| overridevirtual

Removes columns.

The default proxy implementation calls sourceModel()->removeColumns(column, count, parent)

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, and Wt::WReadOnlyProxyModel.

## ◆ setData() [1/2]

virtual bool Wt::WAbstractProxyModel::setData | ( | const WModelIndex & | index,
|  | const cpp17::any & | value,
|  | ItemDataRole | role = ItemDataRole::Edit )
| overridevirtual

Sets the data at the given model index.

The default proxy implementation calls sourceModel()->setData(mapToSource(index), value, role)

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WBatchEditProxyModel, and Wt::WReadOnlyProxyModel.

## ◆ setData() [2/2]

bool Wt::WAbstractItemModel::setData | ( | int | row,
|  | int | column,
|  | const cpp17::any & | value,
|  | ItemDataRole | role = ItemDataRole::Edit,
|  | const WModelIndex & | parent = WModelIndex() )

Sets data at the given row and column.

This is a convience method, and is equivalent to:

setData(index(row, column, parent), value, role);
Wt::WAbstractProxyModel::setData
virtual bool setData(const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
Sets the data at the given model index.

Returns `true` if the operation was successful.

See also
  setData(), index()

## ◆ setHeaderData() [1/2]

bool Wt::WAbstractItemModel::setHeaderData | ( | int | section,
|  | const cpp17::any & | value )

Sets column header data.

Returns `true` if the operation was successful.

See also
  setHeaderData(int, Orientation, const cpp17::any&, int)

## ◆ setHeaderData() [2/2]

virtual bool Wt::WAbstractItemModel::setHeaderData | ( | int | section,
|  | Orientation | orientation,
|  | const cpp17::any & | value,
|  | ItemDataRole | role = ItemDataRole::Edit )
| virtual

Sets header data for a column or row.

Returns `true` if the operation was successful.

See also
  headerData()

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WReadOnlyProxyModel, and Wt::WSortFilterProxyModel.

## ◆ setItemData()

virtual bool Wt::WAbstractProxyModel::setItemData | ( | const WModelIndex & | index,
|  | const DataMap & | values )
| overridevirtual

Sets the data at the given model index.

The default proxy implementation calls sourceModel()->setData(mapToSource(index), values)

Reimplemented from Wt::WAbstractItemModel.

Reimplemented in Wt::WReadOnlyProxyModel.

## ◆ setSourceModel()

virtual void Wt::WAbstractProxyModel::setSourceModel | ( | const std::shared_ptr< 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.

Note that the source model's signals are not forwarded to the proxy model by default, but some specializations, like WBatchEditProxyModel and WSortFilterProxyModel do. If you want to reimplement data() with no changes to row or column indices, consider the use of WIdentityProxyModel.

Reimplemented in Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, and Wt::WSortFilterProxyModel.

## ◆ sourceModel()

std::shared_ptr< WAbstractItemModel > Wt::WAbstractProxyModel::sourceModel | ( |  | ) | const

Returns the source model.

See also
  setSourceModel()

## ◆ startShiftModelIndexes()

void Wt::WAbstractProxyModel::startShiftModelIndexes | ( | const WModelIndex & | sourceParent,
|  | int | start,
|  | int | count,
|  | ItemMap & | items )
| protected

Utility methods to shift items in an item map.

You can use this method to adjust an item map after the source model has inserted or removed rows. When removing rows (count < 0), items may possibly be removed and deleted.

## ◆ toRawIndex()

virtual void * Wt::WAbstractProxyModel::toRawIndex | ( | const WModelIndex & | index | ) | const
| overridevirtual

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

The default proxy implementation calls sourceModel()->toRawIndex(mapToSource(index))

Reimplemented from Wt::WAbstractItemModel.