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
Nested ClassesModifier and TypeClassDescriptionprotected static classA base class for an item modeling a source index parent.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected WModelIndexcreateSourceIndex(int row, int column, Object ptr) Create a source model index.voiddropEvent(WDropEvent e, DropAction action, int row, int column, WModelIndex parent) Handles a drop event.voiddropEvent(WDropEvent e, DropAction action, WModelIndex index, Side side) Handles a drop event.protected voidendShiftModelIndexes(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.booleaninsertColumns(int column, int count, WModelIndex parent) Inserts one or more columns.abstract WModelIndexmapFromSource(WModelIndex sourceIndex) Maps a source model index to the proxy model.abstract WModelIndexmapToSource(WModelIndex proxyIndex) Maps a proxy model index to the source model.booleanremoveColumns(int column, int count, WModelIndex parent) Removes columns.booleansetData(WModelIndex index, Object value, ItemDataRole role) Sets the data at the given model index.booleansetItemData(WModelIndex index, SortedMap<ItemDataRole, Object> values) Sets the data at the given model index.voidsetSourceModel(WAbstractItemModel sourceModel) Sets the source model.protected voidstartShiftModelIndexes(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, 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, sortMethods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, resendFormData, 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
sourceIndexin 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
WBatchEditProxyModelandWSortFilterProxyModeldo. If you want to reimplement data() with no changes to row or column indices, consider the use ofWIdentityProxyModel. -
getSourceModel
Returns the source model.- See Also:
-
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.- Specified by:
getDatain classWAbstractItemModel- See Also:
-
getHeaderData
Returns the row or column header data.The default proxy implementation constructs a dummy
WModelIndexwith the row set to 0 and column set tosectionif the orientation isOrientation.Horizontal, or with the row set tosectionand the column set to 0 if the orientation isOrientation.Vertical.The resulting section that is forwarded to
getSourceModel().getHeaderData()depends on how theWModelIndexis transformed withmapToSource().- Overrides:
getHeaderDatain classWAbstractItemModel- See Also:
-
setData
Sets the data at the given model index.The default proxy implementation calls
getSourceModel().setData(mapToSource(index), value, role)- Overrides:
setDatain classWAbstractItemModel- See Also:
-
setItemData
Sets the data at the given model index.The default proxy implementation calls
getSourceModel().setData(mapToSource(index), values)- Overrides:
setItemDatain classWAbstractItemModel- See Also:
-
getFlags
Returns the flags for an item.The default proxy implementation calls
getSourceModel().flags(mapToSource(index))- Overrides:
getFlagsin classWAbstractItemModel- See Also:
-
getHeaderFlags
Returns the flags for a header.The default proxy implementation constructs a dummy
WModelIndexwith the row set to 0 and column set tosectionif the orientation isOrientation.Horizontal, or with the row set tosectionand the column set to 0 if the orientation isOrientation.Vertical.The resulting section that is forwarded to
getSourceModel().getHeaderFlags()depends on how theWModelIndexis transformed withmapToSource().- Overrides:
getHeaderFlagsin classWAbstractItemModel- See Also:
-
insertColumns
Inserts one or more columns.The default proxy implementation calls
getSourceModel().insertColumns(column, count, parent)- Overrides:
insertColumnsin classWAbstractItemModel- See Also:
-
removeColumns
Removes columns.The default proxy implementation calls
getSourceModel().removeColumns(column, count, parent)- Overrides:
removeColumnsin classWAbstractItemModel- See Also:
-
getMimeType
Returns a mime-type for dragging a set of indexes.The default proxy implementation calls
getSourceModel().getMimeType()- Overrides:
getMimeTypein 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:
getAcceptDropMimeTypesin 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:
dropEventin classWAbstractItemModel- See Also:
-
dropEvent
Handles a drop event.The default proxy implementation maps the given index to the source model, and forwards the dropEvent call to the source model.
- Overrides:
dropEventin 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))- Overrides:
toRawIndexin classWAbstractItemModel- See Also:
-
fromRawIndex
Converts a raw pointer to a model index.The default proxy implementation calls mapFromSource(
getSourceModel().fromRawIndex(rawIndex))- Overrides:
fromRawIndexin 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)
-