diff options
| author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-07-24 16:22:30 +0200 |
|---|---|---|
| committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-08-05 13:40:47 +0200 |
| commit | 67b99c2a106311e167e027426f7e2efa20cbc6ca (patch) | |
| tree | 7be71856e5371708ed4dc40393342297ad7f4713 /src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp | |
| parent | c93cbe39b408c1e8b0c0e7d8152f01d06b07fd2a (diff) | |
QRangeModel: support a "modelData" role for Qt Quick compatibility
In Qt Quick, models support a "modelData" property. Depending on the
underlying data structure, that property holds the data stored. For a
QObjectList, it is the QObject, allowing QML code to access properties
of individual QObject instances in that list.
As of now, this is the only way for QML code to respond to changes of
properties in such a backend data structure, as nothing connects the
propertyChanged-signals of all QObject entries to the dataChanged()
signal of an internal QAIM proxy. And even if we can find a way to do
this in QRangeModel, it will be rather expensive if only a few
properties are actually interesting. So we can assume that there is code
out there doing exactly this.
For QRangeModel to fully replace this use case, we have to provide
access to the QObject that represents a multi-role item. We can fake the
modelData role to return the QObject (or gadget) instance that backs the
item and a given index. For QML to see the role, we include it in the
automatically generated roleNames() mapping, using a new, undocumented
value in Qt::ItemDataRole. We skip that role for itemData.
We do not allow setting the data for that role, as it would make object
ownership very messy, so return early from such calls of setData(), and
ignore an entry for that role in setItemData.
Pick-to: 6.10
Change-Id: Iaf7dee5d6be18cf8b99ce796b9314459dffcfcb8
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp')
0 files changed, 0 insertions, 0 deletions
