diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-11-19 13:04:05 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-03-30 11:00:24 +0200 |
commit | eb64978d115445b2aecf280a64b4433c69913322 (patch) | |
tree | cc126f54ce8ba84bfad4b7348f78ecae593561f8 /src/qml | |
parent | fdb45a0e2eb5d1963bd2ee9a7f6ebd49f7dfc9ca (diff) |
qmltc: Migrate to new object creation/querying mechanism
Serves two things:
a) Provides faster/more correct object creation model (long-term)
b) Eliminates (more of) prototype's code generation (short-term)
The whole object querying now works implicitly through the
std::array<QObject *> that QQmltcObjectCreationBase provides. The
creation logic is still rather recursive with regards to QML base
types processing - unfortunately, we cannot simplify this part now
as qmltc requires deeper introspection into the imported types
(this in turn requires fiddling with QQmlJSTypeReader and
QDeferredFactory<QQmlJSScope>::create())
Since we now use the new object creation pattern,
prototype/codegenerator no longer needs high-level compilation
methods. So replace prototype's code accordingly with qmltccompiler
bits. We can also de-duplicate enum and property compilation
(aliases are not touched for simplification) from prototype. Methods
and bindings have to rely on prototype and QmlIR at present, their
compilation is moved more-or-less unchanged
Task-number: QTBUG-84368
Change-Id: I584ceb8f2e3c9f3f79530b02d1c88a4f6c2d06c9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp | 2 | ||||
-rw-r--r-- | src/qml/qmltc/qqmltcobjectcreationhelper_p.h | 15 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp b/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp index 122084f1d8..0e125a1926 100644 --- a/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp +++ b/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp @@ -69,7 +69,7 @@ class HelloWorld : public QObject Q_PROPERTY(QString hello WRITE setHello READ hello BINDABLE bindableHello) public: - HelloWorld(QQmlEngine * engine, QObject * parent = nullptr); + HelloWorld(QQmlEngine* engine, QObject* parent = nullptr); Q_SIGNALS: void created(); diff --git a/src/qml/qmltc/qqmltcobjectcreationhelper_p.h b/src/qml/qmltc/qqmltcobjectcreationhelper_p.h index e34bb5506a..6aa37b1e53 100644 --- a/src/qml/qmltc/qqmltcobjectcreationhelper_p.h +++ b/src/qml/qmltc/qqmltcobjectcreationhelper_p.h @@ -70,17 +70,15 @@ class QQmltcObjectCreationHelper QObject **m_data = nullptr; // QObject* array const qsizetype m_size = 0; // size of m_data array, exists for bounds checking const qsizetype m_offset = 0; // global offset into m_data array - const qsizetype m_nonRoot = 1; // addresses the "+ 1" in QQmltcObjectCreationBase::m_objects - qsizetype offset() const { return m_offset + m_nonRoot; } + qsizetype offset() const { return m_offset; } public: /*! Constructs initial "view" from basic data. Supposed to only be called once from QQmltcObjectCreationBase. */ - QQmltcObjectCreationHelper(QObject **data, qsizetype size) - : m_data(data), m_size(size), m_nonRoot(0 /* root object */) + QQmltcObjectCreationHelper(QObject **data, qsizetype size) : m_data(data), m_size(size) { Q_UNUSED(m_size); } @@ -92,7 +90,6 @@ public: QQmltcObjectCreationHelper(const QQmltcObjectCreationHelper *base, qsizetype localOffset) : m_data(base->m_data), m_size(base->m_size), m_offset(base->m_offset + localOffset) { - Q_ASSERT(m_nonRoot == 1); // sanity check - a sub-creator is for non-root object } template<typename T> @@ -113,6 +110,12 @@ public: Q_ASSERT(m_data[i + offset()] == nullptr); // prevent accidental resets m_data[i + offset()] = object; } + + template<typename T> + static constexpr uint typeCount() noexcept + { + return T::q_qmltc_typeCount(); + } }; /*! @@ -125,7 +128,7 @@ template<typename QmltcGeneratedType> class QQmltcObjectCreationBase { // Note: +1 for the document root itself - std::array<QObject *, QmltcGeneratedType::q_qmltc_typeCount + 1> m_objects = {}; + std::array<QObject *, QmltcGeneratedType::q_qmltc_typeCount() + 1> m_objects = {}; public: QQmltcObjectCreationHelper view() |