Class WBatchEditProxyModel
This proxy model presents data from a source model, and caches any editing operation without
affecting the underlying source model, until commitAll()
or revertAll()
is called. In this way, you can commit
all the editing in batch to the underlying source model, only when the user confirms the changes.
All editing operations are supported:
- changing data (setData())
- inserting and removing rows (
insertRows()
andremoveRows()
) - inserting and removing columns (
insertColumns()
andremoveColumns()
)
The model supports both simple tabular models, as well as hierarchical (tree-like / treetable-like) models, with children under items in the first column.
Default values for a newly inserted row can be set using setNewRowData()
and flags for its items using setNewRowFlags()
.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WAbstractProxyModel
WAbstractProxyModel.BaseItem
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Commits changes.int
getColumnCount
(WModelIndex parent) Returns the number of columns.getData
(WModelIndex index, ItemDataRole role) Returns the data at a specific model index.getFlags
(WModelIndex index) Returns the flags for an item.getHeaderData
(int section, Orientation orientation, ItemDataRole role) Returns the row or column header data.getIndex
(int row, int column, WModelIndex parent) Returns the child index for the given row and column.getParent
(WModelIndex index) Returns the parent for a model index.int
getRowCount
(WModelIndex parent) Returns the number of rows.boolean
insertColumns
(int column, int count, WModelIndex parent) Inserts one or more columns.boolean
insertRows
(int row, int count, WModelIndex parent) Inserts one or more rows.boolean
isDirty()
Returns whether changes have not yet been committed.mapFromSource
(WModelIndex sourceIndex) Maps a source model index to the proxy model.mapToSource
(WModelIndex proxyIndex) Maps a proxy model index to the source model.boolean
removeColumns
(int column, int count, WModelIndex parent) Removes columns.boolean
removeRows
(int row, int count, WModelIndex parent) Removes rows.void
Reverts changes.boolean
setData
(WModelIndex index, Object value, ItemDataRole role) Sets item data.void
setDirtyIndication
(ItemDataRole role, Object data) Configures data used to indicate a modified item.final void
setNewRowData
(int column, Object data) Sets default data for a newly inserted row.void
setNewRowData
(int column, Object data, ItemDataRole role) Sets default data for a newly inserted row.final void
setNewRowFlags
(int column, ItemFlag flag, ItemFlag... flags) Sets the item flags for items in a newly inserted row.void
setNewRowFlags
(int column, EnumSet<ItemFlag> flags) Sets the item flags for items in a newly inserted row.void
setSourceModel
(WAbstractItemModel model) Sets the source model.void
Sorts the model according to a particular column.Methods inherited from class eu.webtoolkit.jwt.WAbstractProxyModel
createSourceIndex, dropEvent, endShiftModelIndexes, fromRawIndex, getAcceptDropMimeTypes, getHeaderFlags, getMimeType, getSourceModel, setItemData, startShiftModelIndexes, toRawIndex
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, copyData, createIndex, createIndex, dataChanged, dropEvent, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, getIndex, getItemData, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, sort
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
-
Constructor Details
-
WBatchEditProxyModel
public WBatchEditProxyModel()Constructor.
-
-
Method Details
-
isDirty
public boolean isDirty()Returns whether changes have not yet been committed.Returns whether have been made to the proxy model, which could be committed using
commitAll()
or reverted usingrevertAll()
. -
commitAll
public void commitAll()Commits changes.This commits all changes to the source model.
- See Also:
-
revertAll
public void revertAll()Reverts changes.This reverts all changes.
- See Also:
-
setNewRowData
Sets default data for a newly inserted row.You can use this method to initialize data for a newly inserted row.
-
setNewRowData
Sets default data for a newly inserted row. -
setNewRowFlags
Sets the item flags for items in a newly inserted row.By default,
getFlags()
will returnItemFlag.Selectable
. -
setNewRowFlags
Sets the item flags for items in a newly inserted row. -
setDirtyIndication
Configures data used to indicate a modified item.This sets
data
for item data rolerole
to be returned by data() for an item that is dirty (e.g. because it belongs to a newly inserted row/column, or because new data has been set for it.When
role
isItemDataRole.StyleClass
, the style class is appended to any style already returned by the source model or set bysetNewRowData()
.By default there is no dirty indication.
-
mapFromSource
Description copied from class:WAbstractProxyModel
Maps a source model index to the proxy model.This method returns a model index in the proxy model that corresponds to the model index
sourceIndex
in the source model. This method must only be implemented for source model indexes that are mapped and thus are the result ofmapToSource()
.- Specified by:
mapFromSource
in classWAbstractProxyModel
- See Also:
-
mapToSource
Description copied from class:WAbstractProxyModel
Maps a proxy model index to the source model.This method returns a model index in the source model that corresponds to the proxy model index
proxyIndex
.- Specified by:
mapToSource
in classWAbstractProxyModel
- See Also:
-
setSourceModel
Sets the source model.The source model provides the actual data for the proxy model.
Ownership of the source model is not transferred.
All signals of the source model are propagated to the proxy model.
- Overrides:
setSourceModel
in classWAbstractProxyModel
-
getColumnCount
Description copied from class:WAbstractItemModel
Returns the number of columns.This returns the number of columns at index
parent
.- Specified by:
getColumnCount
in classWAbstractItemModel
- See Also:
-
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:
-
getParent
Description copied from class:WAbstractItemModel
Returns the parent for a model index.An implementation should use
createIndex()
to create a model index that corresponds to the parent of a given index.Note that the index itself may be stale (referencing a row/column within the parent that is outside the model geometry), but its parent (identified by the
WModelIndex.getInternalPointer()
) is referencing an existing parent. A stale index can only be used while the model geometry is being updated, i.e. during the emission of the corresponding [rows/columns](Being)[Removed/Inserted]() signals.- Specified by:
getParent
in classWAbstractItemModel
- See Also:
-
getIndex
Description copied from class:WAbstractItemModel
Returns the child index for the given row and column.When implementing this method, you can use
createIndex()
to create an index that corresponds to the item atrow
andcolumn
withinparent
.If the location is invalid (out of bounds at the parent), then an invalid index must be returned.
- Specified by:
getIndex
in classWAbstractItemModel
- See Also:
-
getData
Description copied from class:WAbstractProxyModel
Returns the data at a specific model index.The default proxy implementation translates the index to the source model, and calls
getSourceModel()
.data() with this index. -
setData
Sets item data.The default implementation will copy
ItemDataRole.Edit
data toItemDataRole.Display
. You may want to specialize the model to provide a more specialized editing behaviour.- Overrides:
setData
in classWAbstractProxyModel
- See Also:
-
getFlags
Description copied from class:WAbstractProxyModel
Returns the flags for an item.The default proxy implementation calls
getSourceModel()
.flags(mapToSource(index))- Overrides:
getFlags
in classWAbstractProxyModel
- See Also:
-
getHeaderData
Description copied from class:WAbstractProxyModel
Returns the row or column header data.The default proxy implementation constructs a dummy
WModelIndex
with the row set to 0 and column set tosection
if the orientation isOrientation.Horizontal
, or with the row set tosection
and the column set to 0 if the orientation isOrientation.Vertical
.The resulting section that is forwarded to
getSourceModel()
.getHeaderData()
depends on how theWModelIndex
is transformed withmapToSource()
. -
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:
-
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:
-
insertColumns
Description copied from class:WAbstractProxyModel
Inserts one or more columns.The default proxy implementation calls
getSourceModel()
.insertColumns(column, count, parent)- Overrides:
insertColumns
in classWAbstractProxyModel
- See Also:
-
removeColumns
Description copied from class:WAbstractProxyModel
Removes columns.The default proxy implementation calls
getSourceModel()
.removeColumns(column, count, parent)- Overrides:
removeColumns
in classWAbstractProxyModel
- See Also:
-
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:
-