Commit Graph

4 Commits

Author SHA1 Message Date
Alexey Edelev d6586d97a1 Long live mutable getters
The functionality is desirable by some users, we re-enable it.
New API addresses the core issue that is partially related to
QTBUG-119912, but has wider concequences in blind use in user
projects. We add the 'mut' prefix to all mutable getters to make
the mutable access explicit. Overload approach leads to unwanted
detaches not only whe is used be moc-generated code, but also
in user projects if developers do not pay enough attention to
const modifiers of their variables/references. We declined to
restore it, dispite it was the better looking API, in favor to
the code safety.

This also reveals the code clashing scenario, when the overload
might happen if the message has both 'a' and 'mutA' fields in
its definition. This scenario is kindly forbidden by our generator,
and sanitized at very early stages. We expect that it won't happen
in user projects, but even if it will, the solution is to rename
the field when generating Qt code. The serialization/deserialization
do not depend on field naming directly. json_name attribute also
will help to workaround this.

The undocumented ALLOW_MUTABLE_GETTER_CONFLICTS option allows clashing
the mutable getter names, but its usage currently limited by our
internal code only. The reason unfixed QTBUG-119912 issue in moc.
Once the issue is fixed, the moc version check should get the proper
version, but not '99' as for now and the ALLOW_MUTABLE_GETTER_CONFLICTS
will become public.

Another design solution is the use of overloaded functions that
return pointers, like it's done it the reference protobuf. But this
kind of API leaves the pointer ownership undefined and decided to
not be used.

[ChangeLog][Protobuf] The generated messages now have the mutable
getters for the fiels of the message type. The getters have 'mut'
prefix and implicily allocate the respective fields if needed, so the
use of intermediate message objects is not required.

Task-number: QTBUG-119913
Change-Id: I09b9ee37e1fbbe37b9c3cb501e92442da8ad3e4b
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2025-04-04 17:45:22 +02:00
Alexey Edelev 4b778a70d0 Avoid generating QList aliases for the protobuf messages
Generating the aliases for protobuf QList types leads to the name
clashing when users want ot introduce messages that have name
consisting of previously defined message name and Repeated suffix,
e.g.:
  message MyMessage {
  }
  message MyMessageRepeated {
  }

We shouldn't prohibit the above scheme in our generators and generate
the respective messages correctly. The only possible solution -
complete removal of the protobuf messages QList aliases.

Generator still generates the aliases guarded by the
QT_USE_PROTOBUF_LIST_ALIASES macro. The macro is enabled by
Qt::Protobuf when building using CMake, but can be disabled at any
time by setting QT_USE_PROTOBUF_LIST_ALIASES property on protobuf
target to avoid name clashing.

[ChangeLog][Protobuf] qtprotobufgen doesn't generate protobuf message
QList aliases. All usages of aliases should be replace by respective
QList types. Aliases are still generated and are guarded by the
QT_USE_PROTOBUF_LIST_ALIASES macro in the generated code. The macro
is enabled by default and can be disabled using
QT_USE_PROTOBUF_LIST_ALIASES target property.

Fixes: QTBUG-129652
Pick-to: 6.8 6.9
Change-Id: I026755b36985eef01a6851156d9c9cfff141d247
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-12-16 09:57:33 +01:00
Dennis Oberst 995012aa82 qtprotobufgen: add QVariant operator for value-type messages
Value type classes in Qt usually contain an implicit QVariant opeartor.
Add it to comply with idiomatic Qt patterns.

Task-number: QTBUG-129161
Change-Id: Ib9ccd0cdfa7d6d6c2440323d1cc9b6088ea554c6
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-12-06 18:14:16 +01:00
Alexey Edelev ce98c06105 Refactor the qtprotobufgen test
Use the common .proto scheme for all testcases, that defined lot of
message variants, so we can see how changes in generator affect
various types but not only restricted subset.

Rearrange the test cases according to the generator options.

Change the verification process for command line tests. Consider not
only some files but all generated files, so we can see if some new
file is added or some files are remove/renamed.

Simplify tests.

Add the COPY_TEST_RESULTS environment variable support. This variable
now allows copying test results to the source directory. The introduced
functionality is very handy when need update expected results after the
major changes in generator.

Add the respective feature guards for the QProcess usage. In case if
the feature is disabled in QtCore.

Pick-to: 6.8
Task-number: QTBUG-128753
Change-Id: I5ac33684c8cf4fd5dd133b404061db4435a87344
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2024-09-30 16:06:05 +02:00