Bladeren bron

Fix transparent types converter

- It doesn't make sense to keep type-traits for convertes.
  All integral types suppose to be converted from/to any integral
  type. Add extra converters to qulonglong and qlonglong types.
- Remove the extern keyword for the functions that are explicitly
  defined in header files.
- Add symbols export for the library that contains unversallistmodel.
- Add optional serializer result for QMatrix4x4 and QTransform.
- Temporary disable grpc tests on Windows
- Add windows workflow for pull requests
Alexey Edelev 3 jaren geleden
bovenliggende
commit
e11807106f

+ 1 - 1
.github/workflows/branchpush.yml

@@ -88,4 +88,4 @@ jobs:
     - name: Run tests
       run: |
         cd build-static
-        ctest -C Debug --output-on-failure
+        ctest -C Debug -E grpc --output-on-failure

+ 34 - 0
.github/workflows/pullrequest.yml

@@ -14,3 +14,37 @@ jobs:
       run: docker build . --file .ci/Dockerfile.ubuntu --tag ubuntu_debugimage:latest
     - name: Run tests
       run: docker run ubuntu_debugimage:latest ctest /build --output-on-failure
+  build-windows:
+    name: Static Build and Test Windows MSVC
+    runs-on: windows-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: Init submodules
+      run: git submodule update --init --recursive
+    - uses: shogo82148/actions-setup-perl@v1
+      with:
+        perl-version: '5.30'
+        distribution: strawberry
+    - uses: microsoft/setup-msbuild@v1.0.2
+      with:
+        vs-version: '16.4'
+    - name: Install Deps
+      run: choco install wget golang yasm
+    - name: Install Qt
+      run: |
+        wget -q https://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe -O C:/qt-unified-windows-x86-online.exe
+        C:/qt-unified-windows-x86-online.exe --script ./.ci/qt_installer_windows.qs -d
+    - name: Build in Windows
+      run: |
+        mkdir build-static
+        cd build-static
+        setx GOROOT "c:\Go"
+        setx path "%path%;C:\Qt\5.15.2\msvc2019_64\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
+        set GOROOT="c:\Go"
+        set PATH="%PATH%;C:\Qt\5.15.2\msvc2019_64\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
+        cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.15.2\msvc2019_64;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools" -DBUILD_SHARED_LIBS=OFF ..
+        cmake --build . --config Debug
+    - name: Run tests
+      run: |
+        cd build-static
+        ctest -C Debug -E grpc --output-on-failure

+ 3 - 0
examples/examples_common/CMakeLists.txt

