Add KModelIndexObserver to keep track of data at a particular index
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:
- Device Notifier applet shows info of any first device as its icon and in its tooltip: plasma/plasma-workspace!3274 (comment 759947)
- Print Manager applet also peeking first row's data for its tooltip: https://invent.kde.org/utilities/print-manager/-/blob/f90bd901212375397c4b444f023dee69e729a18d/src/plasmoid/package/contents/ui/main.qml#L41-43
- SDDM theme SessionButton and KeyboardButton are mimicking QQC2/ComboBox and its currentText behavior: https://invent.kde.org/plasma/plasma-workspace/-/blob/c39286e80eb80c90af8ab39f827e53e09270e73e/lookandfeel/sddm-theme/SessionButton.qml#L18
- A pack of lengthy bindings to current index in NeochatMaximizeComponent: https://invent.kde.org/network/neochat/-/blob/2656a93ee73183c936f0e75e710c8f0525d7dcef/src/qml/Component/NeochatMaximizeComponent.qml#L17-29
- ComboBox in Plasma conponentschooser KCM trying real hard to have an icon: https://invent.kde.org/plasma/plasma-desktop/-/blob/a084a10895ef00a183a1d4aca5a85da032a957e7/kcms/componentchooser/ui/ComponentComboBox.qml#L24-40 By the way it would also benefit from porting to KRoleNames as well.
- Tablets KCM, also a candidate for porting to both ModelIndexObserver and KRoleNames: https://invent.kde.org/plasma/plasma-desktop/-/blob/a084a10895ef00a183a1d4aca5a85da032a957e7/kcms/tablet/ui/main.qml#L166-167
- Yet another "icon role" kind of scenario, and some other use-cases in System Monitor: https://invent.kde.org/plasma/plasma-systemmonitor/-/blob/ebe47b1b3f0f58f69813f2250a9c772f9b9df39c/src/faces/applicationstable/contents/ui/ApplicationsTableView.qml#L190-211
- Look and Feel KCM is broken in the same way Bluetooth KCM was: half-binding
and half-copying data from model for a destructive action in popup dialog:
https://invent.kde.org/plasma/plasma-workspace/-/blob/c39286e80eb80c90af8ab39f827e53e09270e73e/kcms/lookandfeel/ui/main.qml#L25-27
- For the reference, here's the relevant Bluetooth patch: plasma/bluedevil!97 (merged)
- Notifications KCM is a golden example of the "details view" scenario: https://invent.kde.org/plasma/plasma-workspace/-/blob/fb40e7ae6159938c1c2b38df10a482007916bcd8/kcms/notifications/ui/ApplicationConfiguration.qml#L27-29