Skip to content

Add KModelIndexObserver to keep track of data at a particular index

ivan tkachenko requested to merge work/ratijas/modelindexobserver into master

As documentation states:

KModelIndexObserver: Observes a single index of a source model and notifies of data changes.

This class provides QQmlPropertyMap object property for declarative bindings on model data. It works just like modelData context property inside delegates of Repeater, ListView etc.

Index can be set directly as a QModelIndex value, or as combination of row, column and parentIndex properties. By default row is -1, column is 0, and parentIndex is an invalid index. The result is now well-defined if both index and of row, column or parentIndex are bound.

Set of observed roles can be limited using roles or roleNames property. Setting one will cause the other one to adjust accordingly. If model is not set or some role/name is not found in mapping, the corresponding value in the other list will be set to -1 for role or an empty string for role name. The object will attempt to refresh roles array when the sourceModel property changes, or the model emits reset signal. By default, arrays are empty, which means all roles are observed.


Practicaly this means we can implement features like icon role for ComboBox, or declaratively update "details" pane with content of selected item in a list view pane. If you ever relied on model.data() in a declarative binding, this new type will fix the bug you introduced.

Thing that need to be ported/fixed:

Merge request reports