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 <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2021-10-26 14:37:40 +03:00
parent 41f96fe05b
commit 982f23be38
3 changed files with 16 additions and 8 deletions

View File

@@ -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()));
}

View File

@@ -76,12 +76,12 @@ 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 {
if (writeValueManually)
lineEdit.text = convertColorToString(colorLogic.valueFromBackend)
else
lineEdit.text = colorLogic.valueFromBackend
}
__dirty = false

View File

@@ -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();