summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-07-13 10:59:48 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-24 00:17:19 +0200
commit1d7a9fc9b4f64a5dd643e0ebfb5057b4b30236b8 (patch)
treea416e17b6fd8b18682bc3e265504b03d872c38b2 /src/corelib/kernel/qmetatype.cpp
parentf44d2ea1cc14587ab8f0ba3a36f10ab3bee34504 (diff)
Add a metatype helper class for Qt Core
This helps get better symmetry with the other modules, and to unify the code paths for both conversion and retrieving the interface for static types. Change-Id: Icbd20de2563f36e3de20d826323acd057734abfb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r--src/corelib/kernel/qmetatype.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 8d15b4a2aa..6d17ceb2b8 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -852,11 +852,29 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ
{nullptr, 0, QMetaType::UnknownType}
};
+static const struct : QMetaTypeModuleHelper
+{
+ QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override {
+ switch (type) {
+ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ default:
+ return nullptr;
+ }
+ }
+} metatypeHelper;
+
+static const QMetaTypeModuleHelper *qMetaTypeCoreHelper = &metatypeHelper;
Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeGuiHelper = nullptr;
Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeWidgetsHelper = nullptr;
static const QMetaTypeModuleHelper *qModuleHelperForType(int type)
{
+ if (type <= QMetaType::LastCoreType)
+ return qMetaTypeCoreHelper;
if (type >= QMetaType::FirstGuiType && type <= QMetaType::LastGuiType)
return qMetaTypeGuiHelper;
else if (type >= QMetaType::FirstWidgetsType && type <= QMetaType::LastWidgetsType)
@@ -1589,24 +1607,19 @@ const QMetaObject *QMetaType::metaObjectForType(int type)
static QtPrivate::QMetaTypeInterface *interfaceForType(int typeId)
{
+ QtPrivate::QMetaTypeInterface *iface = nullptr;
if (typeId >= QMetaType::User) {
if (auto reg = customTypeRegistry())
- return reg->getCustomType(typeId);
- }
- if (auto moduleHelper = qModuleHelperForType(typeId))
- return moduleHelper->interfaceForType(typeId);
-
- switch (typeId) {
- QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_CONVERT_ID_TO_TYPE)
- QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_CONVERT_ID_TO_TYPE)
- QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE)
- QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_CONVERT_ID_TO_TYPE)
- QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_CONVERT_ID_TO_TYPE)
- default:
- if (typeId != QMetaType::UnknownType)
- qWarning("Trying to construct an instance of an invalid type, type id: %i", typeId);
- return nullptr;
+ iface = reg->getCustomType(typeId);
+ } else {
+ if (auto moduleHelper = qModuleHelperForType(typeId))
+ iface = moduleHelper->interfaceForType(typeId);
}
+
+ if (!iface && typeId != QMetaType::UnknownType)
+ qWarning("Trying to construct an instance of an invalid type, type id: %i", typeId);
+
+ return iface;
}
/*!