Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.0 Beta2
-
e9f650cad (dev), be884811d (dev)
Description
Our various views can pass a "generic" property with all the relevant data to each delegate. This property has different names depending on the model that was passed to the view itself. Sometimes the name is "model", and sometimes it's "modelData".
This is a rather leaky abstraction and creates a lot of if'ery in the delegates. Furthermore, it becomes extremely unwieldy if you want to phrase the delegates using required properties. You cannot require both variants as only one will ever be present. Therefore you now have to write two delegates with different required properties.
This piece of code is repeated about 30 times in the various QML files of QtQuick.Controls:
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
QQmlDelegateModelItem has a "model" property and some (all, via custom metaobject construction?) of its derived classes have "modelData" properties.
Judging from some of the documentation (https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html#changing-model-data) "model" is supposed to be read-write and "modelData" is supposed to be read-only. That is fine in principle. But the "modelData" for read access should always be available then. The documentation at https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html is also rather confused. Why does the ListModel shown there not have named roles? I can clearly see "name" and "cost". Granted, named roles for number or string list models are indeed pointless. However, In the case of numbers we can just explicitly expose undefined as modelData. In the case of string lists we already expose the string IIRC.
Attachments
Issue Links
- duplicates
-
QTBUG-104752 No way to support both single and multi-role models in delegates that use required properties
- Closed
- resulted from
-
QTBUG-110934 Make our published QML code as free of qmllint errors/warnings as possible
- Reported