Wt
3.2.0
|
An model that manages a list of strings. More...
#include <Wt/WStringListModel>
Public Member Functions | |
WStringListModel (WObject *parent=0) | |
Creates a new empty string list model. | |
WStringListModel (const std::vector< WString > &strings, WObject *parent=0) | |
Creates a new string list model. | |
~WStringListModel () | |
Destructor. | |
void | setStringList (const std::vector< WString > &strings) |
Sets a new string list. | |
void | insertString (int row, const WString &string) |
Inserts a string. | |
void | addString (const WString &string) |
Adds a string. | |
const std::vector< WString > & | stringList () const |
Returns the string list. | |
virtual WFlags< ItemFlag > | flags (const WModelIndex &index) const |
Returns the flags for an item. | |
virtual bool | setData (const WModelIndex &index, const boost::any &value, int role=EditRole) |
Sets data at the given model index. | |
virtual boost::any | data (const WModelIndex &index, int role=DisplayRole) const |
Returns data at a specific model index. | |
virtual int | rowCount (const WModelIndex &parent=WModelIndex()) const |
Returns the number of rows. | |
virtual bool | insertRows (int row, int count, const WModelIndex &parent=WModelIndex()) |
Inserts one or more rows. | |
virtual bool | removeRows (int row, int count, const WModelIndex &parent=WModelIndex()) |
Removes rows. | |
virtual void | sort (int column, SortOrder order=AscendingOrder) |
Sorts the model according to a particular column. |
An model that manages a list of strings.
This model only manages a unidimensional list of strings. It is used as the default model for view classes that show a list.
The model only presents DisplayRole data of a single column of data, but otherwise provides support for all standard features of a model, including editing and addition and removal of data rows.
You can populate the model by passing a list of strings to its consructor, or by using the setStringList() method. You can set or retrieve data using the setData() and data() methods, and add or remove data using the insertRows() and removeRows() methods.
void Wt::WStringListModel::addString | ( | const WString & | string | ) |
Adds a string.
boost::any Wt::WStringListModel::data | ( | const WModelIndex & | index, |
int | role = DisplayRole |
||
) | const [virtual] |
Returns data at a specific model index.
Return data for a given role at a given index.
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::DisplayRole) but also icons (Wt::DecorationRole), URLs (Wt::LinkRole), and other visual aspects. If your item does not specify data for a particular role, it should simply return a boost::any().
Implements Wt::WAbstractItemModel.
WFlags< ItemFlag > Wt::WStringListModel::flags | ( | const WModelIndex & | index | ) | const [virtual] |
Returns the flags for an item.
This method is reimplemented to return ItemIsSelectable | ItemIsEditable.
Reimplemented from Wt::WAbstractItemModel.
bool Wt::WStringListModel::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.
Reimplemented from Wt::WAbstractItemModel.
void Wt::WStringListModel::insertString | ( | int | row, |
const WString & | string | ||
) |
Inserts a string.
bool Wt::WStringListModel::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.
Reimplemented from Wt::WAbstractItemModel.
int Wt::WStringListModel::rowCount | ( | const WModelIndex & | parent = WModelIndex() | ) | const [virtual] |
Returns the number of rows.
This returns the number of rows at index parent
.
Implements Wt::WAbstractItemModel.
bool Wt::WStringListModel::setData | ( | const WModelIndex & | index, |
const boost::any & | value, | ||
int | role = EditRole |
||
) | [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.
Reimplemented from Wt::WAbstractItemModel.
void Wt::WStringListModel::setStringList | ( | const std::vector< WString > & | strings | ) |
Sets a new string list.
Replaces the current string list with a new list.
void Wt::WStringListModel::sort | ( | int | column, |
SortOrder | order = AscendingOrder |
||
) | [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 std::vector<WString>& Wt::WStringListModel::stringList | ( | ) | const |
Returns the string list.