forked from qt-creator/qt-creator
QmlDesigner: Cast string property values to urls in PropertyMetaInfo
PropertyMetaInfo::castedValue() now casts string values to urls properly. This fixes UrlChooser controls in property view. Adjusted the unit tests accordingly. Fixes: QDS-14663 Change-Id: I2c3a47bcedb8b19af03a49a67b31d43d29e63b7e Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -4600,6 +4600,8 @@ QVariant PropertyMetaInfo::castedValue(const QVariant &value) const
|
||||
} else if (typeId == m_projectStorage->builtinTypeId<QUrl>()) {
|
||||
if (isType(value.metaType(), qUrlType))
|
||||
return value;
|
||||
else if (isType(value.metaType(), qStringType))
|
||||
return value.toUrl();
|
||||
else
|
||||
return QUrl{};
|
||||
} else if (typeId == m_projectStorage->builtinTypeId<QColor>()) {
|
||||
|
@@ -689,16 +689,29 @@ TEST_F(PropertyMetaInfo, cast_url_to_url)
|
||||
ASSERT_THAT(castedValue, IsQVariant<QUrl>(url));
|
||||
}
|
||||
|
||||
TEST_F(PropertyMetaInfo, cast_string_to_empty_url)
|
||||
TEST_F(PropertyMetaInfo, cast_empty_string_to_empty_url)
|
||||
{
|
||||
auto propertyTypeInfo = createNodeMetaInfo("QML", ModuleKind::QmlLibrary, "url", {});
|
||||
projectStorageMock.createProperty(nodeInfo.id(), "bar", {}, propertyTypeInfo.id());
|
||||
auto propertyInfo = nodeInfo.property("bar");
|
||||
auto value = QVariant::fromValue(QString{});
|
||||
|
||||
auto castedValue = propertyInfo.castedValue(value);
|
||||
|
||||
ASSERT_THAT(castedValue, IsQVariant<QUrl>(IsEmpty()));
|
||||
}
|
||||
|
||||
TEST_F(PropertyMetaInfo, cast_string_to_url)
|
||||
{
|
||||
auto propertyTypeInfo = createNodeMetaInfo("QML", ModuleKind::QmlLibrary, "url", {});
|
||||
projectStorageMock.createProperty(nodeInfo.id(), "bar", {}, propertyTypeInfo.id());
|
||||
auto propertyInfo = nodeInfo.property("bar");
|
||||
auto value = QVariant::fromValue(QString{"http://www.qt.io/future"});
|
||||
auto url = QUrl{"http://www.qt.io/future"};
|
||||
|
||||
auto castedValue = propertyInfo.castedValue(value);
|
||||
|
||||
ASSERT_THAT(castedValue, IsQVariant<QUrl>(IsEmpty()));
|
||||
ASSERT_THAT(castedValue, IsQVariant<QUrl>(url));
|
||||
}
|
||||
|
||||
TEST_F(PropertyMetaInfo, cast_default_to_empty_url)
|
||||
|
Reference in New Issue
Block a user