aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypes
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-06-22 09:43:05 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-08-24 10:13:39 +0200
commit1b7a098803a43355abf62e099267d4a122645e07 (patch)
treebd8f744e81250042d3e86c1c942be89e8e292f31 /tests/auto/qml/qqmlvaluetypes
parentae36d94c2f385e272ae25fcd0fe780edb70cf7d9 (diff)
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 <lars.knoll@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/variant_read.qml9
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml25
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml40
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp34
4 files changed, 0 insertions, 108 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/variant_read.qml b/tests/auto/qml/qqmlvaluetypes/data/variant_read.qml
deleted file mode 100644
index a08f3db94f..0000000000
--- a/tests/auto/qml/qqmlvaluetypes/data/variant_read.qml
+++ /dev/null
@@ -1,9 +0,0 @@
-import Test 1.0
-
-MyTypeObject {
- property real s_width: variant.width
- property real s_height: variant.height
- property variant copy: variant
-}
-
-
diff --git a/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml b/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml
deleted file mode 100644
index 6063917dd4..0000000000
--- a/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml
+++ /dev/null
@@ -1,25 +0,0 @@
-import QtQuick 2.0
-
-Item {
- property bool complete: false
- property bool success: false
-
- property variant v1: Qt.vector3d(1,2,3)
- property variant v2: Qt.vector3d(4,5,6)
- property variant v3: v1.plus(v2) // set up doomed binding
-
- Component.onCompleted: {
- complete = false;
- success = true;
-
- v1 = Qt.vector2d(1,2) // changing the type of the property shouldn't cause crash
-
- v1.x = 8;
- v2.x = 9;
-
- if (v1 != Qt.vector2d(8,2)) success = false;
- if (v2 != Qt.vector3d(9,5,6)) success = false;
-
- complete = true;
- }
-}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml b/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml
deleted file mode 100644
index 0dbfd2a012..0000000000
--- a/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml
+++ /dev/null
@@ -1,40 +0,0 @@
-import QtQuick 2.0
-
-Item {
- property bool complete: false
- property bool success: false
-
- property variant v1
-
- Component.onCompleted: {
- complete = false;
- success = true;
-
- // store a js reference to the VariantReference vt in a temp var.
- v1 = Qt.vector3d(1,2,3)
- var ref = v1;
- ref.z = 5
- if (v1 != Qt.vector3d(1,2,5)) success = false;
-
- // now change the type of a reference, and attempt a valid write.
- v1 = Qt.vector2d(1,2);
- ref.x = 5;
- if (v1 != Qt.vector2d(5,2)) success = false;
-
- // now change the type of a reference, and attempt an invalid write.
- v1 = Qt.rgba(1,0,0,1);
- ref.x = 5;
- if (v1.toString() != Qt.rgba(1,0,0,1).toString()) success = false;
- v1 = 6;
- ref.x = 5;
- if (v1 != 6) success = false;
-
- // now change the type of a reference, and attempt an invalid read.
- v1 = Qt.vector3d(1,2,3);
- ref = v1;
- v1 = Qt.vector2d(1,2);
- if (ref.z == 3) success = false;
-
- complete = true;
- }
-}
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index f2e43571d8..317a3bd152 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -65,7 +65,6 @@ private slots:
void matrix4x4();
void font();
void color();
- void variant();
void locale();
void qmlproperty();
@@ -290,39 +289,6 @@ void tst_qqmlvaluetypes::sizef()
}
}
-void tst_qqmlvaluetypes::variant()
-{
- {
- QQmlComponent component(&engine, testFileUrl("variant_read.qml"));
- MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
- QVERIFY(object != nullptr);
-
- QCOMPARE(float(object->property("s_width").toDouble()), float(0.1));
- QCOMPARE(float(object->property("s_height").toDouble()), float(100923.2));
- QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2)));
-
- delete object;
- }
-
- {
- QQmlComponent component(&engine, testFileUrl("variant_write.1.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QVERIFY(object->property("complete").toBool());
- QVERIFY(object->property("success").toBool());
- delete object;
- }
-
- {
- QQmlComponent component(&engine, testFileUrl("variant_write.2.qml"));
- QObject *object = component.create();
- QVERIFY(object != nullptr);
- QVERIFY(object->property("complete").toBool());
- QVERIFY(object->property("success").toBool());
- delete object;
- }
-}
-
void tst_qqmlvaluetypes::locale()
{
{