eu.webtoolkit.jwt
Class WAbstractProxyModel

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WAbstractItemModel
          extended by eu.webtoolkit.jwt.WAbstractProxyModel
Direct Known Subclasses:
WAggregateProxyModel, WBatchEditProxyModel, WReadOnlyProxyModel, WSortFilterProxyModel

public abstract class WAbstractProxyModel
extends WAbstractItemModel

An abstract proxy model for Wt's item models.

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
protected static class WAbstractProxyModel.BaseItem
          A base class for an item modeling a source index parent.
 
Constructor Summary
WAbstractProxyModel()
          Constructor.
WAbstractProxyModel(WObject parent)
          Constructor.
 
Method Summary
protected  WModelIndex createSourceIndex(int row, int column, java.lang.Object ptr)
          Create a source model index.
 void dropEvent(WDropEvent e, DropAction action, int row, int column, WModelIndex parent)
          Handles a drop event.
 WModelIndex fromRawIndex(java.lang.Object rawIndex)
          Converts a raw pointer to a model index.
 java.util.List<java.lang.String> getAcceptDropMimeTypes()
          Returns a list of mime-types that could be accepted for a drop event.
 java.lang.Object getData(WModelIndex index, int role)
          Returns data at a specific model index.
 java.util.EnumSet<ItemFlag> getFlags(WModelIndex index)
          Returns the flags for an item.
 java.lang.String getMimeType()
          Returns a mime-type for dragging a set of indexes.
 WAbstractItemModel getSourceModel()
          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, java.lang.Object value, int role)
          Sets data at the given model index.
 void setSourceModel(WAbstractItemModel sourceModel)
          Sets the source model.
protected  void shiftModelIndexes(WModelIndex sourceParent, int start, int count, java.util.SortedMap<WModelIndex,WAbstractProxyModel.BaseItem> items)
          Utility methods to shift items in an item map.
 java.lang.Object 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, createIndex, dataChanged, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, getColumnCount, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderData, getHeaderFlags, 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, setItemData, sort, sort
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WAbstractProxyModel

public WAbstractProxyModel(WObject parent)
Constructor.


WAbstractProxyModel

public WAbstractProxyModel()
Constructor.

Calls this((WObject)null)

Method Detail

mapFromSource

public abstract WModelIndex mapFromSource(WModelIndex sourceIndex)
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 of mapToSource().

See Also:
mapToSource(WModelIndex proxyIndex)

mapToSource

public abstract WModelIndex mapToSource(WModelIndex proxyIndex)
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:
mapFromSource(WModelIndex sourceIndex)

setSourceModel

public void setSourceModel(WAbstractItemModel sourceModel)
Sets the source model.

The source model provides the actual data for the proxy model.

Ownership of the source model is not transferred.


getSourceModel

public WAbstractItemModel getSourceModel()
Returns the source model.

See Also:
setSourceModel(WAbstractItemModel sourceModel)

getData

public java.lang.Object getData(WModelIndex index,
                                int role)
Description copied from class: WAbstractItemModel
Returns data at a specific model index.

Return data for a given role at a given index.

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

Specified by:
getData in class WAbstractItemModel
See Also:
WAbstractItemModel.getFlags(WModelIndex index), WAbstractItemModel.getHeaderData(int section, Orientation orientation, int role), WAbstractItemModel.setData(WModelIndex index, Object value, int role)

setData

public boolean setData(WModelIndex index,
                       java.lang.Object value,
                       int role)
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 class WAbstractItemModel
See Also:
WAbstractItemModel.getData(WModelIndex index, int role)

getFlags

public java.util.EnumSet<ItemFlag> getFlags(WModelIndex index)
Description copied from class: WAbstractItemModel
Returns the flags for an item.

The default implementation returns ItemIsSelectable.

Overrides:
getFlags in class WAbstractItemModel
See Also:
ItemFlag

insertColumns

public boolean insertColumns(int column,
                             int count,
                             WModelIndex parent)
Description copied from class: WAbstractItemModel
Inserts one or more columns.

In models that support column insertion, this inserts count columns, starting at column, and returns true if the operation was successful. The new columns are inserted under parent.

The default implementation returns false.

The model implementation must call beginInsertColumns() and endInsertColumns() before and after the operation whenever its geometry is changed by inserting columns. This emits signals for views to properly react to these changes.

