| 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 | |
| 58 | QT_BEGIN_NAMESPACE |
| 59 | |
| 60 | class QQmlTypeModule; |
| 61 | class QRecursiveMutex; |
| 62 | class QQmlError; |
| 63 | |
| 64 | namespace QV4 { class ExecutableCompilationUnit; } |
| 65 | |
| 66 | struct CompositeMetaTypeIds |
| 67 | { |
| 68 | int id = -1; |
| 69 | int listId = -1; |
| 70 | CompositeMetaTypeIds() = default; |
| 71 | CompositeMetaTypeIds(int id, int listId) : id(id), listId(listId) {} |
| 72 | bool isValid() const { return id != -1 && listId != -1; } |
| 73 | }; |
| 74 | |
| 75 | class Q_QML_PRIVATE_EXPORT QQmlMetaType |
| 76 | { |
| 77 | public: |
| 78 | static QQmlType registerType(const QQmlPrivate::RegisterType &type); |
| 79 | static QQmlType registerInterface(const QQmlPrivate::RegisterInterface &type); |
| 80 | static QQmlType registerSingletonType(const QQmlPrivate::RegisterSingletonType &type); |
| 81 | static QQmlType registerCompositeSingletonType(const QQmlPrivate::RegisterCompositeSingletonType &type); |
| 82 | static QQmlType registerCompositeType(const QQmlPrivate::RegisterCompositeType &type); |
| 83 | static bool registerPluginTypes(QObject *instance, const QString &basePath, |
| 84 | const QString &uri, const QString &typeNamespace, int vmaj, |
| 85 | QList<QQmlError> *errors); |
| 86 | static QQmlType typeForUrl(const QString &urlString, const QHashedStringRef& typeName, |
| 87 | bool isCompositeSingleton, QList<QQmlError> *errors, |
| 88 | int majorVersion = -1, int minorVersion = -1); |
| 89 | |
| 90 | static void unregisterType(int type); |
| 91 | |
| 92 | static CompositeMetaTypeIds registerInternalCompositeType(const QByteArray &className); |
| 93 | static void unregisterInternalCompositeType(const CompositeMetaTypeIds &typeIds); |
| 94 | static void registerModule(const char *uri, int versionMajor, int versionMinor); |
| 95 | static bool protectModule(const QString &uri, int majVersion); |
| 96 | |
| 97 | static int typeId(const char *uri, int versionMajor, int versionMinor, const char *qmlName); |
| 98 | |
| 99 | static void registerUndeletableType(const QQmlType &dtype); |
| 100 | |
| 101 | static QList<QString> qmlTypeNames(); |
| 102 | static QList<QQmlType> qmlTypes(); |
| 103 | static QList<QQmlType> qmlSingletonTypes(); |
| 104 | static QList<QQmlType> qmlAllTypes(); |
| 105 | |
| 106 | enum class TypeIdCategory { |
| 107 | MetaType, |
| 108 | QmlType |
| 109 | }; |
| 110 | |
| 111 | static QQmlType qmlType(const QString &qualifiedName, int, int); |
| 112 | static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int); |
| 113 | static QQmlType qmlType(const QMetaObject *); |
| 114 | static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor); |
| 115 | static QQmlType qmlType(int typeId, TypeIdCategory category = TypeIdCategory::MetaType); |
| 116 | static QQmlType qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports = false); |
| 117 | |
| 118 | static QQmlPropertyCache *propertyCache(const QMetaObject *metaObject, int minorVersion = -1, bool doRef = false); |
| 119 | static QQmlPropertyCache *propertyCache(const QQmlType &type, int minorVersion); |
| 120 | |
| 121 | static void freeUnusedTypesAndCaches(); |
| 122 | |
| 123 | static QMetaProperty defaultProperty(const QMetaObject *); |
| 124 | static QMetaProperty defaultProperty(QObject *); |
| 125 | static QMetaMethod defaultMethod(const QMetaObject *); |
| 126 | static QMetaMethod defaultMethod(QObject *); |
| 127 | |
| 128 | static bool isQObject(int); |
| 129 | static QObject *toQObject(const QVariant &, bool *ok = nullptr); |
| 130 | |
| 131 | static int listType(int); |
| 132 | #if QT_DEPRECATED_SINCE(5, 14) |
| 133 | static QT_DEPRECATED int attachedPropertiesFuncId(QQmlEnginePrivate *engine, |
| 134 | const QMetaObject *); |
| 135 | static QT_DEPRECATED QQmlAttachedPropertiesFunc attachedPropertiesFuncById(QQmlEnginePrivate *, |
| 136 | int); |
| 137 | #endif |
| 138 | static QQmlAttachedPropertiesFunc attachedPropertiesFunc(QQmlEnginePrivate *, |
| 139 | const QMetaObject *); |
| 140 | |
| 141 | enum TypeCategory { Unknown, Object, List }; |
| 142 | static TypeCategory typeCategory(int); |
| 143 | |
| 144 | static bool isInterface(int); |
| 145 | static const char *interfaceIId(int); |
| 146 | static bool isList(int); |
| 147 | |
| 148 | typedef QVariant (*StringConverter)(const QString &); |
| 149 | static void registerCustomStringConverter(int, StringConverter); |
| 150 | static StringConverter customStringConverter(int); |
| 151 | |
| 152 | static bool isAnyModule(const QString &uri); |
| 153 | static bool isLockedModule(const QString &uri, int majorVersion); |
| 154 | static bool isModule(const QString &module, int versionMajor, int versionMinor); |
| 155 | static QQmlTypeModule *typeModule(const QString &uri, int majorVersion); |
| 156 | |
| 157 | static QList<QQmlPrivate::AutoParentFunction> parentFunctions(); |
| 158 | |
| 159 | enum class CachedUnitLookupError { |
| 160 | NoError, |
| 161 | NoUnitFound, |
| 162 | VersionMismatch |
| 163 | }; |
| 164 | |
| 165 | static const QV4::CompiledData::Unit *findCachedCompilationUnit(const QUrl &uri, CachedUnitLookupError *status); |
| 166 | |
| 167 | // used by tst_qqmlcachegen.cpp |
| 168 | static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler); |
| 169 | static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler); |
| 170 | |
| 171 | static QRecursiveMutex *typeRegistrationLock(); |
| 172 | |
| 173 | static QString prettyTypeName(const QObject *object); |
| 174 | |
| 175 | template <typename QQmlTypeContainer> |
| 176 | static void removeQQmlTypePrivate(QQmlTypeContainer &container, |
| 177 | const QQmlTypePrivate *reference) |
| 178 | { |
| 179 | for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) { |
| 180 | if (*it == reference) |
| 181 | it = container.erase(it); |
| 182 | else |
| 183 | ++it; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent); |
| 188 | static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function); |
| 189 | |
| 190 | static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration); |
| 191 | static void clearTypeRegistrations(); |
| 192 | |
| 193 | static QList<QQmlProxyMetaObject::ProxyData> proxyData(const QMetaObject *mo, |
| 194 | const QMetaObject *baseMetaObject, |
| 195 | QMetaObject *lastMetaObject); |
| 196 | |
| 197 | static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo, |
| 198 | const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd); |
| 199 | |
| 200 | static void qmlInsertModuleRegistration(const QString &uri, int majorVersion, |
| 201 | void (*registerFunction)()); |
| 202 | static void qmlRemoveModuleRegistration(const QString &uri, int majorVersion); |
| 203 | |
| 204 | static bool qmlRegisterModuleTypes(const QString &uri, int majorVersion); |
| 205 | |
| 206 | static int qmlRegisteredListTypeCount(); |
| 207 | }; |
| 208 | |
| 209 | Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE); |
| 210 | |
| 211 | QT_END_NAMESPACE |
| 212 | |
| 213 | #endif // QQMLMETATYPE_P_H |
| 214 | |
| 215 | |