Class WStringListModel
public class WStringListModel extends WAbstractListModel
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 getData()
methods, and add or remove data using the insertRows()
and removeRows()
methods.
- See Also:
WComboBox
,WSelectionBox
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WStringListModel()
Creates a new empty string list model.WStringListModel(WObject parent)
Creates a new empty string list model.WStringListModel(java.util.List<WString> strings)
Creates a new string list model.WStringListModel(java.util.List<WString> strings, WObject parent)
Creates a new string list model. -
Method Summary
Modifier and Type Method Description void
addString(java.lang.CharSequence string)
Adds a string.java.lang.Object
getData(WModelIndex index, int role)
Returns data at a specified model index for the given role.java.util.EnumSet<ItemFlag>
getFlags(WModelIndex index)
Returns the flags for an item.int
getRowCount(WModelIndex parent)
Returns the number of rows.java.util.List<WString>
getStringList()
Returns the string list.boolean
insertRows(int row, int count, WModelIndex parent)
Inserts one or more rows.void
insertString(int row, java.lang.CharSequence string)
Inserts a string.boolean
removeRows(int row, int count, WModelIndex parent)
Removes rows.boolean
setData(WModelIndex index, java.lang.Object value, int role)
Sets data at the given model index.void
setFlags(int row, ItemFlag flag, ItemFlag... flags)
Sets model flags for an item.void
setFlags(int row, java.util.EnumSet<ItemFlag> flags)
Sets model flags for an item.void
setStringList(java.util.List<WString> strings)
Sets a new string list.void
sort(int column, SortOrder order)
Sorts the model according to a particular column.Methods inherited from class eu.webtoolkit.jwt.WAbstractListModel
getColumnCount, getIndex, getParent
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, createIndex, createIndex, dataChanged, dropEvent, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, fromRawIndex, getAcceptDropMimeTypes, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderData, getHeaderFlags, getHeaderFlags, getIndex, getItemData, getMimeType, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, setItemData, sort, toRawIndex
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WStringListModel
Creates a new empty string list model. -
WStringListModel
public WStringListModel()Creates a new empty string list model.Calls
this((WObject)null)
-
WStringListModel
Creates a new string list model. -
WStringListModel
Creates a new string list model.
-
-
Method Details
-
setStringList
Sets a new string list.Replaces the current string list with a new list.
-
insertString
public void insertString(int row, java.lang.CharSequence string)Inserts a string.- See Also:
setStringList(List strings)
-
addString
public void addString(java.lang.CharSequence string)Adds a string.- See Also:
setStringList(List strings)
-
getStringList
Returns the string list.- See Also:
setStringList(List strings)
-
setFlags
Sets model flags for an item.The default item flags are
ItemFlag.ItemIsSelectable
|ItemFlag.ItemIsEditable
. -
setFlags
Sets model flags for an item. -
getFlags
Returns the flags for an item.This method is reimplemented to return flags set in
setFlags()
.- Overrides:
getFlags
in classWAbstractItemModel
- See Also:
setFlags(int row, EnumSet flags)
-
setData
Description copied from class:WAbstractItemModel
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.- Overrides:
setData
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getData(WModelIndex index, int role)
-
getData
Description copied from class:WAbstractItemModel
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 (ItemDataRole.DisplayRole
) but also icons (ItemDataRole.DecorationRole
), URLs (ItemDataRole.LinkRole
), and other visual aspects. If your item does not specify data for a particular role, it should simply return a boost::any(). -
getRowCount
Description copied from class:WAbstractItemModel
Returns the number of rows.This returns the number of rows at index
parent
.- Specified by:
getRowCount
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getColumnCount(WModelIndex parent)
-
insertRows
Description copied from class:WAbstractItemModel
Inserts one or more rows.In models that support row insertion, this inserts
count
rows, starting atrow
, and returnstrue
if the operation was successful. The new rows are inserted underparent
.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()
andendInsertRows()
before and after the operation whenever its geometry is changed by inserting rows. This emits signals for views to properly react to these changes.- Overrides:
insertRows
in classWAbstractItemModel
- See Also:
WAbstractItemModel.insertColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.removeRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.beginInsertRows(WModelIndex parent, int first, int last)
,WAbstractItemModel.endInsertRows()
-
removeRows
Description copied from class:WAbstractItemModel
Removes rows.Returns
true
if the operation was successful.The default implementation returns
false
.The model implementation must call
beginRemoveRows()
andendRemoveRows()
before and after the operation whenever its geometry is changed by removing rows. This emits signals for views to properly react to these changes.- Overrides:
removeRows
in classWAbstractItemModel
- See Also:
WAbstractItemModel.removeColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.insertRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.beginRemoveRows(WModelIndex parent, int first, int last)
,WAbstractItemModel.endRemoveRows()
-
sort
Description copied from class:WAbstractItemModel
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 thelayoutChanged()
signal.- Overrides:
sort
in classWAbstractItemModel
- See Also:
WAbstractItemModel.layoutAboutToBeChanged()
,WAbstractItemModel.layoutChanged()
-