Pages
API Documentation
On this page

KSortFilterProxyModel QML Type

Filter and sort an existing QAbstractItemModel. More...

Detailed Description

For example, filter and sort a list by its name role:

import QtQuick
import org.kde.kitemmodels

ListView {
    width: 200
    height: 200
    model: KSortFilterProxyModel {
        sourceModel: ListModel {
            ListElement { name: "Alice" }
            ListElement { name: "Bob" }
            ListElement { name: "Charlie" }
        }
        filterRoleName: "name"
        filterString: "li"
        filterCaseSensitivity: Qt.CaseInsensitive
        sortRoleName: "name"
        sortCaseSensitivity: Qt.CaseInsensitive
        sortColumn: 0
    }
    delegate: Text { text: name }
}

Property Documentation

[default: false] autoAcceptChildRows : bool

Whether all children of an accepted row remain visible, even if they do not match the filter themselves.

count : int

The number of top level rows.

[default: true] dynamicSortFilter : bool

Whether the proxy updates its sorting and filtering when sourceModel changes.

[default: Qt.CaseSensitive] filterCaseSensitivity : Qt::CaseSensitivity

The case sensitivity used when filtering strings.

filterColumnCallback : var

A JavaScript callable that can be used to perform advanced filters on a given column. The callback is passed the source column, and source parent for a given column as arguments.

See also filterRowCallback

[default: 0] filterKeyColumn : int

The source column used for filtering. A value of -1 checks all columns.

filterRegularExpression : var

The regular expression used to filter source rows. Setting filterString replaces it with a fixed-string filter.

[default: Qt.DisplayRole] filterRole : int

The source role ID used for filtering. Setting this also updates filterRoleName.

filterRoleName : string

The name of the source role used for filtering. Use filterRole to set a numerical role ID instead.

filterRowCallback : var

A JavaScript callable that can be used to perform advanced filters on a given row. The callback is passed the source row, and source parent for a given row as arguments

The callable's return value is evaluated as boolean to determine whether the row is accepted (true) or filtered out (false). It overrides the default row filter, so filterString and filterRegularExpression have no effect while filterRowCallback is set. Attempts to write a non-callable to this property are silently ignored, but you can set it to null.

filterRowCallback: function(source_row, source_parent) {
  return sourceModel.data(sourceModel.index(source_row, 0, source_parent), Qt.DisplayRole) == "...";
};

filterString : string

A fixed string used to filter rows by filterRole. Only matching rows are displayed.

[default: false] isSortLocaleAware : bool

Whether string sorting follows the current locale.

[default: false] recursiveFilteringEnabled : bool

Whether a parent remains visible when one of its descendants matches the filter.

[default: Qt.CaseSensitive] sortCaseSensitivity : Qt::CaseSensitivity

The case sensitivity used when sorting strings.

[default: -1] sortColumn : int

Specify which column should be used for sorting Setting sortRoleName sorts column 0 if no column has been selected.

sortOrder : Qt::SortOrder

One of Qt.AscendingOrder or Qt.DescendingOrder

[default: Qt.DisplayRole] sortRole : int

The source role ID used for sorting. Setting this also updates sortRoleName.

sortRoleName : string

The name of the source role used for sorting. Use sortRole to set a numerical role ID instead. An empty name leaves rows unsorted.

sourceModel : var

The model whose rows are filtered and sorted.

Method Documentation

void invalidate()

Reapplies sorting and filtering to the source model.

void invalidateFilter()

Invalidates the current filtering.

This function should be called if you are implementing custom filtering through filterRowCallback or filterColumnCallback, and your filter parameters have changed.

QModelIndex mapFromSource(QModelIndex sourceIndex)

Returns the proxy model index corresponding to sourceIndex. A filtered-out item has no corresponding proxy index.

See also mapToSource()

QItemSelection mapSelectionFromSource(QItemSelection sourceSelection)

Returns the proxy model selection corresponding to sourceSelection.

QItemSelection mapSelectionToSource(QItemSelection proxySelection)

Returns the source model selection corresponding to proxySelection.

QModelIndex mapToSource(QModelIndex proxyIndex)

Returns the source model index corresponding to proxyIndex.

See also mapFromSource()

void setFilterFixedString(string pattern)

Filters rows using the literal string pattern.

void setFilterRegularExpression(string pattern)

Filters rows using the regular expression pattern.

void setFilterRegularExpression(var regularExpression)

Filters rows using regularExpression.

void setFilterWildcard(string pattern)

Filters rows using the wildcard pattern.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.