Skip to content

Commit

Permalink
GeographicView: Simplify implementation for rendering online maps (WIP)
Browse files Browse the repository at this point in the history
Previous implementation was depending on QtWebKit or QtWebEngine to render
online maps using javascript and the open source Leaflet library.

While it was working fine, it was quite cumbersome to deploy as QtWebKit
is now deprecated and QtWebEngine is a beast in terms of size of binaries.

Prefer to use the lightweight QGeoView library instead which only depends
on Qt base libraries and works pretty fine to smoothly render an online map
and interact with it.

Inspired from the changes in the recent Tulip 6.0 release.
  • Loading branch information
anlambert committed Dec 12, 2024
1 parent a207463 commit f7de2bb
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 16,149 deletions.
1 change: 0 additions & 1 deletion .github/workflows/archlinux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
zstd \
libgit2 \
qt6-base \
qt6-webengine \
quazip-qt6 \
glew \
glu \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
libzstd-dev
libgit2-dev
qtbase5-dev
libqt5webkit5-dev
libquazip5-dev
libglew-dev
libfreetype6-dev
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos-macports-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ jobs:
glew
qt5-qtbase
qt5-qttools
qt5-qtwebkit
quazip
py${{ env.PYTHON_VERSION_NO_DOT }}-pip
- name: Install Sphinx
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
libzstd-dev
libgit2-dev
qtbase5-dev
libqt5webkit5-dev
libquazip5-dev
libglew-dev
libfreetype6-dev
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ubuntu-qt6-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ jobs:
graphviz
qt6-base-dev
libqt6core5compat6-dev
qt6-webengine-dev
qt6-webengine-dev-tools
xvfb
- name: Install sphinx and sip
run: sudo pip install sphinx sip
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/windows-mingw64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
mingw-w64-${{ matrix.config.arch }}-glew
mingw-w64-${{ matrix.config.arch }}-qt5
mingw-w64-${{ matrix.config.arch }}-quazip
mingw-w64-${{ matrix.config.arch }}-qtwebkit
mingw-w64-${{ matrix.config.arch }}-python-sphinx
mingw-w64-${{ matrix.config.arch }}-sip
- name: Prepare ccache timestamp
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/windows-msvc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
arch: win64_msvc2019_64
modules: qtimageformats
qtpositioning
qtwebengine
qtwebchannel
qtwebsockets
qt5compat
Expand Down
21 changes: 2 additions & 19 deletions bundlers/linux/talipot_appimage_centos_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ yum -y install freetype-devel fontconfig-devel glew-devel fribidi-devel
if [ "$centos8" = true ]
then
yum -y install qt5-qtbase-devel qt5-qtimageformats qt5-qtsvg \
quazip-qt5-devel qt5-qtwebkit-devel --enablerepo=epel-testing --nobest
quazip-qt5-devel --enablerepo=epel-testing --nobest
else
yum -y install qt6-qtbase-devel qt6-qtimageformats qt6-qtsvg \
qt6-qt5compat-devel qt6-qtwebengine-devel
qt6-qt5compat-devel
fi

# install Python 3, Sphinx and SIP
Expand Down Expand Up @@ -101,23 +101,6 @@ bash bundlers/linux/make_appimage_bundle.sh --appdir $PWD

APP_DIR=Talipot.AppDir

# ensure QtWebEngine is functional when bundled in AppImage
if [ "$centos9" = true ]
then
yum -y install patchelf cpio
# for some reasons, qt6-qtwebengine translations files are not installed
# by yum but those are still available in the rpm archive so we hack a bit
# to extract and copy them in the AppImage AppDir
yum -y remove --noautoremove qt6-qtwebengine
yum -y install --downloadonly --downloaddir=$PWD qt6-qtwebengine
rpm2cpio qt6-qtwebengine*.rpm | cpio -idmv --directory=/opt/qtwebengine
cp -r /opt/qtwebengine/usr/share/qt6/translations/qtwebengine_locales/ $APP_DIR/usr/translations/
# this file is also required to be bundled in AppImage or V8 crashes on startup
cp /opt/qtwebengine/usr/share/qt6/resources/v8_context_snapshot.bin $APP_DIR/usr/resources/
# rpath of QtWebEngineProcess also needs to be patched to work in AppImage
patchelf --set-rpath '$ORIGIN/../lib' $APP_DIR/usr/libexec/QtWebEngineProcess
fi

# get appimagetool
wget "https://github.com/probonopd/AppImageKit/releases/download/\
continuous/appimagetool-$(uname -p).AppImage"
Expand Down
96 changes: 0 additions & 96 deletions cmake/FindQtX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ UNSET(Qt${QT_MAJOR_VERSION}Widgets_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Xml_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}XmlPatterns_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Network_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebKit_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebKitWidgets_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Multimedia_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}MultimediaWidgets_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Positioning_FOUND CACHE)
Expand All @@ -31,7 +29,6 @@ UNSET(Qt${QT_MAJOR_VERSION}Qml_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Quick_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Sensors_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}DBus_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebEngineWidgets_FOUND CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebChannel_FOUND CACHE)

IF(QT_MAJOR_VERSION EQUAL 6)
Expand All @@ -44,8 +41,6 @@ UNSET(Qt${QT_MAJOR_VERSION}Widgets_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Xml_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}XmlPatterns_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Network_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebKit_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebKitWidgets_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Multimedia_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}MultimediaWidgets_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Positioning_DIR CACHE)
Expand All @@ -54,40 +49,13 @@ UNSET(Qt${QT_MAJOR_VERSION}Qml_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Quick_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}Sensors_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}DBus_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebEngineWidgets_DIR CACHE)
UNSET(Qt${QT_MAJOR_VERSION}WebChannel_DIR CACHE)

IF(QT_MAJOR_VERSION EQUAL 6)
UNSET(Qt6OpenGLWidgets_DIR CACHE)
UNSET(Qt6Core5Compat_DIR CACHE)
ENDIF(QT_MAJOR_VERSION EQUAL 6)

SET(QT_HAS_WEBKIT FALSE)
SET(QT_HAS_WEBENGINE FALSE)

# Macro used to workaround a small issue with QtWebkit components on MSYS2: when
# compiling in RelWithDebInfo mode, Qt debug libraries are selected instead of
# the release one (this should only happen when compiling in Debug mode)
MACRO(SETUP_QT_LIBRARIES QtModule LIBRARIES)
IF(MINGW)
GET_TARGET_PROPERTY(
Qt${QT_MAJOR_VERSION}${QtModule}_INCLUDE_DIRS
Qt${QT_MAJOR_VERSION}::${QtModule} INTERFACE_INCLUDE_DIRECTORIES)

IF(CMAKE_DEBUG_MODE)
GET_TARGET_PROPERTY(Qt${QT_MAJOR_VERSION}${QtModule}_LIBRARIES
Qt${QT_MAJOR_VERSION}::${QtModule} LOCATION_DEBUG)
ELSE(CMAKE_DEBUG_MODE)
GET_TARGET_PROPERTY(Qt${QT_MAJOR_VERSION}${QtModule}_LIBRARIES
Qt${QT_MAJOR_VERSION}::${QtModule} LOCATION_RELEASE)
ENDIF(CMAKE_DEBUG_MODE)
ENDIF(MINGW)

SET(${LIBRARIES}
${${LIBRARIES}} ${Qt${QT_MAJOR_VERSION}${QtModule}_LIBRARIES}
${Qt${QT_MAJOR_VERSION}${QtModule}_LIBRARIES})
ENDMACRO(SETUP_QT_LIBRARIES)

FIND_PACKAGE(Qt${QT_MAJOR_VERSION}Widgets ${QT_MIN_VERSION} REQUIRED)
FIND_PACKAGE(Qt${QT_MAJOR_VERSION}Network ${QT_MIN_VERSION} REQUIRED)

Expand Down Expand Up @@ -201,52 +169,6 @@ IF(APPLE)
ENDIF(EXISTS ${QT_DBUS_CMAKE_DIR} AND EXISTS ${QT_PRINTSUPPORT_CMAKE_DIR})
ENDIF(APPLE)

