|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QSortFilterProxyModel Class Reference
[QtGui module]

The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view. More...

    #include <QSortFilterProxyModel>

Inherits QAbstractProxyModel.

This class was introduced in Qt 4.1.

- List of all members, including inherited members

### Properties

- filterCaseSensitivity : Qt::CaseSensitivity
- filterKeyColumn : int
- filterRegExp : QRegExp

- 1 property inherited from QObject

### Public Functions

- QSortFilterProxyModel ( QObject * parent = 0 )
- ~QSortFilterProxyModel ()
- Qt::CaseSensitivity filterCaseSensitivity () const
- int filterKeyColumn () const
- QRegExp filterRegExp () const
- virtual QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const
- virtual QModelIndex mapToSource ( const QModelIndex & proxyIndex ) const
- void setFilterCaseSensitivity ( Qt::CaseSensitivity cs )
- void setFilterKeyColumn ( int column )
- void setFilterRegExp ( const QRegExp & regExp )

- 6 public functions inherited from QAbstractProxyModel
- 32 public functions inherited from QAbstractItemModel
- 28 public functions inherited from QObject

### Public Slots

- void clear ()
- void setFilterFixedString ( const QString & pattern )
- void setFilterRegExp ( const QString & pattern )
- void setFilterWildcard ( const QString & pattern )

- 2 public slots inherited from QAbstractItemModel
- 1 public slot inherited from QObject

### Protected Functions

- virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const
- virtual bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
- virtual bool lessThan ( const QModelIndex & left, const QModelIndex & right ) const

- 13 protected functions inherited from QAbstractItemModel
- 7 protected functions inherited from QObject

### Additional Inherited Members

- 12 signals inherited from QAbstractItemModel
- 1 signal inherited from QObject
- 4 static public members inherited from QObject

## Detailed Description

The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view.

The sorting filter model transform the structure of a source model by mapping the model indexes it supplies to new indexes, corresponding to different locations, for views to use. This approach allows a given source model to be restructured as far as views are concerned without requiring any transformations on the underlying data.

The default implementation of the filter and sorting functions use the data for the items Qt::DisplayRole compare or accept items.

The default implementation of the lessThan() function used when sorting, can handle the following data types:

- QVariant::Int
- QVariant::UInt
- QVariant::LongLong
- QVariant::ULongLong
- QVariant::Double
- QVariant::Char
- QVariant::Date
- QVariant::Time
- QVariant::DateTime
- QVariant::String

See also QAbstractProxyModel, QAbstractItemModel, and Model/View Programming.

## Property Documentation

### filterCaseSensitivity : Qt::CaseSensitivity

Access functions:

- Qt::CaseSensitivity filterCaseSensitivity () const
- void setFilterCaseSensitivity ( Qt::CaseSensitivity cs )

### filterKeyColumn : int

This property holds the column where the key used to filter the contents of the source model is read from.

Access functions:

- int filterKeyColumn () const
- void setFilterKeyColumn ( int column )

### filterRegExp : QRegExp

This property holds the QRegExp used to filter the contents of the source model.

Setting this property overwrites the current caseSensitivity.

Access functions:

- QRegExp filterRegExp () const
- void setFilterRegExp ( const QRegExp & regExp )
- void setFilterRegExp ( const QString & pattern )

See also setCaseSensitivity(), setFilterWildcard(), and setFilterFixedString().

## Member Function Documentation

### QSortFilterProxyModel::QSortFilterProxyModel ( QObject * parent = 0 )

Constructs a sorting filter model with the given parent.

### QSortFilterProxyModel::~QSortFilterProxyModel ()

Destroys the sorting filter model.

### void QSortFilterProxyModel::clear () `[slot]`

Clears the sorting filter model, removing all mapping.

### bool QSortFilterProxyModel::filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const `[virtual protected]`

Returns true if the value in the item in the column indicated by the given source_column and source_parent should be included in the model. The default implementation returns true.

### bool QSortFilterProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const `[virtual protected]`

Returns true if the value in the item in the row indicated by the given source_row and source_parent should be included in the model. The default implementation uses filterRegExp with the data returned for the Qt::DisplayRole to determine if the row should be accepted or not.

### bool QSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const `[virtual protected]`

Returns true if the value of the item referred to by the given index left is less than the value of the item referred to by the given index right, otherwise returns false. This function is used as the < operator when sorting, and handles several QVariant types:

- QVariant::Int
- QVariant::UInt
- QVariant::LongLong
- QVariant::ULongLong
- QVariant::Double
- QVariant::Char
- QVariant::Date
- QVariant::Time
- QVariant::DateTime
- QVariant::String

### QModelIndex QSortFilterProxyModel::mapFromSource ( const QModelIndex & sourceIndex ) const `[virtual]`

Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model.

Reimplemented from QAbstractProxyModel.

### QModelIndex QSortFilterProxyModel::mapToSource ( const QModelIndex & proxyIndex ) const `[virtual]`

Returns the source model index corresponding to the given proxyIndex from the sorting filter model.

Reimplemented from QAbstractProxyModel.

### void QSortFilterProxyModel::setFilterFixedString ( const QString & pattern ) `[slot]`

Sets the fixed string used to filter the contents of the source model to pattern.

See also setFilterCaseSensitivity(), setFilterRegExp(), and setFilterWildcard().

### void QSortFilterProxyModel::setFilterWildcard ( const QString & pattern ) `[slot]`

Sets the wildcard expression used to filter the contents of the source model to pattern.

See also setFilterCaseSensitivity(), setFilterRegExp(), and setFilterFixedString().