diff --git a/src/protobuf/doc/src/qtprotobuf-generated-code.qdoc b/src/protobuf/doc/src/qtprotobuf-generated-code.qdoc new file mode 100644 index 00000000..1ebbb63f --- /dev/null +++ b/src/protobuf/doc/src/qtprotobuf-generated-code.qdoc @@ -0,0 +1,68 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \page qtprotobuf-mutable-getters.html + \title Qt Protobuf Mutable Getters + \brief The use of mutable getters in \l {Qt Protobuf} + + The generated \l {Qt Protobuf} messages allow access to the fields of a + message type using mutable getters. The getters have the \c{mut} prefix and + return a non-const reference to the field. + + \badcode + message Point { + double x = 1; + double y = 2; + } + + message Line { + Point start = 1; + Point end = 2; + } + \endcode + + The above \c{.proto} scheme generates the following code for the \c{Line} + message: + \code + class Line : public QProtobufMessage + { + const Point &start() const &; + Point &mutStart() &; + ... + + const Point &end() const &; + Point &mutEnd() &; + ... + } + \endcode + + For the \c{start} and \c{end} fields, the + \l {The qtprotobufgen Tool} {qtprotobufgen} generator creates additional + mutable getters: \c{mutStart} and \c{mutEnd}. + Use these getters to modify fields directly, without creating intermediate + messages: + \code + Line line; + + // Setting the line start point to (5.0, 5.0) + line.mutStart().setX(5.0); + line.mutStart().setY(5.0); + + // Setting the line end point to (10.0, 20.0) + line.mutEnd().setX(10.0); + line.mutEnd().setY(20.0); + + // Display the Line data + qDebug().nospace() << "start: (" << line.start().x() << "," << line.start().y() << ") " + "end: (" << line.end().x() << "," << line.end().y() << ")"; + + \endcode + + Calling the mutable getters performs any necessary field allocation and + allows you to modify the underlying data directly. + + \warning Mutable getters add a \c{mut} prefix to field names. If a message + contains fields named \c{field} and \c{mutField}, a naming conflict occurs. + This scenario is currently unsupported and will result in a generator error. +*/ diff --git a/src/protobuf/doc/src/qtprotobuf.qdoc b/src/protobuf/doc/src/qtprotobuf.qdoc index 2af94637..6329de2a 100644 --- a/src/protobuf/doc/src/qtprotobuf.qdoc +++ b/src/protobuf/doc/src/qtprotobuf.qdoc @@ -87,6 +87,7 @@ \li \l {Protobuf Qt Core Types Module} {Protobuf Qt Core Types} \li \l {Protobuf Qt GUI Types Module} {Protobuf Qt GUI Types} \li \l {Qt Protobuf Well-Known Types C++ Classes} {Qt Protobuf Well-Known types} + \li \l {Qt Protobuf Mutable Getters} {Qt Protobuf Mutable Getters} \endlist \section1 References diff --git a/src/tools/qtprotobufgen/Qt6ProtobufToolsMacros.cmake b/src/tools/qtprotobufgen/Qt6ProtobufToolsMacros.cmake index 560fd3c8..dbcdc81f 100644 --- a/src/tools/qtprotobufgen/Qt6ProtobufToolsMacros.cmake +++ b/src/tools/qtprotobufgen/Qt6ProtobufToolsMacros.cmake @@ -9,6 +9,7 @@ macro(_qt_internal_get_protoc_common_options option_args single_args multi_args) COPY_COMMENTS GENERATE_PACKAGE_SUBFOLDERS QML + ALLOW_MUTABLE_GETTER_CONFLICTS ) set(${single_args} EXTRA_NAMESPACE @@ -352,6 +353,26 @@ function(qt6_add_protobuf target) _qt_internal_get_protoc_options(generation_options arg protoc_option_opt protoc_single_opt protoc_multi_opt) + if(arg_ALLOW_MUTABLE_GETTER_CONFLICTS) + set(moc_target ${QT_CMAKE_EXPORT_NAMESPACE}::moc) + if(TARGET ${moc_target}) + _qt_internal_dealias_target(moc_target) + get_target_property(moc_version ${moc_target} _qt_package_version) + else() + message(AUTHOR_WARNING "Unable to determine the moc version. Qt installation might be" + " incomplete.") + set(moc_version 0) + endif() + + # TODO: The Q_PROPERTY related issue QTBUG-119912 is not fixed, so we prohibit the use of + # ALLOW_MUTABLE_GETTER_CONFLICTS until then. The property will remain undocumented and for + # the internal use only. Replace '99' with the proper Qt version once the issue in moc is + # fixed. + if(moc_version VERSION_LESS 99 AND NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + message(FATAL_ERROR "The use of 'ALLOW_MUTABLE_GETTER_CONFLICTS' is prohibited.") + endif() + endif() + if(arg_QML_URI AND NOT arg_QML) message(FATAL_ERROR "QML_URI requires the QML option set, " "but the QML argument is not provided.") diff --git a/src/tools/qtprotobufgen/messagedeclarationprinter.cpp b/src/tools/qtprotobufgen/messagedeclarationprinter.cpp index 452d023b..3197629f 100644 --- a/src/tools/qtprotobufgen/messagedeclarationprinter.cpp +++ b/src/tools/qtprotobufgen/messagedeclarationprinter.cpp @@ -284,6 +284,9 @@ void MessageDeclarationPrinter::printGetters() if (common::isPureMessage(field)) { m_printer->Print(propertyMap, CommonTemplates::GetterMessageDeclarationTemplate()); + m_printer + ->Print(propertyMap, + CommonTemplates::GetterMessageMutableDeclarationTemplate()); m_printer->Print(propertyMap, Options::instance().hasQml() ? CommonTemplates::ClearQmlMessageDeclarationTemplate() diff --git a/src/tools/qtprotobufgen/messagedefinitionprinter.cpp b/src/tools/qtprotobufgen/messagedefinitionprinter.cpp index a7792138..6903bd8c 100644 --- a/src/tools/qtprotobufgen/messagedefinitionprinter.cpp +++ b/src/tools/qtprotobufgen/messagedefinitionprinter.cpp @@ -426,6 +426,9 @@ void MessageDefinitionPrinter::printGetters() CommonTemplates::PrivateGetterMessageDefinitionTemplate()); m_printer->Print(propertyMap, CommonTemplates::GetterMessageDefinitionTemplate()); + m_printer->Print(propertyMap, + CommonTemplates::GetterMessageMutableDefinitionTemplate()); + m_printer->Print(propertyMap, CommonTemplates::ClearMessageDefinitionTemplate()); } else { diff --git a/src/tools/qtprotobufgen/qprotobufgenerator.cpp b/src/tools/qtprotobufgen/qprotobufgenerator.cpp index 19ac20bd..02994b61 100644 --- a/src/tools/qtprotobufgen/qprotobufgenerator.cpp +++ b/src/tools/qtprotobufgen/qprotobufgenerator.cpp @@ -13,6 +13,7 @@ #include "options.h" #include +#include #include #include @@ -33,16 +34,15 @@ QProtobufGenerator::~QProtobufGenerator() = default; bool QProtobufGenerator::Generate(const FileDescriptor *file, [[maybe_unused]] const std::string ¶meter, - GeneratorContext *generatorContext, - [[maybe_unused]] std::string *error) const + GeneratorContext *generatorContext, std::string *error) const { assert(file != nullptr); assert(generatorContext != nullptr); - return GenerateMessages(file, generatorContext); + return GenerateMessages(file, generatorContext, error); } void QProtobufGenerator::GenerateSources(const FileDescriptor *file, - GeneratorContext *generatorContext) const + GeneratorContext *generatorContext, std::string *) const { assert(file != nullptr); assert(generatorContext != nullptr); @@ -109,10 +109,12 @@ void QProtobufGenerator::GenerateSources(const FileDescriptor *file, } void QProtobufGenerator::GenerateHeader(const FileDescriptor *file, - GeneratorContext *generatorContext) const + GeneratorContext *generatorContext, + std::string *error) const { assert(file != nullptr); assert(generatorContext != nullptr); + assert(error != nullptr); const std::string basename = utils::extractFileBasename(file->name()) + CommonTemplates::ProtoFileSuffix(); @@ -155,7 +157,8 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file, std::unordered_set qtTypesSet; - const auto collectSpecialIncludes = [&](const Descriptor *message) { + std::string mutFieldsClashError; + const auto specialMessageHandling = [&](const Descriptor *message) { if (message->oneof_decl_count() > 0) externalIncludes.insert("QtProtobuf/qprotobufoneof.h"); @@ -165,26 +168,71 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file, if (message->full_name() == "google.protobuf.Any") externalIncludes.insert("QtProtobufWellKnownTypes/qprotobufanysupport.h"); - for (int i = 0; i < message->field_count(); ++i) { - const auto *field = message->field(i); - if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() - && !field->is_repeated() && common::isQtType(field)) { - const std::string package{ field->message_type()->file()->package() }; - externalIncludes.insert(package + "/" - + std::string{ field->message_type()->name() }); - qtTypesSet.insert(package); - } + // We collect the 'mut'-prefixed names of either message fields or + // the respective mutable getters that will be generated. The name + // strings are scoped in lambda and we cannot hold any kind of + // references so store the copy. + std::unordered_set mutPrefixedNames; + common::iterateMessageFields( + message, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) { + if (common::isPureMessage(field)) { + const auto getterNameIt = propertyMap.find("mutable_getter_name"); + assert(getterNameIt != propertyMap.end()); - if (common::isOptionalField(field)) - systemIncludes.insert("optional"); - } + const auto propertyNameIt = propertyMap.find("property_name"); + assert(propertyNameIt != propertyMap.end()); + + // Ensure mut prefix doesn't lead to the name clashing + if (mutPrefixedNames.find(getterNameIt->second) != mutPrefixedNames.end() + || mutPrefixedNames.find(propertyNameIt->second) + != mutPrefixedNames.end()) { + std::ostringstream e; + e << "Message '" << message->full_name() << "': "; + e << "Field '" << field->name() << "' causes a naming conflict"; + e << "with a mutable getter. This may lead to unintended behavior."; + e << "Consider reviewing the guidelines for handling mutable getters: "; + e << "https://doc.qt.io/qt-6/qtprotobuf-mutable-getters.html\n"; + mutFieldsClashError = e.str(); + } + mutPrefixedNames.insert(getterNameIt->second); + + // We only care about field names that potentially clash. + if (utils::startsWith(propertyNameIt->second, + CommonTemplates::MutableGetterPrefix())) + mutPrefixedNames.insert(propertyNameIt->second); + } + + // Collect the special includes + if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_map() + && !field->is_repeated() && common::isQtType(field)) { + const std::string package{ field->message_type()->file()->package() }; + externalIncludes.insert(package + "/" + + std::string{ field->message_type()->name() }); + qtTypesSet.insert(package); + } + + if (common::isOptionalField(field)) + systemIncludes.insert("optional"); + }); }; - common::iterateMessages(file, [&collectSpecialIncludes](const Descriptor *message){ - collectSpecialIncludes(message); - common::iterateNestedMessages(message, collectSpecialIncludes); + common::iterateMessages(file, [&specialMessageHandling](const Descriptor *message) { + specialMessageHandling(message); + common::iterateNestedMessages(message, + [&specialMessageHandling](const Descriptor *message) { + specialMessageHandling(message); + }); }); + if (!mutFieldsClashError.empty()) { + if (Options::instance().mutableGetterConflicts()) { + std::clog << mutFieldsClashError << std::endl; + } else { + *error += mutFieldsClashError; + return; + } + } + for (const auto &qtTypeInclude: qtTypesSet) { std::string qtTypeLower = qtTypeInclude; std::transform(qtTypeLower.begin(), qtTypeLower.end(), @@ -246,15 +294,20 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file, } bool QProtobufGenerator::GenerateMessages(const FileDescriptor *file, - GeneratorContext *generatorContext) const + GeneratorContext *generatorContext, + std::string *error) const { assert(file != nullptr); assert(generatorContext != nullptr); + assert(error != nullptr); if (file->message_type_count() <= 0 && file->enum_type_count() <= 0) return true; - GenerateHeader(file, generatorContext); - GenerateSources(file, generatorContext); + GenerateHeader(file, generatorContext, error); + if (!error->empty()) + return false; + + GenerateSources(file, generatorContext, error); return true; } diff --git a/src/tools/qtprotobufgen/qprotobufgenerator.h b/src/tools/qtprotobufgen/qprotobufgenerator.h index cbf81a93..760361d9 100644 --- a/src/tools/qtprotobufgen/qprotobufgenerator.h +++ b/src/tools/qtprotobufgen/qprotobufgenerator.h @@ -30,11 +30,14 @@ public: std::string *error) const override; private: bool GenerateMessages(const ::google::protobuf::FileDescriptor *file, - ::google::protobuf::compiler::GeneratorContext *generatorContext) const; + ::google::protobuf::compiler::GeneratorContext *generatorContext, + std::string *error) const; void GenerateHeader(const ::google::protobuf::FileDescriptor *file, - ::google::protobuf::compiler::GeneratorContext *generatorContext) const; + ::google::protobuf::compiler::GeneratorContext *generatorContext, + std::string *error) const; void GenerateSources(const ::google::protobuf::FileDescriptor *file, - ::google::protobuf::compiler::GeneratorContext *generatorContext) const; + ::google::protobuf::compiler::GeneratorContext *generatorContext, + std::string *error) const; }; } // namespace QtProtobuf diff --git a/src/tools/qtprotoccommon/commontemplates.cpp b/src/tools/qtprotoccommon/commontemplates.cpp index 5820ea19..b39d8bf3 100644 --- a/src/tools/qtprotoccommon/commontemplates.cpp +++ b/src/tools/qtprotoccommon/commontemplates.cpp @@ -472,6 +472,7 @@ const char *CommonTemplates::GetterMessageDeclarationTemplate() return "$export_macro$bool has$property_name_cap$() const;\n" "$export_macro$const $getter_type$ &$property_name$() const &;\n"; } + const char *CommonTemplates::GetterMessageDefinitionTemplate() { return "bool $classname$::has$property_name_cap$() const\n{\n" @@ -483,6 +484,20 @@ const char *CommonTemplates::GetterMessageDefinitionTemplate() "}\n\n"; } +const char *CommonTemplates::GetterMessageMutableDeclarationTemplate() +{ + return "$export_macro$$getter_type$ &$mutable_getter_name$() &;\n"; +} + +const char *CommonTemplates::GetterMessageMutableDefinitionTemplate() +{ + return "$getter_type$ &$classname$::$mutable_getter_name$() &\n" + "{\n" + " dptr.detach();\n" + " return *dptr->m_$property_name$;\n" + "}\n\n"; +} + const char *CommonTemplates::GetterComplexDeclarationTemplate() { return "$export_macro$const $getter_type$ &$property_name$() const &;\n"; @@ -495,6 +510,7 @@ const char *CommonTemplates::GetterComplexDefinitionTemplate() " return dptr->m_$property_name$;\n" "}\n\n"; } + const char *CommonTemplates::PrivateGetterOneofDeclarationTemplate() { return "$export_macro$$getter_type$ $property_name$_p() const;\n"; @@ -1048,3 +1064,8 @@ const char *CommonTemplates::MocIncludeTemplate() { return "#include \"$source_file$\"\n"; } + +const char *CommonTemplates::MutableGetterPrefix() +{ + return "mut"; +} diff --git a/src/tools/qtprotoccommon/commontemplates.h b/src/tools/qtprotoccommon/commontemplates.h index de981326..7e651608 100644 --- a/src/tools/qtprotoccommon/commontemplates.h +++ b/src/tools/qtprotoccommon/commontemplates.h @@ -100,6 +100,8 @@ public: static const char *ClearMessageDefinitionTemplate(); static const char *GetterMessageDeclarationTemplate(); static const char *GetterMessageDefinitionTemplate(); + static const char *GetterMessageMutableDeclarationTemplate(); + static const char *GetterMessageMutableDefinitionTemplate(); static const char *GetterComplexDeclarationTemplate(); static const char *GetterComplexDefinitionTemplate(); static const char *PrivateGetterOneofDeclarationTemplate(); @@ -187,6 +189,8 @@ public: static const char *QmlNamedElement(); static const char *MocIncludeTemplate(); + + static const char *MutableGetterPrefix(); }; } // namespace qtprotoccommon diff --git a/src/tools/qtprotoccommon/generatorcommon.cpp b/src/tools/qtprotoccommon/generatorcommon.cpp index eebfcf18..05df60e5 100644 --- a/src/tools/qtprotoccommon/generatorcommon.cpp +++ b/src/tools/qtprotoccommon/generatorcommon.cpp @@ -558,6 +558,9 @@ PropertyMap common::producePropertyMap(const FieldDescriptor *field, const Descr propertyMap["property_name"] = propertyName; propertyMap["property_name_cap"] = propertyNameCap; + propertyMap["mutable_getter_name"] = CommonTemplates::MutableGetterPrefix(); + propertyMap["mutable_getter_name"] += propertyNameCap; + propertyMap["scriptable"] = scriptable; propertyMap["export_macro"] = common::buildExportMacro(); diff --git a/src/tools/qtprotoccommon/options.cpp b/src/tools/qtprotoccommon/options.cpp index 51e37ca9..f6017df4 100644 --- a/src/tools/qtprotoccommon/options.cpp +++ b/src/tools/qtprotoccommon/options.cpp @@ -16,6 +16,7 @@ static const char FieldEnumGenerationOption[] = "FIELD_ENUM"; static const char ExtraNamespaceGenerationOption[] = "EXTRA_NAMESPACE"; static const char ExportMacroGenerationOption[] = "EXPORT_MACRO"; static const char HeaderGuardOption[] = "HEADER_GUARD"; +static const char MutableGetterConflicts[] = "ALLOW_MUTABLE_GETTER_CONFLICTS"; static const char ExportSuffix[] = "_exports.qpb.h"; @@ -23,7 +24,8 @@ static constexpr std::string_view HeaderGuardPragma = "pragma"; static constexpr std::string_view HeaderGuardProtoFilename = "filename"; Options::Options() - : m_generateComments(false), m_isFolder(false), m_generateFieldEnum(true), m_generateMacroExportFile(false), m_qml(false) + : m_generateComments(false), m_isFolder(false), m_generateFieldEnum(true), + m_generateMacroExportFile(false), m_qml(false), m_mutableGetterConflicts(false) { } @@ -111,6 +113,8 @@ void Options::setFromString(const std::string &options, GeneratorType /*unused*/ } else if (headerGuardValue != HeaderGuardProtoFilename) { QT_PROTOBUF_DEBUG("Unknown HEADER_GUARD option value"); } + } else if (option == MutableGetterConflicts) { + instance.m_mutableGetterConflicts = true; } } } diff --git a/src/tools/qtprotoccommon/options.h b/src/tools/qtprotoccommon/options.h index f17e5954..97d933be 100644 --- a/src/tools/qtprotoccommon/options.h +++ b/src/tools/qtprotoccommon/options.h @@ -46,6 +46,7 @@ public: const std::string &exportMacroFilename() const { return m_exportMacroFilename; } bool generateMacroExportFile() const { return m_generateMacroExportFile; } HeaderGuardType headerGuard() const { return m_headerGuard; } + bool mutableGetterConflicts() const { return m_mutableGetterConflicts; } private: bool m_generateComments; @@ -56,6 +57,8 @@ private: std::string m_exportMacroFilename; bool m_generateMacroExportFile; bool m_qml; + bool m_mutableGetterConflicts; + HeaderGuardType m_headerGuard = Options::HeaderGuardType::ProtoFilename; }; diff --git a/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp index b50c56b0..73825ce2 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_basictypes.cpp @@ -43,6 +43,7 @@ private Q_SLOTS: void moveOperatorTest(); void rvalueSettersTest(); void rvalueOneOfSettersTest(); + void mutableGetterTest(); void invalidMessageConstructorTest(); }; @@ -594,6 +595,41 @@ void QtProtobufTypesGenerationTest::rvalueOneOfSettersTest() } } +void QtProtobufTypesGenerationTest::mutableGetterTest() +{ + ComplexMessage complexMsg; + + const auto MutableGetterValue = "Value from mutable getter"_L1; + complexMsg.mutTestComplexField().setTestFieldString(MutableGetterValue); + QCOMPARE_EQ(MutableGetterValue, complexMsg.testComplexField().testFieldString()); + + const auto InitialFieldValue = "Value from standalone field"; + SimpleStringMessage complexFieldValue; + complexFieldValue.setTestFieldString(InitialFieldValue); + + complexMsg.setTestComplexField(complexFieldValue); + QCOMPARE_EQ(InitialFieldValue, complexMsg.testComplexField().testFieldString()); + + // Reset the field and ensure that it didn't affect the copied standalone + // field value. + complexMsg.mutTestComplexField().setTestFieldString(MutableGetterValue); + QCOMPARE_EQ(MutableGetterValue, complexMsg.testComplexField().testFieldString()); + QCOMPARE_EQ(InitialFieldValue, complexFieldValue.testFieldString()); + + // Make a shared copy of the complexMsg + ComplexMessage complexMsgCopy(complexMsg); + QCOMPARE_EQ(MutableGetterValue, complexMsgCopy.testComplexField().testFieldString()); + QCOMPARE_EQ(complexMsg.testComplexField().testFieldString(), + complexMsgCopy.testComplexField().testFieldString()); + + // Ensure that mutable getter detaches and the new value is not applied to + // to a shared copy. + const auto NewMutableGetterValue = "New value from mutable getter"_L1; + complexMsg.mutTestComplexField().setTestFieldString(NewMutableGetterValue); + QCOMPARE_EQ(MutableGetterValue, complexMsgCopy.testComplexField().testFieldString()); + QCOMPARE_EQ(NewMutableGetterValue, complexMsg.testComplexField().testFieldString()); +} + void QtProtobufTypesGenerationTest::invalidMessageConstructorTest() { QProtobufMessagePointer message(QProtobufMessage::constructByName( diff --git a/tests/auto/protobuf/syntax/CMakeLists.txt b/tests/auto/protobuf/syntax/CMakeLists.txt index fa494d33..0d4beebf 100644 --- a/tests/auto/protobuf/syntax/CMakeLists.txt +++ b/tests/auto/protobuf/syntax/CMakeLists.txt @@ -11,6 +11,7 @@ qt6_add_protobuf(tst_protobuf_syntax_qtprotobuf_gen PROTO_FILES ../../shared/data/proto/syntax.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" + ALLOW_MUTABLE_GETTER_CONFLICTS ) qt_autogen_tools_initial_setup(tst_protobuf_syntax_qtprotobuf_gen) diff --git a/tests/auto/protobuf/syntax/tst_protobuf_syntax.cpp b/tests/auto/protobuf/syntax/tst_protobuf_syntax.cpp index b63150df..39668f0f 100644 --- a/tests/auto/protobuf/syntax/tst_protobuf_syntax.cpp +++ b/tests/auto/protobuf/syntax/tst_protobuf_syntax.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -21,6 +22,8 @@ private Q_SLOTS: void reservedEnumTest(); void lowerCaseEnumTest(); void upperCaseEnumTest(); + + void mutableGetterConflicts(); }; using namespace qtprotobufnamespace::tests; @@ -119,5 +122,27 @@ void QtProtobufSyntaxTest::upperCaseEnumTest() QCOMPARE(simpleEnum.key(2), "EnumValue2"); } +void QtProtobufSyntaxTest::mutableGetterConflicts() +{ + NameClashingMutableGetters msg; + // Set 'data' field for the 'field' field using the mutable getter + msg.mutField().setData(1); + + // Set 'data' field for the 'mutField' field using the mutable getter + msg.mutMutField().setData(2); + + // Access the immutable 'field' field + QVERIFY(msg.field().data() == 1); + // Access the mutable 'field' field + QVERIFY(msg.mutField().data() == 1); + + // Access the immutable 'mutField' field + QVERIFY(std::as_const(msg).mutField().data() == 2); + + // Ensure we use the correct value in serialization + QVERIFY(!msg.property("mutField_p").isNull()); + QVERIFY(msg.property("mutField_p").value()->data() == 2); +} + QTEST_MAIN(QtProtobufSyntaxTest) #include "tst_protobuf_syntax.moc" diff --git a/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.h index b1abf85f..ecd0f402 100644 --- a/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_CUSTOM_EXPORT_NAME_EXPORT bool hasField1() const; QPB_CUSTOM_EXPORT_NAME_EXPORT const ScalarTypes &field1() const &; + QPB_CUSTOM_EXPORT_NAME_EXPORT ScalarTypes &mutField1() &; QPB_CUSTOM_EXPORT_NAME_EXPORT void clearField1(); QPB_CUSTOM_EXPORT_NAME_EXPORT const QList &field2() const &; QPB_CUSTOM_EXPORT_NAME_EXPORT bool hasField3() const; QPB_CUSTOM_EXPORT_NAME_EXPORT const ScalarTypes &field3() const &; + QPB_CUSTOM_EXPORT_NAME_EXPORT ScalarTypes &mutField3() &; QPB_CUSTOM_EXPORT_NAME_EXPORT void clearField3(); QPB_CUSTOM_EXPORT_NAME_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_CUSTOM_EXPORT_NAME_EXPORT bool hasField1() const; QPB_CUSTOM_EXPORT_NAME_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_CUSTOM_EXPORT_NAME_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_CUSTOM_EXPORT_NAME_EXPORT void clearField1(); QPB_CUSTOM_EXPORT_NAME_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_CUSTOM_EXPORT_NAME_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_CUSTOM_EXPORT_NAME_EXPORT bool hasField2() const; QPB_CUSTOM_EXPORT_NAME_EXPORT const MessageTypes &field2() const &; + QPB_CUSTOM_EXPORT_NAME_EXPORT MessageTypes &mutField2() &; QPB_CUSTOM_EXPORT_NAME_EXPORT void clearField2(); QPB_CUSTOM_EXPORT_NAME_EXPORT void setField1(QtProtobuf::int32 field1); QPB_CUSTOM_EXPORT_NAME_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.cpp index 048ae131..555c3de1 100644 --- a/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.h index 8ac218d3..03226fb8 100644 --- a/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT ScalarTypes &mutField1() &; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT ScalarTypes &mutField3() &; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT MessageTypes &mutField2() &; QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_EXTRA_NAMESPACE_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp index 78c43e4b..80233d56 100644 --- a/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h index dd2ef8bd..152a2542 100644 --- a/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT ScalarTypes &mutField1() &; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT ScalarTypes &mutField3() &; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT MessageTypes &mutField2() &; QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_GENERATE_PACKAGE_SUBFOLDERS_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.h index ff90977d..ea7a5876 100644 --- a/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT ScalarTypes &mutField1() &; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT ScalarTypes &mutField3() &; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT MessageTypes &mutField2() &; QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_NO_OPTIONS_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.h index eb993bd0..0f42e251 100644 --- a/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.h @@ -1141,12 +1141,14 @@ public: QPB_TST_QTPROTOBUFGEN_QML_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_QML_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_QML_EXPORT ScalarTypes &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_QML_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_QML_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_QML_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_QML_EXPORT ScalarTypes &mutField3() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_QML_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1259,6 +1261,7 @@ public: QPB_TST_QTPROTOBUFGEN_QML_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_QML_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_QML_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_QML_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_QML_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1321,6 +1324,7 @@ public: QPB_TST_QTPROTOBUFGEN_QML_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_QML_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_QML_EXPORT MessageTypes &mutField2() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_QML_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_QML_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.h index dc9bc4ac..57d0e7dd 100644 --- a/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.h @@ -1141,12 +1141,14 @@ public: QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT ScalarTypes &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT ScalarTypes &mutField3() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1259,6 +1261,7 @@ public: QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1321,6 +1324,7 @@ public: QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT MessageTypes &mutField2() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_QML_URI_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.h index 98500203..f86b3016 100644 --- a/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.h @@ -1115,12 +1115,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1230,6 +1232,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1289,6 +1292,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.h index 2041a209..3b4654b4 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField1() &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField3() &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageTypes &mutField2() &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.h index b80a2efc..928fa278 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT const QList &field2() const &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField3() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field3() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField3() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField3(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField2() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageTypes &field2() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageTypes &mutField2() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField2(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(QtProtobuf::int32 field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.h index 8c082bc7..18c550fe 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT const QList &field2() const &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField3() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field3() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField3() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField3(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField2() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageTypes &field2() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageTypes &mutField2() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField2(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(QtProtobuf::int32 field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.h index 328dc404..20b6cbb6 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.h @@ -1117,12 +1117,14 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT const QList &field2() const &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField3() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const ScalarTypes &field3() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT ScalarTypes &mutField3() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField3(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1232,6 +1234,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField1() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField1(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1291,6 +1294,7 @@ public: QPB_EXPORT_MACRO_WITH_FILE_EXPORT bool hasField2() const; QPB_EXPORT_MACRO_WITH_FILE_EXPORT const MessageTypes &field2() const &; + QPB_EXPORT_MACRO_WITH_FILE_EXPORT MessageTypes &mutField2() &; QPB_EXPORT_MACRO_WITH_FILE_EXPORT void clearField2(); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField1(QtProtobuf::int32 field1); QPB_EXPORT_MACRO_WITH_FILE_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.cpp index 048ae131..555c3de1 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.h index 69715ed3..3c6d2466 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.h @@ -1115,12 +1115,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1230,6 +1232,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1289,6 +1292,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp index 78c43e4b..80233d56 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h index 98500203..f86b3016 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h @@ -1115,12 +1115,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1230,6 +1232,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1289,6 +1292,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.h index 98500203..f86b3016 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.h @@ -1115,12 +1115,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1230,6 +1232,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1289,6 +1292,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.h index 7e2c5dc6..1d8c5d10 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.h @@ -1139,12 +1139,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; Q_INVOKABLE void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; Q_INVOKABLE void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1257,6 +1259,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1319,6 +1322,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; Q_INVOKABLE void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.h index 7e2c5dc6..1d8c5d10 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.h @@ -1139,12 +1139,14 @@ public: bool hasField1() const; const ScalarTypes &field1() const &; + ScalarTypes &mutField1() &; Q_INVOKABLE void clearField1(); const QList &field2() const &; bool hasField3() const; const ScalarTypes &field3() const &; + ScalarTypes &mutField3() &; Q_INVOKABLE void clearField3(); EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1257,6 +1259,7 @@ public: bool hasField1() const; const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE void clearField1(); void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1319,6 +1322,7 @@ public: bool hasField2() const; const MessageTypes &field2() const &; + MessageTypes &mutField2() &; Q_INVOKABLE void clearField2(); void setField1(QtProtobuf::int32 field1); void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.cpp index 518fef52..056865c9 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.h index 93c57513..56791056 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.h @@ -1141,12 +1141,14 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField3() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1259,6 +1261,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1321,6 +1324,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageTypes &mutField2() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp index 78c43e4b..80233d56 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.cpp @@ -3518,6 +3518,12 @@ const ScalarTypes &MessageTypes::field1() const & return *dptr->m_field1; } +ScalarTypes &MessageTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageTypes::clearField1() { if (dptr->m_field1) { @@ -3548,6 +3554,12 @@ const ScalarTypes &MessageTypes::field3() const & return *dptr->m_field3; } +ScalarTypes &MessageTypes::mutField3() & +{ + dptr.detach(); + return *dptr->m_field3; +} + void MessageTypes::clearField3() { if (dptr->m_field3) { @@ -3916,6 +3928,12 @@ const MessageTypes &NestedMessage::field2() const & return *dptr->m_field2; } +MessageTypes &NestedMessage::mutField2() & +{ + dptr.detach(); + return *dptr->m_field2; +} + void NestedMessage::clearField2() { if (dptr->m_field2) { @@ -4068,6 +4086,12 @@ const MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::fi return *dptr->m_field1; } +MessageNestedTypes_QtProtobufNested::NestedMessage &MessageNestedTypes::mutField1() & +{ + dptr.detach(); + return *dptr->m_field1; +} + void MessageNestedTypes::clearField1() { if (dptr->m_field1) { diff --git a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h index 93c57513..56791056 100644 --- a/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h +++ b/tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h @@ -1141,12 +1141,14 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const QList &field2() const &; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField3() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const ScalarTypes &field3() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT ScalarTypes &mutField3() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField3(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT EnumTypes_QtProtobufNested::NestedEnum field4() const; @@ -1259,6 +1261,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField1() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageNestedTypes_QtProtobufNested::NestedMessage &field1() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageNestedTypes_QtProtobufNested::NestedMessage &mutField1() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField1(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(const MessageNestedTypes_QtProtobufNested::NestedMessage &field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(MessageNestedTypes_QtProtobufNested::NestedMessage &&field1); @@ -1321,6 +1324,7 @@ public: QPB_TST_QTPROTOBUFGEN_GEN_EXPORT bool hasField2() const; QPB_TST_QTPROTOBUFGEN_GEN_EXPORT const MessageTypes &field2() const &; + QPB_TST_QTPROTOBUFGEN_GEN_EXPORT MessageTypes &mutField2() &; Q_INVOKABLE QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void clearField2(); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField1(QtProtobuf::int32 field1); QPB_TST_QTPROTOBUFGEN_GEN_EXPORT void setField2(const MessageTypes &field2); diff --git a/tests/auto/protobufgen/data/qtprotobufgen_mutable_getter_clashing.proto b/tests/auto/protobufgen/data/qtprotobufgen_mutable_getter_clashing.proto new file mode 100644 index 00000000..6c390215 --- /dev/null +++ b/tests/auto/protobufgen/data/qtprotobufgen_mutable_getter_clashing.proto @@ -0,0 +1,13 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +syntax = "proto3"; +package qt.protobuf; + +message MessageType { +} + +message MessageHoder { + MessageType mutField = 1; + MessageType field = 2; +} diff --git a/tests/auto/protobufgen/tst_qtprotobufgen.cpp b/tests/auto/protobufgen/tst_qtprotobufgen.cpp index 38a1bc7c..6fce564e 100644 --- a/tests/auto/protobufgen/tst_qtprotobufgen.cpp +++ b/tests/auto/protobufgen/tst_qtprotobufgen.cpp @@ -74,6 +74,8 @@ private Q_SLOTS: void cmdLineGenerated(); void cmdLineInvalidExportMacro_data(); void cmdLineInvalidExportMacro(); + + void cmdLineMutableGetterConflicts(); #endif void cleanupTestCase(); @@ -266,6 +268,31 @@ void qtprotobufgenTest::cmdLineInvalidExportMacro() QVERIFY2(process.exitStatus() == QProcess::NormalExit, msgProcessCrashed(process).constData()); QVERIFY2(process.exitCode() == result, msgProcessFailed(process).constData()); } + +void qtprotobufgenTest::cmdLineMutableGetterConflicts() +{ + static constexpr QLatin1StringView directory("invalid_export_macro"); + QDir outputDirectory(cmdLineGeneratedPath()); + if (!outputDirectory.exists(directory)) + outputDirectory.mkdir(directory); + outputDirectory.cd(directory); + + QProcess process; + process.setWorkingDirectory(cmdLineGeneratedPath()); + process.startCommand(ProtocPath + QString(" ") + PluginKey + QtprotobufgenPath + + OutKey + outputDirectory.absolutePath() + + IncludeKey + expectedResultPath() + + " " + expectedResultPath() + + "/qtprotobufgen_mutable_getter_clashing.proto"); + QVERIFY2(process.waitForStarted(), msgProcessStartFailed(process).constData()); + if (!process.waitForFinished()) { + process.kill(); + QFAIL(msgProcessTimeout(process).constData()); + } + QVERIFY2(process.exitStatus() == QProcess::NormalExit, msgProcessCrashed(process).constData()); + QVERIFY2(process.exitCode() == 1, msgProcessFailed(process).constData()); +} + #endif // QT_CONFIG(process) void qtprotobufgenTest::cleanupTestCase() diff --git a/tests/auto/protobufqml/syntax/CMakeLists.txt b/tests/auto/protobufqml/syntax/CMakeLists.txt index e4edfcd7..94b9620c 100644 --- a/tests/auto/protobufqml/syntax/CMakeLists.txt +++ b/tests/auto/protobufqml/syntax/CMakeLists.txt @@ -23,6 +23,7 @@ qt_add_protobuf(tst_protobuf_syntax_qml_gen ../../shared/data/proto/syntax.proto QML OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" + ALLOW_MUTABLE_GETTER_CONFLICTS ) qt_add_qml_module(tst_protobuf_syntax_qml @@ -43,4 +44,3 @@ qt_autogen_tools_initial_setup(tst_protobuf_syntax_qml_genplugin) if(QT_BUILD_STANDALONE_TESTS) qt_import_qml_plugins(tst_protobuf_syntax_qml) endif() - diff --git a/tests/auto/protobufqml/syntax/qml/tst_syntax.qml b/tests/auto/protobufqml/syntax/qml/tst_syntax.qml index 017d43c4..4265590a 100644 --- a/tests/auto/protobufqml/syntax/qml/tst_syntax.qml +++ b/tests/auto/protobufqml/syntax/qml/tst_syntax.qml @@ -21,6 +21,7 @@ TestCase { property messageReserved msgReserved; property priorMessageUnderscoreField underScoreMsg; property lowerCaseMessageName lowerCaseMsg; + property nameClashingMutableGetters mutableGettersMsg; function initTestCase() { underscore_name.testField = -7 @@ -105,4 +106,14 @@ TestCase { function test_enumValues(data) { compare(data.field, data.answer) } + + function test_mutableGetters() { + mutableGettersMsg.field.data = 1; + mutableGettersMsg.mutField.data = 2; + + compare(Number(mutableGettersMsg.field.data), 1); + expectFailContinue("", "Property getter of 'mutField' accesses non-const getter,"+ + " which clashes to mutable getter of 'field'. See QTBUG-119912.") + compare(Number(mutableGettersMsg.mutField.data), 2); + } } diff --git a/tests/auto/shared/data/proto/syntax.proto b/tests/auto/shared/data/proto/syntax.proto index 19556194..36cb4210 100644 --- a/tests/auto/shared/data/proto/syntax.proto +++ b/tests/auto/shared/data/proto/syntax.proto @@ -144,3 +144,12 @@ message NameClashingMap { int32 Field1_Entry = 2; int32 Field2Entry = 3; } + +message MutFieldMessage { + int32 data = 1; +} + +message NameClashingMutableGetters { + MutFieldMessage field = 1; + MutFieldMessage mutField = 2; +}