Wt  4.11.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::WStringListModel Class Reference

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

#include <Wt/WStringListModel.h>

Inheritance diagram for Wt::WStringListModel:
[legend]

Public Member Functions

 WStringListModel ()
 Creates a new empty string list model.
 
 WStringListModel (const std::vector< WString > &strings)
 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.
 
void setFlags (int index, WFlags< ItemFlag > flags)
 Sets model flags for an item.
 
virtual WFlags< ItemFlagflags (const WModelIndex &index) const override
 Returns the flags for an item.
 
virtual bool setData (const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) override
 Sets data at the given model index.
 
virtual cpp17::any data (const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const override
 Returns data at a specified model index for the given role.
 
virtual int rowCount (const WModelIndex &parent=WModelIndex()) const override
 Returns the number of rows.
 
virtual bool insertRows (int row, int count, const WModelIndex &parent=WModelIndex()) override
 Inserts one or more rows.
 
virtual bool removeRows (int row, int count, const WModelIndex &parent=WModelIndex()) override
 Removes rows.
 
virtual void sort (int column, SortOrder order=SortOrder::Ascending) override
 Sorts the model according to a particular column.
 
- Public Member Functions inherited from Wt::WAbstractListModel
 WAbstractListModel ()
 Create a new abstract list model.
 
 ~WAbstractListModel ()
 Destructor.
 
virtual WModelIndex parent (const WModelIndex &index) const override
 Returns the parent for a model index.
 
virtual WModelIndex index (int row, int column=0, const WModelIndex &parent=WModelIndex()) const override
 Returns the child index for the given row and column.
 
virtual int columnCount (const WModelIndex &parent=WModelIndex()) const override
 Returns the number of columns.
 
- Public Member Functions inherited from Wt::WAbstractItemModel
 WAbstractItemModel ()
 Creates a new data model.
 
virtual WFlags< HeaderFlagheaderFlags (int section, Orientation orientation=Orientation::Horizontal) const
 Returns the flags for a header.
 
virtual bool hasChildren (const WModelIndex &index) const
 Returns if there are children at an index.
 
virtual DataMap itemData (const WModelIndex &index) const
 Returns all data at a specific index.
 
virtual cpp17::any headerData (int section, Orientation orientation=Orientation::Horizontal, ItemDataRole role=ItemDataRole::Display) const
 Returns the row or column header data.
 
virtual WModelIndexList match (const WModelIndex &start, ItemDataRole role, const cpp17::any &value, int hits=-1, WFlags< MatchFlag > flags=WFlags< MatchFlag >(MatchFlag::StartsWith|MatchFlag::Wrap)) const
 Returns an index list for data items that match.
 
cpp17::any data (int row, int column, ItemDataRole role=ItemDataRole::Display, const WModelIndex &parent=WModelIndex()) const
 Returns the data item at the given column and row.
 
virtual bool hasIndex (int row, int column, const WModelIndex &parent=WModelIndex()) const
 Returns if an index at the given position is valid (i.e. falls within the column-row bounds).
 
virtual bool insertColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Inserts one or more columns.
 
virtual bool removeColumns (int column, int count, const WModelIndex &parent=WModelIndex())
 Removes columns.
 
virtual bool setItemData (const WModelIndex &index, const DataMap &values)
 Sets data at the given model index.
 
virtual bool setHeaderData (int section, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
 Sets header data for a column or row.
 
bool setHeaderData (int section, const cpp17::any &value)
 Sets column header data.
 
virtual void expandColumn (int column)
 Expands a column.
 
virtual void collapseColumn (int column)
 Collapses a column.
 
virtual voidtoRawIndex (const WModelIndex &index) const
 Converts a model index to a raw pointer that remains valid while the model's layout is changed.
 
virtual WModelIndex fromRawIndex (void *rawIndex) const
 Converts a raw pointer to a model index.
 
virtual std::string mimeType () const
 Returns a mime-type for dragging a set of indexes.
 
virtual std::vector< std::string > acceptDropMimeTypes () const
 Returns a list of mime-types that could be accepted for a drop event.
 
virtual void dropEvent (const WDropEvent &e, DropAction action, int row, int column, const WModelIndex &parent)
 Handles a drop event.
 
virtual void dropEvent (const WDropEvent &e, DropAction action, const WModelIndex &index, Wt::Side side)
 Handles a drop event.
 
bool insertColumn (int column, const WModelIndex &parent=WModelIndex())
 Inserts one column.
 
bool insertRow (int row, const WModelIndex &parent=WModelIndex())
 Inserts one row.
 
bool removeColumn (int column, const WModelIndex &parent=WModelIndex())
 Removes one column.
 
bool removeRow (int row, const WModelIndex &parent=WModelIndex())
 Removes one row.
 
bool setData (int row, int column, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit, const WModelIndex &parent=WModelIndex())
 Sets data at the given row and column.
 
virtual Signal< WModelIndex, int, int > & columnsAboutToBeInserted ()
 Signal emitted before a number of columns will be inserted.
 
virtual Signal< WModelIndex, int, int > & columnsAboutToBeRemoved ()
 Signal emitted before a number of columns will be removed.
 
virtual Signal< WModelIndex, int, int > & columnsInserted ()
 Signal emitted after a number of columns were inserted.
 
virtual Signal< WModelIndex, int, int > & columnsRemoved ()
 Signal emitted after a number of columns were removed.
 
virtual Signal< WModelIndex, int, int > & rowsAboutToBeInserted ()
 Signal emitted before a number of rows will be inserted.
 
virtual Signal< WModelIndex, int, int > & rowsAboutToBeRemoved ()
 Signal emitted before a number of rows will be removed.
 
virtual Signal< WModelIndex, int, int > & rowsInserted ()
 Signal emitted after a number of rows were inserted.
 
virtual Signal< WModelIndex, int, int > & rowsRemoved ()
 Signal emitted after a number of rows were removed.
 
virtual Signal< WModelIndex, WModelIndex > & dataChanged ()
 Signal emitted when some data was changed.
 
virtual Signal< Orientation, int, int > & headerDataChanged ()
 Signal emitted when some header data was changed.
 
virtual SignallayoutAboutToBeChanged ()
 Signal emitted when the layout is about to be changed.
 
virtual SignallayoutChanged ()
 Signal emitted when the layout is changed.
 
virtual SignalmodelReset ()
 Signal emitted when the model was reset.
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 Add a child WObject whose lifetime is determined by this WObject.
 
template<typename Child >
ChildaddChild (std::unique_ptr< Child > child)
 Add a child WObject, returning a raw pointer.
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 Remove a child WObject, so its lifetime is no longer determined by this WObject.
 
template<typename Child >
std::unique_ptr< ChildremoveChild (Child *child)
 Remove a child WObject, so its lifetime is no longer determined by this WObject.
 
virtual const std::string id () const
 Returns the (unique) identifier for this object.
 
virtual void setObjectName (const std::string &name)
 Sets an object name.
 
virtual std::string objectName () const
 Returns the object name.
 
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
 
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
 
void isNotStateless ()
 Marks the current function as not stateless.
 
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 Default constructor.
 
virtual ~observable ()
 Destructor.
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...)) noexcept
 Protects a method call against object destruction.
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 Protects a const method call against object destruction.
 
template<typename Function >
auto bindSafe (const Function &function) noexcept
 Protects a function against object destruction.
 

Additional Inherited Members

- Public Types inherited from Wt::WAbstractItemModel
typedef std::map< ItemDataRole, cpp17::any > DataMap
 Data map.
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 Typedef for a WObject method without arguments.
 
- Protected Member Functions inherited from Wt::WAbstractItemModel
void reset ()
 Resets the model and invalidate any data.
 
WModelIndex createIndex (int row, int column, void *ptr) const
 Creates a model index for the given row and column.
 
WModelIndex createIndex (int row, int column, ::uint64_t id) const
 Creates a model index for the given row and column.
 
void beginInsertColumns (const WModelIndex &parent, int first, int last)
 Method to be called before inserting columns.
 
void beginInsertRows (const WModelIndex &parent, int first, int last)
 Method to be called before inserting rows.
 
void beginRemoveColumns (const WModelIndex &parent, int first, int last)
 Method to be called before removing columns.
 
void beginRemoveRows (const WModelIndex &parent, 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.
 
virtual void copyData (const WModelIndex &sIndex, const WModelIndex &dIndex)
 Copy data to an index in this model.
 
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.
 

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

Member Function Documentation

◆ addString()

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

Adds a string.

See also
setStringList()

◆ data()

cpp17::any Wt::WStringListModel::data ( const WModelIndex index,
ItemDataRole  role = ItemDataRole::Display 
) const
overridevirtual

Returns data at a specified model index for the given role.

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::ItemDataRole::Display) but also icons (Wt::ItemDataRole::Decoration), URLs (Wt::ItemDataRole::Link), and other visual aspects. If your item does not specify data for a particular role, it should simply return a Wt::cpp17::any().

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

Implements Wt::WAbstractItemModel.

◆ flags()

WFlags< ItemFlag > Wt::WStringListModel::flags ( const WModelIndex index) const
overridevirtual

Returns the flags for an item.

This method is reimplemented to return flags set in setFlags().

See also
setFlags()

Reimplemented from Wt::WAbstractItemModel.

◆ insertRows()

bool Wt::WStringListModel::insertRows ( int  row,
int  count,
const WModelIndex parent = WModelIndex() 
)
overridevirtual

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.

◆ insertString()

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

Inserts a string.

See also
setStringList()

◆ removeRows()

bool Wt::WStringListModel::removeRows ( int  row,
int  count,
const WModelIndex parent = WModelIndex() 
)
overridevirtual

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.

◆ rowCount()

int Wt::WStringListModel::rowCount ( const WModelIndex parent = WModelIndex()) const
overridevirtual

Returns the number of rows.

This returns the number of rows at index parent.

See also
columnCount()

Implements Wt::WAbstractItemModel.

◆ setData()

bool Wt::WStringListModel::setData ( const WModelIndex index,
const cpp17::any &  value,
ItemDataRole  role = ItemDataRole::Edit 
)
overridevirtual

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.

◆ setFlags()

void Wt::WStringListModel::setFlags ( int  index,
WFlags< ItemFlag flags 
)

Sets model flags for an item.

The default item flags are ItemFlag::Selectable | ItemFlag::Editable.

◆ setStringList()

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

◆ sort()

void Wt::WStringListModel::sort ( int  column,
SortOrder  order = SortOrder::Ascending 
)
overridevirtual

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.

◆ stringList()

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

Returns the string list.

See also
setStringList()