Browse Source

Basic port of QtProtobuf module to Qt6

Alexey Edelev 3 years ago
parent
commit
4026995c4f
100 changed files with 1070 additions and 1348 deletions
  1. 2 0
      .cmake.conf
  2. 5 5
      CHANGES.txt
  3. 14 169
      CMakeLists.txt
  4. 11 11
      README.md
  5. 3 3
      cmake/QtProtobufInternalHelpers.cmake
  6. 0 38
      cmake/QtProtobufTestHelpers.cmake
  7. 1 1
      examples/addressbook/main.cpp
  8. 1 1
      examples/clienttutorial/CMakeLists.txt
  9. 4 4
      examples/clienttutorial/main.cpp
  10. 1 1
      examples/fieldenum/field_enum_example.pro
  11. 1 1
      examples/qmakeexample/main.cpp
  12. 1 1
      examples/qmakeexample/qmakeexample.pro
  13. 1 1
      examples/simplechat/main.cpp
  14. 13 0
      src/CMakeLists.txt
  15. 19 15
      src/generator/CMakeLists.txt
  16. 1 1
      src/generator/clientdeclarationprinter.cpp
  17. 9 9
      src/generator/generatorbase.h
  18. 1 1
      src/generator/messagedeclarationprinter.cpp
  19. 0 1
      src/generator/servicedeclarationprinterbase.cpp
  20. 29 29
      src/generator/templates.cpp
  21. 37 49
      src/grpc/CMakeLists.txt
  22. 4 3
      src/grpc/qabstractgrpcchannel.cpp
  23. 8 8
      src/grpc/qabstractgrpcchannel.h
  24. 14 14
      src/grpc/qabstractgrpcclient.cpp
  25. 10 17
      src/grpc/qabstractgrpcclient.h
  26. 5 4
      src/grpc/qabstractgrpccredentials.h
  27. 7 6
      src/grpc/qgrpcasyncoperationbase.cpp
  28. 5 6
      src/grpc/qgrpcasyncoperationbase.h
  29. 3 1
      src/grpc/qgrpccallreply.cpp
  30. 6 5
      src/grpc/qgrpccallreply.h
  31. 5 5
      src/grpc/qgrpcchannel.cpp
  32. 4 2
      src/grpc/qgrpccredentials.cpp
  33. 18 17
      src/grpc/qgrpccredentials.h
  34. 41 30
      src/grpc/qgrpchttp2channel.cpp
  35. 6 5
      src/grpc/qgrpchttp2channel.h
  36. 9 6
      src/grpc/qgrpcinsecurecredentials.h
  37. 7 6
      src/grpc/qgrpcsslcredentials.h
  38. 5 4
      src/grpc/qgrpcstatus.cpp
  39. 13 10
      src/grpc/qgrpcstatus.h
  40. 7 4
      src/grpc/qgrpcstream.cpp
  41. 8 9
      src/grpc/qgrpcstream.h
  42. 7 6
      src/grpc/qgrpcuserpasswordcredentials.h
  43. 8 6
      src/grpc/qtgrpcglobal.h
  44. 7 3
      src/grpc/qtgrpclogging.cpp
  45. 36 0
      src/grpc/qtgrpclogging_p.h
  46. 9 9
      src/grpc/quick/qquickgrpcstream.cpp
  47. 24 54
      src/protobuf/CMakeLists.txt
  48. 63 27
      src/protobuf/cmake/Qt6ProtobufMacro.cmake
  49. 1 7
      src/protobuf/cmake/QtPreParseProtoFile.cmake
  50. 6 3
      src/protobuf/qabstractprotobufserializer.cpp
  51. 16 17
      src/protobuf/qabstractprotobufserializer.h
  52. 23 30
      src/protobuf/qabstractprotobufserializercommon.h
  53. 13 15
      src/protobuf/qprotobufjsonserializer.cpp
  54. 8 8
      src/protobuf/qprotobufjsonserializer.h
  55. 10 5
      src/protobuf/qprotobuflazymessagepointer.h
  56. 5 1
      src/protobuf/qprotobufmetaobject.cpp
  57. 5 5
      src/protobuf/qprotobufmetaobject.h
  58. 4 1
      src/protobuf/qprotobufmetaproperty.cpp
  59. 4 5
      src/protobuf/qprotobufmetaproperty.h
  60. 6 7
      src/protobuf/qprotobufobject.h
  61. 9 9
      src/protobuf/qprotobufselfcheckiterator.h
  62. 9 10
      src/protobuf/qprotobufserializationplugininterface.h
  63. 43 41
      src/protobuf/qprotobufserializer.cpp
  64. 8 8
      src/protobuf/qprotobufserializer.h
  65. 20 20
      src/protobuf/qprotobufserializer_p.h
  66. 8 10
      src/protobuf/qprotobufserializerregistry.cpp
  67. 3 2
      src/protobuf/qprotobufserializerregistry_p.h
  68. 1 1
      src/protobuf/qt_lib_protobuf.pri.in
  69. 35 37
      src/protobuf/qtprotobuf.cpp
  70. 2 2
      src/protobuf/qtprotobufglobal.h
  71. 6 2
      src/protobuf/qtprotobuflogging.cpp
  72. 0 35
      src/protobuf/qtprotobuflogging.h
  73. 8 16
      src/protobuf/qtprotobuflogging_p.h
  74. 15 16
      src/protobuf/qtprotobufqmllistpropertyconstructor.h
  75. 20 19
      src/protobuf/qtprotobuftypes.h
  76. 93 0
      src/protobufquick/CMakeLists.txt
  77. 0 0
      src/protobufquick/qmldir
  78. 0 0
      src/protobufquick/qtprotobufquick_global.h
  79. 8 8
      src/protobufquick/qtprotobufquickplugin.cpp
  80. 9 4
      src/protobufquick/qtprotobufquickplugin_p.h
  81. 31 33
      src/qttypes/CMakeLists.txt
  82. 12 13
      src/qttypes/qtprotobufqttypes.cpp
  83. 4 4
      src/qttypes/qtprotobufqttypes.h
  84. 32 34
      src/wellknowntypes/CMakeLists.txt
  85. 1 1
      src/wellknowntypes/dummy.cpp
  86. 11 0
      sync.profile
  87. 4 40
      tests/CMakeLists.txt
  88. 12 0
      tests/auto/CMakeLists.txt
  89. 0 0
      tests/auto/shared/proto/annotation.proto
  90. 71 0
      tests/auto/shared/proto/basicmessages.proto
  91. 0 0
      tests/auto/shared/proto/crossfiletest.proto_disabled
  92. 0 0
      tests/auto/shared/proto/duplicated_metatypes.proto
  93. 0 0
      tests/auto/shared/proto/duplicated_metatypes_external.proto
  94. 0 0
      tests/auto/shared/proto/externalpackagetest.proto
  95. 0 0
      tests/auto/shared/proto/globalenums.proto
  96. 0 0
      tests/auto/shared/proto/globalenumssamenamespace.proto
  97. 1 271
      tests/auto/shared/proto/mapmessages.proto
  98. 0 0
      tests/auto/shared/proto/nestedmessages.proto
  99. 0 0
      tests/auto/shared/proto/nopackage.proto
  100. 0 0
      tests/auto/shared/proto/nopackageexternal.proto

+ 2 - 0
.cmake.conf

@@ -0,0 +1,2 @@
+set(QT_REPO_MODULE_VERSION "6.3.0")
+set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1")

+ 5 - 5
CHANGES.txt

@@ -46,7 +46,7 @@
     * Improve serializer reentrancy
     * Add static linking for quick plugins
     * Add basic tutorial
-    * Replace qtprotobuf_link_archive with qtprotobuf_link_target
+    * Replace qtprotobuf_link_archive with _qt_internal_link_protobuf_objects
     * Fix static build for well-known types
     * Fix CPack packaging paths
     * Implement "invalid" fields handling in json serializer
@@ -67,17 +67,17 @@
     * Add static compilation for win32 platforms
     generator
     * Fix empty message warning for copy and move operators
-    
+
 2020-02-26 version 0.2.0 (generator/QtProtobuf)
 
     QtProtobuf
-    * Rename generate_qtprotobuf to qtprotobuf_generate
-    * Migrate to new types registration approach. All protobuf types including generated might be registred by calling 'QtProtobuf::qRegisterProtobufTypes()'
+    * Rename generate_qtprotobuf to qt6_protobuf_generate
+    * Migrate to new types registration approach. All protobuf types including generated might be registred by calling 'qRegisterProtobufTypes()'
     * Add basic qmake build procedures support
     * Update well-known types registration. Migrate to common types registration
     * Add .deb package generation based on CPack
     * Add static build support
-    * Migate to options-based parameters for qtprotobuf_generate
+    * Migate to options-based parameters for qt6_protobuf_generate
     * Migrate to whole-archive linking for generated code
     * Supress boringssl warning when compile for windows
     generator

+ 14 - 169
CMakeLists.txt

@@ -1,174 +1,19 @@
-cmake_minimum_required(VERSION 3.16...3.22)
+cmake_minimum_required(VERSION 3.16)
 
-set(QT_PROTOBUF_VERSION 0.6.0)
-set(QT_PROTOBUF_NAMESPACE QtProtobuf)
-set(QT_PREFIX Qt)
-set(QT_VERSIONED_PREFIX Qt6)
+include(.cmake.conf)
+project(QtProtobuf
+    VERSION "${QT_REPO_MODULE_VERSION}"
+    DESCRIPTION "Qt gRPC and Protobuf generator and bindings."
+    HOMEPAGE_URL "https://github.com/semlanik/qtprotobuf"
+    LANGUAGES CXX C
+)
 
-project(${QT_PROTOBUF_NAMESPACE} VERSION ${QT_PROTOBUF_VERSION} LANGUAGES CXX)
+# Make sure we use the fixed BASE argument of qt_add_resource.
+set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE)
 
-# Conan support, optional
-if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
-    include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
-    conan_basic_setup()
-endif()
+find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core Network)
+find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Quick Qml Test QuickTest)
 
-include(GNUInstallDirs)
-include(CMakePackageConfigHelpers)
+include("${CMAKE_CURRENT_LIST_DIR}/src/protobuf/cmake/Qt6ProtobufMacro.cmake")
 