# Check if the QtX installation is bundled with WebKit (deprecated since Qt 5.5)
# and setup its use if it is the case.
SET(QT_WEBKIT_WIDGETS_CMAKE_DIR
"${QT_CMAKE_DIR}/Qt${QT_MAJOR_VERSION}WebKitWidgets")

IF(EXISTS ${QT_WEBKIT_WIDGETS_CMAKE_DIR})
FIND_PACKAGE(Qt${QT_MAJOR_VERSION}WebKit)
FIND_PACKAGE(Qt${QT_MAJOR_VERSION}WebKitWidgets)

IF(${Qt${QT_MAJOR_VERSION}WebKit_FOUND}
AND ${Qt${QT_MAJOR_VERSION}WebKitWidgets_FOUND})
SET(QT_HAS_WEBKIT TRUE)
SET(QT_WEB_COMPONENT "QtWebKit")
SETUP_QT_LIBRARIES(WebKit QT_WEB_LIBRARIES)
SETUP_QT_LIBRARIES(WebKitWidgets QT_WEB_LIBRARIES)
ENDIF(${Qt${QT_MAJOR_VERSION}WebKit_FOUND}
AND ${Qt${QT_MAJOR_VERSION}WebKitWidgets_FOUND})
ENDIF(EXISTS ${QT_WEBKIT_WIDGETS_CMAKE_DIR})

# If QtX is not bundled with WebKit then check if its installation provides
# WebEngine (new web module since Qt 5.4) and setup its use.
SET(QT_WEBENGINE_WIDGETS_CMAKE_DIR
"${QT_CMAKE_DIR}/Qt${QT_MAJOR_VERSION}WebEngineWidgets")

IF(NOT QT_HAS_WEBKIT AND EXISTS ${QT_WEBENGINE_WIDGETS_CMAKE_DIR})
FIND_PACKAGE(Qt${QT_MAJOR_VERSION}WebEngineWidgets ${QT_MIN_VERSION})
FIND_PACKAGE(Qt${QT_MAJOR_VERSION}WebChannel ${QT_MIN_VERSION})

IF(${Qt${QT_MAJOR_VERSION}WebEngineWidgets_FOUND}
AND ${Qt${QT_MAJOR_VERSION}WebChannel_FOUND})
SET(QT_HAS_WEBENGINE TRUE)
SET(QT_WEB_COMPONENT "QtWebEngine")
SET(QT_WEB_LIBRARIES ${Qt${QT_MAJOR_VERSION}WebEngineWidgets_LIBRARIES}
${Qt${QT_MAJOR_VERSION}WebChannel_LIBRARIES})
ENDIF(${Qt${QT_MAJOR_VERSION}WebEngineWidgets_FOUND}
AND ${Qt${QT_MAJOR_VERSION}WebChannel_FOUND})
ENDIF(NOT QT_HAS_WEBKIT AND EXISTS ${QT_WEBENGINE_WIDGETS_CMAKE_DIR})

IF(NOT "${QT_WEB_COMPONENT}" STREQUAL "${LAST_FOUND_QT_WEB_COMPONENT}")
MESSAGE(STATUS "Found ${QT_WEB_COMPONENT}")
ENDIF(NOT "${QT_WEB_COMPONENT}" STREQUAL "${LAST_FOUND_QT_WEB_COMPONENT}")

SET(LAST_FOUND_QT_WEB_COMPONENT
"${QT_WEB_COMPONENT}"
CACHE INTERNAL "")

MACRO(QTX_SET_INCLUDES_AND_DEFINITIONS)
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}Widgets_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}Network_INCLUDE_DIRS})
Expand All @@ -261,24 +183,6 @@ MACRO(QTX_SET_INCLUDES_AND_DEFINITIONS)
ENDIF(QT_MAJOR_VERSION EQUAL 6)
ENDMACRO()

