CopperSpice API  1.9.1
QSortFilterProxyModel Class Reference

Provides support for sorting and filtering data passed between another model and a view. More...

Inheritance diagram for QSortFilterProxyModel:
QAbstractProxyModel QAbstractItemModel QObject

Public Slots

void invalidate ()
 
void setFilterFixedString (const QString &pattern)
 
void setFilterRegExp (const QString &pattern)
 
void setFilterWildcard (const QString &pattern)
 
- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 
virtual bool submit ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QSortFilterProxyModel (QObject *parent=nullptr)
 
 ~QSortFilterProxyModel ()
 
QModelIndex buddy (const QModelIndex &index) const override
 
bool canFetchMore (const QModelIndex &parent) const override
 
int columnCount (const QModelIndex &parent=QModelIndex ()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
bool dynamicSortFilter () const
 
void fetchMore (const QModelIndex &parent) override
 
Qt::CaseSensitivity filterCaseSensitivity () const
 
int filterKeyColumn () const
 
QRegularExpression filterRegExp () const
 
int filterRole () const
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool hasChildren (const QModelIndex &parent=QModelIndex ()) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex ()) const override
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex ()) override
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex ()) override
 
bool isSortLocaleAware () const
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const override
 
QItemSelection mapSelectionFromSource (const QItemSelection &sourceSelection) const override
 
QItemSelection mapSelectionToSource (const QItemSelection &proxySelection) const override
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const override
 
QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags (Qt::MatchStartsWith|Qt::MatchWrap)) const override
 
QMimeDatamimeData (const QModelIndexList &indexes) const override
 
QStringList mimeTypes () const override
 
QObjectparent () const
 
QModelIndex parent (const QModelIndex &child) const override
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex ()) override
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex ()) override
 
int rowCount (const QModelIndex &parent=QModelIndex ()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
void setDynamicSortFilter (bool enable)
 
void setFilterCaseSensitivity (Qt::CaseSensitivity cs)
 
void setFilterKeyColumn (int column)
 
void setFilterRegExp (const QRegularExpression &regExp)
 
void setFilterRole (int role)
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
 
void setSortCaseSensitivity (Qt::CaseSensitivity cs)
 
void setSortLocaleAware (bool on)
 
void setSortRole (int role)
 
void setSourceModel (QAbstractItemModel *sourceModel) override
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const override
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 
Qt::CaseSensitivity sortCaseSensitivity () const
 
int sortColumn () const
 
Qt::SortOrder sortOrder () const
 
int sortRole () const
 
QSize span (const QModelIndex &index) const override
 
Qt::DropActions supportedDropActions () const override
 
- Public Methods inherited from QAbstractProxyModel
 QAbstractProxyModel (QObject *parent=nullptr)
 
 ~QAbstractProxyModel () = default
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
QMap< int, QVariantitemData (const QModelIndex &proxyIndex) const override
 
void revert () override
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override
 
QAbstractItemModelsourceModel () const
 
bool submit () override
 
Qt::DropActions supportedDragActions () const override
 
- Public Methods inherited from QAbstractItemModel
 QAbstractItemModel (QObject *parent=nullptr)
 
virtual ~QAbstractItemModel ()
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex ()) const
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex ())
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex ())
 
bool moveColumn (const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool moveRow (const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
 
QObjectparent () const
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex ())
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex ())
 
virtual QMultiHash< int, QStringroleNames () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

virtual bool filterAcceptsColumn (int source_column, const QModelIndex &sourceParent) const
 
virtual bool filterAcceptsRow (int source_row, const QModelIndex &sourceParent) const
 
void invalidateFilter ()
 
virtual bool lessThan (const QModelIndex &left, const QModelIndex &right) const
 
- Protected Methods inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void beginResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndex createIndex (int row, int column, quintptr id) const
 
QModelIndex createIndex (int row, int column, void *data=nullptr) const
 
void endInsertColumns ()
 
void endInsertRows ()
 
void endMoveColumns ()
 
void endMoveRows ()
 
