[Interest] Sorting QSortFilterProxyModel with QML

André Somers andre at familiesomers.nl
Wed May 27 09:34:11 CEST 2015


Mark Gaiser schreef op 26-5-2015 om 17:02:
> On Tue, May 26, 2015 at 12:35 PM, André Somers <andre at familiesomers.nl 
> <mailto:andre at familiesomers.nl>> wrote:
>
>     I ended up writing my own class that I export to QML for this. It
>     subclasses QSortFilterProxyModel and exposes a nice QML-friendly
>     API for
>     doing filtering and sorting.
>
>
> That sounds interesting!
> Could you share that somewhere (preferably under LGPL, GPL or even BSD)?
Hmm... I can try, but I am not sure I'll get permission for that. It is 
part of a closed source package we have developed. So, definately not in 
the short term.
>
> I was thinking of writing a wrapper class for that as well.
> A thing i also miss is having to ability to set filters 
> in QSortFilterProxyModel without the need to subclass it. That would 
> be possible if it takes a lambda as argument for filtering.
Thats something I'd like to do as well, but preferably as an addition to 
Qt itself. However, that is not really a friendly QML API either.

I created a QML API where you can add filters to the object. Each filter 
has a role it uses to fetch the data, and has some properties like 
"equals" and "contains" to set the criteria. Filters can be combined 
with OR and AND, negated by NOT and grouped, so you end up with 
something like this:

ModelFilter {
    id: filteredModel
    model: myData.model
    combine: ModelFilter.And

    Filter { role: "value"; contains: filterText.text }
    Filter { role: "someRole"; equals: "aValue" }
}


André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150527/6a55d82c/attachment.html>


More information about the Interest mailing list