Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QQmlSortFilterProxyModel Class Reference

Provides sorting and filtering capabilities for a \l QAbstractItemModel. More...

#include <qqmlsortfilterproxymodel_p.h>

Inheritance diagram for QQmlSortFilterProxyModel:
Collaboration diagram for QQmlSortFilterProxyModel:

Signals

void dynamicSortFilterChanged ()
void recursiveFilteringChanged ()
void autoAcceptChildRowsChanged ()
void filtersChanged ()
void sortersChanged ()
void modelChanged ()
void primarySorterChanged ()
Signals inherited from QAbstractProxyModel
void sourceModelChanged (QPrivateSignal)
Signals inherited from QAbstractItemModel
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
 This signal is emitted whenever the data in an existing item changes.
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed.
void layoutChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before rows are inserted into the model.
void rowsInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after rows have been inserted into the model.
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before rows are removed from the model.
void rowsRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after rows have been removed from the model.
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before columns are inserted into the model.
void columnsInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after columns have been inserted into the model.
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before columns are removed from the model.
void columnsRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after columns have been removed from the model.
void modelAboutToBeReset (QPrivateSignal)
void modelReset (QPrivateSignal)
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
void rowsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
void columnsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.

Public Member Functions

 QQmlSortFilterProxyModel (QObject *parent=nullptr)
 ~QQmlSortFilterProxyModel () override
 Clear the filters and sorters and deletes the sort filter proxy model.
QQmlListProperty< QQmlFilterBasefilters ()
QQmlListProperty< QQmlSorterBasesorters ()
bool dynamicSortFilter () const
 \qmlproperty bool SortFilterProxyModel::dynamicSortFilter
void setDynamicSortFilter (const bool enabled)
bool recursiveFiltering () const
 \qmlproperty bool SortFilterProxyModel::recursiveFiltering
void setRecursiveFiltering (const bool enabled)
bool autoAcceptChildRows () const
 \qmlproperty bool SortFilterProxyModel::autoAcceptChildRows
void setAutoAcceptChildRows (const bool enabled)
QVariant model () const
 \qmlproperty var SortFilterProxyModel::model
void setModel (QVariant &sourceModel)
Q_INVOKABLE void invalidate ()
 \qmlmethod SortFilterProxyModel::invalidate()
Q_INVOKABLE void invalidateSorter ()
 \qmlmethod SortFilterProxyModel::invalidateSorter()
Q_INVOKABLE void setPrimarySorter (QQmlSorterBase *sorter)
 \qmlmethod SortFilterProxyModel::setPrimarySorter(sorter)
Q_INVOKABLE QModelIndex mapToSource (const QModelIndex &proxyIndex) const override
 Returns the source model index corresponding to the given proxyIndex from the sorting filter model.
Q_INVOKABLE QModelIndex mapFromSource (const QModelIndex &sourceIndex) const override
 Returns the model index in the QQmlSortFilterProxyModel given the sourceIndex from the source model.
QModelIndex index (int row, int column, const QModelIndex &parent) const override
 \reimp
QModelIndex parent (const QModelIndex &child) const override
 \reimp
QModelIndex sibling (int row, int column, const QModelIndex &idx) const override
 \reimp
bool hasChildren (const QModelIndex &parent=QModelIndex()) const override
 \reimp
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of columns for the children of the given parent.
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of rows under the given parent.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 \reimp
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 \reimp
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 \reimp
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
 \reimp
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 \reimp
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex()) override
 \reimp
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override
 \reimp
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex()) override
 \reimp
QItemSelection mapSelectionToSource (const QItemSelection &proxySelection) const override
 \reimp
QItemSelection mapSelectionFromSource (const QItemSelection &sourceSelection) const override
 \reimp
void setPrimarySortColumn (const int column)
void setPrimarySortOrder (const Qt::SortOrder sortOrder)
QVariant sourceData (const QModelIndex &sourceIndex, int role) const
QHash< int, QByteArrayroleNames () const override
int itemRoleForName (const QString &roleName) const
Public Member Functions inherited from QAbstractProxyModel
 QAbstractProxyModel (QObject *parent=nullptr)
 Constructs a proxy model with the given parent.
 ~QAbstractProxyModel ()
 Destroys the proxy model.
QAbstractItemModelsourceModel () const
 Returns the model that contains the data that is available through the proxy model.
QBindable< QAbstractItemModel * > bindableSourceModel ()
bool submit () override
 \reimp
void revert () override
 \reimp
QMap< int, QVariantitemData (const QModelIndex &index) const override
 \reimp
Qt::ItemFlags flags (const QModelIndex &index) const override
 \reimp
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override
 \reimp
bool clearItemData (const QModelIndex &index) override
 \reimp
QModelIndex buddy (const QModelIndex &index) const override
 \reimp
bool canFetchMore (const QModelIndex &parent) const override
 \reimp
void fetchMore (const QModelIndex &parent) override
 \reimp
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 \reimp
QSize span (const QModelIndex &index) const override
 \reimp
QMimeDatamimeData (const QModelIndexList &indexes) const override
 \reimp
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 \reimp
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 \reimp
QStringList mimeTypes () const override
 \reimp
Qt::DropActions supportedDragActions () const override
 \reimp
Qt::DropActions supportedDropActions () const override
 \reimp
Public Member Functions inherited from QAbstractItemModel
 QAbstractItemModel (QObject *parent=nullptr)
 Constructs an abstract item model with the given parent.
virtual ~QAbstractItemModel ()
 Destroys the abstract item model.
Q_INVOKABLE bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns {true} if the model returns a valid QModelIndex for row and column with parent, otherwise returns {false}.
Q_INVOKABLE Q_REVISION (6, 4) virtual bool insertRows(int row
Q_INVOKABLE Q_REVISION (6, 4) virtual bool insertColumns(int column
Q_INVOKABLE Q_REVISION (6, 4) virtual bool removeRows(int row
Q_INVOKABLE Q_REVISION (6, 4) virtual bool removeColumns(int column
Q_INVOKABLE Q_REVISION (6, 4) virtual bool moveRows(const QModelIndex &sourceParent
Q_INVOKABLE Q_REVISION (6, 4) virtual bool moveColumns(const QModelIndex &sourceParent
Q_INVOKABLE Q_REVISION (6, 4) inline bool insertRow(int row
Q_INVOKABLE Q_REVISION (6, 4) inline bool insertColumn(int column
Q_INVOKABLE Q_REVISION (6, 4) inline bool removeRow(int row
Q_INVOKABLE Q_REVISION (6, 4) inline bool removeColumn(int column
Q_INVOKABLE Q_REVISION (6, 4) inline bool moveRow(const QModelIndex &sourceParent
Q_INVOKABLE Q_REVISION (6, 4) inline bool moveColumn(const QModelIndex &sourceParent
Q_INVOKABLE Q_REVISION (6, 4) virtual void sort(int column
virtual Q_INVOKABLE QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value.
bool checkIndex (const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
virtual void multiData (const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
QObjectparent () const
 Returns a pointer to the parent object.
Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
QString objectName () const
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
QBindable< QStringbindableObjectName ()
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
bool isQmlObjectType () const
 Returns whether the object has been created by the QML engine or ownership has been explicitly set via QJSEngine::setObjectOwnership().
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
QThreadthread () const
 Returns the thread in which the object lives.
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
void killTimer (int id)
 Kills the timer with timer identifier, id.
void killTimer (Qt::TimerId id)
template<typename T>
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
template<typename T>
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
template<typename T>
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const QObjectListchildren () const
 Returns a list of child objects.
void setParent (QObject *parent)
 Makes the object a child of parent.
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
bool disconnect (const QObject *receiver, const char *member=nullptr) const
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
bool setProperty (const char *name, QVariant &&value)
QVariant property (const char *name) const
 Returns the value of the object's name property.
QList< QByteArraydynamicPropertyNames () const
QBindingStoragebindingStorage ()
const QBindingStoragebindingStorage () const
QObjectparent () const
 Returns a pointer to the parent object.
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
Public Member Functions inherited from QQmlParserStatus
 QQmlParserStatus ()
virtual ~QQmlParserStatus ()

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const
bool filterAcceptsColumn (int sourceColumn, const QModelIndex &sourceParent) const
bool lessThan (const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const
void sort (int column=0, Qt::SortOrder sortOrder=Qt::AscendingOrder) override
Protected Member Functions inherited from QAbstractProxyModel
QModelIndex createSourceIndex (int row, int col, void *internalPtr) const
 Equivalent to calling createIndex on the source model.
 QAbstractProxyModel (QAbstractProxyModelPrivate &, QObject *parent)
Protected Member Functions inherited from QAbstractItemModel
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=nullptr)
QModelIndex createIndex (int row, int column, const void *data=nullptr) const
 Creates a model index for the given row and column with the internal pointer ptr.
QModelIndex createIndex (int row, int column, quintptr id) const
 Creates a model index for the given row and column with the internal identifier, id.
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation.
void endInsertRows ()
 Ends a row insertion operation.
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation.
void endRemoveRows ()
 Ends a row removal operation.
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
void endMoveRows ()
 Ends a row move operation.
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation.
void endInsertColumns ()
 Ends a column insertion operation.
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation.
void endRemoveColumns ()
 Ends a column removal operation.
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation.
void endMoveColumns ()
 Ends a column move operation.
void beginResetModel ()
 Begins a model reset operation.
void endResetModel ()
 Completes a model reset operation.
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index.
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
QModelIndexList persistentIndexList () const
Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
int senderSignalIndex () const
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
bool isSignalConnected (const QMetaMethod &signal) const
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
virtual void connectNotify (const QMetaMethod &signal)
virtual void disconnectNotify (const QMetaMethod &signal)
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)

Properties

QQmlListProperty< QQmlFilterBasefilters
 Provides the filters configured in the sort filter proxy model.
QQmlListProperty< QQmlSorterBasesorters
 Provides the sorters configured in the sort filter proxy model.
QVariant model
bool dynamicSortFilter
bool recursiveFiltering
bool autoAcceptChildRows
Properties inherited from QAbstractProxyModel
QAbstractItemModelsourceModel
 the source model of this proxy model.
Properties inherited from QObject
QString objectName
 the name of this object

Private Member Functions

void classBegin () override
 Invoked after class creation, but before any properties have been set.
void componentComplete () override
void setSourceModel (QAbstractItemModel *sourceModel) override

Friends

class QSortFilterProxyModelLessThan
class QSortFilterProxyModelGreaterThan

Additional Inherited Members

Public Types inherited from QAbstractItemModel
enum  LayoutChangeHint { NoLayoutChangeHint , VerticalSortHint , HorizontalSortHint }
 This enum describes the way the model changes layout. More...
enum class  CheckIndexOption { NoOption = 0x0000 , IndexIsValid = 0x0001 , DoNotUseParent = 0x0002 , ParentIsInvalid = 0x0004 }
Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
template<typename Func1, typename Func2>
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
template<typename Func1, typename Func2>
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
template<typename Func1, typename Func2>
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
template<typename Func1>
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
Public Attributes inherited from QAbstractItemModel
Q_INVOKABLE int count
Q_INVOKABLE int const QModelIndexparent = QModelIndex())
 Returns the parent of the model item with the given index.
Q_INVOKABLE int sourceRow
Q_INVOKABLE int int count
Q_INVOKABLE int int const QModelIndexdestinationParent
Q_INVOKABLE int int const QModelIndex int destinationChild
Q_INVOKABLE int sourceColumn
Q_INVOKABLE const QModelIndexparent = QModelIndex())
Q_INVOKABLE int const QModelIndexdestinationParent
Q_INVOKABLE int const QModelIndex int destinationChild
Q_INVOKABLE Qt::SortOrder order = Qt::AscendingOrder)
Protected Slots inherited from QAbstractItemModel
virtual void resetInternalData ()
Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr

Detailed Description

Provides sorting and filtering capabilities for a \l QAbstractItemModel.

\qmltype SortFilterProxyModel

! \nativetype QQmlSortFilterProxyModel \inqmlmodule QtQml.Models

Since
6.10 \preliminary

SortFilterProxyModel inherits from \l QAbstractProxyModel, which handles the transformation of source indexes into proxy indexes. Sorting and filtering are controlled via the \l{SortFilterProxyModel::sorters}{sorters} and \l{SortFilterProxyModel::filters}{filters} properties, which determine the order of execution as specified in QML. This order can be overridden using the priority property available for each sorter. By default, all sorters share the same priority.

SortFilterProxyModel enables users to sort and filter a \l QAbstractItemModel. The item views such as \l TableView or \l TreeView can utilize this proxy model to display filtered content.

Note
Currently, SortFilterProxyModel supports only QAbstractItemModel as the source model.

The snippet below shows the configuration of sorters and filters in the QML SortFilterProxyModel:

\qml ProcessModel { id: processModel }

SortFilterProxyModel { id: sfpm model: processModel sorters: [ RoleSorter: { roleName: "user" priority: 0 }, RoleSorter: { roleName: "pid" priority: 1 } ] filters: [ FunctionFilter: { component RoleData: QtObject { property qreal cpuUsage } function filter(data: RoleData) : bool { return (data.cpuUsage > 90) } } ] } \endqml

The SortFilterProxyModel dynamically sorts and filters data whenever there is a change to the data in the source model and can be disabled through the \l{SortFilterProxyModel::}{dynamicSortFilter} property.

The sorters \l RoleSorter, \l StringSorter and \l FunctionSorter can be configured in SortFilterProxyModel. Each sorter can be configured with a specific column index through \l{Sorter::}{column} property. If a column index is not specified, the sorting will be applied to the column index 0 of the model by default. The execution order of the sorter can be modified through the \l{Sorter::priority}{priority} property. This is particularly useful when performing hierarchical sorting, such as sorting data in the first column and then applying sorting to subsequent columns.

To disable a specific sorter, \l{Sorter::}{enabled} can be set to false.

The sorter priority can also be overridden by setting the primary sorter through the method call \l{SortFilterProxyModel::}{setPrimarySorter()}. This would be helpful in the case where the view wants to sort the data of any specific column by clicking on the column header such as in \l TableView, when there are other sorters also configured for the model.

The filter \l ValueFilter and \l FunctionFilter can be configured in SortFilterProxyModel. Each filter can be set with the \l{Filter::}{column} property, similar to the sorter, to filter data in a specific column. If no column is specified, then the filter will be applied to all the column indexes in the model. To reduce the overhead of unwanted checks during filtering, it's recommended to specify the column index.

To disable a specific filter, \l{Filter::}{enabled} can be set to false.

ListModel {
id: listModel
ListElement { name: "Adan"; age: 25; department: "Process"; pid: 209711; country: "Norway" }
ListElement { name: "Hannah"; age: 48; department: "HR"; pid: 154916; country: "Germany" }
ListElement { name: "Divina"; age: 63; department: "Marketing"; pid: 158038; country: "Spain" }
ListElement { name: "Rohith"; age: 35; department: "Process"; pid: 202582; country: "India" }
ListElement { name: "Latesha"; age: 23; department: "Quality"; pid: 232582; country: "UK" }
}
SortFilterProxyModel {
id: ageFilterModel
model: listModel
filters: [
FunctionFilter {
roleData: QtObject { property int age }
function filter(data: QtObject) : bool {
return data.age > 30
}
}
]
sorters: [
RoleSorter { roleName: "department" }
]
}
ListView {
anchors.fill: parent
clip: true
model: ageFilterModel
delegate: Rectangle {
implicitWidth: 100
implicitHeight: 50
border.width: 1
Text {
text: name
anchors.centerIn: parent
}
}
}
Note
This API is considered tech preview and may change or be removed in future versions of Qt.

\qmlproperty list<Filter> SortFilterProxyModel::filters

This property holds the list of filters for the \l SortFilterProxyModel. If no priority is set, the \l SortFilterProxyModel applies a filter in the order as specified in the list.

\qmlproperty list<Sorter> SortFilterProxyModel::sorters

This property holds the list of sorters for the \l SortFilterProxyModel. If no priority is set, the \l SortFilterProxyModel applies a sorter in the order as specified in the list.

Definition at line 36 of file qqmlsortfilterproxymodel_p.h.

Constructor & Destructor Documentation

◆ QQmlSortFilterProxyModel()

QQmlSortFilterProxyModel::QQmlSortFilterProxyModel ( QObject * parent = nullptr)
explicit

Definition at line 124 of file qqmlsortfilterproxymodel.cpp.

◆ ~QQmlSortFilterProxyModel()

QQmlSortFilterProxyModel::~QQmlSortFilterProxyModel ( )
override

Clear the filters and sorters and deletes the sort filter proxy model.

Definition at line 134 of file qqmlsortfilterproxymodel.cpp.

Member Function Documentation

◆ autoAcceptChildRows()

bool QQmlSortFilterProxyModel::autoAcceptChildRows ( ) const

\qmlproperty bool SortFilterProxyModel::autoAcceptChildRows

This property will not filter out children of accepted rows. The behavior is similar to that of \l autoAcceptChildRows in \l QSortFilterProxyModel.

The default value is false.

Definition at line 215 of file qqmlsortfilterproxymodel.cpp.

◆ autoAcceptChildRowsChanged

void QQmlSortFilterProxyModel::autoAcceptChildRowsChanged ( )
signal

◆ classBegin()

void QQmlSortFilterProxyModel::classBegin ( )
inlineoverrideprivatevirtual

Invoked after class creation, but before any properties have been set.

Implements QQmlParserStatus.

Definition at line 117 of file qqmlsortfilterproxymodel_p.h.

◆ columnCount()

int QQmlSortFilterProxyModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
overridevirtual

Returns the number of columns for the children of the given parent.

In most subclasses, the number of columns is independent of the parent.

For example:

{
return 3;
}
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
\inmodule QtCore
QModelIndex parent(const QModelIndex &child) const override
\reimp
#define Q_UNUSED(x)
Note
When implementing a table based model, columnCount() should return 0 when the parent is valid.
See also
rowCount()

Implements QAbstractItemModel.

Definition at line 506 of file qqmlsortfilterproxymodel.cpp.

◆ componentComplete()

void QQmlSortFilterProxyModel::componentComplete ( )
overrideprivatevirtual

Implements QQmlParserStatus.

Definition at line 768 of file qqmlsortfilterproxymodel.cpp.

◆ data()

QVariant QQmlSortFilterProxyModel::data ( const QModelIndex & proxyIndex,
int role = Qt::DisplayRole ) const
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 530 of file qqmlsortfilterproxymodel.cpp.

◆ dynamicSortFilter()

bool QQmlSortFilterProxyModel::dynamicSortFilter ( ) const

\qmlproperty bool SortFilterProxyModel::dynamicSortFilter

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

The default value is true.

Definition at line 167 of file qqmlsortfilterproxymodel.cpp.

◆ dynamicSortFilterChanged

void QQmlSortFilterProxyModel::dynamicSortFilterChanged ( )
signal

◆ filterAcceptsColumn()

bool QQmlSortFilterProxyModel::filterAcceptsColumn ( int column,
const QModelIndex & sourceParent ) const
protected

Definition at line 746 of file qqmlsortfilterproxymodel.cpp.

◆ filterAcceptsRow()

bool QQmlSortFilterProxyModel::filterAcceptsRow ( int row,
const QModelIndex & sourceParent ) const
protected

Definition at line 735 of file qqmlsortfilterproxymodel.cpp.

◆ filters()

QQmlListProperty< QQmlFilterBase > QQmlSortFilterProxyModel::filters ( )

◆ filtersChanged

void QQmlSortFilterProxyModel::filtersChanged ( )
signal

◆ hasChildren()

bool QQmlSortFilterProxyModel::hasChildren ( const QModelIndex & parent = QModelIndex()) const
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 490 of file qqmlsortfilterproxymodel.cpp.

◆ headerData()

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

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 551 of file qqmlsortfilterproxymodel.cpp.

◆ index()

QModelIndex QQmlSortFilterProxyModel::index ( int row,
int column,
const QModelIndex & parent ) const
overridevirtual

\reimp

Implements QAbstractItemModel.

Definition at line 442 of file qqmlsortfilterproxymodel.cpp.

◆ insertColumns()

bool QQmlSortFilterProxyModel::insertColumns ( int column,
int count,
const QModelIndex & parent = QModelIndex() )
override

\reimp

Definition at line 616 of file qqmlsortfilterproxymodel.cpp.

◆ insertRows()

bool QQmlSortFilterProxyModel::insertRows ( int row,
int count,
const QModelIndex & parent = QModelIndex() )
override

\reimp

Definition at line 596 of file qqmlsortfilterproxymodel.cpp.

◆ invalidate()

void QQmlSortFilterProxyModel::invalidate ( )

\qmlmethod SortFilterProxyModel::invalidate()

This method invalidates the model by reevaluating the configured filters and sorters on the source model data.

Definition at line 273 of file qqmlsortfilterproxymodel.cpp.

◆ invalidateSorter()

void QQmlSortFilterProxyModel::invalidateSorter ( )

\qmlmethod SortFilterProxyModel::invalidateSorter()

This method force the sort filter proxy model to reevaluate the configured sorters against the data. It can used in the case where dynamic sorting was disabled through property \l dynamicSortFilter

Definition at line 289 of file qqmlsortfilterproxymodel.cpp.

◆ itemRoleForName()

int QQmlSortFilterProxyModel::itemRoleForName ( const QString & roleName) const

Definition at line 799 of file qqmlsortfilterproxymodel.cpp.

◆ lessThan()

bool QQmlSortFilterProxyModel::lessThan ( const QModelIndex & sourceLeft,
const QModelIndex & sourceRight ) const
protected

Definition at line 757 of file qqmlsortfilterproxymodel.cpp.

◆ mapFromSource()

QModelIndex QQmlSortFilterProxyModel::mapFromSource ( const QModelIndex & sourceIndex) const
overridevirtual

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

Implements QAbstractProxyModel.

Definition at line 416 of file qqmlsortfilterproxymodel.cpp.

◆ mapSelectionFromSource()

QItemSelection QQmlSortFilterProxyModel::mapSelectionFromSource ( const QItemSelection & sourceSelection) const
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 433 of file qqmlsortfilterproxymodel.cpp.

◆ mapSelectionToSource()

QItemSelection QQmlSortFilterProxyModel::mapSelectionToSource ( const QItemSelection & proxySelection) const
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 425 of file qqmlsortfilterproxymodel.cpp.

◆ mapToSource()

QModelIndex QQmlSortFilterProxyModel::mapToSource ( const QModelIndex & proxyIndex) const
overridevirtual

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

Implements QAbstractProxyModel.

Definition at line 406 of file qqmlsortfilterproxymodel.cpp.

◆ model()

QVariant QQmlSortFilterProxyModel::model ( ) const

\qmlproperty var SortFilterProxyModel::model

This property allows to set source model for the sort filter proxy model.

Definition at line 235 of file qqmlsortfilterproxymodel.cpp.

◆ modelChanged

void QQmlSortFilterProxyModel::modelChanged ( )
signal

◆ parent()

QModelIndex QQmlSortFilterProxyModel::parent ( const QModelIndex & child) const
overridevirtual

\reimp

Implements QAbstractItemModel.

Definition at line 459 of file qqmlsortfilterproxymodel.cpp.

◆ primarySorterChanged

void QQmlSortFilterProxyModel::primarySorterChanged ( )
signal

◆ recursiveFiltering()

bool QQmlSortFilterProxyModel::recursiveFiltering ( ) const

\qmlproperty bool SortFilterProxyModel::recursiveFiltering

This property allows all the configured filters to be applied recursively on children. The behavior is similar to that of \l {QSortFilterProxyModel::}{recursiveFilteringEnabled} in \l QSortFilterProxyModel.

The default value is false.

Definition at line 192 of file qqmlsortfilterproxymodel.cpp.

◆ recursiveFilteringChanged

void QQmlSortFilterProxyModel::recursiveFilteringChanged ( )
signal

◆ removeColumns()

bool QQmlSortFilterProxyModel::removeColumns ( int column,
int count,
const QModelIndex & parent = QModelIndex() )
override

\reimp

Definition at line 678 of file qqmlsortfilterproxymodel.cpp.

◆ removeRows()

bool QQmlSortFilterProxyModel::removeRows ( int row,
int count,
const QModelIndex & parent = QModelIndex() )
override

\reimp

Definition at line 636 of file qqmlsortfilterproxymodel.cpp.

◆ roleNames()

QHash< int, QByteArray > QQmlSortFilterProxyModel::roleNames ( ) const
overridevirtual

Reimplemented from QAbstractProxyModel.

Definition at line 717 of file qqmlsortfilterproxymodel.cpp.

◆ rowCount()

int QQmlSortFilterProxyModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
overridevirtual

Returns the number of rows under the given parent.

When the parent is valid it means that rowCount is returning the number of children of parent.

Note
When implementing a table based model, rowCount() should return 0 when the parent is valid.
See also
columnCount()

Implements QAbstractItemModel.

Definition at line 518 of file qqmlsortfilterproxymodel.cpp.

◆ setAutoAcceptChildRows()

void QQmlSortFilterProxyModel::setAutoAcceptChildRows ( const bool enabled)

Definition at line 221 of file qqmlsortfilterproxymodel.cpp.

◆ setData()

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

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 539 of file qqmlsortfilterproxymodel.cpp.

◆ setDynamicSortFilter()

void QQmlSortFilterProxyModel::setDynamicSortFilter ( const bool enabled)

Definition at line 173 of file qqmlsortfilterproxymodel.cpp.

◆ setHeaderData()

bool QQmlSortFilterProxyModel::setHeaderData ( int section,
Qt::Orientation orientation,
const QVariant & value,
int role = Qt::EditRole )
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 573 of file qqmlsortfilterproxymodel.cpp.

◆ setModel()

void QQmlSortFilterProxyModel::setModel ( QVariant & sourceModel)

Definition at line 241 of file qqmlsortfilterproxymodel.cpp.

◆ setPrimarySortColumn()

void QQmlSortFilterProxyModel::setPrimarySortColumn ( const int column)

Definition at line 808 of file qqmlsortfilterproxymodel.cpp.

◆ setPrimarySorter()

void QQmlSortFilterProxyModel::setPrimarySorter ( QQmlSorterBase * sorter)

\qmlmethod SortFilterProxyModel::setPrimarySorter(sorter)

This method allows to set the primary sorter in the sort filter proxy model. The primary sorter will be evaluated before all other sorters configured as part of sorter property. If not configured or passed null, the sorter with higher priority shall be considered as the primary sorter.

Definition at line 305 of file qqmlsortfilterproxymodel.cpp.

◆ setPrimarySortOrder()

void QQmlSortFilterProxyModel::setPrimarySortOrder ( const Qt::SortOrder order)

Definition at line 818 of file qqmlsortfilterproxymodel.cpp.

◆ setRecursiveFiltering()

void QQmlSortFilterProxyModel::setRecursiveFiltering ( const bool enabled)

Definition at line 198 of file qqmlsortfilterproxymodel.cpp.

◆ setSourceModel()

void QQmlSortFilterProxyModel::setSourceModel ( QAbstractItemModel * sourceModel)
overrideprivatevirtual

Reimplemented from QAbstractProxyModel.

Definition at line 321 of file qqmlsortfilterproxymodel.cpp.

◆ sibling()

QModelIndex QQmlSortFilterProxyModel::sibling ( int row,
int column,
const QModelIndex & idx ) const
overridevirtual

\reimp

Reimplemented from QAbstractProxyModel.

Definition at line 474 of file qqmlsortfilterproxymodel.cpp.

◆ sort()

void QQmlSortFilterProxyModel::sort ( int column = 0,
Qt::SortOrder order = Qt::AscendingOrder )
overrideprotected

Definition at line 784 of file qqmlsortfilterproxymodel.cpp.

◆ sorters()

QQmlListProperty< QQmlSorterBase > QQmlSortFilterProxyModel::sorters ( )

◆ sortersChanged

void QQmlSortFilterProxyModel::sortersChanged ( )
signal

◆ sourceData()

QVariant QQmlSortFilterProxyModel::sourceData ( const QModelIndex & sourceIndex,
int role ) const

Definition at line 727 of file qqmlsortfilterproxymodel.cpp.

◆ QSortFilterProxyModelGreaterThan

friend class QSortFilterProxyModelGreaterThan
friend

Definition at line 136 of file qqmlsortfilterproxymodel_p.h.

◆ QSortFilterProxyModelLessThan

friend class QSortFilterProxyModelLessThan
friend

Definition at line 135 of file qqmlsortfilterproxymodel_p.h.

Property Documentation

◆ autoAcceptChildRows

bool QQmlSortFilterProxyModel::autoAcceptChildRows
readwrite

Definition at line 46 of file qqmlsortfilterproxymodel_p.h.

◆ dynamicSortFilter

bool QQmlSortFilterProxyModel::dynamicSortFilter
readwrite

Definition at line 44 of file qqmlsortfilterproxymodel_p.h.

◆ filters

QQmlListProperty< QQmlFilterBase > QQmlSortFilterProxyModel::filters
read

Provides the filters configured in the sort filter proxy model.

Definition at line 41 of file qqmlsortfilterproxymodel_p.h.

◆ model

QVariant QQmlSortFilterProxyModel::model
readwrite

Definition at line 43 of file qqmlsortfilterproxymodel_p.h.

◆ recursiveFiltering

bool QQmlSortFilterProxyModel::recursiveFiltering
readwrite

Definition at line 45 of file qqmlsortfilterproxymodel_p.h.

◆ sorters

QQmlListProperty< QQmlSorterBase > QQmlSortFilterProxyModel::sorters
read

Provides the sorters configured in the sort filter proxy model.

Definition at line 42 of file qqmlsortfilterproxymodel_p.h.


The documentation for this class was generated from the following files: