#include <Wt/WAbstractItemModel>
Public Member Functions | |
WAbstractItemModel (WObject *parent=0) | |
Create a new data model. | |
virtual | ~WAbstractItemModel () |
Destructor. | |
virtual int | columnCount () const =0 |
Get the number of columns. | |
virtual int | rowCount () const =0 |
Get the number of rows. | |
virtual boost::any | data (const WModelIndex &index) const =0 |
Get the data value at a specific model index. | |
virtual boost::any | headerData (int column) const =0 |
Get the header value for a given column. | |
virtual WModelIndex | index (int row, int column) const =0 |
Get the index for the given row and column. | |
virtual WModelIndexList | match (const WModelIndex &start, const boost::any &value, int hits=-1, MatchFlags flags=MatchFlags(MatchStartsWith|MatchWrap)) const |
Get an index list for data items that match. | |
boost::any | data (int row, int column) const |
Get the data item at the given column and row. | |
virtual bool | hasIndex (int row, int column) const |
Check if an index at the given position is valid (i.e. falls within the column-row bounds of the model). | |
virtual bool | insertColumns (int column, int count) |
Insert one or more columns. | |
virtual bool | insertRows (int row, int count) |
Insert one or more rows. | |
virtual bool | removeColumns (int column, int count) |
Remove columns. | |
virtual bool | removeRows (int row, int count) |
Remove rows. | |
virtual bool | setData (const WModelIndex &index, const boost::any &value)=0 |
Set data at the given model index. | |
virtual bool | setHeaderData (int column, const boost::any &value)=0 |
Set header data for the given column. | |
bool | insertColumn (int column) |
Insert one column. | |
bool | insertRow (int row) |
Insert one row. | |
bool | removeColumn (int column) |
Remove one column. | |
bool | removeRow (int row) |
Remove one row. | |
bool | setData (int row, int column, const boost::any &value) |
Set data at the given row and column. | |
virtual void | refresh () |
Refresh to adjusted to an updated locale. | |
Public Attributes | |
Signal< int, int > | columnsAboutToBeInserted |
Signal emitted before a number of columns will be inserted. | |
Signal< int, int > | columnsAboutToBeRemoved |
Signal emitted before a number of columns will be removed. | |
Signal< int, int > | columnsInserted |
Signal emitted after a number of columns were inserted. | |
Signal< int, int > | columnsRemoved |
Signal emitted after a number of columns were removed. | |
Signal< int, int > | rowsAboutToBeInserted |
Signal emitted before a number of rows will be inserted. | |
Signal< int, int > | rowsAboutToBeRemoved |
Signal emitted before a number of rows will be removed. | |
Signal< int, int > | rowsInserted |
Signal emitted after a number of rows were inserted. | |
Signal< int, int > | rowsRemoved |
Signal emitted after a number of rows were removed. | |
Signal< const WModelIndex &, const WModelIndex & > | dataChanged |
Signal emitted when some data was changed. | |
Signal< int, int > | headerDataChanged |
Signal emitted when some header data was changed. | |
Protected Member Functions | |
WModelIndex | createIndex (int row, int column) const |
Create a model index for the given row and column. | |
void | beginInsertColumns (int first, int last) |
Method to be called before inserting columns. | |
void | beginInsertRows (int first, int last) |
Method to be called before inserting rows. | |
void | beginRemoveColumns (int first, int last) |
Method to be called before removing columns. | |
void | beginRemoveRows (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. | |
Related Functions | |
(Note that these are not member functions.) | |
WT_API WString | asString (const boost::any &v) |
Interpret a boost::any as a string value. | |
WT_API double | asNumber (const boost::any &v) |
Interpret a boost::any as a number value. |
This abstract model is used by several Wt view widgets (WComboBox, WSelectionBox, Ext::ComboBox, and Ext::TableView) as data models. It organizes mixed-type data in a table (rows and columns), and propagates editing events to views.
The data itself is of type boost::any, which can hold the following kind of data:
Conversion between native types and boost::any is done like this:
boost::any a = boost::any(v);For example:
WDate d(1976,6,14); model->setData(row, column, boost::any(d));
Type v = boost::any_cast<Type>(a);For example:
WDate d = boost::any_cast<WDate>(model->data(row, column));
if (!a.empty()) { ... }
if (a.type() == typeid(double)) { ... }
In addition, there are a number of utility functions that try to interpret a boost::any value as a string (asString()) or number (asNumber()).
WModelIndexList Wt::WAbstractItemModel::match | ( | const WModelIndex & | start, | |
const boost::any & | value, | |||
int | hits = -1 , |
|||
MatchFlags | flags = MatchFlags(MatchStartsWith | MatchWrap) | |||
) | const [virtual] |
Get 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 specifes MatchWrap then the search wraps around from the start. If hits is not -1, then at most that number of hits are returned.
bool Wt::WAbstractItemModel::insertColumns | ( | int | column, | |
int | count | |||
) | [virtual] |
Insert one or more columns.
Returns true if the operation was successful.
Reimplemented in Wt::WStandardItemModel.
bool Wt::WAbstractItemModel::insertRows | ( | int | row, | |
int | count | |||
) | [virtual] |
Insert one or more rows.
Returns true if the operation was successful.
Reimplemented in Wt::WStandardItemModel.
bool Wt::WAbstractItemModel::removeColumns | ( | int | column, | |
int | count | |||
) | [virtual] |
Remove columns.
Returns true if the operation was successful.
Reimplemented in Wt::WStandardItemModel.
bool Wt::WAbstractItemModel::removeRows | ( | int | row, | |
int | count | |||
) | [virtual] |
virtual bool Wt::WAbstractItemModel::setData | ( | const WModelIndex & | index, | |
const boost::any & | value | |||
) | [pure virtual] |
Set data at the given model index.
Returns true if the operation was successful.
Implemented in Wt::WStandardItemModel.
virtual bool Wt::WAbstractItemModel::setHeaderData | ( | int | column, | |
const boost::any & | value | |||
) | [pure virtual] |
Set header data for the given column.
Returns true if the operation was successful.
Implemented in Wt::WStandardItemModel.
bool Wt::WAbstractItemModel::insertColumn | ( | int | column | ) |
Insert one column.
Returns true if the operation was successful.
bool Wt::WAbstractItemModel::insertRow | ( | int | row | ) |
Insert one row.
Returns true if the operation was successful.
bool Wt::WAbstractItemModel::removeColumn | ( | int | column | ) |
Remove one column.
Returns true if the operation was successful.
bool Wt::WAbstractItemModel::removeRow | ( | int | row | ) |
Remove one row.
Returns true if the operation was successful.
bool Wt::WAbstractItemModel::setData | ( | int | row, | |
int | column, | |||
const boost::any & | value | |||
) |
Set data at the given row and column.
Returns true if the operation was successful.
void Wt::WAbstractItemModel::refresh | ( | ) | [virtual] |
Refresh to adjusted to an updated locale.
The default implementation simply refreshes all WString headers and data. Reimplement this method if you wish to refresh additional things.
WT_API WString asString | ( | const boost::any & | v | ) | [related] |
Interpret a boost::any as a string value.
A boost::any without a value is converted to an empty string and number types (integers and doubles) are lexically casted. A WDate is converted to a string using the "dd/MM/yy" notation.
WT_API double asNumber | ( | const boost::any & | v | ) | [related] |
Interpret a boost::any as a number value.
A boost::any without a value, or a string that does not represent a number, is converted to a "NaN". You can check for this value using the libc function isnan(). A WDate is converted to an integer number using the WDate::modifiedJulianDay() method.
Signal emitted before a number of columns will be inserted.
The two arguments are the indexes that the first and last column will have when inserted.
Signal emitted before a number of columns will be removed.
The two arguments are the indexes of the first and last column that will be removed.
Signal emitted after a number of columns were inserted.
The two arguments are the indexes of the first and last column that were inserted.
Signal<int, int> Wt::WAbstractItemModel::columnsRemoved |
Signal emitted after a number of columns were removed.
The two arguments are the indexes of the first and last column that were removed.
Signal emitted before a number of rows will be inserted.
The two arguments are the indexes that the first and last row will have when inserted.
Signal emitted before a number of rows will be removed.
The two arguments are the indexes of the first and last row that will be removed.
Signal<int, int> Wt::WAbstractItemModel::rowsInserted |
Signal emitted after a number of rows were inserted.
The two arguments are the indexes of the first and last row that were inserted.
Signal<int, int> Wt::WAbstractItemModel::rowsRemoved |
Signal emitted after a number of rows were removed.
The two arguments are the indexes of the first and last row that were removed.
Signal<const WModelIndex&, const WModelIndex&> Wt::WAbstractItemModel::dataChanged |
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.
Signal<int, int > Wt::WAbstractItemModel::headerDataChanged |
Signal emitted when some header data was changed.
The two arguments are the column indexes of the first and last column for which the header value was changed.