All Projects → oKcerG → Sortfilterproxymodel

oKcerG / Sortfilterproxymodel

Licence: mit
A nicely exposed QSortFilterProxyModel for QML

Projects that are alternatives of or similar to Sortfilterproxymodel

Qtwebdriver
WebDriver implementation for Qt
Stars: ✭ 152 (-28.97%)
Mutual labels:  qt, qml
Qtfirebase
An effort to bring Google's Firebase C++ API to Qt + QML
Stars: ✭ 208 (-2.8%)
Mutual labels:  qt, qml
Qml Loaders
Loading animation implementations in QML
Stars: ✭ 158 (-26.17%)
Mutual labels:  qt, qml
Dotherside
C language library for creating bindings for the Qt QML language
Stars: ✭ 140 (-34.58%)
Mutual labels:  qt, qml
Stackoverflow
my answers in Stack Overflow
Stars: ✭ 211 (-1.4%)
Mutual labels:  qt, qml
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-29.91%)
Mutual labels:  sort, filter
Shell
🐚 QtQuick and Wayland shell for convergence
Stars: ✭ 168 (-21.5%)
Mutual labels:  qt, qml
Ng2 Smart Table
Angular Smart Data Table component
Stars: ✭ 1,590 (+642.99%)
Mutual labels:  sort, filter
Asyncfuture
Use QFuture like a Promise object
Stars: ✭ 193 (-9.81%)
Mutual labels:  qt, qml
Browser
🌍 Cross-platform Material design web browser
Stars: ✭ 184 (-14.02%)
Mutual labels:  qt, qml
Qtmvvm
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
Stars: ✭ 205 (-4.21%)
Mutual labels:  qt, qml
Qml Rust
QML (Qt Quick) bindings for Rust language
Stars: ✭ 196 (-8.41%)
Mutual labels:  qt, qml
Qtandroidtools
A library to manage Android from QML
Stars: ✭ 134 (-37.38%)
Mutual labels:  qt, qml
Haruna
Open source video player built with Qt/QML and libmpv.
Stars: ✭ 147 (-31.31%)
Mutual labels:  qt, qml
Atomicdex Desktop
atomicDEX Desktop app - project codename "Dextop"
Stars: ✭ 126 (-41.12%)
Mutual labels:  qt, qml
Zshelf
reMarkable app: Browse and download books from Z-Library
Stars: ✭ 166 (-22.43%)
Mutual labels:  qt, qml
Faltu
Search sort, filter, limit an array of objects in Mongo-style.
Stars: ✭ 112 (-47.66%)
Mutual labels:  sort, filter
Autoannotationtool
A label tool aim to reduce semantic segmentation label time, rectangle and polygon annotation is supported
Stars: ✭ 113 (-47.2%)
Mutual labels:  qt, qml
Shuffle
Categorize, sort, and filter a responsive grid of items
Stars: ✭ 2,170 (+914.02%)
Mutual labels:  sort, filter
Qml Coding Guide
A collection of good practices when writing QML code
Stars: ✭ 196 (-8.41%)
Mutual labels:  qt, qml

SortFilterProxyModel

SortFilterProxyModel is an implementation of QSortFilterProxyModel conveniently exposed for QML.

Install

With qpm :
  1. qpm install fr.grecko.sortfilterproxymodel
  2. add include(vendor/vendor.pri) in your .pro if it is not already done
  3. import SortFilterProxyModel 0.2 to use this library in your QML files
Without qpm :
  1. clone or download this repository
    • qmake add include (<path/to/SortFilterProxyModel>/SortFilterProxyModel.pri) in your .pro
    • CMake add $<TARGET_OBJECTS:SortFilterProxyModel> to the sources of your executable target in your cmake project
  2. import SortFilterProxyModel 0.2 to use this library in your QML files

Sample Usage

  • You can do simple filtering and sorting with SortFilterProxyModel:
import QtQuick 2.2
import QtQuick.Controls 1.2
import SortFilterProxyModel 0.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480

    ListModel {
        id: personModel
        ListElement {
            firstName: "Erwan"
            lastName: "Castex"
            favorite: true
        }
        // ...
    }

    TextField {
        id: textField
        anchors { top: parent.top; left: parent.left; right: parent.right }
        height: implicitHeight
    }

    SortFilterProxyModel {
        id: personProxyModel
        sourceModel: personModel
        filters: RegExpFilter {
            roleName: "lastName"
            pattern: textField.text
            caseSensitivity: Qt.CaseInsensitive
        }
        sorters: StringSorter { roleName: "firstName" }
    }

    ListView {
        anchors { top: textField.bottom; bottom: parent.bottom; left: parent.left; right: parent.right }
        model: personProxyModel
        delegate: Text { text: model.firstName + " " + model.lastName}
    }
}

Here the ListView will only show elements that contains the content of the TextField in their lastName role.

  • But you can also achieve more complex filtering or sorting with multiple filters and sorters:
    SortFilterProxyModel {
        id: personProxyModel
        sourceModel: personModel
        filters: [
            ValueFilter {
                enabled: onlyShowFavoritesCheckbox.checked
                roleName: "favorite"
                value: true
            },
            AnyOf {
                RegExpFilter {
                    roleName: "lastName"
                    pattern: textField.text
                    caseSensitivity: Qt.CaseInsensitive
                }
                RegExpFilter {
                    roleName: "firstName"
                    pattern: textField.text
                    caseSensitivity: Qt.CaseInsensitive
                }
            }
        ]
        sorters: [
            RoleSorter { roleName: "favorite"; sortOrder: Qt.DescendingOrder },
            StringSorter { roleName: "firstName" },
            StringSorter { roleName: "lastName" }
        ]
    }

    CheckBox {
        id:onlyShowFavoritesCheckbox
    }

This will show in the corresponding ListView only the elements where the firstName or the lastName match the text entered in the textField, and if the onlyShowFavoritesCheckbox is checked it will aditionnally filter the elements where favorite is true. The favorited elements will be shown first and all the elements are sorted by firstName and then lastName.

Showcase Application

You can find an application showcasing this library here: https://github.com/oKcerG/SFPMShowcase

License

This library is licensed under the MIT License.

Documentation

This component is a subclass of QSortFilterProxyModel, to use it, you need to set the sourceModel property to a QAbstractItemModel* with correct role names. This means you can use it with custom c++ models or ListModel, but not with JavaScript models like arrays, integers or object instances.

The complete documentation reference is available here: https://okcerg.github.io/SortFilterProxyModel/

Contributing

Don't hesitate to open an issue about a suggestion, a bug, a lack of clarity in the documentation, etc.

Pull requests are also welcome, if it's a important change you should open an issue first though.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].