Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlvaluetypewrapper_p.h
Go to the documentation of this file.
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
23QT_BEGIN_NAMESPACE
24
25class QQmlValueType;
26
27namespace QV4 {
28
29namespace Heap {
30
31#define QQmlValueTypeWrapperMembers(class, Member)
32
34 DECLARE_MARKOBJECTS(QQmlValueTypeWrapper);
35
36 void init(
37 const void *data, QMetaType metaType, const QMetaObject *metaObject,
38 Object *object, int property, Flags flags)
39 {
40 ReferenceObject::init(object, property, flags | IsDirty);
41 setMetaType(metaType);
42 setMetaObject(metaObject);
43 if (data)
44 setData(data);
45 }
46
47 QQmlValueTypeWrapper *detached() const;
48
49 void destroy();
50
51 QMetaType metaType() const
52 {
53 Q_ASSERT(m_metaType != nullptr);
54 return QMetaType(m_metaType);
55 }
56
57 void setGadgetPtr(void *gadgetPtr) { m_gadgetPtr = gadgetPtr; }
58 void *gadgetPtr() const { return m_gadgetPtr; }
59
60 const QMetaObject *metaObject() const { return m_metaObject; }
61
62 void setData(const void *data)
63 {
64 const QMetaType type = metaType();
65 void *gadget = gadgetPtr();
66 if (gadget) {
67 type.destruct(gadget);
68 } else {
69 gadget = ::operator new(type.sizeOf());
70 setGadgetPtr(gadget);
71 }
72 type.construct(gadget, data);
73 }
74
75 QVariant toVariant() const;
76
77 void *storagePointer();
78 bool setVariant(const QVariant &variant);
79
80 bool readReference();
81 bool writeBack(int propertyIndex = QV4::ReferenceObject::AllProperties);
82
83private:
84 void setMetaObject(const QMetaObject *metaObject) { m_metaObject = metaObject; }
85 void setMetaType(QMetaType metaType)
86 {
87 Q_ASSERT(metaType.isValid());
88 m_metaType = metaType.iface();
89 }
90
91 void *m_gadgetPtr;
92 const QtPrivate::QMetaTypeInterface *m_metaType;
93 const QMetaObject *m_metaObject;
94};
95
96}
97
98struct Q_QML_EXPORT QQmlValueTypeWrapper : public ReferenceObject
99{
104
105public:
106
107 static ReturnedValue create(
108 ExecutionEngine *engine, const void *data, const QMetaObject *metaObject,
110 static ReturnedValue create(
112 static ReturnedValue create(
114
115 QVariant toVariant() const;
116
117 template <typename ValueType>
119 {
120 if (QMetaType::fromType<ValueType>() != d()->metaType())
121 return nullptr;
122 if (d()->isReference() && !readReferenceValue())
123 return nullptr;
124 return static_cast<ValueType *>(d()->gadgetPtr());
125 }
126
127 bool toGadget(void *data) const;
128 bool isEqual(const QVariant& value) const;
129 int typeId() const;
130 QMetaType type() const;
131 bool write(QObject *target, int propertyIndex) const;
132 bool readReferenceValue() const { return d()->readReference(); }
133 const QMetaObject *metaObject() const { return d()->metaObject(); }
134
136
138 static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver);
139 static bool virtualIsEqualTo(Managed *m, Managed *other);
140 static bool virtualHasProperty(const Managed *m, PropertyKey id);
143 static ReturnedValue method_toString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
146
147 static void initProto(ExecutionEngine *v4);
148 static int virtualMetacall(Object *object, QMetaObject::Call call, int index, void **a);
149
153};
154
155}
156
157QT_END_NAMESPACE
158
159#endif // QQMLVALUETYPEWRAPPER_P_H
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:23
static Heap::ReferenceObject::Flags referenceFlags(const QMetaObject *metaObject, int index)
static void doStaticReadCall(const QMetaObject *metaObject, Heap::QQmlValueTypeWrapper *valueTypeWrapper, int index, void **args)
#define VALUE_TYPE_LOAD(metatype, cpptype, constructor)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
~QQmlValueTypeWrapperOwnPropertyKeyIterator() override=default