void endRemoveColumns ()
 
void endRemoveRows ()
 
void endResetModel ()
 
QModelIndexList persistentIndexList () const
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 dynamicSortFilter
 
 filterCaseSensitivity
 
 filterKeyColumn
 
 filterRegExp
 
 filterRole
 
 isSortLocaleAware
 
 sortCaseSensitivity
 
 sortRole
 
- Properties inherited from QAbstractProxyModel
 sourceModel
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Signals inherited from QAbstractProxyModel
void sourceModelChanged ()
 
- Public Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void layoutChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void modelAboutToBeReset ()
 
void modelReset ()
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QAbstractProxyModel
void resetInternalData ()
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 

Detailed Description

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

QSortFilterProxyModel can be used for sorting items, filtering out items, or both. The model transforms 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, and without duplicating the data in memory.

Assume we want to sort and filter the items provided by a custom model. The code to set up the model and the view, without sorting and filtering, would look like this:

QTreeView *treeView = new QTreeView;
MyItemModel *model = new MyItemModel(this);
treeView->setModel(model);

To add sorting and filtering support to MyItemModel, we need to create a QSortFilterProxyModel, call setSourceModel() with the MyItemModel as argument, and install the QSortFilterProxyModel on the view:

QTreeView *treeView = new QTreeView;
MyItemModel *sourceModel = new MyItemModel(this);
treeView->setModel(proxyModel);

At this point, neither sorting nor filtering is enabled; the original data is displayed in the view. Any changes made through the QSortFilterProxyModel are applied to the original model.

The QSortFilterProxyModel acts as a wrapper for the original model. If you need to convert source QModelIndexes to sorted/filtered model indexes or vice versa, use mapToSource(), mapFromSource(), mapSelectionToSource(), and mapSelectionFromSource().

Note
By default the model does not dynamically sort and filter data when the original model changes. This behavior can be changed by setting the dynamicSortFilter property.

Sorting

QTableView and QTreeView have a sortingEnabled property that controls whether the user can sort the view by clicking the view's horizontal header.

treeView->setSortingEnabled(true);

When this feature is on (the default is off), clicking on a header section sorts the items according to that column. By clicking repeatedly, the user can alternate between ascending and descending order.

Sorted QTreeView

The view calls the sort() method on the model to reorder data. You will need to either reimplement sort() in your model or use a QSortFilterProxyModel. The QSortFilterProxyModel class provides a generic sort() which uses the sortRole() of the items. It can handle several data types including int, QString, and QDateTime.

For hierarchical models, sorting is applied recursively to all child items. String comparisons are case sensitive by default. This can be changed by setting the sortCaseSensitivity property. Custom sorting behavior is achieved by subclassing QSortFilterProxyModel and reimplementing lessThan(), which is used to compare items.

bool MySortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QVariant leftData = sourceModel()->data(left);
QVariant rightData = sourceModel()->data(right);
if (leftData.type() == QVariant::DateTime) {
return leftData.toDateTime() < rightData.toDateTime();
} else {
QRegularExpression *emailPattern = new QRegularExpression("([\\w\\.]*@[\\w\\.]*)");
QString leftString = leftData.toString();
if(left.column() == 1 && emailPattern->indexIn(leftString) != -1) {
leftString = emailPattern->cap(1);
}
QString rightString = rightData.toString();
if(right.column() == 1 && emailPattern->indexIn(rightString) != -1) {
rightString = emailPattern->cap(1);
}
return QString::localeAwareCompare(leftString, rightString) < 0;
}
}

An alternative approach to sorting is to disable sorting on the view and to impose a certain order to the user. This is done by explicitly calling sort() with the desired column and order as arguments on the QSortFilterProxyModel (or on the original model if it implements sort()).

proxyModel->sort(2, Qt::AscendingOrder);

QSortFilterProxyModel can be sorted by column -1, in which case it returns to the sort order of the underlying source model.

Filtering

