Class WAbstractProxyModel
- Direct Known Subclasses:
WAggregateProxyModel
,WBatchEditProxyModel
,WIdentityProxyModel
,WReadOnlyProxyModel
,WSortFilterProxyModel
A proxy model does not store data, but presents data from a source model in another way. It may provide filtering, sorting, or other computed changes to the source model. A proxy model may be a fully functional model, that also allows modification of the underlying model.
This abstract proxy model may be used as a starting point for implementing a custom proxy
model, when WSortFilterProxyModel
is not adequate. It implements data access and
manipulation using the a virtual mapping method (mapToSource()
) to access and manipulate
the underlying getSourceModel()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A base class for an item modeling a source index parent.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected WModelIndex
createSourceIndex
(int row, int column, Object ptr) Create a source model index.void
dropEvent
(WDropEvent e, DropAction action, int row, int column, WModelIndex parent) Handles a drop event.protected void
endShiftModelIndexes
(WModelIndex sourceParent, int start, int count, SortedMap<WModelIndex, WAbstractProxyModel.BaseItem> items) fromRawIndex
(Object rawIndex) Converts a raw pointer to a model index.Returns a list of mime-types that could be accepted for a drop event.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.getHeaderFlags
(int section, Orientation orientation) Returns the flags for a header.Returns a mime-type for dragging a set of indexes.Returns the source model.boolean
insertColumns
(int column, int count, WModelIndex parent) Inserts one or more columns.abstract WModelIndex
mapFromSource
(WModelIndex sourceIndex) Maps a source model index to the proxy model.abstract WModelIndex
mapToSource
(WModelIndex proxyIndex) Maps a proxy model index to the source model.boolean
removeColumns
(int column, int count, WModelIndex parent) Removes columns.boolean
setData
(WModelIndex index, Object value, ItemDataRole role) Sets the data at the given model index.boolean
setItemData
(WModelIndex index, SortedMap<ItemDataRole, Object> values) Sets the data at the given model index.void
setSourceModel
(WAbstractItemModel sourceModel) Sets the source model.protected void
startShiftModelIndexes
(WModelIndex sourceParent, int start, int count, SortedMap<WModelIndex, WAbstractProxyModel.BaseItem> items) Utility methods to shift items in an item map.toRawIndex
(WModelIndex index) Converts a model index to a raw pointer that remains valid while the model's layout is changed.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, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, getIndex, getIndex, getItemData, getParent, getRowCount, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, sort, sort
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
-
Constructor Details
-
WAbstractProxyModel
public WAbstractProxyModel()Constructor.
-
-
Method Details
-
mapFromSource
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()
.- See Also:
-
mapToSource
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
.- 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.
Note that the source model's signals are not forwarded to the proxy model by default, but some specializations, like
WBatchEditProxyModel
andWSortFilterProxyModel
do. If you want to reimplement data() with no changes to row or column indices, consider the use ofWIdentityProxyModel
. -
getSourceModel
Returns the source model. -
getData
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. -
getHeaderData
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()
. -
setData
Sets the data at the given model index.The default proxy implementation calls
getSourceModel()
.setData(mapToSource(index), value, role)- Overrides:
setData
in classWAbstractItemModel
- See Also:
-
setItemData
Sets the data at the given model index.The default proxy implementation calls
getSourceModel()
.setData(mapToSource(index), values)- Overrides:
setItemData
in classWAbstractItemModel
- See Also:
-
getFlags
Returns the flags for an item.The default proxy implementation calls
getSourceModel()
.flags(mapToSource(index))- Overrides:
getFlags
in classWAbstractItemModel
- See Also:
-
getHeaderFlags
Returns the flags for a header.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()
.getHeaderFlags()
depends on how theWModelIndex
is transformed withmapToSource()
.- Overrides:
getHeaderFlags
in classWAbstractItemModel
- See Also:
-
insertColumns
Inserts one or more columns.The default proxy implementation calls
getSourceModel()
.insertColumns(column, count, parent)- Overrides:
insertColumns
in classWAbstractItemModel
- See Also:
-
removeColumns
Removes columns.The default proxy implementation calls
getSourceModel()
.removeColumns(column, count, parent)- Overrides:
removeColumns
in classWAbstractItemModel
- See Also:
-
getMimeType
Returns a mime-type for dragging a set of indexes.The default proxy implementation calls
getSourceModel()
.getMimeType()
- Overrides:
getMimeType
in classWAbstractItemModel
- See Also:
-
getAcceptDropMimeTypes
Returns a list of mime-types that could be accepted for a drop event.The default proxy implementation calls
getSourceModel()
.getAcceptDropMimeTypes()
- Overrides:
getAcceptDropMimeTypes
in classWAbstractItemModel
- See Also:
-
dropEvent
Handles a drop event.The default proxy implementation maps the given row and parent to the row and parent in the source model, and forwards the dropEvent call to the source model.
- Overrides:
dropEvent
in classWAbstractItemModel
- See Also:
-
toRawIndex
Converts a model index to a raw pointer that remains valid while the model's layout is changed.The default proxy implementation calls
getSourceModel()
.toRawIndex(mapToSource(index)) -
fromRawIndex
Converts a raw pointer to a model index.The default proxy implementation calls mapFromSource(
getSourceModel()
.fromRawIndex(rawIndex))- Overrides:
fromRawIndex
in classWAbstractItemModel
- See Also:
-
createSourceIndex
Create a source model index.This is a utility function that allows you to create indexes in the source model. In this way, you can reuse the internal pointers of the source model in proxy model indexes, and convert a proxy model index back to the source model index using this method.
-
startShiftModelIndexes
protected void startShiftModelIndexes(WModelIndex sourceParent, int start, int count, SortedMap<WModelIndex, WAbstractProxyModel.BaseItem> items) Utility methods to shift items in an item map.You can use this method to adjust an item map after the source model has inserted or removed rows. When removing rows (count < 0), items may possibly be removed and deleted.
-
endShiftModelIndexes
protected void endShiftModelIndexes(WModelIndex sourceParent, int start, int count, SortedMap<WModelIndex, WAbstractProxyModel.BaseItem> items)
-