ConcatModel QML Type

Proxy model concatenating vertically multiple source models. More...

Import Statement: import QtModelsToolkit .

Properties

Methods

Detailed Description

It allows concatenating multiple source models, with same roles, partially different roles or even totally different roles. The model performs necessary roles mapping internally.

The proxy is similar to QConcatenateTablesProxyModel but QML-ready, performing all necessary role names remapping.

Roles are established when the first item appears in one of the sources. Expected roles can be also declared up-front using expectedRoles property (because on first insertion some roles may be not yet available via roleNames() on other models).

Additionally the model introduces an extra role with a name configurable via ConcatModel::markerRoleName. Value of this role may be set separately for each source model in SourceModel wrapper. This allows to easily create inserts between models using ListView's sections mechanism.

ListModel {
    id: firstModel

    ListElement { name: "entry 1_1" }
    ListElement { name: "entry 1_2" }
    ListElement { name: "entry 1_3" }
}

ListModel {
    id: secondModel

    ListElement {
        name: "entry 1_2"
        key: 1
    }
    ListElement {
        key: 2
        name: "entry 2 _2"
    }
}

ConcatModel {
    id: concatModel

    sources: [
        SourceModel {
            model: firstModel
            markerRoleValue: "first_model"
        },
        SourceModel {
            model: secondModel
            markerRoleValue: "second_model"
        }
    ]

    markerRoleName: "which_model"
    expectedRoles: ["key", "name"]
}

Property Documentation

expectedRoles : list<string>

This property allows to predefine a set of roles exposed by ConcatModel. This is useful when roles are not initially defined for some source models. For example, for ListModel, roles are not defined as long as the model is empty.


markerRoleName : string

This property contains the name of an extra role allowing to distinguish source models from the delegate level.


propagateResets : bool

When set to true, model resets on source models result in model reset of the ConcatModel. Otherwise model resets of sources are handled as removals and insertions. Default is false.


sources : list<SourceModel>

This property holds the list of SourceModel wrappers. Every wrapper holds model which is intended to be concatenated with others within the proxy.


Method Documentation

int fromSourceRow(model, row)

Returns the row number of the ConcatModel for a given source model and source model's row index.


QAbstractItemModel*sourceModel(row)

Returns the source model for a given row of the proxy.


int sourceModelRow(row)

Returns the row index inside the source model for a given row of the proxy.