aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertyvalidator.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/qqmlpropertyvalidator.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/qqmlpropertyvalidator.cpp')
-rw-r--r--src/qml/qml/qqmlpropertyvalidator.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/qml/qml/qqmlpropertyvalidator.cpp b/src/qml/qml/qqmlpropertyvalidator.cpp
index f1826b2f1c..72e0275a53 100644
--- a/src/qml/qml/qqmlpropertyvalidator.cpp
+++ b/src/qml/qml/qqmlpropertyvalidator.cpp
@@ -49,9 +49,9 @@
QT_BEGIN_NAMESPACE
-static bool isPrimitiveType(int typeId)
+static bool isPrimitiveType(QMetaType metaType)
{
- switch (typeId) {
+ switch (metaType.id()) {
#define HANDLE_PRIMITIVE(Type, id, T) \
case QMetaType::Type:
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(HANDLE_PRIMITIVE);
@@ -309,21 +309,21 @@ QVector<QQmlError> QQmlPropertyValidator::validateObject(
return recordError(binding->location, tr("Invalid grouped property access"));
}
} else {
- const int typeId = pd->propType().id();
- if (isPrimitiveType(typeId)) {
+ const QMetaType type = pd->propType();
+ if (isPrimitiveType(type)) {
return recordError(
binding->location,
tr("Invalid grouped property access: Property \"%1\" with primitive type \"%2\".")
.arg(name)
- .arg(QString::fromLatin1(QMetaType(typeId).name()))
+ .arg(QString::fromUtf8(type.name()))
);
}
- if (!enginePrivate->propertyCacheForType(typeId)) {
+ if (!enginePrivate->propertyCacheForType(type)) {
return recordError(binding->location,
tr("Invalid grouped property access: Property \"%1\" with type \"%2\", which is not a value type")
.arg(name)
- .arg(QString::fromLatin1(QMetaType(typeId).name()))
+ .arg(QString::fromUtf8(type.name()))
);
}
}
@@ -586,7 +586,7 @@ QQmlError QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *prope
};
QVariant result;
if (!QQml_valueTypeProvider()->createValueType(
- property->propType().id(),
+ property->propType(),
compilationUnit->bindingValueAsString(binding), result)) {
return warnOrError(tr("Invalid property assignment: %1 expected")
.arg(typeName()));
@@ -647,7 +647,7 @@ QQmlError QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *prope
Returns true if from can be assigned to a (QObject) property of type
to.
*/
-bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo) const
+bool QQmlPropertyValidator::canCoerce(QMetaType to, QQmlPropertyCache *fromMo) const
{
QQmlPropertyCache *toMo = enginePrivate->rawPropertyCacheForType(to);
@@ -657,7 +657,7 @@ bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo) const
// only occurs after the whole file has been validated
// Therefore we need to check the ICs here
for (const auto& icDatum : compilationUnit->inlineComponentData) {
- if (icDatum.typeIds.id.id() == to) {
+ if (icDatum.typeIds.id == to) {
toMo = compilationUnit->propertyCaches.at(icDatum.objectIndex);
break;
}
@@ -718,7 +718,7 @@ QQmlError QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *propert
return noError;
}
- const int propType = property->propType().id();
+ const QMetaType propType = property->propType();
const auto rhsType = [&]() {
return stringAt(compilationUnit->objectAt(binding->value.objectIndex)
->inheritedTypeNameIndex);
@@ -728,11 +728,12 @@ QQmlError QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *propert
// Can only check at instantiation time if the created sub-object successfully casts to the
// target interface.
return noError;
- } else if (propType == QMetaType::QVariant || propType == qMetaTypeId<QJSValue>()) {
+ } else if (propType == QMetaType::fromType<QVariant>()
+ || propType == QMetaType::fromType<QJSValue>()) {
// We can convert everything to QVariant :)
return noError;
} else if (property->isQList()) {
- const int listType = QQmlMetaType::listType(property->propType()).id();
+ const QMetaType listType = QQmlMetaType::listType(property->propType());
if (!QQmlMetaType::isInterface(listType)) {
QQmlPropertyCache *source = propertyCaches.at(binding->value.objectIndex);
if (!canCoerce(listType, source)) {
@@ -748,7 +749,7 @@ QQmlError QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *propert
.arg(rhsType())
.arg(propertyName)
.arg(typeName));
- } else if (propType == qMetaTypeId<QQmlScriptString>()) {
+ } else if (propType == QMetaType::fromType<QQmlScriptString>()) {
return qQmlCompileError(binding->valueLocation, tr("Invalid property assignment: script expected"));
} else if (QQmlMetaType::isValueType(property->propType())) {
return qQmlCompileError(binding->location, tr("Cannot assign value of type \"%1\" to property \"%2\", expecting an object")