From 1b6b1aab8353ff4a41de3a2078b1ea0beaa7418e Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Thu, 22 Jun 2023 14:23:48 +0200 Subject: [PATCH] Registration of Qt Protobuf types is moved into auto-generated code - updated qtprotobufgen test respectively Task-number: QTBUG-104513 Pick-to: 6.6 Change-Id: I6b7c4a963602e6885c9f7412485c6c49c057081b Reviewed-by: Alexey Edelev Reviewed-by: Qt CI Bot --- src/tools/qtprotobufgen/qprotobufgenerator.cpp | 7 ++++--- src/tools/qtprotoccommon/commontemplates.cpp | 5 +++++ src/tools/qtprotoccommon/commontemplates.h | 1 + .../qml-no-package/nopackage_uri_testplugin.cpp | 2 ++ .../qmlgen/qtprotobufnamespace_testsplugin.cpp | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tools/qtprotobufgen/qprotobufgenerator.cpp b/src/tools/qtprotobufgen/qprotobufgenerator.cpp index 27d40dd6..ec3038d3 100644 --- a/src/tools/qtprotobufgen/qprotobufgenerator.cpp +++ b/src/tools/qtprotobufgen/qprotobufgenerator.cpp @@ -156,7 +156,7 @@ bool QProtobufGenerator::GenerateAll(const std::vector & for (const FileDescriptor *file: files) { GenerateQmlPluginSource(file, registrationPluginPrinter); } - + registrationPluginPrinter->Print(CommonTemplates::QmlRegisterProtobufTypes()); registrationPluginPrinter->Indent(); registrationPluginPrinter->Indent(); registrationPluginPrinter->Print(CommonTemplates::SimpleBlockEnclosureTemplate()); @@ -182,9 +182,10 @@ void QProtobufGenerator::GenerateQmlPluginIntro(Printer *printer, } printDisclaimer(printer); - const std::array qmlHeaders = {"QtQml/qqmlextensionplugin.h", + const std::array qmlHeaders = {"QtQml/qqmlextensionplugin.h", "QtQml/qqml.h", - "QtQml/qqmlengine.h"}; + "QtQml/qqmlengine.h", + "QtProtobuf/qtprotobuftypes.h"}; for (const auto &header : qmlHeaders) { printer->Print({{"include", header}}, CommonTemplates::ExternalIncludeTemplate()); diff --git a/src/tools/qtprotoccommon/commontemplates.cpp b/src/tools/qtprotoccommon/commontemplates.cpp index 367b2134..68e7489d 100644 --- a/src/tools/qtprotoccommon/commontemplates.cpp +++ b/src/tools/qtprotoccommon/commontemplates.cpp @@ -947,6 +947,11 @@ const char *CommonTemplates::QmlRegisterMessageTypeTemplate() "but not create its instances in QML scope.\");\n"; } +const char *CommonTemplates::QmlRegisterProtobufTypes() +{ + return " qRegisterProtobufTypes();\n"; +} + const char *CommonTemplates::RepeatedSuffix() { return "Repeated"; diff --git a/src/tools/qtprotoccommon/commontemplates.h b/src/tools/qtprotoccommon/commontemplates.h index b12c04ac..2179cb5c 100644 --- a/src/tools/qtprotoccommon/commontemplates.h +++ b/src/tools/qtprotoccommon/commontemplates.h @@ -184,6 +184,7 @@ public: static const char *QmlRegisterTypeTemplate(); static const char *QmlRegisterGlobalEnumTypeTemplate(); static const char *QmlRegisterMessageTypeTemplate(); + static const char *QmlRegisterProtobufTypes(); static const char *RepeatedSuffix(); static const char *ProtoFileSuffix(); diff --git a/tests/auto/protobufgen/data/expected_result/qml-no-package/nopackage_uri_testplugin.cpp b/tests/auto/protobufgen/data/expected_result/qml-no-package/nopackage_uri_testplugin.cpp index 8b49d90a..3b8eb982 100644 --- a/tests/auto/protobufgen/data/expected_result/qml-no-package/nopackage_uri_testplugin.cpp +++ b/tests/auto/protobufgen/data/expected_result/qml-no-package/nopackage_uri_testplugin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "nopackage.qpb.h" #include "nopackageexternal.qpb.h" @@ -21,6 +22,7 @@ public: qmlRegisterUncreatableMetaObject( ::TestEnumGadget::staticMetaObject, uri, 1, 0, "TestEnum", "You can only use the nested enums of TestEnum, but not create its instances in QML scope."); + qRegisterProtobufTypes(); } }; diff --git a/tests/auto/protobufgen/data/expected_result/qmlgen/qtprotobufnamespace_testsplugin.cpp b/tests/auto/protobufgen/data/expected_result/qmlgen/qtprotobufnamespace_testsplugin.cpp index 3cc70ec4..01375ac0 100644 --- a/tests/auto/protobufgen/data/expected_result/qmlgen/qtprotobufnamespace_testsplugin.cpp +++ b/tests/auto/protobufgen/data/expected_result/qmlgen/qtprotobufnamespace_testsplugin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "basicmessages.qpb.h" #include "enummessages.qpb.h" @@ -33,6 +34,7 @@ public: qmlRegisterUncreatableMetaObject( qtprotobufnamespace::tests::TestEnumSecondInFileGadget::staticMetaObject, uri, 1, 0, "TestEnumSecondInFile", "You can only use the nested enums of TestEnumSecondInFile, but not create its instances in QML scope."); + qRegisterProtobufTypes(); } };