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