diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 03793e6..2207ac4 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -5,7 +5,6 @@ on: branches: - master - dev - - setup-ci pull_request: branches: - master @@ -22,9 +21,11 @@ jobs: - name: Install Qt uses: jurplel/install-qt-action@v3 with: - version: "5.15.2" + aqtversion: "==3.1.*" + version: "6.8.0" host: linux target: desktop + arch: linux_gcc_64 - name: Configure CMake run: cmake --preset linux diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7d4945b..76fca9e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -5,7 +5,6 @@ on: branches: - master - dev - - setup-ci pull_request: branches: - master @@ -13,7 +12,7 @@ on: jobs: build: - runs-on: macos-latest + runs-on: macos-13 steps: - name: Check Out @@ -22,12 +21,14 @@ jobs: - name: Install Qt uses: jurplel/install-qt-action@v3 with: - version: "5.15.2" + aqtversion: "==3.1.*" + version: "6.8.0" host: mac target: desktop + arch: clang_64 - name: Configure CMake - run: cmake --preset macos -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY="-" + run: cmake --preset macos - name: Build library run: cmake --build --preset macos diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 26b61af..db86034 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -5,7 +5,6 @@ on: branches: - master - dev - - setup-ci pull_request: branches: - master @@ -22,9 +21,11 @@ jobs: - name: Install Qt uses: jurplel/install-qt-action@v3 with: - version: "5.15.2" + aqtversion: "==3.1.*" + version: "6.8.0" host: windows target: desktop + arch: win64_msvc2022_64 - name: Configure CMake run: cmake --preset windows diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c56fe5..c17a61b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.3.0 + +- Switch to Qt6. + ## v1.2.1 - Fix deployment on macOS. diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ad4049..c65c209 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.21.0) enable_testing() set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(DeployQt) # Set project information. project("QtUtils" LANGUAGES CXX - VERSION 1.2.1.0 + VERSION 1.3.0.0 + DESCRIPTION "Set of tools for Qt6" ) set(PROJECT_NAMESPACE "oclero") @@ -15,7 +15,17 @@ set(PROJECT_NAMESPACE "oclero") set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) +if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "13.6") +endif() + +# Find Qt. +find_package(Qt6 REQUIRED COMPONENTS Core) +qt_standard_project_setup() # The library. add_subdirectory(src) diff --git a/CMakePresets.json b/CMakePresets.json index 687ce3f..df187c5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,7 +13,7 @@ "generator": "Xcode", "binaryDir": "${sourceDir}/_build", "cacheVariables": { - "Qt5_DIR": "/opt/homebrew/opt/qt/lib/cmake/Qt5" + "CMAKE_PREFIX_PATH": "/opt/homebrew/opt/qt/lib/cmake/Qt6" }, "condition": { "type": "equals", @@ -28,7 +28,7 @@ "generator": "Visual Studio 17 2022", "binaryDir": "${sourceDir}/_build", "cacheVariables": { - "Qt5_DIR": "C:/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5" + "CMAKE_PREFIX_PATH": "C:/Qt/6.8.0/msvc2022_64" }, "condition": { "type": "equals", @@ -55,7 +55,9 @@ "displayName": "macOS", "configurePreset": "macos", "description": "Release build with Xcode for macOS", - "targets": ["QtUtils"], + "targets": [ + "QtUtils" + ], "configuration": "Release", "condition": { "type": "equals", @@ -68,7 +70,9 @@ "displayName": "Tests for macOS", "configurePreset": "macos", "description": "Tests release build with Xcode for macOS", - "targets": ["QtUtilsTests"], + "targets": [ + "QtUtilsTests" + ], "configuration": "Release", "condition": { "type": "equals", @@ -81,7 +85,9 @@ "displayName": "Windows", "configurePreset": "windows", "description": "Release build with Visual Studio for Windows", - "targets": ["QtUtils"], + "targets": [ + "QtUtils" + ], "configuration": "Release", "condition": { "type": "equals", @@ -94,7 +100,9 @@ "displayName": "Tests for Windows", "configurePreset": "windows", "description": "Tests release build with Visual Studio for Windows", - "targets": ["QtUtilsTests"], + "targets": [ + "QtUtilsTests" + ], "configuration": "Release", "condition": { "type": "equals", @@ -107,7 +115,9 @@ "displayName": "Linux", "configurePreset": "linux", "description": "Release build for Linux", - "targets": ["QtUtils"], + "targets": [ + "QtUtils" + ], "configuration": "Release", "condition": { "type": "equals", @@ -120,7 +130,9 @@ "displayName": "Tests for Linux", "configurePreset": "linux", "description": "Tests release build for Linux", - "targets": ["QtUtilsTests"], + "targets": [ + "QtUtilsTests" + ], "configuration": "Release", "condition": { "type": "equals", @@ -139,8 +151,7 @@ }, "execution": { "noTestsAction": "error", - "stopOnFailure": false, - "rerun-failed": true + "stopOnFailure": false }, "condition": { "type": "equals", @@ -157,8 +168,7 @@ }, "execution": { "noTestsAction": "error", - "stopOnFailure": false, - "rerun-failed": true + "stopOnFailure": false }, "condition": { "type": "equals", @@ -175,8 +185,7 @@ }, "execution": { "noTestsAction": "error", - "stopOnFailure": false, - "rerun-failed": true + "stopOnFailure": false }, "condition": { "type": "equals", @@ -185,4 +194,4 @@ } } ] -} +} \ No newline at end of file diff --git a/README.md b/README.md index d70f8b4..03312a0 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ # QtUtils [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://mit-license.org/) -[![CMake version](https://img.shields.io/badge/CMake-3.21+-064F8C?logo=cmake)](https://www.qt.io) -[![C++ version](https://img.shields.io/badge/C++-17-00599C?logo=++)](https://www.qt.io) -[![Qt version](https://img.shields.io/badge/Qt-5.15.2+-41CD52?logo=qt)](https://www.qt.io) +[![CMake version](https://img.shields.io/badge/CMake-3.21+-064F8C?logo=cmake)](https://www.cmake.org) +[![C++ version](https://img.shields.io/badge/C++-17-00599C?logo=++)](https://en.cppreference.com) +[![Qt version](https://img.shields.io/badge/Qt-6.0.0+-41CD52?logo=qt)](https://www.qt.io) **QtUtils** is a set of basic utilities that I consider should be part of Qt API. It contains many helpers that improve the Qt experience, from dealing with `enum` to usage of pointers. @@ -27,7 +27,7 @@ - Platform: Windows, MacOS, Linux. - [CMake 3.21+](https://cmake.org/download/) -- [Qt 5.15+](https://www.qt.io/download-qt-installer) +- [Qt 6.0.0+](https://www.qt.io/download-qt-installer) ## Usage diff --git a/cmake/DeployQt.cmake b/cmake/DeployQt.cmake deleted file mode 100644 index e0ac639..0000000 --- a/cmake/DeployQt.cmake +++ /dev/null @@ -1,32 +0,0 @@ -# Deploys Qt libraries besides the target executable. -function(target_deploy_qt TARGET_NAME) - if(WIN32) - set(DEPLOYQT_NAME "windeployqt") - elseif(APPLE) - get_target_property(TARGET_IS_BUNDLE ${TARGET_NAME} MACOSX_BUNDLE) - if(${TARGET_IS_BUNDLE}) - set(DEPLOYQT_NAME "macdeployqt") - else() - set(DEPLOYQT_NAME "") - endif() - else() - set(DEPLOYQT_NAME "") - endif() - - if (DEPLOYQT_NAME) - get_target_property(QMAKE_LOCATION Qt5::qmake IMPORTED_LOCATION) - get_filename_component(QT_BINARY_DIR ${QMAKE_LOCATION} DIRECTORY) - find_program(DEPLOYQT_EXE "${DEPLOYQT_NAME}" HINTS "${QT_BINARY_DIR}" REQUIRED) - set(QTDEPLOY_TARGET_NAME Qt5::deploy) - add_executable(${QTDEPLOY_TARGET_NAME} IMPORTED) - set_property(TARGET ${QTDEPLOY_TARGET_NAME} PROPERTY IMPORTED_LOCATION ${DEPLOYQT_EXE}) - - # Deploy Qt dependencies to help launch individual instances. - if(TARGET ${QTDEPLOY_TARGET_NAME}) - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Deploying Qt..." - COMMAND ${QTDEPLOY_TARGET_NAME} --verbose 0 --no-patchqt --no-compiler-runtime --no-webkit2 --no-system-d3d-compiler --no-translations --no-angle --no-opengl-sw --dir "$" "$" - ) - endif() - endif() -endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c94959..b9b18d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,5 @@ set(LIB_TARGET_NAME ${PROJECT_NAME}) -find_package(Qt5 - REQUIRED - Core -) - set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/oclero/QtConnectionUtils.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/oclero/QtEnumUtils.hpp @@ -22,16 +17,15 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/source/oclero/QtSettingsUtils.cpp ) -# Configure target. -add_library(${LIB_TARGET_NAME} STATIC) -add_library(${PROJECT_NAMESPACE}::${LIB_TARGET_NAME} ALIAS ${LIB_TARGET_NAME}) - -target_sources(${LIB_TARGET_NAME} - PRIVATE - ${HEADERS} - ${SOURCES} +# Create target. +qt_add_library(${LIB_TARGET_NAME} STATIC + ${HEADERS} + ${SOURCES} ) +# Create a target alias. +add_library(${PROJECT_NAMESPACE}::${LIB_TARGET_NAME} ALIAS ${LIB_TARGET_NAME}) + target_include_directories(${LIB_TARGET_NAME} PUBLIC $ @@ -41,27 +35,33 @@ target_include_directories(${LIB_TARGET_NAME} target_link_libraries(${LIB_TARGET_NAME} PRIVATE - Qt5::Core + Qt::Core ) set_target_properties(${LIB_TARGET_NAME} PROPERTIES - AUTOMOC ON - AUTORCC ON OUTPUT_NAME ${LIB_TARGET_NAME} PROJECT_LABEL ${LIB_TARGET_NAME} FOLDER lib SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} DEBUG_POSTFIX _debug + CMAKE_AUTORCC ON + CMAKE_AUTOMOC ON + CMAKE_AUTOUIC ON ) -target_compile_options(${LIB_TARGET_NAME} PRIVATE $<$:/MP>) - +target_compile_options(${LIB_TARGET_NAME} + PRIVATE + $<$:/MP /WX /W4> + $<$>:-Wall -Wextra -Werror> +) + # Create source groups. -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES - ${HEADERS} - ${SOURCES} +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} + FILES + ${HEADERS} + ${SOURCES} ) # Select correct startup project in Visual Studio. diff --git a/src/include/oclero/QtConnectionUtils.hpp b/src/include/oclero/QtConnectionUtils.hpp index 035ce8e..684d74b 100644 --- a/src/include/oclero/QtConnectionUtils.hpp +++ b/src/include/oclero/QtConnectionUtils.hpp @@ -1,5 +1,11 @@ #pragma once +#include +#include + +#include +#include + namespace oclero { /** * @brief Allows to connect to a signal a callaback that will be executed only once. diff --git a/src/include/oclero/QtEnumUtils.hpp b/src/include/oclero/QtEnumUtils.hpp index 172df9a..cba6833 100644 --- a/src/include/oclero/QtEnumUtils.hpp +++ b/src/include/oclero/QtEnumUtils.hpp @@ -1,8 +1,9 @@ #pragma once +#include + #include #include -#include namespace oclero { template @@ -40,7 +41,7 @@ TEnum enumFromString(const QString& str, const TEnum defaultValue = TEnum()) { template constexpr auto toUnderlyingType(const TEnum value) { - return static_cast::type>(value); + return static_cast>(value); } template diff --git a/src/include/oclero/QtEventFilterUtils.hpp b/src/include/oclero/QtEventFilterUtils.hpp index ed06058..6141c15 100644 --- a/src/include/oclero/QtEventFilterUtils.hpp +++ b/src/include/oclero/QtEventFilterUtils.hpp @@ -1,13 +1,12 @@ #pragma once #include - -#include -#include - -#include -#include -#include "qgraphicssceneevent.h" +#include +#include +#include +#include +#include +#include namespace oclero { @@ -49,7 +48,7 @@ DECLARE_EVENT_TYPE(QEvent::Type::DragMove, QDragMoveEvent) DECLARE_EVENT_TYPE(QEvent::Type::Drop, QDropEvent) DECLARE_EVENT_TYPE(QEvent::Type::DynamicPropertyChange, QEvent) DECLARE_EVENT_TYPE(QEvent::Type::EnabledChange, QEvent) -DECLARE_EVENT_TYPE(QEvent::Type::Enter, QEvent) +DECLARE_EVENT_TYPE(QEvent::Type::Enter, QEnterEvent) #if defined(QT_KEYPAD_NAVIGATION) DECLARE_EVENT_TYPE(QEvent::Type::EnterEditFocus, QEvent) #endif @@ -134,8 +133,6 @@ DECLARE_EVENT_TYPE(QEvent::Type::ShortcutOverride, QKeyEvent) DECLARE_EVENT_TYPE(QEvent::Type::Show, QShowEvent) DECLARE_EVENT_TYPE(QEvent::Type::ShowToParent, QEvent) DECLARE_EVENT_TYPE(QEvent::Type::SockAct, QEvent) -DECLARE_EVENT_TYPE(QEvent::Type::StateMachineSignal, QStateMachine::SignalEvent) -DECLARE_EVENT_TYPE(QEvent::Type::StateMachineWrapped, QStateMachine::WrappedEvent) DECLARE_EVENT_TYPE(QEvent::Type::StatusTip, QStatusTipEvent) DECLARE_EVENT_TYPE(QEvent::Type::StyleChange, QEvent) DECLARE_EVENT_TYPE(QEvent::Type::TabletMove, QTabletEvent) @@ -194,7 +191,7 @@ class EventFilter : private QObject { } protected: - virtual bool eventFilter(QObject* watchedObject, QEvent* evt) override { + bool eventFilter(QObject* watchedObject, QEvent* evt) override { if (evt->type() == T && _eventCallback) { auto* const derivedEvent = static_cast(evt); return _eventCallback(derivedEvent); @@ -228,7 +225,7 @@ class VisibilityEventFilter : private QObject { } protected: - inline virtual bool eventFilter(QObject* watchedObject, QEvent* evt) override { + inline bool eventFilter(QObject* watchedObject, QEvent* evt) override { const auto type = evt->type(); switch (type) { case QEvent::Hide: diff --git a/src/include/oclero/QtPointerUtils.hpp b/src/include/oclero/QtPointerUtils.hpp index d6143ec..c736991 100644 --- a/src/include/oclero/QtPointerUtils.hpp +++ b/src/include/oclero/QtPointerUtils.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + namespace oclero { struct QtDeleteLater { void operator()(QObject* o) const { diff --git a/src/include/oclero/QtScopedConnection.hpp b/src/include/oclero/QtScopedConnection.hpp index ad702d1..1435ba7 100644 --- a/src/include/oclero/QtScopedConnection.hpp +++ b/src/include/oclero/QtScopedConnection.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + namespace oclero { /** * @brief RAII QMetaObject::Connection. @@ -26,7 +27,7 @@ class QtScopedConnection { /** * @brief Returns true if the connection is valid. */ - operator bool() const; + explicit operator bool() const; /** * @brief Disconnects the connection. diff --git a/src/include/oclero/QtSettingsUtils.hpp b/src/include/oclero/QtSettingsUtils.hpp index 4892a24..7d1fea1 100644 --- a/src/include/oclero/QtSettingsUtils.hpp +++ b/src/include/oclero/QtSettingsUtils.hpp @@ -11,19 +11,20 @@ std::optional tryGetVariantValue(const QVariant& variant) { if (!variant.isValid()) return {}; - if constexpr (std::is_same::value) { - const auto variantType = variant.type(); - const auto validType = variantType == QVariant::Type::Int || variantType == QVariant::Type::LongLong - || variantType == QVariant::Type::UInt || variantType == QVariant::Type::ULongLong; + if constexpr (std::is_same_v) { + const auto variantType = variant.metaType().id(); + const auto validType = variantType == QMetaType::Type::Int || variantType == QMetaType::Type::LongLong + || variantType == QMetaType::Type::UInt || variantType == QMetaType::Type::ULongLong; return validType ? variant.toInt() : std::optional(); - } else if constexpr (std::is_same::value) { - const auto variantType = variant.type(); - const auto validType = variantType == QVariant::Type::Int || variantType == QVariant::Type::LongLong - || variantType == QVariant::Type::UInt || variantType == QVariant::Type::ULongLong - || variantType == QVariant::Type::Double; + } else if constexpr (std::is_same_v) { + const auto variantType = variant.metaType().id(); + const auto validType = variantType == QMetaType::Type::Int || variantType == QMetaType::Type::LongLong + || variantType == QMetaType::Type::UInt || variantType == QMetaType::Type::ULongLong + || variantType == QMetaType::Type::Double; return validType ? variant.toDouble() : std::optional(); - } else if constexpr (std::is_same::value) { - return variant.type() == QVariant::Type::String ? variant.toString() : std::optional(); + } else if constexpr (std::is_same_v) { + const auto variantType = variant.metaType().id(); + return variantType == QMetaType::Type::QString ? variant.toString() : std::optional(); } else if (variant.canConvert()) { return variant.value(); } else { @@ -45,7 +46,7 @@ std::optional tryLoadSetting(const QSettings& settings, const char* key) template std::optional tryLoadSetting(const QSettings& settings, const QString& key) { const auto byteArray = key.toUtf8(); - const char* rawKey = byteArray.constData(); + const auto* rawKey = byteArray.constData(); return tryLoadSetting(settings, rawKey); } @@ -57,7 +58,7 @@ TValue loadSetting(const QSettings& settings, const char* key, const TValue& def template TValue loadSetting(const QSettings& settings, const QString& key, const TValue& defaultValue = TValue()) { const auto byteArray = key.toUtf8(); - const char* rawKey = byteArray.constData(); + const auto* rawKey = byteArray.constData(); return loadSetting(settings, rawKey, defaultValue); } @@ -74,7 +75,7 @@ void saveSetting(QSettings& settings, const char* key, const TValue& value) { template void saveSetting(QSettings& settings, const QString& key, const TValue& value) { const auto byteArray = key.toUtf8(); - const char* rawKey = byteArray.constData(); + const auto* rawKey = byteArray.constData(); saveSetting(settings, rawKey, value); } diff --git a/src/include/oclero/QtTestUtils.hpp b/src/include/oclero/QtTestUtils.hpp index bd6bfbb..80a6c2d 100644 --- a/src/include/oclero/QtTestUtils.hpp +++ b/src/include/oclero/QtTestUtils.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace oclero { /// Return true if all tests pass, false otherwise. diff --git a/src/source/oclero/QtScopedConnection.cpp b/src/source/oclero/QtScopedConnection.cpp index 6160ae8..5859925 100644 --- a/src/source/oclero/QtScopedConnection.cpp +++ b/src/source/oclero/QtScopedConnection.cpp @@ -3,7 +3,6 @@ #include namespace oclero { -#pragma region QtScopedConnection QtScopedConnection::QtScopedConnection() = default; QtScopedConnection::QtScopedConnection(QtScopedConnection&& other) noexcept { @@ -46,10 +45,6 @@ void QtScopedConnection::set(const QMetaObject::Connection& connection) { _connection = connection; } -#pragma endregion - -#pragma region QtScopedConnection - QtScopedConnections::QtScopedConnections() {} QtScopedConnections::~QtScopedConnections() { @@ -81,5 +76,4 @@ void QtScopedConnections::clear() { } _connections.clear(); } -#pragma endregion } // namespace oclero diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d988f9f..783a7b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,20 +1,10 @@ set(TESTS_TARGET_NAME ${PROJECT_NAME}Tests) -find_package(Qt5 REQUIRED +find_package(Qt6 REQUIRED COMPONENTS Core Widgets Test ) - -add_executable(${TESTS_TARGET_NAME}) -set_target_properties(${TESTS_TARGET_NAME} - PROPERTIES - AUTOMOC ON - AUTORCC ON - INTERNAL_CONSOLE ON - EXCLUDE_FROM_ALL ON - FOLDER tests -) set(TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/QtConnectionUtilsTests.cpp @@ -28,10 +18,20 @@ set(TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/QtSettingsUtilsTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/QtSettingsUtilsTests.hpp ) -target_sources(${TESTS_TARGET_NAME} - PRIVATE - ${TESTS_SOURCES} +qt_add_executable(${TESTS_TARGET_NAME} + ${TESTS_SOURCES} ) + +set_target_properties(${TESTS_TARGET_NAME} + PROPERTIES + INTERNAL_CONSOLE ON + EXCLUDE_FROM_ALL ON + FOLDER tests + CMAKE_AUTORCC ON + CMAKE_AUTOMOC ON + CMAKE_AUTOUIC ON +) + target_include_directories(${TESTS_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} @@ -39,14 +39,12 @@ target_include_directories(${TESTS_TARGET_NAME} target_link_libraries(${TESTS_TARGET_NAME} PRIVATE ${PROJECT_NAMESPACE}::${PROJECT_NAME} - Qt5::Core - Qt5::Widgets - Qt5::Test + Qt::Core + Qt::Widgets + Qt::Test ) add_test(NAME ${TESTS_TARGET_NAME} COMMAND $ WORKING_DIRECTORY $) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${TESTS_SOURCES}) - -target_deploy_qt(${TESTS_TARGET_NAME}) diff --git a/tests/src/QtConnectionUtilsTests.cpp b/tests/src/QtConnectionUtilsTests.cpp index 923dd04..dcac7f9 100644 --- a/tests/src/QtConnectionUtilsTests.cpp +++ b/tests/src/QtConnectionUtilsTests.cpp @@ -6,7 +6,7 @@ #include void QtConnectionUtilsTests::test_singleShotConnect() { - int count = 0; + auto count = 0; oclero::singleShotConnect(this, &QtConnectionUtilsTests::signalTriggered, [&count]() { count++; }); @@ -16,7 +16,7 @@ void QtConnectionUtilsTests::test_singleShotConnect() { } void QtConnectionUtilsTests::test_scopedConnection() { - int count = 0; + auto count = 0; { oclero::QtScopedConnection scopedConnection = QObject::connect(this, &QtConnectionUtilsTests::signalTriggered, [&count]() { diff --git a/tests/src/QtEventFilterUtilsTests.cpp b/tests/src/QtEventFilterUtilsTests.cpp index c470f18..3041299 100644 --- a/tests/src/QtEventFilterUtilsTests.cpp +++ b/tests/src/QtEventFilterUtilsTests.cpp @@ -7,21 +7,18 @@ void QtEventFilterUtilsTest::test_filter() const { auto* dummyObject = new QObject(); - bool called{ false }; + auto called{ false }; // Listen to a dummy event. - oclero::EventFilter::install(dummyObject, [&called](QContextMenuEvent* e) { + oclero::EventFilter::install(dummyObject, [&called](QContextMenuEvent*) { called = true; return false; }); // Send this dummy event synchronously. - QContextMenuEvent dummyEvent(QContextMenuEvent::Reason::Other, QPoint{ 0, 0 }); + QContextMenuEvent dummyEvent(QContextMenuEvent::Reason::Other, QPoint{ 0, 0 }, QPoint{ 0, 0 }); QCoreApplication::sendEvent(dummyObject, &dummyEvent); // Check if callback has correctly been called. QVERIFY(called); - - // Cleaning. - delete dummyObject; } diff --git a/tests/src/QtPointerUtilsTests.cpp b/tests/src/QtPointerUtilsTests.cpp index 33aadd2..6c405cc 100644 --- a/tests/src/QtPointerUtilsTests.cpp +++ b/tests/src/QtPointerUtilsTests.cpp @@ -5,7 +5,7 @@ #include #include -void QtPointerUtilsTest::test_pointerShouldNotBeDeletedImmediately() { +void QtPointerUtilsTest::test_pointerShouldNotBeDeletedImmediately() const { auto pointerDestroyed = false; auto rawPointer = new QObject; diff --git a/tests/src/QtPointerUtilsTests.hpp b/tests/src/QtPointerUtilsTests.hpp index f172de3..0c457be 100644 --- a/tests/src/QtPointerUtilsTests.hpp +++ b/tests/src/QtPointerUtilsTests.hpp @@ -6,6 +6,6 @@ class QtPointerUtilsTest : public QObject { Q_OBJECT private slots: - void test_pointerShouldNotBeDeletedImmediately(); + void test_pointerShouldNotBeDeletedImmediately() const; void test_pointerShouldBeDeletedAfterEventLoop(); }; diff --git a/tests/src/QtSettingsUtilsTests.cpp b/tests/src/QtSettingsUtilsTests.cpp index 2732856..5b5f0c3 100644 --- a/tests/src/QtSettingsUtilsTests.cpp +++ b/tests/src/QtSettingsUtilsTests.cpp @@ -9,17 +9,13 @@ constexpr auto SETTINGS_KEY = "Toto"; using namespace oclero; void QtSettingsUtilsTests::init() { - { - QSettings qSettings; - qSettings.remove(SETTINGS_KEY); - } + QSettings qSettings; + qSettings.remove(SETTINGS_KEY); } void QtSettingsUtilsTests::cleanup() { - { - QSettings qSettings; - qSettings.remove(SETTINGS_KEY); - } + QSettings qSettings; + qSettings.remove(SETTINGS_KEY); } void QtSettingsUtilsTests::test_tryLoadInexistentSetting_enum() const { @@ -29,14 +25,18 @@ void QtSettingsUtilsTests::test_tryLoadInexistentSetting_enum() const { } void QtSettingsUtilsTests::test_tryLoadInvalidSetting_enum() const { - { QSettings{}.setValue(SETTINGS_KEY, "1"); } + { + QSettings{}.setValue(SETTINGS_KEY, "1"); + } QSettings settings; auto const optionalValue = tryLoadSetting(settings, SETTINGS_KEY); QVERIFY(!optionalValue.has_value()); } void QtSettingsUtilsTests::test_tryLoadValidSetting_enum() const { - { QSettings{}.setValue(SETTINGS_KEY, "DummyValue2"); } + { + QSettings{}.setValue(SETTINGS_KEY, "DummyValue2"); + } QSettings settings; auto const optionalValue = tryLoadSetting(settings, SETTINGS_KEY); QVERIFY(optionalValue.has_value() && optionalValue.value() == DummyEnum::DummyValue2); @@ -49,21 +49,27 @@ void QtSettingsUtilsTests::test_tryLoadInexistentSetting_int() const { } void QtSettingsUtilsTests::test_tryLoadInvalidSetting_int() const { - { QSettings{}.setValue(SETTINGS_KEY, "abc"); } + { + QSettings{}.setValue(SETTINGS_KEY, "abc"); + } QSettings settings; auto const optionalValue = tryLoadSetting(settings, SETTINGS_KEY); QVERIFY(!optionalValue.has_value()); } void QtSettingsUtilsTests::test_tryLoadValidSetting_int() const { - { QSettings{}.setValue(SETTINGS_KEY, 42); } + { + QSettings{}.setValue(SETTINGS_KEY, 42); + } QSettings settings; auto const optionalValue = tryLoadSetting(settings, SETTINGS_KEY); QVERIFY(optionalValue.has_value() && optionalValue.value() == 42); } void QtSettingsUtilsTests::test_loadValidSetting() const { - { QSettings{}.setValue(SETTINGS_KEY, 42); } + { + QSettings{}.setValue(SETTINGS_KEY, 42); + } QSettings settings; auto const value = loadSetting(settings, SETTINGS_KEY); QVERIFY(value == 42); diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 6f3587c..a7ce3cb 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -10,7 +10,7 @@ #include "QtSettingsUtilsTests.hpp" int main(int argc, char* argv[]) { - QTEST_SET_MAIN_SOURCE_PATH; + QTEST_SET_MAIN_SOURCE_PATH // Necessary to get a socket name and to have an event loop running. QCoreApplication::setApplicationName("QtUtilsTests");