MACRO(QTXWEB_SET_INCLUDES_AND_DEFINITIONS)
IF(QT_HAS_WEBKIT)
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}WebKit_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}WebKitWidgets_INCLUDE_DIRS})
ADD_DEFINITIONS(${Qt${QT_MAJOR_VERSION}WebKit_DEFINITIONS})
ADD_DEFINITIONS(${Qt${QT_MAJOR_VERSION}WebKitWidgets_DEFINITIONS})
ADD_COMPILE_DEFINITIONS(QT_HAS_WEBKIT)
ENDIF()

IF(QT_HAS_WEBENGINE)
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}WebEngineWidgets_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Qt${QT_MAJOR_VERSION}WebChannel_INCLUDE_DIRS})
ADD_DEFINITIONS(${Qt${QT_MAJOR_VERSION}WebEngineWidgets_DEFINITIONS})
ADD_DEFINITIONS(${Qt${QT_MAJOR_VERSION}WebChannel_DEFINITIONS})
ADD_COMPILE_DEFINITIONS(QT_HAS_WEBENGINE)
ENDIF()
ENDMACRO(QTXWEB_SET_INCLUDES_AND_DEFINITIONS)

# Define aliases for Qt macros in order to build the project
IF(QT_MAJOR_VERSION EQUAL 5)
MACRO(QT_WRAP_CPP outfiles)
Expand Down
9 changes: 1 addition & 8 deletions plugins/view/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
QTX_SET_INCLUDES_AND_DEFINITIONS()

ADD_SUBDIRECTORY(HistogramView)

IF(QT_HAS_WEBKIT OR QT_HAS_WEBENGINE)
ADD_SUBDIRECTORY(GeographicView)
ELSE()
MESSAGE(
"Unable to build 'GeographicView': QtWebKit and QtWebEngine are missing")
ENDIF(QT_HAS_WEBKIT OR QT_HAS_WEBENGINE)

ADD_SUBDIRECTORY(GeographicView)
ADD_SUBDIRECTORY(MatrixView)
ADD_SUBDIRECTORY(ParallelCoordinatesView)
ADD_SUBDIRECTORY(PixelOrientedView)
Expand Down
28 changes: 4 additions & 24 deletions plugins/view/GeographicView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ INCLUDE_DIRECTORIES(
${TalipotUIGUIInclude}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${GLEW_INCLUDE_DIR})
${GLEW_INCLUDE_DIR}
${QGeoViewInclude})

QTX_SET_INCLUDES_AND_DEFINITIONS()
QTXWEB_SET_INCLUDES_AND_DEFINITIONS()

SET(LIB_SRCS
GeographicView.cpp
Expand All @@ -18,7 +18,6 @@ SET(LIB_SRCS
ProgressWidgetGraphicsProxy.cpp
GeographicViewInteractors.cpp
AddressSelectionDialog.cpp
LeafletMaps.cpp
GeographicViewGraphicsView.cpp
GeographicViewShowElementInfo.cpp
NominatimGeocoder.cpp)
Expand All @@ -36,26 +35,7 @@ QT_WRAP_CPP(
ProgressWidgetGraphicsProxy.h
GeographicViewConfigWidget.h
GeographicViewShowElementInfo.h
GeolocationConfigWidget.h
LeafletMaps.h)

IF(MSVC)
# When compiling with Visual Studio, install QtWebEngine process, resources
# and locales required for the Geographic view to work when installing Talipot
# from a Windows installer
IF(EXISTS "${QT_BINARY_DIR}/QtWebEngineProcess.exe")
INSTALL(FILES "${QT_BINARY_DIR}/QtWebEngineProcess.exe"
DESTINATION ${TalipotBinInstallDir})
ENDIF(EXISTS "${QT_BINARY_DIR}/QtWebEngineProcess.exe")
IF(EXISTS "${QT_BINARY_DIR}/../resources")
INSTALL(DIRECTORY "${QT_BINARY_DIR}/../resources"
DESTINATION ${TalipotBinInstallDir})
ENDIF(EXISTS "${QT_BINARY_DIR}/../resources")
IF(EXISTS "${QT_BINARY_DIR}/../translations/qtwebengine_locales")
INSTALL(DIRECTORY "${QT_BINARY_DIR}/../translations/qtwebengine_locales"
DESTINATION ${TalipotBinInstallDir}/translations/)
ENDIF(EXISTS "${QT_BINARY_DIR}/../translations/qtwebengine_locales")
ENDIF(MSVC)
GeolocationConfigWidget.h)

