diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-31 17:49:42 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-01 16:32:51 +0100 |
commit | f3bcbfd6a50fb7e74f4ff6714d3b3066fa74e253 (patch) | |
tree | 675580377465f8988e3903aad22f248bd784de46 /src | |
parent | 04c1588965b9a4b12ebf04b23e5336fe88bb4f56 (diff) |
QtQml: Re-allow assigning of raw numbers to enum property aliases
This used to work and we cannot just take it away.
Amends commit 3ea55bf398412d373daab9c92b1498f45de70e96.
Pick-to: 6.7 6.6 6.5 6.2
Fixes: QTBUG-121710
Change-Id: I7f856140286bba9d49b7ed1abfdf398a65fb1962
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/common/qv4compileddata_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycachecreator_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertyvalidator.cpp | 5 |
4 files changed, 14 insertions, 4 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 55e73bba7d..f58a176009 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -707,6 +707,8 @@ struct Binding } bool evaluatesToString() const { return type() == Type_String || isTranslationBinding(); } + bool isNumberBinding() const { return type() == Type_Number; } + bool valueAsBoolean() const { if (type() == Type_Boolean) diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index ec7d0b42ce..3d4d3596cc 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -315,8 +315,11 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QMetaType propertyType = property->propType(); if (property->isEnum()) { - if (binding->hasFlag(QV4::CompiledData::Binding::IsResolvedEnum)) { - propertyType = QMetaType::fromType<int>(); + if (binding->hasFlag(QV4::CompiledData::Binding::IsResolvedEnum) || + // TODO: For historical reasons you can assign any number to an enum property alias + // This can be fixed with an opt-out mechanism, for example a pragma. + (property->isAlias() && binding->isNumberBinding())) { + propertyType = property->propType().underlyingType(); } else { // ### This should be resolved earlier at compile time and the binding value should be changed accordingly. QVariant value = compilationUnit->bindingValueAsString(binding); diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 414e7aa728..fe0cdb5cd4 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -905,10 +905,10 @@ inline QQmlError QQmlPropertyCacheAliasCreator<ObjectContainer>::propertyDataFor resettable = property->isResettable(); bindable = property->isBindable(); - // Copy type flags - propertyFlags->copyPropertyTypeFlags(property->flags()); if (property->isVarProperty()) propertyFlags->setType(QQmlPropertyData::Flags::QVariantType); + else + propertyFlags->copyPropertyTypeFlags(property->flags()); }; // for deep aliases, valueTypeIndex is always set diff --git a/src/qml/qml/qqmlpropertyvalidator.cpp b/src/qml/qml/qqmlpropertyvalidator.cpp index 82fd072698..a49393e425 100644 --- a/src/qml/qml/qqmlpropertyvalidator.cpp +++ b/src/qml/qml/qqmlpropertyvalidator.cpp @@ -374,6 +374,11 @@ QQmlError QQmlPropertyValidator::validateLiteralBinding( if (binding->hasFlag(QV4::CompiledData::Binding::IsResolvedEnum)) return noError; + // TODO: For historical reasons you can assign any number to an enum property alias + // This can be fixed with an opt-out mechanism, for example a pragma. + if (property->isAlias() && binding->isNumberBinding()) + return noError; + QString value = compilationUnit->bindingValueAsString(binding); QMetaProperty p = propertyCache->firstCppMetaObject()->property(property->coreIndex()); bool ok; |