From 2241a284995e4c0b100f752060446b6b85848c92 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 8 Apr 2022 14:24:15 -1000 Subject: [PATCH] build-system: make map support its own thing Making this simply depend on Qt5 or Qt6 was short-sighted as work on QtLocation upstream continues. Instead break this out as its own option. Signed-off-by: Dirk Hohndel --- CMakeLists.txt | 27 +++++++++++++++----- core/divefilter.cpp | 6 ++--- desktop-widgets/CMakeLists.txt | 2 +- desktop-widgets/divelistview.cpp | 2 +- desktop-widgets/mainwindow.cpp | 8 +++--- desktop-widgets/tab-widgets/TabDiveNotes.cpp | 2 +- qt-models/CMakeLists.txt | 2 +- subsurface-helper.cpp | 4 +-- 8 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8418aa52b..03ee7fa61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,8 @@ else() set(QT_INSTALL_PREFIX ${_qt5Core_install_prefix}) # for Qt5 we want the Location component (which is missing so far in Qt6) LIST(APPEND QT_EXTRA_COMPONENTS Location) + add_definitions(-DMAP_SUPPORT) + set(MAPSUPPORT ON) endif() message(STATUS "building with Qt ${QT_VERSION}") @@ -343,6 +345,10 @@ endif() set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} ${LIBDIVECOMPUTER_LIBRARIES} ${LIBGIT2_LIBRARIES} ${LIBUSB_LIBRARIES} ${LIBMTP_LIBRARIES}) if (NOT SUBSURFACE_TARGET_EXECUTABLE MATCHES "DownloaderExecutable") if(USINGQT6) + if(MAPSUPPORT) + qt_add_resources(SUBSURFACE_RESOURCES map-widget/qml/map-widget.qrc) + set(SUBSURFACE_MAPWIDGET subsurface_mapwidget) + endif() qt_add_resources(SUBSURFACE_RESOURCES subsurface.qrc profile.qrc stats/statsicons.qrc desktop-widgets/qml/statsview2.qrc) else() qt5_add_resources(SUBSURFACE_RESOURCES subsurface.qrc profile.qrc stats/statsicons.qrc map-widget/qml/map-widget.qrc desktop-widgets/qml/statsview2.qrc) @@ -364,7 +370,7 @@ add_subdirectory(qt-models) add_subdirectory(commands) if (NOT SUBSURFACE_TARGET_EXECUTABLE MATCHES "DownloaderExecutable") add_subdirectory(profile-widget) -if(NOT USINGQT6) +if(MAPSUPPORT) add_subdirectory(map-widget) endif() add_subdirectory(mobile-widgets) @@ -547,13 +553,15 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") install(FILES ${QTTRANSLATIONS} DESTINATION ${RESOURCEDIR}/translations) install(FILES ${CMAKE_SOURCE_DIR}/gpl-2.0.txt DESTINATION ${RESOURCEDIR}) install(CODE "execute_process(COMMAND mkdir -p ${RESOURCEDIR}/qml)") - if(QT_VERSION VERSION_LESS 6.0.0) + if(USINGQT6) + set(QT_INSTALL_PREFIX ${QT6_INSTALL_PREFIX}) + else() set(QT_INSTALL_PREFIX ${_qt5Core_install_prefix}) + endif() + if(MAPSUPPORT) install(CODE "execute_process(COMMAND mkdir -p ${PLUGINDIR}/geoservices)") install(CODE "execute_process(COMMAND cp ${QT_INSTALL_PREFIX}/plugins/geoservices/libqtgeoservices_googlemaps.dylib ${PLUGINDIR}/geoservices ERROR_QUIET)") install(CODE "execute_process(COMMAND cp ${CMAKE_SOURCE_DIR}/../install-root/${QT_INSTALL_PREFIX}/plugins/geoservices/libqtgeoservices_googlemaps.dylib ${PLUGINDIR}/geoservices ERROR_QUIET)") - else() - set(QT_INSTALL_PREFIX ${QT6_INSTALL_PREFIX}) endif() # this will fail is macdeployqt isn't in the PATH - that seemed to happen in the past, but not recently # also, on M1 macOS systems macdeployqt throws a ton of (apparently harmless) errors. Warn the unsuspecting developer @@ -564,9 +572,14 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # the next hack is here to delete the sqlite plugin that get's installed even though it isn't needed install(CODE "execute_process(COMMAND rm -rf ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/PlugIns/sqldrivers)") # and another hack to get the QML Components in the right place - if(QT_VERSION VERSION_LESS 6.0.0) - install(CODE "execute_process(COMMAND rm -rf ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml/{QtQuick.2,QtLocation,QtPositioning})") - install(CODE "execute_process(COMMAND cp -a ${QT_INSTALL_PREFIX}/qml/QtQuick.2 ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)") + if(MAPSUPPORT) + if (USINGQT6) + install(CODE "execute_process(COMMAND rm -rf ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml/{QtQuick,QtLocation,QtPositioning})") + install(CODE "execute_process(COMMAND cp -a ${QT_INSTALL_PREFIX}/qml/QtQuick ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)") + else() + install(CODE "execute_process(COMMAND rm -rf ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml/{QtQuick.2,QtLocation,QtPositioning})") + install(CODE "execute_process(COMMAND cp -a ${QT_INSTALL_PREFIX}/qml/QtQuick.2 ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)") + endif() install(CODE "execute_process(COMMAND cp -a ${QT_INSTALL_PREFIX}/qml/QtLocation ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)") endif() install(CODE "execute_process(COMMAND cp -a ${QT_INSTALL_PREFIX}/qml/QtPositioning ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)") diff --git a/core/divefilter.cpp b/core/divefilter.cpp index a54754c85..d9a8a48ae 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -148,7 +148,7 @@ void DiveFilter::startFilterDiveSites(QVector ds) dive_sites = ds; // When switching into dive site mode, reload the dive sites. // TODO: why here? why not catch the filterReset signal in the map widget -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->reload(); #endif emit diveListNotifier.filterReset(); @@ -161,7 +161,7 @@ void DiveFilter::stopFilterDiveSites() return; dive_sites.clear(); emit diveListNotifier.filterReset(); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->reload(); #endif } @@ -176,7 +176,7 @@ void DiveFilter::setFilterDiveSite(QVector ds) dive_sites = ds; emit diveListNotifier.filterReset(); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->setSelected(dive_sites); MapWidget::instance()->selectionChanged(); #endif diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt index 55b37b338..eab95bd66 100644 --- a/desktop-widgets/CMakeLists.txt +++ b/desktop-widgets/CMakeLists.txt @@ -143,7 +143,7 @@ set(SUBSURFACE_INTERFACE updatemanager.cpp updatemanager.h ) -if(NOT USINGQT6) +if(MAPSUPPORT) LIST(APPEND SUBSURFACE_INTERFACE mapwidget.cpp mapwidget.h diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index ca7d6ccba..25a30eba2 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -523,7 +523,7 @@ void DiveListView::selectionChangeDone() if (d->selected && !d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site)) selectedSites.push_back(d->dive_site); } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->setSelected(selectedSites); #endif } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 139d2fa68..1c72aa1d4 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -134,7 +134,7 @@ MainWindow::MainWindow() : // for the "default" mode mainTab.reset(new MainTab); diveList.reset(new DiveListView); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT mapWidget.reset(MapWidget::instance()); // Yes, this is ominous see comment in mapwidget.cpp. #endif plannerWidgets.reset(new PlannerWidgets); @@ -200,7 +200,7 @@ MainWindow::MainWindow() : initialUiSetup(); readSettings(); diveList->setFocus(); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->reload(); #endif diveList->expand(diveList->model()->index(0, 0)); @@ -329,7 +329,7 @@ void MainWindow::selectionChanged() if (current_dive) enableDisableOtherDCsActions(); profile->plotCurrentDive(); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->selectionChanged(); #endif } @@ -507,7 +507,7 @@ void MainWindow::closeCurrentFile() clear_dive_file_data(); // this clears all the core data structures and resets the models setCurrentFile(nullptr); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT MapWidget::instance()->reload(); #endif if (!existing_filename) diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.cpp b/desktop-widgets/tab-widgets/TabDiveNotes.cpp index fe5b67535..4d052fb2f 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.cpp +++ b/desktop-widgets/tab-widgets/TabDiveNotes.cpp @@ -34,7 +34,7 @@ TabDiveNotes::TabDiveNotes(QWidget *parent) : TabBase(parent), connect(&diveListNotifier, &DiveListNotifier::commandExecuted, this, &TabDiveNotes::closeWarning); connect(ui.editDiveSiteButton, &QToolButton::clicked, MainWindow::instance(), &MainWindow::startDiveSiteEdit); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT connect(ui.location, &DiveLocationLineEdit::entered, MapWidget::instance(), &MapWidget::centerOnIndex); connect(ui.location, &DiveLocationLineEdit::currentChanged, MapWidget::instance(), &MapWidget::centerOnIndex); #endif diff --git a/qt-models/CMakeLists.txt b/qt-models/CMakeLists.txt index a7bbad934..51b743f0d 100644 --- a/qt-models/CMakeLists.txt +++ b/qt-models/CMakeLists.txt @@ -29,7 +29,7 @@ set(SUBSURFACE_GENERIC_MODELS_LIB_SRCS weightsysteminfomodel.h ) -if(NOT USINGQT6) +if(MAPSUPPORT) LIST(APPEND SUBSURFACE_GENERIC_MODELS_LIB_SRCS maplocationmodel.cpp maplocationmodel.h diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index 375d6e84a..690b05e9c 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -2,7 +2,7 @@ #include #include -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT #include "map-widget/qmlmapwidgethelper.h" #include "qt-models/maplocationmodel.h" #endif @@ -224,7 +224,7 @@ static void register_qml_types(QQmlEngine *engine) register_qml_type("ChartListModel"); #endif // not SUBSURFACE_MOBILE -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef MAP_SUPPORT register_qml_type("MapWidgetHelper"); register_qml_type("MapLocationModel"); #endif