SwitchRole QML Type

A role using Filter to conditionnaly compute its data More...

Import Statement: import .
Inherits:

SingleRole

Properties

Attached Properties

Detailed Description

A SwitchRole is a ProxyRole that computes its data with the help of Filter. Each top level filters specified in the SwitchRole is evaluated on the rows of the model, if a Filter evaluates to true, the data of the SwitchRole for this row will be the one of the attached SwitchRole.value property. If no top level filters evaluate to true, the data will default to the one of the defaultRoleName (or the defaultValue if no defaultRoleName is specified).

In the following example, the favoriteOrFirstNameSection role is equal to * if the favorite role of a row is true, otherwise it's the same as the firstName role :

SortFilterProxyModel {
   sourceModel: contactModel
   proxyRoles: SwitchRole {
       name: "favoriteOrFirstNameSection"
       filters: ValueFilter {
           roleName: "favorite"
           value: true
           SwitchRole.value: "*"
       }
       defaultRoleName: "firstName"
    }
}

Property Documentation

defaultRoleName : string

This property holds the default role name of the role. If no filter match a row, the data of this role will be the data of the role whose name is defaultRoleName.


defaultValue : var

This property holds the default value of the role. If no filter match a row, and no defaultRoleName is set, the data of this role will be defaultValue.


filters : list<Filter>

This property holds the list of filters for this proxy role. The data of this role will be equal to the attached SwitchRole.value property of the first filter that matches the model row.

See also Filter.


Attached Property Documentation

SwitchRole.value : var

This property attaches a value to a Filter.