aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-03-18 11:59:53 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2024-03-18 16:49:39 +0000
commit25255f7f37702adcf6890a880a067eb23c249fc1 (patch)
treefe986c1309aca01e2fe222db0f3161afae7ce141
parentccb9c7995703949972f85ce311a5d16b2a43f4b4 (diff)
Handle more potential underlying types
Since f3bcbfd6a50fb7e74f4ff6714d3b3066fa74e253, we use the underlying type of an enum when the binding is detected as a resolved enum and the property is of enum type. When using an enums underlying type, we can receive types that were formerly not possible, because we would normalize them to plain int. Fix this by teaching the object creator to handle assignments of signed and unsigned integer types. Fixes: QTBUG-123428 Change-Id: I3635b7de048e0c6ddf79381679aafee89a5b3def Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 186405955f1057111379369fc43951513c461aa9) Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp43
-rw-r--r--tests/auto/qml/qqmllanguage/data/enumPropsManyUnderlyingTypes.qml10
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.cpp2
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h34
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp18
5 files changed, 107 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 4cd07ffa49..8620904c5e 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -439,6 +439,49 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const
break;
}
break;
+ case QMetaType::SChar: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ qint8 value = qint8(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ case QMetaType::UChar: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ quint8 value = quint8(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ case QMetaType::Short: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ qint16 value = qint16(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ case QMetaType::UShort: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ quint16 value = quint16(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ case QMetaType::LongLong: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ qint64 value = qint64(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ case QMetaType::ULongLong: {
+ assertType(QV4::CompiledData::Binding::Type_Number);
+ double d = compilationUnit->bindingValueAsNumber(binding);
+ quint64 value = quint64(d);
+ property->writeProperty(_qobject, &value, propertyWriteFlags);
+ break;
+ }
+ break;
case QMetaType::Float: {
assertType(QV4::CompiledData::Binding::Type_Number);
float value = float(compilationUnit->bindingValueAsNumber(binding));
diff --git a/tests/auto/qml/qqmllanguage/data/enumPropsManyUnderlyingTypes.qml b/tests/auto/qml/qqmllanguage/data/enumPropsManyUnderlyingTypes.qml
new file mode 100644
index 0000000000..b713d2aa24
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/enumPropsManyUnderlyingTypes.qml
@@ -0,0 +1,10 @@
+import Test
+
+EnumPropsManyUnderlyingTypes {
+ si8prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+ ui8prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+ si16prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+ ui16prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+ si64prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+ ui64prop: EnumPropsManyUnderlyingTypes.ResolvedValue
+}
diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp
index df09d43653..c4fd954450 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.cpp
+++ b/tests/auto/qml/qqmllanguage/testtypes.cpp
@@ -92,6 +92,8 @@ void registerTypes()
qmlRegisterType<MyArrayBufferTestClass>("Test", 1, 0, "MyArrayBufferTestClass");
+ qmlRegisterTypesAndRevisions<EnumPropsManyUnderlyingTypes>("Test", 1);
+
qmlRegisterType<LazyDeferredSubObject>("Test", 1, 0, "LazyDeferredSubObject");
qmlRegisterType<DeferredProperties>("Test", 1, 0, "DeferredProperties");
qmlRegisterType<ImmediateProperties>("Test", 1, 0, "ImmediateProperties");
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 568872fb4e..bbf328b9a7 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1294,6 +1294,40 @@ public:
}
};
+class EnumPropsManyUnderlyingTypes : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+public:
+ enum si8 : qint8 { ResolvedValue = 1};
+ enum ui8 : quint8 {};
+ enum si16 : qint16 {};
+ enum ui16 : quint16 {};
+ enum ui64 : qint64 {};
+ enum si64 : quint64 {};
+ Q_ENUM(si8)
+ Q_ENUM(ui8)
+ Q_ENUM(si16)
+ Q_ENUM(ui16)
+ Q_ENUM(si64)
+ Q_ENUM(ui64)
+
+
+ Q_PROPERTY(si8 si8prop MEMBER si8prop)
+ Q_PROPERTY(ui8 ui8prop MEMBER ui8prop)
+ Q_PROPERTY(si16 si16prop MEMBER si16prop)
+ Q_PROPERTY(ui16 ui16prop MEMBER ui16prop)
+ Q_PROPERTY(si64 si64prop MEMBER si64prop)
+ Q_PROPERTY(ui64 ui64prop MEMBER ui64prop)
+
+ si8 si8prop = si8(0);
+ ui8 ui8prop = ui8(0);
+ si16 si16prop = si16(0);
+ ui16 ui16prop = ui16(0);
+ si64 si64prop = si64(0);
+ ui64 ui64prop = ui64(0);
+};
+
Q_DECLARE_METATYPE(MyEnum2Class::EnumB)
Q_DECLARE_METATYPE(MyEnum1Class::EnumA)
Q_DECLARE_METATYPE(Qt::TextFormat)
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 4569fabf0a..350a8da03a 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -411,6 +411,8 @@ private slots:
void longConversion();
+ void enumPropsManyUnderylingTypes();
+
void typedEnums_data();
void typedEnums();
@@ -7976,6 +7978,22 @@ void tst_qqmllanguage::longConversion()
}
}
+void tst_qqmllanguage::enumPropsManyUnderylingTypes()
+{
+ QQmlEngine e;
+ QQmlComponent c(&e, testFileUrl("enumPropsManyUnderlyingTypes.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ auto *enumObject = qobject_cast<EnumPropsManyUnderlyingTypes *>(o.get());
+ QCOMPARE(enumObject->si8prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+ QCOMPARE(enumObject->ui8prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+ QCOMPARE(enumObject->si16prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+ QCOMPARE(enumObject->ui16prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+ QCOMPARE(enumObject->si64prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+ QCOMPARE(enumObject->ui64prop, EnumPropsManyUnderlyingTypes::ResolvedValue);
+}
+
void tst_qqmllanguage::asValueType()
{
QQmlEngine engine;