Overrides:
insertColumns in class WAbstractItemModel
See Also:
WAbstractItemModel.insertRows(int row, int count, WModelIndex parent), WAbstractItemModel.removeColumns(int column, int count, WModelIndex parent), WAbstractItemModel.beginInsertColumns(WModelIndex parent, int first, int last), WAbstractItemModel.endInsertColumns()

removeColumns

public boolean removeColumns(int column,
                             int count,
                             WModelIndex parent)
Description copied from class: WAbstractItemModel
Removes columns.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must call beginRemoveColumns() and endRemoveColumns() before and after the operation whenever its geometry is changed by removing columns. This emits signals for views to properly react to these changes.

Overrides:
removeColumns in class WAbstractItemModel
See Also:
WAbstractItemModel.removeRows(int row, int count, WModelIndex parent), WAbstractItemModel.insertColumns(int column, int count, WModelIndex parent), WAbstractItemModel.beginRemoveColumns(WModelIndex parent, int first, int last), WAbstractItemModel.endRemoveColumns()

getMimeType

public java.lang.String getMimeType()
Description copied from class: WAbstractItemModel
Returns a mime-type for dragging a set of indexes.

This method returns a mime-type that describes dragging of a selection of items.

The drop event will indicate a selection model for this abstract item model as source.

The default implementation returns a mime-type for generic drag&drop support between abstract item models.

Overrides:
getMimeType in class WAbstractItemModel
See Also:
WAbstractItemModel.getAcceptDropMimeTypes()

getAcceptDropMimeTypes

public java.util.List<java.lang.String> getAcceptDropMimeTypes()
Description copied from class: WAbstractItemModel
Returns a list of mime-types that could be accepted for a drop event.

The default implementation only accepts drag&drop support between abstract item models.

Overrides:
getAcceptDropMimeTypes in class WAbstractItemModel
See Also:
WAbstractItemModel.getMimeType()

dropEvent

public void dropEvent(WDropEvent e,
                      DropAction action,
                      int row,
                      int column,
                      WModelIndex parent)
Description copied from class: WAbstractItemModel
Handles a drop event.

The default implementation only handles generic drag&drop between abstract item models. Source item data is copied (but not the source item's flags).

The location in the model is indicated by the row and column within the parent index. If row is -1, then the item is appended to the parent. Otherwise, the item is inserted at or copied over the indicated item (and subsequent rows). When action is a MoveAction, the original items are deleted from the source model.

You may want to reimplement this method if you want to handle other mime-type data, or if you want to refine how the drop event of an item selection must be interpreted.

Note: Currently, only row selections are handled by the default implementation.

Overrides:
dropEvent in class WAbstractItemModel
See Also:
WAbstractItemModel.getMimeType(), WItemSelectionModel

toRawIndex

public java.lang.Object toRawIndex(WModelIndex index)
Description copied from class: WAbstractItemModel
Converts a model index to a raw pointer that remains valid while the model's layout is changed.

Use this method to temporarily save model indexes while the model's layout is changed by for example a sorting operation.

The default implementation returns null, which indicates that the index cannot be converted to a raw pointer. If you reimplement this method, you also need to reimplemnt fromRawIndex().

Overrides:
toRawIndex in class WAbstractItemModel
See Also:
WAbstractItemModel.layoutAboutToBeChanged(), WAbstractItemModel.sort(int column, SortOrder order), WAbstractItemModel.fromRawIndex(Object rawIndex)

fromRawIndex

public WModelIndex fromRawIndex(java.lang.Object rawIndex)
Description copied from class: WAbstractItemModel
Converts a raw pointer to a model index.

Use this method to create model index from temporary raw pointers. It is the reciproce method of toRawIndex().

You can return an invalid modelindex if the rawIndex no longer points to a valid item because of the layout change.

Overrides:
fromRawIndex in class WAbstractItemModel
See Also:
WAbstractItemModel.toRawIndex(WModelIndex index)

createSourceIndex

protected WModelIndex createSourceIndex(int row,
                                        int column,
                                        java.lang.Object ptr)
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.


shiftModelIndexes

protected void shiftModelIndexes(WModelIndex sourceParent,
                                 int start,
                                 int count,
                                 java.util.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.