diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index 8f1cd53b3..868aa50ad 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -14,9 +14,6 @@ cmake ../source/ \ -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ - -DCMAKE_INSTALL_PREFIX=../install \ -DMLN_WITH_QT=ON \ - -DMLN_QT_IGNORE_ICU=OFF \ - -DMLN_QT_DEPLOYMENT=ON + -DMLN_QT_IGNORE_ICU=OFF ninja -ninja install diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index c3e8dd357..528d64e48 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -12,11 +12,6 @@ qt-cmake ../source/ \ -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ - -DCMAKE_INSTALL_PREFIX=../install \ -DMLN_WITH_QT=ON \ - -DMLN_QT_IGNORE_ICU=OFF \ - -DMLN_QT_DEPLOYMENT=ON + -DMLN_QT_IGNORE_ICU=OFF ninja -ninja install -cd ../install -ln -s lib64 lib diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index 4dde44b16..42a5eb22f 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -64,12 +64,6 @@ jobs: qt_version: 5.15.2 qt_target: desktop compiler: "" - - name: Linux - os: ubuntu-22.04 - build_type: RelWithDebInfo - qt_version: 6.5.3 - qt_target: desktop - compiler: "" - name: Linux_GCC13 os: ubuntu-22.04 build_type: RelWithDebInfo @@ -102,7 +96,7 @@ jobs: compiler: "llvm@17" - name: win64_msvc2019 os: windows-2022 - build_type: "RelWithDebInfo;Debug" + build_type: "RelWithDebInfo" compiler_type: x64 compiler_version: 14.29 qt_version: 5.15.2 @@ -111,31 +105,13 @@ jobs: qt_tools: "" - name: win64_msvc2019 os: windows-2022 - build_type: "RelWithDebInfo;Debug" + build_type: "RelWithDebInfo" compiler_type: x64 compiler_version: 14.29 qt_version: 6.5.3 qt_target: desktop qt_arch: win64_msvc2019_64 qt_tools: "" - - name: win64_mingw - os: windows-2022 - build_type: RelWithDebInfo - compiler_type: mingw810_64 - compiler_version: 8.10.0 - qt_version: 5.15.2 - qt_target: desktop - qt_arch: win64_mingw81 - qt_tools: tools_mingw,qt.tools.win64_mingw810 - - name: win64_mingw - os: windows-2022 - build_type: RelWithDebInfo - compiler_type: mingw1120_64 - compiler_version: 11.2.0 - qt_version: 6.5.3 - qt_target: desktop - qt_arch: win64_mingw - qt_tools: tools_mingw90 runs-on: ${{ matrix.os }} env: BUILD_TYPE: ${{ matrix.build_type }} @@ -159,6 +135,22 @@ jobs: git submodule sync --recursive git -c core.longpaths=true -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 || true + - name: Install test dependencies + if: runner.os == 'Linux' && matrix.compiler != '' + run: | + sudo apt-get install \ + libxkbcommon-x11-0 \ + libxcb-cursor0 \ + libxcb-icccm4 \ + libxcb-image0 \ + libxcb-keysyms1 \ + libxcb-randr0 \ + libxcb-render-util0 \ + libxcb-xinerama0 \ + libxcb-xfixes0 \ + libegl1-mesa \ + fonts-noto-cjk + - name: Install compiler id: install_compiler if: runner.os == 'Linux' && matrix.compiler != '' @@ -242,13 +234,10 @@ jobs: -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ - -DCMAKE_INSTALL_PREFIX="../install" \ -DCMAKE_OSX_DEPLOYMENT_TARGET="${DEPLOYMENT_TARGET}" \ -DCMAKE_OSX_ARCHITECTURES="${DEPLOYMENT_ARCH}" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON + -DMLN_WITH_QT=ON ninja - ninja install - name: Build maplibre-native (Linux, Qt5) if: runner.os == 'Linux' && matrix.qt_version == '5.15.2' @@ -267,13 +256,10 @@ jobs: -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ - -DCMAKE_INSTALL_PREFIX="../install" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON + -DMLN_WITH_QT=ON ninja - ninja install - - name: Build maplibre-native (Linux, Qt6, custom compiler) + - name: Build maplibre-native (Linux, Qt6, custom compiler, internal libraries) if: runner.os == 'Linux' && matrix.qt_version != '5.15.2' && matrix.compiler != '' run: | mkdir build-internal && cd build-internal @@ -283,11 +269,17 @@ jobs: -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON \ -DMLN_QT_WITH_INTERNAL_ICU=ON \ -DMLN_QT_WITH_INTERNAL_SQLITE=ON ninja + - name: Run tests (Linux) + if: runner.os == 'Linux' && matrix.qt_version != '5.15.2' && matrix.compiler != '' + uses: coactions/setup-xvfb@v1 + with: + run: ctest --output-on-failure + working-directory: build + - name: Build maplibre-native (Windows) if: runner.os == 'Windows' shell: bash @@ -300,112 +292,5 @@ jobs: -DCMAKE_CONFIGURATION_TYPES="${BUILD_TYPE}" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache.exe" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache.exe" \ - -DCMAKE_INSTALL_PREFIX="../install" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON + -DMLN_WITH_QT=ON ninja.exe - ninja.exe install - - - name: Create artifacts - shell: bash - env: - QT_ARCH: ${{ matrix.name }} - QT_VERSION: ${{ matrix.qt_version }} - run: | - pushd install - tar cjvf "../maplibre-native_${QT_ARCH}_Qt${QT_VERSION}.tar.bz2" ./* - popd - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }} - path: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }}.tar.bz2 - - test-tarball: - needs: build - strategy: - matrix: - include: - - name: Linux - os: ubuntu-22.04 - qt_version: 6.5.3 - qt_target: desktop - - name: macOS - os: macos-12 - qt_version: 6.5.3 - qt_target: desktop - runs-on: ${{ matrix.os }} - env: - QT_ARCH: ${{ matrix.name }} - QT_VERSION: ${{ matrix.qt_version }} - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 0 - - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }} - - - name: Download Qt - uses: jurplel/install-qt-action@v3 - with: - aqtversion: ==2.1.* - version: ${{ env.QT_VERSION }} - dir: ${{ github.workspace }} - target: ${{ matrix.qt_target }} - - - name: Setup Xcode - if: runner.os == 'macOS' - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: latest-stable - - - name: Build test app - run: | - mkdir install && cd install - tar xf "../maplibre-native_${QT_ARCH}_Qt${QT_VERSION}.tar.bz2" - cd .. - export CMAKE_PREFIX_PATH="$PWD/install" - mkdir build && cd build - cmake ../source/platform/qt/app/ - make - - release: - name: Release QMapLibreGL - if: github.ref_type == 'tag' - runs-on: ubuntu-22.04 - needs: test-tarball - strategy: - max-parallel: 1 - matrix: - name: [Linux, macOS, win64_msvc2019, win64_mingw] - qt_version: [5.15.2, 6.5.3] - permissions: - contents: write - - steps: - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: maplibre-native_${{ matrix.name }}_Qt${{ matrix.qt_version }} - - - name: Name tarball - env: - TAG_NAME: ${{ github.ref_name }} - TAG_PLATFORM: ${{ matrix.name }} - QT_VERSION: ${{ matrix.qt_version }} - run: | - mv "maplibre-native_${TAG_PLATFORM}_Qt${QT_VERSION}.tar.bz2" "QMapLibreGL_${TAG_NAME//qt-/}_Qt${QT_VERSION}_${TAG_PLATFORM}.tar.bz2" - - - name: Release - uses: ncipollo/release-action@v1 - with: - artifacts: QMapLibreGL_*.tar.bz2 - allowUpdates: true - draft: true diff --git a/.gitignore b/.gitignore index ed805de79..bf54006f5 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ .DS_Store .cache +compile_commands.json /build **/.idea /platform/android/MapboxGLAndroidSDKTestApp/local.properties diff --git a/platform/qt/CHANGELOG.md b/platform/qt/CHANGELOG.md index 5900dc639..8d6832fac 100644 --- a/platform/qt/CHANGELOG.md +++ b/platform/qt/CHANGELOG.md @@ -2,14 +2,8 @@ ## Upcoming -### ✨ New features - -- Support for GeoJSON feature collections using std::list ([#541](https://github.com/maplibre/maplibre-native/pull/541)). -- Based on Qt 6.5.0 - -### 🐞 Bug fixes - -- Fixed bitcode issues on iOS. +MapLibre native Qt bindings have been moved to +[maplibre-native-qt](https://github.com/maplibre/maplibre-native-qt) repository. ## v2.0.1 diff --git a/platform/qt/QMapLibreGLConfig.cmake.in b/platform/qt/QMapLibreGLConfig.cmake.in deleted file mode 100644 index d3ae5c80b..000000000 --- a/platform/qt/QMapLibreGLConfig.cmake.in +++ /dev/null @@ -1,15 +0,0 @@ -@PACKAGE_INIT@ - -include(CMakeFindDependencyMacro) -find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS Gui @REQUIRED_QT_VERSION@) -find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS Network @REQUIRED_QT_VERSION@) - -if(@MLN_QT_STATIC@ AND NOT @MLN_QT_INSIDE_PLUGIN@ AND NOT @MLN_QT_WITH_INTERNAL_SQLITE@) - find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS Sql @REQUIRED_QT_VERSION@) -endif() - -include("${CMAKE_CURRENT_LIST_DIR}/QMapLibreGLTargets.cmake") -@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/platform/qt/README.md b/platform/qt/README.md index 81c18376f..750f814f4 100644 --- a/platform/qt/README.md +++ b/platform/qt/README.md @@ -1,46 +1,8 @@ # MapLibre Native for Qt -[![GitHub Action build status](https://github.com/maplibre/maplibre-native/workflows/qt-ci/badge.svg)](https://github.com/maplibre/maplibre-native/actions/workflows/qt-ci.yml) +[![GitHub Action build status](https://github.com/maplibre/maplibre-native/workflows/qt-ci/badge.svg)](https://github.com/maplibre/maplibre-native/actions/workflows/qt-ci.yml) -This is a community maintained MapLibre SDK for usage in Qt apps. -Both Qt5 (minimal 5.6) and Qt6 are supported. -Note that only OpenGL rendering is supported at the moment. - -## Supported platforms - -- macOS -- iOS -- Android -- Linux -- Windows - -## Building - -This project uses out of source build. CMake 3.10 or later is used to generate -make files. Ninja is recommended. - -Before the project can be built Qt installation needs to be added to the `PATH`: - -```shell -export PATH=/Qt///bin:$PATH -``` - -A minimal set of commands to build and install is - -```shell -mkdir build && cd build -cmake ../maplibre-native/ \ - -GNinja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX= \ - -DMLN_WITH_QT=ON -ninja -ninja install -``` - -`` above should be replaced with a wished installation path. -Files installed there can later be used as the dependency for your app. - -For platform-specific details look at build scripts provided -in the [scripts](scripts) folder. Each script requires (at least) paths -to source and installation locations. +MapLibre native Qt bindings have been moved to +[maplibre-native-qt](https://github.com/maplibre/maplibre-native-qt) repository. +This folder only contains minimal platform-specific implementation and allows +sufficient testing of the MapLibre Core built with Qt as platform. diff --git a/platform/qt/VERSION b/platform/qt/VERSION deleted file mode 100644 index 38f77a65b..000000000 --- a/platform/qt/VERSION +++ /dev/null @@ -1 +0,0 @@ -2.0.1 diff --git a/platform/qt/app/CMakeLists.txt b/platform/qt/app/CMakeLists.txt deleted file mode 100644 index 48497ed13..000000000 --- a/platform/qt/app/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# minimal CMakeLists.txt for QMapLibreGL usage -cmake_minimum_required(VERSION 3.16) - -project(hellomaplibre VERSION 1.0.0 LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(APPLE) # suppress some warnings in Qt6 - set(CMAKE_CXX_VISIBILITY_PRESET hidden) -endif() - -find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGLWidgets Widgets) -qt_standard_project_setup() - -find_package(QMapLibreGL REQUIRED) - -add_executable(hellomaplibre - main.cpp - mapwindow.cpp - mapwindow.hpp -) - -target_link_libraries(hellomaplibre - PRIVATE - Qt6::Core - Qt6::Gui - Qt6::OpenGLWidgets - Qt6::Widgets - QMapLibreGL -) diff --git a/platform/qt/app/main.cpp b/platform/qt/app/main.cpp deleted file mode 100644 index ce19aeb0f..000000000 --- a/platform/qt/app/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "mapwindow.hpp" - -#include - -int main(int argc, char **argv) { - QApplication app(argc, argv); - - QMapLibreGL::Settings settings; - settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); - settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); - - settings.setClientName("TestApp"); - settings.setClientVersion("1.0"); - - MapWindow window(settings); - - window.resize(800, 600); - window.show(); - - if (argc == 2 && QString("--test") == argv[1]) { - window.selfTest(); - } - - return app.exec(); -} diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp deleted file mode 100644 index cf198bb6c..000000000 --- a/platform/qt/app/mapwindow.cpp +++ /dev/null @@ -1,474 +0,0 @@ -#include "mapwindow.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -int kAnimationDuration = 10000; - -MapWindow::MapWindow(const QMapLibreGL::Settings &settings) - : m_settings(settings) { - setWindowIcon(QIcon(":icon.png")); -} - -MapWindow::~MapWindow() { - // Make sure we have a valid context so we - // can delete the QMapLibreGL::Map. - makeCurrent(); -} - -void MapWindow::selfTest() { - if (m_bearingAnimation) { - m_bearingAnimation->setDuration(kAnimationDuration); - m_bearingAnimation->setEndValue(m_map->bearing() + 360 * 4); - m_bearingAnimation->start(); - } - - if (m_zoomAnimation) { - m_zoomAnimation->setDuration(kAnimationDuration); - m_zoomAnimation->setEndValue(m_map->zoom() + 3); - m_zoomAnimation->start(); - } -} - -qreal MapWindow::pixelRatio() { - return devicePixelRatioF(); -} - -void MapWindow::animationFinished() { - qDebug() << "Animation ticks/s: " << m_animationTicks / static_cast(kAnimationDuration) * 1000.; - qDebug() << "Frame draws/s: " << m_frameDraws / static_cast(kAnimationDuration) * 1000.; - - qApp->quit(); -} - -void MapWindow::animationValueChanged() { - m_animationTicks++; -} - -void MapWindow::changeStyle() { - static uint8_t currentStyleIndex; - - auto &styles = m_map->defaultStyles(); - - m_map->setStyleUrl(styles[currentStyleIndex].first); - setWindowTitle(QString("MapLibre Native: ") + styles[currentStyleIndex].second); - - if (++currentStyleIndex == styles.size()) { - currentStyleIndex = 0; - } - - m_sourceAdded = false; -} - -void MapWindow::keyPressEvent(QKeyEvent *ev) { - switch (ev->key()) { - case Qt::Key_S: - changeStyle(); - break; - case Qt::Key_L: { - if (m_sourceAdded) { - return; - } - - m_sourceAdded = true; - - // Not in all styles, but will work on streets - QString before = "waterway-label"; - - QFile geojson(":source1.geojson"); - geojson.open(QIODevice::ReadOnly); - - // The data source for the route line and markers - QVariantMap routeSource; - routeSource["type"] = "geojson"; - routeSource["data"] = geojson.readAll(); - m_map->addSource("routeSource", routeSource); - - // The route case, painted before the route - QVariantMap routeCase; - routeCase["id"] = "routeCase"; - routeCase["type"] = "line"; - routeCase["source"] = "routeSource"; - m_map->addLayer(routeCase, before); - - m_map->setPaintProperty("routeCase", "line-color", QColor("white")); - m_map->setPaintProperty("routeCase", "line-width", 20.0); - m_map->setLayoutProperty("routeCase", "line-join", "round"); - m_map->setLayoutProperty("routeCase", "line-cap", "round"); - - // The route, painted on top of the route case - QVariantMap route; - route["id"] = "route"; - route["type"] = "line"; - route["source"] = "routeSource"; - m_map->addLayer(route, before); - - m_map->setPaintProperty("route", "line-color", QColor("blue")); - m_map->setPaintProperty("route", "line-width", 8.0); - m_map->setLayoutProperty("route", "line-join", "round"); - m_map->setLayoutProperty("route", "line-cap", "round"); - - QVariantList lineDashArray; - lineDashArray.append(1); - lineDashArray.append(2); - - m_map->setPaintProperty("route", "line-dasharray", lineDashArray); - - // Markers at the beginning and end of the route - m_map->addImage("label-arrow", QImage(":label-arrow.svg")); - m_map->addImage("label-background", QImage(":label-background.svg")); - - QVariantMap markerArrow; - markerArrow["id"] = "markerArrow"; - markerArrow["type"] = "symbol"; - markerArrow["source"] = "routeSource"; - m_map->addLayer(markerArrow); - - m_map->setLayoutProperty("markerArrow", "icon-image", "label-arrow"); - m_map->setLayoutProperty("markerArrow", "icon-size", 0.5); - m_map->setLayoutProperty("markerArrow", "icon-ignore-placement", true); - - QVariantList arrowOffset; - arrowOffset.append(0.0); - arrowOffset.append(-15.0); - m_map->setLayoutProperty("markerArrow", "icon-offset", arrowOffset); - - QVariantMap markerBackground; - markerBackground["id"] = "markerBackground"; - markerBackground["type"] = "symbol"; - markerBackground["source"] = "routeSource"; - m_map->addLayer(markerBackground); - - m_map->setLayoutProperty("markerBackground", "icon-image", "label-background"); - m_map->setLayoutProperty("markerBackground", "text-field", "{name}"); - m_map->setLayoutProperty("markerBackground", "icon-text-fit", "both"); - m_map->setLayoutProperty("markerBackground", "icon-ignore-placement", true); - m_map->setLayoutProperty("markerBackground", "text-ignore-placement", true); - m_map->setLayoutProperty("markerBackground", "text-anchor", "left"); - m_map->setLayoutProperty("markerBackground", "text-size", 16.0); - m_map->setLayoutProperty("markerBackground", "text-padding", 0.0); - m_map->setLayoutProperty("markerBackground", "text-line-height", 1.0); - m_map->setLayoutProperty("markerBackground", "text-max-width", 8.0); - - QVariantList iconTextFitPadding; - iconTextFitPadding.append(15.0); - iconTextFitPadding.append(10.0); - iconTextFitPadding.append(15.0); - iconTextFitPadding.append(10.0); - m_map->setLayoutProperty("markerBackground", "icon-text-fit-padding", iconTextFitPadding); - - QVariantList backgroundOffset; - backgroundOffset.append(-0.5); - backgroundOffset.append(-1.5); - m_map->setLayoutProperty("markerBackground", "text-offset", backgroundOffset); - - m_map->setPaintProperty("markerBackground", "text-color", QColor("white")); - - QVariantList filterExpression; - filterExpression.append("=="); - filterExpression.append("$type"); - filterExpression.append("Point"); - - QVariantList filter; - filter.append(filterExpression); - - m_map->setFilter("markerArrow", filter); - m_map->setFilter("markerBackground", filter); - - // Tilt the labels when tilting the map and make them larger - m_map->setLayoutProperty("road-label-large", "text-size", 30.0); - m_map->setLayoutProperty("road-label-large", "text-pitch-alignment", "viewport"); - - m_map->setLayoutProperty("road-label-medium", "text-size", 30.0); - m_map->setLayoutProperty("road-label-medium", "text-pitch-alignment", "viewport"); - - m_map->setLayoutProperty("road-label-small", "text-pitch-alignment", "viewport"); - m_map->setLayoutProperty("road-label-small", "text-size", 30.0); - - // Buildings extrusion - QVariantMap buildings; - buildings["id"] = "3d-buildings"; - buildings["source"] = "composite"; - buildings["source-layer"] = "building"; - buildings["type"] = "fill-extrusion"; - buildings["minzoom"] = 15.0; - m_map->addLayer(buildings); - - QVariantList buildingsFilterExpression; - buildingsFilterExpression.append("=="); - buildingsFilterExpression.append("extrude"); - buildingsFilterExpression.append("true"); - - QVariantList buildingsFilter; - buildingsFilter.append(buildingsFilterExpression); - - m_map->setFilter("3d-buildings", buildingsFilterExpression); - - QString fillExtrusionColorJSON = R"JSON( - [ - "interpolate", - ["linear"], - ["get", "height"], - 0.0, "blue", - 20.0, "royalblue", - 40.0, "cyan", - 60.0, "lime", - 80.0, "yellow", - 100.0, "red" - ] - )JSON"; - - m_map->setPaintProperty("3d-buildings", "fill-extrusion-color", fillExtrusionColorJSON); - m_map->setPaintProperty("3d-buildings", "fill-extrusion-opacity", .6); - - QVariantMap extrusionHeight; - extrusionHeight["type"] = "identity"; - extrusionHeight["property"] = "height"; - - m_map->setPaintProperty("3d-buildings", "fill-extrusion-height", extrusionHeight); - - QVariantMap extrusionBase; - extrusionBase["type"] = "identity"; - extrusionBase["property"] = "min_height"; - - m_map->setPaintProperty("3d-buildings", "fill-extrusion-base", extrusionBase); - } break; - case Qt::Key_1: { - if (m_symbolAnnotationId.isNull()) { - QMapLibreGL::Coordinate coordinate = m_map->coordinate(); - QMapLibreGL::SymbolAnnotation symbol{coordinate, "default_marker"}; - m_map->addAnnotationIcon("default_marker", QImage(":default_marker.svg")); - m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue(symbol)); - } else { - m_map->removeAnnotation(m_symbolAnnotationId.toUInt()); - m_symbolAnnotationId.clear(); - } - } break; - case Qt::Key_2: { - if (m_lineAnnotationId.isNull()) { - QMapLibreGL::Coordinates coordinates; - coordinates.push_back(m_map->coordinateForPixel({0, 0})); - coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), qreal(size().height())})); - - QMapLibreGL::CoordinatesCollection collection; - collection.push_back(coordinates); - - QMapLibreGL::CoordinatesCollections lineGeometry; - lineGeometry.push_back(collection); - - QMapLibreGL::ShapeAnnotationGeometry annotationGeometry( - QMapLibreGL::ShapeAnnotationGeometry::LineStringType, lineGeometry); - - QMapLibreGL::LineAnnotation line; - line.geometry = annotationGeometry; - line.opacity = 0.5f; - line.width = 1.0f; - line.color = Qt::red; - m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue(line)); - } else { - m_map->removeAnnotation(m_lineAnnotationId.toUInt()); - m_lineAnnotationId.clear(); - } - } break; - case Qt::Key_3: { - if (m_fillAnnotationId.isNull()) { - QMapLibreGL::Coordinates coordinates; - coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), 0})); - coordinates.push_back(m_map->coordinateForPixel({qreal(size().width()), qreal(size().height())})); - coordinates.push_back(m_map->coordinateForPixel({0, qreal(size().height())})); - coordinates.push_back(m_map->coordinateForPixel({0, 0})); - - QMapLibreGL::CoordinatesCollection collection; - collection.push_back(coordinates); - - QMapLibreGL::CoordinatesCollections fillGeometry; - fillGeometry.push_back(collection); - - QMapLibreGL::ShapeAnnotationGeometry annotationGeometry( - QMapLibreGL::ShapeAnnotationGeometry::PolygonType, fillGeometry); - - QMapLibreGL::FillAnnotation fill; - fill.geometry = annotationGeometry; - fill.opacity = 0.5f; - fill.color = Qt::green; - fill.outlineColor = QVariant::fromValue(QColor(Qt::black)); - m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue(fill)); - } else { - m_map->removeAnnotation(m_fillAnnotationId.toUInt()); - m_fillAnnotationId.clear(); - } - } break; - case Qt::Key_5: { - if (m_map->layerExists("circleLayer")) { - m_map->removeLayer("circleLayer"); - m_map->removeSource("circleSource"); - } else { - QMapLibreGL::Coordinates coordinates; - coordinates.push_back(m_map->coordinate()); - - QMapLibreGL::CoordinatesCollection collection; - collection.push_back(coordinates); - - QMapLibreGL::CoordinatesCollections point; - point.push_back(collection); - - QMapLibreGL::Feature feature(QMapLibreGL::Feature::PointType, point, {}, {}); - - QVariantMap circleSource; - circleSource["type"] = "geojson"; - circleSource["data"] = QVariant::fromValue(feature); - m_map->addSource("circleSource", circleSource); - - QVariantMap circle; - circle["id"] = "circleLayer"; - circle["type"] = "circle"; - circle["source"] = "circleSource"; - m_map->addLayer(circle); - - m_map->setPaintProperty("circleLayer", "circle-radius", 10.0); - m_map->setPaintProperty("circleLayer", "circle-color", QColor("black")); - } - } break; - case Qt::Key_6: { - if (m_map->layerExists("innerCirclesLayer") || m_map->layerExists("outerCirclesLayer")) { - m_map->removeLayer("innerCirclesLayer"); - m_map->removeLayer("outerCirclesLayer"); - m_map->removeSource("innerCirclesSource"); - m_map->removeSource("outerCirclesSource"); - } else { - auto makePoint = [&](double dx, double dy, const QString &color) { - auto coordinate = m_map->coordinate(); - coordinate.first += dx; - coordinate.second += dy; - return QMapLibreGL::Feature{ - QMapLibreGL::Feature::PointType, {{{coordinate}}}, {{"color", color}}, {}}; - }; - - // multiple features by QVector - QVector inner{ - makePoint(0.001, 0, "red"), makePoint(0, 0.001, "green"), makePoint(0, -0.001, "blue")}; - - m_map->addSource("innerCirclesSource", {{"type", "geojson"}, {"data", QVariant::fromValue(inner)}}); - m_map->addLayer({{"id", "innerCirclesLayer"}, {"type", "circle"}, {"source", "innerCirclesSource"}}); - - // multiple features by QList - QList outer{makePoint(0.002, 0.002, "cyan"), - makePoint(-0.002, 0.002, "magenta"), - makePoint(0.002, -0.002, "yellow"), - makePoint(-0.002, -0.002, "black")}; - - m_map->addSource("outerCirclesSource", {{"type", "geojson"}, {"data", QVariant::fromValue(outer)}}); - m_map->addLayer({{"id", "outerCirclesLayer"}, {"type", "circle"}, {"source", "outerCirclesSource"}}); - - QVariantList getColor{"get", "color"}; - m_map->setPaintProperty("innerCirclesLayer", "circle-radius", 10.0); - m_map->setPaintProperty("innerCirclesLayer", "circle-color", getColor); - m_map->setPaintProperty("outerCirclesLayer", "circle-radius", 15.0); - m_map->setPaintProperty("outerCirclesLayer", "circle-color", getColor); - } - } break; - default: - break; - } - - ev->accept(); -} - -void MapWindow::mousePressEvent(QMouseEvent *ev) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - m_lastPos = ev->position(); -#else - m_lastPos = ev->localPos(); -#endif - - if (ev->type() == QEvent::MouseButtonPress) { - if (ev->buttons() == (Qt::LeftButton | Qt::RightButton)) { - changeStyle(); - } - } - - if (ev->type() == QEvent::MouseButtonDblClick) { - if (ev->buttons() == Qt::LeftButton) { - m_map->scaleBy(2.0, m_lastPos); - } else if (ev->buttons() == Qt::RightButton) { - m_map->scaleBy(0.5, m_lastPos); - } - } - - ev->accept(); -} - -void MapWindow::mouseMoveEvent(QMouseEvent *ev) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - const QPointF &position = ev->position(); -#else - const QPointF &position = ev->localPos(); -#endif - - QPointF delta = position - m_lastPos; - if (!delta.isNull()) { - if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) { - m_map->pitchBy(delta.y()); - } else if (ev->buttons() == Qt::LeftButton) { - m_map->moveBy(delta); - } else if (ev->buttons() == Qt::RightButton) { - m_map->rotateBy(m_lastPos, position); - } - } - - m_lastPos = position; - ev->accept(); -} - -void MapWindow::wheelEvent(QWheelEvent *ev) { - if (ev->angleDelta().y() == 0) { - return; - } - - float factor = ev->angleDelta().y() / 1200.; - if (ev->angleDelta().y() < 0) { - factor = factor > -1 ? factor : 1 / factor; - } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - m_map->scaleBy(1 + factor, ev->position()); -#else - m_map->scaleBy(1 + factor, ev->pos()); -#endif - ev->accept(); -} - -void MapWindow::initializeGL() { - m_map.reset(new QMapLibreGL::Map(nullptr, m_settings, size(), pixelRatio())); - connect(m_map.get(), SIGNAL(needsRendering()), this, SLOT(update())); - - // Set default location to Helsinki. - m_map->setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 5); - - QString styleUrl = qgetenv("MLN_STYLE_URL"); - if (styleUrl.isEmpty()) { - changeStyle(); - } else { - m_map->setStyleUrl(styleUrl); - setWindowTitle(QString("MapLibre Native: ") + styleUrl); - } - - m_bearingAnimation = new QPropertyAnimation(m_map.get(), "bearing"); - m_zoomAnimation = new QPropertyAnimation(m_map.get(), "zoom"); - - connect(m_zoomAnimation, &QPropertyAnimation::finished, this, &MapWindow::animationFinished); - connect(m_zoomAnimation, &QPropertyAnimation::valueChanged, this, &MapWindow::animationValueChanged); -} - -void MapWindow::paintGL() { - m_frameDraws++; - m_map->resize(size()); - m_map->setFramebufferObject(defaultFramebufferObject(), size() * pixelRatio()); - m_map->render(); -} diff --git a/platform/qt/app/mapwindow.hpp b/platform/qt/app/mapwindow.hpp deleted file mode 100644 index d03483356..000000000 --- a/platform/qt/app/mapwindow.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef MAPWINDOW_H -#define MAPWINDOW_H - -#include -#include - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -class QKeyEvent; -class QMouseEvent; -class QWheelEvent; - -QT_END_NAMESPACE - -class MapWindow : public QOpenGLWidget { - Q_OBJECT - -public: - MapWindow(const QMapLibreGL::Settings &); - ~MapWindow(); - - void selfTest(); - -protected slots: - void animationValueChanged(); - void animationFinished(); - -private: - void changeStyle(); - qreal pixelRatio(); - - // QWidget implementation. - void keyPressEvent(QKeyEvent *ev) final; - void mousePressEvent(QMouseEvent *ev) final; - void mouseMoveEvent(QMouseEvent *ev) final; - void wheelEvent(QWheelEvent *ev) final; - - // Q{,Open}GLWidget implementation. - void initializeGL() final; - void paintGL() final; - - QPointF m_lastPos; - - QMapLibreGL::Settings m_settings; - std::unique_ptr m_map{}; - - QPropertyAnimation *m_bearingAnimation{}; - QPropertyAnimation *m_zoomAnimation{}; - - unsigned m_animationTicks{}; - unsigned m_frameDraws{}; - - QVariant m_symbolAnnotationId; - QVariant m_lineAnnotationId; - QVariant m_fillAnnotationId; - - bool m_sourceAdded{}; -}; - -#endif diff --git a/platform/qt/config.qdocconf b/platform/qt/config.qdocconf deleted file mode 100644 index e6275f89b..000000000 --- a/platform/qt/config.qdocconf +++ /dev/null @@ -1,19 +0,0 @@ -include($QT_INSTALL_DOCS/global/macros.qdocconf) -include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf) -include($QT_INSTALL_DOCS/global/compat.qdocconf) -include($QT_INSTALL_DOCS/global/fileextensions.qdocconf) -include($QT_INSTALL_DOCS/global/qt-html-templates-online.qdocconf) - -Cpp.ignoretokens = Q_MAPLIBRE_EXPORT - -project = QMapLibreGL -description = MapLibre Native SDK for Qt -language = Cpp - -outputdir = docs -headerdirs += include -sourcedirs += src - -indexes = $QT_INSTALL_DOCS/qtcore/qtcore.index \ - $QT_INSTALL_DOCS/qtgui/qtgui.index \ - $QT_INSTALL_DOCS/qtnetwork/qtnetwork.index diff --git a/platform/qt/include/QMapLibreGL/Map b/platform/qt/include/QMapLibreGL/Map deleted file mode 100644 index 37ff787a6..000000000 --- a/platform/qt/include/QMapLibreGL/Map +++ /dev/null @@ -1 +0,0 @@ -#include "map.hpp" diff --git a/platform/qt/include/QMapLibreGL/QMapLibreGL b/platform/qt/include/QMapLibreGL/QMapLibreGL deleted file mode 100644 index 51045b443..000000000 --- a/platform/qt/include/QMapLibreGL/QMapLibreGL +++ /dev/null @@ -1,5 +0,0 @@ -#include "export.hpp" -#include "map.hpp" -#include "settings.hpp" -#include "types.hpp" -#include "utils.hpp" diff --git a/platform/qt/include/QMapLibreGL/Settings b/platform/qt/include/QMapLibreGL/Settings deleted file mode 100644 index 4f6be8538..000000000 --- a/platform/qt/include/QMapLibreGL/Settings +++ /dev/null @@ -1 +0,0 @@ -#include "settings.hpp" diff --git a/platform/qt/include/QMapLibreGL/Types b/platform/qt/include/QMapLibreGL/Types deleted file mode 100644 index 0be9e32cf..000000000 --- a/platform/qt/include/QMapLibreGL/Types +++ /dev/null @@ -1 +0,0 @@ -#include "types.hpp" diff --git a/platform/qt/include/QMapLibreGL/Utils b/platform/qt/include/QMapLibreGL/Utils deleted file mode 100644 index 0ee624c51..000000000 --- a/platform/qt/include/QMapLibreGL/Utils +++ /dev/null @@ -1 +0,0 @@ -#include "utils.hpp" diff --git a/platform/qt/include/QMapLibreGL/export.hpp b/platform/qt/include/QMapLibreGL/export.hpp deleted file mode 100644 index 4017e5dc4..000000000 --- a/platform/qt/include/QMapLibreGL/export.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef QMAPLIBRE_EXPORT_H -#define QMAPLIBRE_EXPORT_H - -// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style - -#if !defined(QT_MAPLIBREGL_STATIC) -#if defined(QT_BUILD_MAPLIBREGL_LIB) -#define Q_MAPLIBREGL_EXPORT Q_DECL_EXPORT -#else -#define Q_MAPLIBREGL_EXPORT Q_DECL_IMPORT -#endif -#else -#define Q_MAPLIBREGL_EXPORT -#endif - -#endif // QMAPLIBRE_EXPORT_H diff --git a/platform/qt/include/QMapLibreGL/map.hpp b/platform/qt/include/QMapLibreGL/map.hpp deleted file mode 100644 index a8f560e57..000000000 --- a/platform/qt/include/QMapLibreGL/map.hpp +++ /dev/null @@ -1,197 +0,0 @@ -#ifndef QMAPLIBREGL_MAP_H -#define QMAPLIBREGL_MAP_H - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace QMapLibreGL { - -class MapPrivate; - -// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style - -class Q_MAPLIBREGL_EXPORT Map : public QObject { - Q_OBJECT - Q_PROPERTY(double latitude READ latitude WRITE setLatitude) - Q_PROPERTY(double longitude READ longitude WRITE setLongitude) - Q_PROPERTY(double zoom READ zoom WRITE setZoom) - Q_PROPERTY(double bearing READ bearing WRITE setBearing) - Q_PROPERTY(double pitch READ pitch WRITE setPitch) - Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson) - Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl) - Q_PROPERTY(double scale READ scale WRITE setScale) - Q_PROPERTY(QMapLibreGL::Coordinate coordinate READ coordinate WRITE setCoordinate) - Q_PROPERTY(QMargins margins READ margins WRITE setMargins) - -public: - enum MapChange { - MapChangeRegionWillChange = 0, - MapChangeRegionWillChangeAnimated, - MapChangeRegionIsChanging, - MapChangeRegionDidChange, - MapChangeRegionDidChangeAnimated, - MapChangeWillStartLoadingMap, - MapChangeDidFinishLoadingMap, - MapChangeDidFailLoadingMap, - MapChangeWillStartRenderingFrame, - MapChangeDidFinishRenderingFrame, - MapChangeDidFinishRenderingFrameFullyRendered, - MapChangeWillStartRenderingMap, - MapChangeDidFinishRenderingMap, - MapChangeDidFinishRenderingMapFullyRendered, - MapChangeDidFinishLoadingStyle, - MapChangeSourceDidChange - }; - - enum MapLoadingFailure { - StyleParseFailure, - StyleLoadFailure, - NotFoundFailure, - UnknownFailure - }; - - // Determines the orientation of the map. - enum NorthOrientation { - NorthUpwards, // Default - NorthRightwards, - NorthDownwards, - NorthLeftwards, - }; - - Map(QObject *parent = 0, const Settings & = Settings(), const QSize &size = QSize(), qreal pixelRatio = 1); - virtual ~Map(); - - QString styleJson() const; - QString styleUrl() const; - - void setStyleJson(const QString &); - void setStyleUrl(const QString &); - - double latitude() const; - void setLatitude(double latitude); - - double longitude() const; - void setLongitude(double longitude); - - double scale() const; - void setScale(double scale, const QPointF ¢er = QPointF()); - - double zoom() const; - void setZoom(double zoom); - - double minimumZoom() const; - double maximumZoom() const; - - double bearing() const; - void setBearing(double degrees); - void setBearing(double degrees, const QPointF ¢er); - - double pitch() const; - void setPitch(double pitch); - void pitchBy(double pitch); - - NorthOrientation northOrientation() const; - void setNorthOrientation(NorthOrientation); - - Coordinate coordinate() const; - void setCoordinate(const Coordinate &); - void setCoordinateZoom(const Coordinate &, double zoom); - - void jumpTo(const CameraOptions &); - - void setGestureInProgress(bool inProgress); - - void setTransitionOptions(qint64 duration, qint64 delay = 0); - - void addAnnotationIcon(const QString &name, const QImage &sprite); - - AnnotationID addAnnotation(const Annotation &); - void updateAnnotation(AnnotationID, const Annotation &); - void removeAnnotation(AnnotationID); - - bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value); - bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value); - - bool isFullyLoaded() const; - - void moveBy(const QPointF &offset); - void scaleBy(double scale, const QPointF ¢er = QPointF()); - void rotateBy(const QPointF &first, const QPointF &second); - - void resize(const QSize &size); - - QPointF pixelForCoordinate(const Coordinate &) const; - Coordinate coordinateForPixel(const QPointF &) const; - - CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne) const; - CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne, double bearing, double pitch); - - void setMargins(const QMargins &margins); - QMargins margins() const; - - void addSource(const QString &sourceID, const QVariantMap ¶ms); - bool sourceExists(const QString &sourceID); - void updateSource(const QString &sourceID, const QVariantMap ¶ms); - void removeSource(const QString &sourceID); - - void addImage(const QString &name, const QImage &sprite); - void removeImage(const QString &name); - - void addCustomLayer(const QString &id, - std::unique_ptr host, - const QString &before = QString()); - void addLayer(const QVariantMap ¶ms, const QString &before = QString()); - bool layerExists(const QString &id); - void removeLayer(const QString &id); - - QVector layerIds() const; - - void setFilter(const QString &layer, const QVariant &filter); - QVariant getFilter(const QString &layer) const; - // When rendering on a different thread, - // should be called on the render thread. - void createRenderer(); - void destroyRenderer(); - void setFramebufferObject(quint32 fbo, const QSize &size); - - const QVector> &defaultStyles() const; - -public slots: - void render(); - void connectionEstablished(); - - // Commit changes, load all the resources - // and renders the map when completed. - void startStaticRender(); - -signals: - void needsRendering(); - void mapChanged(Map::MapChange); - void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason); - void copyrightsChanged(const QString ©rightsHtml); - - void staticRenderFinished(const QString &error); - -private: - Q_DISABLE_COPY(Map) - - MapPrivate *d_ptr; -}; - -} // namespace QMapLibreGL - -Q_DECLARE_METATYPE(QMapLibreGL::Map::MapChange); -Q_DECLARE_METATYPE(QMapLibreGL::Map::MapLoadingFailure); - -#endif // QMAPLIBREGL_MAP_H diff --git a/platform/qt/include/QMapLibreGL/settings.hpp b/platform/qt/include/QMapLibreGL/settings.hpp deleted file mode 100644 index 6ffdde823..000000000 --- a/platform/qt/include/QMapLibreGL/settings.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef QMAPLIBREGL_SETTINGS_H -#define QMAPLIBREGL_SETTINGS_H - -#include -#include - -#include - -#include "export.hpp" - -// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style - -// TODO: this will be wrapped at some point -namespace mbgl { -class TileServerOptions; -} - -namespace QMapLibreGL { - -class Q_MAPLIBREGL_EXPORT Settings { -public: - Settings(); - - enum GLContextMode { - UniqueGLContext = 0, - SharedGLContext - }; - - enum MapMode { - Continuous = 0, - Static - }; - - enum ConstrainMode { - NoConstrain = 0, - ConstrainHeightOnly, - ConstrainWidthAndHeight - }; - - enum ViewportMode { - DefaultViewport = 0, - FlippedYViewport - }; - - enum SettingsTemplate { - DefaultSettings = 0, - MapLibreSettings, - MapTilerSettings, - MapboxSettings - }; - - GLContextMode contextMode() const; - void setContextMode(GLContextMode); - - MapMode mapMode() const; - void setMapMode(MapMode); - - ConstrainMode constrainMode() const; - void setConstrainMode(ConstrainMode); - - ViewportMode viewportMode() const; - void setViewportMode(ViewportMode); - - unsigned cacheDatabaseMaximumSize() const; - void setCacheDatabaseMaximumSize(unsigned); - - QString cacheDatabasePath() const; - void setCacheDatabasePath(const QString &); - - QString assetPath() const; - void setAssetPath(const QString &); - - QString apiKey() const; - void setApiKey(const QString &); - - QString apiBaseUrl() const; - void setApiBaseUrl(const QString &); - - QString localFontFamily() const; - void setLocalFontFamily(const QString &); - - QString clientName() const; - void setClientName(const QString &); - - QString clientVersion() const; - void setClientVersion(const QString &); - - std::function resourceTransform() const; - void setResourceTransform(const std::function &); - - void resetToTemplate(SettingsTemplate); - - QVector> defaultStyles() const; - - mbgl::TileServerOptions *tileServerOptionsInternal() const; - -private: - GLContextMode m_contextMode; - MapMode m_mapMode; - ConstrainMode m_constrainMode; - ViewportMode m_viewportMode; - - unsigned m_cacheMaximumSize; - QString m_cacheDatabasePath; - QString m_assetPath; - QString m_apiKey; - QString m_localFontFamily; - QString m_clientName; - QString m_clientVersion; - std::function m_resourceTransform; - - mbgl::TileServerOptions *m_tileServerOptionsInternal{}; -}; - -} // namespace QMapLibreGL - -#endif // QMAPLIBREGL_SETTINGS_H diff --git a/platform/qt/include/QMapLibreGL/types.hpp b/platform/qt/include/QMapLibreGL/types.hpp deleted file mode 100644 index 486326993..000000000 --- a/platform/qt/include/QMapLibreGL/types.hpp +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef QMAPLIBREGL_TYPES_H -#define QMAPLIBREGL_TYPES_H - -#include -#include -#include -#include -#include - -#include "export.hpp" - -namespace QMapLibreGL { - -typedef QPair Coordinate; -typedef QPair CoordinateZoom; -typedef QPair ProjectedMeters; - -typedef QVector Coordinates; -typedef QVector CoordinatesCollection; - -typedef QVector CoordinatesCollections; - -struct Q_MAPLIBREGL_EXPORT Feature { - enum Type { - PointType = 1, - LineStringType, - PolygonType - }; - - /*! Class constructor. */ - Feature(Type type_ = PointType, - const CoordinatesCollections& geometry_ = CoordinatesCollections(), - const QVariantMap& properties_ = QVariantMap(), - const QVariant& id_ = QVariant()) - : type(type_), - geometry(geometry_), - properties(properties_), - id(id_) {} - - Type type; - CoordinatesCollections geometry; - QVariantMap properties; - QVariant id; -}; - -struct Q_MAPLIBREGL_EXPORT ShapeAnnotationGeometry { - enum Type { - LineStringType = 1, - PolygonType, - MultiLineStringType, - MultiPolygonType - }; - - /*! Class constructor. */ - ShapeAnnotationGeometry(Type type_ = LineStringType, - const CoordinatesCollections& geometry_ = CoordinatesCollections()) - : type(type_), - geometry(geometry_) {} - - Type type; - CoordinatesCollections geometry; -}; - -struct Q_MAPLIBREGL_EXPORT SymbolAnnotation { - Coordinate geometry; - QString icon; -}; - -struct Q_MAPLIBREGL_EXPORT LineAnnotation { - /*! Class constructor. */ - LineAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), - float opacity_ = 1.0f, - float width_ = 1.0f, - const QColor& color_ = Qt::black) - : geometry(geometry_), - opacity(opacity_), - width(width_), - color(color_) {} - - ShapeAnnotationGeometry geometry; - float opacity; - float width; - QColor color; -}; - -struct Q_MAPLIBREGL_EXPORT FillAnnotation { - /*! Class constructor. */ - FillAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), - float opacity_ = 1.0f, - const QColor& color_ = Qt::black, - const QVariant& outlineColor_ = QVariant()) - : geometry(geometry_), - opacity(opacity_), - color(color_), - outlineColor(outlineColor_) {} - - ShapeAnnotationGeometry geometry; - float opacity; - QColor color; - QVariant outlineColor; -}; - -typedef QVariant Annotation; -typedef quint32 AnnotationID; -typedef QVector AnnotationIDs; - -struct Q_MAPLIBREGL_EXPORT CameraOptions { - QVariant center; // Coordinate - QVariant anchor; // QPointF - QVariant zoom; // double - QVariant bearing; // double - QVariant pitch; // double -}; - -// This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters. -struct Q_MAPLIBREGL_EXPORT CustomLayerRenderParameters { - double width; - double height; - double latitude; - double longitude; - double zoom; - double bearing; - double pitch; - double fieldOfView; -}; - -class Q_MAPLIBREGL_EXPORT CustomLayerHostInterface { -public: - virtual ~CustomLayerHostInterface() = default; - virtual void initialize() = 0; - virtual void render(const CustomLayerRenderParameters&) = 0; - virtual void deinitialize() = 0; -}; - -} // namespace QMapLibreGL - -Q_DECLARE_METATYPE(QMapLibreGL::Coordinate); -Q_DECLARE_METATYPE(QMapLibreGL::Coordinates); -Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollection); -Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollections); -Q_DECLARE_METATYPE(QMapLibreGL::Feature); - -Q_DECLARE_METATYPE(QMapLibreGL::SymbolAnnotation); -Q_DECLARE_METATYPE(QMapLibreGL::ShapeAnnotationGeometry); -Q_DECLARE_METATYPE(QMapLibreGL::LineAnnotation); -Q_DECLARE_METATYPE(QMapLibreGL::FillAnnotation); - -#endif // QMAPLIBREGL_TYPES_H diff --git a/platform/qt/include/QMapLibreGL/utils.hpp b/platform/qt/include/QMapLibreGL/utils.hpp deleted file mode 100644 index a1143a041..000000000 --- a/platform/qt/include/QMapLibreGL/utils.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef QMAPLIBREGL_UTILS_H -#define QMAPLIBREGL_UTILS_H - -#include "export.hpp" -#include "types.hpp" - -// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style - -namespace QMapLibreGL { - -enum NetworkMode { - Online, // Default - Offline, -}; - -Q_MAPLIBREGL_EXPORT NetworkMode networkMode(); -Q_MAPLIBREGL_EXPORT void setNetworkMode(NetworkMode); - -Q_MAPLIBREGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom); -Q_MAPLIBREGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &); -Q_MAPLIBREGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &); - -} // namespace QMapLibreGL - -#endif // QMAPLIBREGL_UTILS_H diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 22dbf45f8..8577648b8 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -1,16 +1,7 @@ -message(STATUS "Configuring GL-Native with Qt bindings") +message(STATUS "Configuring MapLibre Native with Qt platform") -file(READ "${PROJECT_SOURCE_DIR}/platform/qt/VERSION" MLN_QT_VERSION) -string(REGEX REPLACE "\n" "" MLN_QT_VERSION "${MLN_QT_VERSION}") # get rid of the newline at the end -set(MLN_QT_VERSION_COMPATIBILITY 2.0.0) -message(STATUS "Version ${MLN_QT_VERSION}") - -option(MLN_QT_LIBRARY_ONLY "Build only libraries" OFF) -option(MLN_QT_STATIC "Build MapLibre Native Qt bindings staticly" OFF) -option(MLN_QT_INSIDE_PLUGIN "Build QMapLibreGL as OBJECT library, so it can be bundled into separate single plugin lib." OFF) -option(MLN_QT_WITH_HEADLESS "Build MapLibre Native Qt with headless support" ON) +option(MLN_QT_LIBRARY_ONLY "Build only MapLibre Native Qt bindings libraries" OFF) option(MLN_QT_WITH_INTERNAL_SQLITE "Build MapLibre Native Qt bindings with internal sqlite" OFF) -option(MLN_QT_DEPLOYMENT "Autogenerate files necessary for deployment" OFF) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") find_package(Threads REQUIRED) @@ -46,13 +37,6 @@ find_package(Qt${QT_VERSION_MAJOR} Network REQUIRED) -if(NOT MLN_QT_LIBRARY_ONLY) - find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) - if (Qt6_FOUND) - find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED) - endif() -endif() - if(NOT MLN_QT_WITH_INTERNAL_SQLITE) find_package(Qt${QT_VERSION_MAJOR}Sql REQUIRED) else() @@ -71,15 +55,6 @@ if (MSVC) endforeach() endif() -if(ANDROID) - message(STATUS "Building for ABI: ${ANDROID_ABI}") - set(CMAKE_STATIC_LIBRARY_SUFFIX "_${ANDROID_ABI}.a") -elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) - set(CMAKE_DEBUG_POSTFIX "_debug") -elseif(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Windows") - set(CMAKE_DEBUG_POSTFIX "d") -endif() - target_sources( mbgl-core PRIVATE @@ -109,10 +84,10 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/filesystem.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/monotonic_timer.cpp - $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/headless_backend_qt.cpp> ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task.cpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task_impl.hpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/gl_functions.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/headless_backend_qt.cpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.hpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_request.cpp @@ -129,6 +104,11 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer.cpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer_impl.hpp ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/utf.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.hpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_observer.hpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.hpp ) target_compile_definitions( @@ -142,7 +122,6 @@ target_include_directories( PRIVATE ${PROJECT_SOURCE_DIR}/platform/default/include ) -include(GNUInstallDirs) include(${PROJECT_SOURCE_DIR}/vendor/nunicode.cmake) set_property(TARGET mbgl-core PROPERTY AUTOMOC ON) @@ -165,221 +144,29 @@ target_link_libraries( Qt${QT_VERSION_MAJOR}::Network ) -# Interface library for object linking -add_library(mbgl-core-interface INTERFACE) -target_link_libraries( - mbgl-core-interface - INTERFACE - $ $ - $ $ - $ $ - $ $ - $<$:$> - $<$:$> -) -export(TARGETS mbgl-core-interface FILE MapboxCoreTargets.cmake APPEND) - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if (MLN_QT_WITH_INTERNAL_ICU) target_link_libraries(mbgl-core PUBLIC $) - target_link_libraries(mbgl-core-interface INTERFACE $ $) else() target_link_libraries(mbgl-core PUBLIC ICU::uc) endif() endif() -set(qmaplibregl_headers - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/QMapLibreGL - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/export.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/map.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Map - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/settings.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Settings - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/types.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Types - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/utils.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Utils -) - -if (MLN_QT_INSIDE_PLUGIN) - add_library(qmaplibregl OBJECT) -elseif(MLN_QT_STATIC) - add_library(qmaplibregl STATIC) -else() - add_library(qmaplibregl SHARED) -endif() - -target_sources( - qmaplibregl - PRIVATE - ${qmaplibregl_headers} - ${PROJECT_SOURCE_DIR}/platform/qt/src/map.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/map_p.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/settings.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/types.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_observer.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/conversion.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.hpp -) - -# Linux/Mac: Set framework, version and headers -set_target_properties( - qmaplibregl PROPERTIES - AUTOMOC ON - EXPORT_NAME QMapLibreGL - OUTPUT_NAME QMapLibreGL - VERSION ${MLN_QT_VERSION} - SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} - PUBLIC_HEADER "${qmaplibregl_headers}" -) -if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool) - qt_enable_autogen_tool(qmaplibregl "moc" ON) -endif() -if (APPLE AND NOT MLN_QT_STATIC AND NOT MLN_QT_INSIDE_PLUGIN) - set_target_properties( - qmaplibregl PROPERTIES - FRAMEWORK ON - FRAMEWORK_VERSION A - MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.QMapLibreGL - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} - ) - target_include_directories( - qmaplibregl - INTERFACE - $ +# Object library list +get_directory_property(MLN_QT_HAS_PARENT PARENT_DIRECTORY) +if(MLN_QT_HAS_PARENT) + set(MLN_QT_VENDOR_LIBRARIES + mbgl-vendor-parsedate + mbgl-vendor-nunicode + mbgl-vendor-csscolorparser + $<$:$> + $<$,$>:$> + PARENT_SCOPE ) endif() -include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapLibreGL/) - -configure_package_config_file( - "platform/qt/QMapLibreGLConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake" - INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} - PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR - CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO) - -write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake - VERSION ${MLN_QT_VERSION} - COMPATIBILITY AnyNewerVersion) - -install(EXPORT QMapLibreGLTargets - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) - -export(EXPORT QMapLibreGLTargets) - -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake" - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) - -install( - DIRECTORY include/mbgl - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT development -) - -if(MLN_QT_DEPLOYMENT) - install(FILES ${PROJECT_SOURCE_DIR}/LICENSE.md - DESTINATION .) -endif() - -# FIXME: Because of rapidjson conversion -target_include_directories( - qmaplibregl - PRIVATE - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/platform/qt/include -) - -target_compile_definitions( - qmaplibregl - PRIVATE - QT_BUILD_MAPLIBREGL_LIB -) - -target_link_libraries( - qmaplibregl - PUBLIC - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Gui - Qt${QT_VERSION_MAJOR}::Network - PRIVATE - $ - $ -) - -if (MLN_QT_STATIC OR MLN_QT_INSIDE_PLUGIN) - # Don't add import/export into public header because we don't build shared library. - # In case on MLN_QT_INSIDE_PLUGIN it's always OBJECT library and bundled into one - # single Qt plugin lib. - target_compile_definitions( - qmaplibregl - PUBLIC QT_MAPLIBREGL_STATIC - ) -endif() - - -install(TARGETS qmaplibregl - EXPORT QMapLibreGLTargets - # Explicit set of DESTINATION is needed for older CMake versions. - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/QMapLibreGL" -) - if(NOT MLN_QT_LIBRARY_ONLY) - set(mbglqt_sources - ${PROJECT_SOURCE_DIR}/platform/qt/app/main.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/app/mapwindow.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/app/mapwindow.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/resources/common.qrc - ) - if (COMMAND qt_add_executable) - qt_add_executable(mbgl-qt ${mbglqt_sources}) - else() - add_executable(mbgl-qt ${mbglqt_sources}) - endif() - - # Qt public API should keep compatibility with old compilers for legacy systems - set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98) - set_property(TARGET mbgl-qt PROPERTY AUTOMOC ON) - - target_link_libraries( - mbgl-qt - PRIVATE - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Gui - $<$:Qt${QT_VERSION_MAJOR}::OpenGLWidgets> - mbgl-compiler-options - qmaplibregl - ) - - target_include_directories( - mbgl-qt - PRIVATE ${PROJECT_SOURCE_DIR}/platform/qt/include - ) -endif() - -# tests -if(NOT MLN_QT_LIBRARY_ONLY AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + # test runner add_executable( mbgl-test-runner ${PROJECT_SOURCE_DIR}/platform/qt/test/main.cpp @@ -418,18 +205,3 @@ if(NOT MLN_QT_LIBRARY_ONLY AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") add_test(NAME mbgl-test-runner COMMAND mbgl-test-runner WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif() - -find_program(MLN_QDOC NAMES qdoc) - -if(MLN_QDOC) - add_custom_target(mbgl-qt-docs) - - add_custom_command( - TARGET mbgl-qt-docs PRE_BUILD - COMMAND - ${MLN_QDOC} - ${PROJECT_SOURCE_DIR}/platform/qt/config.qdocconf - -outputdir - ${CMAKE_BINARY_DIR}/docs - ) -endif() diff --git a/platform/qt/resources/common.qrc b/platform/qt/resources/common.qrc deleted file mode 100644 index 24f663df7..000000000 --- a/platform/qt/resources/common.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - ../../../misc/mb-icon-blue-square.png - ../../../platform/default/resources/default_marker.svg - source1.geojson - source2.geojson - label-arrow.svg - label-background.svg - - diff --git a/platform/qt/resources/label-arrow.svg b/platform/qt/resources/label-arrow.svg deleted file mode 100644 index c1c9d2b77..000000000 --- a/platform/qt/resources/label-arrow.svg +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform/qt/resources/label-background.svg b/platform/qt/resources/label-background.svg deleted file mode 100644 index af3e47123..000000000 --- a/platform/qt/resources/label-background.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/platform/qt/resources/source1.geojson b/platform/qt/resources/source1.geojson deleted file mode 100644 index 1d270ba18..000000000 --- a/platform/qt/resources/source1.geojson +++ /dev/null @@ -1,1172 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": { - "type": "label", - "name": "Start" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.934420000000003, - 60.163500000000006 - ] - } - }, - { - "type": "Feature", - "properties": { - "type": "label", - "name": "End" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.943690000000004, - 60.155280000000005 - ] - } - }, - { - "type": "Feature", - "properties": { - "type": "label", - "name": "Gas station" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.915920000000003, - 60.17544 - ] - } - }, - { - "type": "Feature", - "properties": { - "type": "label", - "name": "Construction" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.94884, - 60.18657 - ] - } - }, - { - "type": "Feature", - "properties": { - "name": "Route" - }, - "geometry": { - "type": "LineString", - "coordinates": [ - [ - 24.934420000000003, - 60.163500000000006 - ], - [ - 24.934500000000003, - 60.16344000000001 - ], - [ - 24.93338246049353, - 60.16305251411869 - ], - [ - 24.932264947341018, - 60.162665018830225 - ], - [ - 24.931147460542068, - 60.16227751413501 - ], - [ - 24.930030000000002, - 60.16189000000001 - ], - [ - 24.929800000000004, - 60.16180000000001 - ], - [ - 24.929550000000003, - 60.16178000000001 - ], - [ - 24.92931, - 60.16180000000001 - ], - [ - 24.929280000000002, - 60.16172 - ], - [ - 24.928800000000003, - 60.161730000000006 - ], - [ - 24.927669986590868, - 60.161340004809425 - ], - [ - 24.926540000000003, - 60.16095000000001 - ], - [ - 24.92632, - 60.16089 - ], - [ - 24.925890000000003, - 60.16086000000001 - ], - [ - 24.925520000000002, - 60.16089 - ], - [ - 24.92472, - 60.16105 - ], - [ - 24.924270000000003, - 60.161210000000004 - ], - [ - 24.923490008921945, - 60.16159500239787 - ], - [ - 24.922710000000002, - 60.16198000000001 - ], - [ - 24.922390000000004, - 60.16221 - ], - [ - 24.922050000000002, - 60.16228 - ], - [ - 24.921770000000002, - 60.16236000000001 - ], - [ - 24.921580000000002, - 60.16243000000001 - ], - [ - 24.921010000000003, - 60.16284 - ], - [ - 24.92094, - 60.16328000000001 - ], - [ - 24.920890000000004, - 60.16342 - ], - [ - 24.92087, - 60.16344000000001 - ], - [ - 24.920830000000002, - 60.16362 - ], - [ - 24.920820000000003, - 60.16371 - ], - [ - 24.920840000000002, - 60.16376 - ], - [ - 24.92077, - 60.164320000000004 - ], - [ - 24.92077, - 60.164500000000004 - ], - [ - 24.92085, - 60.16467000000001 - ], - [ - 24.92086, - 60.16479 - ], - [ - 24.92086, - 60.164860000000004 - ], - [ - 24.92096, - 60.165090000000006 - ], - [ - 24.920920000000002, - 60.165420000000005 - ], - [ - 24.92096, - 60.16561000000001 - ], - [ - 24.920885001120794, - 60.16610000000575 - ], - [ - 24.920810000000003, - 60.16659000000001 - ], - [ - 24.920800000000003, - 60.166790000000006 - ], - [ - 24.920840000000002, - 60.166900000000005 - ], - [ - 24.920990000000003, - 60.167 - ], - [ - 24.920895002461783, - 60.16785500012713 - ], - [ - 24.920800000000003, - 60.168710000000004 - ], - [ - 24.920740000000002, - 60.16913 - ], - [ - 24.920620000000003, - 60.16971 - ], - [ - 24.920520000000003, - 60.1698 - ], - [ - 24.92049, - 60.169900000000005 - ], - [ - 24.92041, - 60.169920000000005 - ], - [ - 24.919000036342872, - 60.17034334830489 - ], - [ - 24.91759003634794, - 60.17076668163695 - ], - [ - 24.91618, - 60.17119 - ], - [ - 24.916240000000002, - 60.171290000000006 - ], - [ - 24.916220000000003, - 60.17134000000001 - ], - [ - 24.916150000000002, - 60.171530000000004 - ], - [ - 24.916, - 60.17181000000001 - ], - [ - 24.915840000000003, - 60.172000000000004 - ], - [ - 24.915390000000002, - 60.17239000000001 - ], - [ - 24.91524, - 60.17257000000001 - ], - [ - 24.914990000000003, - 60.172990000000006 - ], - [ - 24.914910000000003, - 60.173190000000005 - ], - [ - 24.914830000000002, - 60.17352 - ], - [ - 24.914820000000002, - 60.17365 - ], - [ - 24.915090000000003, - 60.17452000000001 - ], - [ - 24.91512, - 60.17457 - ], - [ - 24.91562, - 60.17486 - ], - [ - 24.915770000000002, - 60.174980000000005 - ], - [ - 24.915860000000002, - 60.175090000000004 - ], - [ - 24.915930000000003, - 60.17526 - ], - [ - 24.915940000000003, - 60.17533 - ], - [ - 24.915920000000003, - 60.17544 - ], - [ - 24.91581, - 60.17564000000001 - ], - [ - 24.9174, - 60.175850000000004 - ], - [ - 24.91786, - 60.17593000000001 - ], - [ - 24.919449989456812, - 60.17614500950065 - ], - [ - 24.92104, - 60.17636 - ], - [ - 24.922050000000002, - 60.176570000000005 - ], - [ - 24.922120000000003, - 60.17683 - ], - [ - 24.921950000000002, - 60.17681 - ], - [ - 24.921770000000002, - 60.17681 - ], - [ - 24.922120000000003, - 60.17683 - ], - [ - 24.922050000000002, - 60.176570000000005 - ], - [ - 24.92207, - 60.176570000000005 - ], - [ - 24.922140000000002, - 60.17658000000001 - ], - [ - 24.922110000000004, - 60.176520000000004 - ], - [ - 24.923530000000003, - 60.17681 - ], - [ - 24.925056651315714, - 60.17697335086663 - ], - [ - 24.92658331781631, - 60.17713668418224 - ], - [ - 24.928110000000004, - 60.1773 - ], - [ - 24.928300000000004, - 60.177330000000005 - ], - [ - 24.92856, - 60.17738000000001 - ], - [ - 24.92978, - 60.17752000000001 - ], - [ - 24.929520000000004, - 60.17797 - ], - [ - 24.929240000000004, - 60.17855000000001 - ], - [ - 24.929840000000002, - 60.178610000000006 - ], - [ - 24.930080000000004, - 60.1786 - ], - [ - 24.93081, - 60.17866000000001 - ], - [ - 24.93081, - 60.178720000000006 - ], - [ - 24.930840000000003, - 60.178830000000005 - ], - [ - 24.931040000000003, - 60.17929 - ], - [ - 24.931060000000002, - 60.179410000000004 - ], - [ - 24.93111, - 60.180170000000004 - ], - [ - 24.931130000000003, - 60.18099000000001 - ], - [ - 24.931160000000002, - 60.18117 - ], - [ - 24.93137, - 60.181670000000004 - ], - [ - 24.931620000000002, - 60.18218 - ], - [ - 24.931710000000002, - 60.182410000000004 - ], - [ - 24.93173, - 60.18253000000001 - ], - [ - 24.93173, - 60.18263 - ], - [ - 24.93166, - 60.18280000000001 - ], - [ - 24.931410000000003, - 60.182990000000004 - ], - [ - 24.931520000000003, - 60.18309000000001 - ], - [ - 24.93177999609094, - 60.183585000274455 - ], - [ - 24.93204, - 60.18408 - ], - [ - 24.93221, - 60.184450000000005 - ], - [ - 24.932250000000003, - 60.18451 - ], - [ - 24.93242, - 60.18462 - ], - [ - 24.932660000000002, - 60.184670000000004 - ], - [ - 24.93428, - 60.184900000000006 - ], - [ - 24.93574999134566, - 60.18509500814494 - ], - [ - 24.937220000000003, - 60.18529 - ], - [ - 24.93774, - 60.18538 - ], - [ - 24.939459986412267, - 60.185640011141956 - ], - [ - 24.941180000000003, - 60.185900000000004 - ], - [ - 24.941160000000004, - 60.185930000000006 - ], - [ - 24.941750000000003, - 60.186020000000006 - ], - [ - 24.942120000000003, - 60.18609000000001 - ], - [ - 24.943450000000002, - 60.186280000000004 - ], - [ - 24.943720000000003, - 60.1863 - ], - [ - 24.94433, - 60.18634000000001 - ], - [ - 24.94583332994822, - 60.186376683681516 - ], - [ - 24.94733666325508, - 60.186413350347536 - ], - [ - 24.94884, - 60.18645000000001 - ], - [ - 24.94884, - 60.18657 - ], - [ - 24.95034, - 60.186600000000006 - ], - [ - 24.95033, - 60.18666 - ], - [ - 24.95034, - 60.186600000000006 - ], - [ - 24.950400000000002, - 60.18661 - ], - [ - 24.95072, - 60.186640000000004 - ], - [ - 24.95097, - 60.1867 - ], - [ - 24.95107, - 60.1867 - ], - [ - 24.95108, - 60.186640000000004 - ], - [ - 24.951130000000003, - 60.18659 - ], - [ - 24.951310000000003, - 60.18647000000001 - ], - [ - 24.95137, - 60.18636000000001 - ], - [ - 24.95144, - 60.185790000000004 - ], - [ - 24.95152000182123, - 60.18504000008196 - ], - [ - 24.951600000000003, - 60.184290000000004 - ], - [ - 24.951610000000002, - 60.184050000000006 - ], - [ - 24.95164, - 60.183960000000006 - ], - [ - 24.95174, - 60.183870000000006 - ], - [ - 24.952, - 60.183730000000004 - ], - [ - 24.95287, - 60.18339 - ], - [ - 24.952990000000003, - 60.18334000000001 - ], - [ - 24.95322, - 60.183310000000006 - ], - [ - 24.95451501994334, - 60.182800006380525 - ], - [ - 24.955810000000003, - 60.18229 - ], - [ - 24.955840000000002, - 60.182230000000004 - ], - [ - 24.95588, - 60.18222000000001 - ], - [ - 24.956170000000004, - 60.182050000000004 - ], - [ - 24.957440000000002, - 60.181490000000004 - ], - [ - 24.958235008897837, - 60.1811250023513 - ], - [ - 24.959030000000002, - 60.18076000000001 - ], - [ - 24.9587, - 60.180580000000006 - ], - [ - 24.958460000000002, - 60.180510000000005 - ], - [ - 24.957690000000003, - 60.18009000000001 - ], - [ - 24.957320000000003, - 60.17987000000001 - ], - [ - 24.95689, - 60.17974 - ], - [ - 24.956770000000002, - 60.17969000000001 - ], - [ - 24.95634, - 60.17929 - ], - [ - 24.95633, - 60.179140000000004 - ], - [ - 24.95654, - 60.17907 - ], - [ - 24.956590000000002, - 60.17902000000001 - ], - [ - 24.95661, - 60.178940000000004 - ], - [ - 24.956895004072333, - 60.178465000388556 - ], - [ - 24.95718, - 60.17799000000001 - ], - [ - 24.957240000000002, - 60.177800000000005 - ], - [ - 24.957305000964798, - 60.17730000020621 - ], - [ - 24.95737, - 60.17680000000001 - ], - [ - 24.957440000000002, - 60.17665 - ], - [ - 24.957520000000002, - 60.17654 - ], - [ - 24.95774, - 60.176390000000005 - ], - [ - 24.9581, - 60.176260000000006 - ], - [ - 24.95867, - 60.176190000000005 - ], - [ - 24.959410000000002, - 60.1762 - ], - [ - 24.959410000000002, - 60.17627 - ], - [ - 24.95999, - 60.17627 - ], - [ - 24.96028, - 60.17625 - ], - [ - 24.960610000000003, - 60.176190000000005 - ], - [ - 24.96113, - 60.17598 - ], - [ - 24.961430000000004, - 60.17582 - ], - [ - 24.961570000000002, - 60.175700000000006 - ], - [ - 24.961660000000002, - 60.17557000000001 - ], - [ - 24.96168, - 60.17551 - ], - [ - 24.961820000000003, - 60.17551 - ], - [ - 24.961920001933628, - 60.17487500003499 - ], - [ - 24.962020000000003, - 60.174240000000005 - ], - [ - 24.96189, - 60.17401 - ], - [ - 24.961509982032023, - 60.17323333442284 - ], - [ - 24.961129982033466, - 60.17245666775814 - ], - [ - 24.96075, - 60.17168 - ], - [ - 24.960810000000002, - 60.171670000000006 - ], - [ - 24.960880000000003, - 60.17181000000001 - ], - [ - 24.960880000000003, - 60.171800000000005 - ], - [ - 24.960810000000002, - 60.171670000000006 - ], - [ - 24.96075, - 60.17168 - ], - [ - 24.960429987467663, - 60.17103666743907 - ], - [ - 24.960109987468513, - 60.170393334106876 - ], - [ - 24.95979, - 60.16975000000001 - ], - [ - 24.95971, - 60.16967 - ], - [ - 24.95961, - 60.16962 - ], - [ - 24.95953, - 60.169610000000006 - ], - [ - 24.958840000000002, - 60.16959000000001 - ], - [ - 24.9587, - 60.169540000000005 - ], - [ - 24.958640000000003, - 60.16946000000001 - ], - [ - 24.958650000000002, - 60.169000000000004 - ], - [ - 24.95859, - 60.16892000000001 - ], - [ - 24.95795, - 60.16852000000001 - ], - [ - 24.95794, - 60.16848 - ], - [ - 24.95737, - 60.16809000000001 - ], - [ - 24.957390000000004, - 60.168060000000004 - ], - [ - 24.95728, - 60.16798000000001 - ], - [ - 24.956850000000003, - 60.167910000000006 - ], - [ - 24.956010000000003, - 60.167880000000004 - ], - [ - 24.955890000000004, - 60.167860000000005 - ], - [ - 24.954429998196012, - 60.16782000802667 - ], - [ - 24.95297, - 60.16778000000001 - ], - [ - 24.952630000000003, - 60.16772 - ], - [ - 24.952550000000002, - 60.167680000000004 - ], - [ - 24.952520000000003, - 60.16762000000001 - ], - [ - 24.9526, - 60.16675000000001 - ], - [ - 24.95266, - 60.16673000000001 - ], - [ - 24.953120000000002, - 60.166740000000004 - ], - [ - 24.95314, - 60.16662 - ], - [ - 24.953170000000004, - 60.166320000000006 - ], - [ - 24.95315, - 60.16608000000001 - ], - [ - 24.953080000000003, - 60.16581000000001 - ], - [ - 24.95313, - 60.165290000000006 - ], - [ - 24.95285, - 60.16528 - ], - [ - 24.952910000000003, - 60.16467000000001 - ], - [ - 24.953030000000002, - 60.16438000000001 - ], - [ - 24.95324, - 60.164100000000005 - ], - [ - 24.953470000000003, - 60.16389 - ], - [ - 24.954400035687588, - 60.16326000649468 - ], - [ - 24.955330035716912, - 60.16263000647425 - ], - [ - 24.95626, - 60.162000000000006 - ], - [ - 24.95652, - 60.16174 - ], - [ - 24.956760000000003, - 60.161300000000004 - ], - [ - 24.956640000000004, - 60.161280000000005 - ], - [ - 24.956400000000002, - 60.16131000000001 - ], - [ - 24.95626, - 60.161280000000005 - ], - [ - 24.956200000000003, - 60.16124000000001 - ], - [ - 24.95597, - 60.16091000000001 - ], - [ - 24.956010000000003, - 60.160830000000004 - ], - [ - 24.955930000000002, - 60.16075000000001 - ], - [ - 24.955604994572663, - 60.16020500033396 - ], - [ - 24.955280000000002, - 60.15966 - ], - [ - 24.955070000000003, - 60.159290000000006 - ], - [ - 24.95493, - 60.159020000000005 - ], - [ - 24.954860000000004, - 60.158930000000005 - ], - [ - 24.954780000000003, - 60.158950000000004 - ], - [ - 24.954860000000004, - 60.158930000000005 - ], - [ - 24.95428499256551, - 60.158505001245636 - ], - [ - 24.95371, - 60.158080000000005 - ], - [ - 24.952809982572653, - 60.157445003022275 - ], - [ - 24.95191, - 60.15681000000001 - ], - [ - 24.951030000000003, - 60.156200000000005 - ], - [ - 24.95089, - 60.15614000000001 - ], - [ - 24.950260000000004, - 60.15605000000001 - ], - [ - 24.948617471181432, - 60.15585753049101 - ], - [ - 24.94697496159803, - 60.15566504065723 - ], - [ - 24.94533247125144, - 60.15547253049904 - ], - [ - 24.943690000000004, - 60.155280000000005 - ] - ] - } - } - ] -} diff --git a/platform/qt/resources/source2.geojson b/platform/qt/resources/source2.geojson deleted file mode 100644 index df300d104..000000000 --- a/platform/qt/resources/source2.geojson +++ /dev/null @@ -1,92 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": { - "type": "label", - "name": "Start" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.943320751190186, - 60.166471893909794 - ] - } - }, - { - "type": "Feature", - "properties": { - "type": "label", - "name": "End" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.942440986633297, - 60.16715507391703 - ] - } - }, - { - "type": "Feature", - "properties": { - "type": "label", - "name": "Traffic Accident" - }, - "geometry": { - "type": "Point", - "coordinates": [ - 24.94018793106079, - 60.16696293097573 - ] - } - }, - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "LineString", - "coordinates": [ - [ - 24.943320751190186, - 60.166471893909794 - ], - [ - 24.934544563293453, - 60.16347213858629 - ], - [ - 24.93321418762207, - 60.16446497048834 - ], - [ - 24.94018793106079, - 60.16696293097573 - ], - [ - 24.93875026702881, - 60.16806240040351 - ], - [ - 24.937891960144043, - 60.16777419352904 - ], - [ - 24.936089515686035, - 60.169033745694826 - ], - [ - 24.9384069442749, - 60.16984495711831 - ], - [ - 24.942440986633297, - 60.16715507391703 - ] - ] - } - } - ] -} diff --git a/platform/qt/scripts/configure_Qt5_Android_static.sh b/platform/qt/scripts/configure_Qt5_Android_static.sh deleted file mode 100755 index 42d8729b1..000000000 --- a/platform/qt/scripts/configure_Qt5_Android_static.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -if [[ -z ${3+x} ]]; then - echo "Error: Pass Qt installation path as the third argument" 1>&2 - exit 3 -fi - -if [[ -z ${4+x} ]]; then - echo "Error: Pass Android ABI as the fourth argument" 1>&2 - exit 3 -fi - -cmake "$1" \ --DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" \ --DANDROID_ABI="$4" \ --DANDROID_NATIVE_API_LEVEL=21 \ --G Ninja \ --DMLN_WITH_QT=ON \ --DMLN_QT_STATIC=ON \ --DMLN_QT_LIBRARY_ONLY=ON \ --DCMAKE_CXX_FLAGS_RELEASE=-g0 \ --DCMAKE_INSTALL_PREFIX="$2" \ --DCMAKE_FIND_ROOT_PATH="$3/android" \ --DCMAKE_PREFIX_PATH="$3/android" diff --git a/platform/qt/scripts/configure_Qt5_Linux.sh b/platform/qt/scripts/configure_Qt5_Linux.sh deleted file mode 100755 index c671461b9..000000000 --- a/platform/qt/scripts/configure_Qt5_Linux.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -cmake "$1" \ - -G Ninja \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DMLN_WITH_QT=ON \ - -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt5_Windows.ps1 b/platform/qt/scripts/configure_Qt5_Windows.ps1 deleted file mode 100644 index 850a136b2..000000000 --- a/platform/qt/scripts/configure_Qt5_Windows.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -$path = $args[0] -$install = $args[1] - -cmake -S "$path" ` - -GNinja ` - -DCMAKE_BUILD_TYPE="Release" ` - -DCMAKE_INSTALL_PREFIX="$install" ` - -DMLN_WITH_QT=ON diff --git a/platform/qt/scripts/configure_Qt5_Windows_static.ps1 b/platform/qt/scripts/configure_Qt5_Windows_static.ps1 deleted file mode 100644 index 75eae5720..000000000 --- a/platform/qt/scripts/configure_Qt5_Windows_static.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -$path = $args[0] -$install = $args[1] - -cmake -S "$path" ` - -GNinja ` - -DCMAKE_BUILD_TYPE="Release" ` - -DCMAKE_INSTALL_PREFIX="$install" ` - -DMLN_WITH_QT=ON ` - -DMLN_QT_STATIC=ON ` - -DMLN_QT_LIBRARY_ONLY=ON diff --git a/platform/qt/scripts/configure_Qt5_iOS_static.sh b/platform/qt/scripts/configure_Qt5_iOS_static.sh deleted file mode 100755 index 8310b5fdf..000000000 --- a/platform/qt/scripts/configure_Qt5_iOS_static.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -if [[ -z ${3+x} ]]; then - echo "Error: Pass Qt installation path as the third argument" 1>&2 - exit 3 -fi - -cmake "$1" \ - -G"Ninja Multi-Config" \ - -DCMAKE_SYSTEM_NAME="iOS" \ - -DCMAKE_CONFIGURATION_TYPES="Release;Debug" \ - -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ - -DCMAKE_OSX_DEPLOYMENT_TARGET="12.0" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_STATIC=ON \ - -DMLN_QT_LIBRARY_ONLY=ON \ - -DCMAKE_INSTALL_PREFIX="$2" \ - -DCMAKE_FIND_ROOT_PATH="$3/ios" \ - -DCMAKE_PREFIX_PATH="$3/ios" diff --git a/platform/qt/scripts/configure_Qt5_macOS.sh b/platform/qt/scripts/configure_Qt5_macOS.sh deleted file mode 100755 index b1db79dc3..000000000 --- a/platform/qt/scripts/configure_Qt5_macOS.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -cmake "$1" \ - -G Ninja \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_OSX_DEPLOYMENT_TARGET="10.13" \ - -DMLN_WITH_QT=ON \ - -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt5_macOS_static.sh b/platform/qt/scripts/configure_Qt5_macOS_static.sh deleted file mode 100755 index df63de252..000000000 --- a/platform/qt/scripts/configure_Qt5_macOS_static.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -cmake "$1" \ - -G Ninja \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_OSX_DEPLOYMENT_TARGET="10.13" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_STATIC=ON \ - -DMLN_QT_LIBRARY_ONLY=ON \ - -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt6_Windows.ps1 b/platform/qt/scripts/configure_Qt6_Windows.ps1 deleted file mode 100644 index 2190b1b74..000000000 --- a/platform/qt/scripts/configure_Qt6_Windows.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -$path = $args[0] -$install = $args[1] - -qt-cmake -S "$path" ` - -GNinja ` - -DCMAKE_BUILD_TYPE="Release" ` - -DCMAKE_INSTALL_PREFIX="$install" ` - -DMLN_WITH_QT=ON diff --git a/platform/qt/scripts/configure_Qt6_macOS.sh b/platform/qt/scripts/configure_Qt6_macOS.sh deleted file mode 100755 index c105191b7..000000000 --- a/platform/qt/scripts/configure_Qt6_macOS.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -qt-cmake "$1" \ - -G Ninja \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" \ - -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ - -DMLN_WITH_QT=ON \ - -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt6_macOS_static.sh b/platform/qt/scripts/configure_Qt6_macOS_static.sh deleted file mode 100755 index 43f48ac2e..000000000 --- a/platform/qt/scripts/configure_Qt6_macOS_static.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -if [[ -z ${1+x} ]]; then - echo "Error: Pass the path to maplibre-native as first argument" 1>&2 - exit 1 -fi - -if [[ -z ${2+x} ]]; then - echo "Error: Pass the install prefix as the second argument" 1>&2 - exit 2 -fi - -qt-cmake "$1" \ - -G Ninja \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" \ - -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ - -DMLN_WITH_QT=ON \ - -DMLN_QT_STATIC=ON \ - -DMLN_QT_LIBRARY_ONLY=ON \ - -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/src/map.cpp b/platform/qt/src/map.cpp deleted file mode 100644 index d20146711..000000000 --- a/platform/qt/src/map.cpp +++ /dev/null @@ -1,1490 +0,0 @@ -#include -#include - -#include "map_p.hpp" - -#include "utils/conversion.hpp" -#include "utils/geojson.hpp" -#include "utils/map_observer.hpp" -#include "utils/renderer_observer.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4805) -#endif - -// mbgl::NorthOrientation -static_assert(mbgl::underlying_type(QMapLibreGL::Map::NorthUpwards) == - mbgl::underlying_type(mbgl::NorthOrientation::Upwards), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Map::NorthRightwards) == - mbgl::underlying_type(mbgl::NorthOrientation::Rightwards), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Map::NorthDownwards) == - mbgl::underlying_type(mbgl::NorthOrientation::Downwards), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Map::NorthLeftwards) == - mbgl::underlying_type(mbgl::NorthOrientation::Leftwards), - "error"); - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -namespace { - -QThreadStorage> loop; - -// Conversion helper functions. - -mbgl::Size sanitizedSize(const QSize &size) { - return mbgl::Size{ - mbgl::util::max(0u, static_cast(size.width())), - mbgl::util::max(0u, static_cast(size.height())), - }; -}; - -std::unique_ptr toStyleImage(const QString &id, const QImage &sprite) { - const QImage swapped = sprite.rgbSwapped().convertToFormat(QImage::Format_ARGB32_Premultiplied); - -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) - auto img = std::make_unique(swapped.sizeInBytes()); - memcpy(img.get(), swapped.constBits(), swapped.sizeInBytes()); -#else - auto img = std::make_unique(swapped.byteCount()); - memcpy(img.get(), swapped.constBits(), swapped.byteCount()); -#endif - - return std::make_unique( - id.toStdString(), - mbgl::PremultipliedImage({static_cast(swapped.width()), static_cast(swapped.height())}, - std::move(img)), - 1.0); -} - -mbgl::MapOptions mapOptionsFromSettings(const QMapLibreGL::Settings &settings, const QSize &size, qreal pixelRatio) { - return std::move(mbgl::MapOptions() - .withSize(sanitizedSize(size)) - .withPixelRatio(pixelRatio) - .withMapMode(static_cast(settings.mapMode())) - .withConstrainMode(static_cast(settings.constrainMode())) - .withViewportMode(static_cast(settings.viewportMode()))); -} - -mbgl::ResourceOptions resourceOptionsFromSettings(const QMapLibreGL::Settings &settings) { - return std::move(mbgl::ResourceOptions() - .withApiKey(settings.apiKey().toStdString()) - .withAssetPath(settings.assetPath().toStdString()) - .withTileServerOptions(*settings.tileServerOptionsInternal()) - .withCachePath(settings.cacheDatabasePath().toStdString()) - .withMaximumCacheSize(settings.cacheDatabaseMaximumSize())); -} - -mbgl::ClientOptions clientOptionsFromSettings(const QMapLibreGL::Settings &settings) { - return std::move(mbgl::ClientOptions() - .withName(settings.clientName().toStdString()) - .withVersion(settings.clientVersion().toStdString())); -} - -std::optional asAnnotation(const QMapLibreGL::Annotation &annotation) { - auto asGeometry = [](const QMapLibreGL::ShapeAnnotationGeometry &geometry) { - mbgl::ShapeAnnotationGeometry result; - switch (geometry.type) { - case QMapLibreGL::ShapeAnnotationGeometry::LineStringType: - result = QMapLibreGL::GeoJSON::asLineString(geometry.geometry.first().first()); - break; - case QMapLibreGL::ShapeAnnotationGeometry::PolygonType: - result = QMapLibreGL::GeoJSON::asPolygon(geometry.geometry.first()); - break; - case QMapLibreGL::ShapeAnnotationGeometry::MultiLineStringType: - result = QMapLibreGL::GeoJSON::asMultiLineString(geometry.geometry.first()); - break; - case QMapLibreGL::ShapeAnnotationGeometry::MultiPolygonType: - result = QMapLibreGL::GeoJSON::asMultiPolygon(geometry.geometry); - break; - } - return result; - }; - - if (annotation.canConvert()) { - QMapLibreGL::SymbolAnnotation symbolAnnotation = annotation.value(); - QMapLibreGL::Coordinate &pair = symbolAnnotation.geometry; - return { - mbgl::SymbolAnnotation(mbgl::Point{pair.second, pair.first}, symbolAnnotation.icon.toStdString())}; - } else if (annotation.canConvert()) { - QMapLibreGL::LineAnnotation lineAnnotation = annotation.value(); - auto color = mbgl::Color::parse(mbgl::style::conversion::convertColor(lineAnnotation.color)); - return {mbgl::LineAnnotation( - asGeometry(lineAnnotation.geometry), lineAnnotation.opacity, lineAnnotation.width, {*color})}; - } else if (annotation.canConvert()) { - QMapLibreGL::FillAnnotation fillAnnotation = annotation.value(); - auto color = mbgl::Color::parse(mbgl::style::conversion::convertColor(fillAnnotation.color)); - if (fillAnnotation.outlineColor.canConvert()) { - auto outlineColor = mbgl::Color::parse( - mbgl::style::conversion::convertColor(fillAnnotation.outlineColor.value())); - return {mbgl::FillAnnotation( - asGeometry(fillAnnotation.geometry), fillAnnotation.opacity, {*color}, {*outlineColor})}; - } else { - return {mbgl::FillAnnotation(asGeometry(fillAnnotation.geometry), fillAnnotation.opacity, {*color}, {})}; - } - } - - qWarning() << "Unable to convert annotation:" << annotation; - return {}; -} - -} // namespace - -namespace QMapLibreGL { - -/*! - \class QMapLibreGL::Map - \brief The QMapLibreGL::Map class is a Qt wrapper for the MapLibre Native engine. - - \inmodule MapLibre Maps SDK for Qt - - QMapLibreGL::Map is a Qt friendly version the MapLibre Native engine using Qt types - and deep integration with Qt event loop. QMapLibreGL::Map relies as much as possible - on Qt, trying to minimize the external dependencies. For instance it will use - QNetworkAccessManager for HTTP requests and QString for UTF-8 manipulation. - - QMapLibreGL::Map is not thread-safe and it is assumed that it will be accessed from - the same thread as the thread where the OpenGL context lives. -*/ - -/*! - \enum QMapLibreGL::Map::MapChange - - This enum represents the last changed occurred to the map state. - - \value MapChangeRegionWillChange A region of the map - will change, like when resizing the map. - - \value MapChangeRegionWillChangeAnimated Not in use by - QMapLibreGL::Map. - - \value MapChangeRegionIsChanging A region of the map is - changing. - - \value MapChangeRegionDidChange A region of the map - finished changing. - - \value MapChangeRegionDidChangeAnimated Not in use by - QMapLibreGL::Map. - - \value MapChangeWillStartLoadingMap The map is getting - loaded. This state is set only once right after QMapLibreGL::Map is created - and a style is set. - - \value MapChangeDidFinishLoadingMap All the resources were - loaded and parsed and the map is fully rendered. After this state the - mapChanged() signal won't fire again unless the is some client side - interaction with the map or a tile expires, causing a new resource to be - requested from the network. - - \value MapChangeDidFailLoadingMap An error occurred when - loading the map. - - \value MapChangeWillStartRenderingFrame Just before rendering - the frame. This is the state of the map just after calling render() and might - happened many times before the map is fully loaded. - - \value MapChangeDidFinishRenderingFrame The current frame was - rendered but was left in a partial state. Some parts of the map might be - missing because have not arrived from the network or are being parsed. - - \value MapChangeDidFinishRenderingFrameFullyRendered The current frame was - fully rendered. - - \value MapChangeWillStartRenderingMap Set once when the map - is about to get rendered for the first time. - - \value MapChangeDidFinishRenderingMap Not in use by - QMapLibreGL::Map. - - \value MapChangeDidFinishRenderingMapFullyRendered Map is fully loaded - and rendered. - - \value MapChangeDidFinishLoadingStyle The style was loaded. - - \value MapChangeSourceDidChange A source has changed. - - \sa mapChanged() -*/ - -/*! - \enum QMapLibreGL::Map::MapLoadingFailure - - This enum represents map loading failure type. - - \value StyleParseFailure Failure to parse the - style. \value StyleLoadFailure Failure to load - the style data. \value NotFoundFailure Failure - to obtain style resource file. \value UnknownFailure Unknown map loading - failure. - - \sa mapLoadingFailed() -*/ - -/*! - \enum QMapLibreGL::Map::NorthOrientation - - This enum sets the orientation of the north bearing. It will directly affect - bearing when resetting the north (i.e. setting bearing to 0). - - \value NorthUpwards The north is pointing up in the map. This is usually - how maps are oriented. - - \value NorthRightwards The north is pointing right. - - \value NorthDownwards The north is pointing down. - - \value NorthLeftwards The north is pointing left. - - \sa northOrientation() - \sa bearing() -*/ - -/*! - Constructs a QMapLibreGL::Map object with \a settings and sets \a parent_ as - the parent object. The \a settings cannot be changed after the object is - constructed. The \a size represents the size of the viewport and the \a - pixelRatio the initial pixel density of the screen. -*/ -Map::Map(QObject *parent_, const Settings &settings, const QSize &size, qreal pixelRatio) - : QObject(parent_) { - assert(!size.isEmpty()); - - // Multiple QMapLibreGL::Map running on the same thread - // will share the same mbgl::util::RunLoop - if (!loop.hasLocalData()) { - loop.setLocalData(std::make_shared()); - } - - d_ptr = new MapPrivate(this, settings, size, pixelRatio); -} - -/*! - Destroys this QMapLibreGL::Map. -*/ -Map::~Map() { - delete d_ptr; -} - -/*! - \property QMapLibreGL::Map::styleJson - \brief the map style JSON. - - Sets a new \a style from a JSON that must conform to the - \l {https://maplibre.org/maplibre-style-spec/} - {MapLibre Style spec}. - - \note In case of a invalid style it will trigger a mapChanged - signal with QMapLibreGL::Map::MapChangeDidFailLoadingMap as argument. -*/ -QString Map::styleJson() const { - return QString::fromStdString(d_ptr->mapObj->getStyle().getJSON()); -} - -void Map::setStyleJson(const QString &style) { - d_ptr->mapObj->getStyle().loadJSON(style.toStdString()); -} - -/*! - \property QMapLibreGL::Map::styleUrl - \brief the map style URL. - - Sets a URL for fetching a JSON that will be later fed to - setStyleJson. URLs using the Mapbox scheme (\a mapbox://) are - also accepted and translated automatically to an actual HTTPS - request. - - The Mapbox scheme is not enforced and a style can be fetched - from anything that QNetworkAccessManager can handle. - - \note In case of a invalid style it will trigger a mapChanged - signal with QMapLibreGL::Map::MapChangeDidFailLoadingMap as argument. -*/ -QString Map::styleUrl() const { - return QString::fromStdString(d_ptr->mapObj->getStyle().getURL()); -} - -void Map::setStyleUrl(const QString &url) { - d_ptr->mapObj->getStyle().loadURL(url.toStdString()); -} - -/*! - \property QMapLibreGL::Map::latitude - \brief the map's current latitude in degrees. - - Setting a latitude doesn't necessarily mean it will be accepted since QMapLibreGL::Map - might constrain it within the limits of the Web Mercator projection. -*/ -double Map::latitude() const { - return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->latitude(); -} - -void Map::setLatitude(double latitude_) { - d_ptr->mapObj->jumpTo( - mbgl::CameraOptions().withCenter(mbgl::LatLng{latitude_, longitude()}).withPadding(d_ptr->margins)); -} - -/*! - \property QMapLibreGL::Map::longitude - \brief the map current longitude in degrees. - - Setting a longitude beyond the limits of the Web Mercator projection will - make the map wrap. As an example, setting the longitude to 360 is effectively - the same as setting it to 0. -*/ -double Map::longitude() const { - return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->longitude(); -} - -void Map::setLongitude(double longitude_) { - d_ptr->mapObj->jumpTo( - mbgl::CameraOptions().withCenter(mbgl::LatLng{latitude(), longitude_}).withPadding(d_ptr->margins)); -} - -/*! - \property QMapLibreGL::Map::scale - \brief the map scale factor. - - This property is used to zoom the map. When \a center is defined, the map will - scale in the direction of the center pixel coordinates. The \a center will remain - at the same pixel coordinate after scaling as before calling this method. - - \note This function could be used for implementing a pinch gesture or zooming - by using the mouse scroll wheel. - - \sa zoom() -*/ -double Map::scale() const { - return std::pow(2.0, zoom()); -} - -void Map::setScale(double scale_, const QPointF ¢er) { - d_ptr->mapObj->jumpTo( - mbgl::CameraOptions().withZoom(::log2(scale_)).withAnchor(mbgl::ScreenCoordinate{center.x(), center.y()})); -} - -/*! - \property QMapLibreGL::Map::zoom - \brief the map zoom factor. - - This property is used to zoom the map. When \a center is defined, the map - will zoom in the direction of the center. This function could be used for - implementing a pinch gesture or zooming by using the mouse scroll wheel. - - \sa scale() -*/ -double Map::zoom() const { - return *d_ptr->mapObj->getCameraOptions().zoom; -} - -void Map::setZoom(double zoom_) { - d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withZoom(zoom_).withPadding(d_ptr->margins)); -} - -/*! - Returns the minimum zoom level allowed for the map. - - \sa maximumZoom() -*/ -double Map::minimumZoom() const { - return *d_ptr->mapObj->getBounds().minZoom; -} - -/*! - Returns the maximum zoom level allowed for the map. - - \sa minimumZoom() -*/ -double Map::maximumZoom() const { - return *d_ptr->mapObj->getBounds().maxZoom; -} - -/*! - \property QMapLibreGL::Map::coordinate - \brief the map center \a coordinate. - - Centers the map at a geographic coordinate respecting the margins, if set. - - \sa margins() -*/ -Coordinate Map::coordinate() const { - const mbgl::LatLng latLng = *d_ptr->mapObj->getCameraOptions(d_ptr->margins).center; - return Coordinate(latLng.latitude(), latLng.longitude()); -} - -void Map::setCoordinate(const Coordinate &coordinate_) { - d_ptr->mapObj->jumpTo(mbgl::CameraOptions() - .withCenter(mbgl::LatLng{coordinate_.first, coordinate_.second}) - .withPadding(d_ptr->margins)); -} - -/*! - \fn QMapLibreGL::Map::setCoordinateZoom(const Coordinate &coordinate, double zoom) - - Convenience method for setting the \a coordinate and \a zoom simultaneously. - - \note Setting \a coordinate and \a zoom at once is more efficient than doing - it in two steps. - - \sa zoom() - \sa coordinate() -*/ -void Map::setCoordinateZoom(const Coordinate &coordinate_, double zoom_) { - d_ptr->mapObj->jumpTo(mbgl::CameraOptions() - .withCenter(mbgl::LatLng{coordinate_.first, coordinate_.second}) - .withZoom(zoom_) - .withPadding(d_ptr->margins)); -} - -/*! - Atomically jumps to the \a camera options. -*/ -void Map::jumpTo(const CameraOptions &camera) { - mbgl::CameraOptions mbglCamera; - if (camera.center.isValid()) { - const Coordinate center = camera.center.value(); - mbglCamera.center = mbgl::LatLng{center.first, center.second}; - } - if (camera.anchor.isValid()) { - const QPointF anchor = camera.anchor.value(); - mbglCamera.anchor = mbgl::ScreenCoordinate{anchor.x(), anchor.y()}; - } - if (camera.zoom.isValid()) { - mbglCamera.zoom = camera.zoom.value(); - } - if (camera.bearing.isValid()) { - mbglCamera.bearing = camera.bearing.value(); - } - if (camera.pitch.isValid()) { - mbglCamera.pitch = camera.pitch.value(); - } - - mbglCamera.padding = d_ptr->margins; - - d_ptr->mapObj->jumpTo(mbglCamera); -} - -/*! - \property QMapLibreGL::Map::bearing - \brief the map bearing in degrees. - - Set the angle in degrees. Negative values and values over 360 are - valid and will wrap. The direction of the rotation is counterclockwise. - - When \a center is defined, the map will rotate around the center pixel - coordinate respecting the margins if defined. - - \sa margins() -*/ -double Map::bearing() const { - return *d_ptr->mapObj->getCameraOptions().bearing; -} - -void Map::setBearing(double degrees) { - d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withBearing(degrees).withPadding(d_ptr->margins)); -} - -void Map::setBearing(double degrees, const QPointF ¢er) { - d_ptr->mapObj->jumpTo( - mbgl::CameraOptions().withBearing(degrees).withAnchor(mbgl::ScreenCoordinate{center.x(), center.y()})); -} - -/*! - \property QMapLibreGL::Map::pitch - \brief the map pitch in degrees. - - Pitch toward the horizon measured in degrees, with 0 resulting in a - two-dimensional map. It will be constrained at 60 degrees. - - \sa margins() -*/ -double Map::pitch() const { - return *d_ptr->mapObj->getCameraOptions().pitch; -} - -void Map::setPitch(double pitch_) { - d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withPitch(pitch_)); -} - -void Map::pitchBy(double pitch_) { - d_ptr->mapObj->pitchBy(pitch_); -} - -/*! - Returns the north orientation mode. -*/ -Map::NorthOrientation Map::northOrientation() const { - return static_cast(d_ptr->mapObj->getMapOptions().northOrientation()); -} - -/*! - Sets the north orientation mode to \a orientation. -*/ -void Map::setNorthOrientation(NorthOrientation orientation) { - d_ptr->mapObj->setNorthOrientation(static_cast(orientation)); -} - -/*! - Tells the map rendering engine that there is currently a gesture in \a - progress. This affects how the map renders labels, as it will use different - texture filters if a gesture is ongoing. -*/ -void Map::setGestureInProgress(bool progress) { - d_ptr->mapObj->setGestureInProgress(progress); -} - -/*! - Sets the \a duration and \a delay of style transitions. Style paint property - values transition to new values with animation when they are updated. -*/ -void Map::setTransitionOptions(qint64 duration, qint64 delay) { - static auto convert = [](qint64 value) -> std::optional { - return std::chrono::duration_cast(mbgl::Milliseconds(value)); - }; - - d_ptr->mapObj->getStyle().setTransitionOptions(mbgl::style::TransitionOptions{convert(duration), convert(delay)}); -} - -/*! - Adds an \a annotation to the map. - - Returns the unique identifier for the new annotation. - - \sa addAnnotationIcon() -*/ -AnnotationID Map::addAnnotation(const Annotation &annotation) { - return static_cast(d_ptr->mapObj->addAnnotation(*asAnnotation(annotation))); -} - -/*! - Updates an existing \a annotation referred by \a id. - - \sa addAnnotationIcon() -*/ -void Map::updateAnnotation(AnnotationID id, const Annotation &annotation) { - d_ptr->mapObj->updateAnnotation(id, *asAnnotation(annotation)); -} - -/*! - Removes an existing annotation referred by \a id. -*/ -void Map::removeAnnotation(AnnotationID id) { - d_ptr->mapObj->removeAnnotation(id); -} - -/*! - Sets a layout \a property_ \a value to an existing \a layer. The \a - property_ string can be any as defined by the \l - {https://maplibre.org/maplibre-style-spec/} {MapLibre Style Spec} - for layout properties. Returns true if the operation succeeds, and false - otherwise. - - The implementation attempts to treat \a value as a JSON string, if the - QVariant inner type is a string. If not a valid JSON string, then it'll - proceed with the mapping described below. - - This example hides the layer \c route: - - \code - map->setLayoutProperty("route", "visibility", "none"); - \endcode - - This table describes the mapping between \l - {https://maplibre.org/maplibre-style-spec/#types} {style types} and Qt - types accepted by setLayoutProperty(): - - \table - \header - \li MapLibre style type - \li Qt type - \row - \li Enum - \li QString - \row - \li String - \li QString - \row - \li Boolean - \li \c bool - \row - \li Number - \li \c int, \c double or \c float - \row - \li Array - \li QVariantList - \endtable -*/ -bool Map::setLayoutProperty(const QString &layer, const QString &propertyName, const QVariant &value) { - return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); -} - -/*! - Sets a paint \a property_ \a value to an existing \a layer. The \a property_ - string can be any as defined by the \l - {https://maplibre.org/maplibre-style-spec/} {MapLibre Style Spec} - for paint properties. Returns true if the operation succeeds, and false - otherwise. - - The implementation attempts to treat \a value as a JSON string, if the - QVariant inner type is a string. If not a valid JSON string, then it'll - proceed with the mapping described below. - - For paint properties that take a color as \a value, such as \c fill-color, a - string such as \c blue can be passed or a QColor. - - \code - map->setPaintProperty("route", "line-color", QColor("blue")); - \endcode - - This table describes the mapping between \l - {https://maplibre.org/maplibre-style-spec/#types} {style types} and Qt - types accepted by setPaintProperty(): - - \table - \header - \li MapLibre style type - \li Qt type - \row - \li Color - \li QString or QColor - \row - \li Enum - \li QString - \row - \li String - \li QString - \row - \li Boolean - \li \c bool - \row - \li Number - \li \c int, \c double or \c float - \row - \li Array - \li QVariantList - \endtable - - If the style specification defines the property's type as \b Array, use a - QVariantList. For example, the following code sets a \c route layer's \c - line-dasharray property: - - \code - QVariantList lineDashArray; - lineDashArray.append(1); - lineDashArray.append(2); - - map->setPaintProperty("route","line-dasharray", lineDashArray); - \endcode -*/ - -bool Map::setPaintProperty(const QString &layer, const QString &propertyName, const QVariant &value) { - return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); -} - -/*! - Returns true when the map is completely rendered, false otherwise. A partially - rendered map ranges from nothing rendered at all to only labels missing. -*/ -bool Map::isFullyLoaded() const { - return d_ptr->mapObj->isFullyLoaded(); -} - -/*! - Pan the map by \a offset in pixels. - - The pixel coordinate origin is located at the upper left corner of the map. -*/ -void Map::moveBy(const QPointF &offset) { - d_ptr->mapObj->moveBy(mbgl::ScreenCoordinate{offset.x(), offset.y()}); -} - -/*! - \fn QMapLibreGL::Map::scaleBy(double scale, const QPointF ¢er) - - Scale the map by \a scale in the direction of the \a center. This function - can be used for implementing a pinch gesture. -*/ -void Map::scaleBy(double scale_, const QPointF ¢er) { - d_ptr->mapObj->scaleBy(scale_, mbgl::ScreenCoordinate{center.x(), center.y()}); -} - -/*! - Rotate the map from the \a first screen coordinate to the \a second screen - coordinate. This method can be used for implementing rotating the map by - clicking and dragging, being \a first the cursor coordinate at the last frame - and \a second the cursor coordinate at the current frame. -*/ -void Map::rotateBy(const QPointF &first, const QPointF &second) { - d_ptr->mapObj->rotateBy(mbgl::ScreenCoordinate{first.x(), first.y()}, - mbgl::ScreenCoordinate{second.x(), second.y()}); -} - -/*! - Resize the map to \a size_ and scale to fit at the framebuffer. For - high DPI screens, the size will be smaller than the framebuffer. -*/ -void Map::resize(const QSize &size_) { - auto size = sanitizedSize(size_); - - if (d_ptr->mapObj->getMapOptions().size() == size) return; - - d_ptr->mapObj->setSize(size); -} - -/*! - Adds an \a icon to the annotation icon pool. This can be later used by the - annotation functions to shown any drawing on the map by referencing its \a - name. - - Unlike using addIcon() for runtime styling, annotations added with - addAnnotation() will survive style changes. - - \sa addAnnotation() -*/ -void Map::addAnnotationIcon(const QString &name, const QImage &icon) { - if (icon.isNull()) return; - - d_ptr->mapObj->addAnnotationImage(toStyleImage(name, icon)); -} - -/*! - \fn QMapLibreGL::Map::pixelForCoordinate(const Coordinate &coordinate) const - - Returns the offset in pixels for \a coordinate. The origin pixel coordinate is - located at the top left corner of the map view. - - This method returns the correct value for any coordinate, even if the coordinate - is not currently visible on the screen. - - /note The return value is affected by the current zoom level, bearing and pitch. -*/ -QPointF Map::pixelForCoordinate(const Coordinate &coordinate_) const { - const mbgl::ScreenCoordinate pixel = d_ptr->mapObj->pixelForLatLng( - mbgl::LatLng{coordinate_.first, coordinate_.second}); - - return QPointF(pixel.x, pixel.y); -} - -/*! - Returns the geographic coordinate for the \a pixel coordinate. -*/ -Coordinate Map::coordinateForPixel(const QPointF &pixel) const { - const mbgl::LatLng latLng = d_ptr->mapObj->latLngForPixel(mbgl::ScreenCoordinate{pixel.x(), pixel.y()}); - - return Coordinate(latLng.latitude(), latLng.longitude()); -} - -/*! - Returns the coordinate and zoom combination needed in order to make the - coordinate bounding box \a sw and \a ne visible. -*/ -CoordinateZoom Map::coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne) const { - auto bounds = mbgl::LatLngBounds::hull(mbgl::LatLng{sw.first, sw.second}, mbgl::LatLng{ne.first, ne.second}); - mbgl::CameraOptions camera = d_ptr->mapObj->cameraForLatLngBounds(bounds, d_ptr->margins); - - return {{(*camera.center).latitude(), (*camera.center).longitude()}, *camera.zoom}; -} - -/*! - Returns the coordinate and zoom combination needed in order to make the - coordinate bounding box \a sw and \a ne visible taking into account \a - newBearing and \a newPitch. -*/ -CoordinateZoom Map::coordinateZoomForBounds(const Coordinate &sw, - const Coordinate &ne, - double newBearing, - double newPitch) - -{ - auto bounds = mbgl::LatLngBounds::hull(mbgl::LatLng{sw.first, sw.second}, mbgl::LatLng{ne.first, ne.second}); - mbgl::CameraOptions camera = d_ptr->mapObj->cameraForLatLngBounds(bounds, d_ptr->margins, newBearing, newPitch); - return {{(*camera.center).latitude(), (*camera.center).longitude()}, *camera.zoom}; -} - -/*! - \property QMapLibreGL::Map::margins - \brief the map margins in pixels from the corners of the map. - - This property sets a new reference center for the map. -*/ -void Map::setMargins(const QMargins &margins_) { - d_ptr->margins = {static_cast(margins_.top()), - static_cast(margins_.left()), - static_cast(margins_.bottom()), - static_cast(margins_.right())}; -} - -QMargins Map::margins() const { - return QMargins(d_ptr->margins.left(), d_ptr->margins.top(), d_ptr->margins.right(), d_ptr->margins.bottom()); -} - -/*! - Adds a source \a id to the map as specified by the \l - {https://maplibre.org/maplibre-style-spec/#root-sources}{MapLibre Style - Specification} with \a params. - - This example reads a GeoJSON from the Qt resource system and adds it as - source: - - \code - QFile geojson(":source1.geojson"); - geojson.open(QIODevice::ReadOnly); - - QVariantMap routeSource; - routeSource["type"] = "geojson"; - routeSource["data"] = geojson.readAll(); - - map->addSource("routeSource", routeSource); - \endcode -*/ -void Map::addSource(const QString &id, const QVariantMap ¶ms) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - Error error; - std::optional> source = convert>( - QVariant(params), error, id.toStdString()); - if (!source) { - qWarning() << "Unable to add source:" << error.message.c_str(); - return; - } - - d_ptr->mapObj->getStyle().addSource(std::move(*source)); -} - -/*! - Returns true if the layer with given \a sourceID exists, false otherwise. -*/ -bool Map::sourceExists(const QString &sourceID) { - return !!d_ptr->mapObj->getStyle().getSource(sourceID.toStdString()); -} - -/*! - Updates the source \a id with new \a params. - - If the source does not exist, it will be added like in addSource(). Only - image and GeoJSON sources can be updated. -*/ -void Map::updateSource(const QString &id, const QVariantMap ¶ms) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - auto source = d_ptr->mapObj->getStyle().getSource(id.toStdString()); - if (!source) { - addSource(id, params); - return; - } - - auto sourceGeoJSON = source->as(); - auto sourceImage = source->as(); - if (!sourceGeoJSON && !sourceImage) { - qWarning() << "Unable to update source: only GeoJSON and Image sources " - "are mutable."; - return; - } - - if (sourceImage && params.contains("url")) { - sourceImage->setURL(params["url"].toString().toStdString()); - } else if (sourceGeoJSON && params.contains("data")) { - Error error; - auto result = convert(params["data"], error); - if (result) { - sourceGeoJSON->setGeoJSON(*result); - } - } -} - -/*! - Removes the source \a id. - - This method has no effect if the source does not exist. -*/ -void Map::removeSource(const QString &id) { - auto sourceIDStdString = id.toStdString(); - - if (d_ptr->mapObj->getStyle().getSource(sourceIDStdString)) { - d_ptr->mapObj->getStyle().removeSource(sourceIDStdString); - } -} - -/*! - Adds a custom layer \a id with the initialization function \a initFn, the - render function \a renderFn and the deinitialization function \a deinitFn - with the user data \a context before the existing layer \a before. - - \warning This is used for delegating the rendering of a layer to the user of - this API and is not officially supported. Use at your own risk. -*/ -void Map::addCustomLayer(const QString &id, std::unique_ptr host, const QString &before) { - class HostWrapper : public mbgl::style::CustomLayerHost { - public: - std::unique_ptr ptr{}; - HostWrapper(std::unique_ptr p) - : ptr(std::move(p)) {} - - void initialize() { ptr->initialize(); } - - void render(const mbgl::style::CustomLayerRenderParameters ¶ms) { - CustomLayerRenderParameters renderParams; - renderParams.width = params.width; - renderParams.height = params.height; - renderParams.latitude = params.latitude; - renderParams.longitude = params.longitude; - renderParams.zoom = params.zoom; - renderParams.bearing = params.bearing; - renderParams.pitch = params.pitch; - renderParams.fieldOfView = params.fieldOfView; - ptr->render(renderParams); - } - - void contextLost() {} - - void deinitialize() { ptr->deinitialize(); } - }; - - d_ptr->mapObj->getStyle().addLayer( - std::make_unique(id.toStdString(), std::make_unique(std::move(host))), - before.isEmpty() ? std::optional() : std::optional(before.toStdString())); -} - -/*! - Adds a style layer to the map as specified by the \l - {https://maplibre.org/maplibre-style-spec/#root-layers}{MapLibre style - specification} with \a params. The layer will be added under the layer - specified by \a before, if specified. Otherwise it will be added as the - topmost layer. - - This example shows how to add a layer that will be used to show a route line - on the map. Note that nothing will be drawn until we set paint properties - using setPaintProperty(). - - \code - QVariantMap route; - route["id"] = "route"; - route["type"] = "line"; - route["source"] = "routeSource"; - - map->addLayer(route); - \endcode - - /note The source must exist prior to adding a layer. -*/ -void Map::addLayer(const QVariantMap ¶ms, const QString &before) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - Error error; - std::optional> layer = convert>(QVariant(params), error); - if (!layer) { - qWarning() << "Unable to add layer:" << error.message.c_str(); - return; - } - - d_ptr->mapObj->getStyle().addLayer( - std::move(*layer), - before.isEmpty() ? std::optional() : std::optional(before.toStdString())); -} - -/*! - Returns true if the layer with given \a id exists, false otherwise. -*/ -bool Map::layerExists(const QString &id) { - return !!d_ptr->mapObj->getStyle().getLayer(id.toStdString()); -} - -/*! - Removes the layer with given \a id. -*/ -void Map::removeLayer(const QString &id) { - d_ptr->mapObj->getStyle().removeLayer(id.toStdString()); -} - -/*! - List of all existing layer ids from the current style. -*/ -QVector Map::layerIds() const { - const auto &layers = d_ptr->mapObj->getStyle().getLayers(); - - QVector layerIds; - layerIds.reserve(static_cast(layers.size())); - - for (const mbgl::style::Layer *layer : layers) { - layerIds.append(QString::fromStdString(layer->getID())); - } - - return layerIds; -} - -/*! - Adds the \a image with the identifier \a id that can be used - later by a symbol layer. - - If the \a id was already added, it gets replaced by the new - \a image only if the dimensions of the image are the same as - the old image, otherwise it has no effect. - - \sa addLayer() -*/ -void Map::addImage(const QString &id, const QImage &image) { - if (image.isNull()) return; - - d_ptr->mapObj->getStyle().addImage(toStyleImage(id, image)); -} - -/*! - Removes the image \a id. -*/ -void Map::removeImage(const QString &id) { - d_ptr->mapObj->getStyle().removeImage(id.toStdString()); -} - -/*! - Adds a \a filter to a style \a layer using the format described in the \l - {https://maplibre.org/maplibre-style-spec/deprecations/#other-filter}{Mapbox - Style Spec}. - - Given a layer \c marker from an arbitrary GeoJSON source containing features - of type \b "Point" and \b "LineString", this example shows how to make sure - the layer will only tag features of type \b "Point". - - \code - QVariantList filterExpression; - filterExpression.push_back(QLatin1String("==")); - filterExpression.push_back(QLatin1String("$type")); - filterExpression.push_back(QLatin1String("Point")); - - QVariantList filter; - filter.push_back(filterExpression); - - map->setFilter(QLatin1String("marker"), filter); - \endcode -*/ -void Map::setFilter(const QString &layer, const QVariant &filter) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - Layer *layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString()); - if (!layer_) { - qWarning() << "Layer not found:" << layer; - return; - } - - Error error; - std::optional converted = convert(filter, error); - if (!converted) { - qWarning() << "Error parsing filter:" << error.message.c_str(); - return; - } - - layer_->setFilter(std::move(*converted)); -} - -QVariant QVariantFromValue(const mbgl::Value &value) { - return value.match([](const mbgl::NullValue) { return QVariant(); }, - [](const bool value_) { return QVariant(value_); }, - [](const float value_) { return QVariant(value_); }, - [](const int64_t value_) { return QVariant(static_cast(value_)); }, - [](const double value_) { return QVariant(value_); }, - [](const std::string &value_) { return QVariant(value_.c_str()); }, - [](const mbgl::Color &value_) { return QColor(value_.r, value_.g, value_.b, value_.a); }, - [&](const std::vector &vector) { - QVariantList list; - list.reserve(static_cast(vector.size())); - for (const auto &value_ : vector) { - list.push_back(QVariantFromValue(value_)); - } - return list; - }, - [&](const std::unordered_map &map) { - QVariantMap varMap; - for (auto &item : map) { - varMap.insert(item.first.c_str(), QVariantFromValue(item.second)); - } - return varMap; - }, - [](const auto &) { return QVariant(); }); -} - -/*! - Returns the current \a expression-based filter value applied to a style - \layer, if any. - - Filter value types are described in the - {https://maplibre.org/maplibre-style-spec/types/}{MapLibre Style - Spec}. -*/ -QVariant Map::getFilter(const QString &layer) const { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - Layer *layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString()); - if (!layer_) { - qWarning() << "Layer not found:" << layer; - return QVariant(); - } - - auto serialized = layer_->getFilter().serialize(); - return QVariantFromValue(serialized); -} - -/*! - Creates the infrastructure needed for rendering the map. It - should be called before any call to render(). - - Must be called on the render thread. -*/ -void Map::createRenderer() { - d_ptr->createRenderer(); -} - -/*! - Destroys the infrastructure needed for rendering the map, - releasing resources. - - Must be called on the render thread. -*/ -void Map::destroyRenderer() { - d_ptr->destroyRenderer(); -} - -/*! - Start a static rendering of the current state of the map. This - should only be called when the map is initialized in static mode. - - \sa QMapLibreGL::Settings::MapMode -*/ -void Map::startStaticRender() { - d_ptr->mapObj->renderStill([this](std::exception_ptr err) { - QString what; - - try { - if (err) { - std::rethrow_exception(err); - } - } catch (const std::exception &e) { - what = e.what(); - } - - emit staticRenderFinished(what); - }); -} - -/*! - Renders the map using OpenGL draw calls. It will make sure to bind the - framebuffer object before drawing; otherwise a valid OpenGL context is - expected with an appropriate OpenGL viewport state set for the size of - the canvas. - - This function should be called only after the signal needsRendering() is - emitted at least once. - - Must be called on the render thread. -*/ -void Map::render() { - d_ptr->render(); -} - -/*! - If MapLibre Native needs to rebind the default \a fbo, it will use the - ID supplied here. \a size is the size of the framebuffer, which - on high DPI screens is usually bigger than the map size. - - Must be called on the render thread. -*/ -void Map::setFramebufferObject(quint32 fbo, const QSize &size) { - d_ptr->setFramebufferObject(fbo, size); -} - -/*! - Informs the map that the network connection has been established, causing - all network requests that previously timed out to be retried immediately. -*/ -void Map::connectionEstablished() { - mbgl::NetworkStatus::Reachable(); -} - -/*! - Returns a list containing a pair of string objects, representing the style - URL and name, respectively. -*/ -const QVector> &Map::defaultStyles() const { - return d_ptr->defaultStyles; -} - -/*! - \fn void QMapLibreGL::Map::needsRendering() - - This signal is emitted when the visual contents of the map have changed - and a redraw is needed in order to keep the map visually consistent - with the current state. - - \sa render() -*/ - -/*! - \fn void QMapLibreGL::Map::staticRenderFinished(const QString &error) - - This signal is emitted when a static map is fully drawn. Usually the next - step is to extract the map from a framebuffer into a container like a - QImage. \a error is set to a message when an error occurs. - - \sa startStaticRender() -*/ - -/*! - \fn void QMapLibreGL::Map::mapChanged(QMapLibreGL::Map::MapChange change) - - This signal is emitted when the state of the map has changed. This signal - may be used for detecting errors when loading a style or detecting when - a map is fully loaded by analyzing the parameter \a change. -*/ - -/*! - \fn void QMapLibreGL::Map::mapLoadingFailed(QMapLibreGL::Map::MapLoadingFailure - type, const QString &description) - - This signal is emitted when a map loading failure happens. Details of the - failures are provided, including its \a type and textual \a description. -*/ - -/*! - \fn void QMapLibreGL::Map::copyrightsChanged(const QString ©rightsHtml); - - This signal is emitted when the copyrights of the current content of the map - have changed. This can be caused by a style change or adding a new source. - - \a copyrightsHtml is a string with a HTML snippet. -*/ - -MapPrivate::MapPrivate(Map *q, const Settings &settings, const QSize &size, qreal pixelRatio_) - : QObject(q), - m_mode(settings.contextMode()), - m_pixelRatio(pixelRatio_), - m_localFontFamily(settings.localFontFamily()) { - // Setup MapObserver - m_mapObserver = std::make_unique(this); - - qRegisterMetaType("Map::MapChange"); - - connect(m_mapObserver.get(), &MapObserver::mapChanged, q, &Map::mapChanged); - connect(m_mapObserver.get(), &MapObserver::mapLoadingFailed, q, &Map::mapLoadingFailed); - connect(m_mapObserver.get(), &MapObserver::copyrightsChanged, q, &Map::copyrightsChanged); - - auto resourceOptions = resourceOptionsFromSettings(settings); - for (auto style : resourceOptions.tileServerOptions().defaultStyles()) { - defaultStyles.append( - QPair(QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName()))); - } - - auto clientOptions = clientOptionsFromSettings(settings); - - // Setup the Map object. - mapObj = std::make_unique(*this, - *m_mapObserver, - mapOptionsFromSettings(settings, size, m_pixelRatio), - resourceOptions, - clientOptionsFromSettings(settings)); - - if (settings.resourceTransform()) { - m_resourceTransform = std::make_unique>( - *mbgl::Scheduler::GetCurrent(), - [callback = settings.resourceTransform()]( - mbgl::Resource::Kind, const std::string &url_, mbgl::ResourceTransform::FinishedCallback onFinished) { - onFinished(callback(std::move(url_))); - }); - - mbgl::ResourceTransform transform{[actorRef = m_resourceTransform->self()]( - mbgl::Resource::Kind kind, - const std::string &url, - mbgl::ResourceTransform::FinishedCallback onFinished) { - actorRef.invoke(&mbgl::ResourceTransform::TransformCallback::operator(), kind, url, std::move(onFinished)); - }}; - std::shared_ptr fs = mbgl::FileSourceManager::get()->getFileSource( - mbgl::FileSourceType::Network, resourceOptions, clientOptions); - fs->setResourceTransform(std::move(transform)); - } - - // Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag. - connect(this, &MapPrivate::needsRendering, q, &Map::needsRendering, Qt::QueuedConnection); -} - -MapPrivate::~MapPrivate() {} - -void MapPrivate::update(std::shared_ptr parameters) { - std::lock_guard lock(m_mapRendererMutex); - - m_updateParameters = std::move(parameters); - - if (!m_mapRenderer) { - return; - } - - m_mapRenderer->updateParameters(std::move(m_updateParameters)); - - requestRendering(); -} - -void MapPrivate::setObserver(mbgl::RendererObserver &observer) { - m_rendererObserver = std::make_shared(*mbgl::util::RunLoop::Get(), observer); - - std::lock_guard lock(m_mapRendererMutex); - - if (m_mapRenderer) { - m_mapRenderer->setObserver(m_rendererObserver); - } -} - -void MapPrivate::createRenderer() { - std::lock_guard lock(m_mapRendererMutex); - - if (m_mapRenderer) { - return; - } - - m_mapRenderer = std::make_unique(m_pixelRatio, m_mode, m_localFontFamily); - - connect(m_mapRenderer.get(), &MapRenderer::needsRendering, this, &MapPrivate::requestRendering); - - m_mapRenderer->setObserver(m_rendererObserver); - - if (m_updateParameters) { - m_mapRenderer->updateParameters(m_updateParameters); - requestRendering(); - } -} - -void MapPrivate::destroyRenderer() { - std::lock_guard lock(m_mapRendererMutex); - - m_mapRenderer.reset(); -} - -void MapPrivate::render() { - std::lock_guard lock(m_mapRendererMutex); - - if (!m_mapRenderer) { - createRenderer(); - } - - m_renderQueued.clear(); - m_mapRenderer->render(); -} - -void MapPrivate::setFramebufferObject(quint32 fbo, const QSize &size) { - std::lock_guard lock(m_mapRendererMutex); - - if (!m_mapRenderer) { - createRenderer(); - } - - m_mapRenderer->updateFramebuffer(fbo, sanitizedSize(size)); -} - -void MapPrivate::requestRendering() { - if (!m_renderQueued.test_and_set()) { - emit needsRendering(); - } -} - -bool MapPrivate::setProperty(const PropertySetter &setter, - const QString &layer, - const QString &name, - const QVariant &value) { - using namespace mbgl::style; - - Layer *layerObject = mapObj->getStyle().getLayer(layer.toStdString()); - if (!layerObject) { - qWarning() << "Layer not found:" << layer; - return false; - } - - const std::string &propertyString = name.toStdString(); - - std::optional result; - -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::QString) { -#else - if (value.type() == QVariant::String) { -#endif - mbgl::JSDocument document; - document.Parse<0>(value.toString().toStdString()); - if (!document.HasParseError()) { - // Treat value as a valid JSON. - const mbgl::JSValue *jsonValue = &document; - result = (layerObject->*setter)(propertyString, jsonValue); - } else { - result = (layerObject->*setter)(propertyString, value); - } - } else { - result = (layerObject->*setter)(propertyString, value); - } - - if (result) { - qWarning() << "Error setting property" << name << "on layer" << layer << ":" - << QString::fromStdString(result->message); - return false; - } - - return true; -} - -} // namespace QMapLibreGL diff --git a/platform/qt/src/map_p.hpp b/platform/qt/src/map_p.hpp deleted file mode 100644 index ae44fcf64..000000000 --- a/platform/qt/src/map_p.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include - -#include "utils/map_observer.hpp" -#include "utils/map_renderer.hpp" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace QMapLibreGL { - -class MapPrivate : public QObject, public mbgl::RendererFrontend { - Q_OBJECT - -public: - explicit MapPrivate(Map*, const Settings&, const QSize& size, qreal pixelRatio); - virtual ~MapPrivate(); - - // mbgl::RendererFrontend implementation. - void reset() final {} - void setObserver(mbgl::RendererObserver&) final; - void update(std::shared_ptr) final; - - // These need to be called on the same thread. - void createRenderer(); - void destroyRenderer(); - void render(); - void setFramebufferObject(quint32 fbo, const QSize& size); - - using PropertySetter = std::optional (mbgl::style::Layer::*)( - const std::string&, const mbgl::style::conversion::Convertible&); - bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value); - - mbgl::EdgeInsets margins; - std::unique_ptr mapObj{}; - QVector> defaultStyles; - -public slots: - void requestRendering(); - -signals: - void needsRendering(); - -private: - Q_DISABLE_COPY(MapPrivate) - - std::recursive_mutex m_mapRendererMutex; - std::shared_ptr m_rendererObserver{}; - std::shared_ptr m_updateParameters{}; - - std::unique_ptr m_mapObserver{}; - std::unique_ptr m_mapRenderer{}; - std::unique_ptr> m_resourceTransform{}; - - Settings::GLContextMode m_mode; - qreal m_pixelRatio; - - QString m_localFontFamily; - - std::atomic_flag m_renderQueued = ATOMIC_FLAG_INIT; -}; - -} // namespace QMapLibreGL diff --git a/platform/qt/src/settings.cpp b/platform/qt/src/settings.cpp deleted file mode 100644 index 86a6c8e15..000000000 --- a/platform/qt/src/settings.cpp +++ /dev/null @@ -1,437 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -#include - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4805) -#endif - -// mbgl::GLContextMode -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::UniqueGLContext) == - mbgl::underlying_type(mbgl::gfx::ContextMode::Unique), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::SharedGLContext) == - mbgl::underlying_type(mbgl::gfx::ContextMode::Shared), - "error"); - -// mbgl::MapMode -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Continuous) == - mbgl::underlying_type(mbgl::MapMode::Continuous), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Static) == mbgl::underlying_type(mbgl::MapMode::Static), - "error"); - -// mbgl::ConstrainMode -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::NoConstrain) == - mbgl::underlying_type(mbgl::ConstrainMode::None), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainHeightOnly) == - mbgl::underlying_type(mbgl::ConstrainMode::HeightOnly), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainWidthAndHeight) == - mbgl::underlying_type(mbgl::ConstrainMode::WidthAndHeight), - "error"); - -// mbgl::ViewportMode -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::DefaultViewport) == - mbgl::underlying_type(mbgl::ViewportMode::Default), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Settings::FlippedYViewport) == - mbgl::underlying_type(mbgl::ViewportMode::FlippedY), - "error"); - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -namespace QMapLibreGL { - -/*! - \class QMapLibreGL::Settings - \brief The Settings class stores the initial configuration for - QMapLibreGL::Map. - - \inmodule MapLibre Maps SDK for Qt - - Settings is used to configure QMapLibreGL::Map at the moment of its - creation. Once created, the Settings of a QMapLibreGL::Map can no longer be - changed. - - Cache-related settings are shared between all QMapLibreGL::Map instances - using the same cache path. The first map to configure cache properties such - as size will force the configuration to all newly instantiated - QMapLibreGL::Map objects using the same cache in the same process. -*/ - -/*! - \enum QMapLibreGL::Settings::GLContextMode - - This enum sets the expectations for the OpenGL state. - - \value UniqueGLContext The OpenGL context is only used by QMapLibreGL::Map, - so it is not reset before each rendering. Use this mode if the intention is - to only draw a fullscreen map. - - \value SharedGLContext The OpenGL context is shared and the state will be - marked dirty - which invalidates any previously assumed GL state. The - embedder is responsible for clearing up the viewport prior to calling - QMapLibreGL::Map::render. The embedder is also responsible for resetting its - own GL state after QMapLibreGL::Map::render has finished, if needed. - - \sa contextMode() -*/ - -/*! - \enum QMapLibreGL::Settings::MapMode - - This enum sets the map rendering mode - - \value Continuous The map will render as data arrives from the network and - react immediately to state changes. - - This is the default mode and the preferred when the map is intended to be - interactive. - - \value Static The map will no longer react to state changes and will only - be rendered when QMapLibreGL::Map::startStaticRender is called. After all the - resources are loaded, the QMapLibreGL::Map::staticRenderFinished signal is emitted. - - This mode is useful for taking a snapshot of the finished rendering result - of the map into a QImage. - - \sa mapMode() -*/ - -/*! - \enum QMapLibreGL::Settings::ConstrainMode - - This enum determines if the map wraps. - - \value NoConstrain The map will wrap on the horizontal axis. - Since it doesn't make sense to wrap on the vertical axis in a Web Mercator - projection, the map will scroll and show some empty space. - - \value ConstrainHeightOnly The map will wrap around the horizontal - axis, like a spinning globe. This is the recommended constrain mode. - - \value ConstrainWidthAndHeight The map won't wrap and panning is restricted - to the boundaries of the map. - - \sa constrainMode() -*/ - -/*! - \enum QMapLibreGL::Settings::ViewportMode - - This enum flips the map vertically. - - \value DefaultViewport Native orientation. - - \value FlippedYViewport Mirrored vertically. - - \sa viewportMode() -*/ - -/*! - Constructs a Settings object with the default values. The default - configuration is valid for initializing a QMapLibreGL::Map. -*/ -Settings::Settings() - : m_contextMode(Settings::SharedGLContext), - m_mapMode(Settings::Continuous), - m_constrainMode(Settings::ConstrainHeightOnly), - m_viewportMode(Settings::DefaultViewport), - m_cacheMaximumSize(mbgl::util::DEFAULT_MAX_CACHE_SIZE), - m_cacheDatabasePath(":memory:"), - m_assetPath(QCoreApplication::applicationDirPath()), - m_apiKey(qgetenv("MLN_API_KEY")), - m_tileServerOptionsInternal(new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration())) {} - -/*! - Returns the OpenGL context mode. This is specially important when mixing - with other OpenGL draw calls. - - By default, it is set to Settings::SharedGLContext. -*/ -Settings::GLContextMode Settings::contextMode() const { - return m_contextMode; -} - -/*! - Sets the OpenGL context \a mode. -*/ -void Settings::setContextMode(GLContextMode mode) { - m_contextMode = mode; -} - -/*! - Returns the map mode. Static mode will emit a signal for - rendering a map only when the map is fully loaded. - Animations like style transitions and labels fading won't - be seen. - - The Continuous mode will emit the signal for every new - change on the map and it is usually what you expect for - a interactive map. - - By default, it is set to QMapLibreGL::Settings::Continuous. -*/ -Settings::MapMode Settings::mapMode() const { - return m_mapMode; -} - -/*! - Sets the map \a mode. -*/ -void Settings::setMapMode(MapMode mode) { - m_mapMode = mode; -} - -/*! - Returns the constrain mode. This is used to limit the map to wrap - around the globe horizontally. - - By default, it is set to QMapLibreGL::Settings::ConstrainHeightOnly. -*/ -Settings::ConstrainMode Settings::constrainMode() const { - return m_constrainMode; -} - -/*! - Sets the map constrain \a mode. -*/ -void Settings::setConstrainMode(ConstrainMode mode) { - m_constrainMode = mode; -} - -/*! - Returns the viewport mode. This is used to flip the vertical - orientation of the map as some devices may use inverted orientation. - - By default, it is set to QMapLibreGL::Settings::DefaultViewport. -*/ -Settings::ViewportMode Settings::viewportMode() const { - return m_viewportMode; -} - -/*! - Sets the viewport \a mode. -*/ -void Settings::setViewportMode(ViewportMode mode) { - m_viewportMode = mode; -} - -/*! - Returns the cache database maximum hard size in bytes. The database - will grow until the limit is reached. Setting a maximum size smaller - than the current size of an existing database results in undefined - behavior - - By default, it is set to 50 MB. -*/ -unsigned Settings::cacheDatabaseMaximumSize() const { - return m_cacheMaximumSize; -} - -/*! - Returns the maximum allowed cache database \a size in bytes. -*/ -void Settings::setCacheDatabaseMaximumSize(unsigned size) { - m_cacheMaximumSize = size; -} - -/*! - Returns the cache database path. The cache is used for storing - recently used resources like tiles and also an offline tile database - pre-populated by the - \l {https://github.com/mapbox/mapbox-gl-native/blob/master/bin/offline.sh} - {Offline Tool}. - - By default, it is set to \c :memory: meaning it will create an in-memory - cache instead of a file on disk. -*/ -QString Settings::cacheDatabasePath() const { - return m_cacheDatabasePath; -} - -/*! - Sets the cache database \a path. - - Setting the \a path to \c :memory: will create an in-memory cache. -*/ -void Settings::setCacheDatabasePath(const QString &path) { - m_cacheDatabasePath = path; -} - -/*! - Returns the asset path, which is the root directory from where - the \c asset:// scheme gets resolved in a style. \c asset:// can be used - for loading a resource from the disk in a style rather than fetching - it from the network. - - By default, it is set to the value returned by QCoreApplication::applicationDirPath(). -*/ -QString Settings::assetPath() const { - return m_assetPath; -} - -/*! - Sets the asset \a path. -*/ -void Settings::setAssetPath(const QString &path) { - m_assetPath = path; -} - -/*! - Returns the API key. - - By default, it is taken from the environment variable \c MLN_API_KEY - or empty if the variable is not set. -*/ -QString Settings::apiKey() const { - return m_apiKey; -} - -/*! - Sets the API key. - - MapTiler-hosted and Mapbox-hosted vector tiles and styles require an API - key or access token. -*/ -void Settings::setApiKey(const QString &key) { - m_apiKey = key; -} - -/*! - Returns the API base URL. -*/ -QString Settings::apiBaseUrl() const { - return QString::fromStdString(m_tileServerOptionsInternal->baseURL()); -} - -/*! - Sets the API base \a url. - - The API base URL is the URL that the \b "mapbox://" protocol will - be resolved to. It defaults to "https://api.mapbox.com" but can be - changed, for instance, to a tile cache server address. -*/ -void Settings::setApiBaseUrl(const QString &url) { - m_tileServerOptionsInternal = &m_tileServerOptionsInternal->withBaseURL(url.toStdString()); -} - -/*! - Returns the local font family. Returns an empty string if no local font family is set. -*/ -QString Settings::localFontFamily() const { - return m_localFontFamily; -} - -/*! - Sets the local font family. - - Rendering Chinese/Japanese/Korean (CJK) ideographs and precomposed Hangul - Syllables requires downloading large amounts of font data, which can - significantly slow map load times. Use the localIdeographFontFamily setting - to speed up map load times by using locally available fonts instead of font - data fetched from the server. -*/ -void Settings::setLocalFontFamily(const QString &family) { - m_localFontFamily = family; -} - -/*! - Returns the client name. Returns an empty string if no client name is set. -*/ -QString Settings::clientName() const { - return m_clientName; -} - -/*! - Sets the client name. -*/ -void Settings::setClientName(const QString &name) { - m_clientName = name; -} - -/*! - Returns the client version. Returns an empty string if no client version is set. -*/ -QString Settings::clientVersion() const { - return m_clientVersion; -} - -/*! - Sets the client version. -*/ -void Settings::setClientVersion(const QString &version) { - m_clientVersion = version; -} - -/*! - Returns resource transformation callback used to transform requested URLs. -*/ -std::function Settings::resourceTransform() const { - return m_resourceTransform; -} - -/*! - Sets the resource \a transform callback. - - When given, resource transformation callback will be used to transform the - requested resource URLs before they are requested from internet. This can be - used add or remove custom parameters, or reroute certain requests to other - servers or endpoints. -*/ -void Settings::setResourceTransform(const std::function &transform) { - m_resourceTransform = transform; -} - -/*! - Reset all settings based on the given template. - - MapLibre can support servers with different resource path structure. - Some of the most common servers like Maptiler and Mapbox are defined - in the library. This function will re-initialise all settings based - on the default values of specific service provider defaults. -*/ -void Settings::resetToTemplate(SettingsTemplate settings_template) { - if (m_tileServerOptionsInternal) delete m_tileServerOptionsInternal; - - if (settings_template == MapLibreSettings) { - m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapLibreConfiguration()); - } else if (settings_template == MapTilerSettings) { - m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapTilerConfiguration()); - } else if (settings_template == MapboxSettings) { - m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapboxConfiguration()); - } else { - m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration()); - } -} - -/*! - All predefined styles. - - Return all styles that are defined in default settings. -*/ -QVector> Settings::defaultStyles() const { - QVector> styles; - for (const auto &style : tileServerOptionsInternal()->defaultStyles()) { - styles.append( - QPair(QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName()))); - } - return styles; -} - -mbgl::TileServerOptions *Settings::tileServerOptionsInternal() const { - return m_tileServerOptionsInternal; -} - -} // namespace QMapLibreGL diff --git a/platform/qt/src/types.cpp b/platform/qt/src/types.cpp deleted file mode 100644 index 825861e00..000000000 --- a/platform/qt/src/types.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include - -#include "mbgl/util/geometry.hpp" -#include "mbgl/util/traits.hpp" - -// mbgl::FeatureType -static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Feature::LineStringType) == - mbgl::underlying_type(mbgl::FeatureType::LineString), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PolygonType) == - mbgl::underlying_type(mbgl::FeatureType::Polygon), - "error"); - -namespace QMapLibreGL { - -/*! - \namespace QMapLibreGL - \inmodule MapLibre Maps SDK for Qt - - Contains miscellaneous MapLibre types and utilities used throughout QMapLibreGLGL. -*/ - -/*! - \typedef QMapLibreGL::Coordinate - - Alias for QPair. - Representation for geographical coordinates - latitude and longitude, respectively. -*/ - -/*! - \typedef QMapLibreGL::CoordinateZoom - - Alias for QPair. - Used as return value in QMapLibreGLGL::coordinateZoomForBounds. -*/ - -/*! - \typedef QMapLibreGL::ProjectedMeters - - Alias for QPair. - Representation for projected meters - northing and easting, respectively. -*/ - -/*! - \typedef QMapLibreGL::Coordinates - - Alias for QVector. - A list of QMapLibreGL::Coordinate objects. -*/ - -/*! - \typedef QMapLibreGL::CoordinatesCollection - - Alias for QVector. - A list of QMapLibreGL::Coordinates objects. -*/ - -/*! - \typedef QMapLibreGL::CoordinatesCollections - - Alias for QVector. - A list of QMapLibreGL::CoordinatesCollection objects. -*/ - -/*! - \class QMapLibreGL::Feature - - \inmodule MapLibre Maps SDK for Qt - - Represents \l {https://www.mapbox.com/help/define-features/}{map features} - via its \a type (PointType, LineStringType or PolygonType), \a geometry, \a - properties map and \a id (optional). -*/ - -/*! - \enum QMapLibreGL::Feature::Type - - This enum is used as basis for geometry disambiguation in - QMapLibreGL::Feature. - - \value PointType A point geometry type. Means a single or a collection - of points. \value LineStringType A line string geometry type. Means a single - or a collection of line strings. \value PolygonType A polygon geometry - type. Means a single or a collection of polygons. -*/ - -/*! - \class QMapLibreGL::ShapeAnnotationGeometry - - \inmodule MapLibre Maps SDK for Qt - - Represents a shape annotation geometry. -*/ - -/*! - \enum QMapLibreGL::ShapeAnnotationGeometry::Type - - This enum is used as basis for shape annotation geometry disambiguation. - - \value PolygonType A polygon geometry type. - \value LineStringType A line string geometry type. - \value MultiPolygonType A polygon geometry collection type. - \value MultiLineStringType A line string geometry collection type. -*/ - -/*! - \class QMapLibreGL::SymbolAnnotation - - \inmodule MapLibre Maps SDK for Qt - - A symbol annotation comprises of its geometry and an icon identifier. -*/ - -/*! - \class QMapLibreGL::LineAnnotation - - \inmodule MapLibre Maps SDK for Qt - - Represents a line annotation object, along with its properties. - - A line annotation comprises of its geometry and line properties such as - opacity, width and color. -*/ - -/*! - \class QMapLibreGL::FillAnnotation - - \inmodule MapLibre Maps SDK for Qt - - Represents a fill annotation object, along with its properties. - - A fill annotation comprises of its geometry and fill properties such as - opacity, color and outline color. -*/ - -/*! - \typedef QMapLibreGL::Annotation - - Alias for QVariant. - Container that encapsulates either a symbol, a line, a fill or a style - sourced annotation. -*/ - -/*! - \typedef QMapLibreGL::AnnotationID - - Alias for quint32 representing an annotation identifier. -*/ - -/*! - \typedef QMapLibreGL::AnnotationIDs - - Alias for QVector representing a container of annotation identifiers. -*/ - -/*! - \class QMapLibreGL::CameraOptions - \inmodule MapLibre Maps SDK for Qt - - QMapLibreGL::CameraOptions provides camera options to the renderer. -*/ - -/*! - \class QMapLibreGL::CustomLayerHostInterface - - Represents a host interface to be implemented for rendering custom layers. - - \warning This is used for delegating the rendering of a layer to the user of - this API and is not officially supported. Use at your own risk. -*/ - -/*! - \class QMapLibreGL::CustomLayerRenderParameters - \inmodule MapLibre Maps SDK for Qt - - QMapLibreGL::CustomLayerRenderParameters provides the data passed on each - render pass for a custom layer. -*/ - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils.cpp b/platform/qt/src/utils.cpp deleted file mode 100644 index 7b670cbc5..000000000 --- a/platform/qt/src/utils.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include - -#include -#include -#include -#include - -#include - -// mbgl::NetworkStatus::Status -static_assert(mbgl::underlying_type(QMapLibreGL::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online), - "error"); -static_assert(mbgl::underlying_type(QMapLibreGL::Offline) == - mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline), - "error"); - -namespace QMapLibreGL { - -/*! - \enum QMapLibreGL::NetworkMode - - This enum represents whether server requests can be performed via network. - - \value Online Server network requests are accessible. - \value Offline Only requests to the local cache are accessible. -*/ - -/*! - \fn QMapLibreGL::NetworkMode QMapLibreGL::networkMode() - - Returns the current QMapLibreGL::NetworkMode. -*/ -NetworkMode networkMode() { - return static_cast(mbgl::NetworkStatus::Get()); -} - -/*! - \fn void QMapLibreGL::setNetworkMode(QMapLibreGL::NetworkMode mode) - - Forwards the network status \a mode to MapLibre Native engine. - - File source requests uses the available network when \a mode is set to \b - Online, otherwise scoped to the local cache. -*/ -void setNetworkMode(NetworkMode mode) { - mbgl::NetworkStatus::Set(static_cast(mode)); -} - -/*! - Returns the amount of meters per pixel from a given \a latitude and \a zoom. -*/ -double metersPerPixelAtLatitude(double latitude, double zoom) { - return mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoom); -} - -/*! - Return the projected meters for a given \a coordinate object. -*/ -ProjectedMeters projectedMetersForCoordinate(const Coordinate &coordinate) { - auto projectedMeters = mbgl::Projection::projectedMetersForLatLng( - mbgl::LatLng{coordinate.first, coordinate.second}); - return ProjectedMeters(projectedMeters.northing(), projectedMeters.easting()); -} - -/*! - Returns the coordinate for a given \a projectedMeters object. -*/ -Coordinate coordinateForProjectedMeters(const ProjectedMeters &projectedMeters) { - auto latLng = mbgl::Projection::latLngForProjectedMeters( - mbgl::ProjectedMeters{projectedMeters.first, projectedMeters.second}); - return Coordinate(latLng.latitude(), latLng.longitude()); -} - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/conversion.hpp b/platform/qt/src/utils/conversion.hpp deleted file mode 100644 index 6e8af00ce..000000000 --- a/platform/qt/src/utils/conversion.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#pragma once - -#include - -#include "geojson.hpp" - -#include -#include - -#include -#include - -#include - -namespace mbgl { -namespace style { -namespace conversion { - -std::string convertColor(const QColor& color); - -template <> -class ConversionTraits { -public: - static bool isUndefined(const QVariant& value) { return value.isNull() || !value.isValid(); } - - static bool isArray(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantList)); -#else - return value.canConvert(QVariant::List); -#endif - } - - static std::size_t arrayLength(const QVariant& value) { return value.toList().size(); } - - static QVariant arrayMember(const QVariant& value, std::size_t i) { return value.toList()[static_cast(i)]; } - - static bool isObject(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantMap)) || - value.typeId() == QMetaType::QByteArray -#else - return value.canConvert(QVariant::Map) || value.type() == QVariant::ByteArray -#endif - || QString(value.typeName()) == QStringLiteral("QMapLibreGL::Feature") || - value.userType() == qMetaTypeId>() || - value.userType() == qMetaTypeId>() || - value.userType() == qMetaTypeId>(); - } - - static std::optional objectMember(const QVariant& value, const char* key) { - auto map = value.toMap(); - auto iter = map.constFind(key); - - if (iter != map.constEnd()) { - return iter.value(); - } else { - return {}; - } - } - - template - static std::optional eachMember(const QVariant& value, Fn&& fn) { - auto map = value.toMap(); - auto iter = map.constBegin(); - - while (iter != map.constEnd()) { - std::optional result = fn(iter.key().toStdString(), QVariant(iter.value())); - if (result) { - return result; - } - - ++iter; - } - - return {}; - } - - static std::optional toBool(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::Bool) { -#else - if (value.type() == QVariant::Bool) { -#endif - return value.toBool(); - } else { - return {}; - } - } - - static std::optional toNumber(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { -#else - if (value.type() == QVariant::Int || value.type() == QVariant::Double) { -#endif - return value.toFloat(); - } else { - return {}; - } - } - - static std::optional toDouble(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { -#else - if (value.type() == QVariant::Int || value.type() == QVariant::Double) { -#endif - return value.toDouble(); - } else { - return {}; - } - } - - static std::optional toString(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::QString) { - return value.toString().toStdString(); - } else if (value.typeId() == QMetaType::QColor) { - return convertColor(value.value()); - } else { - return {}; - } -#else - if (value.type() == QVariant::String) { - return value.toString().toStdString(); - } else if (value.type() == QVariant::Color) { - return convertColor(value.value()); - } else { - return {}; - } -#endif - } - - static std::optional toValue(const QVariant& value) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (value.typeId() == QMetaType::Bool) { - return {value.toBool()}; - } else if (value.typeId() == QMetaType::QString) { - return {value.toString().toStdString()}; - } else if (value.typeId() == QMetaType::QColor) { - return {convertColor(value.value())}; - } else if (value.typeId() == QMetaType::Int) { - return {int64_t(value.toInt())}; - } else if (QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::Double))) { - return {value.toDouble()}; - } else { - return {}; - } -#else - if (value.type() == QVariant::Bool) { - return {value.toBool()}; - } else if (value.type() == QVariant::String) { - return {value.toString().toStdString()}; - } else if (value.type() == QVariant::Color) { - return {convertColor(value.value())}; - } else if (value.type() == QVariant::Int) { - return {int64_t(value.toInt())}; - } else if (value.canConvert(QVariant::Double)) { - return {value.toDouble()}; - } else { - return {}; - } -#endif - } - - static std::optional toGeoJSON(const QVariant& value, Error& error) { - if (value.typeName() == QStringLiteral("QMapLibreGL::Feature")) { - return GeoJSON{QMapLibreGL::GeoJSON::asFeature(value.value())}; - } else if (value.userType() == qMetaTypeId>()) { - return featureCollectionToGeoJSON(value.value>()); - } else if (value.userType() == qMetaTypeId>()) { - return featureCollectionToGeoJSON(value.value>()); - } else if (value.userType() == qMetaTypeId>()) { - return featureCollectionToGeoJSON(value.value>()); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - } else if (value.typeId() != QMetaType::QByteArray) { -#else - } else if (value.type() != QVariant::ByteArray) { -#endif - error = {"JSON data must be in QByteArray"}; - return {}; - } - - QByteArray data = value.toByteArray(); - return parseGeoJSON(std::string(data.constData(), data.size()), error); - } - -private: - template - static GeoJSON featureCollectionToGeoJSON(const T& features) { - mapbox::feature::feature_collection collection; - collection.reserve(static_cast(features.size())); - for (const auto& feature : features) { - collection.push_back(QMapLibreGL::GeoJSON::asFeature(feature)); - } - return GeoJSON{std::move(collection)}; - } -}; - -template -std::optional convert(const QVariant& value, Error& error, Args&&... args) { - return convert(Convertible(value), error, std::forward(args)...); -} - -inline std::string convertColor(const QColor& color) { - return QString::asprintf("rgba(%d,%d,%d,%lf)", color.red(), color.green(), color.blue(), color.alphaF()) - .toStdString(); -} - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/platform/qt/src/utils/geojson.cpp b/platform/qt/src/utils/geojson.cpp deleted file mode 100644 index 6b438e558..000000000 --- a/platform/qt/src/utils/geojson.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include "geojson.hpp" - -#include - -namespace QMapLibreGL::GeoJSON { - -mbgl::Point asPoint(const Coordinate &coordinate) { - return mbgl::Point{coordinate.second, coordinate.first}; -} - -mbgl::MultiPoint asMultiPoint(const Coordinates &multiPoint) { - mbgl::MultiPoint mbglMultiPoint; - mbglMultiPoint.reserve(multiPoint.size()); - for (const auto &point : multiPoint) { - mbglMultiPoint.emplace_back(asPoint(point)); - } - return mbglMultiPoint; -}; - -mbgl::LineString asLineString(const Coordinates &lineString) { - mbgl::LineString mbglLineString; - mbglLineString.reserve(lineString.size()); - for (const auto &coordinate : lineString) { - mbglLineString.emplace_back(asPoint(coordinate)); - } - return mbglLineString; -}; - -mbgl::MultiLineString asMultiLineString(const CoordinatesCollection &multiLineString) { - mbgl::MultiLineString mbglMultiLineString; - mbglMultiLineString.reserve(multiLineString.size()); - for (const auto &lineString : multiLineString) { - mbglMultiLineString.emplace_back(std::forward>(asLineString(lineString))); - } - return mbglMultiLineString; -}; - -mbgl::Polygon asPolygon(const CoordinatesCollection &polygon) { - mbgl::Polygon mbglPolygon; - mbglPolygon.reserve(polygon.size()); - for (const auto &linearRing : polygon) { - mbgl::LinearRing mbglLinearRing; - mbglLinearRing.reserve(linearRing.size()); - for (const auto &coordinate : linearRing) { - mbglLinearRing.emplace_back(asPoint(coordinate)); - } - mbglPolygon.emplace_back(std::move(mbglLinearRing)); - } - return mbglPolygon; -}; - -mbgl::MultiPolygon asMultiPolygon(const CoordinatesCollections &multiPolygon) { - mbgl::MultiPolygon mbglMultiPolygon; - mbglMultiPolygon.reserve(multiPolygon.size()); - for (const auto &polygon : multiPolygon) { - mbglMultiPolygon.emplace_back(std::forward>(asPolygon(polygon))); - } - return mbglMultiPolygon; -}; - -mbgl::Value asPropertyValue(const QVariant &value) { - auto valueList = [](const QVariantList &list) { - std::vector mbglList; - mbglList.reserve(list.size()); - for (const auto &listValue : list) { - mbglList.emplace_back(asPropertyValue(listValue)); - } - return mbglList; - }; - - auto valueMap = [](const QVariantMap &map) { - std::unordered_map mbglMap; - mbglMap.reserve(map.size()); - for (auto it = map.constBegin(); it != map.constEnd(); ++it) { - mbglMap.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value()))); - } - return mbglMap; - }; - -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - switch (value.typeId()) { -#else - switch (static_cast(value.type())) { -#endif - case QMetaType::UnknownType: - return mbgl::NullValue{}; - case QMetaType::Bool: - return {value.toBool()}; - case QMetaType::ULongLong: - return {uint64_t(value.toULongLong())}; - case QMetaType::LongLong: - return {int64_t(value.toLongLong())}; - case QMetaType::Double: - return {value.toDouble()}; - case QMetaType::QString: - return {value.toString().toStdString()}; - case QMetaType::QVariantList: - return valueList(value.toList()); - case QMetaType::QVariantMap: - return valueMap(value.toMap()); - default: - qWarning() << "Unsupported feature property value:" << value; - return {}; - } -} - -mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - switch (id.typeId()) { -#else - switch (static_cast(id.type())) { -#endif - case QMetaType::UnknownType: - return {}; - case QMetaType::ULongLong: - return {uint64_t(id.toULongLong())}; - case QMetaType::LongLong: - return {int64_t(id.toLongLong())}; - case QMetaType::Double: - return {id.toDouble()}; - case QMetaType::QString: - return {id.toString().toStdString()}; - default: - qWarning() << "Unsupported feature identifier:" << id; - return {}; - } -} - -mbgl::GeoJSONFeature asFeature(const Feature &feature) { - mbgl::PropertyMap properties; - properties.reserve(feature.properties.size()); - for (auto it = feature.properties.constBegin(); it != feature.properties.constEnd(); ++it) { - properties.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value()))); - } - - mbgl::FeatureIdentifier id = asFeatureIdentifier(feature.id); - - if (feature.type == Feature::PointType) { - const Coordinates &points = feature.geometry.first().first(); - if (points.size() == 1) { - return {asPoint(points.first()), std::move(properties), std::move(id)}; - } else { - return {asMultiPoint(points), std::move(properties), std::move(id)}; - } - } else if (feature.type == Feature::LineStringType) { - const CoordinatesCollection &lineStrings = feature.geometry.first(); - if (lineStrings.size() == 1) { - return {asLineString(lineStrings.first()), std::move(properties), std::move(id)}; - } else { - return {asMultiLineString(lineStrings), std::move(properties), std::move(id)}; - } - } else { // PolygonType - const CoordinatesCollections &polygons = feature.geometry; - if (polygons.size() == 1) { - return {asPolygon(polygons.first()), std::move(properties), std::move(id)}; - } else { - return {asMultiPolygon(polygons), std::move(properties), std::move(id)}; - } - } -}; - -} // namespace QMapLibreGL::GeoJSON diff --git a/platform/qt/src/utils/geojson.hpp b/platform/qt/src/utils/geojson.hpp deleted file mode 100644 index 90aa38ec4..000000000 --- a/platform/qt/src/utils/geojson.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include - -#include - -namespace QMapLibreGL::GeoJSON { - -mbgl::Point asPoint(const Coordinate &coordinate); -mbgl::MultiPoint asMultiPoint(const Coordinates &multiPoint); -mbgl::LineString asLineString(const Coordinates &lineString); -mbgl::MultiLineString asMultiLineString(const CoordinatesCollection &multiLineString); -mbgl::Polygon asPolygon(const CoordinatesCollection &polygon); -mbgl::MultiPolygon asMultiPolygon(const CoordinatesCollections &multiPolygon); -mbgl::Value asPropertyValue(const QVariant &value); -mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id); -mbgl::GeoJSONFeature asFeature(const Feature &feature); - -} // namespace QMapLibreGL::GeoJSON diff --git a/platform/qt/src/utils/map_observer.cpp b/platform/qt/src/utils/map_observer.cpp deleted file mode 100644 index f153df5bb..000000000 --- a/platform/qt/src/utils/map_observer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "map_observer.hpp" - -#include "../map_p.hpp" - -#include - -#include - -namespace QMapLibreGL { - -MapObserver::MapObserver(MapPrivate* d) - : d_ptr(d) {} - -MapObserver::~MapObserver() {} - -void MapObserver::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) { - if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) { - emit mapChanged(Map::MapChangeRegionWillChange); - } else { - emit mapChanged(Map::MapChangeRegionWillChangeAnimated); - } -} - -void MapObserver::onCameraIsChanging() { - emit mapChanged(Map::MapChangeRegionIsChanging); -} - -void MapObserver::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode) { - if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) { - emit mapChanged(Map::MapChangeRegionDidChange); - } else { - emit mapChanged(Map::MapChangeRegionDidChangeAnimated); - } -} - -void MapObserver::onWillStartLoadingMap() { - emit mapChanged(Map::MapChangeWillStartLoadingMap); -} - -void MapObserver::onDidFinishLoadingMap() { - emit mapChanged(Map::MapChangeDidFinishLoadingMap); -} - -void MapObserver::onDidFailLoadingMap(mbgl::MapLoadError error, const std::string& what) { - emit mapChanged(Map::MapChangeDidFailLoadingMap); - - Map::MapLoadingFailure type; - QString description(what.c_str()); - - switch (error) { - case mbgl::MapLoadError::StyleParseError: - type = Map::MapLoadingFailure::StyleParseFailure; - break; - case mbgl::MapLoadError::StyleLoadError: - type = Map::MapLoadingFailure::StyleLoadFailure; - break; - case mbgl::MapLoadError::NotFoundError: - type = Map::MapLoadingFailure::NotFoundFailure; - break; - default: - type = Map::MapLoadingFailure::UnknownFailure; - } - - emit mapLoadingFailed(type, description); -} - -void MapObserver::onWillStartRenderingFrame() { - emit mapChanged(Map::MapChangeWillStartRenderingFrame); -} - -void MapObserver::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status) { - if (status.mode == mbgl::MapObserver::RenderMode::Partial) { - emit mapChanged(Map::MapChangeDidFinishRenderingFrame); - } else { - emit mapChanged(Map::MapChangeDidFinishRenderingFrameFullyRendered); - } -} - -void MapObserver::onWillStartRenderingMap() { - emit mapChanged(Map::MapChangeWillStartRenderingMap); -} - -void MapObserver::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) { - if (mode == mbgl::MapObserver::RenderMode::Partial) { - emit mapChanged(Map::MapChangeDidFinishRenderingMap); - } else { - emit mapChanged(Map::MapChangeDidFinishRenderingMapFullyRendered); - } -} - -void MapObserver::onDidFinishLoadingStyle() { - emit mapChanged(Map::MapChangeDidFinishLoadingStyle); -} - -void MapObserver::onSourceChanged(mbgl::style::Source&) { - std::string attribution; - for (const auto& source : d_ptr->mapObj->getStyle().getSources()) { - // Avoid duplicates by using the most complete attribution HTML snippet. - if (source->getAttribution() && (attribution.size() < source->getAttribution()->size())) - attribution = *source->getAttribution(); - } - emit copyrightsChanged(QString::fromStdString(attribution)); - emit mapChanged(Map::MapChangeSourceDidChange); -} - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/map_observer.hpp b/platform/qt/src/utils/map_observer.hpp deleted file mode 100644 index 4ab0b9602..000000000 --- a/platform/qt/src/utils/map_observer.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace QMapLibreGL { - -class MapPrivate; - -class MapObserver : public QObject, public mbgl::MapObserver { - Q_OBJECT - -public: - explicit MapObserver(MapPrivate *); - virtual ~MapObserver(); - - // mbgl::MapObserver implementation. - void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final; - void onCameraIsChanging() final; - void onCameraDidChange(mbgl::MapObserver::CameraChangeMode) final; - void onWillStartLoadingMap() final; - void onDidFinishLoadingMap() final; - void onDidFailLoadingMap(mbgl::MapLoadError, const std::string &) final; - void onWillStartRenderingFrame() final; - void onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus) final; - void onWillStartRenderingMap() final; - void onDidFinishRenderingMap(mbgl::MapObserver::RenderMode) final; - void onDidFinishLoadingStyle() final; - void onSourceChanged(mbgl::style::Source &) final; - -signals: - void mapChanged(Map::MapChange); - void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason); - void copyrightsChanged(const QString ©rightsHtml); - -private: - Q_DISABLE_COPY(MapObserver) - - MapPrivate *d_ptr; -}; - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/map_renderer.cpp b/platform/qt/src/utils/map_renderer.cpp deleted file mode 100644 index 4cfcbc95b..000000000 --- a/platform/qt/src/utils/map_renderer.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "map_renderer.hpp" -#include "scheduler.hpp" - -#include - -#include - -namespace { - -static bool needsToForceScheduler() { - static QThreadStorage force; - - if (!force.hasLocalData()) { - force.setLocalData(mbgl::Scheduler::GetCurrent() == nullptr); - } - - return force.localData(); -}; - -static auto *getScheduler() { - static QThreadStorage> scheduler; - - if (!scheduler.hasLocalData()) { - scheduler.setLocalData(std::make_shared()); - } - - return scheduler.localData().get(); -}; - -} // namespace - -namespace QMapLibreGL { - -MapRenderer::MapRenderer(qreal pixelRatio, Settings::GLContextMode mode, const QString &localFontFamily) - : m_backend(static_cast(mode)), - m_renderer(std::make_unique( - m_backend, - pixelRatio, - localFontFamily.isEmpty() ? std::nullopt : std::optional{localFontFamily.toStdString()})), - m_forceScheduler(needsToForceScheduler()) { - // If we don't have a Scheduler on this thread, which - // is usually the case for render threads, use a shared - // dummy scheduler that needs to be explicitly forced to - // process events. - if (m_forceScheduler) { - auto scheduler = getScheduler(); - - if (mbgl::Scheduler::GetCurrent() == nullptr) { - mbgl::Scheduler::SetCurrent(scheduler); - } - - connect(scheduler, &Scheduler::needsProcessing, this, &MapRenderer::needsRendering); - } -} - -MapRenderer::~MapRenderer() { - MBGL_VERIFY_THREAD(tid); -} - -void MapRenderer::updateParameters(std::shared_ptr newParameters) { - std::lock_guard lock(m_updateMutex); - m_updateParameters = std::move(newParameters); -} - -void MapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size) { - MBGL_VERIFY_THREAD(tid); - - m_backend.updateFramebuffer(fbo, size); -} - -void MapRenderer::render() { - MBGL_VERIFY_THREAD(tid); - - std::shared_ptr params; - { - // Lock on the parameters - std::lock_guard lock(m_updateMutex); - - // UpdateParameters should always be available when rendering. - assert(m_updateParameters); - - // Hold on to the update parameters during render - params = m_updateParameters; - } - - // The OpenGL implementation automatically enables the OpenGL context for us. - mbgl::gfx::BackendScope scope(m_backend, mbgl::gfx::BackendScope::ScopeType::Implicit); - - m_renderer->render(params); - - if (m_forceScheduler) { - getScheduler()->processEvents(); - } -} - -void MapRenderer::setObserver(std::shared_ptr observer) { - m_renderer->setObserver(observer.get()); -} - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/map_renderer.hpp b/platform/qt/src/utils/map_renderer.hpp deleted file mode 100644 index 4b5f0fc5f..000000000 --- a/platform/qt/src/utils/map_renderer.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include - -#include "renderer_backend.hpp" - -#include -#include -#include - -#include -#include - -#include -#include - -namespace mbgl { -class Renderer; -class UpdateParameters; -} // namespace mbgl - -namespace QMapLibreGL { - -class RendererBackend; - -class MapRenderer : public QObject { - Q_OBJECT - -public: - MapRenderer(qreal pixelRatio, Settings::GLContextMode, const QString &localFontFamily); - virtual ~MapRenderer(); - - void render(); - void updateFramebuffer(quint32 fbo, const mbgl::Size &size); - void setObserver(std::shared_ptr); - - // Thread-safe, called by the Frontend - void updateParameters(std::shared_ptr); - -signals: - void needsRendering(); - -private: - MBGL_STORE_THREAD(tid) - - Q_DISABLE_COPY(MapRenderer) - - std::mutex m_updateMutex; - std::shared_ptr m_updateParameters; - - RendererBackend m_backend; - std::unique_ptr m_renderer{}; - - bool m_forceScheduler{}; -}; - -} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/renderer_backend.cpp b/platform/qt/src/utils/renderer_backend.cpp index 5a0a0e16f..bc601cde6 100644 --- a/platform/qt/src/utils/renderer_backend.cpp +++ b/platform/qt/src/utils/renderer_backend.cpp @@ -3,14 +3,15 @@ #include #include -#include #include -namespace QMapLibreGL { +#include + +namespace QMapLibre { class RenderableResource final : public mbgl::gl::RenderableResource { public: - RenderableResource(RendererBackend& backend_) + explicit RenderableResource(RendererBackend &backend_) : backend(backend_) {} void bind() override { @@ -20,11 +21,11 @@ public: } private: - RendererBackend& backend; + RendererBackend &backend; }; -RendererBackend::RendererBackend(const mbgl::gfx::ContextMode contextMode_) - : mbgl::gl::RendererBackend(contextMode_), +RendererBackend::RendererBackend(const mbgl::gfx::ContextMode mode) + : mbgl::gl::RendererBackend(mode), mbgl::gfx::Renderable({0, 0}, std::make_unique(*this)) {} RendererBackend::~RendererBackend() = default; @@ -38,18 +39,18 @@ void RendererBackend::restoreFramebufferBinding() { setFramebufferBinding(m_fbo); } -void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size& newSize) { +void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size &newSize) { m_fbo = fbo; size = newSize; } /*! - Initializes an OpenGL extension function such as Vertex Array Objects - (VAOs), required by MapLibre Native engine. + Initializes an OpenGL extension function such as Vertex Array Objects (VAOs), + required by MapLibre Native engine. */ -mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char* name) { - QOpenGLContext* thisContext = QOpenGLContext::currentContext(); +mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char *name) { + QOpenGLContext *thisContext = QOpenGLContext::currentContext(); return thisContext->getProcAddress(name); } -} // namespace QMapLibreGL +} // namespace QMapLibre diff --git a/platform/qt/src/utils/renderer_backend.hpp b/platform/qt/src/utils/renderer_backend.hpp index c83c24338..5077d5459 100644 --- a/platform/qt/src/utils/renderer_backend.hpp +++ b/platform/qt/src/utils/renderer_backend.hpp @@ -5,19 +5,19 @@ #include -namespace QMapLibreGL { +namespace QMapLibre { class RendererBackend final : public mbgl::gl::RendererBackend, public mbgl::gfx::Renderable { public: - RendererBackend(mbgl::gfx::ContextMode); + explicit RendererBackend(mbgl::gfx::ContextMode mode); ~RendererBackend() override; - void updateFramebuffer(quint32 fbo, const mbgl::Size&); + void updateFramebuffer(quint32 fbo, const mbgl::Size &newSize); void restoreFramebufferBinding(); // mbgl::gfx::RendererBackend implementation public: - mbgl::gfx::Renderable& getDefaultRenderable() override { return *this; } + mbgl::gfx::Renderable &getDefaultRenderable() override { return *this; } protected: // No-op, implicit mode. @@ -26,7 +26,7 @@ protected: // mbgl::gl::RendererBackend implementation protected: - mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) override; + mbgl::gl::ProcAddress getExtensionFunctionPointer(const char *name) override; void updateAssumedState() override; private: @@ -35,4 +35,4 @@ private: Q_DISABLE_COPY(RendererBackend) }; -} // namespace QMapLibreGL +} // namespace QMapLibre diff --git a/platform/qt/src/utils/renderer_observer.hpp b/platform/qt/src/utils/renderer_observer.hpp index f226910fb..161198cdc 100644 --- a/platform/qt/src/utils/renderer_observer.hpp +++ b/platform/qt/src/utils/renderer_observer.hpp @@ -8,17 +8,17 @@ #include -namespace QMapLibreGL { +namespace QMapLibre { // Forwards RendererObserver signals to the given // Delegate RendererObserver on the given RunLoop -class RendererObserver : public mbgl::RendererObserver { +class RendererObserver final : public mbgl::RendererObserver { public: - RendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_) + RendererObserver(mbgl::util::RunLoop &mapRunLoop, mbgl::RendererObserver &delegate_) : mailbox(std::make_shared(mapRunLoop)), delegate(delegate_, mailbox) {} - ~RendererObserver() { mailbox->close(); } + ~RendererObserver() final { mailbox->close(); } void onInvalidate() final { delegate.invoke(&mbgl::RendererObserver::onInvalidate); } @@ -34,7 +34,7 @@ public: bool repaintNeeded, bool placementChanged, double frameEncodingTime, - double frameRenderingTime) override { + double frameRenderingTime) final { void (mbgl::RendererObserver::*f)( RenderMode, bool, bool, double, double) = &mbgl::RendererObserver::onDidFinishRenderingFrame; delegate.invoke(f, mode, repaintNeeded, placementChanged, frameEncodingTime, frameRenderingTime); @@ -47,4 +47,4 @@ private: mbgl::ActorRef delegate; }; -} // namespace QMapLibreGL +} // namespace QMapLibre diff --git a/platform/qt/src/utils/scheduler.cpp b/platform/qt/src/utils/scheduler.cpp index bcc5e97f1..0c450a1bc 100644 --- a/platform/qt/src/utils/scheduler.cpp +++ b/platform/qt/src/utils/scheduler.cpp @@ -4,16 +4,16 @@ #include -namespace QMapLibreGL { +namespace QMapLibre { -Scheduler::Scheduler() {} +Scheduler::Scheduler() = default; Scheduler::~Scheduler() { MBGL_VERIFY_THREAD(tid); } void Scheduler::schedule(std::function function) { - std::lock_guard lock(m_taskQueueMutex); + const std::lock_guard lock(m_taskQueueMutex); m_taskQueue.push(std::move(function)); // Need to force the main thread to wake @@ -24,15 +24,17 @@ void Scheduler::schedule(std::function function) { void Scheduler::processEvents() { std::queue> taskQueue; { - std::unique_lock lock(m_taskQueueMutex); + const std::unique_lock lock(m_taskQueueMutex); std::swap(taskQueue, m_taskQueue); } while (!taskQueue.empty()) { auto& function = taskQueue.front(); - if (function) function(); + if (function) { + function(); + } taskQueue.pop(); } } -} // namespace QMapLibreGL +} // namespace QMapLibre diff --git a/platform/qt/src/utils/scheduler.hpp b/platform/qt/src/utils/scheduler.hpp index cbe4dfc13..f5dc18028 100644 --- a/platform/qt/src/utils/scheduler.hpp +++ b/platform/qt/src/utils/scheduler.hpp @@ -9,17 +9,17 @@ #include #include -namespace QMapLibreGL { +namespace QMapLibre { class Scheduler : public QObject, public mbgl::Scheduler { Q_OBJECT public: Scheduler(); - virtual ~Scheduler(); + ~Scheduler() override; // mbgl::Scheduler implementation. - void schedule(std::function scheduled) final; + void schedule(std::function function) final; mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } void processEvents(); @@ -35,4 +35,4 @@ private: mapbox::base::WeakPtrFactory weakFactory{this}; }; -} // namespace QMapLibreGL +} // namespace QMapLibre diff --git a/platform/qt/test/qmaplibregl.test.cpp b/platform/qt/test/qmaplibregl.test.cpp deleted file mode 100644 index ef685a36c..000000000 --- a/platform/qt/test/qmaplibregl.test.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "qmaplibregl.test.hpp" - -#include - -#include -#include -#include -#include -#include - -#include - -QMapLibreGLTest::QMapLibreGLTest() - : size(512, 512), - fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), - map(nullptr, settings, size) { - connect(&map, &QMapLibreGL::mapChanged, this, &QMapLibreGLTest::onMapChanged); - connect(&map, &QMapLibreGL::needsRendering, this, &QMapLibreGLTest::onNeedsRendering); - map.resize(fbo.size()); - map.setFramebufferObject(fbo.handle(), fbo.size()); - map.setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 14); -} - -void QMapLibreGLTest::runUntil(QMapLibreGL::MapChange status) { - changeCallback = [&](QMapLibreGL::MapChange change) { - if (change == status) { - qApp->exit(); - changeCallback = nullptr; - } - }; - - qApp->exec(); -} - -void QMapLibreGLTest::onMapChanged(QMapLibreGL::MapChange change) { - if (changeCallback) { - changeCallback(change); - } -} - -void QMapLibreGLTest::onNeedsRendering() { - widget.makeCurrent(); - fbo.bind(); - QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo.width(), fbo.height()); - map.render(); -} - -TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleJson)) { - QFile f("test/fixtures/resources/style_vector.json"); - - ASSERT_TRUE(f.open(QFile::ReadOnly | QFile::Text)); - - QTextStream in(&f); - QString json = in.readAll(); - - map.setStyleJson(json); - ASSERT_EQ(map.styleJson(), json); - runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap); - - map.setStyleJson("invalid json"); - runUntil(QMapLibreGL::MapChangeDidFailLoadingMap); - - map.setStyleJson("\"\""); - runUntil(QMapLibreGL::MapChangeDidFailLoadingMap); - - map.setStyleJson(QString()); - runUntil(QMapLibreGL::MapChangeDidFailLoadingMap); -} - -TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleUrl)) { - QString url(QMapLibreGL::defaultStyles()[0].first); - - map.setStyleUrl(url); - ASSERT_EQ(map.styleUrl(), url); - runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap); - - map.setStyleUrl("invalid://url"); - runUntil(QMapLibreGL::MapChangeDidFailLoadingMap); - - map.setStyleUrl(QString()); - runUntil(QMapLibreGL::MapChangeDidFailLoadingMap); -} diff --git a/platform/qt/test/qmaplibregl.test.hpp b/platform/qt/test/qmaplibregl.test.hpp deleted file mode 100644 index c57d6e6ec..000000000 --- a/platform/qt/test/qmaplibregl.test.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#include -#include - -#include - -class QMapLibreGLTest : public QObject, public ::testing::Test { - Q_OBJECT - -public: - QMapLibreGLTest(); - - void runUntil(QMapLibreGL::MapChange); - -private: - QGLWidget widget; - const QSize size; - QGLFramebufferObject fbo; - -protected: - Settings settings; - Map map; - - std::function changeCallback; - -private slots: - void onMapChanged(QMapLibreGL::MapChange); - void onNeedsRendering(); -}; diff --git a/test/util/image.test.cpp b/test/util/image.test.cpp index b0f89bba7..deae15c40 100644 --- a/test/util/image.test.cpp +++ b/test/util/image.test.cpp @@ -78,11 +78,13 @@ TEST(Image, JPEGTile) { EXPECT_EQ(256u, image.size.height); } +#if !defined(__QT__) // WebP support is not enabled in Qt by default TEST(Image, WebPTile) { PremultipliedImage image = decodeImage(util::read_file("test/fixtures/image/tile.webp")); EXPECT_EQ(256u, image.size.width); EXPECT_EQ(256u, image.size.height); } +#endif // !defined(__QT__) TEST(Image, Resize) { AlphaImage image({0, 0});