From f3dccc334f01d088fcdf1c2016c8153fe6154b61 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 7 Jan 2020 11:37:01 +0100 Subject: Adapt to the the new QMetaType change Fixes: QTBUG-82453 Change-Id: I7e5682945a07c3af183becd3947a69568f139d16 Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4executablecompilationunit_p.h | 4 +- src/qml/qml/qqml.cpp | 6 +- src/qml/qml/qqml.h | 107 +++++++------------- src/qml/qml/qqmlengine.cpp | 19 ++-- src/qml/qml/qqmlmetatype.cpp | 109 ++++++++++++--------- src/qml/qml/qqmlmetatype_p.h | 8 +- src/qml/qml/qqmlmetatypedata_p.h | 7 +- src/qml/qml/qqmlprivate.h | 40 +++----- src/qml/qml/qqmlpropertycache.cpp | 22 ++--- src/qml/qml/qqmlpropertycachecreator_p.h | 18 ++-- src/qml/qml/qqmltype.cpp | 10 +- src/qml/qml/qqmltype_p.h | 4 +- src/qml/qml/qqmltype_p_p.h | 4 +- src/qml/qml/qqmltypedata.cpp | 3 +- src/qml/qml/qqmltypewrapper.cpp | 8 +- src/qml/qml/qqmlvaluetype_p.h | 6 +- 16 files changed, 163 insertions(+), 212 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h index c080978a87..a748e0a762 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit_p.h +++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h @@ -182,8 +182,8 @@ public: CompositeMetaTypeIds typeIdsForComponent(int objectid = 0) const; - int metaTypeId = -1; - int listMetaTypeId = -1; + QMetaType metaTypeId; + QMetaType listMetaTypeId; bool isRegisteredWithEngine = false; QHash inlineComponentData; diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp index ea6f15e9c2..20dd3827c5 100644 --- a/src/qml/qml/qqml.cpp +++ b/src/qml/qml/qqml.cpp @@ -366,12 +366,10 @@ namespace QQmlPrivate { { using T = QQmlTypeNotAvailable; - QML_GETTYPENAMES - RegisterTypeAndRevisions type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType>(), 0, nullptr, diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index c617f81006..840c6aaee3 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -156,13 +156,11 @@ QQmlCustomParser *qmlCreateCustomParser(); template int qmlRegisterAnonymousType(const char *uri, int versionMajor) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), 0, nullptr, QString(), @@ -199,13 +197,11 @@ int Q_QML_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, template int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType>(), 0, nullptr, reason, @@ -231,13 +227,11 @@ int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMin template int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), 0, nullptr, reason, @@ -263,8 +257,6 @@ int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMin template int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason) { - QML_GETTYPENAMES - QQmlAttachedPropertiesFunc attached = QQmlPrivate::attachedPropertiesFunc(); const QMetaObject * attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject(); if (!attached) { @@ -275,8 +267,8 @@ int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int ve QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), 0, nullptr, reason, @@ -302,8 +294,6 @@ int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int ve template int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason) { - QML_GETTYPENAMES - QQmlAttachedPropertiesFunc attached = QQmlPrivate::attachedPropertiesFunc(); const QMetaObject * attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject(); if (!attached) { @@ -314,8 +304,8 @@ int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int ve QQmlPrivate::RegisterType type = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), 0, nullptr, reason, @@ -343,13 +333,11 @@ Q_QML_EXPORT int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaO template int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -374,13 +362,11 @@ int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const c template int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -405,13 +391,11 @@ int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const c template int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -436,13 +420,11 @@ int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor) template int qmlRegisterExtendedType(const char *uri, int versionMajor) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), 0, nullptr, QString(), @@ -478,8 +460,6 @@ template int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, const char *qmlName) { - QML_GETTYPENAMES - QQmlAttachedPropertiesFunc attached = QQmlPrivate::attachedPropertiesFunc(); const QMetaObject * attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject(); if (!attached) { @@ -490,8 +470,8 @@ int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -526,8 +506,8 @@ int qmlRegisterInterface(const char *typeName) QQmlPrivate::RegisterInterface qmlInterface = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), qobject_interface_iid(), "", @@ -541,12 +521,10 @@ int qmlRegisterInterface(const char *typeName) template int qmlRegisterInterface(const char *uri, int versionMajor) { - QML_GETTYPENAMES - QQmlPrivate::RegisterInterface qmlInterface = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType>(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), qobject_interface_iid(), uri, @@ -560,13 +538,11 @@ template int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, QQmlCustomParser *parser) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -592,13 +568,11 @@ template int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, QQmlCustomParser *parser) { - QML_GETTYPENAMES - QQmlPrivate::RegisterType type = { 1, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -624,8 +598,6 @@ template int qmlRegisterCustomExtendedType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, QQmlCustomParser *parser) { - QML_GETTYPENAMES - QQmlAttachedPropertiesFunc attached = QQmlPrivate::attachedPropertiesFunc(); const QMetaObject * attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject(); if (!attached) { @@ -636,8 +608,8 @@ int qmlRegisterCustomExtendedType(const char *uri, int versionMajor, int version QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType >(), sizeof(T), QQmlPrivate::createInto, QString(), @@ -718,7 +690,7 @@ inline int qmlRegisterSingletonType(const char *uri, int versionMajor, int versi uri, QTypeRevision::fromVersion(versionMajor, versionMinor), typeName, - callback, nullptr, nullptr, 0, QTypeRevision::zero(), {} + callback, nullptr, nullptr, QMetaType(), QTypeRevision::zero(), {} }; return QQmlPrivate::qmlregister(QQmlPrivate::SingletonRegistration, &api); @@ -729,15 +701,13 @@ template inline int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, QObject *(*callback)(QQmlEngine *, QJSEngine *)) { - QML_GETTYPENAMES - QQmlPrivate::RegisterSingletonType api = { QmlCurrentSingletonTypeRegistrationVersion, uri, QTypeRevision::fromVersion(versionMajor, versionMinor), typeName, - nullptr, nullptr, &T::staticMetaObject, qRegisterNormalizedMetaType(pointerName.constData()), - QTypeRevision::zero(), callback + + nullptr, nullptr, &T::staticMetaObject, QMetaType::fromType(), QTypeRevision::zero(), callback }; return QQmlPrivate::qmlregister(QQmlPrivate::SingletonRegistration, &api); @@ -748,16 +718,13 @@ template (pointerName.constData()), - QTypeRevision::zero(), callback + + nullptr, nullptr, &T::staticMetaObject, QMetaType::fromType(), QTypeRevision::zero(), callback }; return QQmlPrivate::qmlregister(QQmlPrivate::SingletonRegistration, &api); @@ -860,8 +827,8 @@ inline void qmlRegisterNamespaceAndRevisions(const QMetaObject *metaObject, { QQmlPrivate::RegisterTypeAndRevisions type = { 0, - 0, - 0, + QMetaType(), + QMetaType(), 0, nullptr, diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 58bdd3da2d..b8b7545ed8 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -112,8 +112,8 @@ int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaObject, QQmlPrivate::RegisterType type = { 0, - 0, - 0, + QMetaType(), + QMetaType(), 0, nullptr, reason, @@ -2344,10 +2344,10 @@ int QQmlEnginePrivate::listType(int t) const static QQmlPropertyCache *propertyCacheForPotentialInlineComponentType(int t, const QHash::const_iterator &iter) { - if (t != (*iter)->metaTypeId) { + if (t != (*iter)->metaTypeId.id()) { // this is an inline component, and what we have in the iterator is currently the parent compilation unit for (auto &&icDatum: (*iter)->inlineComponentData) - if (icDatum.typeIds.id == t) + if (icDatum.typeIds.id.id() == t) return (*iter)->propertyCaches.at(icDatum.objectIndex); } return (*iter)->rootPropertyCache().data(); @@ -2447,10 +2447,9 @@ void QQmlEnginePrivate::registerInternalCompositeType(QV4::ExecutableCompilation Locker locker(this); // The QQmlCompiledData is not referenced here, but it is removed from this // hash in the QQmlCompiledData destructor - m_compositeTypes.insert(compilationUnit->metaTypeId, compilationUnit); - for (auto &&data: compilationUnit->inlineComponentData) { - m_compositeTypes.insert(data.typeIds.id, compilationUnit); - } + m_compositeTypes.insert(compilationUnit->metaTypeId.id(), compilationUnit); + for (auto &&data: compilationUnit->inlineComponentData) + m_compositeTypes.insert(data.typeIds.id.id(), compilationUnit); } void QQmlEnginePrivate::unregisterInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit) @@ -2458,9 +2457,9 @@ void QQmlEnginePrivate::unregisterInternalCompositeType(QV4::ExecutableCompilati compilationUnit->isRegisteredWithEngine = false; Locker locker(this); - m_compositeTypes.remove(compilationUnit->metaTypeId); + m_compositeTypes.remove(compilationUnit->metaTypeId.id()); for (auto&& icDatum: compilationUnit->inlineComponentData) - m_compositeTypes.remove(icDatum.typeIds.id); + m_compositeTypes.remove(icDatum.typeIds.id.id()); } QV4::ExecutableCompilationUnit *QQmlEnginePrivate::obtainExecutableCompilationUnit(int typeId) diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 0baf142913..68b95d1cc3 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -352,15 +352,12 @@ QQmlType QQmlMetaType::registerInterface(const QQmlPrivate::RegisterInterface &t QQmlTypePrivate *priv = createQQmlType(data, type); Q_ASSERT(priv); - data->idToType.insert(priv->typeId, priv); - data->idToType.insert(priv->listId, priv); - if (data->interfaces.size() <= type.typeId) - data->interfaces.resize(type.typeId + 16); - if (data->lists.size() <= type.listId) - data->lists.resize(type.listId + 16); - data->interfaces.setBit(type.typeId, true); - data->lists.setBit(type.listId, true); + data->idToType.insert(priv->typeId.id(), priv); + data->idToType.insert(priv->listId.id(), priv); + + data->interfaces.insert(type.typeId.id()); + data->lists.insert(type.listId.id()); return QQmlType(priv); } @@ -441,18 +438,14 @@ void addTypeToData(QQmlTypePrivate *type, QQmlMetaTypeData *data) if (type->baseMetaObject) data->metaObjectToType.insert(type->baseMetaObject, type); - if (type->typeId) { - data->idToType.insert(type->typeId, type); - if (data->objects.size() <= type->typeId) - data->objects.resize(type->typeId + 16); - data->objects.setBit(type->typeId, true); + if (type->typeId.isValid()) { + data->idToType.insert(type->typeId.id(), type); + data->objects.insert(type->typeId.id()); } - if (type->listId) { - if (data->lists.size() <= type->listId) - data->lists.resize(type->listId + 16); - data->lists.setBit(type->listId, true); - data->idToType.insert(type->listId, type); + if (type->listId.isValid()) { + data->idToType.insert(type->listId.id(), type); + data->lists.insert(type->listId.id()); } if (!type->module.isEmpty()) { @@ -475,8 +468,8 @@ QQmlType QQmlMetaType::registerType(const QQmlPrivate::RegisterType &type) QQmlTypePrivate *priv = createQQmlType(data, elementName, type); addTypeToData(priv, data); - if (!type.typeId) - data->idToType.insert(priv->typeId, priv); + if (!type.typeId.isValid()) + data->idToType.insert(priv->typeId.id(), priv); return QQmlType(priv); } @@ -540,26 +533,50 @@ QQmlType QQmlMetaType::registerCompositeType(const QQmlPrivate::RegisterComposit return QQmlType(priv); } + + +template +struct QQmlMetaTypeInterface : QtPrivate::QMetaTypeInterface +{ + const QByteArray name; + QQmlMetaTypeInterface(const QByteArray &name) + : QMetaTypeInterface { + /*.revision=*/ 0, + /*.size=*/ sizeof(T), + /*.alignment=*/ alignof(T), + /*.flags=*/ QtPrivate::QMetaTypeTypeFlags::Flags, + /*.metaObject=*/ nullptr, + /*.name=*/ name.constData(), + /*.typeId=*/ 0, + /*.ref=*/ Q_REFCOUNT_INITIALIZE_STATIC, + /*.deleteSelf=*/ [](QMetaTypeInterface *self) { + delete static_cast(self); + }, + /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) { new (addr) T(); }, + /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) { + new (addr) T(*reinterpret_cast(other)); + }, + /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) { + new (addr) T(std::move(*reinterpret_cast(other))); + }, + /*.dtor=*/ [](const QMetaTypeInterface *, void *addr) { + reinterpret_cast(addr)->~T(); + }, + /*.legacyRegisterOp=*/ nullptr + } + , name(name) { } +}; + CompositeMetaTypeIds QQmlMetaType::registerInternalCompositeType(const QByteArray &className) { QByteArray ptr = className + '*'; QByteArray lst = "QQmlListProperty<" + className + '>'; - int ptr_type = QMetaType::registerNormalizedType(ptr, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper::Construct, - sizeof(QObject*), - static_cast >(QtPrivate::QMetaTypeTypeFlags::Flags), - nullptr); - int lst_type = QMetaType::registerNormalizedType(lst, - QtMetaTypePrivate::QMetaTypeFunctionHelper >::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper >::Construct, - sizeof(QQmlListProperty), - static_cast >(QtPrivate::QMetaTypeTypeFlags >::Flags), - static_cast(nullptr)); + QMetaType ptr_type(new QQmlMetaTypeInterface(ptr)); + QMetaType lst_type(new QQmlMetaTypeInterface>(lst)); QQmlMetaTypeDataPtr data; - data->qmlLists.insert(lst_type, ptr_type); + data->qmlLists.insert(lst_type.id(), ptr_type.id()); return {ptr_type, lst_type}; } @@ -567,10 +584,7 @@ CompositeMetaTypeIds QQmlMetaType::registerInternalCompositeType(const QByteArra void QQmlMetaType::unregisterInternalCompositeType(const CompositeMetaTypeIds &typeIds) { QQmlMetaTypeDataPtr data; - data->qmlLists.remove(typeIds.listId); - - QMetaType::unregisterType(typeIds.id); - QMetaType::unregisterType(typeIds.listId); + data->qmlLists.remove(typeIds.listId.id()); } int QQmlMetaType::registerUnitCacheHook( @@ -915,9 +929,8 @@ bool QQmlMetaType::isQObject(int userType) { if (userType == QMetaType::QObjectStar) return true; - QQmlMetaTypeDataPtr data; - return userType >= 0 && userType < data->objects.size() && data->objects.testBit(userType); + return data->objects.contains(userType); } /* @@ -930,8 +943,8 @@ int QQmlMetaType::listType(int id) if (iter != data->qmlLists.cend()) return *iter; QQmlTypePrivate *type = data->idToType.value(id); - if (type && type->listId == id) - return type->typeId; + if (type && type->listId.id() == id) + return type->typeId.id(); else return 0; } @@ -1031,9 +1044,9 @@ QQmlMetaType::TypeCategory QQmlMetaType::typeCategory(int userType) QQmlMetaTypeDataPtr data; if (data->qmlLists.contains(userType)) return List; - else if (userType < data->objects.size() && data->objects.testBit(userType)) + else if (data->objects.contains(userType)) return Object; - else if (userType < data->lists.size() && data->lists.testBit(userType)) + else if (data->lists.contains(userType)) return List; else return Unknown; @@ -1045,7 +1058,7 @@ QQmlMetaType::TypeCategory QQmlMetaType::typeCategory(int userType) bool QQmlMetaType::isInterface(int userType) { const QQmlMetaTypeDataPtr data; - return userType >= 0 && userType < data->interfaces.size() && data->interfaces.testBit(userType); + return data->interfaces.contains(userType); } const char *QQmlMetaType::interfaceIId(int userType) @@ -1058,7 +1071,7 @@ const char *QQmlMetaType::interfaceIId(int userType) } QQmlType type(typePrivate); - if (type.isInterface() && type.typeId() == userType) + if (type.isInterface() && type.typeId().id() == userType) return type.interfaceIId(); else return nullptr; @@ -1066,10 +1079,10 @@ const char *QQmlMetaType::interfaceIId(int userType) bool QQmlMetaType::isList(int userType) { - const QQmlMetaTypeDataPtr data; + QQmlMetaTypeDataPtr data; if (data->qmlLists.contains(userType)) return true; - return userType >= 0 && userType < data->lists.size() && data->lists.testBit(userType); + return data->lists.contains(userType); } /*! @@ -1185,7 +1198,7 @@ QQmlType QQmlMetaType::qmlType(int typeId, TypeIdCategory category) if (category == TypeIdCategory::MetaType) { QQmlTypePrivate *type = data->idToType.value(typeId); - if (type && type->typeId == typeId) + if (type && type->typeId.id() == typeId) return QQmlType(type); } else if (category == TypeIdCategory::QmlType) { QQmlType type = data->types.value(typeId); diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 0fc179fd34..28d647520d 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -65,11 +65,9 @@ namespace QV4 { class ExecutableCompilationUnit; } struct CompositeMetaTypeIds { - int id = -1; - int listId = -1; - CompositeMetaTypeIds() = default; - CompositeMetaTypeIds(int id, int listId) : id(id), listId(listId) {} - bool isValid() const { return id != -1 && listId != -1; } + QMetaType id; + QMetaType listId; + bool isValid() const { return id.isValid() && listId.isValid(); } }; class Q_QML_PRIVATE_EXPORT QQmlMetaType diff --git a/src/qml/qml/qqmlmetatypedata_p.h b/src/qml/qml/qqmlmetatypedata_p.h index 26fc566653..322ead084a 100644 --- a/src/qml/qml/qqmlmetatypedata_p.h +++ b/src/qml/qml/qqmlmetatypedata_p.h @@ -57,7 +57,6 @@ #include #include -#include QT_BEGIN_NAMESPACE @@ -102,9 +101,9 @@ struct QQmlMetaTypeData QHash moduleTypeRegistrationFunctions; bool registerModuleTypes(const QString &uri); - QBitArray objects; - QBitArray interfaces; - QBitArray lists; + QSet interfaces; + QSet objects; + QSet lists; QList parentFunctions; QVector lookupCachedQmlUnit; diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h index 2e4bc60f79..8a1cbc2ddf 100644 --- a/src/qml/qml/qqmlprivate.h +++ b/src/qml/qml/qqmlprivate.h @@ -68,20 +68,6 @@ #include #include -#define QML_GETTYPENAMES \ - const char *className = T::staticMetaObject.className(); \ - const int nameLen = int(strlen(className)); \ - QVarLengthArray pointerName(nameLen+2); \ - memcpy(pointerName.data(), className, size_t(nameLen)); \ - pointerName[nameLen] = '*'; \ - pointerName[nameLen+1] = '\0'; \ - const int listLen = int(strlen("QQmlListProperty<")); \ - QVarLengthArray listName(listLen + nameLen + 2); \ - memcpy(listName.data(), "QQmlListProperty<", size_t(listLen)); \ - memcpy(listName.data()+listLen, className, size_t(nameLen)); \ - listName[listLen+nameLen] = '>'; \ - listName[listLen+nameLen+1] = '\0'; - QT_BEGIN_NAMESPACE class QQmlPropertyValueInterceptor; @@ -346,8 +332,8 @@ namespace QQmlPrivate struct RegisterType { int structVersion; - int typeId; - int listId; + QMetaType typeId; + QMetaType listId; int objectSize; void (*create)(void *); QString noCreationReason; @@ -376,8 +362,8 @@ namespace QQmlPrivate struct RegisterTypeAndRevisions { int structVersion; - int typeId; - int listId; + QMetaType typeId; + QMetaType listId; int objectSize; void (*create)(void *); @@ -403,8 +389,8 @@ namespace QQmlPrivate struct RegisterInterface { int structVersion; - int typeId; - int listId; + QMetaType typeId; + QMetaType listId; const char *iid; @@ -428,7 +414,7 @@ namespace QQmlPrivate QJSValue (*scriptApi)(QQmlEngine *, QJSEngine *); QObject *(*qobjectApi)(QQmlEngine *, QJSEngine *); const QMetaObject *instanceMetaObject; // new in version 1 - int typeId; // new in version 2 + QMetaType typeId; // new in version 2 QTypeRevision revision; // new in version 2 std::function generalizedQobjectApi; // new in version 3 // If this is extended ensure "version" is bumped!!! @@ -443,7 +429,7 @@ namespace QQmlPrivate const QMetaObject *instanceMetaObject; const QMetaObject *classInfoMetaObject; - int typeId; + QMetaType typeId; std::function generalizedQobjectApi; // new in version 3 }; @@ -598,8 +584,6 @@ namespace QQmlPrivate void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject) { - QML_GETTYPENAMES - RegisterSingletonTypeAndRevisions api = { 0, @@ -611,7 +595,7 @@ namespace QQmlPrivate &T::staticMetaObject, classInfoMetaObject, - qRegisterNormalizedMetaType(pointerName.constData()), + QMetaType::fromType(), Constructors::createSingletonInstance }; @@ -622,12 +606,10 @@ namespace QQmlPrivate void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject) { - QML_GETTYPENAMES - RegisterTypeAndRevisions type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), - qRegisterNormalizedMetaType >(listName.constData()), + QMetaType::fromType(), + QMetaType::fromType>(), int(sizeof(T)), Constructors::createInto, diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 7ba3d7b813..09e16fdbe0 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -83,13 +83,11 @@ static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p) return flags; } -// Flags that do depend on the property's QMetaProperty::userType() and thus are slow to -// load -static void flagsForPropertyType(int propType, QQmlPropertyData::Flags &flags) +// Flags that do depend on the property's QMetaType +static void flagsForPropertyType(QMetaType metaType, QQmlPropertyData::Flags &flags) { - Q_ASSERT(propType != -1); - - if (propType == QMetaType::QObjectStar) { + int propType = metaType.id(); + if (metaType.flags() & QMetaType::PointerToQObject) { flags.type = QQmlPropertyData::Flags::QObjectDerivedType; } else if (propType == QMetaType::QVariant) { flags.type = QQmlPropertyData::Flags::QVariantType; @@ -101,8 +99,7 @@ static void flagsForPropertyType(int propType, QQmlPropertyData::Flags &flags) flags.type = QQmlPropertyData::Flags::QJSValueType; } else { QQmlMetaType::TypeCategory cat = QQmlMetaType::typeCategory(propType); - - if (cat == QQmlMetaType::Object || QMetaType::typeFlags(propType) & QMetaType::PointerToQObject) + if (cat == QQmlMetaType::Object) flags.type = QQmlPropertyData::Flags::QObjectDerivedType; else if (cat == QQmlMetaType::List) flags.type = QQmlPropertyData::Flags::QListType; @@ -121,7 +118,7 @@ QQmlPropertyData::Flags QQmlPropertyData::flagsForProperty(const QMetaProperty &p) { auto flags = fastFlagsForProperty(p); - flagsForPropertyType(p.userType(), flags); + flagsForPropertyType(p.metaType(), flags); return flags; } @@ -154,8 +151,9 @@ void QQmlPropertyData::lazyLoad(const QMetaProperty &p) void QQmlPropertyData::load(const QMetaProperty &p) { populate(this, p); - setPropType(p.userType()); - flagsForPropertyType(propType(), m_flags); + QMetaType type = p.metaType(); + setPropType(type.id()); + flagsForPropertyType(type, m_flags); } void QQmlPropertyData::load(const QMetaMethod &m) @@ -687,7 +685,7 @@ void QQmlPropertyCache::resolve(QQmlPropertyData *data) const data->setPropType(registerResult == -1 ? QMetaType::UnknownType : registerResult); } } - flagsForPropertyType(data->propType(), data->m_flags); + flagsForPropertyType(QMetaType(data->propType()), data->m_flags); } } diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 2d99ea9fd5..cadbfdd481 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -591,15 +591,15 @@ inline QQmlError QQmlPropertyCacheCreator::createMetaObject(int } if (p->isList) { - propertyType = typeIds.listId; + propertyType = typeIds.listId.id(); } else { - propertyType = typeIds.id; + propertyType = typeIds.id.id(); } } else { if (p->isList) { - propertyType = qmltype.qListTypeId(); + propertyType = qmltype.qListTypeId().id(); } else { - propertyType = qmltype.typeId(); + propertyType = qmltype.typeId().id(); propertyTypeVersion = qmltype.version(); } } @@ -647,10 +647,10 @@ inline int QQmlPropertyCacheCreator::metaTypeForParameter(const return QMetaType::UnknownType; if (!qmltype.isComposite()) - return qmltype.typeId(); + return qmltype.typeId().id(); if (selfReference) - return objectContainer->typeIdsForComponent().id; + return objectContainer->typeIdsForComponent().id.id(); QQmlRefPointer tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl()); Q_ASSERT(tdata); @@ -658,7 +658,7 @@ inline int QQmlPropertyCacheCreator::metaTypeForParameter(const auto compilationUnit = tdata->compilationUnit(); - return compilationUnit->metaTypeId; + return compilationUnit->metaTypeId.id(); } template @@ -840,9 +840,9 @@ inline QQmlError QQmlPropertyCacheAliasCreator::propertyDataFor } if (typeRef->type.isValid()) - *type = typeRef->type.typeId(); + *type = typeRef->type.typeId().id(); else - *type = typeRef->compilationUnit->metaTypeId; + *type = typeRef->compilationUnit->metaTypeId.id(); *version = typeRef->version; diff --git a/src/qml/qml/qqmltype.cpp b/src/qml/qml/qqmltype.cpp index 047da376c6..db22c93733 100644 --- a/src/qml/qml/qqmltype.cpp +++ b/src/qml/qml/qqmltype.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QQmlTypePrivate::QQmlTypePrivate(QQmlType::RegistrationType type) - : regType(type), iid(nullptr), typeId(0), listId(0), revision(QTypeRevision::zero()), + : regType(type), iid(nullptr), revision(QTypeRevision::zero()), containsRevisionedAttributes(false), baseMetaObject(nullptr), index(-1), isSetup(false), isEnumFromCacheSetup(false), isEnumFromBaseSetup(false), haveSuperType(false) @@ -587,14 +587,14 @@ bool QQmlType::isQJSValueSingleton() const return d && d->regType == SingletonType && d->extraData.sd->singletonInstanceInfo->scriptCallback; } -int QQmlType::typeId() const +QMetaType QQmlType::typeId() const { - return d ? d->typeId : -1; + return d ? d->typeId : QMetaType{}; } -int QQmlType::qListTypeId() const +QMetaType QQmlType::qListTypeId() const { - return d ? d->listId : -1; + return d ? d->listId : QMetaType{}; } const QMetaObject *QQmlType::metaObject() const diff --git a/src/qml/qml/qqmltype_p.h b/src/qml/qml/qqmltype_p.h index c33cad7c88..2b37ec16be 100644 --- a/src/qml/qml/qqmltype_p.h +++ b/src/qml/qml/qqmltype_p.h @@ -124,8 +124,8 @@ public: bool isQObjectSingleton() const; bool isQJSValueSingleton() const; - int typeId() const; - int qListTypeId() const; + QMetaType typeId() const; + QMetaType qListTypeId() const; const QMetaObject *metaObject() const; const QMetaObject *baseMetaObject() const; diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h index 0d493c4871..c94ac8c130 100644 --- a/src/qml/qml/qqmltype_p_p.h +++ b/src/qml/qml/qqmltype_p_p.h @@ -157,8 +157,8 @@ public: QHashedString module; QString name; QString elementName; - int typeId; - int listId; + QMetaType typeId; + QMetaType listId; QTypeRevision version; QTypeRevision revision; mutable bool containsRevisionedAttributes; diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index 9d44e85ba4..7b21edec37 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -934,7 +934,8 @@ QQmlError QQmlTypeData::buildTypeResolutionCaches( ref->type = qmlType; if (qmlType.isValid()) { // this is required for inline components in singletons - auto typeID = qmlType.lookupInlineComponentById(qmlType.inlineComponendId()).typeId(); + auto type = qmlType.lookupInlineComponentById(qmlType.inlineComponendId()).typeId(); + auto typeID = type.isValid() ? type.id() : -1; auto exUnit = engine->obtainExecutableCompilationUnit(typeID); if (exUnit) { ref->compilationUnit = exUnit; diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index fa5d36503d..7bcc5e9900 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -407,9 +407,9 @@ ReturnedValue QQmlTypeWrapper::virtualInstanceOf(const Object *typeObject, const if (!wrapperObject) return engine->throwTypeError(); - const int myTypeId = typeWrapper->d()->type().typeId(); + const QMetaType myTypeId = typeWrapper->d()->type().typeId(); QQmlMetaObject myQmlType; - if (myTypeId == 0) { + if (!myTypeId.isValid()) { // we're a composite type; a composite type cannot be equal to a // non-composite object instance (Rectangle{} is never an instance of // CustomRectangle) @@ -420,9 +420,9 @@ ReturnedValue QQmlTypeWrapper::virtualInstanceOf(const Object *typeObject, const QQmlRefPointer td = qenginepriv->typeLoader.getType(typeWrapper->d()->type().sourceUrl()); ExecutableCompilationUnit *cu = td->compilationUnit(); - myQmlType = qenginepriv->metaObjectForType(cu->metaTypeId); + myQmlType = qenginepriv->metaObjectForType(cu->metaTypeId.id()); } else { - myQmlType = qenginepriv->metaObjectForType(myTypeId); + myQmlType = qenginepriv->metaObjectForType(myTypeId.id()); } const QMetaObject *theirType = wrapperObject->metaObject(); diff --git a/src/qml/qml/qqmlvaluetype_p.h b/src/qml/qml/qqmlvaluetype_p.h index e716f79ae3..0b38c746d6 100644 --- a/src/qml/qml/qqmlvaluetype_p.h +++ b/src/qml/qml/qqmlvaluetype_p.h @@ -310,14 +310,10 @@ public: template int qmlRegisterValueTypeEnums(const char *uri, int versionMajor, int versionMinor, const char *qmlName) { - QByteArray name(T::staticMetaObject.className()); - - QByteArray pointerName(name + '*'); - QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType(pointerName.constData()), 0, 0, nullptr, + QMetaType::fromType(), QMetaType(), 0, nullptr, QString(), -- cgit v1.2.3