From 982f23be3890d5c24a6bc74ed1cca4717fc456a8 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 26 Oct 2021 14:37:40 +0300 Subject: [PATCH] QmlDesigner: Allow invalid property value for QVariant type properties Invalid QVariant is a valid value for properties of type QVariant, so propagate the value change from puppet to creator in that case. Also change the property editor to notify controls of value change in case of invalid value set, and clear LineEdit when invalid value is set. Fixes: QDS-5304 Change-Id: I02c7daaf3cde06317690a32e7ac8a82da754bd58 Reviewed-by: Mahmoud Badri Reviewed-by: Qt CI Bot Reviewed-by: Thomas Hartmann --- .../qml2puppet/instances/nodeinstanceserver.cpp | 10 +++++++++- .../imports/HelperWidgets/LineEdit.qml | 12 ++++++------ .../propertyeditor/propertyeditorvalue.cpp | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp index bb80c2e2e1c..bd3994400ba 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -1221,7 +1221,15 @@ ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVecto if (instance.isValid()) { QVariant propertyValue = instance.property(propertyName); - if (QMetaType::isRegistered(propertyValue.userType()) && supportedVariantType(propertyValue.type())) { + bool isValid = QMetaType::isRegistered(propertyValue.userType()) + && supportedVariantType(propertyValue.type()); + if (!isValid && propertyValue.userType() == 0) { + // If the property is QVariant type, invalid variant can be a valid value + const QMetaObject *mo = instance.internalObject()->metaObject(); + const int idx = mo->indexOfProperty(propertyName); + isValid = idx >= 0 && mo->property(idx).userType() == QMetaType::QVariant; + } + if (isValid) { valueVector.append(PropertyValueContainer(instance.instanceId(), propertyName, propertyValue, PropertyName())); } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/LineEdit.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/LineEdit.qml index 4e2b1a2c1af..93a0878d377 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/LineEdit.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/LineEdit.qml @@ -76,13 +76,13 @@ StudioControls.TextField { id: colorLogic backendValue: lineEdit.backendValue onValueFromBackendChanged: { - if (colorLogic.valueFromBackend === undefined) - return - - if (writeValueManually) { - lineEdit.text = convertColorToString(colorLogic.valueFromBackend) + if (colorLogic.valueFromBackend === undefined) { + lineEdit.text = "" } else { - lineEdit.text = colorLogic.valueFromBackend + if (writeValueManually) + lineEdit.text = convertColorToString(colorLogic.valueFromBackend) + else + lineEdit.text = colorLogic.valueFromBackend } __dirty = false } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index 6602cf36317..c37549e074a 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -167,7 +167,7 @@ void PropertyEditorValue::setValue(const QVariant &value) fixAmbigousColorNames(modelNode(), name(), &m_value); fixUrl(modelNode(), name(), &m_value); - if (m_value.isValid() && !colorsEqual) + if (!colorsEqual) emit valueChangedQml(); emit isExplicitChanged();