1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | |
5 | #ifndef QQMLADAPTORMODELENGINEDATA_P_H |
6 | #define QQMLADAPTORMODELENGINEDATA_P_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <private/qqmldelegatemodel_p_p.h> |
20 | #include <private/qmetaobjectbuilder_p.h> |
21 | #include <private/qqmlproperty_p.h> |
22 | |
23 | #include <private/qv4value_p.h> |
24 | #include <private/qv4functionobject_p.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QQmlAdaptorModelEngineData : public QV4::ExecutionEngine::Deletable |
29 | { |
30 | public: |
31 | QQmlAdaptorModelEngineData(QV4::ExecutionEngine *v4); |
32 | |
33 | QV4::ExecutionEngine *v4; |
34 | QV4::PersistentValue listItemProto; |
35 | |
36 | static QV4::ReturnedValue get_index(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *, int) |
37 | { |
38 | QV4::Scope scope(f); |
39 | QV4::Scoped<QQmlDelegateModelItemObject> o(scope, thisObject->as<QQmlDelegateModelItemObject>()); |
40 | if (!o) |
41 | RETURN_RESULT(scope.engine->throwTypeError(QStringLiteral("Not a valid DelegateModel object" ))); |
42 | |
43 | RETURN_RESULT(QV4::Encode(o->d()->item->index)); |
44 | } |
45 | |
46 | template <typename T, typename M> static void setModelDataType(QMetaObjectBuilder *builder, M *metaType) |
47 | { |
48 | builder->setFlags(MetaObjectFlag::DynamicMetaObject); |
49 | builder->setClassName(T::staticMetaObject.className()); |
50 | builder->setSuperClass(&T::staticMetaObject); |
51 | metaType->propertyOffset = T::staticMetaObject.propertyCount(); |
52 | metaType->signalOffset = T::staticMetaObject.methodCount(); |
53 | } |
54 | |
55 | static void addProperty(QMetaObjectBuilder *builder, int propertyId, const QByteArray &propertyName, const QByteArray &propertyType) |
56 | { |
57 | builder->addSignal(signature: "__" + QByteArray::number(propertyId) + "()" ); |
58 | QMetaPropertyBuilder property = builder->addProperty( |
59 | name: propertyName, type: propertyType, notifierId: propertyId); |
60 | property.setWritable(true); |
61 | } |
62 | |
63 | V4_DEFINE_EXTENSION(QQmlAdaptorModelEngineData, get) |
64 | }; |
65 | |
66 | QT_END_NAMESPACE |
67 | |
68 | #endif // QQMLADAPTORMODELENGINEDATA_P_H |
69 | |