From 22e5cfbacf9427c5e536dec2c1d3252e9ea1398a Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen <645432-yan12125@users.noreply.gitlab.com> Date: Tue, 30 Apr 2024 00:30:33 +0800 Subject: [PATCH 1/3] Replace deprecated Qt API --- CMakeLists.txt | 2 +- src/model/UserphraseModel.cpp | 7 ++++++- src/view/ChewingEditor.cpp | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a42b12..60e83f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ elseif(MSVC) add_definitions(-DUNICODE -D_UNICODE) endif() -add_definitions(-DTESTDATA="${PROJECT_SOURCE_DIR}/test/data") +add_definitions(-DTESTDATA="${PROJECT_SOURCE_DIR}/test/data" -DQT_DISABLE_DEPRECATED_BEFORE=0x050e00) find_package(PkgConfig) find_package(Qt5Widgets REQUIRED) diff --git a/src/model/UserphraseModel.cpp b/src/model/UserphraseModel.cpp index 995abeb..7e06004 100644 --- a/src/model/UserphraseModel.cpp +++ b/src/model/UserphraseModel.cpp @@ -20,6 +20,8 @@ #include "UserphraseModel.h" #include +#include +#include static void logger(void *data, int level, const char *fmt, ...) { @@ -86,7 +88,10 @@ void UserphraseModel::remove(QModelIndexList indexList) return; } - qSort(indexList.begin(), indexList.end(), qGreater()); + std::sort(indexList.begin(), indexList.end(), [] (const QModelIndex& a, const QModelIndex& b) { + // QModelIndex provides operator< but no operator> + return !(a < b); + }); // XXX: indexList is in revsrsed order, so first is actual last, and vice // verse. diff --git a/src/view/ChewingEditor.cpp b/src/view/ChewingEditor.cpp index be56c05..6200ad3 100644 --- a/src/view/ChewingEditor.cpp +++ b/src/view/ChewingEditor.cpp @@ -86,7 +86,7 @@ void ChewingEditor::execFileDialog(DialogType type) fileDialog_->setWindowTitle(tr("Import")); fileDialog_->setAcceptMode(QFileDialog::AcceptOpen); fileDialog_->setFileMode(QFileDialog::ExistingFile); - fileDialog_->setConfirmOverwrite(false); + fileDialog_->setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog_->selectFile(""); break; @@ -94,7 +94,7 @@ void ChewingEditor::execFileDialog(DialogType type) fileDialog_->setWindowTitle(tr("Export")); fileDialog_->setAcceptMode(QFileDialog::AcceptSave); fileDialog_->setFileMode(QFileDialog::AnyFile); - fileDialog_->setConfirmOverwrite(true); + fileDialog_->setOption(QFileDialog::DontConfirmOverwrite, false); fileDialog_->selectFile("chewing.json"); break; From 07ec6320773f006153811c3b57bdad8cec0f7de3 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen <645432-yan12125@users.noreply.gitlab.com> Date: Mon, 15 Jul 2024 15:18:54 +0800 Subject: [PATCH 2/3] Avoid qt5_use_modules Fixes https://github.com/chewing/chewing-editor/issues/234 --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60e83f2..079cab0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,12 +161,12 @@ QT5_ADD_RESOURCES(qt_resources ${PROJECT_SOURCE_DIR}/ts/ts.qrc) # exporter file(GLOB_RECURSE exporter_src ${PROJECT_SOURCE_DIR}/src/exporter/*) add_library(exporter STATIC ${exporter_src}) -qt5_use_modules(exporter Widgets) +target_link_libraries(exporter Qt5::Widgets) # importer file(GLOB_RECURSE importer_src ${PROJECT_SOURCE_DIR}/src/importer/*) add_library(importer STATIC ${importer_src}) -qt5_use_modules(importer Widgets) +target_link_libraries(importer Qt5::Widgets) # ui file(GLOB ui_src ${PROJECT_SOURCE_DIR}/src/ui/*) @@ -175,7 +175,7 @@ qt5_wrap_ui(ui ${ui_src}) # util file(GLOB util_src ${PROJECT_SOURCE_DIR}/src/util/*) add_library(util STATIC ${util_src}) -qt5_use_modules(util Widgets) +target_link_libraries(util Qt5::Widgets) # chewing-editor file(GLOB chewing-editor_src @@ -206,7 +206,7 @@ if(MSVC) ) endif() -qt5_use_modules(chewing-editor Widgets) +target_link_libraries(chewing-editor Qt5::Widgets) install(PROGRAMS ${CMAKE_BINARY_DIR}/chewing-editor DESTINATION ${CMAKE_INSTALL_BINDIR}) # icon @@ -273,7 +273,7 @@ target_link_libraries(run-test util pthread ) -qt5_use_modules(run-test Widgets) +target_link_libraries(run-test Qt5::Widgets) add_test(test run-test) From b6031448550e6846b832504ec21145093cca7ba1 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen <645432-yan12125@users.noreply.gitlab.com> Date: Mon, 15 Jul 2024 16:23:11 +0800 Subject: [PATCH 3/3] Fix building on macOS in CI The original hack no longer works as Homebrew installs to /opt/homebrew by default for ARM [1], and hosted macOS runners on GitHub now uses ARM by default [2]. While I'm at it, I replaced the hack with a more general solution. It's inspired by other Homebrew formulae that use cmake and qt@5 [3]. [1] https://docs.brew.sh/Installation [2] https://github.com/actions/runner-images?tab=readme-ov-file#available-images [3] https://github.com/search?q=repo%3AHomebrew%2Fhomebrew-core+CMAKE_PREFIX_PATH+qt%405&type=code --- .github/workflows/ci.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebf7aa0..6404c42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,12 +39,8 @@ jobs: brew update brew install libchewing qt@5 - # Qt - brew link --force qt@5 - # Homebrew does not link mkspecs and plugins https://github.com/Homebrew/homebrew-core/issues/93056 - export HOMEBREW_QT5_VERSION=$(brew list --versions qt@5 | rev | cut -d' ' -f1 | rev) - sudo ln -s /usr/local/Cellar/qt@5/$HOMEBREW_QT5_VERSION/mkspecs /usr/local/mkspecs - sudo ln -s /usr/local/Cellar/qt@5/$HOMEBREW_QT5_VERSION/plugins /usr/local/plugins + # Allow CMake to find qt@5 by passing down the environment variable + echo "CMAKE_PREFIX_PATH=$(brew --prefix qt@5)" >> $GITHUB_ENV if: ${{ matrix.os == 'macos-latest' }} - name: Configure CMake