In addition to sorting, QSortFilterProxyModel can be used to hide items that do not match a certain filter. The filter is specified using a QRegularExpression object and is applied to the filterRole() (Qt::DisplayRole by default) of each item, for a given column. The QRegularExpression object can be used to match a regular expression or a wildcard pattern.

proxyModel->setFilterRegExp(QRegularExpression("\\.png$", QPatternOption::CaseInsensitiveOption));
proxyModel->setFilterKeyColumn(1);

For hierarchical models the filter is applied recursively to all children. If a parent item does not match the filter, none of its children will be shown.

A common use case is to let the user specify the filter regular expression or wildcard pattern in a QLineEdit and to connect the textChanged() signal to setFilterRegExp() or setFilterWildcard() to reapply the filter.

Custom filtering behavior can be achieved by reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions. For example, the following implementation ignores the filterKeyColumn property and performs filtering on columns 0, 1, and 2:

bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
return (sourceModel()->data(index0).toString().contains(filterRegExp())
|| sourceModel()->data(index1).toString().contains(filterRegExp()))
&& dateInRange(sourceModel()->data(index2).toDate());
}

If you are working with large amounts of filtering and have to invoke invalidateFilter() repeatedly, using reset() may be more efficient, depending on the implementation of your model. However, reset() returns the proxy model to its original state, losing selection information, and will cause the proxy model to be repopulated.

Subclassing

Many of the default implementations of methods in this class are written so that they call the equivalent methods in the source model. This simple proxying mechanism may need to be overridden for source models with more complex behavior. For example, if the source model provides a custom hasChildren() implementation, you should also provide one in the proxy model.

See also
QAbstractProxyModel, QAbstractItemModel, QIdentityProxyModel, Model/View Architecture, Custom Models

Constructor & Destructor Documentation

QSortFilterProxyModel::QSortFilterProxyModel ( QObject parent = nullptr)

Constructs a sorting filter model with the given parent.

QSortFilterProxyModel::~QSortFilterProxyModel ( )

Destroys this sorting filter model.

Method Documentation

QModelIndex QSortFilterProxyModel::buddy ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractProxyModel::buddy()

bool QSortFilterProxyModel::canFetchMore ( const QModelIndex parent) const
overridevirtual
int QSortFilterProxyModel::columnCount ( const QModelIndex parent = QModelIndex()) const
overridevirtual
QVariant QSortFilterProxyModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
overridevirtual
See also
setData()

Reimplemented from QAbstractProxyModel::data()

bool QSortFilterProxyModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
overridevirtual
bool QSortFilterProxyModel::dynamicSortFilter ( ) const

Returns the value of the property.

void QSortFilterProxyModel::fetchMore ( const QModelIndex parent)
overridevirtual
bool QSortFilterProxyModel::filterAcceptsColumn ( int  source_column,
const QModelIndex sourceParent 
) const
protectedvirtual

Returns true if the item in the column indicated by the given source_column and sourceParent should be included in the model, otherwise returns false. The default implementation returns true if the value held by the relevant item matches the filter string, wildcard string or regular expression.

By default the Qt::DisplayRole is used to determine if the row should be accepted or not. This can be changed by setting the filterRole property.