-set(QT_PROTOBUF_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-set(QT_PROTOBUF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
-set(QT_PROTOBUF_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
-
-list(PREPEND CMAKE_MODULE_PATH ${QT_PROTOBUF_CMAKE_DIR})
-
-find_package(WrapgRPC)
-if(NOT CMAKE_CROSSCOMPILING)
-    find_package(WrapProtobuf COMPONENTS Protoc OPTIONAL_COMPONENTS Generator Protobuf REQUIRED)
-else()
-    if(NOT QT_PROTOBUF_HOST_PATH)
-        message(FATAL_ERROR "QT_PROTOBUF_HOST_PATH is not specified. You shall specify
-QT_PROTOBUF_HOST_PATH to find the host version of QtProtobufGenerator")
-    endif()
-    find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS ProtobufGenerator CONFIG REQUIRED
-        PATHS ${QT_PROTOBUF_HOST_PATH}
-        NO_DEFAULT_PATH
-    )
-endif()
-find_package(Threads)
-find_package(${QT_VERSIONED_PREFIX} COMPONENTS Core Qml CONFIG REQUIRED)
-find_package(${QT_VERSIONED_PREFIX} OPTIONAL_COMPONENTS Network Quick Gui CONFIG)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_POSITION_INDEPENDENT_CODE ${${QT_VERSIONED_PREFIX}_POSITION_INDEPENDENT_CODE})
-if(UNIX)
-    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-        # using Clang
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-pessimizing-move -Wno-mismatched-tags -Wno-unused-private-field -Wno-self-assign-overloaded")
-    elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
-        # using GCC
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=deprecated-declarations")
-    endif()
-elseif(WIN32)
-    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
-#TODO: not all l4 warnings are fixed for MSVC. Enable options bellow
-#      once fixed
-#        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W4 /MD")
-#        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W4 /MD")
-        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /wd4005")
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4005")
-    else()
-        message(WARNING "Only MSVC compilers family are supported for build")
-    endif()
-endif()
-
-include(QtProtobufInternalHelpers)
-include(QtProtobufCoverage)
-include(QtProtobufGen)
-
-qt_protobuf_internal_check_install()
-
-set(PROTOBUF_QUICK_PLUGIN_NAME protobufquickplugin)
-set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
-
-set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
-set(QT_PROTOBUF_STANDALONE_TESTS OFF CACHE BOOL "Enable QtProtobuf tests build")
-set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
-set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
-set(QT_PROTOBUF_FIELD_ENUM OFF CACHE BOOL "Enable generation of enumeration with fields numbers for well-known and Qt types libraries")
-set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF CACHE BOOL "Enable native gRPC channel implementation")
-
-if(NOT QT_PROTOBUF_STANDALONE_TESTS)
-    if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)
-        if(NOT WrapgRPC_FOUND OR NOT Threads_FOUND)
-            message("QT_PROTOBUF_NATIVE_GRPC_CHANNEL is ON, but required dependencies are not found.")
-            set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF)
-        endif()
-    endif()
-
-    if(CMAKE_CROSSCOMPILING)
-        set(QT_PROTOBUF_MAKE_TESTS OFF)
-        set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
-    endif()
-
-    set(QT_PROTOBUF_STATIC OFF CACHE INTERNAL "" FORCE)
-    if(NOT BUILD_SHARED_LIBS)
-        set(QT_PROTOBUF_STATIC ON CACHE INTERNAL "" FORCE)
-    endif()
-
-    set(extra_type_libraries_options "") #Prevent to set from outside
-    if(QT_PROTOBUF_FIELD_ENUM)
-        set(extra_type_libraries_options "FIELDENUM ${extra_type_libraries_options}")
-    endif()
-
-    configure_package_config_file(
-         "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
-         INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
-
-    install(FILES "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
-        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
-        COMPONENT dev
-    )
-    export(PACKAGE ${QT_PROTOBUF_NAMESPACE})
-    install(FILES "${QT_PROTOBUF_CMAKE_DIR}/FindWrapProtobuf.cmake"
-        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
-        COMPONENT dev
-    )
-
-    if(NOT CMAKE_CROSSCOMPILING)
-        add_subdirectory("src/generator")
-    endif()
-
-    add_subdirectory("src/protobuf")
-    if(TARGET ${QT_VERSIONED_PREFIX}::Network)
-        if(${QT_VERSIONED_PREFIX}Core_VERSION VERSION_LESS "5.12.4")
-            # grpc target requires QT version not less than 5.12.4
-            # earlier versions Http2DirectAttribute is broken: https://doc.qt.io/qt-5/whatsnew511.html
-            #                                                  https://bugreports.qt.io/browse/QTBUG-74765
-            message(WARNING "QtGrpc requires the Qt framework version 5.12.4 or higher")
-        else()
-            add_subdirectory("src/grpc")
-        endif()
-    endif()
-
-    if(TARGET protobuf::libprotobuf AND TARGET protobuf::protoc)
-         add_subdirectory("src/wellknowntypes")
-    endif()
-    if(TARGET ${QT_VERSIONED_PREFIX}::Gui AND TARGET protobuf::protoc)
-        add_subdirectory("src/qttypes")
-    endif()
-else()
-    # Disable any installtion rules if build tests only
-    set(QT_PROTOBUF_INSTALL FALSE CACHE INTERNAL "" FORCE)
-    set(QT_PROTOBUF_MAKE_TESTS TRUE)
-endif()
-
-if(QT_PROTOBUF_MAKE_TESTS)
-    find_package(WrapGTest)
-    find_package(${QT_VERSIONED_PREFIX} OPTIONAL_COMPONENTS Test QuickTest CONFIG)
-    if(WrapGTest_FOUND AND TARGET ${QT_VERSIONED_PREFIX}::Test)
-        enable_testing()
-        add_subdirectory("tests")
-    else()
-        message(STATUS "googletest not found. Force disable tests.")
-    endif()
-endif()
-
-if(QT_PROTOBUF_MAKE_EXAMPLES AND NOT QT_PROTOBUF_STANDALONE_TESTS)
-    if(TARGET ${QT_VERSIONED_PREFIX}::Quick)
-        add_subdirectory("examples")
-    else()
-        message(STATUS "${QT_VERSIONED_PREFIX}::Quick is not found. Disable examples")
-    endif()
-endif()
-
-if(QT_PROTOBUF_INSTALL)
-    include(packaging)
-endif()
-include(doxygen)
-
-qt_protobuf_internal_install_targets()
+qt_build_repo()

+ 11 - 11
README.md

@@ -417,7 +417,7 @@ file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/path/to/protofile1.pr
 # Function below generates source files for specified PROTO_FILES,
 # and link them to the MyTarget as static library
 add_executable(MyTarget main.cpp) # Add your target here
-qtprotobuf_generate(TARGET MyTarget
+qt6_protobuf_generate(TARGET MyTarget
 OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
 PROTO_FILES ${PROTO_FILES})
 
@@ -427,13 +427,13 @@ Another option is to pre-specify expected generated headers to prevent dummy-par
 
 ```cmake
 ...
-qtprotobuf_generate(TARGET MyTarget
+qt6_protobuf_generate(TARGET MyTarget
 OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
 PROTO_FILES ${PROTO_FILES})
 ...
 ```
 
-In case if you somehow avoided ```qtprotobuf_generate``` usage, you need manualy link QtProtobuf libraries used by project, e.g.:
+In case if you somehow avoided ```qt6_protobuf_generate``` usage, you need manualy link QtProtobuf libraries used by project, e.g.:
 ```cmake
 ...
 target_link_libraries(${TARGET} QtProtobuf::Protobuf QtProtobuf::Grpc QtProtobuf::ProtobufWellKnownTypes)
@@ -441,9 +441,9 @@ target_link_libraries(${TARGET} QtProtobuf::Protobuf QtProtobuf::Grpc QtProtobuf
 ```
 
 ### CMake functions reference
-#### qtprotobuf_generate
+#### qt6_protobuf_generate
 
-qtprotobuf_generate is cmake helper function that automatically generates STATIC library target from your .proto files
+qt6_protobuf_generate is cmake helper function that automatically generates STATIC library target from your .proto files
 
 ***Parameters:***
 
@@ -475,9 +475,9 @@ qtprotobuf_generate is cmake helper function that automatically generates STATIC
 
 *EXTRA_NAMESPACE <namespace>* - Wraps the generated code with the specified namespace. (EXPERIMETAL)
 
-#### qtprotobuf_link_target
+#### _qt_internal_link_protobuf_objects
 
-qtprotobuf_link_target is cmake helper function that links generated protobuf target to your binary. It's useful when you try to link generated target to shared library or/and to executable that doesn't utilize all protobuf generated classes directly from C++ code, but requires them from QML.
+_qt_internal_link_protobuf_objects is cmake helper function that links generated protobuf target to your binary. It's useful when you try to link generated target to shared library or/and to executable that doesn't utilize all protobuf generated classes directly from C++ code, but requires them from QML.
 
 ***Parameters:***
 
@@ -511,12 +511,12 @@ Once build and installation is finished, you may use QtProtobuf and QtGrpc in qm
 QT += protobuf #for protobuf libraries support
 QT += grpc #for grpc libraries support
 ```
-To generate source code and link it to you project use predefined *qtprotobuf_generate* function
+To generate source code and link it to you project use predefined *qt6_protobuf_generate* function
 
 ### qmake functions reference
-#### qtprotobuf_generate([generate_qml=false])
+#### qt6_protobuf_generate([generate_qml=false])
 
-qtprotobuf_generate is qmake helper [test function](https://doc.qt.io/qt-5/qmake-language.html#test-functions) that generates QtProtobuf source code based on files provided by PROTO_FILES global context variable
+qt6_protobuf_generate is qmake helper [test function](https://doc.qt.io/qt-5/qmake-language.html#test-functions) that generates QtProtobuf source code based on files provided by PROTO_FILES global context variable
 
 ***Parameters:***
 
@@ -535,7 +535,7 @@ To enable QtProtobuf project you need to register protobuf types. It's good prac
 ...
 int main(int argc, char *argv[])
 {
-QtProtobuf::qRegisterProtobufTypes();
+qRegisterProtobufTypes();
 ... //Qt application initialization and run
 }
 ```

+ 3 - 3
cmake/QtProtobufInternalHelpers.cmake

@@ -49,7 +49,7 @@ function(qt_protobuf_internal_add_test)
         set(EXTRA_OPTIONS ${EXTRA_OPTIONS} EXTRA_NAMESPACE ${add_test_target_EXTRA_NAMESPACE})
     endif()
 
-    qtprotobuf_generate(TARGET ${add_test_target_TARGET}
+    qt6_protobuf_generate(TARGET ${add_test_target_TARGET}
         OUTPUT_DIRECTORY ${GENERATED_SOURCES_DIR}
         PROTO_FILES ${proto_files}
         EXCLUDE_HEADERS ${add_test_target_EXCLUDE_HEADERS}
@@ -81,8 +81,8 @@ function(qt_protobuf_internal_add_example)
     file(GLOB SOURCES ${arg_SOURCES})
 
     add_executable(${arg_TARGET} ${SOURCES} ${arg_RESOURCES})
-    qtprotobuf_generate(TARGET ${arg_TARGET}
-        OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
+    qt6_protobuf_generate(TARGET ${arg_TARGET}
+        OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated
         PROTO_FILES ${PROTO_FILES}
         QML)
 

+ 0 - 38
cmake/QtProtobufTestHelpers.cmake

@@ -1,42 +1,4 @@
-function(qt_protobuf_internal_protobuf_generate_all)
-    set(options)
-    set(oneValueArgs OUTPUT_DIRECTORY TARGET)
-    set(multiValueArgs GENERATED_SOURCES PROTO_FILES)
-    cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
-    set(GEN_TARGET "${arg_TARGET}_generate")
-
-    foreach(PROTO_FILE IN LISTS arg_PROTO_FILES)
-        get_filename_component(BASE_DIR "${PROTO_FILE}" DIRECTORY)
-        list(APPEND PROTO_INCLUDES "-I${BASE_DIR}")
-    endforeach()
-
-    if(NOT DEFINED arg_OUTPUT_DIRECTORY)
-        set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
-    else()
-        set(OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}")
-    endif()
-
-    file(MAKE_DIRECTORY "${OUTPUT_DIRECTORY}")
-
-    if(NOT TARGET gRPC::grpc_cpp_plugin)
-        message(FATAL_ERROR "gRPC plugin is not found")
-    endif()
-
-    add_custom_command(
-        OUTPUT ${GENERATED_SOURCES}
-        COMMAND protobuf::protoc
-        ARGS --grpc_out="${OUTPUT_DIRECTORY}"
-            --cpp_out="${OUTPUT_DIRECTORY}"
-            ${PROTO_INCLUDES}
-            "--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
-            ${arg_PROTO_FILES}
-        DEPENDS ${arg_PROTO_FILES}
-    )
 
-    add_custom_target(${GEN_TARGET} DEPENDS ${arg_PROTO_FILES} ${GENERATED_SOURCES})
-    add_dependencies(${arg_TARGET} ${GEN_TARGET})
-endfunction()
 
 function(qt_protobuf_internal_add_target_qml)
     set(options)

+ 1 - 1
examples/addressbook/main.cpp

@@ -39,7 +39,7 @@ using namespace qtprotobuf::examples;
 
 int main(int argc, char *argv[])
 {
-    QtProtobuf::qRegisterProtobufTypes();
+    qRegisterProtobufTypes();
 
     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 

+ 1 - 1
examples/clienttutorial/CMakeLists.txt

@@ -23,7 +23,7 @@ endif()
 
 add_executable(clienttutorial main.cpp echoclientengine.cpp qml.qrc)
 
-qtprotobuf_generate(TARGET clienttutorial
+qt6_protobuf_generate(TARGET clienttutorial
                     PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tutorial.proto
                     QML TRUE)
 

+ 4 - 4
examples/clienttutorial/main.cpp

@@ -62,13 +62,13 @@
  * }
  * \endcode
  *
- * Integration with your Qt application starts at point when you add protobuf and gRPC generation for .proto filed. Add \ref cmake_qtprotobuf_generate function to your CMakeLists.txt as following:
+ * Integration with your Qt application starts at point when you add protobuf and gRPC generation for .proto filed. Add \ref cmake_qt6_protobuf_generate function to your CMakeLists.txt as following:
  *
  * \code
  * ...
  * add_executable(clienttutorial main.cpp qml.qrc) #Add QtProtobuf generator rules after CMake target defined
  *
- * qtprotobuf_generate(TARGET clienttutorial QML TRUE PROTO_FILES tutorial.proto)
+ * qt6_protobuf_generate(TARGET clienttutorial QML TRUE PROTO_FILES tutorial.proto)
  * ...
  * \endcode
  *
@@ -167,7 +167,7 @@
  * int main(int argc, char *argv[])
  * {
  * ... //Before load QML
- *     QtProtobuf::qRegisterProtobufTypes();
+ *     qRegisterProtobufTypes();
  *     qmlRegisterSingletonType<EchoClientEngine>("qtprotobuf.tutorial", 1, 0, "EchoClientEngine", [](QQmlEngine *engine, QJSEngine *){
  *         static EchoClientEngine echoEngine;
  *         engine->setObjectOwnership(&echoEngine, QQmlEngine::CppOwnership);
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
             QCoreApplication::exit(-1);
     }, Qt::QueuedConnection);
 
-    QtProtobuf::qRegisterProtobufTypes();
+    qRegisterProtobufTypes();
     qmlRegisterSingletonType<EchoClientEngine>("qtprotobuf.tutorial", 1, 0, "EchoClientEngine", [](QQmlEngine *engine, QJSEngine *) -> QObject *{
         static EchoClientEngine echoEngine;
         engine->setObjectOwnership(&echoEngine, QQmlEngine::CppOwnership);

+ 1 - 1
examples/fieldenum/field_enum_example.pro

@@ -3,4 +3,4 @@ QT += protobuf grpc core
 
 SOURCES = field_enum_example.cpp
 PROTO_FILES = field_enum_example.proto
-qtprotobuf_generate(false)
+qt6_protobuf_generate(false)

+ 1 - 1
examples/qmakeexample/main.cpp

@@ -29,7 +29,7 @@
 
 int main(int argc, char *argv[])
 {
-    QtProtobuf::qRegisterProtobufTypes();
+    qRegisterProtobufTypes();
     QCoreApplication a(argc, argv);
     return a.exec();
 }

+ 1 - 1
examples/qmakeexample/qmakeexample.pro

@@ -9,4 +9,4 @@ SOURCES += \
 
 PROTO_FILES = test1.proto \
               test2.proto
-qtprotobuf_generate(true)
+qt6_protobuf_generate(true)

+ 1 - 1
examples/simplechat/main.cpp

@@ -41,7 +41,7 @@ using namespace qtprotobuf::examples;
 
 int main(int argc, char *argv[])
 {
-    QtProtobuf::qRegisterProtobufTypes();
+    qRegisterProtobufTypes();
 
     QGuiApplication app(argc, argv);
 

+ 13 - 0
src/CMakeLists.txt

@@ -0,0 +1,13 @@
+add_subdirectory(generator)
+
+add_subdirectory(protobuf)
+add_subdirectory(wellknowntypes)
+add_subdirectory(qttypes)
+
+if(TARGET Qt::Quick)
+    add_subdirectory(protobufquick)
+endif()
+
+if(TARGET Qt::Network)
+    add_subdirectory(grpc)
+endif()

+ 19 - 15
src/generator/CMakeLists.txt

@@ -1,4 +1,8 @@
-qt_protobuf_internal_add_executable(qtprotobufgen
+find_package(Protobuf)
+qt_get_tool_target_name(target_name qtprotobufgen)
+qt_internal_add_tool(${target_name}
+    TOOLS_TARGET
+        Protobuf
     SOURCES
         utils.h
         descriptorprinterbase.h
@@ -23,18 +27,18 @@ qt_protobuf_internal_add_executable(qtprotobufgen
         protobuf::libprotoc
 )
 
-configure_file("${QT_PROTOBUF_CMAKE_DIR}/QtProtobufGen.cmake"
-    "${QT_PROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" COPYONLY
-)
-configure_file("${QT_PROTOBUF_CMAKE_DIR}/QtPreParseProtoFile.cmake"
-    "${QT_PROTOBUF_BINARY_DIR}/QtPreParseProtoFile.cmake" COPYONLY
-)
+# configure_file("${QT_PROTOBUF_CMAKE_DIR}/QtProtobufGen.cmake"
+#     "${QT_PROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" COPYONLY
+# )
+# configure_file("${QT_PROTOBUF_CMAKE_DIR}/QtPreParseProtoFile.cmake"
+#     "${QT_PROTOBUF_BINARY_DIR}/QtPreParseProtoFile.cmake" COPYONLY
+# )
 
-if(QT_PROTOBUF_INSTALL)
-    install(FILES
-           "${QT_PROTOBUF_BINARY_DIR}/QtProtobufGen.cmake"
-           "${QT_PROTOBUF_BINARY_DIR}/QtPreParseProtoFile.cmake"
-        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
-        COMPONENT dev
-    )
-endif()
+# if(QT_PROTOBUF_INSTALL)
+#     install(FILES
+#            "${QT_PROTOBUF_BINARY_DIR}/QtProtobufGen.cmake"
+#            "${QT_PROTOBUF_BINARY_DIR}/QtPreParseProtoFile.cmake"
+#         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
+#         COMPONENT dev
+#     )
+# endif()

+ 1 - 1
src/generator/clientdeclarationprinter.cpp

@@ -47,7 +47,7 @@ ClientDeclarationPrinter::ClientDeclarationPrinter(const ::google::protobuf::Ser
 
 void ClientDeclarationPrinter::printClientClass()
 {
-    mPrinter->Print({{"classname", mName}, {"parent_class", "QtProtobuf::QAbstractGrpcClient"}}, Templates::ClassDefinitionTemplate);
+    mPrinter->Print({{"classname", mName}, {"parent_class", "QAbstractGrpcClient"}}, Templates::ClassDefinitionTemplate);
     Indent();
     mPrinter->Print(Templates::QObjectMacro);
     mPrinter->Print("\n");

+ 9 - 9
src/generator/generatorbase.h

@@ -81,13 +81,13 @@ namespace generator {
  *
  * For CMake based project QtProtobuf has macroses those should be used to generate code and in link it to your project:
  *
- * - \ref cmake_qtprotobuf_generate
- * - \ref cmake_qtprotobuf_link_target
+ * - \ref cmake_qt6_protobuf_generate
+ * - \ref cmake_qt_internal_link_protobuf_objects
  *
  *
- * \subsection cmake_qtprotobuf_generate qtprotobuf_generate
+ * \subsection cmake_qt6_protobuf_generate qt6_protobuf_generate
  *
- * \brief qtprotobuf_generate is cmake helper function that automatically generates STATIC library target from your .proto files
+ * \brief qt6_protobuf_generate is cmake helper function that automatically generates STATIC library target from your .proto files
  *
  * \param TARGET a name of your target that the generated code will be linked to.
  * \param GENERATED_TARGET name that will be used for generated archive library target. It's usefull when you supposed to have multiple generated targets to be linked to single one.
@@ -102,9 +102,9 @@ namespace generator {
  * \param FIELDENUM Enables generation of field numbers as an enum within the message class.
  * \param EXTRA_NAMESPACE <namespace> Wraps the generated code with the specified namespace(EXPERIMENTAL).
  *
- * \subsection cmake_qtprotobuf_link_target qtprotobuf_link_target
+ * \subsection cmake_qt_internal_link_protobuf_objects _qt_internal_link_protobuf_objects
  *
- * \brief qtprotobuf_link_target is cmake helper function that links generated protobuf target to your binary
+ * \brief _qt_internal_link_protobuf_objects is cmake helper function that links generated protobuf target to your binary
  *
  * \details It's useful when you try to link generated target to shared library or/and to executable that doesn't utilize all protobuf generated classes directly from C++ code, but requires them from QML.
  *
@@ -112,11 +112,11 @@ namespace generator {
  * \param GENERATED_TARGET protobuf generated target name
  *
  * \section qmake
- *  - \ref qmake_qtprotobuf_generate
+ *  - \ref qmake_qt6_protobuf_generate
  *
- * \subsection qmake_qtprotobuf_generate qtprotobuf_generate
+ * \subsection qmake_qt6_protobuf_generate qt6_protobuf_generate
  *
- * \brief qtprotobuf_generate is qmake helper <a href="https://doc.qt.io/qt-5/qmake-language.html#test-functions">test function</a> that generates QtProtobuf source code based on files provided by PROTO_FILES global context variable
+ * \brief qt6_protobuf_generate is qmake helper <a href="https://doc.qt.io/qt-5/qmake-language.html#test-functions">test function</a> that generates QtProtobuf source code based on files provided by PROTO_FILES global context variable
  * \param generate_qml generate_qml enables/disables QML code generation in protobuf classes. If set to `true` QML-related code for lists and QML registration to be generated.
  */
 

+ 1 - 1
src/generator/messagedeclarationprinter.cpp

@@ -152,7 +152,7 @@ void MessageDeclarationPrinter::printConstructor(int fieldCount)
 }
 
 void MessageDeclarationPrinter::printMaps()
-{    
+{
     Indent();
     for (int i = 0; i < mDescriptor->field_count(); i++) {
         const FieldDescriptor *field = mDescriptor->field(i);

+ 0 - 1
src/generator/servicedeclarationprinterbase.cpp

@@ -39,7 +39,6 @@
 using namespace ::QtProtobuf::generator;
 using namespace ::google::protobuf;
 using namespace ::google::protobuf::compiler;
-using namespace QtProtobuf::generator;
 
 ServiceDeclarationPrinterBase::ServiceDeclarationPrinterBase(const ::google::protobuf::ServiceDescriptor *service,
                 const std::shared_ptr<::google::protobuf::io::Printer> &printer) :

+ 29 - 29
src/generator/templates.cpp

@@ -33,8 +33,8 @@ const std::vector<std::string> Templates::ListOfQmlExeptions{"id", "property", "
 
 const char *Templates::DefaultProtobufIncludesTemplate = "#include <QMetaType>\n"
                                                          "#include <QList>\n"
-                                                         "#include <QProtobufObject>\n"
-                                                         "#include <QProtobufLazyMessagePointer>\n"
+                                                         "#include <QtProtobuf/qprotobufobject.h>\n"
+                                                         "#include <QtProtobuf/qprotobuflazymessagepointer.h>\n"
                                                          "#include <QSharedPointer>\n"
                                                          "\n"
                                                          "#include <memory>\n"
@@ -42,7 +42,7 @@ const char *Templates::DefaultProtobufIncludesTemplate = "#include <QMetaType>\n
                                                          "\n";
 
 const char *Templates::QmlProtobufIncludesTemplate = "#include <QtQml/QQmlListProperty>\n"
-                                                     "#include <QQmlListPropertyConstructor>\n\n";
+                                                     "#include <QtProtobuf/qtprotobufqmllistpropertyconstructor.h>\n\n";
 
 const char *Templates::GlobalEnumClassNameTemplate = "GlobalEnums";
 
@@ -55,7 +55,7 @@ const char *Templates::InternalIncludeTemplate =  "#include \"$include$.h\"\n";
 const char *Templates::ExternalIncludeTemplate = "#include <$include$>\n";
 const char *Templates::GlobalEnumIncludeTemplate = "#include <globalenums.h>\n";
 
-const char *Templates::UsingQtProtobufNamespaceTemplate = "\nusing namespace QtProtobuf;\n";
+const char *Templates::UsingQtProtobufNamespaceTemplate = "\n";
 const char *Templates::ManualRegistrationDeclaration = "static void registerTypes();\n";
 const char *Templates::ManualRegistrationComplexTypeDefinition = "void $type$::registerTypes()\n{\n"
                                                                  "    qRegisterMetaType<$type$>(\"$full_type$\");\n"
@@ -200,7 +200,7 @@ const char *Templates::GetterContainerExtraTemplate = "$getter_type$ &$property_
 
 const char *Templates::GetterQmlListDeclarationTemplate = "QQmlListProperty<$scope_type$> $property_name$_l();\n";
 const char *Templates::GetterQmlListDefinitionTemplate = "QQmlListProperty<$full_type$> $classname$::$property_name$_l()\n{\n"
-                                                         "    return QtProtobuf::constructQmlListProperty<$scope_type$>(this, &m_$property_name$);\n"
+                                                         "    return qProtobufConstructQmlListProperty<$scope_type$>(this, &m_$property_name$);\n"
                                                          "}\n\n";
 
 const char *Templates::SetterPrivateTemplateDeclarationMessageType = "void set$property_name_cap$_p($setter_type$ *$property_name$);\n";
@@ -243,8 +243,8 @@ const char *Templates::NonScriptableSetterTemplate = "void set$property_name_cap
 const char *Templates::SignalsBlockTemplate = "\nsignals:\n";
 const char *Templates::SignalTemplate = "void $property_name$Changed();\n";
 
-const char *Templates::FieldsOrderingContainerTemplate = "const QtProtobuf::QProtobufMetaObject $type$::protobufMetaObject = QtProtobuf::QProtobufMetaObject($type$::staticMetaObject, $type$::propertyOrdering);\n"
-                                                         "const QtProtobuf::QProtobufPropertyOrdering $type$::propertyOrdering = {";
+const char *Templates::FieldsOrderingContainerTemplate = "const QProtobufMetaObject $type$::protobufMetaObject = QProtobufMetaObject($type$::staticMetaObject, $type$::propertyOrdering);\n"
+                                                         "const QProtobufPropertyOrdering $type$::propertyOrdering = {";
 const char *Templates::FieldOrderTemplate = "{$field_number$, {$property_number$, \"$json_name$\"}}";
 
 const char *Templates::EnumTemplate = "$type$";
@@ -291,9 +291,9 @@ const char *Templates::QEnumTemplate = "Q_ENUM($type$)\n";
 const char *Templates::ClassDefinitionTemplate = "\nclass $classname$ : public $parent_class$\n"
                                                  "{\n";
 const char *Templates::QObjectMacro = "Q_OBJECT";
-const char *Templates::ClientMethodDeclarationSyncTemplate = "QtProtobuf::QGrpcStatus $method_name$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$);\n";
-const char *Templates::ClientMethodDeclarationAsyncTemplate = "QtProtobuf::QGrpcCallReplyShared $method_name$(const $param_type$ &$param_name$);\n";
-const char *Templates::ClientMethodDeclarationAsync2Template = "Q_INVOKABLE void $method_name$(const $param_type$ &$param_name$, const QObject *context, const std::function<void(QtProtobuf::QGrpcCallReplyShared)> &callback);\n";
+const char *Templates::ClientMethodDeclarationSyncTemplate = "QGrpcStatus $method_name$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$);\n";
+const char *Templates::ClientMethodDeclarationAsyncTemplate = "QGrpcCallReplyShared $method_name$(const $param_type$ &$param_name$);\n";
+const char *Templates::ClientMethodDeclarationAsync2Template = "Q_INVOKABLE void $method_name$(const $param_type$ &$param_name$, const QObject *context, const std::function<void(QGrpcCallReplyShared)> &callback);\n";
 const char *Templates::ClientMethodDeclarationQmlTemplate = "Q_INVOKABLE void $method_name$($param_type$ *$param_name$, const QJSValue &callback, const QJSValue &errorCallback);\n";
 const char *Templates::ClientMethodDeclarationQml2Template = "Q_INVOKABLE void $method_name$($param_type$ *$param_name$, $return_type$ *$return_name$, const QJSValue &errorCallback);\n";
 
@@ -303,18 +303,18 @@ const char *Templates::ServerMethodDeclarationTemplate = "Q_INVOKABLE virtual $r
 const char *Templates::ClientConstructorDefinitionTemplate = "\n$classname$::$classname$(QObject *parent) : $parent_class$(\"$service_name$\", parent)\n"
                                                              "{\n"
                                                              "}\n";
-const char *Templates::ClientMethodDefinitionSyncTemplate = "\nQtProtobuf::QGrpcStatus $classname$::$method_name$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$)\n"
+const char *Templates::ClientMethodDefinitionSyncTemplate = "\nQGrpcStatus $classname$::$method_name$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$)\n"
                                                             "{\n"
                                                             "    return call(\"$method_name$\", $param_name$, $return_name$);\n"
                                                             "}\n";
-const char *Templates::ClientMethodDefinitionAsyncTemplate = "\nQtProtobuf::QGrpcCallReplyShared $classname$::$method_name$(const $param_type$ &$param_name$)\n"
+const char *Templates::ClientMethodDefinitionAsyncTemplate = "\nQGrpcCallReplyShared $classname$::$method_name$(const $param_type$ &$param_name$)\n"
                                                              "{\n"
                                                              "    return call(\"$method_name$\", $param_name$);\n"
                                                              "}\n";
 const char *Templates::ClientMethodDefinitionAsync2Template = "\nvoid $classname$::$method_name$(const $param_type$ &$param_name$, const QObject *context, const std::function<void(QGrpcCallReplyShared)> &callback)\n"
                                                               "{\n"
-                                                              "    QtProtobuf::QGrpcCallReplyShared reply = call(\"$method_name$\", $param_name$);\n"
-                                                              "    QObject::connect(reply.get(), &QtProtobuf::QGrpcCallReply::finished, context, [reply, callback]() {\n"
+                                                              "    QGrpcCallReplyShared reply = call(\"$method_name$\", $param_name$);\n"
+                                                              "    QObject::connect(reply.get(), &QGrpcCallReply::finished, context, [reply, callback]() {\n"
                                                               "        callback(reply);\n"
                                                               "    });\n"
                                                               "}\n";
@@ -322,19 +322,19 @@ const char *Templates::ClientMethodDefinitionAsync2Template = "\nvoid $classname
 const char *Templates::ClientMethodDefinitionQmlTemplate = "\nvoid $classname$::$method_name$($param_type$ *$param_name$, const QJSValue &callback, const QJSValue &errorCallback)\n"
                                                            "{\n"
                                                            "    if (!callback.isCallable()) {\n"
-                                                           "        qProtoWarning() << \"Unable to call $classname$::$method_name$, callback is not callable\";\n"
+                                                           "        qWarning() << \"Unable to call $classname$::$method_name$, callback is not callable\";\n"
                                                            "        return;\n"
                                                            "    }\n\n"
                                                            "    if (arg == nullptr) {\n"
-                                                           "        qProtoWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$param_type$ *' expected\";\n"
+                                                           "        qWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$param_type$ *' expected\";\n"
                                                            "        return;\n"
                                                            "    }\n\n"
                                                            "    QJSEngine *jsEngine = qjsEngine(this);\n"
                                                            "    if (jsEngine == nullptr) {\n"
-                                                           "        qProtoWarning() << \"Unable to call $classname$::$method_name$, it's only callable from JS engine context\";\n"
+                                                           "        qWarning() << \"Unable to call $classname$::$method_name$, it's only callable from JS engine context\";\n"
                                                            "        return;\n"
                                                            "    }\n\n"
-                                                           "    QtProtobuf::QGrpcCallReplyShared reply = call(\"$method_name$\", *$param_name$);\n"
+                                                           "    QGrpcCallReplyShared reply = call(\"$method_name$\", *$param_name$);\n"
                                                            "    reply->subscribe(jsEngine, [this, reply, callback, jsEngine]() {\n"
                                                            "        auto result = new $return_type$(reply->read<$return_type$>());\n"
                                                            "        qmlEngine(this)->setObjectOwnership(result, QQmlEngine::JavaScriptOwnership);\n"
@@ -346,23 +346,23 @@ const char *Templates::ClientMethodDefinitionQmlTemplate = "\nvoid $classname$::
 const char *Templates::ClientMethodDefinitionQml2Template = "\nvoid $classname$::$method_name$($param_type$ *$param_name$, $return_type$ *$return_name$, const QJSValue &errorCallback)\n"
                                                             "{\n"
                                                             "    if ($return_name$ == nullptr) {\n"
-                                                            "        qProtoWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$return_type$ *' expected\";\n"
+                                                            "        qWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$return_type$ *' expected\";\n"
                                                             "        return;\n"
                                                             "    }\n\n"
                                                             "    QPointer<$return_type$> safeReturn($return_name$);\n\n"
                                                             "    if ($param_name$ == nullptr) {\n"
-                                                            "        qProtoWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$param_type$ *' expected\";\n"
+                                                            "        qWarning() << \"Invalid argument provided for method $classname$::$method_name$, argument of type '$param_type$ *' expected\";\n"
                                                             "        return;\n"
                                                             "    }\n\n"
                                                             "    QJSEngine *jsEngine = qjsEngine(this);\n"
                                                             "    if (jsEngine == nullptr) {\n"
-                                                            "        qProtoWarning() << \"Unable to call $classname$::$method_name$, it's only callable from JS engine context\";\n"
+                                                            "        qWarning() << \"Unable to call $classname$::$method_name$, it's only callable from JS engine context\";\n"
                                                             "        return;\n"
                                                             "    }\n\n"
-                                                            "    QtProtobuf::QGrpcCallReplyShared reply = call(\"$method_name$\", *$param_name$);\n"
+                                                            "    QGrpcCallReplyShared reply = call(\"$method_name$\", *$param_name$);\n"
                                                             "    reply->subscribe(jsEngine, [this, reply, jsEngine, safeReturn]() {\n"
                                                             "        if (safeReturn.isNull()) {\n"
-                                                            "            qProtoWarning() << \"Return value is destroyed. Ignore call result\";\n"
+                                                            "            qWarning() << \"Return value is destroyed. Ignore call result\";\n"
                                                             "            return;\n"
                                                             "        }\n"
                                                             "        *safeReturn = $return_type$(reply->read<$return_type$>());\n"
@@ -379,19 +379,19 @@ const char *Templates::QmlRegisterEnumTypeTemplate = "qmlRegisterUncreatableType
 
 
 const char *Templates::ClientMethodSignalDeclarationTemplate = "Q_SIGNAL void $method_name$Updated(const $return_type$ &);\n";
-const char *Templates::ClientMethodServerStreamDeclarationTemplate = "QtProtobuf::QGrpcStreamShared stream$method_name_upper$(const $param_type$ &$param_name$);\n";
-const char *Templates::ClientMethodServerStream2DeclarationTemplate = "QtProtobuf::QGrpcStreamShared stream$method_name_upper$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$);\n";
-const char *Templates::ClientMethodServerStreamQmlDeclarationTemplate = "Q_INVOKABLE QtProtobuf::QGrpcStreamShared qmlStream$method_name_upper$_p($param_type$ *$param_name$, $return_type$ *$return_name$);\n";
+const char *Templates::ClientMethodServerStreamDeclarationTemplate = "QGrpcStreamShared stream$method_name_upper$(const $param_type$ &$param_name$);\n";
+const char *Templates::ClientMethodServerStream2DeclarationTemplate = "QGrpcStreamShared stream$method_name_upper$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$);\n";
+const char *Templates::ClientMethodServerStreamQmlDeclarationTemplate = "Q_INVOKABLE QGrpcStreamShared qmlStream$method_name_upper$_p($param_type$ *$param_name$, $return_type$ *$return_name$);\n";
 
-const char *Templates::ClientMethodServerStreamDefinitionTemplate = "QtProtobuf::QGrpcStreamShared $classname$::stream$method_name_upper$(const $param_type$ &$param_name$)\n"
+const char *Templates::ClientMethodServerStreamDefinitionTemplate = "QGrpcStreamShared $classname$::stream$method_name_upper$(const $param_type$ &$param_name$)\n"
                                                                     "{\n"
                                                                     "    return stream(\"$method_name$\", $param_name$);\n"
                                                                     "}\n";
-const char *Templates::ClientMethodServerStream2DefinitionTemplate = "QtProtobuf::QGrpcStreamShared $classname$::stream$method_name_upper$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$)\n"
+const char *Templates::ClientMethodServerStream2DefinitionTemplate = "QGrpcStreamShared $classname$::stream$method_name_upper$(const $param_type$ &$param_name$, const QPointer<$return_type$> &$return_name$)\n"
                                                                      "{\n"
                                                                      "    return stream(\"$method_name$\", $param_name$, $return_name$);\n"
                                                                      "}\n";
-const char *Templates::ClientMethodServerStreamQmlDefinitionTemplate = "QtProtobuf::QGrpcStreamShared $classname$::qmlStream$method_name_upper$_p($param_type$ *$param_name$, $return_type$ *$return_name$)\n"
+const char *Templates::ClientMethodServerStreamQmlDefinitionTemplate = "QGrpcStreamShared $classname$::qmlStream$method_name_upper$_p($param_type$ *$param_name$, $return_type$ *$return_name$)\n"
                                                                        "{\n"
                                                                        "    return stream(\"$method_name$\", *$param_name$, QPointer<$return_type$>($return_name$));\n"
                                                                        "}\n";

+ 37 - 49
src/grpc/CMakeLists.txt

@@ -1,56 +1,44 @@
-qt_protobuf_internal_add_library(Grpc
+qt_internal_add_module(Grpc
     SOURCES
-        qgrpcasyncoperationbase.cpp
-        qgrpccallreply.cpp
-        qgrpcstream.cpp
-        qgrpcstatus.cpp
-        qabstractgrpcchannel.cpp
-        qgrpchttp2channel.cpp
-        qabstractgrpcclient.cpp
-        qgrpccredentials.cpp
-        qgrpcsslcredentials.cpp
-        qgrpcinsecurecredentials.cpp
-        qgrpcuserpasswordcredentials.cpp
-    PUBLIC_HEADER
-        qgrpcasyncoperationbase_p.h
-        qgrpccallreply.h
-        qgrpcstream.h
-        qgrpcstatus.h
-        qabstractgrpcchannel.h
-        qgrpchttp2channel.h
-        qabstractgrpcclient.h
+        qgrpcasyncoperationbase.cpp qgrpcasyncoperationbase.h
+        qgrpccallreply.cpp qgrpccallreply.h
+        qgrpcstream.cpp qgrpcstream.h
+        qgrpcstatus.cpp qgrpcstatus.h
+        qabstractgrpcchannel.cpp qabstractgrpcchannel.h
+        qgrpchttp2channel.cpp qgrpchttp2channel.h
+        qabstractgrpcclient.cpp qabstractgrpcclient.h
+        qgrpccredentials.cpp qgrpccredentials.h
+        qgrpcsslcredentials.cpp qgrpcsslcredentials.h
+        qgrpcinsecurecredentials.cpp qgrpcinsecurecredentials.h
+        qgrpcuserpasswordcredentials.cpp qgrpcuserpasswordcredentials.h
+        qtgrpclogging.cpp qtgrpclogging_p.h
         qabstractgrpccredentials.h
-        qgrpccredentials.h
-        qgrpcsslcredentials.h
-        qgrpcinsecurecredentials.h
-        qgrpcuserpasswordcredentials.h
         qtgrpcglobal.h
     PUBLIC_LIBRARIES
-        ${QT_PROTOBUF_NAMESPACE}::Protobuf
-        Qt6::Core
-        Qt6::Network
+        Qt::Protobuf
+        Qt::Core
+        Qt::Network
+    LIBRARIES
+       Qt::ProtobufPrivate
+    EXCEPTIONS
 )
 
-if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)
-    qt_protobuf_internal_extend_target(Grpc
-        SOURCES
-            qgrpcchannel.cpp qgrpcchannel_p.h
-        PUBLIC_HEADER
-            qgrpcchannel.h
-        PUBLIC_DEFINES
-            QT_PROTOBUF_NATIVE_GRPC_CHANNEL
-        PUBLIC_LIBRARIES
-            gRPC::grpc++
-            ${CMAKE_THREAD_LIBS_INIT}
-    )
-endif()
+# TODO Qt6: Perhaps it will be removed after the new implementation of HTTP/2 channel is introduced
+# if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)
+#     qt_protobuf_internal_extend_target(Grpc
+#         SOURCES
+#             qgrpcchannel.cpp qgrpcchannel_p.h
+#         PUBLIC_HEADER
+#             qgrpcchannel.h
+#         PUBLIC_DEFINES
+#             QT_PROTOBUF_NATIVE_GRPC_CHANNEL
+#         PUBLIC_LIBRARIES
+#             gRPC::grpc++
+#             ${CMAKE_THREAD_LIBS_INIT}
+#     )
+# endif()
 
-if(NOT BUILD_SHARED_LIBS)
-    set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") #extra config for .pri file in case if static build enabled
-endif()
-
-qt_protobuf_internal_generate_pri(Grpc)
-
-if(TARGET Qt6::Quick)
-    add_subdirectory("quick")
-endif()
+# TODO Qt6: Restore QML support
+# if(TARGET Qt5::Quick)
+#     add_subdirectory("quick")
+# endif()

+ 4 - 3
src/grpc/qabstractgrpcchannel.cpp

@@ -29,9 +29,10 @@
 #include "qgrpcstream.h"
 #include <QThread>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
-struct QAbstractGrpcChannelPrivate {
+struct QAbstractGrpcChannelPrivate
+{
     QAbstractGrpcChannelPrivate() : thread(QThread::currentThread()) {
         assert(thread != nullptr && "QAbstractGrpcChannel has to be created in QApplication context");
     }
@@ -46,4 +47,4 @@ const QThread *QAbstractGrpcChannel::thread() const
     return dPtr->thread;
 }
 
-}
+QT_END_NAMESPACE

+ 8 - 8
src/grpc/qabstractgrpcchannel.h

@@ -30,14 +30,13 @@
 #include <functional>
 #include <memory>
 
-#include "qgrpcstatus.h"
-#include "qgrpccredentials.h"
-#include "qtgrpcglobal.h"
+#include <QtGrpc/qgrpcstatus.h>
+#include <QtGrpc/qgrpccredentials.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
-QT_FORWARD_DECLARE_CLASS(QThread);
-
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
+class QThread;
 class QAbstractGrpcClient;
 class QAbstractProtobufSerializer;
 struct QAbstractGrpcChannelPrivate;
@@ -73,7 +72,7 @@ public:
      *            QGrpcCallReply lifecycle is managed by QAbstractGrpcClient only.
      *            \see QGrpcCallReply for details
      */
-    virtual void call(const QString &method, const QString &service, const QByteArray &args, QtProtobuf::QGrpcCallReply *ret) = 0;
+    virtual void call(const QString &method, const QString &service, const QByteArray &args, QGrpcCallReply *ret) = 0;
 
     /*!
      * \brief Streams to server-side stream to receive updates for given \p method.
@@ -98,4 +97,5 @@ private:
     Q_DISABLE_COPY(QAbstractGrpcChannel)
     std::unique_ptr<QAbstractGrpcChannelPrivate> dPtr;
 };
-}
+
+QT_END_NAMESPACE

+ 14 - 14
src/grpc/qabstractgrpcclient.cpp

@@ -25,14 +25,15 @@
 
 #include "qabstractgrpcclient.h"
 
+#include <QtProtobuf/private/qprotobufserializerregistry_p.h>
 #include "qgrpccallreply.h"
 #include "qgrpcstream.h"
-#include "qprotobufserializerregistry_p.h"
+#include "qtgrpclogging_p.h"
 
 #include <QTimer>
 #include <QThread>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 //! \private
 class QAbstractGrpcClientPrivate final {
@@ -43,9 +44,6 @@ public:
     const QString service;
     std::vector<QGrpcStreamShared> activeStreams;
 };
-}
-
-using namespace QtProtobuf;
 
 QAbstractGrpcClient::QAbstractGrpcClient(const QString &service, QObject *parent) : QObject(parent)
   , dPtr(std::make_unique<QAbstractGrpcClientPrivate>(service))
@@ -58,10 +56,10 @@ QAbstractGrpcClient::~QAbstractGrpcClient()
 void QAbstractGrpcClient::attachChannel(const std::shared_ptr<QAbstractGrpcChannel> &channel)
 {
     if (channel->thread() != QThread::currentThread()) {
-        qProtoCritical() << "QAbstractGrpcClient::attachChannel is called from different thread.\n"
+        qGrpcCritical() << "QAbstractGrpcClient::attachChannel is called from different thread.\n"
                            "QtGrpc doesn't guarantie thread safety on channel level.\n"
                            "You have to be confident that channel routines are working in the same thread as QAbstractGrpcClient";
-        throw std::runtime_error("Call from another thread");
+        QT_THROW(std::runtime_error("Call from another thread"));
     }
     for (auto stream : dPtr->activeStreams) {
         stream->abort();
@@ -77,7 +75,7 @@ QGrpcStatus QAbstractGrpcClient::call(const QString &method, const QByteArray &a
     QGrpcStatus callStatus{QGrpcStatus::Unknown};
     if (thread() != QThread::currentThread()) {
         QMetaObject::invokeMethod(this, [&]()->QGrpcStatus {
-                                                qProtoDebug() << "Method: " << dPtr->service << method << " called from different thread";
+                                                qGrpcDebug() << "Method: " << dPtr->service << method << " called from different thread";
                                                 return call(method, arg, ret);
                                             }, Qt::BlockingQueuedConnection, &callStatus);
         return callStatus;
@@ -101,7 +99,7 @@ QGrpcCallReplyShared QAbstractGrpcClient::call(const QString &method, const QByt
     QGrpcCallReplyShared reply;
     if (thread() != QThread::currentThread()) {
         QMetaObject::invokeMethod(this, [&]()->QGrpcCallReplyShared {
-                                      qProtoDebug() << "Method: " << dPtr->service << method << " called from different thread";
+                                      qGrpcDebug() << "Method: " << dPtr->service << method << " called from different thread";
                                       return call(method, arg);
                                   }, Qt::BlockingQueuedConnection, &reply);
     } else if (dPtr->channel) {
@@ -130,13 +128,13 @@ QGrpcCallReplyShared QAbstractGrpcClient::call(const QString &method, const QByt
     return reply;
 }
 
-QGrpcStreamShared QAbstractGrpcClient::stream(const QString &method, const QByteArray &arg, const QtProtobuf::StreamHandler &handler)
+QGrpcStreamShared QAbstractGrpcClient::stream(const QString &method, const QByteArray &arg, const QGrpcStreamHandler &handler)
 {
     QGrpcStreamShared grpcStream;
 
     if (thread() != QThread::currentThread()) {
         QMetaObject::invokeMethod(this, [&]()->QGrpcStreamShared {
-                                      qProtoDebug() << "Stream: " << dPtr->service << method << " called from different thread";
+                                      qGrpcDebug() << "Stream: " << dPtr->service << method << " called from different thread";
                                       return stream(method, arg, handler);
                                   }, Qt::BlockingQueuedConnection, &grpcStream);
     } else if (dPtr->channel) {
@@ -153,7 +151,7 @@ QGrpcStreamShared QAbstractGrpcClient::stream(const QString &method, const QByte
 
         auto errorConnection = std::make_shared<QMetaObject::Connection>();
         *errorConnection = connect(grpcStream.get(), &QGrpcStream::error, this, [this, grpcStream](const QGrpcStatus &status) {
-            qProtoWarning() << grpcStream->method() << "call" << dPtr->service << "stream error: " << status.message();
+            qGrpcWarning() << grpcStream->method() << "call" << dPtr->service << "stream error: " << status.message();
             error(status);
             std::weak_ptr<QGrpcStream> weakStream = grpcStream;
             //TODO: Make timeout configurable from channel settings
@@ -162,14 +160,14 @@ QGrpcStreamShared QAbstractGrpcClient::stream(const QString &method, const QByte
                 if (stream) {
                     dPtr->channel->stream(stream.get(), dPtr->service, this);
                 } else {
-                    qProtoDebug() << "Stream for " << dPtr->service << "method" << method << " will not be restored by timeout.";
+                    qGrpcDebug() << "Stream for " << dPtr->service << "method" << method << " will not be restored by timeout.";
                 }
             });
         });
 
         auto finishedConnection = std::make_shared<QMetaObject::Connection>();
         *finishedConnection = connect(grpcStream.get(), &QGrpcStream::finished, this, [this, grpcStream, errorConnection, finishedConnection]() mutable {
-            qProtoWarning() << grpcStream->method() << "call" << dPtr->service << "stream finished";
+            qGrpcWarning() << grpcStream->method() << "call" << dPtr->service << "stream finished";
             auto it = std::find_if(std::begin(dPtr->activeStreams), std::end(dPtr->activeStreams), [grpcStream](QGrpcStreamShared activeStream) {
                return *activeStream == *grpcStream;
             });
@@ -197,3 +195,5 @@ std::shared_ptr<QAbstractProtobufSerializer> QAbstractGrpcClient::serializer() c
     }
     return dPtr->channel->serializer();
 }
+
+QT_END_NAMESPACE

+ 10 - 17
src/grpc/qabstractgrpcclient.h

@@ -33,18 +33,16 @@
 #include <QPointer>
 #include <QByteArray>
 
-#include <qtprotobuflogging.h>
-#include <qabstractprotobufserializer.h>
+#include <QtProtobuf/qabstractprotobufserializer.h>
 
-#include "qabstractgrpcchannel.h"
-
-#include "qtgrpcglobal.h"
+#include <QtGrpc/qabstractgrpcchannel.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
 /*!
  * \defgroup QtGrpc
  * \brief Qt framework based gRPC clients and services
  */
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QGrpcAsyncOperationBase;
 class QAbstractGrpcChannel;
@@ -93,10 +91,9 @@ protected:
     QGrpcStatus call(const QString &method, const A &arg, const QPointer<R> &ret) {
         QGrpcStatus status{QGrpcStatus::Ok};
         if (ret.isNull()) {
-            static const QString errorString("Unable to call method: %1. Pointer to return data is null");
+            static const QLatin1String errorString("Unable to call method: %1. Pointer to return data is null");
             status = QGrpcStatus{QGrpcStatus::InvalidArgument, errorString.arg(method)};
             error(status);
-            qProtoCritical() << errorString.arg(method);
             return status;
         }
 
@@ -161,9 +158,8 @@ protected:
     template<typename A, typename R>
     QGrpcStreamShared stream(const QString &method, const A &arg, const QPointer<R> &ret) {
         if (ret.isNull()) {
-            static const QString nullPointerError("Unable to stream method: %1. Pointer to return data is null");
+            static const QLatin1String nullPointerError("Unable to stream method: %1. Pointer to return data is null");
             error({QGrpcStatus::InvalidArgument, nullPointerError.arg(method)});
-            qProtoCritical() << nullPointerError.arg(method);
             return nullptr;
         }
         bool ok = false;
@@ -177,7 +173,6 @@ protected:
             } else {
                 static const QLatin1String nullPointerError("Pointer to return data is null while stream update received");
                 error({QGrpcStatus::InvalidArgument, nullPointerError});
-                qProtoCritical() << nullPointerError;
             }
         });
     }
@@ -197,7 +192,7 @@ private:
     QGrpcCallReplyShared call(const QString &method, const QByteArray &arg);
 
     //!\private
-    QGrpcStreamShared stream(const QString &method, const QByteArray &arg, const QtProtobuf::StreamHandler &handler = {});
+    QGrpcStreamShared stream(const QString &method, const QByteArray &arg, const QGrpcStreamHandler &handler = {});
 
     /*!
      * \private
@@ -214,12 +209,10 @@ private:
                 static const QLatin1String invalidArgumentErrorMessage("Response deserialization failed invalid field found");
                 status = {QGrpcStatus::InvalidArgument, invalidArgumentErrorMessage};
                 error(status);
-                qProtoCritical() << invalidArgumentErrorMessage;
             } catch (std::out_of_range &) {
                 static const QLatin1String outOfRangeErrorMessage("Invalid size of received buffer");
                 status = {QGrpcStatus::OutOfRange, outOfRangeErrorMessage};
                 error(status);
-                qProtoCritical() << outOfRangeErrorMessage;
             } catch (...) {
                 status = {QGrpcStatus::Internal, QLatin1String("Unknown exception caught during deserialization")};
                 error(status);
@@ -231,7 +224,6 @@ private:
         return status;
     }
 
-
     template<typename R>
     QByteArray trySerialize(const R &arg, bool &ok) {
         ok = false;
@@ -248,7 +240,7 @@ private:
     /*!
      * \private
      * \brief serializer provides assigned to client serializer
-     * \return pointer to serializer. Serializer is owned by QtProtobuf::QProtobufSerializerRegistry.
+     * \return pointer to serializer. Serializer is owned by QProtobufSerializerRegistry.
      */
     std::shared_ptr<QAbstractProtobufSerializer> serializer() const;
 
@@ -256,4 +248,5 @@ private:
 
     std::unique_ptr<QAbstractGrpcClientPrivate> dPtr;
 };
-}
+
+QT_END_NAMESPACE

+ 5 - 4
src/grpc/qabstractgrpccredentials.h

@@ -25,13 +25,13 @@
 
 #pragma once
 
-#include "qtgrpcglobal.h"
-
 #include <QHash>
 #include <QString>
 #include <QVariant>
 
-namespace QtProtobuf {
+#include <QtGrpc/qtgrpcglobal.h>
+
+QT_BEGIN_NAMESPACE
 
 using QGrpcCredentialMap = QHash<QLatin1String, QVariant>;
 
@@ -42,4 +42,5 @@ public:
     virtual QGrpcCredentialMap callCredentials() = 0;
     virtual QGrpcCredentialMap channelCredentials() = 0;
 };
-}
+
+QT_END_NAMESPACE

+ 7 - 6
src/grpc/qgrpcasyncoperationbase.cpp

@@ -23,16 +23,17 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "qgrpcasyncoperationbase_p.h"
+#include "qgrpcasyncoperationbase.h"
+#include "qtgrpclogging_p.h"
 
-#include <qtprotobuflogging.h>
-
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
 
 QGrpcAsyncOperationBase::~QGrpcAsyncOperationBase()
 {
-    qProtoDebug() << "Trying ~QGrpcAsyncOperationBase" << this;
+    qGrpcDebug() << "Trying ~QGrpcAsyncOperationBase" << this;
     QMutexLocker locker(&m_asyncLock);
-    qProtoDebug() << "~QGrpcAsyncOperationBase" << this;
+    qGrpcDebug() << "~QGrpcAsyncOperationBase" << this;
     (void)locker;
 }
+
+QT_END_NAMESPACE

+ 5 - 6
src/grpc/qgrpcasyncoperationbase_p.h → src/grpc/qgrpcasyncoperationbase.h

@@ -31,11 +31,10 @@
 #include <functional>
 #include <memory>
 
-#include "qabstractgrpcclient.h"
+#include <QtGrpc/qtgrpcglobal.h>
+#include <QtGrpc/qabstractgrpcclient.h>
 
-#include "qtgrpcglobal.h"
-
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtGrpc
@@ -86,7 +85,7 @@ signals:
      * \brief The signal is emitted when error happend in channel or during serialization
      * \param[out] status received from gRPC channel
      */
-    void error(const QtProtobuf::QGrpcStatus &status);
+    void error(const QGrpcStatus &status);
 
 protected:
     //! \private
@@ -104,4 +103,4 @@ private:
     QMutex m_asyncLock;
 };
 
-}
+QT_END_NAMESPACE

+ 3 - 1
src/grpc/qgrpccallreply.cpp

@@ -27,7 +27,7 @@
 
 #include <QThread>
 
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
 
 void QGrpcCallReply::abort()
 {
@@ -41,3 +41,5 @@ void QGrpcCallReply::abort()
         abortFunc();
     }
 }
+
+QT_END_NAMESPACE

+ 6 - 5
src/grpc/qgrpccallreply.h

@@ -29,12 +29,12 @@
 #include <QMutex>
 #include <memory>
 
-#include "qabstractgrpcclient.h"
-#include "qgrpcasyncoperationbase_p.h"
+#include <QtGrpc/qabstractgrpcclient.h>
+#include <QtGrpc/qgrpcasyncoperationbase.h>
 
-#include "qtgrpcglobal.h"
+#include <QtGrpc/qtgrpcglobal.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtGrpc
@@ -87,4 +87,5 @@ private:
 
     friend class QAbstractGrpcClient;
 };
-}
+
+QT_END_NAMESPACE

+ 5 - 5
src/grpc/qgrpcchannel.cpp

@@ -138,7 +138,7 @@ QGrpcChannelStream::~QGrpcChannelStream()
 
 void QGrpcChannelStream::cancel() {
     // TODO: check thread safety
-    qProtoDebug() << "Stream thread terminated";
+    qGrpcDebug() << "Stream thread terminated";
     context.TryCancel();
 }
 
@@ -191,7 +191,7 @@ QGrpcChannelCall::~QGrpcChannelCall()
 void QGrpcChannelCall::cancel()
 {
     // TODO: check thread safety
-    qProtoDebug() << "Call thread terminated";
+    qGrpcDebug() << "Call thread terminated";
     context.TryCancel();
 }
 
@@ -278,7 +278,7 @@ void QGrpcChannelPrivate::stream(QGrpcStream *stream, const QString &service, QA
     });
 
     *connection = QObject::connect(sub.get(), &QGrpcChannelStream::finished, stream, [sub, stream, readConnection, abortConnection, service, connection, clientConnection](){
-        qProtoDebug() << "Stream ended with server closing connection";
+        qGrpcDebug() << "Stream ended with server closing connection";
 
         QObject::disconnect(*connection);
         QObject::disconnect(*readConnection);
@@ -292,7 +292,7 @@ void QGrpcChannelPrivate::stream(QGrpcStream *stream, const QString &service, QA
     });
 
     *abortConnection = QObject::connect(stream, &QGrpcStream::finished, sub.get(), [connection, abortConnection, readConnection, sub, clientConnection] {
-        qProtoDebug() << "Stream client was finished";
+        qGrpcDebug() << "Stream client was finished";
 
         QObject::disconnect(*connection);
         QObject::disconnect(*readConnection);
@@ -303,7 +303,7 @@ void QGrpcChannelPrivate::stream(QGrpcStream *stream, const QString &service, QA
     });
 
     *clientConnection = QObject::connect(client, &QAbstractGrpcClient::destroyed, sub.get(), [readConnection, connection, abortConnection, sub, clientConnection](){
-        qProtoDebug() << "Grpc client was destroyed";
+        qGrpcDebug() << "Grpc client was destroyed";
 
         QObject::disconnect(*connection);
         QObject::disconnect(*readConnection);

+ 4 - 2
src/grpc/qgrpccredentials.cpp

@@ -25,6 +25,8 @@
 
 #include "qgrpccredentials.h"
 
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
 
-const char *QtProtobuf::SslConfigCredential = "sslConfig";
+const char *QGrpcSslConfigCredential = "sslConfig";
+
+QT_END_NAMESPACE

+ 18 - 17
src/grpc/qgrpccredentials.h

@@ -25,13 +25,13 @@
 
 #pragma once //QGrpcCredentials
 
-#include "qtgrpcglobal.h"
-#include "qabstractgrpccredentials.h"
+#include <QtGrpc/qabstractgrpccredentials.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
 #include <memory>
 #include <type_traits>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtGrpc
@@ -39,7 +39,7 @@ namespace QtProtobuf {
  *        You may inherrit of this calls to create you own credentials implementation,
  *        that will be used for each method call.
  *        Classes inherited of QGrpcCallCredentials should reimplement
- *        QtProtobuf::QGrpcCredentialMap operator() method and return actual credentials
+ *        QGrpcCredentialMap operator() method and return actual credentials
  *        map for the call.
  */
 class Q_GRPC_EXPORT QGrpcCallCredentials {};
@@ -62,8 +62,8 @@ class Q_GRPC_EXPORT QGrpcChannelCredentials {};
  *        authentications parameters.
  */
 template<typename Call, typename Channel,
-         typename std::enable_if_t<std::is_base_of<QtProtobuf::QGrpcCallCredentials, Call>::value &&
-                                   std::is_base_of<QtProtobuf::QGrpcChannelCredentials, Channel>::value, int> = 0>
+         typename std::enable_if_t<std::is_base_of<QGrpcCallCredentials, Call>::value &&
+                                   std::is_base_of<QGrpcChannelCredentials, Channel>::value, int> = 0>
 class QGrpcCredentials final : public QAbstractGrpcCredentials
 {
 public:
@@ -100,27 +100,28 @@ private:
 };
 
 /*!
- * \brief SslConfigCredential
+ * \brief QGrpcSslConfigCredential
  */
-extern Q_GRPC_EXPORT const char *SslConfigCredential;
+extern Q_GRPC_EXPORT const char *QGrpcSslConfigCredential;
 
 /*! \} */
-}
+
+QT_END_NAMESPACE
 
 //! \private
 template<typename Call, typename Channel,
-         typename std::enable_if_t<std::is_base_of<QtProtobuf::QGrpcCallCredentials, Call>::value &&
-                                   std::is_base_of<QtProtobuf::QGrpcChannelCredentials, Channel>::value, int> = 0>
-std::unique_ptr<QtProtobuf::QAbstractGrpcCredentials> operator |(const Call &call, const Channel &channel)
+         typename std::enable_if_t<std::is_base_of<QGrpcCallCredentials, Call>::value &&
+                                   std::is_base_of<QGrpcChannelCredentials, Channel>::value, int> = 0>
+std::unique_ptr<QAbstractGrpcCredentials> operator |(const Call &call, const Channel &channel)
 {
-    return std::unique_ptr<QtProtobuf::QAbstractGrpcCredentials>(new QtProtobuf::QGrpcCredentials<Call, Channel>(call, channel));
+    return std::unique_ptr<QAbstractGrpcCredentials>(new QGrpcCredentials<Call, Channel>(call, channel));
 }
 
 //! \private
 template<typename Call, typename Channel,
-         typename std::enable_if_t<std::is_base_of<QtProtobuf::QGrpcCallCredentials, Call>::value &&
-                                   std::is_base_of<QtProtobuf::QGrpcChannelCredentials, Channel>::value, int> = 0>
-std::unique_ptr<QtProtobuf::QAbstractGrpcCredentials> operator |(const Channel &channel, const Call &call)
+         typename std::enable_if_t<std::is_base_of<QGrpcCallCredentials, Call>::value &&
+                                   std::is_base_of<QGrpcChannelCredentials, Channel>::value, int> = 0>
+std::unique_ptr<QAbstractGrpcCredentials> operator |(const Channel &channel, const Call &call)
 {
-    return std::unique_ptr<QtProtobuf::QAbstractGrpcCredentials>(new QtProtobuf::QGrpcCredentials<Call, Channel>(call, channel));
+    return std::unique_ptr<QAbstractGrpcCredentials>(new QGrpcCredentials<Call, Channel>(call, channel));
 }

+ 41 - 30
src/grpc/qgrpchttp2channel.cpp

@@ -40,12 +40,11 @@
 #include "qgrpcstream.h"
 #include "qabstractgrpcclient.h"
 #include "qgrpccredentials.h"
-#include "qprotobufserializerregistry_p.h"
-#include "qtprotobuflogging.h"
+#include "qtgrpclogging_p.h"
 
-#include <qglobal.h>
+#include <QtProtobuf/private/qprotobufserializerregistry_p.h>
 
-using namespace QtProtobuf;
+#include <qglobal.h>
 
 namespace  {
 
@@ -96,7 +95,7 @@ const char *GrpcStatusMessage = "grpc-message";
 const int GrpcMessageSizeHeaderSize = 5;
 }
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 //! \private
 struct QGrpcHttp2ChannelPrivate {
     //! \private
@@ -116,9 +115,9 @@ struct QGrpcHttp2ChannelPrivate {
         QUrl callUrl = url;
         callUrl.setPath("/" + service + "/" + method);
 
-        qProtoDebug() << "Service call url: " << callUrl;
+        qGrpcDebug() << "Service call url: " << callUrl;
         QNetworkRequest request(callUrl);
-        request.setHeader(QNetworkRequest::ContentTypeHeader, "application/grpc");
+        request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/grpc"));
         request.setRawHeader(GrpcAcceptEncodingHeader, "identity,deflate,gzip");
         request.setRawHeader(AcceptEncodingHeader, "identity,gzip");
         request.setRawHeader(TEHeader, "trailers");
@@ -131,14 +130,17 @@ struct QGrpcHttp2ChannelPrivate {
         request.setAttribute(QNetworkRequest::Http2DirectAttribute, true);
 
         QByteArray msg(GrpcMessageSizeHeaderSize, '\0');
-        *reinterpret_cast<int *>(msg.data() + 1) = qToBigEndian(args.size());
+        // TODO Qt6: QByteArray::size now has the qsizetype type, which might be larger than int32_t.
+        // FIXME: The channel truncates an args to the int32_t size. Need to implement the sequencial
+        // message sending.
+        *reinterpret_cast<int32_t *>(msg.data() + 1) = qToBigEndian((int32_t)args.size());
         msg += args;
-        qProtoDebug() << "SEND: " << msg.size();
+        qGrpcDebug() << "SEND: " << msg.size();
 
         QNetworkReply *networkReply = nm.post(request, msg);
 
         QObject::connect(networkReply, &QNetworkReply::sslErrors, [networkReply](const QList<QSslError> &errors) {
-           qProtoCritical() << errors;
+           qGrpcCritical() << errors;
            // TODO: filter out noncritical SSL handshake errors
            // FIXME: error due to ssl failure is not transferred to the client: last error will be Operation canceled
            QGrpcHttp2ChannelPrivate::abortNetworkReply(networkReply);
@@ -169,7 +171,16 @@ struct QGrpcHttp2ChannelPrivate {
         }
 
         //Check if server answer with error
-        statusCode = static_cast<QGrpcStatus::StatusCode>(networkReply->rawHeader(GrpcStatusHeader).toInt());
+        QByteArray statusData = networkReply->rawHeader(GrpcStatusHeader);
+        if (!statusData.isEmpty()) {
+            bool ok = false;
+            statusCode = static_cast<QGrpcStatus::StatusCode>(networkReply->rawHeader(GrpcStatusHeader).toInt(&ok));
+            if (!ok) {
+                statusCode = QGrpcStatus::Unknown;
+            }
+        } else {
+            statusCode = QGrpcStatus::Unknown;
+        }
         if (statusCode != QGrpcStatus::StatusCode::Ok) {
             return {};
         }
@@ -182,13 +193,13 @@ struct QGrpcHttp2ChannelPrivate {
         : url(_url)
         , credentials(std::move(_credentials))
     {
-        if (url.scheme() == "https") {
-            if (!credentials->channelCredentials().contains(QLatin1String(SslConfigCredential))) {
-                throw std::invalid_argument("Https connection requested but not ssl configuration provided.");
+        if (url.scheme() == QStringLiteral("https")) {
+            if (!credentials->channelCredentials().contains(QLatin1String(QGrpcSslConfigCredential))) {
+                QT_THROW(std::invalid_argument("Https connection requested but not ssl configuration provided."));
             }
-            sslConfig = credentials->channelCredentials().value(QLatin1String(SslConfigCredential)).value<QSslConfiguration>();
+            sslConfig = credentials->channelCredentials().value(QLatin1String(QGrpcSslConfigCredential)).value<QSslConfiguration>();
         } else if (url.scheme().isEmpty()) {
-            url.setScheme("http");
+            url.setScheme(QStringLiteral("http"));
         }
     }
 
@@ -197,8 +208,6 @@ struct QGrpcHttp2ChannelPrivate {
     }
 };
 
-}
-
 QGrpcHttp2Channel::QGrpcHttp2Channel(const QUrl &url, std::unique_ptr<QAbstractGrpcCredentials> credentials) : QAbstractGrpcChannel()
   , dPtr(std::make_unique<QGrpcHttp2ChannelPrivate>(url, std::move(credentials)))
 {
@@ -224,7 +233,7 @@ QGrpcStatus QGrpcHttp2Channel::call(const QString &method, const QString &servic
     ret = dPtr->processReply(networkReply, grpcStatus);
 
     networkReply->deleteLater();
-    qProtoDebug() << __func__ << "RECV: " << ret.toHex() << "grpcStatus" << grpcStatus;
+    qGrpcDebug() << __func__ << "RECV: " << ret.toHex() << "grpcStatus" << grpcStatus;
     return {grpcStatus, QString::fromUtf8(networkReply->rawHeader(GrpcStatusMessage))};
 }
 
@@ -245,7 +254,7 @@ void QGrpcHttp2Channel::call(const QString &method, const QString &service, cons
             QObject::disconnect(*abortConnection);
         }
 
-        qProtoDebug() << "RECV: " << data;
+        qGrpcDebug() << "RECV: " << data;
         if (QGrpcStatus::StatusCode::Ok == grpcStatus) {
             reply->setData(data);
             reply->finished();
@@ -281,12 +290,12 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
         auto replyIt = dPtr->activeStreamReplies.find(networkReply);
 
         QByteArray data = networkReply->readAll();
-        qProtoDebug() << "RECV" << data.size();
+        qGrpcDebug() << "RECV" << data.size();
 
         if (replyIt == dPtr->activeStreamReplies.end()) {
-            qProtoDebug() << data.toHex();
+            qGrpcDebug() << data.toHex();
             int expectedDataSize = QGrpcHttp2ChannelPrivate::getExpectedDataSize(data);
-            qProtoDebug() << "First chunk received: " << data.size() << " expectedDataSize: " << expectedDataSize;
+            qGrpcDebug() << "First chunk received: " << data.size() << " expectedDataSize: " << expectedDataSize;
 
             if (expectedDataSize == 0) {
                 grpcStream->handler(QByteArray());
@@ -300,15 +309,15 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
         QGrpcHttp2ChannelPrivate::ExpectedData &dataContainer = replyIt->second;
         dataContainer.container.append(data);
 
-        qProtoDebug() << "Proceed chunk: " << data.size() << " dataContainer: " << dataContainer.container.size() << " capacity: " << dataContainer.expectedSize;
+        qGrpcDebug() << "Proceed chunk: " << data.size() << " dataContainer: " << dataContainer.container.size() << " capacity: " << dataContainer.expectedSize;
         while (dataContainer.container.size() >= dataContainer.expectedSize && !networkReply->isFinished()) {
-            qProtoDebug() << "Full data received: " << data.size() << " dataContainer: " << dataContainer.container.size() << " capacity: " << dataContainer.expectedSize;
+            qGrpcDebug() << "Full data received: " << data.size() << " dataContainer: " << dataContainer.container.size() << " capacity: " << dataContainer.expectedSize;
             grpcStream->handler(dataContainer.container.mid(GrpcMessageSizeHeaderSize, dataContainer.expectedSize - GrpcMessageSizeHeaderSize));
             dataContainer.container.remove(0, dataContainer.expectedSize);
             if (dataContainer.container.size() > GrpcMessageSizeHeaderSize) {
                 dataContainer.expectedSize = QGrpcHttp2ChannelPrivate::getExpectedDataSize(dataContainer.container);
             } else if (dataContainer.container.size() > 0) {
-                qProtoWarning() << "Invalid container size received, size header is less than 5 bytes";
+                qGrpcWarning() << "Invalid container size received, size header is less than 5 bytes";
             }
         }
 
@@ -345,10 +354,10 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
         dPtr->activeStreamReplies.erase(networkReply);
         QGrpcHttp2ChannelPrivate::abortNetworkReply(networkReply);
         networkReply->deleteLater();
-        qProtoWarning() << grpcStream->method() << "call" << service << "stream finished: " << errorString;
+        qGrpcWarning() << grpcStream->method() << "call" << service << "stream finished: " << errorString;
         switch (networkError) {
         case QNetworkReply::RemoteHostClosedError:
-            qProtoDebug() << "Remote server closed connection. Reconnect silently";
+            qGrpcDebug() << "Remote server closed connection. Reconnect silently";
             stream(grpcStream, service, client);
             break;
         case QNetworkReply::NoError: {
@@ -365,7 +374,7 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
             break;
         }
         default:
-            grpcStream->error(QGrpcStatus{StatusCodeMap.at(networkError), QString("%1 call %2 stream failed: %3").arg(service).arg(grpcStream->method()).arg(errorString)});
+            grpcStream->error(QGrpcStatus{StatusCodeMap.at(networkError), QString::fromLatin1("%1 call %2 stream failed: %3").arg(service).arg(grpcStream->method()).arg(errorString)});
             break;
         }
     });
@@ -388,5 +397,7 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
 std::shared_ptr<QAbstractProtobufSerializer> QGrpcHttp2Channel::serializer() const
 {
     //TODO: make selection based on credentials or channel settings
-    return QProtobufSerializerRegistry::instance().getSerializer("protobuf");
+    return QProtobufSerializerRegistry::instance().getSerializer(QLatin1String("protobuf"));
 }
+
+QT_END_NAMESPACE

+ 6 - 5
src/grpc/qgrpchttp2channel.h

@@ -25,12 +25,12 @@
 
 #pragma once //QGrpcHttp2Channel
 
-#include "qabstractgrpcchannel.h"
+#include <QtGrpc/qabstractgrpcchannel.h>
 
 #include <QUrl>
 #include <memory>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QAbstractGrpcCredentials;
 struct QGrpcHttp2ChannelPrivate;
@@ -38,7 +38,7 @@ struct QGrpcHttp2ChannelPrivate;
  * \ingroup QtGrpc
  * \brief The QGrpcHttp2Channel class is HTTP/2 implementation of QAbstractGrpcChannel interface
  * \details For QGrpcHttp2Channel utilizes channel and call credentials.
- *          For channel credential QGrpcHttp2Channel supports SslConfigCredential key. When https
+ *          For channel credential QGrpcHttp2Channel supports QGrpcSslConfigCredential key. When https
  *          is used, this key has to be explicitly specified and provide QSslConfiguration and value.
  *          Provided QSslConfiguration will be used to establish HTTP/2 secured connection.
  *          All keys passed as QGrpcCallCredentials will be used as HTTP/2 headers with related values
@@ -56,7 +56,7 @@ public:
     ~QGrpcHttp2Channel();
 
     QGrpcStatus call(const QString &method, const QString &service, const QByteArray &args, QByteArray &ret) override;
-    void call(const QString &method, const QString &service, const QByteArray &args, QtProtobuf::QGrpcCallReply *reply) override;
+    void call(const QString &method, const QString &service, const QByteArray &args, QGrpcCallReply *reply) override;
     void stream(QGrpcStream *stream, const QString &service, QAbstractGrpcClient *client) override;
     std::shared_ptr<QAbstractProtobufSerializer> serializer() const override;
 private:
@@ -64,4 +64,5 @@ private:
 
     std::unique_ptr<QGrpcHttp2ChannelPrivate> dPtr;
 };
-}
+
+QT_END_NAMESPACE

+ 9 - 6
src/grpc/qgrpcinsecurecredentials.h

@@ -25,10 +25,10 @@
 
 #pragma once //QGrpcInsecureCredentials
 
-#include "qgrpccredentials.h"
-#include "qtgrpcglobal.h"
+#include <QtGrpc/qgrpccredentials.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 /*!
  * \ingroup QtGrpc
  * \brief The QGrpcInsecureCallCredentials class is dummy implementation of
@@ -36,7 +36,8 @@ namespace QtProtobuf {
  *
  *        Use it when you don't need any call credentials.
  */
-class Q_GRPC_EXPORT QGrpcInsecureCallCredentials final : public QGrpcCallCredentials {
+class Q_GRPC_EXPORT QGrpcInsecureCallCredentials final : public QGrpcCallCredentials
+{
 public:
     QGrpcCredentialMap operator()() const {
         return QGrpcCredentialMap{};
@@ -50,10 +51,12 @@ public:
  *
  *        Use it when you don't need any channel credentials.
  */
-class Q_GRPC_EXPORT QGrpcInsecureChannelCredentials final : public QGrpcChannelCredentials {
+class Q_GRPC_EXPORT QGrpcInsecureChannelCredentials final : public QGrpcChannelCredentials
+{
 public:
     QGrpcCredentialMap channelCredentials() const {
         return QGrpcCredentialMap{};
     }
 };
-}
+
+QT_END_NAMESPACE

+ 7 - 6
src/grpc/qgrpcsslcredentials.h

@@ -25,12 +25,12 @@
 
 #pragma once //QGrpcSslCredentials
 
-#include "qgrpccredentials.h"
-#include "qtgrpcglobal.h"
+#include <QtGrpc/qgrpccredentials.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
-#include <QSslConfiguration>
+#include <QtNetwork/qsslconfiguration.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtGrpc
@@ -40,7 +40,7 @@ class Q_GRPC_EXPORT QGrpcSslCredentials final : public QGrpcChannelCredentials
 {
 public:
     QGrpcSslCredentials(const QSslConfiguration &configuation) :
-        m_map(QGrpcCredentialMap{{QLatin1String(SslConfigCredential),
+        m_map(QGrpcCredentialMap{{QLatin1String(QGrpcSslConfigCredential),
               QVariant::fromValue<QSslConfiguration>(configuation)}})
     {}
 
@@ -51,4 +51,5 @@ private:
 	QGrpcSslCredentials() = default;
     QGrpcCredentialMap m_map;
 };
-}
+
+QT_END_NAMESPACE

+ 5 - 4
src/grpc/qgrpcstatus.cpp

@@ -25,7 +25,7 @@
 
 #include "qgrpcstatus.h"
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 //! \private
 class QGrpcStatusPrivate {
 public:
@@ -91,13 +91,14 @@ bool QGrpcStatus::operator ==(const QGrpcStatus &other) const
     return dPtr->m_code == other.dPtr->m_code;
 }
 
-}
+QT_END_NAMESPACE
 
-bool operator ==(QtProtobuf::QGrpcStatus::StatusCode code, const QtProtobuf::QGrpcStatus &status)
+bool operator ==(QGrpcStatus::StatusCode code, const QGrpcStatus &status)
 {
     return status == code;
 }
-bool operator !=(QtProtobuf::QGrpcStatus::StatusCode code, const QtProtobuf::QGrpcStatus &status)
+
+bool operator !=(QGrpcStatus::StatusCode code, const QGrpcStatus &status)
 {
     return status != code;
 }

+ 13 - 10
src/grpc/qgrpcstatus.h

@@ -25,14 +25,15 @@
 
 #pragma once //QGrpcStatus
 
-#include <QString>
-#include <QMetaType>
-#include <qobjectdefs.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qmetatype.h>
+#include <QtCore/qobjectdefs.h>
+
+#include <QtGrpc/qtgrpcglobal.h>
 
-#include "qtgrpcglobal.h"
 #include <memory>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QGrpcStatusPrivate;
 
@@ -55,7 +56,8 @@ class QGrpcStatusPrivate;
  *        processing QGrpcStatus will contain code any of non-Ok QGrpcStatus::StatusCode.
  *        This class combines QGrpcStatus::StatusCode and message returned from channel or QGrpc framework.
  */
-class Q_GRPC_EXPORT QGrpcStatus final {
+class Q_GRPC_EXPORT QGrpcStatus final
+{
     Q_GADGET
     Q_PROPERTY(StatusCode code READ code CONSTANT)
     Q_PROPERTY(QString message READ message CONSTANT)
@@ -114,9 +116,10 @@ public:
 private:
     std::unique_ptr<QGrpcStatusPrivate> dPtr;
 };
-}
 
-bool operator ==(QtProtobuf::QGrpcStatus::StatusCode code, const QtProtobuf::QGrpcStatus &status);
-bool operator !=(QtProtobuf::QGrpcStatus::StatusCode code, const QtProtobuf::QGrpcStatus &status);
+QT_END_NAMESPACE
+
+bool operator ==(QGrpcStatus::StatusCode code, const QGrpcStatus &status);
+bool operator !=(QGrpcStatus::StatusCode code, const QGrpcStatus &status);
 
-Q_DECLARE_METATYPE(QtProtobuf::QGrpcStatus)
+Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QGrpcStatus))

+ 7 - 4
src/grpc/qgrpcstream.cpp

@@ -25,12 +25,13 @@
 
 #include "qgrpcstream.h"
 
-#include <qtprotobuflogging.h>
+#include "qtgrpclogging_p.h"
+
 #include <QThread>
 
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
 
-QGrpcStream::QGrpcStream(const QString &method, const QByteArray &arg, const StreamHandler &handler, QAbstractGrpcClient *parent) : QGrpcAsyncOperationBase(parent)
+QGrpcStream::QGrpcStream(const QString &method, const QByteArray &arg, const QGrpcStreamHandler &handler, QAbstractGrpcClient *parent) : QGrpcAsyncOperationBase(parent)
   , m_method(method)
   , m_arg(arg)
 {
@@ -39,7 +40,7 @@ QGrpcStream::QGrpcStream(const QString &method, const QByteArray &arg, const Str
     }
 }
 
-void QGrpcStream::addHandler(const StreamHandler &handler)
+void QGrpcStream::addHandler(const QGrpcStreamHandler &handler)
 {
     if (handler) {
         m_handlers.push_back(handler);
@@ -54,3 +55,5 @@ void QGrpcStream::abort()
         finished();
     }
 }
+
+QT_END_NAMESPACE

+ 8 - 9
src/grpc/qgrpcstream.h

@@ -29,12 +29,11 @@
 #include <QMutex>
 #include <memory>
 
-#include "qabstractgrpcclient.h"
-#include "qgrpcasyncoperationbase_p.h"
+#include <QtGrpc/qabstractgrpcclient.h>
+#include <QtGrpc/qgrpcasyncoperationbase.h>
+#include <QtGrpc/qtgrpcglobal.h>
 
-#include "qtgrpcglobal.h"
-
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QAbstractGrpcClient;
 
@@ -88,12 +87,12 @@ signals:
 protected:
     //! \private
     QGrpcStream(const QString &method, const QByteArray &arg,
-                const StreamHandler &handler, QAbstractGrpcClient *parent);
+                const QGrpcStreamHandler &handler, QAbstractGrpcClient *parent);
     //! \private
     virtual ~QGrpcStream() = default;
 
     //! \private
-    void addHandler(const StreamHandler &handler);
+    void addHandler(const QGrpcStreamHandler &handler);
 
     bool operator ==(const QGrpcStream &other) const {
         return other.method() == this->method() &&
@@ -104,7 +103,7 @@ private:
     friend class QAbstractGrpcClient;
     QString m_method;
     QByteArray m_arg;
-    std::vector<StreamHandler> m_handlers;
+    std::vector<QGrpcStreamHandler> m_handlers;
 };
 
-}
+QT_END_NAMESPACE

+ 7 - 6
src/grpc/qgrpcuserpasswordcredentials.h

@@ -25,9 +25,9 @@
 
 #pragma once //QGrpcUserPasswordCredentials
 
-#include "qgrpccredentials.h"
+#include <QtGrpc/qgrpccredentials.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 constexpr char defaultUserFieldName[] = "user-name";
 constexpr char defaultPasswordFieldName[] = "user-password";
@@ -53,16 +53,17 @@ public:
      * \param password value that will be assigned to PasswordFieldName header for each gRPC call
      */
     QGrpcUserPasswordCredentials(const QString &userName, const QString &password) :
-        m_map(QtProtobuf::QGrpcCredentialMap{{QLatin1String(UserFieldName), QVariant::fromValue(userName)},
+        m_map(QGrpcCredentialMap{{QLatin1String(UserFieldName), QVariant::fromValue(userName)},
                                       {QLatin1String(PasswordFieldName), QVariant::fromValue(password)}})
 	{}
 
     //!\private
-	QtProtobuf::QGrpcCredentialMap operator()() {
+    QGrpcCredentialMap operator()() {
 		return m_map;
 	}
 private:
 	QGrpcUserPasswordCredentials() = default;
-    QtProtobuf::QGrpcCredentialMap m_map;
+    QGrpcCredentialMap m_map;
 };
-}
+
+QT_END_NAMESPACE

+ 8 - 6
src/grpc/qtgrpcglobal.h

@@ -27,6 +27,9 @@
 
 #include <QtCore/QtGlobal>
 
+#include <memory>
+#include <functional>
+
 #ifndef QT_PROTOBUF_STATIC
     #ifdef QT_BUILD_GRPC_LIB
         #define Q_GRPC_EXPORT Q_DECL_EXPORT
@@ -52,7 +55,7 @@
 #endif
 
 #ifndef Q_GRPC_IMPORT_QUICK_PLUGIN
-    #if defined(QT_PROTOBUF_STATIC) && defined(QT_QML_LIB) // TODO: Check how detect this in Qt6
+    #if defined(QT_PROTOBUF_STATIC) && defined(QT_QML_LIB)
         #include <QtPlugin>
         #include <QQmlExtensionPlugin>
         #define Q_GRPC_IMPORT_QUICK_PLUGIN() \
@@ -63,13 +66,12 @@
     #endif //QT_PROTOBUF_STATIC
 #endif //Q_PROTOBUF_IMPORT_QUICK_PLUGIN
 
-#include <memory>
-#include <functional>
+QT_BEGIN_NAMESPACE
 
-namespace QtProtobuf {
 class QGrpcCallReply;
 class QGrpcStream;
 using QGrpcCallReplyShared = std::shared_ptr<QGrpcCallReply>;
 using QGrpcStreamShared = std::shared_ptr<QGrpcStream>;
-using StreamHandler = std::function<void(const QByteArray&)>;
-}
+using QGrpcStreamHandler = std::function<void(const QByteArray&)>;
+
+QT_END_NAMESPACE

+ 7 - 3
tests/test_protobuf/nestedtest.cpp → src/grpc/qtgrpclogging.cpp

@@ -1,7 +1,7 @@
 /*
  * MIT License
  *
- * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>
+ * Copyright (c) 2022 Alexey Edelev <semlanik@gmail.com>
  *
  * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  *
@@ -23,6 +23,10 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "nestedmessages.qpb.h"
+#include "qtgrpclogging_p.h"
 
-#include "./nestedtest.cpp.inc"
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(Grpc, "qt.grpc", QtWarningMsg)
+
+QT_END_NAMESPACE

+ 36 - 0
src/grpc/qtgrpclogging_p.h

@@ -0,0 +1,36 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Alexey Edelev <semlanik@gmail.com>
+ *
+ * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(Grpc)
+QT_END_NAMESPACE
+
+#define qGrpcDebug(...) qCDebug(Grpc, __VA_ARGS__)
+#define qGrpcInfo(...) qCInfo(Grpc, __VA_ARGS__)
+#define qGrpcWarning(...) qCWarning(Grpc, __VA_ARGS__)
+#define qGrpcCritical(...) qCCritical(Grpc, __VA_ARGS__)

+ 9 - 9
src/grpc/quick/qquickgrpcstream.cpp

@@ -85,14 +85,14 @@ bool QQuickGrpcStream::stream()
     QString errorString;
     if (!method.isValid()) {
         errorString = m_method + "is not either server or bidirectional stream.";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::Unimplemented, errorString});
         return false;
     }
 
     if (method.parameterCount() < 2) {
         errorString = QString("Unable to call ") + method.name() + ". Invalid arguments set.";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -100,7 +100,7 @@ bool QQuickGrpcStream::stream()
     QMetaType argumentPointerMetaType(method.parameterType(0));
     if (argumentPointerMetaType.metaObject() != m_argument->metaObject()) {
         errorString = QString("Unable to call ") + method.name() + ". Argument type mismatch: '" + method.parameterTypes().at(0) + "' expected, '" + m_argument->metaObject()->className() + "' provided";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -108,7 +108,7 @@ bool QQuickGrpcStream::stream()
     QMetaType argumentMetaType(QMetaType::type(m_argument->metaObject()->className()));
     if (!argumentMetaType.isValid()) {
         errorString = QString("Argument of type '") + m_argument->metaObject()->className() + "' is not registred in metatype system";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -116,7 +116,7 @@ bool QQuickGrpcStream::stream()
     QObject *argument = reinterpret_cast<QObject*>(argumentMetaType.create(m_argument));
     if (argument == nullptr) {
         errorString = "Unable to create argument copy. Unknown metatype system error";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -125,7 +125,7 @@ bool QQuickGrpcStream::stream()
     QMetaType returnPointerType(method.parameterType(1));
     if (!returnPointerType.isValid()) {
         errorString = QString("Return type argument of type '") + method.parameterTypes().at(1) + "' is not registred in metatype system";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -133,7 +133,7 @@ bool QQuickGrpcStream::stream()
     QMetaType returnMetaType(QMetaType::type(returnPointerType.metaObject()->className()));
     if (!returnMetaType.isValid()) {
         errorString = QString("Unable to allocate return value. '") + returnPointerType.metaObject()->className() + "' is not registred in metatype system";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::InvalidArgument, errorString});
         return false;
     }
@@ -145,7 +145,7 @@ bool QQuickGrpcStream::stream()
 
     if (m_returnValue == nullptr) {
         errorString = "Unable to allocate return value. Unknown metatype system error";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::Unknown, errorString});
         return false;
     }
@@ -157,7 +157,7 @@ bool QQuickGrpcStream::stream()
                                       QGenericArgument(method.parameterTypes().at(1).data(), static_cast<const void *>(&m_returnValue)));
     if (!ok || stream == nullptr) {
         errorString = QString("Unable to call ") + m_method + " invalidate stream.";
-        qProtoWarning() << errorString;
+        qGrpcWarning() << errorString;
         error({QGrpcStatus::Unknown, errorString});
         return false;
     }

+ 24 - 54
src/protobuf/CMakeLists.txt

@@ -1,5 +1,3 @@
-qt_protobuf_extract_qt_variable(QT_INSTALL_PLUGINS)
-
 if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/3rdparty/microjson/CMakeLists.txt")
     set(MICROJSON_MAKE_TESTS OFF)
     set(MICROJSON_OBJECT_LIB_ONLY ON)
@@ -9,68 +7,40 @@ else()
     message(FATAL_ERROR "microjson is not found.")
 endif()
 
-qt_protobuf_internal_add_library(Protobuf
+qt_internal_add_module(Protobuf
     SOURCES
         qtprotobuf.cpp
-        qtprotobuflogging.cpp
-        qprotobufserializerregistry.cpp
-        qabstractprotobufserializer.cpp
-        qprotobufjsonserializer.cpp
-        qprotobufserializer.cpp
-        qprotobufmetaproperty.cpp
-        qprotobufmetaobject.cpp
-        qtprotobufglobal.h
-        qtprotobuftypes.h
-        qtprotobuflogging.h
-        qprotobufobject.h
-        qprotobufserializerregistry_p.h
-        qqmllistpropertyconstructor.h
-        qabstractprotobufserializer.h
-        qabstractprotobufserializer_p.h
-        qprotobufserializer.h
+        qtprotobuflogging.cpp qtprotobuflogging_p.h
+        qprotobufserializerregistry.cpp qprotobufserializerregistry_p.h
+        qabstractprotobufserializer.cpp qabstractprotobufserializer.h
+        qabstractprotobufserializercommon.h
+        qprotobufjsonserializer.cpp qprotobufjsonserializer.h
+        qprotobufserializer.cpp qprotobufserializer.h
         qprotobufserializer_p.h
-        qprotobufjsonserializer.h
-        qprotobufselfcheckiterator.h
-        qprotobufmetaproperty.h
-        qprotobufmetaobject.h
-        qprotobufserializationplugininterface.h
-        qprotobuflazymessagepointer.h
-    PUBLIC_HEADER
+        qprotobufmetaproperty.cpp qprotobufmetaproperty.h
+        qprotobufmetaobject.cpp qprotobufmetaobject.h
         qtprotobufglobal.h
         qtprotobuftypes.h
-        qtprotobuflogging.h
         qprotobufobject.h
-        qqmllistpropertyconstructor.h
-        qabstractprotobufserializer.h
-        qabstractprotobufserializer_p.h
-        qprotobufserializer.h
-        qprotobufjsonserializer.h
         qprotobufselfcheckiterator.h
-        qprotobufmetaproperty.h
-        qprotobufmetaobject.h
         qprotobufserializationplugininterface.h
         qprotobuflazymessagepointer.h
     PUBLIC_LIBRARIES
-        Qt6::Core
-        Qt6::Qml
-    PUBLIC_DEFINES
-        QT_PROTOBUF_PLUGIN_PATH="${QT_INSTALL_PLUGINS}/protobuf"
+        Qt::Core
+    LIBRARIES
+        microjson
+    EXTRA_CMAKE_FILES
+        "${CMAKE_CURRENT_LIST_DIR}/cmake/${INSTALL_CMAKE_NAMESPACE}ProtobufMacro.cmake"
+        "${CMAKE_CURRENT_LIST_DIR}/cmake/QtPreParseProtoFile.cmake"
+    EXTRA_CMAKE_INCLUDES
+        "${INSTALL_CMAKE_NAMESPACE}ProtobufMacro.cmake"
+    EXCEPTIONS
 )
 
-qtprotobuf_link_target(Protobuf microjson)
-set_target_properties(Protobuf PROPERTIES
-    QT_PROTOBUF_PLUGIN_PATH "${QT_INSTALL_PLUGINS}/protobuf"
+qt_internal_extend_target(Protobuf
+    CONDITION TARGET Qt::Qml
+    SOURCES
+        qtprotobufqmllistpropertyconstructor.h
+    PUBLIC_LIBRARIES
+        Qt::Qml
 )
-set_property(TARGET Protobuf APPEND PROPERTY EXPORT_PROPERTIES QT_PROTOBUF_PLUGIN_PATH)
-
-if(NOT BUILD_SHARED_LIBS)
-    set(QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS QT_PROTOBUF_STATIC)
-    set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") # extra config for .pri file in case if static
-                                              # build enabled
-endif()
-
-qt_protobuf_internal_generate_pri(Protobuf)
-
-if(TARGET Qt6::Quick)
-    add_subdirectory("quick")
-endif()

+ 63 - 27
cmake/QtProtobufGen.cmake → src/protobuf/cmake/Qt6ProtobufMacro.cmake

@@ -1,22 +1,46 @@
-# TODO: give the variable a proper name while migrating to Qt6
-set(_qt_internal_qtprotobuf_top_level_dir "${CMAKE_CURRENT_LIST_DIR}")
-
-function(qtprotobuf_link_target target generated_target)
-    target_sources(${target} PRIVATE $<TARGET_OBJECTS:${generated_target}>)
-    target_include_directories(${target} PRIVATE $<TARGET_PROPERTY:${generated_target},INTERFACE_INCLUDE_DIRECTORIES>)
-    add_dependencies(${target} ${generated_target})
+# TODO Qt6: give the variable a proper name while migrating to Qt6
+set(_qt_internal_qtprotobufgen_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
+
+function(_qt_internal_link_protobuf_objects target)
+    foreach(generated_target IN LISTS ARGN)
+        target_sources(${target} PRIVATE $<TARGET_OBJECTS:${generated_target}>)
+        target_include_directories(${target} PRIVATE $<TARGET_PROPERTY:${generated_target},INTERFACE_INCLUDE_DIRECTORIES>)
+        add_dependencies(${target} ${generated_target})
+    endforeach()
 endfunction()
 
-function(qtprotobuf_generate)
+# TODO Qt6: Use WrapProtobuf instead
+find_package(Protobuf)
+
+# TODO Qt6:
+#     - Collect PROTO_INCLUDES from the LINK_LIBRARIES property of TARGET
+#     - Compile static/shared library instead of object library
+#     - Move protobuf types registration to a separate register file, like it's done for QML
+#       and build only this file into OBJECT library.
+#     - Collect proto files from the source files of the ${TARGET}
+function(qt6_protobuf_generate)
     set(options MULTI QML COMMENTS FOLDER FIELDENUM)
-    set(oneValueArgs OUTPUT_DIRECTORY TARGET GENERATED_TARGET EXTRA_NAMESPACE)
+    set(oneValueArgs OUTPUT_DIRECTORY TARGET GENERATED_TARGET EXTRA_NAMESPACE PROTO_FILES_BASE_DIR)
     set(multiValueArgs EXCLUDE_HEADERS PROTO_FILES PROTO_INCLUDES)
     cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
-    if(NOT DEFINED arg_PROTO_FILES)
-        message(FATAL_ERROR "Missing the PROTO_FILES argument.")
+    unset(proto_files)
+    foreach(proto_file IN LISTS arg_PROTO_FILES)
+        if(NOT IS_ABSOLUTE "${proto_file}")
+            if(arg_PROTO_FILES_BASE_DIR)
+                set(proto_file "${arg_PROTO_FILES_BASE_DIR}/${proto_file}")
+            endif()
+            get_filename_component(proto_file "${proto_file}" ABSOLUTE)
+        endif()
+        list(APPEND proto_files "${proto_file}")
+    endforeach()
+    list(REMOVE_DUPLICATES proto_files)
+
+    if("${proto_files}" STREQUAL "")
+        message(FATAL_ERROR "PROTO_FILES list is empty.")
     endif()
 
+
     if(DEFINED arg_GENERATED_TARGET)
         set(generated_target_name ${arg_GENERATED_TARGET})
     elseif(TARGET ${arg_TARGET})
@@ -78,7 +102,7 @@ function(qtprotobuf_generate)
 
     set(proto_includes ${arg_PROTO_INCLUDES})
 
-    set(pre_parse_script "${_qt_internal_qtprotobuf_top_level_dir}/QtPreParseProtoFile.cmake")
+    set(pre_parse_script "${_qt_internal_qtprotobufgen_cmake_dir}/QtPreParseProtoFile.cmake")
 
     if(NOT EXISTS "${pre_parse_script}")
         message(FATAL_ERROR "Unable to locate the QtPreParseProtoFile script"
@@ -86,7 +110,7 @@ function(qtprotobuf_generate)
     endif()
 
     unset(generated_files)
-    foreach(proto_file IN LISTS arg_PROTO_FILES)
+    foreach(proto_file IN LISTS proto_files)
         get_filename_component(proto_file_base_dir "${proto_file}" DIRECTORY)
         list(PREPEND proto_includes "-I\"${proto_file_base_dir}\"")
         execute_process(COMMAND ${CMAKE_COMMAND}
@@ -134,6 +158,9 @@ function(qtprotobuf_generate)
     set_source_files_properties(${generated_files} PROPERTIES
         GENERATED TRUE
         SKIP_AUTOGEN ON
+        SKIP_AUTOMOC ON
+        SKIP_AUTORCC ON
+        SKIP_AUTOUIC ON
     )
 
     # Filter generated headers
@@ -145,7 +172,7 @@ function(qtprotobuf_generate)
         endif()
     endforeach()
 
-    qt5_wrap_cpp(moc_sources ${generated_headers})
+    qt_wrap_cpp(moc_sources ${generated_headers})
 
     get_property(num_deps GLOBAL PROPERTY ${generated_target_name}_deps_num)
     if(NOT num_deps)
@@ -158,14 +185,14 @@ function(qtprotobuf_generate)
 
     add_custom_command(OUTPUT ${generated_files}
         COMMAND ${PROTOC_COMMAND}
-            --plugin=protoc-gen-qtprotobufgen=$<TARGET_FILE:${QT_PROTOBUF_NAMESPACE}::qtprotobufgen>
+            --plugin=protoc-gen-qtprotobufgen=$<TARGET_FILE:${QT_CMAKE_EXPORT_NAMESPACE}::qtprotobufgen>
             --qtprotobufgen_out=${out_dir}
             ${proto_includes}
-            ${arg_PROTO_FILES}
+            ${proto_files}
         WORKING_DIRECTORY ${out_dir}
         DEPENDS
-            ${QT_PROTOBUF_NAMESPACE}::qtprotobufgen
-            ${arg_PROTO_FILES}
+        ${QT_CMAKE_EXPORT_NAMESPACE}::qtprotobufgen
+            ${proto_files}
         COMMENT "Generating QtProtobuf ${generated_target_name} sources..."
         COMMAND_EXPAND_LISTS
     )
@@ -182,27 +209,36 @@ function(qtprotobuf_generate)
     set_target_properties(${generated_target_name} PROPERTIES PUBLIC_HEADER "${generated_headers}")
 
     #Add include directories in case if targets are found by find_project or in source tree
-    target_include_directories(${generated_target_name} PUBLIC ${out_dir} PRIVATE
-        $<TARGET_PROPERTY:${QT_PROTOBUF_NAMESPACE}::Protobuf,INTERFACE_INCLUDE_DIRECTORIES>)
+    target_include_directories(${generated_target_name}
+        PRIVATE $<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Protobuf,INTERFACE_INCLUDE_DIRECTORIES>)
 
     #TODO: Do not link targets if they are not used in .proto files.
-    if(TARGET ${QT_PROTOBUF_NAMESPACE}::Grpc)
+    if(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::Grpc)
         target_include_directories(${generated_target_name} PRIVATE
-            $<TARGET_PROPERTY:${QT_PROTOBUF_NAMESPACE}::Grpc,INTERFACE_INCLUDE_DIRECTORIES>)
+            $<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Grpc,INTERFACE_INCLUDE_DIRECTORIES>)
     endif()
 
-    if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufWellKnownTypes)
+    if(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::ProtobufWellKnownTypes)
         target_include_directories(${generated_target_name} PRIVATE
-            $<TARGET_PROPERTY:${QT_PROTOBUF_NAMESPACE}::ProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>)
+            $<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::ProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>)
     endif()
 
-    if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufQtTypes)
+    if(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::ProtobufQtTypes)
         target_include_directories(${generated_target_name} PRIVATE
-            $<TARGET_PROPERTY:${QT_PROTOBUF_NAMESPACE}::ProtobufQtTypes,INTERFACE_INCLUDE_DIRECTORIES>)
+            $<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::ProtobufQtTypes,INTERFACE_INCLUDE_DIRECTORIES>)
     endif()
 
+    target_include_directories(${generated_target_name} PUBLIC "$<BUILD_INTERFACE:${out_dir}>")
+
     # Automatically link whole static library to specified in parameters target
     if(TARGET ${arg_TARGET})
-        qtprotobuf_link_target(${arg_TARGET} ${generated_target_name})
+        _qt_internal_link_protobuf_objects(${arg_TARGET} ${generated_target_name})
+        target_include_directories(${arg_TARGET} PUBLIC "$<BUILD_INTERFACE:${out_dir}>")
     endif()
 endfunction()
+
+if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
+    function(qt_protobuf_generate)
+        qt6_protobuf_generate(${ARGV})
+    endfunction()
+endif()

+ 1 - 7
cmake/QtPreParseProtoFile.cmake → src/protobuf/cmake/QtPreParseProtoFile.cmake

@@ -1,11 +1,5 @@
 cmake_minimum_required(VERSION 3.16)
 
-function(extract_proto_keys out_var regex file_content)
-    cmake_parse_arguments(arg "SINGLE_VALUE" "" "" ${ARGN})
-
-
-endfunction()
-
 if(NOT PROTO_FILE OR NOT EXISTS "${PROTO_FILE}")
     message(FATAL_ERROR "Unable to scan '${PROTO_FILE}': file doesn't exist.")
 endif()
@@ -95,4 +89,4 @@ else()
     endif()
 endif()
 
-message("${output_files}")
+message("${output_files}")

+ 6 - 3
src/protobuf/qabstractprotobufserializer.cpp

@@ -29,11 +29,10 @@
 #include <QMutex>
 #include <QSemaphore>
 
-#include "qabstractprotobufserializer.h"
+#include <QtProtobuf/qabstractprotobufserializer.h>
 
-using namespace QtProtobuf;
 
-namespace  {
+namespace {
 
 const int MaximumSimultaniousThreads = 64;
 /*!
@@ -77,6 +76,8 @@ private:
     static QtProtobufPrivate::SerializationHandler empty;
 };
 
+QT_BEGIN_NAMESPACE
+
 QtProtobufPrivate::SerializationHandler HandlersRegistry::empty{};
 }
 
@@ -89,3 +90,5 @@ QtProtobufPrivate::SerializationHandler QtProtobufPrivate::findHandler(int userT
 {
     return HandlersRegistry::instance().findHandler(userType);
 }
+
+QT_END_NAMESPACE

+ 16 - 17
src/protobuf/qabstractprotobufserializer.h

@@ -33,13 +33,12 @@
 #include <functional>
 #include <memory>
 
-#include "qtprotobuftypes.h"
-#include "qtprotobuflogging.h"
-#include "qprotobufselfcheckiterator.h"
+#include <QtProtobuf/qtprotobuftypes.h>
+#include <QtProtobuf/qprotobufselfcheckiterator.h>
 
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qtprotobufglobal.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QProtobufMetaProperty;
 class QProtobufMetaObject;
@@ -62,7 +61,7 @@ class QProtobufMetaObject;
  *          };
  *          \endcode
  *          Practically code above is generated automaticaly by running qtprotobufgenerator or using cmake build macro
- *          qtprotobuf_generate, based on .proto files. But it's still possible to reuse manually written code if needed.
+ *          qt6_protobuf_generate, based on .proto files. But it's still possible to reuse manually written code if needed.
  *
  *          This class should be used as base for specific serializers. The handlers property contains all
  *          message-specific serializers and should be used while serialization/deserialization. Inherited classes should reimplement
@@ -81,7 +80,6 @@ public:
     template<typename T>
     QByteArray serialize(const QObject *object) {
         Q_ASSERT(object != nullptr);
-        qProtoDebug() << T::staticMetaObject.className() << "serialize";
         return serializeMessage(object, T::protobufMetaObject);
     }
 
@@ -97,15 +95,14 @@ public:
     template<typename T>
     void deserialize(T *object, const QByteArray &data) {
         Q_ASSERT(object != nullptr);
-        qProtoDebug() << T::staticMetaObject.className() << "deserialize";
         //Initialize default object first and make copy aferwards, it's necessary to set default
         //values of properties that was not stored in data.
         T newValue;
-        try {
+        QT_TRY {
             deserializeMessage(&newValue, T::protobufMetaObject, data);
-        } catch(...) {
+        } QT_CATCH(...) {
             *object = newValue;
-            throw;
+            QT_RETHROW;
         }
         *object = newValue;
     }
@@ -220,6 +217,7 @@ public:
      */
     virtual QByteArray serializeMapEnd(QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const {
         Q_UNUSED(metaProperty);
+        Q_UNUSED(buffer);
         return {};
     }
 
@@ -244,7 +242,7 @@ public:
      *
      * \see https://developers.google.com/protocol-buffers/docs/proto3#maps for details
      */
-    virtual QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const = 0;
+    virtual QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const = 0;
 
     /*!
      * \brief serializeEnumList  Method called to serialize list of enum values
@@ -255,7 +253,7 @@ public:
      *
      * \see https://developers.google.com/protocol-buffers/docs/proto3#maps for details
      */
-    virtual QByteArray serializeEnumList(const QList<int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const = 0;
+    virtual QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const = 0;
 
     /*!
      * \brief deserializeEnum Deserializes enum value from byte stream
@@ -263,7 +261,7 @@ public:
      * \param[in] metaEnum Information about enumeration type
      * \param[in] it Points to serialized raw key/value data
      */
-    virtual void deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const = 0;
+    virtual void deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const = 0;
 
     /*!
      * \brief deserializeEnum Deserializes list of enum values from byte stream
@@ -271,12 +269,13 @@ public:
      * \param[in] metaEnum Information about enumeration type
      * \param[in] it Points to serialized raw key/value data
      */
-    virtual void deserializeEnumList(QList<int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const = 0;
+    virtual void deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const = 0;
 };
 /*! \} */
-}
 
-#include "qabstractprotobufserializer_p.h"
+QT_END_NAMESPACE
+
+#include <QtProtobuf/qabstractprotobufserializercommon.h>
 
 /*!
  * \brief Registers serializers for type T in QtProtobuf global serializers registry

+ 23 - 30
src/protobuf/qabstractprotobufserializer_p.h → src/protobuf/qabstractprotobufserializercommon.h

@@ -32,25 +32,23 @@
 
 #include <functional>
 
-#include "qtprotobuftypes.h"
-#include "qtprotobuflogging.h"
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qtprotobuftypes.h>
+#include <QtProtobuf/qabstractprotobufserializer.h>
+#include <QtProtobuf/qtprotobufglobal.h>
 
-namespace QtProtobuf {
-    class QAbstractProtobufSerializer;
-    class QProtobufSelfcheckIterator;
-    class QProtobufMetaProperty;
-}
+QT_BEGIN_NAMESPACE
+class QProtobufSelfcheckIterator;
+class QProtobufMetaProperty;
 
 namespace QtProtobufPrivate {
 //! \private
 constexpr int NotUsedFieldIndex = -1;
 
-using Serializer = std::function<void(const QtProtobuf::QAbstractProtobufSerializer *, const QVariant &, const QtProtobuf::QProtobufMetaProperty &, QByteArray &)>;
+using Serializer = std::function<void(const QAbstractProtobufSerializer *, const QVariant &, const QProtobufMetaProperty &, QByteArray &)>;
 /*!
  * \brief Deserializer is interface function for deserialize method
  */
-using Deserializer = std::function<void(const QtProtobuf::QAbstractProtobufSerializer *, QtProtobuf::QProtobufSelfcheckIterator &, QVariant &)>;
+using Deserializer = std::function<void(const QAbstractProtobufSerializer *, QProtobufSelfcheckIterator &, QVariant &)>;
 
 enum HandlerType {
     ObjectHandler,
@@ -77,7 +75,7 @@ extern Q_PROTOBUF_EXPORT void registerHandler(int userType, const SerializationH
  */
 template <typename T,
           typename std::enable_if_t<std::is_base_of<QObject, T>::value, int> = 0>
-void serializeObject(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeObject(const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     buffer.append(serializer->serializeObject(value.value<T *>(), T::protobufMetaObject, metaProperty));
 }
@@ -88,16 +86,13 @@ void serializeObject(const QtProtobuf::QAbstractProtobufSerializer *serializer,
  */
 template<typename V,
          typename std::enable_if_t<std::is_base_of<QObject, V>::value, int> = 0>
-void serializeList(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &listValue, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeList(const QAbstractProtobufSerializer *serializer, const QVariant &listValue, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QList<QSharedPointer<V>> list = listValue.value<QList<QSharedPointer<V>>>();
 
-    qProtoDebug() << __func__ << "listValue.count" << list.count();
-
     buffer.append(serializer->serializeListBegin(metaProperty));
     for (auto &value : list) {
         if (!value) {
-            qProtoWarning() << "Null pointer in list";
             continue;
         }
         buffer.append(serializer->serializeListObject(value.data(), V::protobufMetaObject, metaProperty));
@@ -111,7 +106,7 @@ void serializeList(const QtProtobuf::QAbstractProtobufSerializer *serializer, co
  */
 template<typename K, typename V,
          typename std::enable_if_t<!std::is_base_of<QObject, V>::value, int> = 0>
-void serializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeMap(const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QMap<K,V> mapValue = value.value<QMap<K,V>>();
     buffer.append(serializer->serializeMapBegin(metaProperty));
@@ -127,13 +122,12 @@ void serializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, con
  */
 template<typename K, typename V,
          typename std::enable_if_t<std::is_base_of<QObject, V>::value, int> = 0>
-void serializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeMap(const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QMap<K, QSharedPointer<V>> mapValue = value.value<QMap<K, QSharedPointer<V>>>();
     buffer.append(serializer->serializeMapBegin(metaProperty));
     for (auto it = mapValue.constBegin(); it != mapValue.constEnd(); it++) {
         if (it.value().isNull()) {
-            qProtoWarning() << __func__ << "Trying to serialize map value that contains nullptr";
             continue;
         }
         buffer.append(serializer->serializeMapPair(QVariant::fromValue<K>(it.key()), QVariant::fromValue<V *>(it.value().data()), metaProperty));
@@ -147,7 +141,7 @@ void serializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, con
  */
 template<typename T,
          typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
-void serializeEnum(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeEnum(const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     buffer.append(serializer->serializeEnum(QtProtobuf::int64(value.value<T>()), QMetaEnum::fromType<T>(),  metaProperty));
 }
@@ -158,7 +152,7 @@ void serializeEnum(const QtProtobuf::QAbstractProtobufSerializer *serializer, co
  */
 template<typename T,
          typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
-void serializeEnumList(const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
+void serializeEnumList(const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &metaProperty, QByteArray &buffer) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QList<QtProtobuf::int64> intList;
     for (auto enumValue : value.value<QList<T>>()) {
@@ -173,7 +167,7 @@ void serializeEnumList(const QtProtobuf::QAbstractProtobufSerializer *serializer
  */
 template <typename T,
           typename std::enable_if_t<std::is_base_of<QObject, T>::value, int> = 0>
-void deserializeObject(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &to) {
+void deserializeObject(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &to) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     T *value = new T;
     serializer->deserializeObject(value, T::protobufMetaObject, it);
@@ -186,9 +180,8 @@ void deserializeObject(const QtProtobuf::QAbstractProtobufSerializer *serializer
  */
 template <typename V,
           typename std::enable_if_t<std::is_base_of<QObject, V>::value, int> = 0>
-void deserializeList(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &previous) {
+void deserializeList(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &previous) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
-    qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
     V *newValue = new V;
     QList<QSharedPointer<V>> list = previous.value<QList<QSharedPointer<V>>>();
@@ -205,9 +198,8 @@ void deserializeList(const QtProtobuf::QAbstractProtobufSerializer *serializer,
  */
 template <typename K, typename V,
           typename std::enable_if_t<!std::is_base_of<QObject, V>::value, int> = 0>
-void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &previous) {
+void deserializeMap(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &previous) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
-    qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
     QMap<K, V> out = previous.value<QMap<K, V>>();
     QVariant key = QVariant::fromValue<K>(K());
@@ -227,9 +219,8 @@ void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, Q
  */
 template <typename K, typename V,
           typename std::enable_if_t<std::is_base_of<QObject, V>::value, int> = 0>
-void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &previous) {
+void deserializeMap(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &previous) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
-    qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
     auto out = previous.value<QMap<K, QSharedPointer<V>>>();
     QVariant key = QVariant::fromValue<K>(K());
@@ -248,7 +239,7 @@ void deserializeMap(const QtProtobuf::QAbstractProtobufSerializer *serializer, Q
  */
 template <typename T,
           typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
-void deserializeEnum(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &to) {
+void deserializeEnum(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &to) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QtProtobuf::int64 intValue;
     serializer->deserializeEnum(intValue, QMetaEnum::fromType<T>(), it);
@@ -262,7 +253,7 @@ void deserializeEnum(const QtProtobuf::QAbstractProtobufSerializer *serializer,
  */
 template <typename T,
           typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
-void deserializeEnumList(const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &previous) {
+void deserializeEnumList(const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &previous) {
     Q_ASSERT_X(serializer != nullptr, "QAbstractProtobufSerializer", "Serializer is null");
     QList<QtProtobuf::int64> intList;
     serializer->deserializeEnumList(intList, QMetaEnum::fromType<T>(), it);
@@ -272,4 +263,6 @@ void deserializeEnumList(const QtProtobuf::QAbstractProtobufSerializer *serializ
     }
     previous = QVariant::fromValue<QList<T>>(enumList);
 }
-}
+}// namespace QtProtobufPrivate
+
+QT_END_NAMESPACE

+ 13 - 15
src/protobuf/qprotobufjsonserializer.cpp

@@ -26,15 +26,13 @@
 #include "qprotobufjsonserializer.h"
 #include "qprotobufmetaobject.h"
 #include "qprotobufmetaproperty.h"
-#include "qtprotobuflogging.h"
+#include "qtprotobuflogging_p.h"
 
 #include <microjson.h>
 
 #include <QMetaProperty>
 
-using namespace QtProtobuf;
-
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 //! \private
 class QProtobufJsonSerializerPrivate final
@@ -61,7 +59,7 @@ public:
     }
 
     static QByteArray serializeString(const QVariant &propertyValue) {
-        return QString("\"%1\"").arg(propertyValue.toString()).toUtf8() ;
+        return QString::fromUtf8("\"%1\"").arg(propertyValue.toString()).toUtf8() ;
     }
 
     static QByteArray serializeBytes(const QVariant &propertyValue) {
@@ -83,7 +81,7 @@ public:
     }
 
     static QByteArray serializeDoubleList(const QVariant &propertyValue) {
-        DoubleList listValue = propertyValue.value<DoubleList>();
+        QtProtobuf::DoubleList listValue = propertyValue.value<QtProtobuf::DoubleList>();
         QByteArray result("[");
         for (auto value : listValue) {
             result += QString::number(value, 'g').toUtf8() + ",";
@@ -253,7 +251,7 @@ public:
     static QVariant deserializeString(const QByteArray &data, microjson::JsonType type, bool &ok) {
         if (type == microjson::JsonStringType) {
             ok = true;
-            return QVariant::fromValue(QString::fromUtf8(data).replace("\\\"", "\""));
+            return QVariant::fromValue(QString::fromUtf8(data).replace(QLatin1String("\\\""), QLatin1String("\"")));
         }
 
         ok = false;
@@ -315,8 +313,8 @@ public:
         QVariant newValue;
         auto handler = QtProtobufPrivate::findHandler(type);
         if (handler.deserializer) {
-            QtProtobuf::QProtobufSelfcheckIterator it(data);
-            QtProtobuf::QProtobufSelfcheckIterator last = it;
+            QProtobufSelfcheckIterator it(data);
+            QProtobufSelfcheckIterator last = it;
             last += it.size();
             while (it != last) {
                 ok = true;
@@ -365,8 +363,6 @@ private:
 
 QProtobufJsonSerializerPrivate::SerializerRegistry QProtobufJsonSerializerPrivate::handlers = {};
 
-}
-
 QProtobufJsonSerializer::QProtobufJsonSerializer() : dPtr(new QProtobufJsonSerializerPrivate(this))
 {
 }
@@ -476,12 +472,12 @@ bool QProtobufJsonSerializer::deserializeMapPair(QVariant &key, QVariant &value,
     return true;
 }
 
-QByteArray QProtobufJsonSerializer::serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &/*metaProperty*/) const
+QByteArray QProtobufJsonSerializer::serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &/*metaProperty*/) const
 {
     return QByteArray("\"") + metaEnum.key(static_cast<int>(value)) + "\"";
 }
 
-QByteArray QProtobufJsonSerializer::serializeEnumList(const QList<int64> &values, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &/*metaProperty*/) const
+QByteArray QProtobufJsonSerializer::serializeEnumList(const QList<QtProtobuf::int64> &values, const QMetaEnum &metaEnum, const QProtobufMetaProperty &/*metaProperty*/) const
 {
     QByteArray result = "[";
     for (auto value : values) {
@@ -496,13 +492,13 @@ QByteArray QProtobufJsonSerializer::serializeEnumList(const QList<int64> &values
     return result;
 }
 
-void QProtobufJsonSerializer::deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
+void QProtobufJsonSerializer::deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
 {
     value = metaEnum.keyToValue(it.data());
     it += it.size();
 }
 
-void QProtobufJsonSerializer::deserializeEnumList(QList<int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
+void QProtobufJsonSerializer::deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const
 {
     auto arrayValues = microjson::parseJsonArray(it.data(), static_cast<size_t>(it.size()));
 
@@ -516,3 +512,5 @@ void QProtobufJsonSerializer::deserializeEnumList(QList<int64> &value, const QMe
 
     it += it.size();
 }
+
+QT_END_NAMESPACE

+ 8 - 8
src/protobuf/qprotobufjsonserializer.h

@@ -25,12 +25,12 @@
 
 #pragma once //QProtobufJsonSerializer
 
-#include "qabstractprotobufserializer.h"
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qabstractprotobufserializer.h>
+#include <QtProtobuf/qtprotobufglobal.h>
 
 #include <memory>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 class QProtobufJsonSerializerPrivate;
 /*!
 *  \ingroup QtProtobuf
@@ -61,13 +61,13 @@ protected:
 
     bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
 
-    QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    QByteArray serializeEnumList(const QList<int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const override;
 
-    void deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
-    void deserializeEnumList(QList<int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
 private:
     std::unique_ptr<QProtobufJsonSerializerPrivate> dPtr;
 };
 
-}
+QT_END_NAMESPACE

+ 10 - 5
src/protobuf/qprotobuflazymessagepointer.h

@@ -25,17 +25,19 @@
 
 #pragma once //QProtobufLazyMessagePointer
 
-#include "qtprotobufglobal.h"
-#include <QObject>
-#if defined(QT_QML_LIB) // TODO: Check how detect this in Qt6
+#include <QtProtobuf/qtprotobufglobal.h>
+#include <QtCore/qobject.h>
+
+#if defined(QT_QML_LIB)
 #  include <QQmlEngine>
 #endif
 
 #include <memory>
 #include <type_traits>
 
+QT_BEGIN_NAMESPACE
 template <typename T>
-class QProtobufLazyMessagePointer {//TODO: final?
+class QProtobufLazyMessagePointer final {
 public:
     QProtobufLazyMessagePointer(T *p = nullptr) : m_ptr(p) {}
 
@@ -104,7 +106,8 @@ private:
         bool qmlCheck = true;
 #endif
         if (m_ptr != nullptr && qmlCheck) {
-            m_ptr.release();//In case if object owned by QML it's qml responsibility to clean it up
+            //If the object owned by QML it's QML's responsibility to clean it up
+            m_ptr.release();
             QObject::disconnect(m_destroyed);
         }
     }
@@ -114,3 +117,5 @@ private:
     mutable std::unique_ptr<T> m_ptr;
     mutable QMetaObject::Connection m_destroyed;
 };
+
+QT_END_NAMESPACE

+ 5 - 1
src/protobuf/qprotobufmetaobject.cpp

@@ -24,9 +24,13 @@
  */
 
 #include "qprotobufmetaobject.h"
-using namespace QtProtobuf;
+
+QT_BEGIN_NAMESPACE
+
 QProtobufMetaObject::QProtobufMetaObject(const QMetaObject &_staticMetaObject, const QProtobufPropertyOrdering &_propertyOrdering)
     : staticMetaObject(_staticMetaObject)
     , propertyOrdering(_propertyOrdering)
 {
 }
+
+QT_END_NAMESPACE

+ 5 - 5
src/protobuf/qprotobufmetaobject.h

@@ -25,11 +25,11 @@
 
 #pragma once //QProtobufMetaObject
 
-#include "qtprotobufglobal.h"
-#include "qtprotobuftypes.h"
+#include <QtProtobuf/qtprotobufglobal.h>
+#include <QtProtobuf/qtprotobuftypes.h>
 
 #include <QMetaObject>
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtProtobuf
@@ -43,7 +43,7 @@ public:
     const QMetaObject &staticMetaObject;
     const QProtobufPropertyOrdering &propertyOrdering;
 private:
-    QProtobufMetaObject();
+    QProtobufMetaObject() = delete;
 };
 
-}
+QT_END_NAMESPACE

+ 4 - 1
src/protobuf/qprotobufmetaproperty.cpp

@@ -26,7 +26,8 @@
 #include "qprotobufmetaproperty.h"
 #include "qtprotobuftypes.h"
 
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
+
 QProtobufMetaProperty::QProtobufMetaProperty(const QMetaProperty &metaProperty,
                                              int fieldIndex,
                                              const QString &jsonName) : QMetaProperty(metaProperty)
@@ -45,3 +46,5 @@ QString QProtobufMetaProperty::jsonPropertyName() const
 {
     return m_jsonName;
 }
+
+QT_END_NAMESPACE

+ 4 - 5
src/protobuf/qprotobufmetaproperty.h

@@ -26,16 +26,15 @@
 #pragma once //QProtobufMetaProperty
 
 #include <QMetaProperty>
+#include <QtProtobuf/qtprotobufglobal.h>
 
-#include "qtprotobufglobal.h"
-
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 /*!
  * \ingroup QtProtobuf
  * \private
  * \brief The QProtobufMetaProperty class
  */
-struct PropertyOrderingInfo;
+struct QProtobufPropertyOrderingInfo;
 
 class Q_PROTOBUF_EXPORT QProtobufMetaProperty : public QMetaProperty
 {
@@ -49,4 +48,4 @@ private:
     const QString &m_jsonName;
 };
 
-}
+QT_END_NAMESPACE

+ 6 - 7
src/protobuf/qprotobufobject.h

@@ -25,9 +25,8 @@
 
 #pragma once //QProtobufObject
 
-#include "qabstractprotobufserializer.h"
-#include "qprotobufmetaobject.h"
-#include <unordered_map>
+#include <QtProtobuf/qabstractprotobufserializer.h>
+#include <QtProtobuf/qprotobufmetaobject.h>
 
 /*!
  * \defgroup QtProtobuf
@@ -42,8 +41,8 @@
 
 #define Q_DECLARE_PROTOBUF_SERIALIZERS(T)\
     public:\
-        QByteArray serialize(QtProtobuf::QAbstractProtobufSerializer *serializer) const { Q_ASSERT_X(serializer != nullptr, "QProtobufObject", "Serializer is null"); return serializer->serialize<T>(this); }\
-        void deserialize(QtProtobuf::QAbstractProtobufSerializer *serializer, const QByteArray &array) { Q_ASSERT_X(serializer != nullptr, "QProtobufObject", "Serializer is null"); serializer->deserialize<T>(this, array); }\
+        QByteArray serialize(QAbstractProtobufSerializer *serializer) const { Q_ASSERT_X(serializer != nullptr, "QProtobufObject", "Serializer is null"); return serializer->serialize<T>(this); }\
+        void deserialize(QAbstractProtobufSerializer *serializer, const QByteArray &array) { Q_ASSERT_X(serializer != nullptr, "QProtobufObject", "Serializer is null"); serializer->deserialize<T>(this, array); }\
     private:
 
 /*!
@@ -54,6 +53,6 @@
 
 #define Q_PROTOBUF_OBJECT\
     public:\
-        static const QtProtobuf::QProtobufPropertyOrdering propertyOrdering;\
-        static const QtProtobuf::QProtobufMetaObject protobufMetaObject;\
+        static const QProtobufPropertyOrdering propertyOrdering;\
+        static const QProtobufMetaObject protobufMetaObject;\
     private:

+ 9 - 9
src/protobuf/qprotobufselfcheckiterator.h

@@ -26,11 +26,11 @@
 #include <QByteArray>
 #include <stdexcept>
 
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qtprotobufglobal.h>
 
 #pragma once //QProtobufSelfcheckIterator
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtProtobuf
@@ -47,7 +47,7 @@ public:
       , m_containerSize(other.m_containerSize)
       , m_it(other.m_it) {
         if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
     }
 
@@ -59,7 +59,7 @@ public:
     QProtobufSelfcheckIterator &operator ++() {
         --m_sizeLeft;
         if (m_sizeLeft < 0) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
         ++m_it;
         return *this;
@@ -68,7 +68,7 @@ public:
     QProtobufSelfcheckIterator &operator --() {
         ++m_sizeLeft;
         if (m_sizeLeft > m_containerSize) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
         --m_it;
         return *this;
@@ -77,7 +77,7 @@ public:
     QProtobufSelfcheckIterator &operator +=(int count) {
         m_sizeLeft -= count;
         if (m_sizeLeft < 0) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
         m_it += count;
         return *this;
@@ -86,7 +86,7 @@ public:
     QProtobufSelfcheckIterator &operator -=(int count) {
         m_sizeLeft += count;
         if (m_sizeLeft > m_containerSize) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
         m_it -= count;
         return *this;
@@ -100,7 +100,7 @@ public:
         m_containerSize = other.m_containerSize;
         m_sizeLeft = other.m_sizeLeft;
         if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
-            throw std::out_of_range("Container is less than required fields number. Deserialization failed");
+            QT_THROW(std::out_of_range("Container is less than required fields number. Deserialization failed"));
         }
         m_it = other.m_it;
         return *this;
@@ -140,4 +140,4 @@ inline QProtobufSelfcheckIterator operator +(const QProtobufSelfcheckIterator &i
     return itNew += lenght;
 }
 
-}
+QT_END_NAMESPACE

+ 9 - 10
src/protobuf/qprotobufserializationplugininterface.h

@@ -32,10 +32,10 @@
 #include <unordered_map>
 #include <memory>
 
-#include "qtprotobufglobal.h"
-#include "qabstractprotobufserializer.h"
+#include <QtProtobuf/qtprotobufglobal.h>
+#include <QtProtobuf/qabstractprotobufserializer.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtProtobuf
@@ -49,17 +49,17 @@ namespace QtProtobuf {
  *          An example of class source code:
  *
  *          \code{.cpp}
- *          class SERIALIZATIONSHARED_EXPORT QtSerializationPlugin : public QObject, QtProtobuf::QProtobufSerializationPluginInterface
+ *          class SERIALIZATIONSHARED_EXPORT QtSerializationPlugin : public QObject, QProtobufSerializationPluginInterface
  *          {
  *              Q_OBJECT
  *              Q_PLUGIN_METADATA(IID SerializatorInterface_iid FILE "serializeinfo.json")
- *              Q_INTERFACES(QtProtobuf::QProtobufSerializationPluginInterface)
+ *              Q_INTERFACES(QProtobufSerializationPluginInterface)
  *
  *          public:
  *              QtSerializationPlugin();
  *              ~QtSerializationPlugin() = default;
  *
- *              virtual std::shared_ptr<QtProtobuf::QAbstractProtobufSerializer> serializer(const QString &serializerName);
+ *              virtual std::shared_ptr<QAbstractProtobufSerializer> serializer(const QString &serializerName);
  *
  *          }
  *          \endcode
@@ -92,11 +92,10 @@ public:
      * \param[in] name of specific serializer that should be supplied by plugin.
      * \return An object to serializer realization.
      */
-    virtual std::shared_ptr<QtProtobuf::QAbstractProtobufSerializer> serializer(const QString &serializerName) = 0;
+    virtual std::shared_ptr<QAbstractProtobufSerializer> serializer(const QString &serializerName) = 0;
 };
 
-}
-QT_BEGIN_NAMESPACE
 #define SerializatorInterface_iid "com.qtprotobuf.QProtobufSerializationPluginInterface"
-Q_DECLARE_INTERFACE(QtProtobuf::QProtobufSerializationPluginInterface, SerializatorInterface_iid)
+Q_DECLARE_INTERFACE(QProtobufSerializationPluginInterface, SerializatorInterface_iid)
+
 QT_END_NAMESPACE

+ 43 - 41
src/protobuf/qprotobufserializer.cpp

@@ -29,7 +29,7 @@
 #include "qprotobufmetaproperty.h"
 #include "qprotobufmetaobject.h"
 
-using namespace QtProtobuf;
+QT_BEGIN_NAMESPACE
 
 template<>
 QByteArray QProtobufSerializerPrivate::serializeListType<QByteArray>(const QByteArrayList &listValue, int &outFieldIndex)
@@ -142,40 +142,40 @@ bool QProtobufSerializer::deserializeMapPair(QVariant &key, QVariant &value, QPr
     return true;
 }
 
-QByteArray QProtobufSerializer::serializeEnum(int64 value, const QMetaEnum &/*metaEnum*/, const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+QByteArray QProtobufSerializer::serializeEnum(QtProtobuf::int64 value, const QMetaEnum &/*metaEnum*/, const QProtobufMetaProperty &metaProperty) const
 {
     WireTypes type = Varint;
     int fieldIndex = metaProperty.protoFieldIndex();
-    QByteArray result = QProtobufSerializerPrivate::serializeBasic<int64>(value, fieldIndex);
+    QByteArray result = QProtobufSerializerPrivate::serializeBasic<QtProtobuf::int64>(value, fieldIndex);
     if (fieldIndex != QtProtobufPrivate::NotUsedFieldIndex) {
         result.prepend(QProtobufSerializerPrivate::encodeHeader(metaProperty.protoFieldIndex(), type));
     }
     return result;
 }
 
-QByteArray QProtobufSerializer::serializeEnumList(const QList<int64> &value, const QMetaEnum &/*metaEnum*/, const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+QByteArray QProtobufSerializer::serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &/*metaEnum*/, const QProtobufMetaProperty &metaProperty) const
 {
     WireTypes type = LengthDelimited;
     int fieldIndex = metaProperty.protoFieldIndex();
-    QByteArray result = QProtobufSerializerPrivate::serializeListType<int64>(value, fieldIndex);
+    QByteArray result = QProtobufSerializerPrivate::serializeListType<QtProtobuf::int64>(value, fieldIndex);
     if (fieldIndex != QtProtobufPrivate::NotUsedFieldIndex) {
         result.prepend(QProtobufSerializerPrivate::encodeHeader(metaProperty.protoFieldIndex(), type));
     }
     return result;
 }
 
-void QProtobufSerializer::deserializeEnum(int64 &value, const QMetaEnum &/*metaEnum*/, QProtobufSelfcheckIterator &it) const
+void QProtobufSerializer::deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &/*metaEnum*/, QProtobufSelfcheckIterator &it) const
 {
     QVariant variantValue;
-    QProtobufSerializerPrivate::deserializeBasic<int64>(it, variantValue);
-    value = variantValue.value<int64>();
+    QProtobufSerializerPrivate::deserializeBasic<QtProtobuf::int64>(it, variantValue);
+    value = variantValue.value<QtProtobuf::int64>();
 }
 
-void QProtobufSerializer::deserializeEnumList(QList<int64> &value, const QMetaEnum &/*metaEnum*/, QProtobufSelfcheckIterator &it) const
+void QProtobufSerializer::deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &/*metaEnum*/, QProtobufSelfcheckIterator &it) const
 {
     QVariant variantValue;
-    QProtobufSerializerPrivate::deserializeList<int64>(it, variantValue);
-    value = variantValue.value<QList<int64>>();
+    QProtobufSerializerPrivate::deserializeList<QtProtobuf::int64>(it, variantValue);
+    value = variantValue.value<QList<QtProtobuf::int64>>();
 }
 
 QProtobufSerializerPrivate::QProtobufSerializerPrivate(QProtobufSerializer *q) : q_ptr(q)
@@ -184,32 +184,32 @@ QProtobufSerializerPrivate::QProtobufSerializerPrivate(QProtobufSerializer *q) :
     if (handlers.empty()) {
         wrapSerializer<float, serializeBasic, deserializeBasic<float>, Fixed32>();
         wrapSerializer<double, serializeBasic, deserializeBasic<double>, Fixed64>();
-        wrapSerializer<int32, serializeBasic, deserializeBasic<int32>, Varint>();
-        wrapSerializer<int64, serializeBasic, deserializeBasic<int64>, Varint>();
-        wrapSerializer<uint32, serializeBasic, deserializeBasic<uint32>, Varint>();
-        wrapSerializer<uint64, serializeBasic, deserializeBasic<uint64>, Varint>();
-        wrapSerializer<sint32, serializeBasic, deserializeBasic<sint32>, Varint>();
-        wrapSerializer<sint64, serializeBasic, deserializeBasic<sint64>, Varint>();
-        wrapSerializer<fixed32, serializeBasic, deserializeBasic<fixed32>, Fixed32>();
-        wrapSerializer<fixed64, serializeBasic, deserializeBasic<fixed64>, Fixed64>();
-        wrapSerializer<sfixed32, serializeBasic, deserializeBasic<sfixed32>, Fixed32>();
-        wrapSerializer<sfixed64, serializeBasic, deserializeBasic<sfixed64>, Fixed64>();
-        wrapSerializer<bool, uint32, serializeBasic<uint32>, deserializeBasic<uint32>, Varint>();
+        wrapSerializer<QtProtobuf::int32, serializeBasic, deserializeBasic<QtProtobuf::int32>, Varint>();
+        wrapSerializer<QtProtobuf::int64, serializeBasic, deserializeBasic<QtProtobuf::int64>, Varint>();
+        wrapSerializer<QtProtobuf::uint32, serializeBasic, deserializeBasic<QtProtobuf::uint32>, Varint>();
+        wrapSerializer<QtProtobuf::uint64, serializeBasic, deserializeBasic<QtProtobuf::uint64>, Varint>();
+        wrapSerializer<QtProtobuf::sint32, serializeBasic, deserializeBasic<QtProtobuf::sint32>, Varint>();
+        wrapSerializer<QtProtobuf::sint64, serializeBasic, deserializeBasic<QtProtobuf::sint64>, Varint>();
+        wrapSerializer<QtProtobuf::fixed32, serializeBasic, deserializeBasic<QtProtobuf::fixed32>, Fixed32>();
+        wrapSerializer<QtProtobuf::fixed64, serializeBasic, deserializeBasic<QtProtobuf::fixed64>, Fixed64>();
+        wrapSerializer<QtProtobuf::sfixed32, serializeBasic, deserializeBasic<QtProtobuf::sfixed32>, Fixed32>();
+        wrapSerializer<QtProtobuf::sfixed64, serializeBasic, deserializeBasic<QtProtobuf::sfixed64>, Fixed64>();
+        wrapSerializer<bool, QtProtobuf::uint32, serializeBasic<QtProtobuf::uint32>, deserializeBasic<QtProtobuf::uint32>, Varint>();
         wrapSerializer<QString, serializeBasic, deserializeBasic<QString>, LengthDelimited>();
         wrapSerializer<QByteArray, serializeBasic, deserializeBasic<QByteArray>, LengthDelimited>();
 
-        wrapSerializer<FloatList, serializeListType, deserializeList<float>, LengthDelimited>();
-        wrapSerializer<DoubleList, serializeListType, deserializeList<double>, LengthDelimited>();
-        wrapSerializer<fixed32List, serializeListType, deserializeList<fixed32>, LengthDelimited>();
-        wrapSerializer<fixed64List, serializeListType, deserializeList<fixed64>, LengthDelimited>();
-        wrapSerializer<sfixed32List, serializeListType, deserializeList<sfixed32>, LengthDelimited>();
-        wrapSerializer<sfixed64List, serializeListType, deserializeList<sfixed64>, LengthDelimited>();
-        wrapSerializer<int32List, serializeListType, deserializeList<int32>, LengthDelimited>();
-        wrapSerializer<int64List, serializeListType, deserializeList<int64>, LengthDelimited>();
-        wrapSerializer<sint32List, serializeListType, deserializeList<sint32>, LengthDelimited>();
-        wrapSerializer<sint64List, serializeListType, deserializeList<sint64>, LengthDelimited>();
-        wrapSerializer<uint32List, serializeListType, deserializeList<uint32>, LengthDelimited>();
-        wrapSerializer<uint64List, serializeListType, deserializeList<uint64>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::FloatList, serializeListType, deserializeList<float>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::DoubleList, serializeListType, deserializeList<double>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::fixed32List, serializeListType, deserializeList<QtProtobuf::fixed32>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::fixed64List, serializeListType, deserializeList<QtProtobuf::fixed64>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::sfixed32List, serializeListType, deserializeList<QtProtobuf::sfixed32>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::sfixed64List, serializeListType, deserializeList<QtProtobuf::sfixed64>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::int32List, serializeListType, deserializeList<QtProtobuf::int32>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::int64List, serializeListType, deserializeList<QtProtobuf::int64>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::sint32List, serializeListType, deserializeList<QtProtobuf::sint32>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::sint64List, serializeListType, deserializeList<QtProtobuf::sint64>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::uint32List, serializeListType, deserializeList<QtProtobuf::uint32>, LengthDelimited>();
+        wrapSerializer<QtProtobuf::uint64List, serializeListType, deserializeList<QtProtobuf::uint64>, LengthDelimited>();
         wrapSerializer<QStringList, QStringList, serializeListType<QString>, deserializeList<QString>, LengthDelimited>();
         wrapSerializer<QByteArrayList, serializeListType, deserializeList<QByteArray>, LengthDelimited>();
     }
@@ -226,7 +226,7 @@ void QProtobufSerializerPrivate::skipVarint(QProtobufSelfcheckIterator &it)
 void QProtobufSerializerPrivate::skipLengthDelimited(QProtobufSelfcheckIterator &it)
 {
     //Get length of lenght-delimited field
-    uint32 length = QProtobufSerializerPrivate::deserializeVarintCommon<uint32>(it);
+    QtProtobuf::uint32 length = QProtobufSerializerPrivate::deserializeVarintCommon<QtProtobuf::uint32>(it);
     it += length;
 }
 
@@ -238,17 +238,17 @@ int QProtobufSerializerPrivate::skipSerializedFieldBytes(QProtobufSelfcheckItera
         skipVarint(it);
         break;
     case WireTypes::Fixed32:
-        it += sizeof(decltype(fixed32::_t));
+        it += sizeof(decltype(QtProtobuf::fixed32::_t));
         break;
     case WireTypes::Fixed64:
-        it += sizeof(decltype(fixed64::_t));
+        it += sizeof(decltype(QtProtobuf::fixed64::_t));
         break;
     case WireTypes::LengthDelimited:
         skipLengthDelimited(it);
         break;
     case WireTypes::UnknownWireType:
     default:
-        throw std::invalid_argument("Cannot skip due to undefined length of the redundant field.");
+        QT_THROW(std::invalid_argument("Cannot skip due to undefined length of the redundant field."));
     }
 
     return std::distance(initialIt, QByteArray::const_iterator(it));
@@ -290,8 +290,8 @@ void QProtobufSerializerPrivate::deserializeProperty(QObject *object, const QPro
     if (!QProtobufSerializerPrivate::decodeHeader(it, fieldNumber, wireType)) {
         qProtoCritical() << "Message received doesn't contains valid header byte. "
                             "Trying next, but seems stream is broken" << QString::number((*it), 16);
-        throw std::invalid_argument("Message received doesn't contains valid header byte. "
-                              "Seems stream is broken");
+        QT_THROW(std::invalid_argument("Message received doesn't contains valid header byte. "
+                              "Seems stream is broken"));
     }
 
     auto propertyNumberIt = metaObject.propertyOrdering.find(fieldNumber);
@@ -328,7 +328,7 @@ void QProtobufSerializerPrivate::deserializeMapPair(QVariant &key, QVariant &val
 {
     int mapIndex = 0;
     WireTypes type = WireTypes::UnknownWireType;
-    unsigned int count = QProtobufSerializerPrivate::deserializeVarintCommon<uint32>(it);
+    unsigned int count = QProtobufSerializerPrivate::deserializeVarintCommon<QtProtobuf::uint32>(it);
     qProtoDebug() << __func__ << "count:" << count;
     QProtobufSelfcheckIterator last = it + count;
     while (it != last) {
@@ -353,3 +353,5 @@ void QProtobufSerializerPrivate::deserializeMapPair(QVariant &key, QVariant &val
 }
 
 QProtobufSerializerPrivate::SerializerRegistry QProtobufSerializerPrivate::handlers = {};
+
+QT_END_NAMESPACE

+ 8 - 8
src/protobuf/qprotobufserializer.h

@@ -25,10 +25,10 @@
 
 #pragma once //QProtobufSerializer
 
-#include "qabstractprotobufserializer.h"
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qabstractprotobufserializer.h>
+#include <QtProtobuf/qtprotobufglobal.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QProtobufSerializerPrivate;
 /*!
@@ -54,13 +54,13 @@ protected:
     QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QProtobufMetaProperty &metaProperty) const override;
     bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const override;
 
-    QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
-    QByteArray serializeEnumList(const QList<int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QProtobufMetaProperty &metaProperty) const override;
 
-    void deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
-    void deserializeEnumList(QList<int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const override;
 
     std::unique_ptr<QProtobufSerializerPrivate> dPtr;
 };
 
-}
+QT_END_NAMESPACE

+ 20 - 20
src/protobuf/qprotobufserializer_p.h

@@ -26,12 +26,12 @@
 #include <QString>
 #include <QByteArray>
 
-#include "qprotobufselfcheckiterator.h"
-#include "qtprotobuftypes.h"
-#include "qtprotobuflogging.h"
-#include "qabstractprotobufserializer.h"
+#include <QtProtobuf/qprotobufselfcheckiterator.h>
+#include <QtProtobuf/qtprotobuftypes.h>
+#include <QtProtobuf/private/qtprotobuflogging_p.h>
+#include <QtProtobuf/qabstractprotobufserializer.h>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtProtobuf
@@ -126,10 +126,10 @@ public:
      * \return Byte array with value encoded
      */
     template <typename V,
-              typename std::enable_if_t<std::is_same<V, fixed32>::value
-                                        || std::is_same<V, fixed64>::value
-                                        || std::is_same<V, sfixed32>::value
-                                        || std::is_same<V, sfixed64>::value, int> = 0>
+              typename std::enable_if_t<std::is_same<V, QtProtobuf::fixed32>::value
+                                        || std::is_same<V, QtProtobuf::fixed64>::value
+                                        || std::is_same<V, QtProtobuf::sfixed32>::value
+                                        || std::is_same<V, QtProtobuf::sfixed64>::value, int> = 0>
     static QByteArray serializeBasic(const V &value, int &/*outFieldIndex*/) {
         qProtoDebug() << __func__ << "value" << value;
 
@@ -165,8 +165,8 @@ public:
     }
 
     template <typename V,
-              typename std::enable_if_t<std::is_same<V, int32>::value
-                                        || std::is_same<V, int64>::value, int> = 0>
+              typename std::enable_if_t<std::is_same<V, QtProtobuf::int32>::value
+                                        || std::is_same<V, QtProtobuf::int64>::value, int> = 0>
     static QByteArray serializeBasic(const V &value, int &outFieldIndex) {
         qProtoDebug() << __func__ << "value" << value;
         using UV = typename std::make_unsigned<V>::type;
@@ -296,10 +296,10 @@ public:
     //-------------Integral and floating point types deserializers---------------
     template <typename V,
               typename std::enable_if_t<std::is_floating_point<V>::value
-                                        || std::is_same<V, fixed32>::value
-                                        || std::is_same<V, fixed64>::value
-                                        || std::is_same<V, sfixed32>::value
-                                        || std::is_same<V, sfixed64>::value, int> = 0>
+                                        || std::is_same<V, QtProtobuf::fixed32>::value
+                                        || std::is_same<V, QtProtobuf::fixed64>::value
+                                        || std::is_same<V, QtProtobuf::sfixed32>::value
+                                        || std::is_same<V, QtProtobuf::sfixed64>::value, int> = 0>
     static void deserializeBasic(QProtobufSelfcheckIterator &it, QVariant &variantValue) {
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
@@ -328,8 +328,8 @@ public:
     }
 
     template <typename V,
-              typename std::enable_if_t<std::is_same<int32, V>::value
-                                        || std::is_same<int64, V>::value, int> = 0>
+              typename std::enable_if_t<std::is_same<QtProtobuf::int32, V>::value
+                                        || std::is_same<QtProtobuf::int64, V>::value, int> = 0>
     static void deserializeBasic(QProtobufSelfcheckIterator &it, QVariant &variantValue) {
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
         using  UV = typename std::make_unsigned<V>::type;
@@ -358,7 +358,7 @@ public:
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
         QList<V> out;
-        unsigned int count = deserializeVarintCommon<uint32>(it);
+        unsigned int count = deserializeVarintCommon<QtProtobuf::uint32>(it);
         QProtobufSelfcheckIterator lastVarint = it + count;
         while (it != lastVarint) {
             QVariant variantValue;
@@ -374,7 +374,7 @@ public:
     static QByteArray deserializeLengthDelimited(QProtobufSelfcheckIterator &it) {
         qProtoDebug() << __func__ << "currentByte:" << QString::number((*it), 16);
 
-        unsigned int length = deserializeVarintCommon<uint32>(it);
+        unsigned int length = deserializeVarintCommon<QtProtobuf::uint32>(it);
         QByteArray result((QByteArray::const_iterator&)it, length); //TODO: it's possible to avoid buffer copying by setuping new "end of QByteArray";
         it += length;
         return result;
@@ -492,4 +492,4 @@ inline bool QProtobufSerializerPrivate::decodeHeader(QProtobufSelfcheckIterator
                                                              || wireType == LengthDelimited);
 }
 
-}
+QT_END_NAMESPACE

+ 8 - 10
src/protobuf/qprotobufserializerregistry.cpp

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "qtprotobuflogging.h"
+#include "qtprotobuflogging_p.h"
 #include "qprotobufserializerregistry_p.h"
 #include "qprotobufserializer.h"
 #include "qprotobufjsonserializer.h"
@@ -35,6 +35,7 @@
 #include <QPluginLoader>
 #include <QJsonObject>
 #include <QJsonArray>
+#include <QLibraryInfo>
 
 namespace {
 const QLatin1String TypeNames("types");
@@ -53,12 +54,11 @@ const QLatin1String LibExtension(".so");
 const QLatin1String LibPrefix("lib");
 #endif
 
-static const char *QtProtobufPluginPath = QT_PROTOBUF_PLUGIN_PATH;
-const QString DefaultImpl("Default");
+const QLatin1String DefaultImpl("Default");
 }
 
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 //! \private
 struct QProtobufSerializerRegistryPrivateRecord final
 {
@@ -111,7 +111,7 @@ struct QProtobufSerializerRegistryPrivateRecord final
     {
         if (loader == nullptr || !loader->load()) {
             qProtoWarning() << "Can't load plugin from" << libPath
-                            << "loader error" << (loader != nullptr ? loader->errorString() : "");
+                            << "loader error" << (loader != nullptr ? loader->errorString() : QLatin1String(""));
             return nullptr;
         }
         return loader->instance();
@@ -137,7 +137,7 @@ public:
         std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> plugin = std::shared_ptr<QProtobufSerializerRegistryPrivateRecord>(new QProtobufSerializerRegistryPrivateRecord());
         plugin->createDefaultImpl();
         m_plugins[DefaultImpl] = plugin;
-        m_pluginPath = QString::fromUtf8(QtProtobufPluginPath);
+        m_pluginPath = QLibraryInfo::path(QLibraryInfo::PluginsPath);
         QString envPluginPath = QString::fromUtf8(qgetenv("QT_PROTOBUF_PLUGIN_PATH"));
         if (!envPluginPath.isEmpty()) {
             m_pluginPath = envPluginPath;
@@ -168,10 +168,6 @@ public:
     QString m_pluginPath;
 };
 
-}
-
-using namespace QtProtobuf;
-
 QProtobufSerializerRegistry::QProtobufSerializerRegistry() :
     dPtr(new QProtobufSerializerRegistryPrivate())
 {
@@ -253,3 +249,5 @@ int QProtobufSerializerRegistry::pluginRating(const QString &plugin)
 
     return implementation->metaData.value(Rating).toInt();
 }
+
+QT_END_NAMESPACE

+ 3 - 2
src/protobuf/qprotobufserializerregistry_p.h

@@ -36,7 +36,7 @@
 
 #include "qtprotobufglobal.h"
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 class QProtobufSerializerRegistryPrivate;
 
@@ -76,4 +76,5 @@ private:
 
     std::unique_ptr<QProtobufSerializerRegistryPrivate> dPtr;
 };
-}
+
+QT_END_NAMESPACE

+ 1 - 1
src/protobuf/qt_lib_protobuf.pri.in

@@ -10,7 +10,7 @@ QT.protobuf.module_config = @QT_PROTOBUF_EXTRA_CONFIG@
 CONFIG += c++17
 DEFINES += @QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS@
 
-defineTest(qtprotobuf_generate) {
+defineTest(qt6_protobuf_generate) {
     OK = false
 
     QML_ENABLED = $$1

+ 35 - 37
src/protobuf/qtprotobuf.cpp

@@ -26,14 +26,10 @@
 #include "qtprotobuftypes.h"
 #include "qprotobufobject.h"
 
-#include <type_traits>
-
-#define registerProtobufType(X) qRegisterMetaType<X>(# X);\
-                                qRegisterMetaType<X>("QtProtobuf::"# X)
+#define registerProtobufType(X) qRegisterMetaType<X>(# X)
 
 namespace QtProtobuf {
 
-namespace  {
 template<typename T>
 void registerBasicConverters() {
     QMetaType::registerConverter<int32_t, T>(T::fromType);
@@ -52,53 +48,55 @@ void registerBasicConverters() {
     QMetaType::registerConverter<T, double>(T::toType);
     QMetaType::registerConverter<T, QString>(T::toString);
 }
-}
 
-std::list<RegisterFunction>& registerFunctions() {
+std::list<QtProtobuf::RegisterFunction>& registerFunctions() {
     static std::list<std::function<void(void)>> registrationList;
     return registrationList;
 }
 
+} //namespace QtProtobuf
+
 void qRegisterProtobufTypes() {
     static bool registred = false;
     if (registred) {
         return;
     }
     registred = true;
-    registerProtobufType(int32);
-    registerProtobufType(int64);
-    registerProtobufType(uint32);
-    registerProtobufType(uint64);
-    registerProtobufType(sint32);
-    registerProtobufType(sint64);
-    registerProtobufType(fixed32);
-    registerProtobufType(fixed64);
-    registerProtobufType(sfixed32);
-    registerProtobufType(sfixed64);
+    registerProtobufType(QtProtobuf::int32);
+    registerProtobufType(QtProtobuf::int64);
+    registerProtobufType(QtProtobuf::uint32);
+    registerProtobufType(QtProtobuf::uint64);
+    registerProtobufType(QtProtobuf::sint32);
+    registerProtobufType(QtProtobuf::sint64);
+    registerProtobufType(QtProtobuf::fixed32);
+    registerProtobufType(QtProtobuf::fixed64);
+    registerProtobufType(QtProtobuf::sfixed32);
+    registerProtobufType(QtProtobuf::sfixed64);
 
-    registerProtobufType(int32List);
-    registerProtobufType(int64List);
-    registerProtobufType(uint32List);
-    registerProtobufType(uint64List);
-    registerProtobufType(sint32List);
-    registerProtobufType(sint64List);
-    registerProtobufType(fixed32List);
-    registerProtobufType(fixed64List);
-    registerProtobufType(sfixed32List);
-    registerProtobufType(sfixed64List);
+    registerProtobufType(QtProtobuf::int32List);
+    registerProtobufType(QtProtobuf::int64List);
+    registerProtobufType(QtProtobuf::uint32List);
+    registerProtobufType(QtProtobuf::uint64List);
+    registerProtobufType(QtProtobuf::sint32List);
+    registerProtobufType(QtProtobuf::sint64List);
+    registerProtobufType(QtProtobuf::fixed32List);
+    registerProtobufType(QtProtobuf::fixed64List);
+    registerProtobufType(QtProtobuf::sfixed32List);
+    registerProtobufType(QtProtobuf::sfixed64List);
 
-    registerProtobufType(DoubleList);
-    registerProtobufType(FloatList);
+    registerProtobufType(QtProtobuf::DoubleList);
+    registerProtobufType(QtProtobuf::FloatList);
 
-    registerBasicConverters<int32>();
-    registerBasicConverters<int64>();
-    registerBasicConverters<sfixed32>();
-    registerBasicConverters<sfixed64>();
-    registerBasicConverters<fixed32>();
-    registerBasicConverters<fixed64>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::int32>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::int64>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::sfixed32>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::sfixed64>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::fixed32>();
+    QtProtobuf::registerBasicConverters<QtProtobuf::fixed64>();
 
-    for (auto registerFunc : registerFunctions()) {
+    for (auto registerFunc : QtProtobuf::registerFunctions()) {
         registerFunc();
     }
 }
-}
+
+QT_END_NAMESPACE

+ 2 - 2
src/protobuf/qtprotobufglobal.h

@@ -60,7 +60,7 @@
  * \code
  * int main(int argc, char *argv[]) {
  *     ...
- *     QtProtobuf::qRegisterProtobufTypes();
+ *     qRegisterProtobufTypes();
  *     Q_PROTOBUF_IMPORT_QUICK_PLUGIN()
  *     ...
  * }
@@ -78,7 +78,7 @@
  * \endcode
  */
 #ifndef Q_PROTOBUF_IMPORT_QUICK_PLUGIN
-    #if defined(QT_PROTOBUF_STATIC) && defined(QT_QML_LIB) // TODO: Check how detect this in Qt6
+    #if defined(QT_PROTOBUF_STATIC) && defined(QT_QML_LIB)
         #include <QtPlugin>
         #include <QQmlExtensionPlugin>
         #define Q_PROTOBUF_IMPORT_QUICK_PLUGIN() \

+ 6 - 2
src/protobuf/qtprotobuflogging.cpp

@@ -23,6 +23,10 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "qtprotobuflogging.h"
+#include "qtprotobuflogging_p.h"
 
-Q_LOGGING_CATEGORY(qtprotobuflog, "qtprotobuflog", QtWarningMsg)
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(Protobuf, "qt.protobuf", QtWarningMsg)
+
+QT_END_NAMESPACE

+ 0 - 35
src/protobuf/qtprotobuflogging.h

@@ -1,35 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
- *
- * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this
- * software and associated documentation files (the "Software"), to deal in the Software
- * without restriction, including without limitation the rights to use, copy, modify,
- * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
- * to permit persons to whom the Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies
- * or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
- * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#pragma once
-#include <QLoggingCategory>
-#include <qtprotobufglobal.h>
-
-Q_PROTOBUF_EXPORT Q_DECLARE_LOGGING_CATEGORY(qtprotobuflog)
-
-#define qProtoDebug(...) qCDebug(qtprotobuflog, __VA_ARGS__)
-#define qProtoInfo(...) qCInfo(qtprotobuflog, __VA_ARGS__)
-#define qProtoWarning(...) qCWarning(qtprotobuflog, __VA_ARGS__)
-#define qProtoCritical(...) qCCritical(qtprotobuflog, __VA_ARGS__)

+ 8 - 16
tests/test_protobuf/deserializationtest.h → src/protobuf/qtprotobuflogging_p.h

@@ -25,21 +25,13 @@
 
 #pragma once
 
-#include <gtest/gtest.h>
-#include <qprotobufserializer.h>
+#include <QtCore/qloggingcategory.h>
 
-namespace QtProtobuf {
-namespace tests {
+QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(Protobuf)
+QT_END_NAMESPACE
 
-class DeserializationTest : public ::testing::Test
-{
-public:
-    DeserializationTest() = default;
-    void SetUp() override;
-    static void SetUpTestCase();
-protected:
-    std::unique_ptr<QProtobufSerializer> serializer;
-};
-
-}
-}
+#define qProtoDebug(...) qCDebug(Protobuf, __VA_ARGS__)
+#define qProtoInfo(...) qCInfo(Protobuf, __VA_ARGS__)
+#define qProtoWarning(...) qCWarning(Protobuf, __VA_ARGS__)
+#define qProtoCritical(...) qCCritical(Protobuf, __VA_ARGS__)

+ 15 - 16
src/protobuf/qqmllistpropertyconstructor.h → src/protobuf/qtprotobufqmllistpropertyconstructor.h

@@ -28,44 +28,43 @@
 #include <QQmlListProperty>
 #include <QQmlEngine>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
+
 //! \private
 template<typename T>
-static void qmllistpropertyAppend(QQmlListProperty<T> *p, T *v) {
+static void qProtobufQmlListPropertyAppend(QQmlListProperty<T> *p, T *v) {
     QQmlEngine::setObjectOwnership(v, QQmlEngine::CppOwnership);
     reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->append(QSharedPointer<T>(v));
 }
 
 //! \private
 template<typename T>
-static qsizetype qmllistpropertyCount(QQmlListProperty<T> *p) {
-    return reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->count();
+static qsizetype qProtobufQmlListPropertyCount(QQmlListProperty<T> *p) {
+    return reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->size();
 }
 
 //! \private
 template<typename T>
-static T *qmllistpropertyAt(QQmlListProperty<T> *p, qsizetype index) {
+static T *qProtobufQmlListPropertyAt(QQmlListProperty<T> *p, qsizetype index) {
     return reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->at(index).data();
 }
 
 //! \private
 template<typename T>
-static void qmllistpropertyReset(QQmlListProperty<T> *p) {
+static void qProtobufQmlListPropertyClear(QQmlListProperty<T> *p) {
     reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->clear();
 }
-    // using AppendFunction = void (*)(QQmlListProperty<T> *, T *);
-    // using CountFunction = qsizetype (*)(QQmlListProperty<T> *);
-    // using AtFunction = T *(*)(QQmlListProperty<T> *, qsizetype);
-    // using ClearFunction = void (*)(QQmlListProperty<T> *);
-    // using ReplaceFunction = void (*)(QQmlListProperty<T> *, qsizetype, T *);
-    // using RemoveLastFunction = void (*)(QQmlListProperty<T> *);
+// TODO Qt6: Check if it's necessary to implement missing functions
+// using ClearFunction = void (*)(QQmlListProperty<T> *);
+// using ReplaceFunction = void (*)(QQmlListProperty<T> *, qsizetype, T *);
+// using RemoveLastFunction = void (*)(QQmlListProperty<T> *);
 
 //! \private
 template<typename T>
-static QQmlListProperty<T> constructQmlListProperty(QObject *p, QList<QSharedPointer<T>> *data)
+static QQmlListProperty<T> qProtobufConstructQmlListProperty(QObject *p, QList<QSharedPointer<T>> *data)
 {
-    return QQmlListProperty<T>(p, data, qmllistpropertyAppend<T>, qmllistpropertyCount<T>,
-                               qmllistpropertyAt<T>, qmllistpropertyReset<T>);
+    return QQmlListProperty<T>(p, data, qProtobufQmlListPropertyAppend<T>, qProtobufQmlListPropertyCount<T>,
+                               qProtobufQmlListPropertyAt<T>, qProtobufQmlListPropertyClear<T>);
 }
 
-}
+QT_END_NAMESPACE

+ 20 - 19
src/protobuf/qtprotobuftypes.h

@@ -25,7 +25,7 @@
 
 #pragma once //QtProtobufTypes
 
-#include "qtprotobufglobal.h"
+#include <QtProtobuf/qtprotobufglobal.h>
 
 #include <QList>
 #include <QMap>
@@ -36,7 +36,7 @@
 #include <list>
 #include <type_traits>
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 
 /*!
  * \ingroup QtProtobuf
@@ -56,8 +56,8 @@ enum WireTypes {
 };
 
 //! \private
-struct PropertyOrderingInfo {
-    PropertyOrderingInfo(int _qtProperty, const QString &_jsonName) : qtProperty(_qtProperty)
+struct QProtobufPropertyOrderingInfo {
+    QProtobufPropertyOrderingInfo(int _qtProperty, const QString &_jsonName) : qtProperty(_qtProperty)
       , jsonName(_jsonName) {}
 
     int qtProperty;
@@ -75,8 +75,9 @@ struct PropertyOrderingInfo {
 
 //! \private
 //!
-using QProtobufPropertyOrdering = std::unordered_map<int, PropertyOrderingInfo>;
+using QProtobufPropertyOrdering = std::unordered_map<int, QProtobufPropertyOrderingInfo>;
 
+namespace QtProtobuf {
 /*!
  * \private
  * \ingroup QtProtobuf
@@ -190,7 +191,7 @@ using int32List = QList<int32>;
  * \ingroup QtProtobuf
  * \brief alias for list of QtProtobuf::int64
  */
-using int64List = QList<int64>;
+using int64List = QList<QtProtobuf::int64>;
 
 /*!
  * \ingroup QtProtobuf
@@ -242,36 +243,29 @@ using sfixed64List = QList<sfixed64>;
 
 /*!
  * \ingroup QtProtobuf
- * \brief alias for list of QtProtobuf::float
+ * \brief alias for list of float
  */
 using FloatList = QList<float>;
 
 /*!
  * \ingroup QtProtobuf
- * \brief alias for list of QtProtobuf::double
+ * \brief alias for list of double
  */
 using DoubleList = QList<double>;
 
-/*!
- * \ingroup QtProtobuf
- * \brief qRegisterProtobufTypes
- * This method should be called in all applications that supposed to use QtProtobuf
- */
-Q_PROTOBUF_EXPORT void qRegisterProtobufTypes();
-
 /*! \} */
 
 //!\private
 using RegisterFunction = std::function<void(void)>;
 
 //!\private
-Q_PROTOBUF_EXPORT std::list<RegisterFunction>& registerFunctions();
+Q_PROTOBUF_EXPORT std::list<QtProtobuf::RegisterFunction>& registerFunctions();
 
 //!\private
 template <typename T>
 struct ProtoTypeRegistrar {
-    ProtoTypeRegistrar(RegisterFunction initializer) {
-        registerFunctions().push_back(initializer);
+    ProtoTypeRegistrar(QtProtobuf::RegisterFunction initializer) {
+        QtProtobuf::registerFunctions().push_back(initializer);
     }
 };
 
@@ -314,7 +308,14 @@ bool repeatedValueCompare(const QMap<K, QSharedPointer<V>>& a, const QMap<K, QSh
     return true;
 }
 
-}
+} //namespace QtProtobuf
+
+/*!
+ * \brief qRegisterProtobufTypes
+ * This method should be called in all applications that supposed to use QtProtobuf
+ */
+// TODO Qt6: Replace with the automatic type registrar
+Q_PROTOBUF_EXPORT void qRegisterProtobufTypes();
 
 Q_DECLARE_METATYPE(QtProtobuf::int32)
 Q_DECLARE_METATYPE(QtProtobuf::int64)

+ 93 - 0
src/protobufquick/CMakeLists.txt

@@ -0,0 +1,93 @@
+qt_internal_add_qml_module(ProtobufQuick
+    URI "QtProtobuf"
+    VERSION "${PROJECT_VERSION}"
+    CLASS_NAME QtProtobufQuickPlugin
+    SOURCES
+        qtprotobufquickplugin.cpp qtprotobufquickplugin_p.h
+        qtprotobufquick_global.h
+    LIBRARIES
+        Qt::Protobuf
+        Qt::QmlPrivate
+)
+
+# set(TARGET ${PROTOBUF_QUICK_PLUGIN_NAME})
+
+# set(TARGET_EXPORT ${TARGET}Targets)
+# set(TARGET_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET})
+# set(TARGET_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
+
+# set(CMAKE_AUTOMOC ON)
+# set(CMAKE_AUTOMOC_MOC_OPTIONS -Muri=QtProtobuf)
+# set(CMAKE_AUTORCC ON)
+
+# qt_protobuf_extract_qt_variable(QT_INSTALL_QML)
+# qt_protobuf_extract_qt_variable(QT_INSTALL_PREFIX)
+
+# if("${QT_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
+#     set(TARGET_IMPORTS_DIR ${QT_INSTALL_QML}/QtProtobuf)
+# else()
+#     set(TARGET_IMPORTS_DIR ${CMAKE_INSTALL_LIBDIR}/qml/QtProtobuf)
+# endif()
+
+# file(GLOB SOURCES
+#     qtprotobufquickplugin.cpp)
+
+# file(GLOB HEADERS
+#     qtprotobufquickplugin.h
+#     qtprotobufquick_global.h)
+
+# add_library(${TARGET} ${SOURCES})
+
+# if(NOT BUILD_SHARED_LIBS)
+#     target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_STATIC QT_STATICPLUGIN QT_PROTOBUF_QUICK_PLUGIN_NAME="QtProtobufQuickPlugin")
+# endif()
+
+# target_link_libraries(${TARGET} PRIVATE Qt5::Core Qt5::Qml ${QT_PROTOBUF_NAMESPACE}::Protobuf)
+# set_target_properties(${TARGET} PROPERTIES
+#     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+#     RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+#     RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+#     RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf")
+# target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_QUICK_LIB)
+
+# #Check for QML private headers
+# if(NOT DEFINED Qt5Qml_PRIVATE_INCLUDE_DIRS OR Qt5Qml_PRIVATE_INCLUDE_DIRS STREQUAL "")
+#     message(FATAL_ERROR "Qt protobuf project requires Qml private headers defined in system")
+# endif()
+
+# foreach(QML_PRIVATE_HEADER IN LISTS Qt5Qml_PRIVATE_INCLUDE_DIRS)
+#     message(STATUS "Check for QtQml private headers dir: ${QML_PRIVATE_HEADER}")
+#     if(NOT IS_DIRECTORY ${QML_PRIVATE_HEADER})
+#         message(FATAL_ERROR "Qt protobuf project requires Qml private headers defined in system ${QML_PRIVATE_HEADER}")
+#     endif()
+# endforeach()
+
+# target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
+
+# add_library(${QT_PROTOBUF_NAMESPACE}::${TARGET} ALIAS ${TARGET})
+# if(NOT BUILD_SHARED_LIBS)
+#     export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
+#     if(QT_PROTOBUF_INSTALL)
+#         install(TARGETS ${TARGET} COMPONENT lib
+#             EXPORT ${TARGET_EXPORT} COMPONENT dev
+#             ARCHIVE DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib
+#             RUNTIME DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib
+#             LIBRARY DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)
+#         install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR} COMPONENT dev)
+#     endif()
+# else()
+#     if(QT_PROTOBUF_INSTALL)
+#         install(TARGETS ${TARGET} COMPONENT lib
+#             ARCHIVE DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib
+#             RUNTIME DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib
+#             LIBRARY DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)
+#     endif()
+# endif()
+
+# add_custom_command(TARGET ${TARGET}
+#     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
+#             "$<TARGET_FILE_DIR:${TARGET}>/qmldir"
+#     COMMENT "Copying qmldir to binary directory")
+# if(QT_PROTOBUF_INSTALL)
+#     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)
+# endif()

+ 0 - 0
src/protobuf/quick/qmldir → src/protobufquick/qmldir


+ 0 - 0
src/protobuf/quick/qtprotobufquick_global.h → src/protobufquick/qtprotobufquick_global.h


+ 8 - 8
src/protobuf/quick/qtprotobufquickplugin.cpp → src/protobufquick/qtprotobufquickplugin.cpp

@@ -23,10 +23,9 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "qtprotobufquickplugin.h"
-#include "qtprotobuftypes.h"
+#include "qtprotobufquickplugin_p.h"
+#include <QtProtobuf/qtprotobuftypes.h>
 #include <private/qqmlmetatype_p.h>
-#include <QDebug>
 
 template<typename T>
 static QVariant coverter(const QString &str) {
@@ -38,9 +37,10 @@ static QVariant coverter(const QString &str) {
 void QtProtobufQuickPlugin::registerTypes(const char *uri)
 {
     // @uri QtProtobuf
-    Q_ASSERT(uri == QLatin1String("QtProtobuf"));
-    qmlRegisterModule(uri, QT_PROTOBUF_VERSION_MAJOR, QT_PROTOBUF_VERSION_MINOR);
-    // QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::int32>(), coverter<QtProtobuf::int32>);
-    // QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::fixed32>(), coverter<QtProtobuf::fixed32>);
-    // QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::sfixed32>(), coverter<QtProtobuf::sfixed32>);
+    Q_ASSERT(QLatin1String(uri) == QLatin1String("QtProtobuf"));
+    qRegisterProtobufTypes();
+    qmlRegisterModule(uri, QT_VERSION_MAJOR, QT_VERSION_MINOR);
+//    QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::int32>(), coverter<QtProtobuf::int32>);
+//    QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::fixed32>(), coverter<QtProtobuf::fixed32>);
+//    QQmlMetaType::registerCustomStringConverter(qMetaTypeId<QtProtobuf::sfixed32>(), coverter<QtProtobuf::sfixed32>);
 }

+ 9 - 4
src/protobuf/quick/qtprotobufquickplugin.h → src/protobufquick/qtprotobufquickplugin_p.h

@@ -26,13 +26,13 @@
 #pragma once
 
 #include <QQmlExtensionPlugin>
-#include "qtprotobufquick_global.h"
+#include <QtProtobufQuick/qtprotobufquick_global.h>
 
 /*!
  * \defgroup QtProtobufQML QML QtProtobuf
  * \brief QML bindings for QtGrpc
  * \details
- * QtProtobuf allows to use generated classes in QML. All types are registred automatically when QtProtobuf::qRegisterProtobufTypes() called.
+ * QtProtobuf allows to use generated classes in QML. All types are registred automatically when qRegisterProtobufTypes() called.
  * To make generated classes and QtProtobuf types visible in QML you need to import QtProtobuf QML plugin and your protobuf package
  *
  * sample.proto:
@@ -66,7 +66,7 @@
  * \code
  * ...
  * if(QT_PROTOBUF_STATIC)
- *     target_link_libraries(${TARGET} PRIVATE QtProtobuf::protobufquickplugin)
+ *     target_link_libraries(${TARGET} PRIVATE QProtobufprotobufquickplugin)
  * endif()
  * ...
  * \endcode
@@ -75,7 +75,7 @@
  * \code
  * int main(int argc, char *argv[]) {
  *     ...
- *     QtProtobuf::qRegisterProtobufTypes();
+ *     qRegisterProtobufTypes();
  *     Q_PROTOBUF_IMPORT_QUICK_PLUGIN()
  *     ...
  * }
@@ -86,6 +86,9 @@
  * \private
  * \brief The QtProtobufQuickPlugin class
  */
+
+QT_BEGIN_NAMESPACE
+
 class QT_PROTOBUF_QUICK_SHARED_EXPORT QtProtobufQuickPlugin : public QQmlExtensionPlugin
 {
     Q_OBJECT
@@ -95,3 +98,5 @@ public:
     ~QtProtobufQuickPlugin() = default;
     void registerTypes(const char *) override;
 };
+
+QT_END_NAMESPACE

+ 31 - 33
src/qttypes/CMakeLists.txt

@@ -1,53 +1,51 @@
 set(qttypes_install_includedir ${CMAKE_INSTALL_INCLUDEDIR}/${QT_PROTOBUF_NAMESPACE}Protobuf)
 
-qt_protobuf_internal_add_library(ProtobufQtTypes
+qt_internal_add_module(ProtobufQtTypes
     SOURCES
-        qtprotobufqttypes.cpp
-    PUBLIC_HEADER
-        qtprotobufqttypes.h
+        qtprotobufqttypes.cpp qtprotobufqttypes.h
         qtprotobufqttypesglobal.h
-    INSTALL_INCLUDEDIR
-        "${qttypes_install_includedir}"
-    PUBLIC_INCLUDE_DIRECTORIES
-        "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>"
+    #TODO Qt6: install generated header files
+    #INSTALL_INCLUDEDIR
+        #"${qttypes_install_includedir}"
+    # PUBLIC_INCLUDE_DIRECTORIES
+    #     "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated>"
     PUBLIC_LIBRARIES
-        Qt6::Core
-        Qt6::Gui
-        Qt6::Qml
-        ${QT_PROTOBUF_NAMESPACE}::Protobuf
+        Qt::Core
+        Qt::Gui
+        Qt::Protobuf
 )
 
+qt_internal_extend_target(ProtobufWellKnownTypes
+    CONDITION TARGET Qt::Qml
+    LIBRARIES
+        Qt::Qml
+)
 
-file(GLOB PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/Qt*.proto)
+ set(qml_enabled "")
+ if(TARGET Qt::Qml)
+     set(qml_enabled QML)
+ endif()
 
-set(qml_enabled "")
-if(TARGET Qt6::Qml)
-    set(qml_enabled QML)
-endif()
+file(GLOB proto_files ${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/Qt*.proto)
 
-qtprotobuf_generate(TARGET ProtobufQtTypes
-    OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
-    PROTO_FILES ${PROTO_FILE}
+qt6_protobuf_generate(TARGET ProtobufQtTypes
+    OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated
+    PROTO_FILES ${proto_files}
     FOLDER
     ${qml_enabled}
     ${extra_type_libraries_options}
 )
 
-target_compile_definitions(ProtobufQtTypes PRIVATE QT_BUILD_PROTOBUF_QT_TYPES_LIB)
-
 set_target_properties(ProtobufQtTypes PROPERTIES
-    PROTO_INCLUDES
+    QT_PROTO_INCLUDES
         "-I\"${CMAKE_CURRENT_SOURCE_DIR}\";\
 -I\"${CMAKE_INSTALL_PREFIX}/${qttypes_install_includedir}\""
 )
+set_property(TARGET ProtobufQtTypes APPEND PROPERTY EXPORT_PROPERTIES QT_PROTO_INCLUDES)
 
-set_property(TARGET ProtobufQtTypes APPEND PROPERTY EXPORT_PROPERTIES PROTO_INCLUDES)
-
-if(QT_PROTOBUF_INSTALL)
-    install(FILES
-            "${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/QtCore.proto"
-            "${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/QtGui.proto"
-        DESTINATION "${qttypes_install_includedir}"
-        COMPONENT dev
-    )
-endif()
+qt_install(FILES
+        "${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/QtCore.proto"
+        "${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/QtGui.proto"
+    DESTINATION "${qttypes_install_includedir}"
+    COMPONENT dev
+)

+ 12 - 13
src/qttypes/qtprotobufqttypes.cpp

@@ -23,6 +23,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include "qtprotobufqttypes.h"
+
 #include <QUrl>
 #include <QChar>
 #include <QUuid>
@@ -49,17 +51,14 @@
 #include <QImage>
 #include <QBuffer>
 
-#include <qtprotobuftypes.h>
-#include <qtprotobufqttypes.h>
-
-#include "qabstractprotobufserializer.h"
-#include "qabstractprotobufserializer_p.h"
+#include <QtProtobuf/qtprotobuftypes.h>
+#include <QtProtobuf/qabstractprotobufserializer.h>
+#include <QtProtobuf/qabstractprotobufserializercommon.h>
 
 #include "QtProtobuf/QtCore.qpb.h"
 #include "QtProtobuf/QtGui.qpb.h"
 
-namespace QtProtobuf {
-
+namespace {
 ::QUrl convert(const ::QtProtobuf::QUrl &from) {
     return ::QUrl(from.url());
 }
@@ -271,24 +270,25 @@ namespace QtProtobuf {
     QBuffer buffer(&data);
     buffer.open(QIODevice::WriteOnly);
     from.save(&buffer, "PNG");
-    qProtoWarning() << "QImage always is sent in PNG format";
-    return ::QtProtobuf::QImage(data, "PNG");
+    return ::QtProtobuf::QImage(data, QLatin1String("PNG"));
 }
 
 template <typename QType, typename PType>
 void registerQtTypeHandler() {
     QtProtobufPrivate::registerHandler(qMetaTypeId<QType>(), {
-                                           [](const QtProtobuf::QAbstractProtobufSerializer *serializer, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &property, QByteArray &buffer) {
+                                           [](const QAbstractProtobufSerializer *serializer, const QVariant &value, const QProtobufMetaProperty &property, QByteArray &buffer) {
                                                PType object(convert(value.value<QType>()));
                                                buffer.append(serializer->serializeObject(&object, PType::protobufMetaObject, property));
                                            },
-                                           [](const QtProtobuf::QAbstractProtobufSerializer *serializer, QtProtobuf::QProtobufSelfcheckIterator &it, QVariant &value) {
+                                           [](const QAbstractProtobufSerializer *serializer, QProtobufSelfcheckIterator &it, QVariant &value) {
                                                PType object;
                                                serializer->deserializeObject(&object, PType::protobufMetaObject, it);
                                                value = QVariant::fromValue<QType>(convert(object));
                                            }, QtProtobufPrivate::ObjectHandler });
 }
+}
 
+QT_BEGIN_NAMESPACE
 void qRegisterProtobufQtTypes() {
     registerQtTypeHandler<::QUrl, ::QtProtobuf::QUrl>();
     registerQtTypeHandler<::QChar, ::QtProtobuf::QChar>();
@@ -315,5 +315,4 @@ void qRegisterProtobufQtTypes() {
     registerQtTypeHandler<::QQuaternion, ::QtProtobuf::QQuaternion>();
     registerQtTypeHandler<::QImage, ::QtProtobuf::QImage>();
 }
-
-}
+QT_END_NAMESPACE

+ 4 - 4
src/qttypes/qtprotobufqttypes.h

@@ -78,7 +78,7 @@
  * Before any serialization/deserialization of messages that use Qt types as fields, call registration method:
  * \code
  * ... //E.g. somewhere in main.cpp
- * QtProtobuf::qRegisterProtobufQtTypes();
+ * qRegisterProtobufQtTypes();
  * ...
  * \endcode
  *
@@ -88,7 +88,7 @@
  * - QtGui.proto - contains description of Qt types from QtGui module
  *
  * These files also useful if you would like to generate code for other languages or frameworks.
- * They located in project include directories, but no need to specify anything manualy, qtprotobuf_generate macro takes care about all side work for you.
+ * They located in project include directories, but no need to specify anything manualy, qt6_protobuf_generate macro takes care about all side work for you.
  *
  * Import required Qt types module in your interface .proto file, e.g.:
  * \code
@@ -118,10 +118,10 @@
  * \endcode
  */
 
-namespace QtProtobuf {
+QT_BEGIN_NAMESPACE
 /*!
  * \brief qRegisterProtobufQtTypes registers serializers set for Qt types supported by QtProtobufQtTypes
  * \note Call it before any serialization\deserialization of messages that use QtProtobufQtTypes directly on indirectly
  */
 Q_PROTOBUF_QT_TYPES_EXPORT void qRegisterProtobufQtTypes();
-}
+QT_END_NAMESPACE

+ 32 - 34
src/wellknowntypes/CMakeLists.txt

@@ -1,37 +1,39 @@
-qt_protobuf_internal_add_library(ProtobufWellKnownTypes
+qt_internal_add_module(ProtobufWellKnownTypes
     SOURCES
         dummy.cpp
-    INSTALL_INCLUDEDIR
-         "${CMAKE_INSTALL_INCLUDEDIR}/${QT_PROTOBUF_NAMESPACE}Protobuf/google/protobuf"
-    PUBLIC_INCLUDE_DIRECTORIES
-        "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>"
+    # TODO Qt6: Need to specify the special install include directory for the wellknowntypes module
+    # INSTALL_INCLUDEDIR
+    #  "${CMAKE_INSTALL_INCLUDEDIR}/QtProtobuf/google/protobuf"
     PUBLIC_LIBRARIES
-        Qt6::Core
-        Qt6::Qml
-        ${QT_PROTOBUF_NAMESPACE}::Protobuf
+        Qt::Core
+        Qt::Protobuf
 )
 
-function(add_wellknowntype type_name)
-    set(lookup_dirs "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/grpc/third_party/protobuf/src"
-        ${Protobuf_INCLUDE_DIRS}
-    )
+qt_internal_extend_target(ProtobufWellKnownTypes
+    CONDITION TARGET Qt::Qml
+    LIBRARIES
+        Qt::Qml
+)
+
+function(qt_internal_add_protobuf_wellknowntype type_name)
+    # TODO Qt6: use WrapProtobuf's INTERFACE_INCLUDE_DIRECTORIES
+    set(lookup_dirs ${Protobuf_INCLUDE_DIRS})
 
     set(qml_enabled "")
-    if(TARGET Qt6::Qml)
+    if(TARGET Qt::Qml)
         set(qml_enabled QML)
     endif()
     foreach(dir ${lookup_dirs})
         file(GLOB PROTO_FILE "${dir}/google/protobuf/${type_name}.proto")
         if(NOT "${PROTO_FILE}" STREQUAL "")
             message(STATUS "Add well-known type ${PROTO_FILE}")
-            qtprotobuf_generate(TARGET ProtobufWellKnownTypes
+            qt6_protobuf_generate(TARGET ProtobufWellKnownTypes
                 GENERATED_TARGET ${type_name}
-                OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated"
+                OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/proto_generated"
                 PROTO_FILES "${PROTO_FILE}"
                 PROTO_INCLUDES "-I\"${dir}\""
                 ${qml_enabled}
                 FOLDER
-                ${extra_type_libraries_options}
             )
             target_include_directories(${type_name} PRIVATE
                 "$<TARGET_PROPERTY:ProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>"
@@ -44,24 +46,20 @@ function(add_wellknowntype type_name)
     endif()
 endfunction()
 
-add_wellknowntype(any)
-add_wellknowntype(duration)
-add_wellknowntype(empty)
-add_wellknowntype(field_mask)
-add_wellknowntype(source_context)
-add_wellknowntype(struct)
-add_wellknowntype(timestamp)
-add_wellknowntype(wrappers)
-add_wellknowntype(type)
+# TODO Qt6: The generated header files are not installed properly.
+qt_internal_add_protobuf_wellknowntype(any)
+qt_internal_add_protobuf_wellknowntype(duration)
+qt_internal_add_protobuf_wellknowntype(empty)
+qt_internal_add_protobuf_wellknowntype(field_mask)
+qt_internal_add_protobuf_wellknowntype(source_context)
+qt_internal_add_protobuf_wellknowntype(struct)
+qt_internal_add_protobuf_wellknowntype(timestamp)
+qt_internal_add_protobuf_wellknowntype(wrappers)
+qt_internal_add_protobuf_wellknowntype(type)
 add_dependencies(type any source_context)
-add_wellknowntype(api)
+qt_internal_add_protobuf_wellknowntype(api)
 add_dependencies(api type source_context)
 
-# TODO: Check if 3rdparty protobuf module is initialized
-if(EXISTS "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/grpc/third_party/protobuf/src")
-    set_target_properties(ProtobufWellKnownTypes PROPERTIES
-        PROTO_INCLUDES "-I\"${QT_PROTOBUF_SOURCE_DIR}/3rdparty/grpc/third_party/protobuf/src\"")
-elseif(Protobuf_INCLUDE_DIRS)
-    set_target_properties(ProtobufWellKnownTypes PROPERTIES
-        PROTO_INCLUDES "-I\"${Protobuf_INCLUDE_DIRS}\"")
-endif()
+set_target_properties(ProtobufWellKnownTypes PROPERTIES
+    QT_PROTO_INCLUDES "-I\"${Protobuf_INCLUDE_DIRS}\"")
+set_property(TARGET ProtobufWellKnownTypes APPEND PROPERTY EXPORT_PROPERTIES QT_PROTO_INCLUDES)

+ 1 - 1
src/wellknowntypes/dummy.cpp

@@ -95,6 +95,6 @@
  * In both scenarious you also need to link QtProtobuf WellKnownTypes library by adding following lines to
  * **CMakeLists.txt** for your target.
  * \code
- *     target_link_libraries(YourTargetName PRIVATE QtProtobuf::ProtobufWellKnownTypes)
+ *     target_link_libraries(YourTargetName PRIVATE Qt::ProtobufWellKnownTypes)
  * \endcode
  */

+ 11 - 0
sync.profile

@@ -0,0 +1,11 @@
+%modules = ( # path to module name map
+    "QtProtobuf" => "$basedir/src/protobuf",
+    "QtProtobufWellKnownTypes" => "$basedir/src/wellknowntypes",
+    "QtProtobufQtTypes" => "$basedir/src/qttypes",
+    "QtProtobufQuick" => "$basedir/src/protobufquick",
+    "QtGrpc" => "$basedir/src/grpc",
+);
+%moduleheaders = ( # restrict the module headers to those found in relative path
+);
+
+@ignore_headers = ( );

+ 4 - 40
tests/CMakeLists.txt

@@ -1,42 +1,6 @@
-if(QT_PROTOBUF_STANDALONE_TESTS)
-    find_package(QtProtobuf COMPONENTS Protobuf ProtobufGenerator
-        OPTIONAL_COMPONENTS Grpc ProtobufWellKnownTypes ProtobufQtTypes REQUIRED
-    )
+if(QT_BUILD_STANDALONE_TESTS)
+    # Add qt_find_package calls for extra dependencies that need to be found when building
+    # the standalone tests here.
 endif()
 
-include(QtProtobufTestHelpers)
-
-add_subdirectory("test_protobuf")
-if(TARGET ${QT_VERSIONED_PREFIX}::QuickTest)
-    add_subdirectory("test_qml")
-endif()
-add_subdirectory("test_protobuf_multifile")
-add_subdirectory("test_extra_namespace")
-if(NOT QT_PROTOBUF_STANDALONE_TESTS) # Disable in standalone mode as it requires some private
-                                     # headers to work properly.
-    add_subdirectory("test_extra_namespace_qml")
-    add_subdirectory("test_qprotobuf_serializer_plugin")
-endif()
-
-if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufWellKnownTypes)
-    add_subdirectory("test_wellknowntypes")
-endif()
-
-if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufQtTypes)
-    add_subdirectory("test_qttypes")
-endif()
-
-if(WrapgRPC_FOUND AND TARGET ${QT_PROTOBUF_NAMESPACE}::Grpc)
-    if(UNIX)
-        set(TEST_DRIVER_NAME "test_driver.sh")
-    elseif(WIN32)
-        set(TEST_DRIVER_NAME "test_driver.bat")
-    endif()
-
-    add_subdirectory("test_grpc")
-    if(TARGET ${QT_VERSIONED_PREFIX}::QuickTest)
-        add_subdirectory("test_grpc_qml")
-    endif()
-else()
-    message(WARNING "gRPC not found: some tests cannot be built.")
-endif()
+qt_build_tests()

+ 12 - 0
tests/auto/CMakeLists.txt

@@ -0,0 +1,12 @@
+add_subdirectory(test_protobuf)
+add_subdirectory(test_protobuf_extra_namespace)
+#add_subdirectory(test_protobuf_multifile)
+# TODO Qt6: Need to use qt_internal_add_plugin for the test plugin.
+# add_subdirectory(test_protobuf_serializer_plugin)
+add_subdirectory(test_wellknowntypes)
+add_subdirectory(test_qttypes)
+add_subdirectory(test_grpc)
+
+if(TARGET Qt::Quick OR TARGET Qt::QuickTest)
+#    add_subdirectory(test_protobuf_qml)
+endif()

+ 0 - 0
tests/test_protobuf/proto/annotation.proto → tests/auto/shared/proto/annotation.proto


+ 71 - 0
tests/auto/shared/proto/basicmessages.proto

@@ -0,0 +1,71 @@
+syntax = "proto3";
+
+package qtprotobufnamespace.tests;
+
+message EmptyMessage {
+}
+
+message SimpleBoolMessage {
+    bool testFieldBool = 1;
+}
+
+message SimpleIntMessage {
+    int32 testFieldInt = 1;
+}
+
+message SimpleSIntMessage {
+    sint32 testFieldInt = 1;
+}
+
+message SimpleUIntMessage {
+    uint32 testFieldInt = 1;
+}
+
+message SimpleInt64Message {
+    int64 testFieldInt = 1;
+}
+
+message SimpleSInt64Message {
+    sint64 testFieldInt = 1;
+}
+
+message SimpleUInt64Message {
+    uint64 testFieldInt = 1;
+}
+
+message SimpleStringMessage {
+    string testFieldString = 6;
+}
+
+message SimpleFloatMessage {
+    float testFieldFloat = 7;
+}
+
+message SimpleDoubleMessage {
+    double testFieldDouble = 8;
+}
+
+message SimpleBytesMessage {
+    bytes testFieldBytes = 1;
+}
+
+message SimpleFixedInt32Message {
+    fixed32 testFieldFixedInt32 = 1;
+}
+
+message SimpleFixedInt64Message {
+    fixed64 testFieldFixedInt64 = 1;
+}
+
+message SimpleSFixedInt32Message {
+    sfixed32 testFieldFixedInt32 = 1;
+}
+
+message SimpleSFixedInt64Message {
+    sfixed64 testFieldFixedInt64 = 1;
+}
+
+message ComplexMessage {
+    int32 testFieldInt = 1;
+    SimpleStringMessage testComplexField = 2;
+}

+ 0 - 0
tests/test_protobuf/proto/crossfiletest.proto_disabled → tests/auto/shared/proto/crossfiletest.proto_disabled


+ 0 - 0
tests/test_protobuf/proto/duplicated_metatypes.proto → tests/auto/shared/proto/duplicated_metatypes.proto


+ 0 - 0
tests/test_protobuf/proto/duplicated_metatypes_external.proto → tests/auto/shared/proto/duplicated_metatypes_external.proto


+ 0 - 0
tests/test_protobuf/proto/externalpackagetest.proto → tests/auto/shared/proto/externalpackagetest.proto


+ 0 - 0
tests/test_protobuf/proto/globalenums.proto → tests/auto/shared/proto/globalenums.proto


+ 0 - 0
tests/test_protobuf/proto/globalenumssamenamespace.proto → tests/auto/shared/proto/globalenumssamenamespace.proto


+ 1 - 271
tests/test_protobuf/proto/simpletest.proto → tests/auto/shared/proto/mapmessages.proto

@@ -1,178 +1,9 @@
 syntax = "proto3";
 
-import "externalpackagetest.proto";
-import "nopackageexternal.proto";
+import "basicmessages.proto";
 
 package qtprotobufnamespace.tests;
 
-message EmptyMessage {
-}
-
-message SimpleEnumMessage {
-  enum LocalEnum {
-    LOCAL_ENUM_VALUE0 = 0;
-    LOCAL_ENUM_VALUE1 = 1;
-    LOCAL_ENUM_VALUE2 = 2;
-    LOCAL_ENUM_VALUE3 = 3;
-  }
-
-  LocalEnum localEnum = 1;
-}
-
-message SimpleEnumListMessage {
-  enum LocalEnum {
-    LOCAL_ENUM_VALUE0 = 0;
-    LOCAL_ENUM_VALUE1 = 1;
-    LOCAL_ENUM_VALUE2 = 2;
-    LOCAL_ENUM_VALUE3 = 3;
-  }
-
-  repeated LocalEnum localEnumList = 1;
-}
-
-message SimpleFileEnumMessage {
-  TestEnum globalEnum = 1;
-  repeated TestEnum globalEnumList = 2;
-}
-
-message StepChildEnumMessage {
-  SimpleEnumMessage.LocalEnum localStepChildEnum = 1;
-  repeated SimpleEnumMessage.LocalEnum localStepChildList = 2;
-}
-
-message SimpleExternalEnumMessage {
-    qtprotobufnamespace1.externaltests.ExternalTestEnum externalEnum = 1;
-}
-
-message SimpleBoolMessage {
-    bool testFieldBool = 1;
-}
-
-message SimpleIntMessage {
-    int32 testFieldInt = 1;
-}
-
-message SimpleSIntMessage {
-    sint32 testFieldInt = 1;
-}
-
-message SimpleUIntMessage {
-    uint32 testFieldInt = 1;
-}
-
-message SimpleInt64Message {
-    int64 testFieldInt = 1;
-}
-
-message SimpleSInt64Message {
-    sint64 testFieldInt = 1;
-}
-
-message SimpleUInt64Message {
-    uint64 testFieldInt = 1;
-}
-
-message SimpleStringMessage {
-    string testFieldString = 6;
-}
-
-message SimpleFloatMessage {
-    float testFieldFloat = 7;
-}
-
-message SimpleDoubleMessage {
-    double testFieldDouble = 8;
-}
-
-message SimpleBytesMessage {
-    bytes testFieldBytes = 1;
-}
-
-message SimpleFixedInt32Message {
-    fixed32 testFieldFixedInt32 = 1;
-}
-
-message SimpleFixedInt64Message {
-    fixed64 testFieldFixedInt64 = 1;
-}
-
-message SimpleSFixedInt32Message {
-    sfixed32 testFieldFixedInt32 = 1;
-}
-
-message SimpleSFixedInt64Message {
-    sfixed64 testFieldFixedInt64 = 1;
-}
-
-message ComplexMessage {
-    int32 testFieldInt = 1;
-    SimpleStringMessage testComplexField = 2;
-}
-
-message RepeatedStringMessage {
-    repeated string testRepeatedString = 1;
-}
-
-message RepeatedDoubleMessage {
-    repeated double testRepeatedDouble = 1;
-}
-
-message RepeatedBytesMessage {
-    repeated bytes testRepeatedBytes = 1;
-}
-
-message RepeatedFloatMessage {
-    repeated float testRepeatedFloat = 1;
-}
-
-message RepeatedComplexMessage {
-    repeated ComplexMessage testRepeatedComplex = 1;
-}
-
-message RepeatedExternalComplexMessage {
-    repeated qtprotobufnamespace1.externaltests.ExternalComplexMessage testExternalComplex = 1;
-}
-
-message RepeatedSIntMessage {
-    repeated sint32 testRepeatedInt = 1;
-}
-
-message RepeatedIntMessage {
-    repeated int32 testRepeatedInt = 1;
-}
-
-message RepeatedUIntMessage {
-    repeated uint32 testRepeatedInt = 1;
-}
-
-message RepeatedSInt64Message {
-    repeated sint64 testRepeatedInt = 1;
-}
-
-message RepeatedInt64Message {
-    repeated int64 testRepeatedInt = 1;
-}
-
-message RepeatedUInt64Message {
-    repeated uint64 testRepeatedInt = 1;
-}
-
-message RepeatedFixedIntMessage {
-    repeated fixed32 testRepeatedInt = 1;
-}
-
-message RepeatedSFixedIntMessage {
-    repeated sfixed32 testRepeatedInt = 1;
-}
-
-message RepeatedFixedInt64Message {
-    repeated fixed64 testRepeatedInt = 1;
-}
-
-message RepeatedSFixedInt64Message {
-    repeated sfixed64 testRepeatedInt = 1;
-}
-
 //MAPS
 //Types to String
 message SimpleSInt32StringMapMessage {
@@ -533,104 +364,3 @@ message SimpleSFixed64ComplexMessageMapMessage {
 message SimpleStringComplexMessageMapMessage {
     map<string, ComplexMessage> mapField = 13;
 }
-
-enum TestEnum {
-    TEST_ENUM_VALUE0 = 0;
-    TEST_ENUM_VALUE1 = 1;
-    TEST_ENUM_VALUE2 = 2;
-    TEST_ENUM_VALUE3 = 4;
-    TEST_ENUM_VALUE4 = 3;
-}
-
-enum TestEnumSecondInFile {
-    TEST_ENUM_SIF_VALUE0 = 0;
-    TEST_ENUM_SIF_VALUE1 = 1;
-    TEST_ENUM_SIF_VALUE2 = 2;
-}
-
-message FieldIndexTest1Message {
-    sint32 testField = 31;
-}
-
-message FieldIndexTest2Message {
-    sint32 testField = 8191;
-}
-
-message FieldIndexTest3Message {
-    sint32 testField = 2097151;
-}
-
-message FieldIndexTest4Message {
-    sint32 testField = 536870911;
-}
-
-message Message_Uderscore_name {
-    sint32 testField = 1;
-}
-
-message MessageUderscorename {
-    sint32 testField = 1;
-}
-
-message MessageUnderscoreField {
-    sint32 underScore_Message_field = 1;
-}
-
-message PriorMessageUnderscoreField {
-    sint32 _underScoreMessageField = 1;
-}
-
-message FollowingMessageUnderscoreField {
-    sint32 underScoreMessageField_ = 1;
-}
-
-message CombinedMessageUnderscoreField {
-    sint32 _underScoreMessage_Field_ = 1;
-}
-
-message MessageUpperCase {
-    sint32 TestField = 1;
-}
-
-message MessageReserved {
-    sint32 import = 1;
-    sint32 property = 2;
-    sint32 id = 3;
-}
-
-message MessageUpperCaseReserved {
-    sint32 Import = 1;
-    sint32 Property = 2;
-    sint32 Id = 3;
-}
-
-message MessageEnumReserved {
-    enum ReservedEnum {
-        Import = 0;
-        Property = 1;
-        Id = 2;
-    }
-
-    enum LowerCaseEnum {
-        enumValue0 = 0;
-        enumValue1 = 1;
-        enumValue2 = 2;
-    }
-
-    enum UnderScoreEnum {
-        _enumUnderscoreValue0 = 0;
-        _EnumUnderscoreValue1 = 1;
-    }
-}
-
-message lowerCaseMessageName {
-    sint32 testField = 1;
-}
-
-message LowerCaseFieldMessageName {
-    lowerCaseMessageName testField = 1;
-}
-
-message NoPackageMessage {
-    SimpleIntMessageExt testField = 1;
-}

+ 0 - 0
tests/test_protobuf/proto/nestedmessages.proto → tests/auto/shared/proto/nestedmessages.proto


+ 0 - 0
tests/test_protobuf/proto/nopackage.proto → tests/auto/shared/proto/nopackage.proto


+ 0 - 0
tests/test_protobuf/proto/nopackageexternal.proto → tests/auto/shared/proto/nopackageexternal.proto


Some files were not shown because too many files changed in this diff