@@ -7,6 +7,7 @@ find_package(Qt5 COMPONENTS Core CONFIG REQUIRED)
 file(GLOB HEADERS
     universallistmodelbase.h
     universallistmodel.h
+    exmaples_common_global.h
 )
 
 file(GLOB SOURCES
@@ -17,5 +18,7 @@ file(GLOB SOURCES
 # headers added to make them visible in IDE
 add_library(examples_common ${SOURCES} ${HEADERS})
 
+target_compile_definitions(examples_common PRIVATE EXAMPLES_COMMON_LIB)
+
 target_include_directories(examples_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 target_link_libraries(examples_common Qt5::Core)

+ 13 - 0
examples/examples_common/exmaples_common_global.h

@@ -0,0 +1,13 @@
+#pragma once
+
+#include <QtCore/QtGlobal>
+
+#ifndef QT_PROTOBUF_STATIC
+    #ifdef EXAMPLES_COMMON_LIB
+        #define UNVERSALLISTMODEL_EXPORT Q_DECL_EXPORT
+    #else
+        #define UNVERSALLISTMODEL_EXPORT Q_DECL_IMPORT
+    #endif
+#else
+    #define UNVERSALLISTMODEL_EXPORT
+#endif

+ 3 - 1
examples/examples_common/universallistmodelbase.h

@@ -1,11 +1,13 @@
 #pragma once
 
+#include <exmaples_common_global.h>
+
 #include <QAbstractListModel>
 /*!
  * \brief The UniversalListModelBase class to make possible properties definition for UniversalListModel
  * This class should not be used as is, but leaves this possibility.
  */
-class UniversalListModelBase : public QAbstractListModel
+class UNVERSALLISTMODEL_EXPORT UniversalListModelBase : public QAbstractListModel
 {
     Q_OBJECT
     Q_PROPERTY(int count READ count NOTIFY countChanged)

+ 7 - 35
src/protobuf/qtprotobuf.cpp

@@ -34,52 +34,24 @@
 namespace QtProtobuf {
 
 namespace  {
-
-template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int32_t)
-                                      && std::is_signed<T>::value, int> = 0>
+template<typename T>
 void registerBasicConverters() {
     QMetaType::registerConverter<int32_t, T>(T::fromType);
     QMetaType::registerConverter<T, int32_t>(T::toType);
-    QMetaType::registerConverter<double, T>(T::fromType);
-    QMetaType::registerConverter<T, double>(T::toType);
-    QMetaType::registerConverter<T, QString>(T::toString);
-}
-
-template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int64_t)
-                                      && std::is_signed<T>::value, int> = 0>
-void registerBasicConverters() {
     QMetaType::registerConverter<int64_t, T>(T::fromType);
     QMetaType::registerConverter<T, int64_t>(T::toType);
-    QMetaType::registerConverter<qint64, T>(T::fromType);
-    QMetaType::registerConverter<T, qint64>(T::toType);
-    QMetaType::registerConverter<int32_t, T>(T::fromType);
-    QMetaType::registerConverter<T, int32_t>(T::toType); //Required for enum handling
-    QMetaType::registerConverter<T, QString>(T::toString);
-}
-
-template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int32_t)
-                                      && !std::is_signed<T>::value, int> = 0>
-void registerBasicConverters() {
     QMetaType::registerConverter<uint32_t, T>(T::fromType);
     QMetaType::registerConverter<T, uint32_t>(T::toType);
-    QMetaType::registerConverter<int32_t, T>(T::fromType);
-    QMetaType::registerConverter<T, int32_t>(T::toType);
-    QMetaType::registerConverter<double, T>(T::fromType);
-    QMetaType::registerConverter<T, double>(T::toType);
-    QMetaType::registerConverter<T, QString>(T::toString);
-}
-
-template<typename T, typename std::enable_if_t<sizeof(T) == sizeof(int64_t)
-                                      && !std::is_signed<T>::value, int> = 0>
-void registerBasicConverters() {
     QMetaType::registerConverter<uint64_t, T>(T::fromType);
     QMetaType::registerConverter<T, uint64_t>(T::toType);
-    QMetaType::registerConverter<quint64, T>(T::fromType);
-    QMetaType::registerConverter<T, quint64>(T::toType);
-    QMetaType::registerConverter<uint32_t, T>(T::fromType);
+    QMetaType::registerConverter<qulonglong, T>(T::fromType);
+    QMetaType::registerConverter<T, qulonglong>(T::toType);
+    QMetaType::registerConverter<qlonglong, T>(T::fromType);
+    QMetaType::registerConverter<T, qlonglong>(T::toType);
+    QMetaType::registerConverter<double, T>(T::fromType);
+    QMetaType::registerConverter<T, double>(T::toType);
     QMetaType::registerConverter<T, QString>(T::toString);
 }
-
 }
 
 std::list<RegisterFunction>& registerFunctions() {

+ 2 - 2
src/protobuf/qtprotobuftypes.h

@@ -236,7 +236,7 @@ using DoubleList = QList<double>;
  * \brief qRegisterProtobufTypes
  * This method should be called in all applications that supposed to use QtProtobuf
  */
-extern Q_PROTOBUF_EXPORT void qRegisterProtobufTypes();
+Q_PROTOBUF_EXPORT void qRegisterProtobufTypes();
 
 /*! \} */
 
@@ -244,7 +244,7 @@ extern Q_PROTOBUF_EXPORT void qRegisterProtobufTypes();
 using RegisterFunction = std::function<void(void)>;
 
 //!\private
-extern Q_PROTOBUF_EXPORT std::list<RegisterFunction>& registerFunctions();
+Q_PROTOBUF_EXPORT std::list<RegisterFunction>& registerFunctions();
 
 //!\private
 template <typename T>

+ 1 - 1
src/qttypes/qtprotobufqttypes.h

@@ -123,5 +123,5 @@ namespace QtProtobuf {
  * \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
  */
-extern Q_PROTOBUF_QT_TYPES_EXPORT void qRegisterProtobufQtTypes();
+Q_PROTOBUF_QT_TYPES_EXPORT void qRegisterProtobufQtTypes();
 }

+ 4 - 2
tests/test_qttypes/qtguitest.cpp

@@ -85,7 +85,8 @@ TEST_F(QtTypesQtGuiTest, QMatrix4x4Test)
 
     EXPECT_TRUE(QByteArray::fromHex("0a518501000070417d0000604175000050416d0000404165000030415d0000204155000010414d00000041450000e0403d0000c040350000a0402d0000804025000040401d00000040150000803f0d00000000") == result
                 || QByteArray::fromHex("0a4c150000803f1d0000004025000040402d00008040350000a0403d0000c040450000e0404d0000004155000010415d0000204165000030416d0000404175000050417d00006041850100007041") == result
-                || QByteArray::fromHex("0a514d000000410d00000000150000803f1d0000004025000040402d00008040350000a0403d0000c040450000e04055000010415d0000204165000030416d0000404175000050417d00006041850100007041") == result);
+                || QByteArray::fromHex("0a514d000000410d00000000150000803f1d0000004025000040402d00008040350000a0403d0000c040450000e04055000010415d0000204165000030416d0000404175000050417d00006041850100007041") == result
+                || QByteArray::fromHex("0a510d00000000150000803f1d0000004025000040402d00008040350000a0403d0000c040450000e0404d0000004155000010415d0000204165000030416d0000404175000050417d00006041850100007041") == result);
 
     msg.setTestField({});
     msg.deserialize(serializer.get(), QByteArray::fromHex("0a4c150000803f1d0000004025000040402d00008040350000a0403d0000c040450000e0404d0000004155000010415d0000204165000030416d0000404175000050417d00006041850100007041"));
@@ -155,7 +156,8 @@ TEST_F(QtTypesQtGuiTest, QTransformTest)
 
     EXPECT_TRUE(QByteArray::fromHex("0a51490000000000002040410000000000001c4039000000000000184031000000000000144029000000000000104021000000000000084019000000000000004011000000000000f03f090000000000000000") == result
                 || QByteArray::fromHex("0a4811000000000000f03f190000000000000040210000000000000840290000000000001040310000000000001440390000000000001840410000000000001c40490000000000002040") == result
-                || QByteArray::fromHex("0a5149000000000000204009000000000000000011000000000000f03f190000000000000040210000000000000840290000000000001040310000000000001440390000000000001840410000000000001c40") == result);
+                || QByteArray::fromHex("0a5149000000000000204009000000000000000011000000000000f03f190000000000000040210000000000000840290000000000001040310000000000001440390000000000001840410000000000001c40") == result
+                || QByteArray::fromHex("0a5109000000000000000011000000000000f03f190000000000000040210000000000000840290000000000001040310000000000001440390000000000001840410000000000001c40490000000000002040") == result);
 
     msg.setTestField({});
     msg.deserialize(serializer.get(), QByteArray::fromHex("0a48090000000000002040110000000000001c4019000000000000184021000000000000144029000000000000104031000000000000084039000000000000004041000000000000f03f"));