See also
filterAcceptsRow(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()
bool QSortFilterProxyModel::filterAcceptsRow ( int  source_row,
const QModelIndex sourceParent 
) const
protectedvirtual

Returns true if the item in the row indicated by the given source_row and sourceParent should be included in the model, otherwise returns false.

The default implementation returns true if the value held by the relevant item matches the filter string, wildcard string or regular expression.

By default the Qt::DisplayRole is used to determine if the row should be accepted or not. This can be changed by setting the filterRole property.

See also
filterAcceptsColumn(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()
Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity ( ) const

Returns the value of the property.

int QSortFilterProxyModel::filterKeyColumn ( ) const

Returns the value of the property.

QRegularExpression QSortFilterProxyModel::filterRegExp ( ) const

Returns the value of the property.

int QSortFilterProxyModel::filterRole ( ) const

Returns the value of the property.

Qt::ItemFlags QSortFilterProxyModel::flags ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractProxyModel::flags()

bool QSortFilterProxyModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
overridevirtual
QVariant QSortFilterProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
overridevirtual
QModelIndex QSortFilterProxyModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
overridevirtual
bool QSortFilterProxyModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual
bool QSortFilterProxyModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual
void QSortFilterProxyModel::invalidate ( )
slot

Invalidates the current sorting and filtering.

See also
invalidateFilter()
void QSortFilterProxyModel::invalidateFilter ( )
protected

Invalidates the current filtering. This method should be called if you are implementing custom filtering and your filter parameters have changed.

See also
invalidate()
bool QSortFilterProxyModel::isSortLocaleAware ( ) const

Returns the value of the property.

bool QSortFilterProxyModel::lessThan ( const QModelIndex left,
const QModelIndex right 
) const
protectedvirtual

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 method is used as the < operator when sorting, and handles the following QVariant types.

The indices passed to this method correspond to the source model.

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

Any other type will be converted to a QString using QVariant::toString(). Comparison of QStrings is case sensitive by default; this can be changed using the sortCaseSensitivity property. By default, the Qt::DisplayRole associated with the QModelIndexes is used for comparisons. This can be changed by setting the sortRole property.

See also
sortRole, sortCaseSensitivity, dynamicSortFilter
QModelIndex QSortFilterProxyModel::mapFromSource ( const QModelIndex sourceIndex) const
overridevirtual

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

See also
mapToSource()

Implements QAbstractProxyModel::mapFromSource()

QItemSelection QSortFilterProxyModel::mapSelectionFromSource ( const QItemSelection sourceSelection) const
overridevirtual
QItemSelection QSortFilterProxyModel::mapSelectionToSource ( const QItemSelection proxySelection) const
overridevirtual
QModelIndex QSortFilterProxyModel::mapToSource ( const QModelIndex proxyIndex) const
overridevirtual

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

See also
mapFromSource()

Implements QAbstractProxyModel::mapToSource()

QModelIndexList QSortFilterProxyModel::match ( const QModelIndex start,
int  role,
const QVariant value,
int  hits = 1,
Qt::MatchFlags  flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap) 
) const
overridevirtual

Reimplemented from QAbstractItemModel::match()

QMimeData * QSortFilterProxyModel::mimeData ( const QModelIndexList indexes) const
overridevirtual

Reimplemented from QAbstractProxyModel::mimeData()

QStringList QSortFilterProxyModel::mimeTypes ( ) const
overridevirtual
QObject * QObject::parent ( ) const
using

Returns a pointer to the parent object.

See also
setParent(), children()
QModelIndex QSortFilterProxyModel::parent ( const QModelIndex child) const
overridevirtual
bool QSortFilterProxyModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual
bool QSortFilterProxyModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual
int QSortFilterProxyModel::rowCount ( const QModelIndex parent = QModelIndex()) const
overridevirtual
bool QSortFilterProxyModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
overridevirtual
See also
data()

Reimplemented from QAbstractProxyModel::setData()

void QSortFilterProxyModel::setDynamicSortFilter ( bool  enable)

Sets the value of the property to enable.

void QSortFilterProxyModel::setFilterCaseSensitivity ( Qt::CaseSensitivity  cs)

Sets the value of the property to cs.

void QSortFilterProxyModel::setFilterFixedString ( const QString pattern)
slot

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

See also
setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard(), filterRegExp()
void QSortFilterProxyModel::setFilterKeyColumn ( int  column)

Sets the value of the property to column.

void QSortFilterProxyModel::setFilterRegExp ( const QRegularExpression regExp)

Sets the value of the property to regExp.

void QSortFilterProxyModel::setFilterRegExp ( const QString pattern)
slot

Sets the value of the property to pattern.

void QSortFilterProxyModel::setFilterRole ( int  role)

Sets the value of the property to role.

void QSortFilterProxyModel::setFilterWildcard ( const QString pattern)
slot

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

See also
setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString(), filterRegExp()
bool QSortFilterProxyModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant value,
int  role = Qt::EditRole 
)
overridevirtual
void QSortFilterProxyModel::setSortCaseSensitivity ( Qt::CaseSensitivity  cs)

