From 1b7a098803a43355abf62e099267d4a122645e07 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 22 Jun 2020 09:43:05 +0200 Subject: Unify "variant" and "var" properties in QML variant and var properties differ in two important ways: - variant properties trigger "magic" string conversions: variant v1: "red" // contains a QColor var v2: "red" // contains a string - variant properties behave differently for value types: they create copies, instead of references. However, as variant properties were marked as obsolete and this behavior was effetively undocumented, it should be safe to give "variant" "var semantics". With this change, we can also avoid doing magic conversions when storing data in QVariant properties of QObjects/QGadgets Change-Id: I549b1beb98e6af9639c1ee81f316bda513d5ff65 Reviewed-by: Lars Knoll Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 37 +----------------------- 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index e5ac59f379..2932b112e3 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -104,7 +104,6 @@ private slots: void assignBasicTypes(); void assignTypeExtremes(); void assignCompositeToType(); - void assignLiteralToVariant(); void assignLiteralToVar(); void assignLiteralToJSValue(); void assignNullStrings(); @@ -849,41 +848,6 @@ void tst_qqmllanguage::assignCompositeToType() QVERIFY(object != nullptr); } -// Test that literals are stored correctly in variant properties -void tst_qqmllanguage::assignLiteralToVariant() -{ - QQmlComponent component(&engine, testFileUrl("assignLiteralToVariant.qml")); - VERIFY_ERRORS(0); - QScopedPointer object(component.create()); - QVERIFY(object != nullptr); - - QVERIFY(isJSNumberType(object->property("test1").userType())); - QVERIFY(isJSNumberType(object->property("test2").userType())); - QCOMPARE(object->property("test3").userType(), (int)QVariant::String); - QCOMPARE(object->property("test4").userType(), (int)QVariant::Color); - QCOMPARE(object->property("test5").userType(), (int)QVariant::RectF); - QCOMPARE(object->property("test6").userType(), (int)QVariant::PointF); - QCOMPARE(object->property("test7").userType(), (int)QVariant::SizeF); - QCOMPARE(object->property("test8").userType(), (int)QVariant::Vector3D); - QCOMPARE(object->property("test9").userType(), (int)QVariant::String); - QCOMPARE(object->property("test10").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test12").userType(), (int)QVariant::Vector4D); - - QCOMPARE(object->property("test1"), QVariant(1)); - QCOMPARE(object->property("test2"), QVariant((double)1.7)); - QVERIFY(object->property("test3") == QVariant(QString(QLatin1String("Hello world!")))); - QCOMPARE(object->property("test4"), QVariant(QColor::fromRgb(0xFF008800))); - QVERIFY(object->property("test5") == QVariant(QRectF(10, 10, 10, 10))); - QVERIFY(object->property("test6") == QVariant(QPointF(10, 10))); - QVERIFY(object->property("test7") == QVariant(QSizeF(10, 10))); - QVERIFY(object->property("test8") == QVariant(QVector3D(100, 100, 100))); - QCOMPARE(object->property("test9"), QVariant(QString(QLatin1String("#FF008800")))); - QCOMPARE(object->property("test10"), QVariant(bool(true))); - QCOMPARE(object->property("test11"), QVariant(bool(false))); - QVERIFY(object->property("test12") == QVariant(QVector4D(100, 100, 100, 100))); -} - // Test that literals are stored correctly in "var" properties // Note that behaviour differs from "variant" properties in that // no conversion from "special strings" to QVariants is performed. @@ -3560,6 +3524,7 @@ void tst_qqmllanguage::variantNotify() QScopedPointer object(component.create()); QVERIFY(object != nullptr); + QEXPECT_FAIL("", "var properties always trigger notify", Continue); QCOMPARE(object->property("notifyCount").toInt(), 1); } -- cgit v1.2.3