1 | // Copyright (C) 2019 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 QQMLMETAOBJECT_P_H |
5 | #define QQMLMETAOBJECT_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 <private/qqmlpropertycache_p.h> |
19 | |
20 | #include <QtQml/qtqmlglobal.h> |
21 | #include <QtCore/qvarlengtharray.h> |
22 | #include <QtCore/qmetaobject.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | // QQmlMetaObject serves as a wrapper around either QMetaObject or QQmlPropertyCache. |
27 | // This is necessary as we delay creation of QMetaObject for synthesized QObjects, but |
28 | // we don't want to needlessly generate QQmlPropertyCaches every time we encounter a |
29 | // QObject type used in assignment or when we don't have a QQmlEngine etc. |
30 | // |
31 | // This class does NOT reference the propertycache. |
32 | class QQmlEnginePrivate; |
33 | class QQmlPropertyData; |
34 | class Q_QML_EXPORT QQmlMetaObject |
35 | { |
36 | public: |
37 | typedef QVarLengthArray<QMetaType, 9> ArgTypeStorage; |
38 | |
39 | inline QQmlMetaObject() = default; |
40 | inline QQmlMetaObject(const QObject *); |
41 | inline QQmlMetaObject(const QMetaObject *); |
42 | inline QQmlMetaObject(const QQmlPropertyCache::ConstPtr &); |
43 | inline QQmlMetaObject(const QQmlMetaObject &); |
44 | |
45 | inline QQmlMetaObject &operator=(const QQmlMetaObject &); |
46 | |
47 | inline bool isNull() const; |
48 | |
49 | inline const char *className() const; |
50 | inline int propertyCount() const; |
51 | |
52 | inline const QMetaObject *metaObject() const; |
53 | |
54 | QMetaType methodReturnType(const QQmlPropertyData &data, QByteArray *unknownTypeError) const; |
55 | /*! |
56 | \internal |
57 | Returns false if one of the types is unknown. Otherwise, fills \a argstorage with the |
58 | metatypes of the function. |
59 | */ |
60 | bool methodParameterTypes(int index, ArgTypeStorage *argStorage, |
61 | QByteArray *unknownTypeError) const; |
62 | /*! |
63 | \internal |
64 | Returns false if one of the types is unknown. Otherwise, fills \a argstorage with the |
65 | metatypes of the function. |
66 | */ |
67 | bool constructorParameterTypes(int index, ArgTypeStorage *dummy, QByteArray *unknownTypeError) const; |
68 | |
69 | |
70 | static bool canConvert(const QQmlMetaObject &from, const QQmlMetaObject &to) |
71 | { |
72 | Q_ASSERT(!from.isNull() && !to.isNull()); |
73 | return from.metaObject()->inherits(metaObject: to.metaObject()); |
74 | } |
75 | |
76 | // static_metacall (on Gadgets) doesn't call the base implementation and therefore |
77 | // we need a helper to find the correct meta object and property/method index. |
78 | static void resolveGadgetMethodOrPropertyIndex(QMetaObject::Call type, const QMetaObject **metaObject, int *index); |
79 | |
80 | static bool methodParameterTypes(const QMetaMethod &method, ArgTypeStorage *argStorage, |
81 | QByteArray *unknownTypeError); |
82 | protected: |
83 | const QMetaObject *_m = nullptr; |
84 | |
85 | }; |
86 | |
87 | QQmlMetaObject::QQmlMetaObject(const QObject *o) |
88 | { |
89 | if (o) |
90 | _m = o->metaObject(); |
91 | } |
92 | |
93 | QQmlMetaObject::QQmlMetaObject(const QMetaObject *m) |
94 | : _m(m) |
95 | { |
96 | } |
97 | |
98 | QQmlMetaObject::QQmlMetaObject(const QQmlPropertyCache::ConstPtr &m) |
99 | { |
100 | if (m) |
101 | _m = m->createMetaObject(); |
102 | } |
103 | |
104 | QQmlMetaObject::QQmlMetaObject(const QQmlMetaObject &o) |
105 | : _m(o._m) |
106 | { |
107 | } |
108 | |
109 | QQmlMetaObject &QQmlMetaObject::operator=(const QQmlMetaObject &o) |
110 | { |
111 | _m = o._m; |
112 | return *this; |
113 | } |
114 | |
115 | bool QQmlMetaObject::isNull() const |
116 | { |
117 | return !_m; |
118 | } |
119 | |
120 | const char *QQmlMetaObject::className() const |
121 | { |
122 | if (!_m) |
123 | return nullptr; |
124 | return metaObject()->className(); |
125 | } |
126 | |
127 | int QQmlMetaObject::propertyCount() const |
128 | { |
129 | if (!_m) |
130 | return 0; |
131 | return metaObject()->propertyCount(); |
132 | } |
133 | |
134 | const QMetaObject *QQmlMetaObject::metaObject() const |
135 | { |
136 | return _m; |
137 | } |
138 | |
139 | QT_END_NAMESPACE |
140 | |
141 | #endif // QQMLMETAOBJECT_P_H |
142 | |