QmlDesigner: Properly parse variant type

If a property actually is a variant we have to properly parse
the string and convert it to the correct type.
Booleans and numbers were not probably converted.
This did not create many issues, since the conversion happened
later, but it broke copy and paste and merging.
In Qt 5 this conversion seemed to happen mostly automatically.

Boolean literals have to be handled explcitly, since e.g. "10"
is technically true and can be interpreted as boolean.

Task-numbner: QDS-5944
Change-Id: I35c7cae7041667c7eac81e36a285a394263b35a4
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
Thomas Hartmann
2022-04-29 14:23:09 +02:00
parent 176dbff127
commit c3d04642e1

View File

@@ -242,9 +242,21 @@ QVariant read(int variantType, const QString &str)
bool conversionOk = true;
switch (variantType) {
case QMetaType::QVariant: {
if (str == "true")
return true;
if (str == "false")
return false;
auto tmp = QVariant(str);
value = QVariant(tmp);
conversionOk = tmp.isValid();
value = QVariant(tmp);
if (tmp.canConvert(QMetaType::Double))
value.convert(QMetaType::Double);
else if (tmp.canConvert(QMetaType::QColor))
value.convert(QMetaType::QColor);
break;
}
case QMetaType::QPoint: