From 1697fbdf05ff643d617a9ba1614454926e86a3d9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 4 Aug 2020 10:35:46 +0200 Subject: Deprecate the static int based API in QMetaType And remove one of the type id to name mapping that still existed in QMetaType. QMetaTypeInterface can provide that, so there's no need to have a second copy of the data. qMetaTypeTypeInternal() can still map all the names of all builtin types to ids. That functionality is for now still required by moc and can't be removed yet. Change-Id: Ib4f8e9c71e1e7d99d52da9e44477c9a1f1805e57 Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetatype.h | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'src/corelib/kernel/qmetatype.h') diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index cbf1e19187..ba4f2e8050 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -363,18 +363,39 @@ public: static void registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type); - static int type(const char *typeName); - - static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName); - static const char *typeName(int type); - static int sizeOf(int type); - static TypeFlags typeFlags(int type); - static const QMetaObject *metaObjectForType(int type); +#if QT_DEPRECATED_SINCE(6, 0) + QT_DEPRECATED_VERSION_6_0 + static int type(const char *typeName) + { return QMetaType::fromName(typeName).id(); } + QT_DEPRECATED_VERSION_6_0 + static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName) + { return QMetaType::fromName(typeName).id(); } + QT_DEPRECATED_VERSION_6_0 + static const char *typeName(int type) + { return QMetaType(type).name(); } + QT_DEPRECATED_VERSION_6_0 + static int sizeOf(int type) + { return QMetaType(type).sizeOf(); } + QT_DEPRECATED_VERSION_6_0 + static TypeFlags typeFlags(int type) + { return QMetaType(type).flags(); } + QT_DEPRECATED_VERSION_6_0 + static const QMetaObject *metaObjectForType(int type) + { return QMetaType(type).metaObject(); } + QT_DEPRECATED_VERSION_6_0 + static void *create(int type, const void *copy = nullptr) + { return QMetaType(type).create(copy); } + QT_DEPRECATED_VERSION_6_0 + static void destroy(int type, void *data) + { return QMetaType(type).destroy(data); } + QT_DEPRECATED_VERSION_6_0 + static void *construct(int type, void *where, const void *copy) + { return QMetaType(type).construct(where, copy); } + QT_DEPRECATED_VERSION_6_0 + static void destruct(int type, void *where) + { return QMetaType(type).destruct(where); } +#endif static bool isRegistered(int type); - static void *create(int type, const void *copy = nullptr); - static void destroy(int type, void *data); - static void *construct(int type, void *where, const void *copy); - static void destruct(int type, void *where); explicit QMetaType(int type); explicit constexpr QMetaType(QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {} @@ -387,7 +408,7 @@ public: int alignOf() const; TypeFlags flags() const; const QMetaObject *metaObject() const; - QT_PREPEND_NAMESPACE(QByteArray) name() const; + const char *name() const; void *create(const void *copy = nullptr) const; void destroy(void *data) const; @@ -415,6 +436,7 @@ public: template static QMetaType fromType(); + static QMetaType fromName(QByteArrayView name); friend bool operator==(const QMetaType &a, const QMetaType &b) { return a.id() == b.id(); } friend bool operator!=(const QMetaType &a, const QMetaType &b) { return !(a == b); } @@ -1690,7 +1712,7 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE > \ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ if (const int id = metatype_id.loadRelaxed()) \ return id; \ - const char *tName = QMetaType::typeName(qMetaTypeId()); \ + const char *tName = QMetaType::fromType().name(); \ Q_ASSERT(tName); \ const int tNameLen = int(qstrlen(tName)); \ QByteArray typeName; \ @@ -1725,8 +1747,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE > \ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ if (const int id = metatype_id.loadAcquire()) \ return id; \ - const char *tName = QMetaType::typeName(qMetaTypeId()); \ - const char *uName = QMetaType::typeName(qMetaTypeId()); \ + const char *tName = QMetaType::fromType().name(); \ + const char *uName = QMetaType::fromType().name(); \ Q_ASSERT(tName); \ Q_ASSERT(uName); \ const int tNameLen = int(qstrlen(tName)); \ -- cgit v1.2.3