aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2024-03-20 11:33:37 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-03-22 18:11:41 +0100
commitc7995e6aa3643e5da76ae32ce1e1166fd6f81b0e (patch)
tree4554adad51fe8cb635e0acdef44602cd70d1ccf2
parent4a660da8d33beaec91286dca2affb012420bf84b (diff)
QQmlGadgetPtrWrapper: Consider QVariant as possible type
If the type is QVariant, we have to store and retrieve the member as-is, instead of wrapping and unwrapping it. Pick-to: 6.7 Fixes: QTBUG-123484 Change-Id: I01ac33158236b0f1082744aafa86108225b68392 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qml/qml/qqmlvaluetype.cpp19
-rw-r--r--tests/auto/quick/qquickdesignersupport/data/RegTestComponent.qml20
-rw-r--r--tests/auto/quick/qquickdesignersupport/data/regTestProperties.qml13
-rw-r--r--tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp32
4 files changed, 79 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp
index 428ce9b697..4088d6e6c4 100644
--- a/src/qml/qml/qqmlvaluetype.cpp
+++ b/src/qml/qml/qqmlvaluetype.cpp
@@ -55,16 +55,25 @@ void QQmlGadgetPtrWrapper::write(
QVariant QQmlGadgetPtrWrapper::value() const
{
Q_ASSERT(m_gadgetPtr);
- return QVariant(metaType(), m_gadgetPtr);
+
+ const QMetaType m = metaType();
+ return m == QMetaType::fromType<QVariant>()
+ ? *static_cast<const QVariant *>(m_gadgetPtr)
+ : QVariant(m, m_gadgetPtr);
}
void QQmlGadgetPtrWrapper::setValue(const QVariant &value)
{
Q_ASSERT(m_gadgetPtr);
- Q_ASSERT(metaType() == value.metaType());
- const QQmlValueType *type = valueType();
- type->destruct(m_gadgetPtr);
- type->construct(m_gadgetPtr, value.constData());
+
+ const QMetaType m = metaType();
+ m.destruct(m_gadgetPtr);
+ if (m == QMetaType::fromType<QVariant>()) {
+ m.construct(m_gadgetPtr, &value);
+ } else {
+ Q_ASSERT(m == value.metaType());
+ m.construct(m_gadgetPtr, value.constData());
+ }
}
int QQmlGadgetPtrWrapper::metaCall(QMetaObject::Call type, int id, void **argv)
diff --git a/tests/auto/quick/qquickdesignersupport/data/RegTestComponent.qml b/tests/auto/quick/qquickdesignersupport/data/RegTestComponent.qml
new file mode 100644
index 0000000000..8bb8480daf
--- /dev/null
+++ b/tests/auto/quick/qquickdesignersupport/data/RegTestComponent.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+
+QtObject {
+ id: root
+
+ property int currentCategory: 0
+
+
+
+ property var materialsNames: [[qsTr("Car Paint"), qsTr("Glittery Car Paint"), qsTr("Aluminium"), qsTr("Chrome"), qsTr("Steel"), qsTr("Brushed Steel"), qsTr("Steel Floor"), qsTr("Copper"), qsTr("Silver"), qsTr("Gold"), qsTr("Mirror")],
+ [qsTr("Asphalt"), qsTr("Brick"), qsTr("Ceramic"), qsTr("Concrete"), qsTr("Glass"), qsTr("Darkened Glass"), qsTr("Wood"), qsTr("Wood - Planks"), qsTr("Wood - Parquet"), qsTr("Stone")],
+ [qsTr("Acrylic Paint"), qsTr("Carbon Fiber"), qsTr("Shiny Plastic"), qsTr("Matte Plastic"), qsTr("Textured Plastic"), qsTr("Rubber"), qsTr("Wax")],
+ [qsTr("Fabric"), qsTr("Fabric: Rough"), qsTr("Fabric: Satin"), qsTr("Leather"), qsTr("Paper")]]
+
+
+
+ property var model: root.materialsNames[root.currentCategory]
+
+} \ No newline at end of file
diff --git a/tests/auto/quick/qquickdesignersupport/data/regTestProperties.qml b/tests/auto/quick/qquickdesignersupport/data/regTestProperties.qml
new file mode 100644
index 0000000000..5ea3f58aff
--- /dev/null
+++ b/tests/auto/quick/qquickdesignersupport/data/regTestProperties.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.11
+
+Rectangle {
+ objectName: "rootItem"
+ color: "white"
+ width: 800
+ height: 600
+
+ RegTestComponent {
+ objectName: "testComponent"
+
+ }
+}
diff --git a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp
index 4a3c778938..bdc8f97d3a 100644
--- a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp
+++ b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp
@@ -42,6 +42,7 @@ private slots:
void testDotProperties();
void testItemReparenting();
void testPropertyNames();
+ void regressionTestAllProperties();
};
@@ -783,6 +784,37 @@ void tst_qquickdesignersupport::testPropertyNames()
QVERIFY(!names.contains("testProperty"));
}
+void tst_qquickdesignersupport::regressionTestAllProperties()
+{
+ QScopedPointer<QQuickView> view(new QQuickView);
+ view->engine()->setOutputWarningsToStandardError(false);
+ view->setSource(testFileUrl("regTestProperties.qml"));
+
+ QVERIFY(view->errors().isEmpty());
+ QQuickItem *rootItem = view->rootObject();
+ QVERIFY(rootItem);
+
+ QObject *component = rootItem->findChild<QObject*>("testComponent");
+
+ QVERIFY(component);
+ QCOMPARE(component->objectName(), QLatin1String("testComponent"));
+
+ QVERIFY(component);
+
+ QQuickDesignerSupport::PropertyNameList names
+ = QQuickDesignerSupportProperties::allPropertyNames(component);
+ QVERIFY(!names.isEmpty());
+
+ const QByteArrayList expectedNames = QByteArrayList {
+ "objectName", "currentCategory", "materialsNames", "model"
+ };
+
+ QCOMPARE(names, expectedNames);
+ names = QQuickDesignerSupportProperties::propertyNameListForWritableProperties(component);
+ QVERIFY(!names.isEmpty());
+ QCOMPARE(names, expectedNames);
+}
+
QTEST_MAIN(tst_qquickdesignersupport)
#include "tst_qquickdesignersupport.moc"