Wt: Wt::WStringListModel Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Private Types
Wt::WStringListModel Class Reference
Model/view system

An model that manages a list of strings. More...

`#include <Wt/WStringListModel>`

Inheritance diagram for Wt::WStringListModel:
[legend]

List of all members.

## 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.
## Private Types
typedef std::map< int, boost::any > | DataMap
| Data map.

## Detailed Description

An model that manages a list of strings.

This model only manages a unidimensional list of items and is optimized for usage by view widgets such as combo-boxes.

It supports all features of a typical item model, including data for multiple roles, 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.

See also:
  WComboBox, WSelectionBox, Ext::ComboBox

## Member Typedef Documentation

typedef std::map<int, boost::any> Wt::WStringListModel::DataMap`[private]`

Data map.

A map of data, indexed by a role.

Reimplemented from Wt::WAbstractItemModel.

## Member Function Documentation

void Wt::WStringListModel::addString | ( | const WString & | string | ) |

Adds a string.

See also:
  setStringList()

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().

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

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.

See also:
  Wt::ItemFlag

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.

See also:
  insertColumns(), removeRows(), beginInsertRows(), endInsertRows()

Reimplemented from Wt::WAbstractItemModel.

void Wt::WStringListModel::insertString | ( | int | row,
|  | const WString & | string
| ) |  |

Inserts a string.

See also:
  setStringList()

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.

See also:
  removeColumns(), insertRows(), beginRemoveRows(), endRemoveRows()

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`.

See also:
  columnCount()

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.

See also:
  data()

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.

See also:
  dataChanged()
  addString()

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.

See also:
  layoutAboutToBeChanged(), layoutChanged()

Reimplemented from Wt::WAbstractItemModel.

const std::vector<WString>& Wt::WStringListModel::stringList | ( |  | ) | const

Returns the string list.

See also:
  setStringList()

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator