Wt  4.11.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
Wt::WAbstractItemModel Class Referenceabstract

An abstract model for use with Wt's view classes. More...

#include <Wt/WAbstractItemModel.h>

Inheritance diagram for Wt::WAbstractItemModel:
[legend]

Public Types

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.
 

Public Member Functions

 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 WFlags< ItemFlagflags (const WModelIndex &index) const
 Returns the flags for an item.
 
virtual WFlags< HeaderFlagheaderFlags (int section, Orientation orientation=Orientation::Horizontal) const
 Returns the flags for a header.
 
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 cpp17::any data (const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const =0
 Returns data at a specified model index for the given role.
 
virtual DataMap itemData (const WModelIndex &index) const
 Returns all data at a specific index.
 
virtual cpp17::any headerData (int section, Orientation orientation=Orientation::Horizontal, ItemDataRole role=ItemDataRole::Display) const
 Returns the row or column header data.
 
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 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 bool setData (const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
 Sets data at the given model index.
 
virtual bool setItemData (const WModelIndex &index, const DataMap &values)
 Sets data at the given model index.
 
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.
 
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 voidtoRawIndex (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.
 
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 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 SignallayoutAboutToBeChanged ()
 Signal emitted when the layout is about to be changed.
 
virtual SignallayoutChanged ()
 Signal emitted when the layout is changed.
 
virtual SignalmodelReset ()
 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 >
ChildaddChild (std::unique_ptr< Child > child)
 Add a child WObject, returning a raw pointer.
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 Remove a child WObject, so its lifetime is no longer determined by this WObject.
 
template<typename Child >
std::unique_ptr< ChildremoveChild (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 Member Functions

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.
 

Detailed Description

An abstract model for use with Wt's view classes.

This abstract model is used by several Wt view widgets as data models.

It may model data for both tree-like and table-like view widgets. Data is therefore organized in a hierarchical structure of tables, where every item stores data and items in column 0 can be the parent of a nested table of data. Every data item is uniquely identified by their row, column and parent index, and items may be referenced using the helper class WModelIndex.

Each item may provide data for one or more roles, and indicate options using flags. The different roles can be used to model different aspects of an item (its text value, an icon, style class), or to hold auxiliary custom information. The flags provide information to the View on possible interactivity.

Side::Top level data have an invalid parent WModelIndex.

The data itself is of type Wt::any, which can either be empty, or hold any type of data. Depending on the role however, view classes may expect certain types of data (e.g. a string for Wt::ItemDataRole::StyleClass).

Wt's standard view classes can display (Wt::ItemDataRole::Display) the following data:

The view classes know how to interpret data of these types as a string or as a number.

Conversion between native types and Wt::any is done like this:

To implement a custom model, you need to reimplement the following methods:

A crucial point in implementing a hierarchical model is to decide how to reference an index in terms of an internal pointer (WModelIndex::internalPointer()) or internal id (WModelIndex::internalId()). Other than the top-level index, which is special since it is referenced using an invalid index, every index with children must be identifiable using this number or pointer. For example, in the WStandardItemModel, the internal pointer points to the parent WStandardItem. For table models, the internal pointer plays no role, since only the toplevel index has children.

If you want to support editing of the model, then you need to indicate this support using a Wt::ItemFlag::Editable flag, and reimplement setData(). View classes will use the ItemDataRole::Edit to read and update the data for the editor.

When the model's data has been changed, the model must emit the dataChanged() signal.

Finally, there is a generic interface for insertion of new data or removal of data (changing the geometry), although this interface is not yet used by any View class:

Alternatively, you can provide your own API for changing the model. In either case it is important that you call the corresponding protected member functions which will emit the relevant signals so that views can adapt themselves to the new geometry.

Member Typedef Documentation

◆ DataMap

Data map.

A map of data, indexed by a role.

Member Function Documentation

◆ acceptDropMimeTypes()

std::vector< std::string > Wt::WAbstractItemModel::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 in Wt::WAbstractProxyModel.

◆ beginInsertColumns()

void Wt::WAbstractItemModel::beginInsertColumns ( const WModelIndex parent,
int  first,
int  last 
)
protected

Method to be called before inserting columns.

If your model supports insertion of columns, then you should call this method before inserting one or more columns, and endInsertColumns() afterwards. These methods emit the necessary signals to allow view classes to update themselves.

See also
endInsertColumns(), insertColumns(), columnsAboutToBeInserted

◆ beginInsertRows()

void Wt::WAbstractItemModel::beginInsertRows ( const WModelIndex parent,
int  first,
int  last 
)
protected

Method to be called before inserting rows.

If your model supports insertion of rows, then you should call this method before inserting one or more rows, and endInsertRows() afterwards. These methods emit the necessary signals to allow view classes to update themselves.

See also
endInsertRows(), insertRows(), rowsAboutToBeInserted

◆ beginRemoveColumns()

void Wt::WAbstractItemModel::beginRemoveColumns ( const WModelIndex parent,
int  first,
int  last 
)
protected

Method to be called before removing columns.

If your model supports removal of columns, then you should call this method before removing one or more columns, and endRemoveColumns() afterwards. These methods emit the necessary signals to allow view classes to update themselves.

See also
endRemoveColumns(), removeColumns(), columnsAboutToBeRemoved

◆ beginRemoveRows()

void Wt::WAbstractItemModel::beginRemoveRows ( const WModelIndex parent,
int  first,
int  last 
)
protected

Method to be called before removing rows.

If your model supports removal of rows, then you should call this method before removing one or more rows, and endRemoveRows() afterwards. These methods emit the necessary signals to allow view classes to update themselves.

See also
endRemoveRows(), removeRows(), rowsAboutToBeRemoved

◆ collapseColumn()

void Wt::WAbstractItemModel::collapseColumn ( int  column)
virtual

Collapses a column.

Collapses a column. This may only be called by a view when the Wt::HeaderFlag::ColumnIsExpandedLeft or Wt::HeaderFlag::ColumnIsExpandedRight flag is set.

The default implementation does nothing.

See also
WAggregateProxyModel

Reimplemented in Wt::WAggregateProxyModel.

◆ columnCount()

virtual int Wt::WAbstractItemModel::columnCount ( const WModelIndex parent = WModelIndex()) const
pure virtual

Returns the number of columns.

This returns the number of columns at index parent.

See also
rowCount()

Implemented in Wt::Dbo::QueryModel< Result >, Wt::WAbstractListModel, Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WReadOnlyProxyModel, and Wt::WSortFilterProxyModel.

◆ columnsAboutToBeInserted()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::columnsAboutToBeInserted ( )
virtual

Signal emitted before a number of columns will be inserted.

The first argument is the parent index. The two integer arguments are the column numbers that the first and last column will have when inserted.

See also
columnsInserted(), beginInsertColumns()

◆ columnsAboutToBeRemoved()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::columnsAboutToBeRemoved ( )
virtual

Signal emitted before a number of columns will be removed.

The first argument is the parent index. The two integer arguments are the column numbers of the first and last column that will be removed.

See also
columnsRemoved(), beginRemoveColumns()

◆ columnsInserted()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::columnsInserted ( )
virtual

Signal emitted after a number of columns were inserted.

The first argument is the parent index. The two integer arguments are the column numbers of the first and last column that were inserted.

See also
columnsAboutToBeInserted(), endInsertColumns()

◆ columnsRemoved()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::columnsRemoved ( )
virtual

Signal emitted after a number of columns were removed.

The first argument is the parent index. The two integer arguments are the column numbers of the first and last column that were removed.

See also
columnsAboutToBeRemoved(), endRemoveColumns()

◆ copyData()

void Wt::WAbstractItemModel::copyData ( const WModelIndex sIndex,
const WModelIndex dIndex 
)
protectedvirtual

Copy data to an index in this model.

The source index can be any valid index. The destination index must be part of this model.

Reimplemented in Wt::WStandardItemModel.

◆ createIndex() [1/2]

WModelIndex Wt::WAbstractItemModel::createIndex ( int  row,
int  column,
::uint64_t  id 
) const
protected

Creates a model index for the given row and column.

Use this method to create a model index. id is an internal id that may be used to identify the parent of the corresponding item. For a flat table model, ptr can thus always be 0.

See also
WModelIndex::internalId()

◆ createIndex() [2/2]

WModelIndex Wt::WAbstractItemModel::createIndex ( int  row,
int  column,
void ptr 
) const
protected

Creates a model index for the given row and column.

Use this method to create a model index. ptr is an internal pointer that may be used to identify the parent of the corresponding item. For a flat table model, ptr can thus always be 0.

See also
WModelIndex::internalPointer()

◆ data() [1/2]

virtual cpp17::any Wt::WAbstractItemModel::data ( const WModelIndex index,
ItemDataRole  role = ItemDataRole::Display 
) const
pure virtual

Returns data at a specified model index for the given role.

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::ItemDataRole::Display) but also icons (Wt::ItemDataRole::Decoration), URLs (Wt::ItemDataRole::Link), and other visual aspects. If your item does not specify data for a particular role, it should simply return a Wt::cpp17::any().

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

Implemented in Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, Wt::WStringListModel, Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, and 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)
A signal that conveys user-interface events.
Definition WSignal.h:558
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const =0
Returns the child index for the given row and column.
virtual WModelIndex parent(const WModelIndex &index) const =0
Returns the parent for a model index.
See also
index(), data()

◆ dataChanged()

virtual Signal< WModelIndex, WModelIndex > & Wt::WAbstractItemModel::dataChanged ( )
virtual

Signal emitted when some data was changed.

The two arguments are the model indexes of the top-left and bottom-right data items that span the rectangle of changed data items.

See also
setData()

◆ dropEvent() [1/2]

void Wt::WAbstractItemModel::dropEvent ( const WDropEvent e,
DropAction  action,
const WModelIndex index,
Wt::Side  side 
)
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).

This method is overloaded for handling drop events on top of items or drop events between items. This overload handles drops between items. The drop was received relative to the index item and the side parameter will only be Wt::Top or Wt::Bottom.

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

◆ dropEvent() [2/2]

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

This method is overloaded for handling drop events on top of items or drop events between items (see Wt::DropLocation). This overload handles drops on top of items, but note that due to historical reasons it will also insert the items in between when called with DropAction::Move.

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 DropAction::Move, 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 in Wt::WAbstractProxyModel, and Wt::WReadOnlyProxyModel.

◆ endInsertColumns()

void Wt::WAbstractItemModel::endInsertColumns ( )
protected

Method to be called after inserting columns.

See also
beginInsertColumns()

◆ endInsertRows()

void Wt::WAbstractItemModel::endInsertRows ( )
protected

Method to be called after inserting rows.

See also
beginInsertRows()

◆ endRemoveColumns()

void Wt::WAbstractItemModel::endRemoveColumns ( )
protected

Method to be called after removing columns.

See also
beginRemoveColumns()

◆ endRemoveRows()

void Wt::WAbstractItemModel::endRemoveRows ( )
protected

Method to be called after removing rows.

See also
beginRemoveRows()

◆ expandColumn()

void Wt::WAbstractItemModel::expandColumn ( int  column)
virtual

Expands a column.

Expands a column. This may only be called by a view when the Wt::HeaderFlag::ColumnIsCollapsed flag is set.

The default implementation does nothing.

See also
WAggregateProxyModel

Reimplemented in Wt::WAggregateProxyModel.

◆ flags()

WFlags< ItemFlag > Wt::WAbstractItemModel::flags ( const WModelIndex index) const
virtual

Returns the flags for an item.

The default implementation returns ItemFlag::Selectable.

See also
Wt::ItemFlag

Reimplemented in Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, and Wt::WStringListModel.

◆ fromRawIndex()

WModelIndex Wt::WAbstractItemModel::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 in Wt::Dbo::QueryModel< Result >, and Wt::WAbstractProxyModel.

◆ hasChildren()

bool Wt::WAbstractItemModel::hasChildren ( const WModelIndex index) const
virtual

Returns if there are children at an index.

Returns true when rowCount(index) > 0 and columnCount(index) > 0.

See also
rowCount(), columnCount()

◆ hasIndex()

bool Wt::WAbstractItemModel::hasIndex ( int  row,
int  column,
const WModelIndex parent = WModelIndex() 
) const
virtual

Returns if an index at the given position is valid (i.e. falls within the column-row bounds).

Equivalent to:

return row >= 0 && column >= 0
&& row < rowCount(parent) && column < columnCount(parent);
virtual int rowCount(const WModelIndex &parent=WModelIndex()) const =0
Returns the number of rows.
virtual int columnCount(const WModelIndex &parent=WModelIndex()) const =0
Returns the number of columns.
See also
rowCount(), columnCount()

◆ headerData()

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

Returns the row or column header data.

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

See also
data(), setHeaderData()

Reimplemented in Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, and Wt::WSortFilterProxyModel.

◆ headerDataChanged()

virtual Signal< Orientation, int, int > & Wt::WAbstractItemModel::headerDataChanged ( )
virtual

Signal emitted when some header data was changed.

The first argument indicates the orientation of the header, and the two integer arguments are the row or column numbers of the first and last header item of which the value was changed.

See also
setHeaderData()

◆ headerFlags()

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

Returns the flags for a header.

The default implementation returns no flags set.

See also
Wt::HeaderFlag

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

◆ index()

virtual WModelIndex Wt::WAbstractItemModel::index ( int  row,
int  column,
const WModelIndex parent = WModelIndex() 
) const
pure 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()

Implemented in Wt::WAbstractTableModel, Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WReadOnlyProxyModel, Wt::WSortFilterProxyModel, and Wt::WAbstractListModel.

◆ insertColumn()

bool Wt::WAbstractItemModel::insertColumn ( int  column,
const WModelIndex parent = WModelIndex() 
)

Inserts one column.

This is a convenience method that adds a single column, and is equivalent to:

insertColumns(column, 1, parent);
virtual bool insertColumns(int column, int count, const WModelIndex &parent=WModelIndex())
Inserts one or more columns.
Definition WAbstractItemModel.C:107

Returns true if the operation was successful.

See also
insertColumns()

◆ insertColumns()

bool Wt::WAbstractItemModel::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 in Wt::WReadOnlyProxyModel, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, and Wt::WIdentityProxyModel.

◆ insertRow()

bool Wt::WAbstractItemModel::insertRow ( int  row,
const WModelIndex parent = WModelIndex() 
)

Inserts one row.

This is a convenience method that adds a single row, and is equivalent to:

insertRows(row, 1, parent);
virtual bool insertRows(int row, int count, const WModelIndex &parent=WModelIndex())
Inserts one or more rows.
Definition WAbstractItemModel.C:112

Returns true if the operation was successful.

See also
insertRows()

◆ insertRows()

bool Wt::WAbstractItemModel::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 in Wt::Dbo::QueryModel< Result >, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WSortFilterProxyModel, and Wt::WStringListModel.

◆ itemData()

WAbstractItemModel::DataMap Wt::WAbstractItemModel::itemData ( const WModelIndex index) const
virtual

Returns all data at a specific index.

This is a convenience function that returns a map with data corresponding to all standard roles.

See also
data()

◆ layoutAboutToBeChanged()

virtual Signal & Wt::WAbstractItemModel::layoutAboutToBeChanged ( )
virtual

Signal emitted when the layout is about to be changed.

A layout change may reorder or add/remove rows in the model, but columns are preserved. Model indexes are invalidated by a layout change, but indexes may be ported across a layout change by using the toRawIndex() and fromRawIndex() methods.

See also
layoutChanged(), toRawIndex(), fromRawIndex()

◆ layoutChanged()

virtual Signal & Wt::WAbstractItemModel::layoutChanged ( )
virtual

Signal emitted when the layout is changed.

See also
layoutAboutToBeChanged()

◆ match()

WModelIndexList Wt::WAbstractItemModel::match ( const WModelIndex start,
ItemDataRole  role,
const cpp17::any &  value,
int  hits = -1,
WFlags< MatchFlag flags = WFlags<MatchFlag>(MatchFlag::StartsWith                                                    | MatchFlag::Wrap) 
) const
virtual

Returns an index list for data items that match.

Returns an index list of data items that match, starting at start, and searching further in that column. If flags specifies MatchFlag::Wrap then the search wraps around from the start. If hits is not -1, then at most that number of hits are returned.

◆ mimeType()

std::string Wt::WAbstractItemModel::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 in Wt::WAbstractProxyModel.

◆ modelReset()

virtual Signal & Wt::WAbstractItemModel::modelReset ( )
virtual

Signal emitted when the model was reset.

A model reset invalidates all existing data, and the model may change its entire geometry (column count, row count).

See also
reset()

◆ parent()

virtual WModelIndex Wt::WAbstractItemModel::parent ( const WModelIndex index) const
pure 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()

Implemented in Wt::WIdentityProxyModel, Wt::WAbstractListModel, Wt::WAbstractTableModel, Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WReadOnlyProxyModel, and Wt::WSortFilterProxyModel.

◆ removeColumn()

bool Wt::WAbstractItemModel::removeColumn ( int  column,
const WModelIndex parent = WModelIndex() 
)

Removes one column.

This is a convenience method that removes a single column, and is equivalent to:

removeColumns(column, 1, parent);
virtual bool removeColumns(int column, int count, const WModelIndex &parent=WModelIndex())
Removes columns.
Definition WAbstractItemModel.C:117

Returns true if the operation was successful.

See also
removeColumns()

◆ removeColumns()

bool Wt::WAbstractItemModel::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 in Wt::WReadOnlyProxyModel, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, and Wt::WIdentityProxyModel.

◆ removeRow()

bool Wt::WAbstractItemModel::removeRow ( int  row,
const WModelIndex parent = WModelIndex() 
)

Removes one row.

This is a convenience method that removes a single row, and is equivalent to:

removeRows(row, 1, parent);
virtual bool removeRows(int row, int count, const WModelIndex &parent=WModelIndex())
Removes rows.
Definition WAbstractItemModel.C:122

Returns true if the operation was successful.

See also
removeRows()

◆ removeRows()

bool Wt::WAbstractItemModel::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 in Wt::Dbo::QueryModel< Result >, Wt::WBatchEditProxyModel, Wt::WIdentityProxyModel, Wt::WSortFilterProxyModel, and Wt::WStringListModel.

◆ reset()

void Wt::WAbstractItemModel::reset ( )
protected

Resets the model and invalidate any data.

Informs any attached view that all data in the model was invalidated, and the model's data should be reread.

This causes the modelReset() signal to be emitted.

◆ rowCount()

virtual int Wt::WAbstractItemModel::rowCount ( const WModelIndex parent = WModelIndex()) const
pure virtual

◆ rowsAboutToBeInserted()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::rowsAboutToBeInserted ( )
virtual

Signal emitted before a number of rows will be inserted.

The first argument is the parent index. The two integer arguments are the row numbers that the first and last row will have when inserted.

See also
rowsInserted(), beginInsertRows()

◆ rowsAboutToBeRemoved()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::rowsAboutToBeRemoved ( )
virtual

Signal emitted before a number of rows will be removed.

The first argument is the parent index. The two integer arguments are the row numbers of the first and last row that will be removed.

See also
rowsRemoved(), beginRemoveRows()

◆ rowsInserted()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::rowsInserted ( )
virtual

Signal emitted after a number of rows were inserted.

The first argument is the parent index. The two integer arguments are the row numbers of the first and last row that were inserted.

See also
rowsAboutToBeInserted(), endInsertRows()

◆ rowsRemoved()

virtual Signal< WModelIndex, int, int > & Wt::WAbstractItemModel::rowsRemoved ( )
virtual

Signal emitted after a number of rows were removed.

The first argument is the parent index. The two integer arguments are the row numbers of the first and last row that were removed.

See also
rowsAboutToBeRemoved(), endRemoveRows()

◆ setData() [1/2]

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

Sets data at the given model index.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must emit the dataChanged() signal after data was changed.

See also
data()

Reimplemented in Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, Wt::WReadOnlyProxyModel, Wt::Dbo::QueryModel< Result >, Wt::WAbstractProxyModel, Wt::WBatchEditProxyModel, Wt::WReadOnlyProxyModel, Wt::WReadOnlyProxyModel, and Wt::WStringListModel.

◆ 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);
virtual bool setData(const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
Sets 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

◆ setItemData()

bool Wt::WAbstractItemModel::setItemData ( const WModelIndex index,
const DataMap values 
)
virtual

Sets data at the given model index.

This is a convenience function that sets data for all roles at once.

See also
setData()

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

◆ sort()

void Wt::WAbstractItemModel::sort ( int  column,
SortOrder  order = SortOrder::Ascending 
)
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 in Wt::Dbo::QueryModel< Result >, Wt::WAggregateProxyModel, Wt::WBatchEditProxyModel, Wt::WSortFilterProxyModel, Wt::WStandardItemModel, and Wt::WStringListModel.

◆ toRawIndex()

void * Wt::WAbstractItemModel::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 in Wt::Dbo::QueryModel< Result >, and Wt::WAbstractProxyModel.