blob: bab86de1b9190d85879f0a5a268151801a2d34cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qqmltcobjectcreationhelper_p.h"
#include <private/qqmlmetatype_p.h>
#include <private/qmetaobjectbuilder_p.h>
#include <private/qobject_p.h>
#include <private/qqmltype_p_p.h>
QT_BEGIN_NAMESPACE
void qmltcCreateDynamicMetaObject(QObject *object, const QmltcTypeData &data)
{
// TODO: when/if qmltc-compiled types would be registered via
// qmltyperegistrar, instead of creating a dummy QQmlTypePrivate, fetch the
// good QQmlType via QQmlMetaType::qmlType(). to do it correctly, one needs,
// along with the meta object, module name and revision. all that should be
// available ahead-of-time to qmltc.
auto qmlTypePrivate = new QQmlTypePrivate(data.regType);
// tie qmlTypePrivate destruction to objects's destruction. the type's
// content is not needed once the associated object is deleted
QObject::connect(object, &QObject::destroyed, object,
[qmlTypePrivate](QObject *) { qmlTypePrivate->release(); },
Qt::DirectConnection);
// initialize QQmlType::QQmlCppTypeData
Q_ASSERT(data.regType == QQmlType::CppType);
qmlTypePrivate->extraData.cppTypeData->allocationSize = data.allocationSize;
qmlTypePrivate->extraData.cppTypeData->newFunc = nullptr;
qmlTypePrivate->extraData.cppTypeData->userdata = nullptr;
qmlTypePrivate->extraData.cppTypeData->noCreationReason =
QStringLiteral("Qmltc-compiled type is not creatable via QQmlType");
qmlTypePrivate->extraData.cppTypeData->createValueTypeFunc = nullptr;
qmlTypePrivate->extraData.cppTypeData->parserStatusCast = -1;
qmlTypePrivate->extraData.cppTypeData->extFunc = nullptr;
qmlTypePrivate->extraData.cppTypeData->extMetaObject = nullptr;
qmlTypePrivate->extraData.cppTypeData->customParser = nullptr;
qmlTypePrivate->extraData.cppTypeData->attachedPropertiesFunc = nullptr;
qmlTypePrivate->extraData.cppTypeData->attachedPropertiesType = nullptr;
qmlTypePrivate->extraData.cppTypeData->propertyValueSourceCast = -1;
qmlTypePrivate->extraData.cppTypeData->propertyValueInterceptorCast = -1;
qmlTypePrivate->extraData.cppTypeData->finalizerCast = -1;
qmlTypePrivate->extraData.cppTypeData->registerEnumClassesUnscoped = false;
qmlTypePrivate->extraData.cppTypeData->registerEnumsFromRelatedTypes = false;
qmlTypePrivate->baseMetaObject = data.metaObject;
QQmlType qmlType(qmlTypePrivate);
Q_ASSERT(qmlType.isValid());
QObjectPrivate *op = QObjectPrivate::get(object);
// ### inefficient - rather, call this function only once for the leaf type
if (op->metaObject) {
delete op->metaObject;
op->metaObject = nullptr;
}
qmlType.createProxy(object);
}
QT_END_NAMESPACE
|