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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-04-08 14:24:15 -10:00
parent 890f21bd58
commit 2241a28499
8 changed files with 33 additions and 20 deletions

View file

@ -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)
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)")

View file

@ -148,7 +148,7 @@ void DiveFilter::startFilterDiveSites(QVector<dive_site *> 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<dive_site *> 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

View file

@ -143,7 +143,7 @@ set(SUBSURFACE_INTERFACE
updatemanager.cpp
updatemanager.h
)
if(NOT USINGQT6)
if(MAPSUPPORT)
LIST(APPEND SUBSURFACE_INTERFACE
mapwidget.cpp
mapwidget.h

View file

@ -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
}

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -2,7 +2,7 @@
#include <QQmlEngine>
#include <QQuickItem>
#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>("ChartListModel");
#endif // not SUBSURFACE_MOBILE
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#ifdef MAP_SUPPORT
register_qml_type<MapWidgetHelper>("MapWidgetHelper");
register_qml_type<MapLocationModel>("MapLocationModel");
#endif