Wt::Dbo::QueryModel< Result > Class Template Reference
[Database Objects (Dbo)Model/view system]

A Wt MVC Model to view the results of a query. More...

#include <Wt/Dbo/QueryModel>

Inheritance diagram for Wt::Dbo::QueryModel< Result >:

Inheritance graph
[legend]

List of all members.

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.


Detailed Description

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

A Wt MVC Model to view the results of a query.

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.


Constructor & Destructor Documentation

template<class Result>
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().


Member Function Documentation

template<class Result>
void Wt::Dbo::QueryModel< Result >::setQuery ( const Query< Result > &  query  )  [inline]

Sets the query.

The query is used to query the database.

template<class Result>
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.

template<class Result>
void Wt::Dbo::QueryModel< Result >::addAllFieldsAsColumns (  )  [inline]

Adds all the columns from the field list.

See also:
fields()

template<class Result>
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.

See also:
rowCount()

Implements Wt::WAbstractItemModel.

template<class Result>
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.

See also:
columnCount()

Implements Wt::WAbstractItemModel.

template<class Result>
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.

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

Implements Wt::WAbstractItemModel.

template<class Result>
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.

See also:
data(), setHeaderData()

Reimplemented from Wt::WAbstractItemModel.

template<class Result>
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.

See also:
layoutAboutToBeChanged(), layoutChanged()

Reimplemented from Wt::WAbstractItemModel.

template<class Result>
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.

template<class Result>
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.

template<class Result>
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.

template<class Result>
int Wt::Dbo::QueryModel< Result >::batchSize (  )  const [inline]

Returns the batch size for fetching results.

See also:
setBatchSize()

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

Returns the query field list.

This returns the field list from the underlying query.


Generated on Thu May 20 18:14:52 2010 for Wt by doxygen 1.5.6