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 QQMLMETATYPEDATA_P_H
5#define QQMLMETATYPEDATA_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/qqmltype_p.h>
19#include <private/qqmlmetatype_p.h>
20#include <private/qhashedstring_p.h>
21#include <private/qqmlvaluetype_p.h>
22
23#include <QtCore/qset.h>
24#include <QtCore/qvector.h>
25
26QT_BEGIN_NAMESPACE
27
28struct InlineComponentKey
29{
30 const QQmlTypePrivate *containingType = nullptr;
31 QString name;
32
33private:
34 friend bool operator==(const InlineComponentKey &a, const InlineComponentKey &b)
35 {
36 return a.containingType == b.containingType && a.name == b.name;
37 }
38
39 friend size_t qHash(const InlineComponentKey &byId, size_t seed = 0)
40 {
41 return qHashMulti(seed, args: byId.containingType, args: byId.name);
42 }
43};
44
45class QQmlTypePrivate;
46struct QQmlMetaTypeData
47{
48 QQmlMetaTypeData();
49 ~QQmlMetaTypeData();
50 void registerType(QQmlTypePrivate *priv);
51 QList<QQmlType> types;
52 QSet<QQmlType> undeletableTypes;
53 typedef QHash<int, QQmlTypePrivate *> Ids;
54 Ids idToType;
55
56 using Names = QMultiHash<QHashedString, const QQmlTypePrivate *>;
57 Names nameToType;
58
59 typedef QHash<QUrl, QQmlTypePrivate *> Files; //For file imported composite types only
60 Files urlToType;
61 Files urlToNonFileImportType; // For non-file imported composite and composite
62 // singleton types. This way we can locate any
63 // of them by url, even if it was registered as
64 // a module via QQmlPrivate::RegisterCompositeType
65 typedef QMultiHash<const QMetaObject *, QQmlTypePrivate *> MetaObjects;
66 MetaObjects metaObjectToType;
67 QVector<QHash<QTypeRevision, QQmlPropertyCache::ConstPtr>> typePropertyCaches;
68 QHash<int, QQmlValueType *> metaTypeToValueType;
69 QHash<const QtPrivate::QMetaTypeInterface *, QV4::ExecutableCompilationUnit *> compositeTypes;
70 QHash<InlineComponentKey, QQmlType> inlineComponentTypes;
71
72 struct VersionedUri {
73 VersionedUri() = default;
74 VersionedUri(const QString &uri, QTypeRevision version)
75 : uri(uri), majorVersion(version.majorVersion()) {}
76 VersionedUri(const std::unique_ptr<QQmlTypeModule> &module);
77
78 friend bool operator==(const VersionedUri &a, const VersionedUri &b)
79 {
80 return a.majorVersion == b.majorVersion && a.uri == b.uri;
81 }
82
83 friend size_t qHash(const VersionedUri &v, size_t seed = 0)
84 {
85 return qHashMulti(seed, args: v.uri, args: v.majorVersion);
86 }
87
88 friend bool operator<(const QQmlMetaTypeData::VersionedUri &a,
89 const QQmlMetaTypeData::VersionedUri &b)
90 {
91 const int diff = a.uri.compare(s: b.uri);
92 return diff < 0 || (diff == 0 && a.majorVersion < b.majorVersion);
93 }
94
95 QString uri;
96 quint8 majorVersion = 0;
97 };
98
99 typedef std::vector<std::unique_ptr<QQmlTypeModule>> TypeModules;
100 TypeModules uriToModule;
101 QQmlTypeModule *findTypeModule(const QString &module, QTypeRevision version);
102 QQmlTypeModule *addTypeModule(std::unique_ptr<QQmlTypeModule> module);
103
104 using ModuleImports = QMultiMap<VersionedUri, QQmlDirParser::Import>;
105 ModuleImports moduleImports;
106
107 QHash<QString, void (*)()> moduleTypeRegistrationFunctions;
108 bool registerModuleTypes(const QString &uri);
109
110 QSet<int> interfaces;
111
112 QList<QQmlPrivate::AutoParentFunction> parentFunctions;
113 QVector<QQmlPrivate::QmlUnitCacheLookupFunction> lookupCachedQmlUnit;
114
115 QHash<const QMetaObject *, QQmlPropertyCache::ConstPtr> propertyCaches;
116
117 QQmlPropertyCache::ConstPtr propertyCacheForVersion(int index, QTypeRevision version) const;
118 void setPropertyCacheForVersion(
119 int index, QTypeRevision version, const QQmlPropertyCache::ConstPtr &cache);
120 void clearPropertyCachesForVersion(int index);
121
122 QQmlPropertyCache::ConstPtr propertyCache(const QMetaObject *metaObject, QTypeRevision version);
123 QQmlPropertyCache::ConstPtr propertyCache(const QQmlType &type, QTypeRevision version);
124 QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t) const;
125
126 void setTypeRegistrationFailures(QStringList *failures)
127 {
128 m_typeRegistrationFailures = failures;
129 }
130
131 void recordTypeRegFailure(const QString &message)
132 {
133 if (m_typeRegistrationFailures)
134 m_typeRegistrationFailures->append(t: message);
135 else
136 qWarning(msg: "%s", message.toUtf8().constData());
137 }
138
139private:
140 QStringList *m_typeRegistrationFailures = nullptr;
141};
142
143QT_END_NAMESPACE
144
145#endif // QQMLMETATYPEDATA_P_H
146

source code of qtdeclarative/src/qml/qml/qqmlmetatypedata_p.h