diff options
| author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2025-05-29 12:13:57 +0200 |
|---|---|---|
| committer | Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> | 2025-05-30 08:17:04 +0200 |
| commit | 9efc1fb4ac7982f105a13781fccff74a61907601 (patch) | |
| tree | d5ed4e7f82f15c978a6adfa8052bc5cab6758d3a /src/qmlmodels/doc/snippets | |
| parent | 5b17c03634dcf8f9da6e6570f579f5c2fa280830 (diff) | |
Provide a way to sieve data in QML through the SortFilterProxyModel
Enhance QSortFilterProxyModel to be available in QML with changes
as mentioned below and export the type as SortFilterProxyModel
(Note: adopted most of these features from existing project -
https://github.com/oKcerG/SortFilterProxyModel)
* Inherit QQmlSortFilterProxyModelPrivate from
QSortFilterProxyModelHelper and use the mapping logic
of source to proxy indexes from it.
* Allow the model to be configurable with multiple filters and
sorters. The filter and sorter components shall be inherited
from QQmlFilterBase and QQmlSorterBase respectively.
The components are maintained within the respective compositor
classes. The filter and sorting operation from
QQmlSortFilterProxyModel will be forwarded to the compositor
which then iterate through the configured components to sieve
the data. This patch allows the following filters and sorters
configurable in SFPM,
Filters:
ValueFilter - Filters the data that matching with the
provided value or role name or combined
together if both are specified.
FunctionFilter - Filters the data according to the result
of the evaluated js method.
Sorters:
RoleSorter - Sorts the data according to the provided
role name.
StringSorter - Sorts the data by considering the locale.
FunctionSorter - Sorts the data according to the evaluated
js method.
* Add support for 'enabled', 'column' property for both filters
and sorters, and 'priority' property for the sorters.
Task-number: QTBUG-71348
Change-Id: I65b84936642e5f0f382d83413648d2c6794c18aa
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/qmlmodels/doc/snippets')
| -rw-r--r-- | src/qmlmodels/doc/snippets/qml/sortfilterproxymodel/qml-sortfilterproxymodel.qml | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/qmlmodels/doc/snippets/qml/sortfilterproxymodel/qml-sortfilterproxymodel.qml b/src/qmlmodels/doc/snippets/qml/sortfilterproxymodel/qml-sortfilterproxymodel.qml new file mode 100644 index 0000000000..9f7c2e508f --- /dev/null +++ b/src/qmlmodels/doc/snippets/qml/sortfilterproxymodel/qml-sortfilterproxymodel.qml @@ -0,0 +1,57 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//![0] +import QtQuick +import QtQuick.Controls + +ApplicationWindow { + width: 640 + height: 480 + visible: true + title: qsTr("Sort Filter Proxy Model") + + //! [sfpm-usage] + 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: sfpm + delegate: Rectangle { + implicitWidth: 100 + implicitHeight: 50 + border.width: 1 + Text { + text: name + anchors.centerIn: parent + } + } + } + //! [sfpm-usage] +} + +//![0] |
