Use common::iterateMessageFields in MessageDeclarationPrinter::printProperties

Deduplicate code.

Pick-to: 6.9 6.8
Change-Id: Ieb50b0e41787fb3988f85ca83024069d161c872a
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
(cherry picked from commit 342694b2d3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexey Edelev 2025-03-17 20:31:15 +01:00 committed by Qt Cherry-pick Bot
parent 750c0edd64
commit 17d2bef72b
1 changed files with 29 additions and 30 deletions

View File

@ -209,41 +209,40 @@ void MessageDeclarationPrinter::printProperties()
Indent();
const int numFields = m_descriptor->field_count();
for (int i = 0; i < numFields; ++i) {
const FieldDescriptor *field = m_descriptor->field(i);
const char *propertyTemplate = CommonTemplates::PropertyTemplate();
const auto propertyMap = common::producePropertyMap(field, m_descriptor);
if (common::isOneofField(field)) {
m_printer->Print(propertyMap,
common::isPureMessage(field)
common::iterateMessageFields(
m_descriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
const char *propertyTemplate = CommonTemplates::PropertyTemplate();
if (common::isOneofField(field)) {
m_printer->Print(propertyMap,
common::isPureMessage(field)
? CommonTemplates::PropertyOneofMessageTemplate()
: CommonTemplates::PropertyOneofTemplate());
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
continue;
}
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
return;
}
if (common::isOptionalField(field)) {
m_printer->Print(propertyMap, CommonTemplates::PropertyOneofTemplate());
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
continue;
}
if (common::isOptionalField(field)) {
m_printer->Print(propertyMap, CommonTemplates::PropertyOneofTemplate());
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
return;
}
if (common::isPureMessage(field)) {
m_printer->Print(propertyMap, CommonTemplates::PropertyMessageTemplate());
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
continue;
}
if (common::isPureMessage(field)) {
m_printer->Print(propertyMap, CommonTemplates::PropertyMessageTemplate());
m_printer->Print(propertyMap, CommonTemplates::PropertyHasFieldTemplate());
return;
}
if (field->is_repeated() && !field->is_map()) {
// Non-message list properties don't require an extra QQmlListProperty to access
// their data, so the property name should not contain the 'Data' suffix
if (field->type() == FieldDescriptor::TYPE_MESSAGE)
propertyTemplate = CommonTemplates::PropertyRepeatedMessageTemplate();
else
propertyTemplate = CommonTemplates::PropertyRepeatedTemplate();
}
m_printer->Print(propertyMap, propertyTemplate);
}
if (field->is_repeated() && !field->is_map()) {
// Non-message list properties don't require an extra QQmlListProperty to access
// their data, so the property name should not contain the 'Data' suffix
if (field->type() == FieldDescriptor::TYPE_MESSAGE)
propertyTemplate = CommonTemplates::PropertyRepeatedMessageTemplate();
else
propertyTemplate = CommonTemplates::PropertyRepeatedTemplate();
}
m_printer->Print(propertyMap, propertyTemplate);
});
// Generate extra QML property, that can be used in QML context
if (Options::instance().hasQml()) {