#include <Wt/Dbo/QueryModel>
Public Member Functions | |
QueryModel (WObject *parent=0) | |
Creates a new query model. | |
void | setQuery (const Query< Result > &query) |
Sets the query. | |
const Query< Result > & | query () const |
Returns the query. | |
int | addColumn (const std::string &field) |
Adds a column. | |
void | addAllFieldsAsColumns () |
Adds all the columns from the field list. | |
virtual int | columnCount (const WModelIndex &parent=WModelIndex()) const |
Returns the number of columns. | |
virtual int | rowCount (const WModelIndex &parent=WModelIndex()) const |
Returns the number of rows. | |
virtual boost::any | data (const WModelIndex &index, int role=DisplayRole) const |
Returns data at a specific model index. | |
virtual boost::any | headerData (int section, Orientation orientation=Horizontal, int role=DisplayRole) const |
Returns the row or column header data. | |
virtual void | sort (int column, SortOrder order=AscendingOrder) |
Sorts the model according to a particular column. | |
const Result & | resultRow (int row) const |
Returns a result 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 () |
Returns the query field list. |
The model fetches results from the query (but is smart about what to fetch), and presents their data in a table. It supports sorting by altering the query to sort using SQL (Query::orderBy()). Query results are converted to model data using query_result_traits<Result>::getValues().
You may add columns which you want to display using addColumn(). You can also add all columns based on the query using addAllFieldsAsColumns().
Currently no editing support is provided.
Wt::Dbo::QueryModel< Result >::QueryModel | ( | WObject * | parent = 0 |
) | [inline] |
Creates a new query model.
You need to seed the model with a query using setQuery().
void Wt::Dbo::QueryModel< Result >::setQuery | ( | const Query< Result > & | query | ) | [inline] |
Sets the query.
The query
is used to query the database.
int Wt::Dbo::QueryModel< Result >::addColumn | ( | const std::string & | field | ) | [inline] |
Adds a column.
The field
name may be a qualified or unqualified field name.
void Wt::Dbo::QueryModel< Result >::addAllFieldsAsColumns | ( | ) | [inline] |
int Wt::Dbo::QueryModel< Result >::columnCount | ( | const WModelIndex & | parent = WModelIndex() |
) | const [inline, virtual] |
Returns the number of columns.
This returns the number of columns at index parent
.
Implements Wt::WAbstractItemModel.
int Wt::Dbo::QueryModel< Result >::rowCount | ( | const WModelIndex & | parent = WModelIndex() |
) | const [inline, virtual] |
Returns the number of rows.
This returns the number of rows at index parent
.
Implements Wt::WAbstractItemModel.
boost::any Wt::Dbo::QueryModel< Result >::data | ( | const WModelIndex & | index, | |
int | role = DisplayRole | |||
) | const [inline, virtual] |
Returns data at a specific model index.
Return data for a given role at a given index.
Implements Wt::WAbstractItemModel.
boost::any Wt::Dbo::QueryModel< Result >::headerData | ( | int | section, | |
Orientation | orientation = Horizontal , |
|||
int | role = DisplayRole | |||
) | const [inline, virtual] |
Returns the row or column header data.
When orientation
is Horizontal, section
is a column number, when orientation
is Vertical, section
is a row number.
Reimplemented from Wt::WAbstractItemModel.
void Wt::Dbo::QueryModel< Result >::sort | ( | int | column, | |
SortOrder | order = AscendingOrder | |||
) | [inline, 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.
Reimplemented from Wt::WAbstractItemModel.
const Result & Wt::Dbo::QueryModel< Result >::resultRow | ( | int | row | ) | const [inline] |
Returns a result row.
This returns the result corresponding to a particular row, and could be used to customize the view or provide editing support.
void Wt::Dbo::QueryModel< Result >::reload | ( | ) | [inline] |
Rereads the data from the database.
This invalidates the current (cached) data and informs views that they should rerender.
void Wt::Dbo::QueryModel< Result >::setBatchSize | ( | int | count | ) | [inline] |
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.
int Wt::Dbo::QueryModel< Result >::batchSize | ( | ) | const [inline] |
const std::vector<FieldInfo>& Wt::Dbo::QueryModel< Result >::fields | ( | ) |
Returns the query field list.
This returns the field list from the underlying query.