1 | // Copyright (C) 2016 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 | #ifndef QQMLVALUETYPEWRAPPER_P_H |
5 | #define QQMLVALUETYPEWRAPPER_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qglobal.h> |
19 | #include <private/qtqmlglobal_p.h> |
20 | |
21 | #include <private/qv4referenceobject_p.h> |
22 | #include <private/qqmlpropertycache_p.h> |
23 | #include <private/qqmltype_p_p.h> |
24 | #include <private/qqmltypewrapper_p.h> |
25 | #include <private/qv4object_p.h> |
26 | #include <private/qv4qobjectwrapper_p.h> |
27 | #include <private/qv4sequenceobject_p.h> |
28 | #include <private/qv4value_p.h> |
29 | #include <private/qv4referenceobject_p.h> |
30 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | class QQmlValueType; |
34 | |
35 | namespace QV4 { |
36 | |
37 | namespace Heap { |
38 | |
39 | #define QQmlValueTypeWrapperMembers(class, Member) |
40 | |
41 | DECLARE_HEAP_OBJECT(QQmlValueTypeWrapper, ReferenceObject) { |
42 | DECLARE_MARKOBJECTS(QQmlValueTypeWrapper); |
43 | |
44 | void init( |
45 | const void *data, QMetaType metaType, const QMetaObject *metaObject, |
46 | Object *object, int property, Flags flags) |
47 | { |
48 | ReferenceObject::init(object, property, flags); |
49 | setMetaType(metaType); |
50 | setMetaObject(metaObject); |
51 | if (data) |
52 | setData(data); |
53 | } |
54 | |
55 | QQmlValueTypeWrapper *detached() const; |
56 | |
57 | void destroy(); |
58 | |
59 | QMetaType metaType() const |
60 | { |
61 | Q_ASSERT(m_metaType != nullptr); |
62 | return QMetaType(m_metaType); |
63 | } |
64 | |
65 | void setGadgetPtr(void *gadgetPtr) { m_gadgetPtr = gadgetPtr; } |
66 | void *gadgetPtr() const { return m_gadgetPtr; } |
67 | |
68 | const QMetaObject *metaObject() const { return m_metaObject; } |
69 | |
70 | void setData(const void *data); |
71 | QVariant toVariant() const; |
72 | |
73 | void *storagePointer(); |
74 | bool setVariant(const QVariant &variant); |
75 | |
76 | bool readReference(); |
77 | bool writeBack(int propertyIndex = QV4::ReferenceObject::AllProperties); |
78 | |
79 | private: |
80 | void setMetaObject(const QMetaObject *metaObject) { m_metaObject = metaObject; } |
81 | void setMetaType(QMetaType metaType) |
82 | { |
83 | Q_ASSERT(metaType.isValid()); |
84 | m_metaType = metaType.iface(); |
85 | } |
86 | |
87 | void *m_gadgetPtr; |
88 | const QtPrivate::QMetaTypeInterface *m_metaType; |
89 | const QMetaObject *m_metaObject; |
90 | }; |
91 | |
92 | } |
93 | |
94 | struct Q_QML_EXPORT QQmlValueTypeWrapper : public ReferenceObject |
95 | { |
96 | V4_OBJECT2(QQmlValueTypeWrapper, ReferenceObject) |
97 | V4_PROTOTYPE(valueTypeWrapperPrototype) |
98 | V4_NEEDS_DESTROY |
99 | |
100 | public: |
101 | |
102 | static ReturnedValue create( |
103 | ExecutionEngine *engine, const void *data, const QMetaObject *metaObject, |
104 | QMetaType type, Heap::Object *object, int property, Heap::ReferenceObject::Flags flags); |
105 | static ReturnedValue create( |
106 | ExecutionEngine *engine, Heap::QQmlValueTypeWrapper *cloneFrom, Heap::Object *object); |
107 | static ReturnedValue create( |
108 | ExecutionEngine *engine, const void *, const QMetaObject *metaObject, QMetaType type); |
109 | |
110 | QVariant toVariant() const; |
111 | bool toGadget(void *data) const; |
112 | bool isEqual(const QVariant& value) const; |
113 | int typeId() const; |
114 | QMetaType type() const; |
115 | bool write(QObject *target, int propertyIndex) const; |
116 | bool readReferenceValue() const { return d()->readReference(); } |
117 | const QMetaObject *metaObject() const { return d()->metaObject(); } |
118 | |
119 | QQmlPropertyData dataForPropertyKey(PropertyKey id) const; |
120 | |
121 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); |
122 | static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); |
123 | static bool virtualIsEqualTo(Managed *m, Managed *other); |
124 | static bool virtualHasProperty(const Managed *m, PropertyKey id); |
125 | static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p); |
126 | static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *target); |
127 | static ReturnedValue method_toString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); |
128 | static ReturnedValue virtualResolveLookupGetter(const Object *object, ExecutionEngine *engine, Lookup *lookup); |
129 | static bool virtualResolveLookupSetter(Object *object, ExecutionEngine *engine, Lookup *lookup, const Value &value); |
130 | static ReturnedValue lookupGetter(Lookup *lookup, ExecutionEngine *engine, const Value &object); |
131 | static bool lookupSetter(QV4::Lookup *l, QV4::ExecutionEngine *engine, |
132 | QV4::Value &object, const QV4::Value &value); |
133 | |
134 | static void initProto(ExecutionEngine *v4); |
135 | static int virtualMetacall(Object *object, QMetaObject::Call call, int index, void **a); |
136 | }; |
137 | |
138 | } |
139 | |
140 | QT_END_NAMESPACE |
141 | |
142 | #endif // QV8VALUETYPEWRAPPER_P_H |
143 | |
144 | |
145 | |