Class WSortFilterProxyModel

public class WSortFilterProxyModel extends WAbstractProxyModel
A proxy model for JWt's item models that provides filtering and/or sorting.

This proxy model does not store data itself, but presents data from a source model, after filtering rows. It also allows sorting of the source model data, without actually altering the source model. This may be convenient when the source model does not support sorting (i.e. does not reimplement WAbstractItemModel#sort()), or you do not want to reorder the underlying model since that affects all views on the model.

To use the proxy model to filter data, you use the methods setFilterKeyColumn(), setFilterRegExp() and setFilterRole() to specify a filtering operation based on the values of a single column. If this filtering mechanism is too limiting, you can provide specialized filtering by reimplementing the filterAcceptRow() method.

Sorting is provided by reimplementing the standard WAbstractItemModel#sort() method. In this way, a view class such as WTreeView may resort the model as indicated by the user. Use setSortRole() to indicate on what data role sorting should be done, or reimplement the lessThan() method to provide a specialized sorting method.

By default, the proxy does not automatically refilter and resort when the original model changes. Data changes or row additions to the source model are not automatically reflected in the proxy model, but to maintain integrity, row removals in the source model are always reflected in the proxy model. You can enable the model to always refilter and resort when the underlying model changes using setDynamicSortFilter().

Usage example:

 // model is the source model
 WAbstractItemModel model = ...

 // we setup a proxy to filter the source model
 WSortFilterProxyModel proxy = new WSortFilterProxyModel(this);

 // configure a view to use the proxy model instead of the source model
 WTreeView view = new WTreeView(this);