From e7d9048257fbd53d5cb40510dd4acd1af35031b5 Mon Sep 17 00:00:00 2001 From: re2zero Date: Thu, 2 Jan 2025 17:20:51 +0800 Subject: [PATCH] feat: Enable Qt6 building Enable build with Qt6, and it compats Qt5. Log: Enable Qt6 building. --- .reuse/dep5 | 5 + CMakeLists.txt | 22 +++- cmake/translation-generate.cmake | 39 ++++++ debian/changelog | 6 + debian/control | 21 +++- debian/rules | 28 ++++- src/AptInstallDepend/CMakeLists.txt | 30 +++-- src/deb-installer/CMakeLists.txt | 119 ++++++++++-------- .../compatible/compatible_backend.h | 1 + src/deb-installer/main.cpp | 3 - .../manager/DealDependThread.cpp | 2 +- src/deb-installer/manager/packagesmanager.cpp | 30 +++-- src/deb-installer/manager/packagesmanager.h | 2 +- src/deb-installer/model/deblistmodel.cpp | 12 +- .../model/packageselectmodel.cpp | 12 +- .../model/packageslistdelegate.cpp | 6 +- src/deb-installer/process/Pty.cpp | 16 ++- src/deb-installer/process/Pty.h | 3 + src/deb-installer/process/kprocess.cpp | 4 + src/deb-installer/process/kprocess.h | 2 + src/deb-installer/process/kpty.cpp | 2 +- src/deb-installer/process/kptyprocess.cpp | 2 + src/deb-installer/process/kptyprocess.h | 2 + .../utils/hierarchicalverify.cpp | 3 +- src/deb-installer/utils/qtcompat.h | 42 +++++++ src/deb-installer/utils/utils.cpp | 11 +- src/deb-installer/utils/utils.h | 4 +- .../view/pages/AptConfigMessage.cpp | 1 - src/deb-installer/view/pages/debinstaller.cpp | 1 - .../view/pages/singleinstallpage.cpp | 5 +- .../view/widgets/choosefilebutton.cpp | 2 +- .../view/widgets/coloredprogressbar.cpp | 4 + .../view/widgets/debinfolabel.cpp | 10 +- .../view/widgets/droundbgframe.cpp | 2 +- .../view/widgets/filechoosewidget.cpp | 7 +- .../view/widgets/infocontrolbutton.cpp | 2 +- .../view/widgets/installprocessinfoview.cpp | 4 +- .../view/widgets/packageselectitem.cpp | 2 +- src/deepin-deb-installer-dev/CMakeLists.txt | 23 ++-- .../status/PackageStatus.cpp | 4 +- tests/CMakeLists.txt | 63 ++++------ tests/src/model/ut_deblistmodel.cpp | 14 ++- tests/src/ut_singleInstallerApplication.cpp | 6 +- tests/src/utils/ut_utils.cpp | 4 + tests/src/view/pages/ut_AptConfigMessage.cpp | 6 +- tests/src/view/pages/ut_debinstaller.cpp | 6 +- .../src/view/pages/ut_multipleinstallpage.cpp | 6 +- tests/src/view/pages/ut_singleinstallpage.cpp | 6 +- .../view/pages/ut_uninstallconfirmpage.cpp | 6 +- .../view/widgets/ut_coloredprogressbar.cpp | 12 +- tests/src/view/widgets/ut_droundbgframe.cpp | 6 +- tests/src/view/widgets/ut_processwidget.cpp | 5 + 52 files changed, 437 insertions(+), 199 deletions(-) create mode 100644 cmake/translation-generate.cmake create mode 100644 src/deb-installer/utils/qtcompat.h diff --git a/.reuse/dep5 b/.reuse/dep5 index ddabc21e..61cd6a9b 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -23,6 +23,11 @@ Files: debian/* Copyright: UnionTech Software Technology Co., Ltd. License: CC0-1.0 +# cmake +Files: cmake/* +Copyright: UnionTech Software Technology Co., Ltd. +License: CC0-1.0 + # Project file Files: *.pro *.prf *.pri *.qrc *CMakeLists.txt .tx/* Copyright: UnionTech Software Technology Co., Ltd. diff --git a/CMakeLists.txt b/CMakeLists.txt index 4423cedd..fe9e360d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,22 @@ set(CMAKE_SAFETYTEST OFF) project(deepin_deb_installer) option(DMAN_RELEAE OFF "Install dman resources to system or not") -find_package(Qt5LinguistTools REQUIRED) -set(POLICY_FILE com.deepin.pkexec.aptInstallDepend.policy) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +# 引入翻译生成 +include(translation-generate) + +# Find Qt version +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +message(" >>> Found Qt version: ${QT_VERSION_MAJOR}") +set(QT_DESIRED_VERSION ${QT_VERSION_MAJOR}) + +if (QT_VERSION_MAJOR MATCHES 6) + set(DTK_VERSION_MAJOR 6) +else() + set(DTK_VERSION_MAJOR "") +endif() +message(" >>> Build with DTK: ${DTK_VERSION_MAJOR}") + add_subdirectory(src/AptInstallDepend) add_subdirectory(src/deb-installer) @@ -24,6 +38,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") endif() add_subdirectory(src/deepin-deb-installer-dev) -add_subdirectory(translations) + +set(POLICY_FILE com.deepin.pkexec.aptInstallDepend.policy) +add_subdirectory(translations/policy) # add_subdirectory(tests/FuzzyTest) diff --git a/cmake/translation-generate.cmake b/cmake/translation-generate.cmake new file mode 100644 index 00000000..a45ee68e --- /dev/null +++ b/cmake/translation-generate.cmake @@ -0,0 +1,39 @@ +function(TRANSLATION_GENERATE QMS) + find_package(Qt${QT_VERSION_MAJOR}LinguistTools QUIET) + + if (NOT Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE) + set(QT_LRELEASE "/lib/qt${QT_VERSION_MAJOR}/bin/lrelease") + message(STATUS "NOT found lrelease, set QT_LRELEASE = ${QT_LRELEASE}") + else() + set(QT_LRELEASE "${Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE}") + endif() + + if(NOT ARGN) + message(SEND_ERROR "Error: TRANSLATION_GENERATE() called without any .ts path") + return() + endif() + + # # 获取 translations 目录下的所有 .ts 文件 + # file(GLOB_RECURSE TS_FILES "${ARGN}/*.ts") + # 获取指定目录下的所有 .ts 文件,不包括子目录 + file(GLOB TS_FILES "${ARGN}/*.ts") + + set(${QMS}) + foreach(TSFIL ${TS_FILES}) + get_filename_component(FIL_WE ${TSFIL} NAME_WE) +# get_filename_component(TS_DIR ${TSFIL} DIRECTORY) + set(QMFIL ${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.qm) + list(APPEND ${QMS} ${QMFIL}) + add_custom_command( + OUTPUT ${QMFIL} + # COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -ts ${TSFIL} + COMMAND ${QT_LRELEASE} ${TSFIL} -qm ${QMFIL} + DEPENDS ${TSFIL} + COMMENT "Running ${QT_LRELEASE} on ${TSFIL}" + VERBATIM + ) + endforeach() + + set_source_files_properties(${${QMS}} PROPERTIES GENERATED TRUE) + set(${QMS} ${${QMS}} PARENT_SCOPE) +endfunction() diff --git a/debian/changelog b/debian/changelog index a6ae510c..ec7ebef4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +deepin-deb-installer (6.5.4) unstable; urgency=medium + + * feat: Enable support Qt6 build. + + -- re2zero Fri, 3 Jan 2025 16:27:05 +0800 + deepin-deb-installer (6.5.3) unstable; urgency=medium * fix: assume yes in immutable install(Bug: 291783)(Influence: immutable) diff --git a/debian/control b/debian/control index c08ad11d..27951c51 100644 --- a/debian/control +++ b/debian/control @@ -2,15 +2,30 @@ Source: deepin-deb-installer Section: utils Priority: optional Maintainer: Deepin Packages Builder -Build-Depends: debhelper (>= 9), pkg-config, cmake, libqt5widgets5, libqt5concurrent5, libqapt-dev, libdtkwidget-dev, qtbase5-dev, qttools5-dev-tools, qttools5-dev, qtchooser, libgtest-dev, deepin-gettext-tools, libpolkit-qt5-1-dev +Build-Depends: + debhelper (>= 9), + pkg-config, + cmake, + qt6-5compat-dev | hello, + qt6-base-dev | qtbase5-dev, + qt6-tools-dev-tools | qttools5-dev-tools, + qt6-tools-dev | qttools5-dev, + qt6-svg-dev | libqt5svg5-dev, + libdtk6widget-dev | libdtkwidget-dev, + libdtk6gui-dev | libdtkgui-dev, + libdtk6core-dev | libdtkcore-dev, + libqapt-qt6-dev | libqapt-dev, + libpolkit-qt6-1-dev | libpolkit-qt5-1-dev, + libgtest-dev, + deepin-gettext-tools, Standards-Version: 4.3.0 Homepage: https://www.deepin.com/ Package: deepin-deb-installer Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - libqapt3-runtime, - libqapt3, + libqapt3-qt6-runtime | libqapt-runtime, + libqapt3-qt6 | libqapt3, # deepin-app-store-runtime is available in the community edition. deepin-elf-verify | deepin-app-store-runtime, deepin-elf-sign-tool | deepin-app-store-runtime diff --git a/debian/rules b/debian/rules index 94dfcec7..9f47e158 100755 --- a/debian/rules +++ b/debian/rules @@ -9,13 +9,31 @@ export QT_SELECT := 5 #export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed include /usr/share/dpkg/default.mk -override_dh_auto_configure: - dh_auto_configure -- \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \ - -DAPP_VERSION=$(DEB_VERSION_UPSTREAM) -DVERSION=$(DEB_VERSION_UPSTREAM) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) +# 检测当前安装的Qt版本,优先使用Qt6,否则使用Qt5 +define detect_qt_version +ifneq (,$(shell which qmake6 2>/dev/null)) + QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt6" +else + QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5" +endif +endef + +# 调用检测Qt版本的命令 +$(eval $(call detect_qt_version)) + +# hardcode this if want to force build with sepecific Qt version +# QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5" + %: dh $@ --parallel +override_dh_auto_configure: + dh_auto_configure -- \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \ + -DAPP_VERSION=$(DEB_VERSION_UPSTREAM) \ + -DVERSION=$(DEB_VERSION_UPSTREAM) \ + -DQT_DIR=$(QT_DIR) + override_dh_shlibdeps: dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info diff --git a/src/AptInstallDepend/CMakeLists.txt b/src/AptInstallDepend/CMakeLists.txt index 5f9ff8bb..e6b587c4 100644 --- a/src/AptInstallDepend/CMakeLists.txt +++ b/src/AptInstallDepend/CMakeLists.txt @@ -10,9 +10,7 @@ endif() project(AptInstallDepend) set(EXE_NAME deepin-deb-installer-dependsInstall) -set(LINK_LIBS - Qt5::Core -) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) @@ -38,14 +36,28 @@ add_executable(${EXE_NAME} ) # Find the library -find_package(Qt5 REQUIRED Core Gui Widgets) +set(qt_required_components Core Gui Widgets) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) + +set(LINK_LIBS + Qt${QT_DESIRED_VERSION}::Core + Qt${QT_DESIRED_VERSION}::Gui + Qt${QT_DESIRED_VERSION}::Widgets +) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat) +endif() + set(CMAKE_INSTALL_PREFIX /usr) # Install files install(TARGETS ${EXE_NAME} DESTINATION bin) -target_link_libraries(${EXE_NAME} ${LINK_LIBS}) target_link_libraries(${EXE_NAME} - Qt5::Core - Qt5::Gui - Qt5::Widgets -) + PUBLIC + ${LINK_LIBS} + ) diff --git a/src/deb-installer/CMakeLists.txt b/src/deb-installer/CMakeLists.txt index 375d3bdf..2ad01a45 100644 --- a/src/deb-installer/CMakeLists.txt +++ b/src/deb-installer/CMakeLists.txt @@ -9,35 +9,45 @@ if(NOT DEFINED VERSION) set(VERSION 5.3.9) endif() -# 检查qapt版本 -execute_process(COMMAND dpkg -s libqapt-dev - COMMAND grep Version - TIMEOUT 5 - OUTPUT_VARIABLE QAPT_VERSION_STR) -string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR}) -message(STATUS "BUILD QAPT VERSION ${QAPT_VERSION_STR}") - -if(${QAPT_VERSION_STR} VERSION_LESS "3.0.5-1") - if(${QAPT_VERSION_STR} VERSION_LESS "3.0.4.8-1+deepin2") - message(STATUS "disable virtual package enhance") - else() - message(STATUS "enable virtual package enhance") - add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE) - endif() +if (QT_DESIRED_VERSION MATCHES 6) + # Qt6支持的qapt已基于3.0.5.2-1-deepin3版本变为libqapt-qt6-dev + # execute_process(COMMAND dpkg -s libqapt-qt6-dev + # COMMAND grep Version + # TIMEOUT 5 + # OUTPUT_VARIABLE QAPT_VERSION_STR) + # string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR}) + message(STATUS "enable virtual package enhance") + add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE) else() - # 部分包名后可能添加后缀,后续更新的deepin分支libqapt包应包含虚包处理 - if(${QAPT_VERSION_STR} VERSION_GREATER_EQUAL "3.0.5.1-1-deepin1" AND ${QAPT_VERSION_STR} MATCHES ".*deepin.*") - message(STATUS "enable virtual package enhance") - add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE) + # 检查qapt版本 + execute_process(COMMAND dpkg -s libqapt-dev + COMMAND grep Version + TIMEOUT 5 + OUTPUT_VARIABLE QAPT_VERSION_STR) + string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR}) + message(STATUS "BUILD QAPT VERSION ${QAPT_VERSION_STR}") + + if(${QAPT_VERSION_STR} VERSION_LESS "3.0.5-1") + if(${QAPT_VERSION_STR} VERSION_LESS "3.0.4.8-1+deepin2") + message(STATUS "disable virtual package enhance") + else() + message(STATUS "enable virtual package enhance") + add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE) + endif() else() - message(STATUS "disable virtual package enhance") + # 部分包名后可能添加后缀,后续更新的deepin分支libqapt包应包含虚包处理 + if(${QAPT_VERSION_STR} VERSION_GREATER_EQUAL "3.0.5.1-1-deepin1" AND ${QAPT_VERSION_STR} MATCHES ".*deepin.*") + message(STATUS "enable virtual package enhance") + add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE) + else() + message(STATUS "disable virtual package enhance") + endif() endif() endif() # common resource names set(APP_RES_DIR "${CMAKE_SOURCE_DIR}/assets") set(APP_BIN_NAME "deepin-deb-installer") -set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh") set(APP_DESKTOP "${APP_RES_DIR}/deepin-deb-installer.desktop") set(APP_MIME "${APP_RES_DIR}/deepin-deb-installer.xml") set(APP_QRC "${APP_RES_DIR}/resources.qrc") @@ -104,38 +114,39 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections") endif() -# Generate the qm file -execute_process(COMMAND bash ${APP_TRANS_SCRIPT} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") - configure_file(${APP_RES_DIR}/environments.h.in environments.h @ONLY) add_definitions(-DUSE_POLKIT -DENABLE_INACTIVE_DISPLAY) # Find the library find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Core REQUIRED) -find_package(Qt5LinguistTools REQUIRED) -find_package(Qt5Concurrent REQUIRED) -find_package(DtkWidget REQUIRED) -find_package(DtkGui REQUIRED) -find_package(DtkCore REQUIRED) -find_package(Qt5DBus REQUIRED) -find_package(PolkitQt5-1 REQUIRED) + +find_package(PolkitQt${QT_DESIRED_VERSION}-1) +set(qt_required_components Core DBus Gui Widgets Concurrent) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) +find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Core Gui Widget REQUIRED) + set(LINK_LIBS - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::DBus - QApt - Qt5::Concurrent - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} - ${DtkGUI_LIBRARIES} + Qt${QT_DESIRED_VERSION}::Core + Qt${QT_DESIRED_VERSION}::DBus + Qt${QT_DESIRED_VERSION}::Gui + Qt${QT_DESIRED_VERSION}::Widgets + Qt${QT_DESIRED_VERSION}::Concurrent + Dtk${DTK_VERSION_MAJOR}::Widget + Dtk${DTK_VERSION_MAJOR}::Core + Dtk${DTK_VERSION_MAJOR}::Gui + PolkitQt${QT_DESIRED_VERSION}-1::Agent ) +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat) +endif() + macro(SUBDIRLIST result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) set(dirlist "") @@ -164,8 +175,6 @@ file(GLOB_RECURSE APP_SRCS ${CMAKE_CURRENT_LIST_DIR}/*.cpp ) -include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) - # Tell CMake to create the executable add_executable(${PROJECT_NAME} ${APP_SRCS} ${APP_QRC}) @@ -173,19 +182,19 @@ target_include_directories(${APP_BIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR}) target_link_libraries(${APP_BIN_NAME} - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::DBus + ${LINK_LIBS} QApt - Qt5::Concurrent - PolkitQt5-1::Agent - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} - ${DtkGUI_LIBRARIES} ) set(CMAKE_INSTALL_PREFIX /usr) +# translation files +TRANSLATION_GENERATE(QM_FILES ${CMAKE_SOURCE_DIR}/translations) +add_custom_target(${PROJECT_NAME}_qm_files DEPENDS ${QM_FILES}) +add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_qm_files) + +# Install translations +install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations) + # Install files install(DIRECTORY ${APP_RES_DIR}/deepin-deb-installer DESTINATION /usr/share/deepin-manual/manual-assets/application/) install(TARGETS deepin-deb-installer RUNTIME DESTINATION bin) diff --git a/src/deb-installer/compatible/compatible_backend.h b/src/deb-installer/compatible/compatible_backend.h index 400795f9..157ad3f0 100644 --- a/src/deb-installer/compatible/compatible_backend.h +++ b/src/deb-installer/compatible/compatible_backend.h @@ -6,6 +6,7 @@ #define COMPATIBLEBACKEND_H #include +#include #include "compatible_defines.h" diff --git a/src/deb-installer/main.cpp b/src/deb-installer/main.cpp index bfd14812..8f914b47 100644 --- a/src/deb-installer/main.cpp +++ b/src/deb-installer/main.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -55,8 +54,6 @@ int main(int argc, char *argv[]) if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) setenv("XDG_CURRENT_DESKTOP", "Deepin", 1); - DApplicationSettings settings; - DLogManager::registerConsoleAppender(); DLogManager::registerFileAppender(); diff --git a/src/deb-installer/manager/DealDependThread.cpp b/src/deb-installer/manager/DealDependThread.cpp index aefcaf08..7301ebeb 100644 --- a/src/deb-installer/manager/DealDependThread.cpp +++ b/src/deb-installer/manager/DealDependThread.cpp @@ -10,7 +10,7 @@ DealDependThread::DealDependThread(QObject *parent) { Q_UNUSED(parent); proc = new QProcess(this); - connect(proc, static_cast(&QProcess::finished), this, &DealDependThread::slotInstallFinished); + connect(proc, QOverload::of(&QProcess::finished), this, &DealDependThread::slotInstallFinished); connect(proc, &QProcess::readyReadStandardOutput, this, &DealDependThread::slotReadOutput); } diff --git a/src/deb-installer/manager/packagesmanager.cpp b/src/deb-installer/manager/packagesmanager.cpp index 7c3772f5..a563a497 100644 --- a/src/deb-installer/manager/packagesmanager.cpp +++ b/src/deb-installer/manager/packagesmanager.cpp @@ -13,6 +13,7 @@ #include "model/packageanalyzer.h" #include "singleInstallerApplication.h" #include "compatible/compatible_backend.h" +#include "utils/qtcompat.h" #include @@ -583,7 +584,12 @@ bool PackagesManager::targetPackageCanReplace(QApt::Package *targetPackage, QApt return false; } - auto rdepends = installedPackage->requiredByList().toSet(); + auto reqList = installedPackage->requiredByList(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + auto rdepends = reqList.toSet(); +#else + QSet rdepends(reqList.begin(), reqList.end()); +#endif // itself package rdepends.remove(targetPackage->name()); // conflict package @@ -600,8 +606,15 @@ bool PackagesManager::targetPackageCanReplace(QApt::Package *targetPackage, QApt } } #else - auto targetProvides = targetPackage->providesList().toSet(); - auto installedProvides = installedPackage->providesList().toSet(); + auto providList = targetPackage->providesList(); + auto installList = installedPackage->providesList(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + auto targetProvides = providList.toSet(); + auto installedProvides = installList.toSet(); +#else + QSet targetProvides(providList.begin(), providList.end()); + QSet installedProvides(installList.begin(), installList.end()); +#endif QSet canReplaceProvides = targetProvides.unite(installedProvides); #endif // ENABLE_VIRTUAL_PACKAGE_ENHANCE @@ -1092,7 +1105,7 @@ void PackagesManager::getPackageOrDepends(const QString &package, const QString // 使用二维数组进行存储 for (QString depend : dependsList) { - depend = depend.remove(QRegExp("\\s")); + depend = depend.remove(REG_EXP("\\s")); // 非或包,判断虚包依赖 if (!depend.contains("|")) { @@ -1184,7 +1197,7 @@ QStringList PackagesManager::debFileAvailableDepends(const QString &filePath) packageCandidateChoose(choose_set, debArch, depends, levelInfo); // TODO: check upgrade from conflicts - return choose_set.toList(); + return choose_set.values(); } void PackagesManager::packageCandidateChoose(QSet &choosed_set, @@ -1346,7 +1359,7 @@ const QStringList PackagesManager::packageReverseDependsList(const QString &pack // 存放当前需要验证反向依赖的包 QQueue reverseQueue; - for (const auto &requiredPackage : requiredList.toSet()) + for (const auto &requiredPackage : requiredList) reverseQueue.append(requiredPackage); while (!reverseQueue.isEmpty()) { const auto item = reverseQueue.first(); @@ -1413,7 +1426,7 @@ const QStringList PackagesManager::packageReverseDependsList(const QString &pack // remove self reverseDependSet.remove(packageName); - return reverseDependSet.toList(); + return reverseDependSet.values(); } bool PackagesManager::isNegativeReverseDepend(const QString &packageName, const QApt::Package *reverseDepend) @@ -1771,7 +1784,6 @@ QList PackagesManager::getAllDepends(const QList &depen m_allDependsList << info.packageName() << dList; // 存储所有依赖 } } - m_allDependsList = m_allDependsList.toSet().values(); return m_allDependsList; } @@ -2151,7 +2163,7 @@ bool PackagesManager::checkPackageArchValid(const QApt::Package *package, const // providesList 列表中含当前包名的则认为满足多架构支持 // i386 包一般不提供 amd64 架构支持,而 amd64 经常提供 i386 QString findPackage = packageName; - findPackage.remove(QRegExp(":[^:]*$")); + findPackage.remove(REG_EXP(":[^:]*$")); #endif // 查找当前软件包支持的包名中是否包含对应架构软件包 diff --git a/src/deb-installer/manager/packagesmanager.h b/src/deb-installer/manager/packagesmanager.h index 754d31b7..12424d67 100644 --- a/src/deb-installer/manager/packagesmanager.h +++ b/src/deb-installer/manager/packagesmanager.h @@ -284,7 +284,7 @@ public slots: const PackageDependsStatus checkDependsPackageStatus(QSet &choosed_set, const QString &architecture, const QApt::DependencyInfo &dependencyInfo, - const QString &providesName = QString::null); + const QString &providesName = QString()); /** * @brief packageCandidateChoose 查找包的依赖候选 * @param choosed_set 包的依赖候选的集合 diff --git a/src/deb-installer/model/deblistmodel.cpp b/src/deb-installer/model/deblistmodel.cpp index f91cb7ec..09c1124d 100644 --- a/src/deb-installer/model/deblistmodel.cpp +++ b/src/deb-installer/model/deblistmodel.cpp @@ -16,6 +16,7 @@ #include "compatible/compatible_process_controller.h" #include "immutable/immutable_backend.h" #include "immutable/immutable_process_controller.h" +#include "utils/qtcompat.h" #include #include @@ -158,7 +159,7 @@ void DebListModel::initInstallConnections() // 配置安装结束 connect(m_procInstallConfig, - static_cast(&QProcess::finished), + QOverload::of(&QProcess::finished), this, &DebListModel::slotConfigInstallFinish); @@ -1241,10 +1242,17 @@ void DebListModel::slotShowDevelopModeWindow() unlock->waitForFinished(); auto output = unlock->readAllStandardOutput(); auto str = QString::fromUtf8(output); - QRegExp re("\t.+\n"); + REG_EXP re("\t.+\n"); QString osVerStr; + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (re.indexIn(str) > -1) { auto result = re.cap(0); +#else + QRegularExpressionMatch match = re.match(str); + if (match.hasMatch()) { + auto result = match.captured(0); +#endif osVerStr = result.remove(0, 1).remove(result.size() - 1, 1); qInfo() << "lsb_release -r:" << output; qInfo() << "OS version:" << osVerStr; diff --git a/src/deb-installer/model/packageselectmodel.cpp b/src/deb-installer/model/packageselectmodel.cpp index 33de3af8..fc4d0c30 100644 --- a/src/deb-installer/model/packageselectmodel.cpp +++ b/src/deb-installer/model/packageselectmodel.cpp @@ -129,7 +129,17 @@ bool PackageSelectModel::collectData() getDebIrs(&dependInfos, &md5s, ddimIrs, [](const DdimIrPackage &info) { return info.dependInfos; }); // 3.查看是否存在改变 - bool ret = !(newSelectInfos == selectInfos); + bool ret = false; + if (newSelectInfos.size() != selectInfos.size()) { + ret = true; + } else { + for (int i = 0; i < newSelectInfos.size(); ++i) { + if (!(newSelectInfos[i] == selectInfos[i])) { + ret = true; + break; + } + } + } // 4.清理老数据 selectInfos = newSelectInfos; diff --git a/src/deb-installer/model/packageslistdelegate.cpp b/src/deb-installer/model/packageslistdelegate.cpp index 72adde85..a667405e 100644 --- a/src/deb-installer/model/packageslistdelegate.cpp +++ b/src/deb-installer/model/packageslistdelegate.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include DWIDGET_USE_NAMESPACE @@ -36,7 +36,7 @@ void PackagesListDelegate::refreshDebItemStatus( { DPalette parentViewPattle = DebApplicationHelper::instance()->palette(m_parentView); - DApplicationHelper *dAppHelper = DApplicationHelper::instance(); + DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette appPalette = dAppHelper->applicationPalette(); QPen forground; // 前景色 @@ -96,7 +96,7 @@ void PackagesListDelegate::paint(QPainter *painter, const QStyleOptionViewItem & bgPath.addRect(option.rect); // 将当前Item的位置参数 发送给ListView,确定右键菜单的位置。 emit sigIndexAndRect(option.rect, index.row()); - DApplicationHelper *dAppHelper = DApplicationHelper::instance(); + DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette palette = dAppHelper->applicationPalette(); QBrush background; QPen forground; diff --git a/src/deb-installer/process/Pty.cpp b/src/deb-installer/process/Pty.cpp index 75d08d75..357b6ebb 100644 --- a/src/deb-installer/process/Pty.cpp +++ b/src/deb-installer/process/Pty.cpp @@ -45,9 +45,16 @@ #include #include #include -#include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#include +#else +#include +#include +#endif + using namespace Konsole; @@ -293,9 +300,14 @@ bool isPatternAcceptable(QString strCommand, QString strPattern) { QString strTrimmedCmd = strCommand.trimmed(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QRegularExpression cmdRegExp(strPattern); + QRegularExpressionValidator cmdREValidator(cmdRegExp, nullptr); +#else QRegExp cmdRegExp; cmdRegExp.setPattern(strPattern); QRegExpValidator cmdREValidator(cmdRegExp, nullptr); +#endif int pos = 0; QValidator::State validateState = cmdREValidator.validate(strTrimmedCmd, pos); @@ -579,6 +591,7 @@ void Pty::setSessionId(int sessionId) _sessionId = sessionId; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void Pty::setupChildProcess() { KPtyProcess::setupChildProcess(); @@ -599,3 +612,4 @@ void Pty::setupChildProcess() } sigprocmask(SIG_UNBLOCK, &sigset, nullptr); } +#endif diff --git a/src/deb-installer/process/Pty.h b/src/deb-installer/process/Pty.h index 511c43fc..2baddca7 100644 --- a/src/deb-installer/process/Pty.h +++ b/src/deb-installer/process/Pty.h @@ -36,6 +36,7 @@ #include #include #include +#include // KDE #include "kptyprocess.h" @@ -195,7 +196,9 @@ Q_OBJECT /******** Modify by nt001000 renfeixiang 2020-05-14:修改 增加参数区别remove和purge卸载命令 End***************/ protected: + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void setupChildProcess() override; + #endif private slots: // called when data is received from the terminal process diff --git a/src/deb-installer/process/kprocess.cpp b/src/deb-installer/process/kprocess.cpp index 6df56679..98057665 100644 --- a/src/deb-installer/process/kprocess.cpp +++ b/src/deb-installer/process/kprocess.cpp @@ -404,7 +404,11 @@ int KProcess::startDetached(const QStringList &argv) int KProcess::pid() const { #ifdef Q_OS_UNIX +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return (int) QProcess::pid(); +#else + return QProcess::processId(); +#endif #else return QProcess::pid() ? QProcess::pid()->dwProcessId : 0; #endif diff --git a/src/deb-installer/process/kprocess.h b/src/deb-installer/process/kprocess.h index 9b22318f..aa69f329 100644 --- a/src/deb-installer/process/kprocess.h +++ b/src/deb-installer/process/kprocess.h @@ -336,8 +336,10 @@ class KProcess : public QProcess private: // hide those +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) using QProcess::setReadChannelMode; using QProcess::readChannelMode; +#endif using QProcess::setProcessChannelMode; using QProcess::processChannelMode; diff --git a/src/deb-installer/process/kpty.cpp b/src/deb-installer/process/kpty.cpp index d0155408..42ce3aa0 100644 --- a/src/deb-installer/process/kpty.cpp +++ b/src/deb-installer/process/kpty.cpp @@ -338,7 +338,7 @@ bool KPty::open() !d->chownpty(true)) { qWarning() << "chownpty failed for device " << ptyName << "::" << d->ttyName - << "\nThis means the communication can be eavesdropped." << endl; + << "\nThis means the communication can be eavesdropped."; } #if defined (HAVE__GETPTY) || defined (HAVE_GRANTPT) diff --git a/src/deb-installer/process/kptyprocess.cpp b/src/deb-installer/process/kptyprocess.cpp index b61fd53a..1f750d0e 100644 --- a/src/deb-installer/process/kptyprocess.cpp +++ b/src/deb-installer/process/kptyprocess.cpp @@ -119,6 +119,7 @@ KPtyDevice *KPtyProcess::pty() const return d->pty; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void KPtyProcess::setupChildProcess() { Q_D(KPtyProcess); @@ -140,5 +141,6 @@ void KPtyProcess::setupChildProcess() KProcess::setupChildProcess(); } +#endif //#include "kptyprocess.moc" diff --git a/src/deb-installer/process/kptyprocess.h b/src/deb-installer/process/kptyprocess.h index ae1166e6..d18ef4c1 100644 --- a/src/deb-installer/process/kptyprocess.h +++ b/src/deb-installer/process/kptyprocess.h @@ -144,7 +144,9 @@ class KPtyProcess : public KProcess /** * @reimp */ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void setupChildProcess() override; +#endif private: Q_PRIVATE_SLOT(d_func(), void _k_onStateChanged(QProcess::ProcessState)) diff --git a/src/deb-installer/utils/hierarchicalverify.cpp b/src/deb-installer/utils/hierarchicalverify.cpp index ae9a5070..a1e9b6a5 100644 --- a/src/deb-installer/utils/hierarchicalverify.cpp +++ b/src/deb-installer/utils/hierarchicalverify.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "hierarchicalverify.h" +#include "utils/qtcompat.h" #include @@ -81,7 +82,7 @@ bool HierarchicalVerify::isValid() */ bool HierarchicalVerify::checkTransactionError(const QString &pkgName, const QString &errorString) { - static QRegExp s_ErrorReg(QString(VERIFY_ERROR_REGEXP).arg(VerifyError).arg(VerffyErrorVer2)); + static REG_EXP s_ErrorReg(QString(VERIFY_ERROR_REGEXP).arg(VerifyError).arg(VerffyErrorVer2)); if (errorString.contains(s_ErrorReg)) { invalidPackages.insert(pkgName); qWarning() << QString("[Hierarchical] Package %1 detected hierarchical error!").arg(pkgName); diff --git a/src/deb-installer/utils/qtcompat.h b/src/deb-installer/utils/qtcompat.h new file mode 100644 index 00000000..9109e399 --- /dev/null +++ b/src/deb-installer/utils/qtcompat.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef QTCOMPAT_H +#define QTCOMPAT_H + +#include + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#include +class QEnterEvent; + +#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts +#define SPLIT_BH Qt::SplitBehavior +#define ENDL Qt::endl +#define REG_EXP QRegularExpression +#define REG_EXPV QRegularExpressionValidator +#define DATE_FOTIME QDateTime::fromSecsSinceEpoch +#define DATE_TOTIME QDateTime::toSecsSinceEpoch + +using EnterEvent = QEnterEvent; + +#else // QT_VERSION < 6.0.0 + +#include +class QEvent; + +#define SKIP_EMPTY_PARTS QString::SkipEmptyParts +#define SPLIT_BH QString::SplitBehavior +#define ENDL endl +#define REG_EXP QRegExp +#define REG_EXPV QRegExpValidator +#define DATE_FOTIME QDateTime::fromTime_t +#define DATE_TOTIME QDateTime::toTime_t + +using EnterEvent = QEvent; + +#endif + +#endif // QTCOMPAT_H diff --git a/src/deb-installer/utils/utils.cpp b/src/deb-installer/utils/utils.cpp index 17d8ab92..2ab1a437 100644 --- a/src/deb-installer/utils/utils.cpp +++ b/src/deb-installer/utils/utils.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "utils.h" +#include "qtcompat.h" #include @@ -35,6 +36,8 @@ #include +DWIDGET_USE_NAMESPACE + QHash Utils::m_imgCacheHash; QHash Utils::m_fontNameCache; @@ -55,7 +58,7 @@ QFont Utils::loadFontBySizeAndWeight(const QString &fontFamily, int fontSize, in Q_UNUSED(fontSize) QFont font(fontFamily); - font.setWeight(fontWeight); + font.setWeight((QFont::Weight)fontWeight); return font; } @@ -107,7 +110,7 @@ void Utils::bindFontBySizeAndWeight(QWidget *widget, const QString &fontFamily, QString Utils::fromSpecialEncoding(const QString &inputStr) { - bool bFlag = inputStr.contains(QRegExp("[\\x4e00-\\x9fa5]+")); + bool bFlag = inputStr.contains(REG_EXP("[\\x4e00-\\x9fa5]+")); if (bFlag) { return inputStr; } @@ -179,7 +182,7 @@ Utils::VerifyResultCode Utils::Digital_Verify(const QString &filepath_name) QString Utils::holdTextInRect(const QFont &font, const QString &srcText, const QSize &size) { - bool bContainsChinese = srcText.contains(QRegExp("[\\x4e00-\\x9fa5]+")); + bool bContainsChinese = srcText.contains(REG_EXP("[\\x4e00-\\x9fa5]+")); QString text; QString tempText; @@ -244,7 +247,7 @@ QString Utils::holdTextInRect(const QFont &font, const QString &srcText, const Q QString Utils::holdTextInRect(const QFont &font, const QString &srcText, const int &width) { - bool bContainsChinese = srcText.contains(QRegExp("[\\x4e00-\\x9fa5]+")); + bool bContainsChinese = srcText.contains(REG_EXP("[\\x4e00-\\x9fa5]+")); QString text; QString tempText; diff --git a/src/deb-installer/utils/utils.h b/src/deb-installer/utils/utils.h index 3dc999ee..6f72dc50 100644 --- a/src/deb-installer/utils/utils.h +++ b/src/deb-installer/utils/utils.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ class QTextDocumnet; -DWIDGET_USE_NAMESPACE +DGUI_USE_NAMESPACE class DebApplicationHelper : public DGuiApplicationHelper { diff --git a/src/deb-installer/view/pages/AptConfigMessage.cpp b/src/deb-installer/view/pages/AptConfigMessage.cpp index 3d35bc3b..6b146b82 100644 --- a/src/deb-installer/view/pages/AptConfigMessage.cpp +++ b/src/deb-installer/view/pages/AptConfigMessage.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/src/deb-installer/view/pages/debinstaller.cpp b/src/deb-installer/view/pages/debinstaller.cpp index b53c11f6..bc55aebf 100644 --- a/src/deb-installer/view/pages/debinstaller.cpp +++ b/src/deb-installer/view/pages/debinstaller.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include diff --git a/src/deb-installer/view/pages/singleinstallpage.cpp b/src/deb-installer/view/pages/singleinstallpage.cpp index ee7ce933..337bc628 100644 --- a/src/deb-installer/view/pages/singleinstallpage.cpp +++ b/src/deb-installer/view/pages/singleinstallpage.cpp @@ -20,7 +20,8 @@ #include #include -#include +#include +#include using QApt::DebFile; using QApt::Transaction; @@ -1125,7 +1126,7 @@ void SingleInstallPage::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); - DPalette palette = DApplicationHelper::instance()->palette(m_packageDescription); + DPalette palette = DPaletteHelper::instance()->palette(m_packageDescription); palette.setBrush(DPalette::WindowText, palette.color(DPalette::TextTips)); m_packageDescription->setPalette(palette); } diff --git a/src/deb-installer/view/widgets/choosefilebutton.cpp b/src/deb-installer/view/widgets/choosefilebutton.cpp index 67b2cc98..5549bb04 100644 --- a/src/deb-installer/view/widgets/choosefilebutton.cpp +++ b/src/deb-installer/view/widgets/choosefilebutton.cpp @@ -5,7 +5,7 @@ #include "choosefilebutton.h" #include "utils/utils.h" -#include +#include #include diff --git a/src/deb-installer/view/widgets/coloredprogressbar.cpp b/src/deb-installer/view/widgets/coloredprogressbar.cpp index dff64137..7d674b66 100644 --- a/src/deb-installer/view/widgets/coloredprogressbar.cpp +++ b/src/deb-installer/view/widgets/coloredprogressbar.cpp @@ -77,7 +77,11 @@ void ColoredProgressBar::paintEvent(QPaintEvent *event) painter.drawControl(QStyle::ControlElement::CE_ProgressBarGroove, styopt); painter.drawControl(QStyle::ControlElement::CE_ProgressBarContents, styopt); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (styopt.textVisible && styopt.orientation == Qt::Horizontal) { +#else + if (styopt.textVisible && (styopt.direction == Qt::LeftToRight || styopt.direction == Qt::RightToLeft)) { +#endif painter.drawControl(QStyle::ControlElement::CE_ProgressBarLabel, styopt); } } else { diff --git a/src/deb-installer/view/widgets/debinfolabel.cpp b/src/deb-installer/view/widgets/debinfolabel.cpp index b95d8971..b28a563d 100644 --- a/src/deb-installer/view/widgets/debinfolabel.cpp +++ b/src/deb-installer/view/widgets/debinfolabel.cpp @@ -8,6 +8,8 @@ #include #include +#include + DebInfoLabel::DebInfoLabel(QWidget *parent, Qt::WindowFlags windowFlags) : DLabel(parent, windowFlags) , m_colorRole(QPalette::NoRole) @@ -24,10 +26,10 @@ void DebInfoLabel::setCustomQPalette(QPalette::ColorRole colorRole) m_colorRole = colorRole; // 获取当前使用QPalette的字体颜色角色 m_bUserColorType = false; // 当前使用的不是DPalette - // 判断传入的QPalette是否是WindowText 如果是则设置当前Label的Palette的画刷为DApplicationHelper画刷,颜色为WindowText + // 判断传入的QPalette是否是WindowText 如果是则设置当前Label的Palette的画刷为DGuiApplicationHelper画刷,颜色为WindowText // 否则设置当前的Label的Palette的画刷为DebApplicationHelperr画刷,颜色为传入的颜色 if (m_colorRole == QPalette::WindowText) { - DPalette palette = DApplicationHelper::instance()->palette(this); + DPalette palette = DPaletteHelper::instance()->palette(this); palette.setBrush(QPalette::Text, palette.color(QPalette::WindowText)); this->setPalette(palette); } else { @@ -54,8 +56,8 @@ void DebInfoLabel::setCustomDPalette() m_bMultiIns = true; // 当前使用的是默认的颜色 m_bUserColorType = true; // 当前是用的是DPalette - // 设置当前的Label的Palette的画刷为DApplicationHelper画刷,颜色为默认的颜色 - DPalette palette = DApplicationHelper::instance()->palette(this); + // 设置当前的Label的Palette的画刷为DGuiApplicationHelper画刷,颜色为默认的颜色 + DPalette palette = DPaletteHelper::instance()->palette(this); palette.setBrush(DPalette::WindowText, QColor(00, 130, 252)); this->setPalette(palette); } diff --git a/src/deb-installer/view/widgets/droundbgframe.cpp b/src/deb-installer/view/widgets/droundbgframe.cpp index 1d68ea08..f41d593c 100644 --- a/src/deb-installer/view/widgets/droundbgframe.cpp +++ b/src/deb-installer/view/widgets/droundbgframe.cpp @@ -6,7 +6,7 @@ #include "utils/utils.h" #include -#include +#include #include #include diff --git a/src/deb-installer/view/widgets/filechoosewidget.cpp b/src/deb-installer/view/widgets/filechoosewidget.cpp index cb2321c3..c00efcb9 100644 --- a/src/deb-installer/view/widgets/filechoosewidget.cpp +++ b/src/deb-installer/view/widgets/filechoosewidget.cpp @@ -17,7 +17,8 @@ #include #include #include -#include +#include +#include #include #include @@ -50,7 +51,7 @@ FileChooseWidget::FileChooseWidget(QWidget *parent) m_dndTips->setObjectName("DNDTips"); // 修改字体颜色 - palette = DApplicationHelper::instance()->palette(m_dndTips); + palette = DPaletteHelper::instance()->palette(m_dndTips); palette.setBrush(DPalette::WindowText, palette.color(DPalette::TextTips)); m_dndTips->setPalette(palette); @@ -180,7 +181,7 @@ void FileChooseWidget::themeChanged() split_line->setPixmap(icon_split_line.pixmap(QSize(220, 3))); // change tips color when theme changed - auto palette = DApplicationHelper::instance()->palette(m_dndTips); + auto palette = DPaletteHelper::instance()->palette(m_dndTips); palette.setBrush(DPalette::WindowText, palette.color(DPalette::TextTips)); m_dndTips->setPalette(palette); } diff --git a/src/deb-installer/view/widgets/infocontrolbutton.cpp b/src/deb-installer/view/widgets/infocontrolbutton.cpp index e66b9e17..ce0e3bba 100644 --- a/src/deb-installer/view/widgets/infocontrolbutton.cpp +++ b/src/deb-installer/view/widgets/infocontrolbutton.cpp @@ -7,7 +7,7 @@ #include "utils/utils.h" #include -#include +#include #include #include diff --git a/src/deb-installer/view/widgets/installprocessinfoview.cpp b/src/deb-installer/view/widgets/installprocessinfoview.cpp index cdcea0fe..b40abe59 100644 --- a/src/deb-installer/view/widgets/installprocessinfoview.cpp +++ b/src/deb-installer/view/widgets/installprocessinfoview.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include InstallProcessInfoView::InstallProcessInfoView(int w, int h, QWidget *parent) : QWidget(parent) @@ -63,7 +63,7 @@ void InstallProcessInfoView::initUI(int w, int h) // 设置只读,不允许对其进行修改 m_editor->setReadOnly(true); m_editor->setFrameShape(QFrame::NoFrame); // 设置frame类型为noframe - m_editor->viewport()->setBackgroundRole(QPalette::Background); // 设置内容的背景色 + m_editor->viewport()->setBackgroundRole(QPalette::Window); // 设置内容的背景色 m_editor->viewport()->setAutoFillBackground(false); QTextCursor textCursor = m_editor->textCursor(); // 获取游标 diff --git a/src/deb-installer/view/widgets/packageselectitem.cpp b/src/deb-installer/view/widgets/packageselectitem.cpp index a7862ee2..9681486f 100644 --- a/src/deb-installer/view/widgets/packageselectitem.cpp +++ b/src/deb-installer/view/widgets/packageselectitem.cpp @@ -40,7 +40,7 @@ PackageSelectItem::PackageSelectItem(QWidget *parent) infoLayout->addWidget(line); auto allLayout = new QHBoxLayout; - allLayout->setMargin(0); + allLayout->setContentsMargins(0, 0, 0, 0); allLayout->addWidget(checkBox); allLayout->addLayout(infoLayout); diff --git a/src/deepin-deb-installer-dev/CMakeLists.txt b/src/deepin-deb-installer-dev/CMakeLists.txt index b6041b3b..a530ef2e 100644 --- a/src/deepin-deb-installer-dev/CMakeLists.txt +++ b/src/deepin-deb-installer-dev/CMakeLists.txt @@ -18,16 +18,22 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") find_package(PkgConfig REQUIRED) -find_package(Qt5Core REQUIRED) -find_package(Qt5Concurrent REQUIRED) -find_package(Qt5DBus REQUIRED) + +set(qt_required_components Core DBus Concurrent) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) set(LINK_LIBS - Qt5::Core - Qt5::DBus + Qt${QT_DESIRED_VERSION}::Core + Qt${QT_DESIRED_VERSION}::DBus + Qt${QT_DESIRED_VERSION}::Concurrent QApt - Qt5::Concurrent ) + include_directories(${CMAKE_CURRENT_LIST_DIR}) file(GLOB_RECURSE APP_SRCS ${CMAKE_CURRENT_LIST_DIR}/*.cpp @@ -46,10 +52,9 @@ add_library( ${APP_BIN_NAME} SHARED ${APP_SRCS}) # Find the library target_link_libraries(${APP_BIN_NAME} - Qt5::Core - Qt5::DBus + PRIVATE + ${LINK_LIBS} QApt - Qt5::Concurrent ) set(CMAKE_INSTALL_PREFIX /usr) diff --git a/src/deepin-deb-installer-dev/status/PackageStatus.cpp b/src/deepin-deb-installer-dev/status/PackageStatus.cpp index b156db40..7d8376fc 100644 --- a/src/deepin-deb-installer-dev/status/PackageStatus.cpp +++ b/src/deepin-deb-installer-dev/status/PackageStatus.cpp @@ -645,7 +645,7 @@ const QStringList PackageStatus::getPackageReverseDependsList(const QString &pac QSet ret{packageName}; QQueue testQueue; - for (const auto &item : package->requiredByList().toSet()) + for (const auto &item : package->requiredByList()) testQueue.append(item); while (!testQueue.isEmpty()) { const auto item = testQueue.first(); @@ -706,7 +706,7 @@ const QStringList PackageStatus::getPackageReverseDependsList(const QString &pac // remove self ret.remove(packageName); - return ret.toList(); + return ret.values(); } PackageStatus::~PackageStatus() {} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae1d96bc..485f4b09 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,6 @@ include_directories(${GTEST_INCLUDE_DIRS}) # common resource names set(APP_RES_DIR "${CMAKE_SOURCE_DIR}/assets") set(APP_BIN_NAME_TEST "deepin-deb-installer-test") -set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh") set(APP_DESKTOP "${APP_RES_DIR}/deepin-deb-installer.desktop") set(APP_QRC "${APP_RES_DIR}/resources.qrc") @@ -75,9 +74,6 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage") -# Generate the qm file -execute_process(COMMAND bash ${APP_TRANS_SCRIPT} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") configure_file(${APP_RES_DIR}/environments.h.in environments.h @ONLY) @@ -85,30 +81,34 @@ add_definitions(-DUSE_POLKIT -DENABLE_INACTIVE_DISPLAY) # Find the library find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Core REQUIRED) -find_package(Qt5LinguistTools REQUIRED) -find_package(Qt5Concurrent REQUIRED) -find_package(DtkWidget REQUIRED) -find_package(DtkGui REQUIRED) -find_package(DtkCore REQUIRED) -find_package(Qt5DBus REQUIRED) -find_package(Qt5Test REQUIRED) -find_package(PolkitQt5-1 REQUIRED) + +find_package(PolkitQt${QT_DESIRED_VERSION}-1) +set(qt_required_components Core DBus Gui Widgets Concurrent Test) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) +find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Core Gui Widget REQUIRED) set(LINK_LIBS - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::DBus - QApt - Qt5::Concurrent - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} - ${DtkGUI_LIBRARIES} + Qt${QT_DESIRED_VERSION}::Core + Qt${QT_DESIRED_VERSION}::DBus + Qt${QT_DESIRED_VERSION}::Gui + Qt${QT_DESIRED_VERSION}::Widgets + Qt${QT_DESIRED_VERSION}::Concurrent + Qt${QT_DESIRED_VERSION}::Test + Dtk${DTK_VERSION_MAJOR}::Widget + Dtk${DTK_VERSION_MAJOR}::Core + Dtk${DTK_VERSION_MAJOR}::Gui + PolkitQt${QT_DESIRED_VERSION}-1::Agent ) +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat) +endif() + macro(SUBDIRLIST result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) set(dirlist "") @@ -154,26 +154,15 @@ FILE(GLOB allTestSource ) include_directories(src) include_directories(${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/) -include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) # Tell CMake to create the executable add_executable(${APP_BIN_NAME_TEST} ${APP_SRCS} ${APP_QRC} ${TEST_ACCESSIBLE_HEADERS_FILES} ${allTestSource}) -target_include_directories(${APP_BIN_NAME_TEST} - PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR}) target_link_libraries(${APP_BIN_NAME_TEST} - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::DBus + PUBLIC + ${LINK_LIBS} QApt - PolkitQt5-1::Agent - Qt5::Test - Qt5::Concurrent - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} - ${DtkGUI_LIBRARIES} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread diff --git a/tests/src/model/ut_deblistmodel.cpp b/tests/src/model/ut_deblistmodel.cpp index 9ca2d46c..28949065 100644 --- a/tests/src/model/ut_deblistmodel.cpp +++ b/tests/src/model/ut_deblistmodel.cpp @@ -379,7 +379,9 @@ void ut_DebListModel_test::stubFunction() stub.set(ADDR(Transaction, isCancellable), model_transaction_isCancellable); stub.set(ADDR(Transaction, isCancelled), model_transaction_isCancelled); stub.set(ADDR(Transaction, errorDetails), model_transaction_errorDetails); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) stub.set(ADDR(Transaction, setProperty), model_transaction_setProperty); +#endif stub.set(ADDR(Transaction, exitStatus), model_transaction_exitStatus); stub.set(ADDR(DebFile, architecture), model_deb_arch_i386); @@ -1185,9 +1187,15 @@ TEST_F(ut_DebListModel_test, deblistmodel_UT_initInstallConnections) m_debListModel->initInstallConnections(); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#define FILE_LINK readLink +#else +#define FILE_LINK symLinkTarget +#endif + TEST_F(ut_DebListModel_test, deblistmodel_UT_recheckPackagePath_readRealPathExist) { - stub.set((QString(QFile::*)(void) const)ADDR(QFile, readLink), stub_readLink_empty); + stub.set((QString(QFile::*)(void) const)ADDR(QFile, FILE_LINK), stub_readLink_empty); stub.set((bool(QFile::*)(void) const)ADDR(QFile, exists), stub_exists_true); ASSERT_TRUE(m_debListModel->recheckPackagePath("/0")); @@ -1195,7 +1203,7 @@ TEST_F(ut_DebListModel_test, deblistmodel_UT_recheckPackagePath_readRealPathExis TEST_F(ut_DebListModel_test, deblistmodel_UT_recheckPackagePath_readLinkPathExist) { - stub.set((QString(QFile::*)(void) const)ADDR(QFile, readLink), stub_readLink); + stub.set((QString(QFile::*)(void) const)ADDR(QFile, FILE_LINK), stub_readLink); stub.set((bool(QFile::*)(void) const)ADDR(QFile, exists), stub_exists_true); ASSERT_TRUE(m_debListModel->recheckPackagePath("/0")); @@ -1203,7 +1211,7 @@ TEST_F(ut_DebListModel_test, deblistmodel_UT_recheckPackagePath_readLinkPathExis TEST_F(ut_DebListModel_test, deblistmodel_UT_recheckPackagePath_readLinkPathNotExist) { - stub.set((QString(QFile::*)(void) const)ADDR(QFile, readLink), stub_readLink); + stub.set((QString(QFile::*)(void) const)ADDR(QFile, FILE_LINK), stub_readLink); stub.set((bool(QFile::*)(void) const)ADDR(QFile, exists), stub_exists_false); ASSERT_FALSE(m_debListModel->recheckPackagePath("/0")); diff --git a/tests/src/ut_singleInstallerApplication.cpp b/tests/src/ut_singleInstallerApplication.cpp index ec5dc9b3..fd511524 100644 --- a/tests/src/ut_singleInstallerApplication.cpp +++ b/tests/src/ut_singleInstallerApplication.cpp @@ -30,8 +30,8 @@ class SingleInstallerApplication_UT : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { int a = 1; @@ -41,7 +41,7 @@ class SingleInstallerApplication_UT : public UT_HEAD char *pArgv[] = {argv, argv1}; singleInstaller = new SingleInstallerApplication(argc, pArgv); usleep(100 * 1000); - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/utils/ut_utils.cpp b/tests/src/utils/ut_utils.cpp index bbbbefaf..094bb44c 100644 --- a/tests/src/utils/ut_utils.cpp +++ b/tests/src/utils/ut_utils.cpp @@ -236,7 +236,9 @@ TEST(Utils_Test, Utils_UT_setPalette) { Stub stub; stub.set(ADDR(QWidget, setPalette), util_setPalette); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) stub.set(ADDR(QWidget, setProperty), util_setProperty); +#endif DebApplicationHelper *helper = DebApplicationHelper::instance(); QWidget *w = nullptr; @@ -250,7 +252,9 @@ void util_setAttribute(Qt::WidgetAttribute, bool) TEST(Utils_Test, Utils_UT_resetPalette) { Stub stub; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) stub.set(ADDR(QWidget, setProperty), util_setProperty); +#endif stub.set(ADDR(QWidget, setAttribute), util_setAttribute); DebApplicationHelper *helper = DebApplicationHelper::instance(); diff --git a/tests/src/view/pages/ut_AptConfigMessage.cpp b/tests/src/view/pages/ut_AptConfigMessage.cpp index 83c0e8e5..06c99d43 100644 --- a/tests/src/view/pages/ut_AptConfigMessage.cpp +++ b/tests/src/view/pages/ut_AptConfigMessage.cpp @@ -15,13 +15,13 @@ class AptConfigMessage_UT : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { aptConfig = new AptConfigMessage(); usleep(100 * 1000); - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/pages/ut_debinstaller.cpp b/tests/src/view/pages/ut_debinstaller.cpp index d3eb144b..10fad23c 100644 --- a/tests/src/view/pages/ut_debinstaller.cpp +++ b/tests/src/view/pages/ut_debinstaller.cpp @@ -110,8 +110,8 @@ class UT_Debinstaller : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { Stub stub; @@ -122,7 +122,7 @@ class UT_Debinstaller : public UT_HEAD debListModel = qobject_cast(proxyModel->modelFromType(Pkg::Deb)); usleep(1000 * 1000); - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/pages/ut_multipleinstallpage.cpp b/tests/src/view/pages/ut_multipleinstallpage.cpp index b2456c34..ca4d4c9b 100644 --- a/tests/src/view/pages/ut_multipleinstallpage.cpp +++ b/tests/src/view/pages/ut_multipleinstallpage.cpp @@ -33,8 +33,8 @@ class UT_MultipleInstallPage : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { Stub stub; @@ -43,7 +43,7 @@ class UT_MultipleInstallPage : public UT_HEAD usleep(100 * 1000); multiplepage = new MultipleInstallPage(debListModel); usleep(100 * 1000); - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/pages/ut_singleinstallpage.cpp b/tests/src/view/pages/ut_singleinstallpage.cpp index 046d1806..a94e8f0c 100644 --- a/tests/src/view/pages/ut_singleinstallpage.cpp +++ b/tests/src/view/pages/ut_singleinstallpage.cpp @@ -100,11 +100,11 @@ class UT_SingleInstallpage : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/pages/ut_uninstallconfirmpage.cpp b/tests/src/view/pages/ut_uninstallconfirmpage.cpp index d4bd6b15..a6bac1b4 100644 --- a/tests/src/view/pages/ut_uninstallconfirmpage.cpp +++ b/tests/src/view/pages/ut_uninstallconfirmpage.cpp @@ -23,13 +23,13 @@ class UnInstallConfirmPage_UT : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { uninstallPage = new UninstallConfirmPage(); usleep(100 * 1000); - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/widgets/ut_coloredprogressbar.cpp b/tests/src/view/widgets/ut_coloredprogressbar.cpp index 7dec027f..3620b9fe 100644 --- a/tests/src/view/widgets/ut_coloredprogressbar.cpp +++ b/tests/src/view/widgets/ut_coloredprogressbar.cpp @@ -29,20 +29,20 @@ class ut_coloredProgressBar_Test : public ::testing::Test ColoredProgressBar *m_colorProcessBar = nullptr; }; -DApplicationHelper::ColorType ut_themeType() +DGuiApplicationHelper::ColorType ut_themeType() { - return DApplicationHelper::DarkType; + return DGuiApplicationHelper::DarkType; } -DApplicationHelper::ColorType ut_themeType01() +DGuiApplicationHelper::ColorType ut_themeType01() { - return DApplicationHelper::LightType; + return DGuiApplicationHelper::LightType; } TEST_F(ut_coloredProgressBar_Test, ColoredProgressBar_UT_themeChanged) { Stub stub; - stub.set(ADDR(DApplicationHelper, themeType), ut_themeType01); + stub.set(ADDR(DGuiApplicationHelper, themeType), ut_themeType01); m_colorProcessBar->themeChanged(); ASSERT_EQ(DGuiApplicationHelper::LightType, m_colorProcessBar->m_themeType); // m_colorProcessBar->d_d_ptr.get() @@ -51,7 +51,7 @@ TEST_F(ut_coloredProgressBar_Test, ColoredProgressBar_UT_themeChanged) TEST_F(ut_coloredProgressBar_Test, ColoredProgressBar_UT_themeChanged_01) { Stub stub; - stub.set(ADDR(DApplicationHelper, themeType), ut_themeType); + stub.set(ADDR(DGuiApplicationHelper, themeType), ut_themeType); m_colorProcessBar->themeChanged(); ASSERT_EQ(DGuiApplicationHelper::DarkType, m_colorProcessBar->m_themeType); } diff --git a/tests/src/view/widgets/ut_droundbgframe.cpp b/tests/src/view/widgets/ut_droundbgframe.cpp index 62a1ed2a..913c3e56 100644 --- a/tests/src/view/widgets/ut_droundbgframe.cpp +++ b/tests/src/view/widgets/ut_droundbgframe.cpp @@ -16,11 +16,11 @@ class DRoundBgFrame_UT : public UT_HEAD { public: // 添加日志 - static void SetUpTestCase() { qDebug() << "SetUpTestCase" << endl; } - static void TearDownTestCase() { qDebug() << "TearDownTestCase" << endl; } + static void SetUpTestCase() { qDebug() << "SetUpTestCase"; } + static void TearDownTestCase() { qDebug() << "TearDownTestCase"; } void SetUp() // TEST跑之前会执行SetUp { - qDebug() << "SetUp" << endl; + qDebug() << "SetUp"; } void TearDown() // TEST跑完之后会执行TearDown { diff --git a/tests/src/view/widgets/ut_processwidget.cpp b/tests/src/view/widgets/ut_processwidget.cpp index 222b1a47..035a1166 100644 --- a/tests/src/view/widgets/ut_processwidget.cpp +++ b/tests/src/view/widgets/ut_processwidget.cpp @@ -24,8 +24,13 @@ TEST_F(ut_processwidget_TEST, Processwidget_UT_setIcon) { QIcon icon; w->setIcon(icon); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ASSERT_EQ(w->mainIcon->pixmap()->width(), 0); ASSERT_EQ(w->mainIcon->pixmap()->height(), 0); +#else + ASSERT_EQ(w->mainIcon->pixmap().width(), 0); + ASSERT_EQ(w->mainIcon->pixmap().height(), 0); +#endif } TEST_F(ut_processwidget_TEST, Processwidget_UT_setMainText)