Wt: Wt::Dbo::QueryModel< Result > Class Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
Wt::Dbo::QueryModel< Result > Class Template Reference
Database Objects (Wt::Dbo) | Model/view system

A Wt MVC Model to view/edit query results. More...

`#include <Wt/Dbo/QueryModel.h>`

Inheritance diagram for Wt::Dbo::QueryModel< Result >:
[legend]

## Public Member Functions
| QueryModel ()
| Creates a new query model.
void | setQuery (const Query< Result > &query, bool keepColumns=false)
| Sets the query.
Query< Result > | query () const
| Returns the query.
int | addColumn (const std::string &field, const WString &header, WFlags< ItemFlag > flags=ItemFlag::Selectable)
| Adds a column.
int | addColumn (const std::string &field, WFlags< ItemFlag > flags=ItemFlag::Selectable)
| Adds a column.
void | setColumnFlags (int column, WFlags< ItemFlag > flags)
| Sets column item flags.
WFlags< ItemFlag > | columnFlags (int column) const
| Returns column item flags.
void | addAllFieldsAsColumns ()
| Adds all the columns from the field list.
Result | stableResultRow (int row) const
| Returns a stable result row.
const Result & | resultRow (int row) const
| Returns a result row.
virtual Result & | resultRow (int row)
| Returns a result row.
int | indexOf (const Result &row) const
| Returns the index of row.
void | reload ()
| Rereads the data from the database.
void | setBatchSize (int count)
| Sets the batch size for fetching results.
int | batchSize () const
| Returns the batch size for fetching results.
const std::vector< FieldInfo > & | fields () const
| Returns the query field list.
const FieldInfo & | fieldInfo (int column) const
| Returns the FieldInfo structure for a column.
const std::string & | fieldName (int column) const
| Returns the field name for the a column.
virtual int | columnCount (const WModelIndex &parent=WModelIndex()) const override
| Returns the number of columns.
virtual int | rowCount (const WModelIndex &parent=WModelIndex()) const override
| Returns the number of rows.
virtual WFlags< ItemFlag > | flags (const WModelIndex &index) const override
| Returns the flags for an item.
virtual cpp17::any | data (const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const override
| Returns the data for an item.
virtual bool | setData (const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
| Sets data at the given model index.
virtual void | sort (int column, SortOrder order=SortOrder::Ascending) override
| Sorts the model according to a particular column.
virtual std::string | createOrderBy (int column, SortOrder order)
| Create specialized orderBy clause for sort.
virtual bool | insertRows (int row, int count, const WModelIndex &parent=WModelIndex()) override
| Inserts one or more rows.
virtual bool | removeRows (int row, int count, const WModelIndex &parent=WModelIndex()) override
| Removes one or more rows.
virtual bool | setHeaderData (int column, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
| Sets header data for a column.
virtual cpp17::any | headerData (int section, Orientation orientation=Orientation::Horizontal, ItemDataRole role=ItemDataRole::Display) const override
| Returns header data.
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.
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.
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.
Public Member Functions inherited from Wt::WAbstractTableModel
| WAbstractTableModel ()
| Creates a new abstract list model.
| ~WAbstractTableModel ()
| Destructor.
virtual WModelIndex | parent (const WModelIndex &index) const override
| Returns the parent for a model index.
virtual WModelIndex | index (int row, int column, const WModelIndex &parent=WModelIndex()) const override
| Returns the child index for the given row and column.
Public Member Functions inherited from Wt::WAbstractItemModel
| WAbstractItemModel ()
| Creates a new data model.
virtual WFlags< HeaderFlag > | headerFlags (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 DataMap | itemData (const WModelIndex &index) const
| Returns all data at a specific index.
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 | removeColumns (int column, int count, const WModelIndex &parent=WModelIndex())
| Removes columns.
virtual bool | setItemData (const WModelIndex &index, const DataMap &values)
| Sets data at the given model index.
bool | setHeaderData (int section, const cpp17::any &value)
| Sets column header data.
virtual void | expandColumn (int column)
| Expands a column.
virtual void | collapseColumn (int column)
| Collapses a column.
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 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 Member Functions
virtual Result | createRow ()
| Creates a new row.
virtual void | addRow (Result &result)
| Adds a row to the session.
virtual void | deleteRow (Result &result)
| Deletes a row from the session.
virtual long long | resultId (const Result &result) const
| Returns a unique id for a result.
virtual Result | resultById (long long id) const
| Returns a result by id.
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

template<class Result>
class Wt::Dbo::QueryModel< Result >

A Wt MVC Model to view/edit query results.

The model fetches results from the query and presents the data in a table. It supports sorting the underlying SQL query using Query::orderBy().

The default implementation of data() converts Query results to model data using query_result_traits<Result>::getValues(). You may define your own data presentation using the underlying `Result` by specializing data() and accessing data from resultRow().

You may selectively add fields that you want to display using addColumn(), or you can also add all columns based on the query using addAllFieldsAsColumns().

The model supports editing of the underlying data (even if the underlying query fetches results from multiple tables!). Values in columns that correspond to fields that have been mapped (and are writable) in a Database Object can be edited. The default implementation of setData() uses query_result_traits<Result>::setValue() to manipulate the database object, and thus uses the same write-behind properties as ptr<C>::modify(). To customize editing, you can specialize setData() and use resultRow() to modify the result object directly.

The model supports also inserting rows (only at the end), and removing rows, which are reflected in object additions and removals from the Session.

Editing is directly to the underlying database objects (change, insert and remove). Note that these changes will be flushed to the database whenever a transaction is committed, or before a query is run. The model will not explicitly create a transaction for the modification, but since the model uses a query for reading data, the change may be committed to the database depending on how the model is loading data. Still, this implies that usually inserting a row and setting its data happens within a single SQL `"insert"` statement.

To get good performance, the model keeps the following data cached:

- rowCount()
- a batch of data, controlled by setBatchSize()

Moreover, the model will try to fetch a batch of data even if you ask for the rowCount(), which may provide the row count as a side-effect if the query returns less results than a single batch size. If you do not want this behaviour (which might be the case if you are only interested in rowCount(), not the actual data) then you can avoid this behaviour by setting batchSize to 0.

## Constructor & Destructor Documentation

## ◆ QueryModel()

template<class Result >

Wt::Dbo::QueryModel< Result >::QueryModel | ( |  | ) |

Creates a new query model.

You need to seed the model with a query using setQuery().

## Member Function Documentation

## ◆ addAllFieldsAsColumns()

template<class Result >

void Wt::Dbo::QueryModel< Result >::addAllFieldsAsColumns | ( |  | ) |

Adds all the columns from the field list.

All fields are added as columns. Fields that are mutable are marked as editable columns.

This is a convenient alternative to selectively adding columns using addColumn().

See also
  fields()

## ◆ addColumn() [1/2]

template<class Result >

int Wt::Dbo::QueryModel< Result >::addColumn | ( | const std::string & | field,
|  | const WString & | header,
|  | WFlags< ItemFlag > | flags = ItemFlag::Selectable )

Adds a column.

The `field` name may be a qualified or unqualified field name. The list of available fields can be inspected using fields().

The `header` is used as Wt::ItemDataRole::Display for the column header data.

For the column items, flags() will returned the given `flags`. For example, to indicate that a field is editable, you can set the Wt::ItemFlag::Editable flag.

See also
  fields()

## ◆ addColumn() [2/2]

template<class Result >

int Wt::Dbo::QueryModel< Result >::addColumn | ( | const std::string & | field,
|  | WFlags< ItemFlag > | flags = ItemFlag::Selectable )

Adds a column.

This is an overloaded function for convenience, which uses the field name as the header value.

See also
  setHeaderData()

## ◆ addRow()

template<class Result >

void Wt::Dbo::QueryModel< Result >::addRow | ( | Result & | result | ) |
| protectedvirtual

Adds a row to the session.

This method is called from within insertRows() to add (and save) a new result row to the Dbo session.

The default implementation uses query_result_traits<Result>::add().

## ◆ batchSize()

template<class Result >

int Wt::Dbo::QueryModel< Result >::batchSize | ( |  | ) | const

Returns the batch size for fetching results.

See also
  setBatchSize()

## ◆ columnCount()

template<class Result >

int Wt::Dbo::QueryModel< Result >::columnCount | ( | const WModelIndex & | parent = WModelIndex() | ) | const
| overridevirtual

Returns the number of columns.

Returns the number of columns that have been added using addColumn() or addAllFieldsAsColumns().

Since the query model implements a flat table model, this returns 0 when `parent` is valid.

Implements Wt::WAbstractItemModel.

## ◆ columnFlags()

template<class Result >

WFlags< ItemFlag > Wt::Dbo::QueryModel< Result >::columnFlags | ( | int | column | ) | const

Returns column item flags.

See also
  setColumnFlags()

## ◆ createOrderBy()

template<class Result >

std::string Wt::Dbo::QueryModel< Result >::createOrderBy | ( | int | column,
|  | SortOrder | order )
| virtual

Create specialized orderBy clause for sort.

The sort() method calls createOrderBy() to format a SQL clause for use in Query<BindStrategy>::orderBy(). The default is to return a string that will sort on a single column in the specified order.

Customize this method if you need a more complex orderBy clause, e.g. to break ties consistently.

See also
  sort()

## ◆ createRow()

template<class Result >

Result Wt::Dbo::QueryModel< Result >::createRow | ( |  | ) |
| protectedvirtual

Creates a new row.

This method is called from within insertRows() to create a new row.

The default implementation uses query_result_traits<Result>::create().

## ◆ data() [1/2]

template<class Result >

cpp17::any Wt::Dbo::QueryModel< Result >::data | ( | const WModelIndex & | index,
|  | ItemDataRole | role = ItemDataRole::Display ) const
| overridevirtual

Returns the data for an item.

Returns data of type Wt::ItemDataRole::Display or Wt::ItemDataRole::Edit based on the field value corresponding to the index. If necessary, this fetches a batch of results from the underlying database.

The default implementation of data() converts Query results to model data using query_result_traits<Result>::getValues(). You may define your own data presentation using the underlying `Result` by specializing data() and accessing data from resultRow().

Implements Wt::WAbstractItemModel.

## ◆ data() [2/2]

template<class Result >

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::WAbstractTableModel::index
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const override
Returns the child index for the given row and column.
Wt::WAbstractTableModel::parent
virtual WModelIndex parent(const WModelIndex &index) const override
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()

## ◆ deleteRow()

template<class Result >

void Wt::Dbo::QueryModel< Result >::deleteRow | ( | Result & | result | ) |
| protectedvirtual

Deletes a row from the session.

This method is called from within removeRows() to remove (and delete) a new result row from the Dbo session.

The default implementation uses query_result_traits<Result>::remove().

## ◆ fields()

template<class Result >

const std::vector< FieldInfo > & Wt::Dbo::QueryModel< Result >::fields | ( |  | ) | const

Returns the query field list.

This returns the field list from the underlying query.

## ◆ flags()

template<class Result >

WFlags< ItemFlag > Wt::Dbo::QueryModel< Result >::flags | ( | const WModelIndex & | index | ) | const
| overridevirtual

Returns the flags for an item.

Returns the flags set for the column using setColumnFlags().

Reimplemented from Wt::WAbstractItemModel.

## ◆ fromRawIndex()

template<class Result >

WModelIndex Wt::Dbo::QueryModel< Result >::fromRawIndex | ( | void * | rawIndex | ) | const
| overridevirtual

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.

## ◆ headerData()

template<class Result >

cpp17::any Wt::Dbo::QueryModel< Result >::headerData | ( | int | section,
|  | Orientation | orientation = Orientation::Horizontal,
|  | ItemDataRole | role = ItemDataRole::Display ) const
| overridevirtual

Returns header data.

See also
  setHeaderData()

Reimplemented from Wt::WAbstractItemModel.

## ◆ indexOf()

template<class Result >

int Wt::Dbo::QueryModel< Result >::indexOf | ( | const Result & | row | ) | const

Returns the index of row.

If the row isn't contained in the model, returns -1.

## ◆ insertRows()

template<class Result >

bool Wt::Dbo::QueryModel< Result >::insertRows | ( | int | row,
|  | int | count,
|  | const WModelIndex & | parent = WModelIndex() )
| overridevirtual

Inserts one or more rows.

Row insertions are only supported at the end (`row` == rowCount()). For each added row, a new result is added to the underlying database.

Reimplemented from Wt::WAbstractItemModel.

## ◆ query()

template<class Result >

Query< Result > Wt::Dbo::QueryModel< Result >::query | ( |  | ) | const

Returns the query.

See also
  setQuery()

## ◆ reload()

template<class Result >

void Wt::Dbo::QueryModel< Result >::reload | ( |  | ) |

Rereads the data from the database.

This invalidates the current (cached) data and informs views that they should rerender. This emits the layoutAboutToBeChanged() signal to inform the views that data and perhaps also row count was changed.

## ◆ removeRows()

template<class Result >

bool Wt::Dbo::QueryModel< Result >::removeRows | ( | int | row,
|  | int | count,
|  | const WModelIndex & | parent = WModelIndex() )
| overridevirtual

Removes one or more rows.

For each removed row, the result is removed from the underlying database.

Reimplemented from Wt::WAbstractItemModel.

## ◆ resultById()

template<class Result >

Result Wt::Dbo::QueryModel< Result >::resultById | ( | long long | id | ) | const
| protectedvirtual

Returns a result by id.

This should be the inverse of the resultId() function.

The default implementation uses query_result_traits<Result>::findById().

## ◆ resultId()

template<class Result >

long long Wt::Dbo::QueryModel< Result >::resultId | ( | const Result & | result | ) | const
| protectedvirtual

Returns a unique id for a result.

This should, if possible, identify the result using a unique long long id, and otherwise return -1.

The default implementation uses query_result_traits<Result>::id().

This is required for a working stableResultRow() implementation.

See also
  resultById()

## ◆ resultRow() [1/2]

template<class Result >

Result & Wt::Dbo::QueryModel< Result >::resultRow | ( | int | row | ) |
| virtual

Returns a result row.

This returns the result corresponding to a particular row, and could be used to customize the model behaviour, e.g. by specializing setData() for certain columns.

Returns a reference to an entry in the result cache.

See also
  resultRow(int row) const

## ◆ resultRow() [2/2]

template<class Result >

const Result & Wt::Dbo::QueryModel< Result >::resultRow | ( | int | row | ) | const

Returns a result row.

This returns the result corresponding to a particular row, and could be used to customize the model behaviour, e.g. by specializing data() for certain columns.

Returns a const reference to an entry in the result cache.

## ◆ rowCount()

template<class Result >

int Wt::Dbo::QueryModel< Result >::rowCount | ( | const WModelIndex & | parent = WModelIndex() | ) | const
| overridevirtual

Returns the number of rows.

Returns the number of rows returned from the underlying query.

Since the query model implements a flat table model, this returns 0 when `parent` is valid.

Implements Wt::WAbstractItemModel.

## ◆ setBatchSize()

template<class Result >

void Wt::Dbo::QueryModel< Result >::setBatchSize | ( | int | count | ) |

Sets the batch size for fetching results.

The model fetches results from the query in batch, and caches these in memory to avoid repetitive querying of the database.

The default batch size is 40.

## ◆ setColumnFlags()

template<class Result >

void Wt::Dbo::QueryModel< Result >::setColumnFlags | ( | int | column,
|  | WFlags< ItemFlag > | flags )

Sets column item flags.

For items in column `column`, flags() will returned the given `flags`. For example, to indicate that a field is editable, you can set the Wt::ItemFlag::Editable flag.

## ◆ setData() [1/2]

template<class Result >

bool Wt::Dbo::QueryModel< Result >::setData | ( | const WModelIndex & | index,
|  | const cpp17::any & | value,
|  | ItemDataRole | role = ItemDataRole::Edit )
| overridevirtual

Sets data at the given model index.

If `role` = Wt::ItemDataRole::Edit, sets the value for the field corresponding to the index. All other editing is ignored.

See also
  setCachedResult()

Reimplemented from Wt::WAbstractItemModel.

## ◆ setData() [2/2]

template<class Result >

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::Dbo::QueryModel::setData
virtual bool setData(const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
Sets data at the given model index.
Definition QueryModel_impl.h:175

Returns `true` if the operation was successful.

See also
  setData(), index()

## ◆ setHeaderData()

template<class Result >

bool Wt::Dbo::QueryModel< Result >::setHeaderData | ( | int | column,
|  | Orientation | orientation,
|  | const cpp17::any & | value,
|  | ItemDataRole | role = ItemDataRole::Edit )
| overridevirtual

Sets header data for a column.

The model will return this data in headerData(). Only column headers are supported (orientation == Wt::Orientation::Horizontal).

Reimplemented from Wt::WAbstractItemModel.

## ◆ setQuery()

template<class Result >

void Wt::Dbo::QueryModel< Result >::setQuery | ( | const Query< Result > & | query,
|  | bool | keepColumns = false )

Sets the query.

The `query` is used to query the database.

Unless `keepColumns` is `true`, this resets the column list, so you will need to (re-)add one or more columns using addColumn().

When keeping the current columns, a LayoutChange rather than a Reset is emitted by the model, allowing views to keep their column geometry as well.

## ◆ sort()

template<class Result >

void Wt::Dbo::QueryModel< Result >::sort | ( | int | column,
|  | SortOrder | order = SortOrder::Ascending )
| overridevirtual

Sorts the model according to a particular column.

This sorts the model by changing the query using Query<BindStrategy>::orderBy().

See also
  createOrderBy()

Reimplemented from Wt::WAbstractItemModel.

## ◆ stableResultRow()

template<class Result >

Result Wt::Dbo::QueryModel< Result >::stableResultRow | ( | int | row | ) | const

Returns a stable result row.

This return the same result row as was previously returned by resultRow(), even if there were database inserts going on.

This requires suitable implementations for resultId() and resultById() functions.

If the row wasn't fetched before (or since a reload()), then the result of resultRow() is returned instead.

## ◆ toRawIndex()

template<class Result >

void * Wt::Dbo::QueryModel< Result >::toRawIndex | ( | const WModelIndex & | index | ) | const
| overridevirtual

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.