TALIPOT_ADD_PLUGIN(
NAME
Expand All @@ -71,7 +51,7 @@ TALIPOT_ADD_PLUGIN(
${LibTalipotGUIName}
${OPENGL_gl_LIBRARY}
${QT_LIBRARIES}
${QT_WEB_LIBRARIES}
${QGeoViewLibrary}
INSTALL_DIR
${TalipotViewPluginsInstallDir}
FIXUP_INSTALL)
22 changes: 11 additions & 11 deletions plugins/view/GeographicView/GeographicView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#include <talipot/FontIcon.h>
#include <talipot/MaterialDesignIcons.h>

#include <QDir>
#include <QNetworkDiskCache>
#include <QTimer>
#include <QGraphicsProxyWidget>

#include "GeographicView.h"
#include "GeographicViewGraphicsView.h"
Expand Down Expand Up @@ -183,20 +186,21 @@ void GeographicView::setState(const DataSet &dataSet) {
}

void GeographicView::initMap() {
geoViewGraphicsView->getLeafletMapsPage()->setMapCenter(mapCenterLatitudeInit,
mapCenterLongitudeInit);
geoViewGraphicsView->getLeafletMapsPage()->setCurrentZoom(mapZoomInit);
// geoViewGraphicsView->getLeafletMapsPage()->setMapCenter(mapCenterLatitudeInit,
// mapCenterLongitudeInit);
// geoViewGraphicsView->getLeafletMapsPage()->setCurrentZoom(mapZoomInit);
}

DataSet GeographicView::state() const {
DataSet dataSet = View::state();
DataSet configurationWidget = geoViewConfigWidget->state();
dataSet.set("configurationWidget", configurationWidget);
dataSet.set("viewType", int(_viewType));
pair<double, double> mapCenter = geoViewGraphicsView->getLeafletMapsPage()->getCurrentMapCenter();
dataSet.set("mapCenterLatitude", mapCenter.first);
dataSet.set("mapCenterLongitude", mapCenter.second);
dataSet.set("mapZoom", geoViewGraphicsView->getLeafletMapsPage()->getCurrentMapZoom());
// pair<double, double> mapCenter =
// geoViewGraphicsView->getLeafletMapsPage()->getCurrentMapCenter();
// dataSet.set("mapCenterLatitude", mapCenter.first);
// dataSet.set("mapCenterLongitude", mapCenter.second);
// dataSet.set("mapZoom", geoViewGraphicsView->getLeafletMapsPage()->getCurrentMapZoom());
dataSet.set("renderingParameters",
geoViewGraphicsView->glWidget()->renderingParameters().getParameters());

Expand Down Expand Up @@ -461,10 +465,6 @@ void GeographicView::graphChanged(Graph *graph) {
}
}

LeafletMaps *GeographicView::getLeafletMap() {
return geoViewGraphicsView->getLeafletMapsPage();
}

bool GeographicView::getNodeOrEdgeAtViewportPos(int x, int y, node &n, edge &e) const {
return GlView::getNodeOrEdgeAtViewportPos(geoViewGraphicsView->glWidget(), x, y, n, e);
}
Expand Down
3 changes: 0 additions & 3 deletions plugins/view/GeographicView/GeographicView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace tlp {
class GeographicViewGraphicsView;
class GeographicViewConfigWidget;
class GeolocationConfigWidget;
class LeafletMaps;

/** \file
* \brief Geographic View
Expand Down Expand Up @@ -98,8 +97,6 @@ class GeographicView : public View {

QGraphicsItem *centralItem() const override;

LeafletMaps *getLeafletMap();

void registerTriggers();

ViewType viewType() {
Expand Down
Loading

0 comments on commit f7de2bb

Please sign in to comment.