Ubuntu.Components.SortFilterModel
SortFilterModel sorts and filters rows from an existing model. More...
Import Statement: | import Ubuntu.Components 1.3 |
Properties
- filter.pattern : string
- filter.property : string
- model : QAbstractItemModel
- sort.order : string
- sort.property : string
Detailed Description
The SortFilterModel takes an existing model such as a ListModel or any QAbstractItemModel implementation. The original rows and role names show up in the SortFilterModel with two basic differences. For one if sort.property is set all rows will be sorted. Further more if filter.property is set only rows matching the filter will be in the model.
Example usage:
import QtQuick 2.4 import Ubuntu.Components 1.2 import Ubuntu.Components.ListItems 1.1 MainView { width: units.gu(80) height: units.gu(40) ListModel { id: movies ListElement { title: "Esign" producer: "Chris Larkee" } ListElement { title: "Elephants Dream" producer: "Blender" } ListElement { title: "Big Buck Bunny" producer: "Blender" } } SortFilterModel { id: sortedMovies model: movies sort.property: "title" sort.order: Qt.DescendingOrder // case insensitive sorting sortCaseSensitivity: Qt.CaseInsensitive filter.property: "producer" filter.pattern: /blender/ } ListView { model: sortedMovies anchors.fill: parent delegate: Subtitled { text: title subText: producer } section.delegate: ListItem.Header { text: i18n.tr(section) } section.property: "title" section.criteria: ViewSection.FirstCharacter } }
Pay attention to the differences between the original model and the result:
- Big Buck Bunny will be the first row, because it's sorted by title
- Esign won't be visible, because it's from the wrong producer
Property Documentation
filter.pattern : string |
The pattern all rows must match, if filter.property is set.
Some examples:
- /possible/ matches anywhere in a word, so both "impossible" and "possible".
- /^sign/ matches "sign". But not "assignment" because ^ means start.
- /vest$/ matches "safety vest" and "vest" but not "vested".
For more advanced uses it's recommended to read up on Javascript regular expressions.
filter.property : string |
If set to a valid role name, only rows matching filter.pattern will be in the model.
model : QAbstractItemModel |
The source model to sort and/ or filter.
sort.order : string |
The order, if sort.property is set. Qt::AscendingOrder sorts results from A to Z or 0 to 9. Qt::DescendingOrder sorts results from Z to A or 9 to 0.
sort.property : string |
If set to a valid role name, all rows will be sorted according to sort.order.