From cb37c1c2febf91eb9e701a5bc155b9ae5e30715e Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Wed, 16 Dec 2020 23:06:08 +0100 Subject: [PATCH] Add switch for KF5 (QT6) and Mod Cmake if we want to test QET on QT6, KF5 must be removed from the code, this switch is for that, this is for testing only --- CMakeLists.txt | 26 +------ cmake/define_definitions.cmake | 7 +- cmake/developer_options.cmake | 3 + cmake/fetch_kdeaddons.cmake | 74 ++++++++++++-------- cmake/qet_compilation_vars.cmake | 21 ++++-- sources/editor/ui/dynamictextfieldeditor.cpp | 3 + sources/qetapp.cpp | 15 ++-- sources/qetdiagrameditor.cpp | 9 ++- sources/qetdiagrameditor.h | 12 +++- sources/qetproject.cpp | 21 ++++-- sources/qetproject.h | 15 +++- tests/catch/CMakeLists.txt | 11 +-- tests/googlemock/CMakeLists.txt | 11 +-- tests/googletest/CMakeLists.txt | 12 +--- tests/qttest/CMakeLists.txt | 11 +-- 15 files changed, 135 insertions(+), 116 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38996e75e..4b9e1c4e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,36 +85,14 @@ add_executable( ${QET_DIR}/qelectrotech.qrc ) -target_link_libraries( - ${PROJECT_NAME} - PUBLIC - PRIVATE - Qt${QT_VERSION_MAJOR}::Xml - Qt${QT_VERSION_MAJOR}::Svg - Qt${QT_VERSION_MAJOR}::Network - Qt${QT_VERSION_MAJOR}::Sql - Qt${QT_VERSION_MAJOR}::PrintSupport - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Concurrent - KF5::WidgetsAddons - KF5::CoreAddons - ) - target_link_libraries( ${PROJECT_NAME} PUBLIC PRIVATE pugixml::pugixml SingleApplication::SingleApplication - KF5::WidgetsAddons - KF5::CoreAddons - Qt5::Gui - Qt5::Xml - Qt5::Svg - Qt5::Network - Qt5::Sql - Qt5::Widgets - Qt5::Concurrent + ${KF5_PRIVATE_LIBRARIES} + ${QET_PRIVATE_LIBRARIES} ) target_include_directories( diff --git a/cmake/define_definitions.cmake b/cmake/define_definitions.cmake index 8f300d33c..659838dde 100644 --- a/cmake/define_definitions.cmake +++ b/cmake/define_definitions.cmake @@ -61,6 +61,11 @@ message("PROJECT_HOMEPAGE_URL :" ${PROJECT_HOMEPAGE_URL}) message("PROJECT_SOURCE_DIR :" ${PROJECT_SOURCE_DIR}) message("QET_DIR :" ${QET_DIR}) message("GIT_COMMIT_SHA :" ${GIT_COMMIT_SHA}) -message("KF5_GIT_TAG :" ${KF5_GIT_TAG}) + +if(BUILD_WITH_KF5) + message("KF5_GIT_TAG :" ${KF5_GIT_TAG}) +else() + add_definitions(-DBUILD_WITHOUT_KF5) +endif() message("QET_COMPONENTS :" ${QET_COMPONENTS}) message("QT_VERSION_MAJOR :" ${QT_VERSION_MAJOR}) diff --git a/cmake/developer_options.cmake b/cmake/developer_options.cmake index 2c9e2ff6d..9b03b8265 100644 --- a/cmake/developer_options.cmake +++ b/cmake/developer_options.cmake @@ -30,3 +30,6 @@ add_definitions(-DQT_MESSAGELOGCONTEXT) # You can make your code warn on compile time for the TODO's # In order to do so, uncomment the following line. #add_definitions(-DTODO_LIST) + +# Build with KF5 +option(BUILD_WITH_KF5 "Build with KF5" ON) diff --git a/cmake/fetch_kdeaddons.cmake b/cmake/fetch_kdeaddons.cmake index 513d93f05..f286ed5cc 100644 --- a/cmake/fetch_kdeaddons.cmake +++ b/cmake/fetch_kdeaddons.cmake @@ -16,40 +16,52 @@ message(" - fetch_kdeaddons") -Include(FetchContent) +if(DEFINED BUILD_WITH_KF5) + Include(FetchContent) -set(BUILD_KF5_YES "YES") + set(BUILD_KF5_YES "YES") -if(DEFINED BUILD_KF5_YES) + if(DEFINED BUILD_KF5_YES) - if(NOT DEFINED KF5_GIT_TAG) - #https://qelectrotech.org/forum/viewtopic.php?pid=13924#p13924 - set(KF5_GIT_TAG v5.70.0) + if(NOT DEFINED KF5_GIT_TAG) + #https://qelectrotech.org/forum/viewtopic.php?pid=13924#p13924 + set(KF5_GIT_TAG v5.70.0) + endif() + + # Fix stop the run autotests of kcoreaddons + # see + # https://invent.kde.org/frameworks/kcoreaddons/-/blob/master/CMakeLists.txt#L98 + # issue: + # CMake Error at /usr/share/ECM/modules/ECMAddTests.cmake:89 (add_executable): + # Cannot find source file: + # see + # https://qelectrotech.org/forum/viewtopic.php?pid=13929#p13929 + set(KDE_SKIP_TEST_SETTINGS "TRUE") + set(BUILD_TESTING "0") + FetchContent_Declare( + ecm + GIT_REPOSITORY https://invent.kde.org/frameworks/extra-cmake-modules.git + GIT_TAG ${KF5_GIT_TAG}) + FetchContent_MakeAvailable(ecm) + + FetchContent_Declare( + kcoreaddons + GIT_REPOSITORY https://invent.kde.org/frameworks/kcoreaddons.git + GIT_TAG ${KF5_GIT_TAG}) + FetchContent_MakeAvailable(kcoreaddons) + + FetchContent_Declare( + kwidgetsaddons + GIT_REPOSITORY https://invent.kde.org/frameworks/kwidgetsaddons.git + GIT_TAG ${KF5_GIT_TAG}) + FetchContent_MakeAvailable(kwidgetsaddons) + else() + find_package(KF5CoreAddons REQUIRED) + find_package(KF5WidgetsAddons REQUIRED) endif() - # Fix stop the run autotests of kcoreaddons - # see - # https://invent.kde.org/frameworks/kcoreaddons/-/blob/master/CMakeLists.txt#L98 - # issue: - # CMake Error at /usr/share/ECM/modules/ECMAddTests.cmake:89 (add_executable): - # Cannot find source file: - # see - # https://qelectrotech.org/forum/viewtopic.php?pid=13929#p13929 - set(KDE_SKIP_TEST_SETTINGS "TRUE") - set(BUILD_TESTING "0") - - FetchContent_Declare( - kcoreaddons - GIT_REPOSITORY https://invent.kde.org/frameworks/kcoreaddons.git - GIT_TAG ${KF5_GIT_TAG}) - FetchContent_MakeAvailable(kcoreaddons) - - FetchContent_Declare( - kwidgetsaddons - GIT_REPOSITORY https://invent.kde.org/frameworks/kwidgetsaddons.git - GIT_TAG ${KF5_GIT_TAG}) - FetchContent_MakeAvailable(kwidgetsaddons) -else() - find_package(KF5CoreAddons REQUIRED) - find_package(KF5WidgetsAddons REQUIRED) + set(KF5_PRIVATE_LIBRARIES + KF5::WidgetsAddons + KF5::CoreAddons + ) endif() diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 17963c1fd..e24a0948d 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -17,14 +17,25 @@ message(" - qet_compilation_vars") set(QET_COMPONENTS - Widgets - Concurrent + LinguistTools + PrintSupport Xml Svg - Network Sql - PrintSupport - LinguistTools) + Network + Widgets + Concurrent) + +set(QET_PRIVATE_LIBRARIES + Qt::PrintSupport + Qt::Gui + Qt::Xml + Qt::Svg + Qt::Sql + Qt::Network + Qt::Widgets + Qt::Concurrent + ) set(QET_SRC_FILES ${QET_DIR}/sources/borderproperties.cpp diff --git a/sources/editor/ui/dynamictextfieldeditor.cpp b/sources/editor/ui/dynamictextfieldeditor.cpp index e60005a31..6b8e59bbb 100644 --- a/sources/editor/ui/dynamictextfieldeditor.cpp +++ b/sources/editor/ui/dynamictextfieldeditor.cpp @@ -135,7 +135,10 @@ void DynamicTextFieldEditor::updateForm() ui -> m_frame_cb -> setChecked(m_text_field.data() -> frame()); ui -> m_user_text_le -> setText(m_text_field.data() -> text()); ui -> m_size_sb -> setValue(m_text_field.data() -> font().pointSize()); +#ifdef BUILD_WITHOUT_KF5 +#else ui -> m_color_kpb -> setColor(m_text_field.data() -> color()); +#endif ui -> m_width_sb -> setValue(m_text_field.data() -> textWidth()); ui -> m_font_pb -> setText(m_text_field -> font().family()); diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 72494dddd..ec2f5c4db 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -42,7 +42,10 @@ #define STRINGIFY(x) #x #include #include -#include +#ifdef BUILD_WITHOUT_KF5 +#else +# include +#endif #ifdef QET_ALLOW_OVERRIDE_CED_OPTION QString QETApp::common_elements_dir = QString(); @@ -2080,6 +2083,9 @@ void QETApp::buildSystemTrayMenu() */ void QETApp::checkBackupFiles() { +#ifdef BUILD_WITHOUT_KF5 + return; +#else QList stale_files = KAutoSaveFile::allStaleFiles(); //Remove from the list @stale_files, the stales file of opened project @@ -2116,12 +2122,12 @@ void QETApp::checkBackupFiles() } for(const KAutoSaveFile *kasf : stale_files) { -#ifdef Q_OS_WIN +# ifdef Q_OS_WIN //Remove the first character '/' before the name of the drive text.append("
" + kasf->managedFile().path().remove(0,1)); -#else +# else text.append("
" + kasf->managedFile().path()); -#endif +# endif } //Open backup file @@ -2154,6 +2160,7 @@ void QETApp::checkBackupFiles() delete stale; } } +#endif } /** diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index d4000eb66..bf0546e66 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -42,7 +42,10 @@ #include "undocommand/rotateselectioncommand.h" #include "undocommand/rotatetextscommand.h" -#include +#ifdef BUILD_WITHOUT_KF5 +#else +# include +#endif /** @brief QETDiagramEditor::QETDiagramEditor @@ -1847,6 +1850,8 @@ bool QETDiagramEditor::drawGrid() const return m_draw_grid->isChecked(); } +#ifdef BUILD_WITHOUT_KF5 +#else /** @brief QETDiagramEditor::openBackupFiles @param backup_files @@ -1877,7 +1882,7 @@ void QETDiagramEditor::openBackupFiles(QList backup_files) DialogWaiting::dropInstance(); } } - +#endif /** met a jour le menu "Fenetres" */ diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 1b84453e1..d18098188 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -41,8 +41,11 @@ class RecentFiles; class DiagramPropertiesEditorDockWidget; class ElementsCollectionWidget; class AutoNumberingDockWidget; -class KAutoSaveFile; +#ifdef BUILD_WITHOUT_KF5 +#else +class KAutoSaveFile; +#endif /** This class represents the main window of the QElectroTech diagram editor and, ipso facto, the most important part of the QElectroTech user interface. @@ -65,9 +68,12 @@ class QETDiagramEditor : public QETMainWindow ProjectView *currentProjectView() const; QETProject *currentProject() const; bool drawGrid() const; +#ifdef BUILD_WITHOUT_KF5 +#else void openBackupFiles (QList backup_files); - - protected: +#endif + + protected: bool event(QEvent *) override; private: QETDiagramEditor(const QETDiagramEditor &); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 17db03714..0bad5a891 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -77,6 +77,8 @@ QETProject::QETProject(const QString &path, QObject *parent) : init(); } +#ifdef BUILD_WITHOUT_KF5 +#else /** @brief QETProject::QETProject @param backup : backup file to open, QETProject take ownership of backup. @@ -110,6 +112,7 @@ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) : init(); } +#endif /** @brief QETProject::~QETProject @@ -276,12 +279,13 @@ void QETProject::setFilePath(const QString &filepath) if (filepath == m_file_path) { return; } - +#ifdef BUILD_WITHOUT_KF5 +#else if (m_backup_file.isOpen()) { m_backup_file.close(); } m_backup_file.setManagedFile(QUrl::fromLocalFile(filepath)); - +#endif m_file_path = filepath; QFileInfo fi(m_file_path); @@ -1742,15 +1746,18 @@ NamesList QETProject::namesListForIntegrationCategory() */ void QETProject::writeBackup() { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove +#ifdef BUILD_WITHOUT_KF5 +#else +# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove QDomDocument xml_project(toXml()); QtConcurrent::run( QET::writeToFile,xml_project,&m_backup_file,nullptr); -#else -#if TODO_LIST -#pragma message("@TODO remove code for QT 6 or later") -#endif +# else +# if TODO_LIST +# pragma message("@TODO remove code for QT 6 or later") +# endif qDebug()<<"Help code for QT 6 or later"; +# endif #endif } diff --git a/sources/qetproject.h b/sources/qetproject.h index a90cf0691..7003d15b6 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -27,8 +27,10 @@ #include "properties/xrefproperties.h" #include "titleblock/templatescollection.h" #include "titleblockproperties.h" - -#include +#ifdef BUILD_WITHOUT_KF5 +#else +# include +#endif #include class Diagram; @@ -40,7 +42,10 @@ class NumerotationContext; class QUndoStack; class XmlElementCollection; class QTimer; +#ifdef BUILD_WITHOUT_KF5 +#else class KAutoSaveFile; +#endif /** This class represents a QET project. Typically saved as a .qet file, it @@ -68,7 +73,10 @@ class QETProject : public QObject public: QETProject (QObject *parent = nullptr); QETProject (const QString &path, QObject * = nullptr); +#ifdef BUILD_WITHOUT_KF5 +#else QETProject (KAutoSaveFile *backup, QObject *parent=nullptr); +#endif ~QETProject() override; private: @@ -267,7 +275,10 @@ class QETProject : public QObject bool m_freeze_new_conductors = false; QTimer m_save_backup_timer, m_autosave_timer; +#ifdef BUILD_WITHOUT_KF5 +#else KAutoSaveFile m_backup_file; +#endif QUuid m_uuid = QUuid::createUuid(); projectDataBase m_data_base; }; diff --git a/tests/catch/CMakeLists.txt b/tests/catch/CMakeLists.txt index d87e5ab9c..b6ab66bf0 100644 --- a/tests/catch/CMakeLists.txt +++ b/tests/catch/CMakeLists.txt @@ -88,15 +88,8 @@ target_link_libraries( PUBLIC Catch2::Catch2 PRIVATE - KF5::WidgetsAddons - KF5::CoreAddons - Qt::Gui - Qt::Xml - Qt::Svg - Qt::Sql - Qt::Network - Qt::Widgets - Qt::Concurrent) + ${KF5_PRIVATE_LIBRARIES} + ${QET_PRIVATE_LIBRARIES}) if (DEFINED ENV{CATCH_INCLUDE_DIR}) set(CATCH_INCLUDE_DIR $ENV{CATCH_INCLUDE_DIR}) diff --git a/tests/googlemock/CMakeLists.txt b/tests/googlemock/CMakeLists.txt index 577f85a88..db29ef8c9 100644 --- a/tests/googlemock/CMakeLists.txt +++ b/tests/googlemock/CMakeLists.txt @@ -85,13 +85,6 @@ target_link_libraries( PUBLIC gmock gmock_main PRIVATE - KF5::WidgetsAddons - KF5::CoreAddons - Qt::Gui - Qt::Xml - Qt::Svg - Qt::Sql - Qt::Network - Qt::Widgets - Qt::Concurrent) + ${KF5_PRIVATE_LIBRARIES} + ${QET_PRIVATE_LIBRARIES}) diff --git a/tests/googletest/CMakeLists.txt b/tests/googletest/CMakeLists.txt index 3984d82d5..d9a4ae750 100644 --- a/tests/googletest/CMakeLists.txt +++ b/tests/googletest/CMakeLists.txt @@ -79,19 +79,11 @@ add_executable( tst_My_test.cpp main.cpp ) - target_link_libraries( ${PROJECT_NAME} PUBLIC gtest gtest_main PRIVATE - KF5::WidgetsAddons - KF5::CoreAddons - Qt::Gui - Qt::Xml - Qt::Svg - Qt::Sql - Qt::Network - Qt::Widgets - Qt::Concurrent) + ${KF5_PRIVATE_LIBRARIES} + ${QET_PRIVATE_LIBRARIES}) diff --git a/tests/qttest/CMakeLists.txt b/tests/qttest/CMakeLists.txt index 960a0324b..41137a3e5 100644 --- a/tests/qttest/CMakeLists.txt +++ b/tests/qttest/CMakeLists.txt @@ -74,13 +74,6 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE Qt::Test - KF5::CoreAddons - KF5::WidgetsAddons - Qt::Gui - Qt::Xml - Qt::Svg - Qt::Sql - Qt::Network - Qt::Widgets - Qt::Concurrent) + ${KF5_PRIVATE_LIBRARIES} + ${QET_PRIVATE_LIBRARIES})