Sets the value of the property to cs.

void QSortFilterProxyModel::setSortLocaleAware ( bool  on)

Sets the value of the property to on.

void QSortFilterProxyModel::setSortRole ( int  role)

Sets the value of the property to role.

void QSortFilterProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
overridevirtual
QModelIndex QSortFilterProxyModel::sibling ( int  row,
int  column,
const QModelIndex index 
) const
overridevirtual

Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. The sibling() is just a convenience method that finds the item's parent, and uses it to retrieve the index of the child item in the specified row and column.

See also
index(), QModelIndex::row(), QModelIndex::column()

Reimplemented from QAbstractProxyModel::sibling()

void QSortFilterProxyModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
overridevirtual

Reimplemented from QAbstractProxyModel::sort()

Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity ( ) const

Returns the value of the property.

int QSortFilterProxyModel::sortColumn ( ) const

Returns the most recently used sort column value.

Qt::SortOrder QSortFilterProxyModel::sortOrder ( ) const

Returns the most recently used sort order enum.

int QSortFilterProxyModel::sortRole ( ) const

Returns the value of the property.

QSize QSortFilterProxyModel::span ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractProxyModel::span()

Qt::DropActions QSortFilterProxyModel::supportedDropActions ( ) const
overridevirtual

Property Documentation

QSortFilterProxyModel::dynamicSortFilter

This property holds whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change.

Note that you should not update the source model through the proxy model when dynamicSortFilter is true. For instance, if you set the proxy model on a QComboBox, then using functions that update the model, e.g., addItem(), will not work as expected. An alternative is to set dynamicSortFilter to false and call sort() after adding items to the QComboBox.

The default value is false.

PropertiesClass Methods
read dynamicSortFilter
write setDynamicSortFilter
QSortFilterProxyModel::filterCaseSensitivity

This property holds the case sensitivity of the QRegularExpression pattern used to filter the contents of the source model. By default the filter is case sensitive.

See also
filterRegExp, sortCaseSensitivity
PropertiesClass Methods
read filterCaseSensitivity
write setFilterCaseSensitivity
QSortFilterProxyModel::filterKeyColumn

This property holds the column where the key used to filter the contents of the source model is read from. The default value is 0. If the value is -1, the keys will be read from all columns.

PropertiesClass Methods
read filterKeyColumn
write setFilterKeyColumn
QSortFilterProxyModel::filterRegExp

This property holds the QRegularExpression used to filter the contents of the source model. Setting this property overwrites the current filterCaseSensitivity. By default the QRegularExpression is an empty string matching all contents. If no QRegularExpression or an empty string is set, everything in the source model will be accepted.

See also
filterCaseSensitivity, setFilterWildcard(), setFilterFixedString()
PropertiesClass Methods
read filterRegExp
write setFilterRegExp
QSortFilterProxyModel::filterRole

This property holds the item role that is used to query the source model's data when filtering items. The default value is Qt::DisplayRole.

See also
filterAcceptsRow()
PropertiesClass Methods
read filterRole
write setFilterRole
QSortFilterProxyModel::isSortLocaleAware

This property holds the local aware setting used for comparing strings when sorting.

By default, sorting is not local aware.

See also
sortCaseSensitivity, lessThan()
PropertiesClass Methods
read isSortLocaleAware
write setSortLocaleAware
QSortFilterProxyModel::sortCaseSensitivity

This property holds the case sensitivity setting used for comparing strings when sorting.

By default, sorting is case sensitive.

See also
filterCaseSensitivity, lessThan()
PropertiesClass Methods
read sortCaseSensitivity
write setSortCaseSensitivity
QSortFilterProxyModel::sortRole

This property holds the item role that is used to query the source model's data when sorting items.

The default value is Qt::DisplayRole.

See also
lessThan()
PropertiesClass Methods
read sortRole
write setSortRole