qtprotobufqttypes.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #pragma once //QtProtobufQtTypes
  26. #include <qtprotobufqttypesglobal.h>
  27. /*!
  28. * \defgroup QtProtobufQtTypes
  29. * \brief Provides support of native Qt types
  30. *
  31. * \details Like Google Protocol Buffers provide bench of standard types, QtProtobuf give you possibility to use Qt types directly in your projects.
  32. * QtProtobufQtTypes library makes this possible.
  33. *
  34. * List of supported types:
  35. *
  36. * \par \b QtCore
  37. * - QUrl
  38. * - QChar
  39. * - QUuid
  40. * - QTime
  41. * - QDate
  42. * - QDateTime
  43. * - QSize
  44. * - QSizeF
  45. * - QPoint
  46. * - QPointF
  47. * - QRect
  48. * - QRectF
  49. * - QPolygon
  50. * - QPolygonF
  51. *
  52. * \par \b QtGui
  53. * - QColor
  54. * - QMatrix4x4
  55. * - QVector2D
  56. * - QVector3D
  57. * - QVector4D
  58. * - QTransform
  59. * - QQuaternion
  60. * - QImage
  61. *
  62. * \note To request support of any other <a href="https://doc.qt.io/qt-5/qmetatype.html#Type-enum">Qt meta type</a> please submit feature issue in project <a href="https://github.com/semlanik/qtprotobuf/issues">bugtracker</a>.
  63. *
  64. * \subsubsection Usage
  65. *
  66. * To enable Qt types support add ProtobufQtTypes as dependency to CMake project:
  67. * \code
  68. * ...
  69. * find_package(QtProtobuf CONFIG COMPONENTS ProtobufGenerator Protobuf ProtobufQtTypes REQUIRED)
  70. * ... #After target creation
  71. * target_link_libraries(${TARGET} PRIVATE ${QT_PROTOBUF_NAMESPACE}::ProtobufQtTypes)
  72. * \endcode
  73. *
  74. * Starting from this point you are almost complete preparation. Unlike automatical registration of generated code, QtProtobufQtTypes requires additional intialization step.
  75. * Before any serialization/deserialization of messages that use Qt types as fields, call registration method:
  76. * \code
  77. * ... //E.g. somewhere in main.cpp
  78. * QtProtobuf::qRegisterProtobufQtTypes();
  79. * ...
  80. * \endcode
  81. *
  82. * All supported message are described in special .proto files:
  83. *
  84. * - QtCore.proto - contains description of Qt types from QtCore module
  85. * - QtGui.proto - contains description of Qt types from QtGui module
  86. *
  87. * These files also useful if you would like to generate code for other languages or frameworks.
  88. * They located in project include directories, but no need to specify anything manualy, qtprotobuf_generate macro takes care about all side work for you.
  89. *
  90. * Import required Qt types module in your interface .proto file, e.g.:
  91. * \code
  92. * syntax = "proto3";
  93. *
  94. * package project.module.component;
  95. *
  96. * import "QtProtobuf/QtCore.proto";
  97. *
  98. * message QUrlMessage {
  99. * QtProtobuf.QUrl url = 1;
  100. * }
  101. * \endcode
  102. *
  103. * QtProtobuf generator detects fields of type is located in QtProtobuf package and use Qt type directly instead of complex message generation. This give you
  104. * flexibility to use Qt types without additional convertion steps.
  105. *
  106. * In generated code you will see following property ready to use:
  107. *
  108. * \code
  109. * class QUrlMessage : public QObject
  110. * {
  111. * ...
  112. * Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged SCRIPTABLE true)
  113. * ...
  114. * }
  115. * \endcode
  116. */
  117. namespace QtProtobuf {
  118. /*!
  119. * \brief qRegisterProtobufQtTypes registers serializers set for Qt types supported by QtProtobufQtTypes
  120. * \note Call it before any serialization\deserialization of messages that use QtProtobufQtTypes directly on indirectly
  121. */
  122. Q_PROTOBUF_QT_TYPES_EXPORT void qRegisterProtobufQtTypes();
  123. }