CopperSpice API  1.7.2
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 &objName=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 &source_parent) const
 
virtual bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) 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)
 
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 re-sort and re-filter data whenever 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. For example:

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.

Behind the scene, the view calls the sort() virtual function on the model to reorder the data in the model. To make your data sortable, you can either implement sort() in your model, or use a QSortFilterProxyModel to wrap your model – QSortFilterProxyModel provides a generic sort() reimplementation that operates on the sortRole() (Qt::DisplayRole by default) of the items and that understands 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()). For example:

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

Since QAbstractProxyModel and its subclasses are derived from QAbstractItemModel, much of the same advice about subclassing normal models also applies to proxy models. In addition, it is worth noting that many of the default implementations of functions in this class are written so that they call the equivalent functions in the relevant 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.

Note
Some general guidelines for subclassing models are available in the Model Subclassing Reference.
See also
QAbstractProxyModel, QAbstractItemModel, Model/View Programming, QIdentityProxyModel

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 QAbstractItemModel::buddy().

Reimplemented from QAbstractProxyModel.

bool QSortFilterProxyModel::canFetchMore ( const QModelIndex parent) const
overridevirtual

Reimplemented from QAbstractItemModel::canFetchMore().

Reimplemented from QAbstractProxyModel.

int QSortFilterProxyModel::columnCount ( const QModelIndex parent = QModelIndex()) const
overridevirtual

Reimplemented from QAbstractItemModel::columnCount().

Implements QAbstractItemModel.

QVariant QSortFilterProxyModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
overridevirtual

Reimplemented from QAbstractItemModel::data().

See also
setData()

Reimplemented from QAbstractProxyModel.

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

Reimplemented from QAbstractItemModel::dropMimeData().

Reimplemented from QAbstractProxyModel.

bool QSortFilterProxyModel::dynamicSortFilter ( ) const

Property documentation pending.

void QSortFilterProxyModel::fetchMore ( const QModelIndex parent)
overridevirtual

Reimplemented from QAbstractItemModel::fetchMore().

Reimplemented from QAbstractProxyModel.

bool QSortFilterProxyModel::filterAcceptsColumn ( int  source_column,
const QModelIndex source_parent 
) const
protectedvirtual

Returns true if the item in the column indicated by the given source_column and source_parent 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.

Note
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 source_parent 
) const
protectedvirtual

Returns true if the item in the row indicated by the given source_row and source_parent 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.

Note
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

Property documentation pending.

int QSortFilterProxyModel::filterKeyColumn ( ) const

Property documentation pending.

QRegularExpression QSortFilterProxyModel::filterRegExp ( ) const

Property documentation pending.

int QSortFilterProxyModel::filterRole ( ) const

Property documentation pending.

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

Reimplemented from QAbstractItemModel::flags().

Reimplemented from QAbstractProxyModel.

bool QSortFilterProxyModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
overridevirtual

Reimplemented from QAbstractItemModel::hasChildren().

Reimplemented from QAbstractProxyModel.

QVariant QSortFilterProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
overridevirtual

Reimplemented from QAbstractItemModel::headerData().

See also
setHeaderData()

Reimplemented from QAbstractProxyModel.

QModelIndex QSortFilterProxyModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
overridevirtual

Reimplemented from QAbstractItemModel::index().

Implements QAbstractItemModel.

bool QSortFilterProxyModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual

Reimplemented from QAbstractItemModel::insertColumns().

Reimplemented from QAbstractItemModel.

bool QSortFilterProxyModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual

Reimplemented from QAbstractItemModel::insertRows().

Reimplemented from QAbstractItemModel.

void QSortFilterProxyModel::invalidate ( )
slot

Invalidates the current sorting and filtering.

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

Invalidates the current filtering.

This function should be called if you are implementing custom filtering (e.g. filterAcceptsRow()), and your filter parameters have changed.

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

Property documentation pending.

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

  • 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.

Note
The indices passed in correspond to the source model.
See also
sortRole, sortCaseSensitivity, dynamicSortFilter
QModelIndex QSortFilterProxyModel::mapFromSource ( const QModelIndex sourceIndex) const
overridevirtual

Reimplemented from QAbstractProxyModel::mapFromSource().

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

See also
mapToSource()

Implements QAbstractProxyModel.

QItemSelection QSortFilterProxyModel::mapSelectionFromSource ( const QItemSelection sourceSelection) const
overridevirtual

Reimplemented from QAbstractProxyModel::mapSelectionFromSource().

Reimplemented from QAbstractProxyModel.

QItemSelection QSortFilterProxyModel::mapSelectionToSource ( const QItemSelection proxySelection) const
overridevirtual

Reimplemented from QAbstractProxyModel::mapSelectionToSource().

Reimplemented from QAbstractProxyModel.

QModelIndex QSortFilterProxyModel::mapToSource ( const QModelIndex proxyIndex) const
overridevirtual

Reimplemented from QAbstractProxyModel::mapToSource().

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

See also
mapFromSource()

Implements QAbstractProxyModel.

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

Reimplemented from QAbstractItemModel.

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

Reimplemented from QAbstractItemModel::mimeData().

Reimplemented from QAbstractProxyModel.

QStringList QSortFilterProxyModel::mimeTypes ( ) const
overridevirtual

Reimplemented from QAbstractItemModel::mimeTypes().

Reimplemented from QAbstractProxyModel.

QObject * QObject::parent ( ) const
using

Returns a pointer to the parent object.

See also
setParent(), children()
QModelIndex QSortFilterProxyModel::parent ( const QModelIndex child) const
overridevirtual

Reimplemented from QAbstractItemModel::parent().

Implements QAbstractItemModel.

bool QSortFilterProxyModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual

Reimplemented from QAbstractItemModel::removeColumns().

Reimplemented from QAbstractItemModel.

bool QSortFilterProxyModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
overridevirtual

Reimplemented from QAbstractItemModel::removeRows().

Reimplemented from QAbstractItemModel.

int QSortFilterProxyModel::rowCount ( const QModelIndex parent = QModelIndex()) const
overridevirtual

Reimplemented from QAbstractItemModel::rowCount().

Implements QAbstractItemModel.

bool QSortFilterProxyModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
overridevirtual

Reimplemented from QAbstractItemModel::setData().

See also
data()

Reimplemented from QAbstractProxyModel.

void QSortFilterProxyModel::setDynamicSortFilter ( bool  enable)

Property documentation pending.

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

Property documentation pending.

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)

Property documentation pending.

void QSortFilterProxyModel::setFilterRegExp ( const QRegularExpression regExp)

Property documentation pending.

void QSortFilterProxyModel::setFilterRegExp ( const QString pattern)
slot

Property documentation pending.

void QSortFilterProxyModel::setFilterRole ( int  role)

Property documentation pending.

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

Reimplemented from QAbstractItemModel::setHeaderData().

See also
headerData()

Reimplemented from QAbstractProxyModel.

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

Property documentation pending.

void QSortFilterProxyModel::setSortLocaleAware ( bool  on)

Property documentation pending.

void QSortFilterProxyModel::setSortRole ( int  role)

Property documentation pending.

void QSortFilterProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
overridevirtual

Reimplemented from QAbstractProxyModel::setSourceModel().

Reimplemented from QAbstractProxyModel.

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 function 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.

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

Reimplemented from QAbstractItemModel::sort().

Reimplemented from QAbstractProxyModel.

Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity ( ) const

Property documentation pending.

int QSortFilterProxyModel::sortColumn ( ) const

the column currently used for sorting

This returns the most recently used sort column.

Qt::SortOrder QSortFilterProxyModel::sortOrder ( ) const

the order currently used for sorting

This returns the most recently used sort order.

int QSortFilterProxyModel::sortRole ( ) const

Property documentation pending.

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

Reimplemented from QAbstractItemModel::span().

Reimplemented from QAbstractProxyModel.

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

Reimplemented from QAbstractItemModel::supportedDropActions().

Reimplemented from QAbstractProxyModel.

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 cs_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