QmlDesigner: Generate no text for no properties

If there are no properties don't generate no properties for custom
properties.

Change-Id: I94b328d56b29df7b1727f10c7ffe664319c7ad02
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Marco Bubke
2025-01-30 00:20:45 +01:00
parent afb808db65
commit 4d4f0e394f
2 changed files with 30 additions and 43 deletions

View File

@@ -77,7 +77,7 @@ Utils::SmallStringView propertyName(const GeneratorProperty &property)
property);
}
PropertyMetaInfos getUnmangedProperties(const NodeMetaInfos &prototypes)
PropertyMetaInfos getUnmanagedProperties(const NodeMetaInfos &prototypes)
{
PropertyMetaInfos properties;
properties.reserve(128);
@@ -116,15 +116,11 @@ GeneratorProperties createSortedGeneratorProperties(
return generatorProperties;
}
QString createPropertySections(const PropertyComponentGeneratorType &propertyGenerator,
const NodeMetaInfos &prototypeChain)
QString createPropertySections(GeneratorProperties generatorProperties)
{
QString propertyComponents;
propertyComponents.reserve(100000);
auto generatorProperties = createSortedGeneratorProperties(getUnmangedProperties(prototypeChain),
propertyGenerator);
const auto begin = generatorProperties.begin();
const auto end = generatorProperties.end();
@@ -150,6 +146,12 @@ PropertyEditorComponentGenerator::PropertyEditorComponentGenerator(
QString PropertyEditorComponentGenerator::create(const NodeMetaInfos &prototypeChain, bool isComponent)
{
auto generatorProperties = createSortedGeneratorProperties(getUnmanagedProperties(prototypeChain),
m_propertyGenerator);
if (generatorProperties.empty())
return {};
return QString{R"xy(
%1
Column {
@@ -171,7 +173,7 @@ QString PropertyEditorComponentGenerator::create(const NodeMetaInfos &prototypeC
.arg(createImports(m_propertyGenerator.imports()),
componentButton(isComponent),
Tr::tr("Exposed Custom Properties"),
createPropertySections(m_propertyGenerator, prototypeChain));
createPropertySections(std::move(generatorProperties)));
}
} // namespace QmlDesigner

View File

@@ -93,53 +93,20 @@ protected:
QmlDesigner::TypeId dummyTypeId = projectStorageMock.commonTypeCache().builtinTypeId<double>();
};
TEST_F(PropertyEditorComponentGenerator, no_properties_and_no_imports)
TEST_F(PropertyEditorComponentGenerator, no_properties_and_no_imports_is_empty)
{
QString expectedText{
R"xy(
Column {
width: parent.width
Section {
caption: "Exposed Custom Properties"
anchors.left: parent.left
anchors.right: parent.right
leftPadding: 0
rightPadding: 0
bottomPadding: 0
Column {
width: parent.width
}
}
})xy"};
auto text = generator.create(fooTypeInfo.selfAndPrototypes(), false);
ASSERT_THAT(text, StrippedStringEq(expectedText));
ASSERT_THAT(text, IsEmpty());
}
TEST_F(PropertyEditorComponentGenerator, properties_without_component_are_not_shows)
{
QString expectedText{
R"xy(
Column {
width: parent.width
Section {
caption: "Exposed Custom Properties"
anchors.left: parent.left
anchors.right: parent.right
leftPadding: 0
rightPadding: 0
bottomPadding: 0
Column {
width: parent.width
}
}
})xy"};
createProperty(fooTypeInfo.id(), "x", {}, dummyTypeId);
auto text = generator.create(fooTypeInfo.selfAndPrototypes(), false);
ASSERT_THAT(text, StrippedStringEq(expectedText));
ASSERT_THAT(text, IsEmpty());
}
TEST_F(PropertyEditorComponentGenerator, show_component_button_for_a_component_node)
@@ -158,9 +125,18 @@ TEST_F(PropertyEditorComponentGenerator, show_component_button_for_a_component_n
bottomPadding: 0
Column {
width: parent.width
Column {
width: parent.width
leftPadding: 8
bottomPadding: 10
SectionLayout {
Double{}
}
}
}
}
})xy"};
createBasicProperty(fooTypeInfo.id(), "value", {}, dummyTypeId, "Double{}");
auto text = generator.create(fooTypeInfo.selfAndPrototypes(), true);
@@ -184,10 +160,19 @@ TEST_F(PropertyEditorComponentGenerator, imports)
bottomPadding: 0
Column {
width: parent.width
Column {
width: parent.width
leftPadding: 8
bottomPadding: 10
SectionLayout {
Double{}
}
}
}
}
})xy"};
setImports({"import QtQtuick", "import Studio 2.1"});
createBasicProperty(fooTypeInfo.id(), "value", {}, dummyTypeId, "Double{}");
auto text = generator.create(fooTypeInfo.selfAndPrototypes(), false);