aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlglobal.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-06-07 15:28:54 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-06-09 14:47:13 +0200
commitc4addf7d0e91cd39b636a88772ae9543f11e2c8c (patch)
treea82c384a019573365ab357767972d5344abed495 /src/qml/qml/qqmlglobal.cpp
parente5383a5d5dd02afdbe94b380394fd88d8320e35a (diff)
Pass QMetaType by value rather than by ID in more places
This saves us some ping-pong between the IDs and the QMetaTypes, and avoids possible ambiguities if multiple metatypes are registered for the same C++ type. Change-Id: I81cec94a9cd05d69927dc884f65574f0ab2ddc22 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlglobal.cpp')
-rw-r--r--src/qml/qml/qqmlglobal.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp
index d4473b7020..bd0d8e5e88 100644
--- a/src/qml/qml/qqmlglobal.cpp
+++ b/src/qml/qml/qqmlglobal.cpp
@@ -48,21 +48,20 @@
QT_BEGIN_NAMESPACE
-bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst)
+bool QQmlValueTypeProvider::initValueType(QMetaType metaType, QVariant &dst)
{
- const QMetaType metaType(type);
if (!metaType.isValid())
return false;
- dst = QVariant(QMetaType(type));
+ dst = QVariant(metaType);
return true;
}
-bool QQmlValueTypeProvider::createValueType(int type, const QJSValue &s, QVariant &data)
+bool QQmlValueTypeProvider::createValueType(QMetaType metaType, const QJSValue &s, QVariant &data)
{
- const QQmlType qmlType = QQmlMetaType::qmlType(type, QQmlMetaType::TypeIdCategory::MetaType);
+ const QQmlType qmlType = QQmlMetaType::qmlType(metaType);
if (auto valueTypeFunction = qmlType.createValueTypeFunction()) {
QVariant result = valueTypeFunction(s);
- if (result.userType() == type) {
+ if (result.metaType() == metaType) {
data = std::move(result);
return true;
}
@@ -71,32 +70,34 @@ bool QQmlValueTypeProvider::createValueType(int type, const QJSValue &s, QVarian
return false;
}
-bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const QVariant& rhs)
+bool QQmlValueTypeProvider::equalValueType(QMetaType metaType, const void *lhs, const QVariant &rhs)
{
Q_ASSERT(lhs);
- return QMetaType(type).equals(lhs, rhs.constData());
+ return metaType.equals(lhs, rhs.constData());
}
-bool QQmlValueTypeProvider::readValueType(const QVariant& src, void *dst, int type)
+bool QQmlValueTypeProvider::readValueType(QMetaType metaType, const QVariant &src, void *dst)
{
Q_ASSERT(dst);
- const QMetaType dstType(type);
- if (!dstType.isValid() || (src.metaType() == dstType && dstType.equals(src.constData(), dst)))
+ if (!metaType.isValid()
+ || (src.metaType() == metaType && metaType.equals(src.constData(), dst))) {
return false;
+ }
- dstType.destruct(dst);
- dstType.construct(dst, src.metaType() == dstType ? src.constData() : nullptr);
+ metaType.destruct(dst);
+ metaType.construct(dst, src.metaType() == metaType ? src.constData() : nullptr);
return true;
}
-bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& dst)
+bool QQmlValueTypeProvider::writeValueType(QMetaType metaType, const void *src, QVariant &dst)
{
Q_ASSERT(src);
- const QMetaType srcType(type);
- if (!srcType.isValid() || (dst.metaType() == srcType && srcType.equals(src, dst.constData())))
+ if (!metaType.isValid()
+ || (dst.metaType() == metaType && metaType.equals(src, dst.constData()))) {
return false;
+ }
- dst = QVariant(srcType, src);
+ dst = QVariant(metaType, src);
return true;
}