Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-111176

Views pass either "model" or "modelData" to delegates, depending on type of model

    XMLWordPrintable

Details

    • e9f650cad (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

          Activity

            People

              ulherman Ulf Hermann
              ulherman Ulf Hermann
              Votes:
              5 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: