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

Typed model data in QML

    XMLWordPrintable

Details

    Description

      We would like to define models with types, so that we can statically compile them to C++. A proposal for the syntax would be:

      // ElementWithModel.qml
      Item {
          id: root
          component DataItem {
              property string city;
              property real shift;
          }
      
          property Model<DataItem> model;
      }
      
      // Instance.qml
      Item {
          ElementWithModel {
              model: Model<DataItem> {
                  DataItem {
                      city: "x"
                      shift: 0.5
                  }
      
                  DataItem {
                      city: "x"
                      shift: 0.5
                  }
              }
          }
      }
      
      
      // InstanceWithShorthand.qml
      Item {
          ElementWithModel {
              model: [
                  {
                      city: "x",
                      shift: 0.5,
                  }, {
                      city: "x"
                      shift: 0.5
                  }
              ]
          }
      }
      
      // InstanceWithRepeater.qml (for mock data)
      Item {
          ElementWithModel {
              model: {
                  Repeater<DataItem> {
                      model: 25
                      DataItem {
                          city: "x" + modelData
                          shift: modelData
                      }
                  }
              }
          }
      }
      
      // Window with shorthand for Items (doesn't make much sense)
      Window {
          [ { x: 5, y: 6 }, { x: 30, y: 7 } ]
      }
      

      This code would be simpler and easier to read when using inline components. In addition the typed model data can be used to verify the compatibility against delegates with required properties.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              ulherman Ulf Hermann
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes