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

Provide a better way to register sequential and associative types for usage in QML

    XMLWordPrintable

    Details

    • Commits:
      d621027babff9a30d56ab6af871a465108c9eaba (qt/qtdeclarative/dev)

      Description

      At the moment all available sequence types are registered from qv4sequenceobject.cpp.

      qv4sequenceobject.cpp produces the largest single piece of binary code in Qt QML. It registers a variety of C++ containers as sequence objects to V4. For each combination of container and item type a few accessor functions have to be generated, leading to combinatorial explosion. In particular, the following types are registered:

      //  F(elementType, elementTypeName, sequenceType, defaultValue)
      #define FOREACH_QML_SEQUENCE_TYPE(F) \
          F(int, IntVector, QVector<int>, 0) \
          F(qreal, RealVector, QVector<qreal>, 0.0) \
          F(bool, BoolVector, QVector<bool>, false) \
          F(int, IntStdVector, std::vector<int>, 0) \
          F(qreal, RealStdVector, std::vector<qreal>, 0.0) \
          F(bool, BoolStdVector, std::vector<bool>, false) \
          F(int, Int, QList<int>, 0) \
          F(qreal, Real, QList<qreal>, 0.0) \
          F(bool, Bool, QList<bool>, false) \
          F(QString, String, QList<QString>, QString()) \
          F(QString, QString, QStringList, QString()) \
          F(QString, StringVector, QVector<QString>, QString()) \
          F(QString, StringStdVector, std::vector<QString>, QString()) \
          F(QUrl, Url, QList<QUrl>, QUrl()) \
          F(QUrl, UrlVector, QVector<QUrl>, QUrl()) \
          F(QUrl, UrlStdVector, std::vector<QUrl>, QUrl()) \
          F(QModelIndex, QModelIndex, QModelIndexList, QModelIndex()) \
          F(QModelIndex, QModelIndexVector, QVector<QModelIndex>, QModelIndex()) \
          F(QModelIndex, QModelIndexStdVector, std::vector<QModelIndex>, QModelIndex()) \
          F(QItemSelectionRange, QItemSelectionRange, QItemSelection, QItemSelectionRange()) 

      Quite obviously, this list is rather arbitrary. Hardly anyone will use all of those, but some rather common ones are missing. For example there is no real reason why you wouldn't be able to pass a QList<QColor>.

      The fix to this involves three measures:

      1. Add public API to register your own container types as sequence objects via a template.
      2. Add a convenience wrapper around that to allow registering all the currently pre-registered sequence objects in one line in Qt6.
      3. Drop the pre-registering in Qt6.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              ulherman Ulf Hermann
              Reporter:
              ulherman Ulf Hermann
              Votes:
              2 Vote for this issue
              Watchers:
              13 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes