1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLMETATYPE_P_H
41#define QQMLMETATYPE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <private/qtqmlglobal_p.h>
55#include <private/qqmltype_p.h>
56#include <private/qqmlproxymetaobject_p.h>
57
58QT_BEGIN_NAMESPACE
59
60class QQmlTypeModule;
61class QRecursiveMutex;
62class QQmlError;
63
64namespace QV4 { class ExecutableCompilationUnit; }
65
66class Q_QML_PRIVATE_EXPORT QQmlMetaType
67{
68public:
69 static QQmlType registerType(const QQmlPrivate::RegisterType &type);
70 static QQmlType registerInterface(const QQmlPrivate::RegisterInterface &type);
71 static QQmlType registerSingletonType(const QQmlPrivate::RegisterSingletonType &type);
72 static QQmlType registerCompositeSingletonType(const QQmlPrivate::RegisterCompositeSingletonType &type);
73 static QQmlType registerCompositeType(const QQmlPrivate::RegisterCompositeType &type);
74 static bool registerPluginTypes(QObject *instance, const QString &basePath,
75 const QString &uri, const QString &typeNamespace, int vmaj,
76 QList<QQmlError> *errors);
77 static QQmlType typeForUrl(const QString &urlString, const QHashedStringRef& typeName,
78 bool isCompositeSingleton, QList<QQmlError> *errors,
79 int majorVersion = -1, int minorVersion = -1);
80
81 static void unregisterType(int type);
82
83 static void registerInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit);
84 static void unregisterInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit);
85
86 static void registerModule(const char *uri, int versionMajor, int versionMinor);
87 static bool protectModule(const char *uri, int majVersion);
88
89 static int typeId(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
90
91 static void registerUndeletableType(const QQmlType &dtype);
92
93 static QList<QString> qmlTypeNames();
94 static QList<QQmlType> qmlTypes();
95 static QList<QQmlType> qmlSingletonTypes();
96 static QList<QQmlType> qmlAllTypes();
97
98 enum class TypeIdCategory {
99 MetaType,
100 QmlType
101 };
102
103 static QQmlType qmlType(const QString &qualifiedName, int, int);
104 static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int);
105 static QQmlType qmlType(const QMetaObject *);
106 static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor);
107 static QQmlType qmlType(int typeId, TypeIdCategory category = TypeIdCategory::MetaType);
108 static QQmlType qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports = false);
109
110 static QQmlPropertyCache *propertyCache(const QMetaObject *metaObject, int minorVersion = -1);
111 static QQmlPropertyCache *propertyCache(const QQmlType &type, int minorVersion);
112
113 static void freeUnusedTypesAndCaches();
114
115 static QMetaProperty defaultProperty(const QMetaObject *);
116 static QMetaProperty defaultProperty(QObject *);
117 static QMetaMethod defaultMethod(const QMetaObject *);
118 static QMetaMethod defaultMethod(QObject *);
119
120 static bool isQObject(int);
121 static QObject *toQObject(const QVariant &, bool *ok = nullptr);
122
123 static int listType(int);
124#if QT_DEPRECATED_SINCE(5, 14)
125 static QT_DEPRECATED int attachedPropertiesFuncId(QQmlEnginePrivate *engine,
126 const QMetaObject *);
127 static QT_DEPRECATED QQmlAttachedPropertiesFunc attachedPropertiesFuncById(QQmlEnginePrivate *,
128 int);
129#endif
130 static QQmlAttachedPropertiesFunc attachedPropertiesFunc(QQmlEnginePrivate *,
131 const QMetaObject *);
132
133 enum TypeCategory { Unknown, Object, List };
134 static TypeCategory typeCategory(int);
135
136 static bool isInterface(int);
137 static const char *interfaceIId(int);
138 static bool isList(int);
139
140 typedef QVariant (*StringConverter)(const QString &);
141 static void registerCustomStringConverter(int, StringConverter);
142 static StringConverter customStringConverter(int);
143
144 static bool isAnyModule(const QString &uri);
145 static bool isLockedModule(const QString &uri, int majorVersion);
146 static bool isModule(const QString &module, int versionMajor, int versionMinor);
147 static QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
148
149 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
150
151 enum class CachedUnitLookupError {
152 NoError,
153 NoUnitFound,
154 VersionMismatch
155 };
156
157 static const QV4::CompiledData::Unit *findCachedCompilationUnit(const QUrl &uri, CachedUnitLookupError *status);
158
159 // used by tst_qqmlcachegen.cpp
160 static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
161 static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
162
163 static QRecursiveMutex *typeRegistrationLock();
164
165 static QString prettyTypeName(const QObject *object);
166
167 template <typename QQmlTypeContainer>
168 static void removeQQmlTypePrivate(QQmlTypeContainer &container,
169 const QQmlTypePrivate *reference)
170 {
171 for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) {
172 if (*it == reference)
173 it = container.erase(it);
174 else
175 ++it;
176 }
177 }
178
179 static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent);
180 static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function);
181
182 static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration);
183 static void clearTypeRegistrations();
184
185 static QList<QQmlProxyMetaObject::ProxyData> proxyData(const QMetaObject *mo,
186 const QMetaObject *baseMetaObject,
187 QMetaObject *lastMetaObject);
188
189 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
190 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd);
191};
192
193Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE);
194
195QT_END_NAMESPACE
196
197#endif // QQMLMETATYPE_P_H
198
199