diff --git a/platform/qt/QMapboxGLConfig.cmake.in b/platform/qt/QMapLibreGLConfig.cmake.in similarity index 52% rename from platform/qt/QMapboxGLConfig.cmake.in rename to platform/qt/QMapLibreGLConfig.cmake.in index f1ed73a38..dc44d5c4a 100644 --- a/platform/qt/QMapboxGLConfig.cmake.in +++ b/platform/qt/QMapLibreGLConfig.cmake.in @@ -6,10 +6,10 @@ find_dependency(Qt@QT_VERSION_MAJOR@ find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Network @REQUIRED_QT_VERSION@) -if(@MBGL_WITH_QT_HEADLESS@ OR NOT @MBGL_WITH_QT_LIB_ONLY@) - find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS OpenGL @REQUIRED_QT_VERSION@) +if(@MBGL_QT_STATIC@ AND NOT @MBGL_QT_INSIDE_PLUGIN@ AND NOT @MBGL_QT_WITH_INTERNAL_SQLITE@) + find_dependency(Qt@QT_VERSION_MAJOR@ + COMPONENTS Sql @REQUIRED_QT_VERSION@) endif() -include("${CMAKE_CURRENT_LIST_DIR}/QMapboxGLTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/QMapLibreGLTargets.cmake") @PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/platform/qt/app/main.cpp b/platform/qt/app/main.cpp index 851674b5a..0ca5cd705 100644 --- a/platform/qt/app/main.cpp +++ b/platform/qt/app/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - QMapboxGLSettings settings; + QMapLibreGL::Settings settings; settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 7f657ed08..b1d0ce148 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -11,7 +11,7 @@ int kAnimationDuration = 10000; -MapWindow::MapWindow(const QMapboxGLSettings &settings) +MapWindow::MapWindow(const QMapLibreGL::Settings &settings) : m_settings(settings) { setWindowIcon(QIcon(":icon.png")); @@ -20,7 +20,7 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) MapWindow::~MapWindow() { // Make sure we have a valid context so we - // can delete the QMapboxGL. + // can delete the QMapLibreGL::Map. makeCurrent(); } @@ -64,7 +64,7 @@ void MapWindow::changeStyle() auto& styles = m_map->defaultStyles(); m_map->setStyleUrl(styles[currentStyleIndex].first); - setWindowTitle(QString("Mapbox GL: ") + styles[currentStyleIndex].second); + setWindowTitle(QString("MapLibre GL: ") + styles[currentStyleIndex].second); if (++currentStyleIndex == styles.size()) { currentStyleIndex = 0; @@ -250,10 +250,10 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_1: { if (m_symbolAnnotationId.isNull()) { - QMapbox::Coordinate coordinate = m_map->coordinate(); - QMapbox::SymbolAnnotation symbol { coordinate, "default_marker" }; + 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)); + m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue(symbol)); } else { m_map->removeAnnotation(m_symbolAnnotationId.toUInt()); m_symbolAnnotationId.clear(); @@ -262,24 +262,24 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_2: { if (m_lineAnnotationId.isNull()) { - QMapbox::Coordinates coordinates; + QMapLibreGL::Coordinates coordinates; coordinates.push_back(m_map->coordinateForPixel({ 0, 0 })); coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) })); - QMapbox::CoordinatesCollection collection; + QMapLibreGL::CoordinatesCollection collection; collection.push_back(coordinates); - QMapbox::CoordinatesCollections lineGeometry; + QMapLibreGL::CoordinatesCollections lineGeometry; lineGeometry.push_back(collection); - QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::LineStringType, lineGeometry); + QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(QMapLibreGL::ShapeAnnotationGeometry::LineStringType, lineGeometry); - QMapbox::LineAnnotation line; + 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)); + m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue(line)); } else { m_map->removeAnnotation(m_lineAnnotationId.toUInt()); m_lineAnnotationId.clear(); @@ -288,26 +288,26 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_3: { if (m_fillAnnotationId.isNull()) { - QMapbox::Coordinates coordinates; + 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 })); - QMapbox::CoordinatesCollection collection; + QMapLibreGL::CoordinatesCollection collection; collection.push_back(coordinates); - QMapbox::CoordinatesCollections fillGeometry; + QMapLibreGL::CoordinatesCollections fillGeometry; fillGeometry.push_back(collection); - QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::PolygonType, fillGeometry); + QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(QMapLibreGL::ShapeAnnotationGeometry::PolygonType, fillGeometry); - QMapbox::FillAnnotation fill; + 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)); + m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue(fill)); } else { m_map->removeAnnotation(m_fillAnnotationId.toUInt()); m_fillAnnotationId.clear(); @@ -319,20 +319,20 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) m_map->removeLayer("circleLayer"); m_map->removeSource("circleSource"); } else { - QMapbox::Coordinates coordinates; + QMapLibreGL::Coordinates coordinates; coordinates.push_back(m_map->coordinate()); - QMapbox::CoordinatesCollection collection; + QMapLibreGL::CoordinatesCollection collection; collection.push_back(coordinates); - QMapbox::CoordinatesCollections point; + QMapLibreGL::CoordinatesCollections point; point.push_back(collection); - QMapbox::Feature feature(QMapbox::Feature::PointType, point, {}, {}); + QMapLibreGL::Feature feature(QMapLibreGL::Feature::PointType, point, {}, {}); QVariantMap circleSource; circleSource["type"] = "geojson"; - circleSource["data"] = QVariant::fromValue(feature); + circleSource["data"] = QVariant::fromValue(feature); m_map->addSource("circleSource", circleSource); QVariantMap circle; @@ -357,12 +357,12 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) auto coordinate = m_map->coordinate(); coordinate.first += dx; coordinate.second += dy; - return QMapbox::Feature{QMapbox::Feature::PointType, + return QMapLibreGL::Feature{QMapLibreGL::Feature::PointType, {{{coordinate}}}, {{"color", color}}, {}}; }; - // multiple features by QVector - QVector inner{ + // multiple features by QVector + QVector inner{ makePoint(0.001, 0, "red"), makePoint(0, 0.001, "green"), makePoint(0, -0.001, "blue") @@ -376,8 +376,8 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) {"source", "innerCirclesSource"} }); - // multiple features by QList - QList outer{ + // multiple features by QList + QList outer{ makePoint( 0.002, 0.002, "cyan"), makePoint(-0.002, 0.002, "magenta"), makePoint( 0.002, -0.002, "yellow"), @@ -476,11 +476,11 @@ void MapWindow::wheelEvent(QWheelEvent *ev) void MapWindow::initializeGL() { - m_map.reset(new QMapboxGL(nullptr, m_settings, size(), pixelRatio())); + 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(QMapbox::Coordinate(60.170448, 24.942046), 5); + m_map->setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 5); QString styleUrl = qgetenv("MGL_STYLE_URL"); if (styleUrl.isEmpty()) { diff --git a/platform/qt/app/mapwindow.hpp b/platform/qt/app/mapwindow.hpp index f74f1b378..7a7016f2a 100644 --- a/platform/qt/app/mapwindow.hpp +++ b/platform/qt/app/mapwindow.hpp @@ -1,11 +1,12 @@ #ifndef MAPWINDOW_H #define MAPWINDOW_H -#include +#include +#include +#include #include #include -#include #include @@ -18,7 +19,7 @@ class MapWindow : public QOpenGLWidget Q_OBJECT public: - MapWindow(const QMapboxGLSettings &); + MapWindow(const QMapLibreGL::Settings &); ~MapWindow(); void selfTest(); @@ -43,20 +44,20 @@ private: QPointF m_lastPos; - QMapboxGLSettings m_settings; - std::unique_ptr m_map{}; + QMapLibreGL::Settings m_settings; + std::unique_ptr m_map{}; - QPropertyAnimation *m_bearingAnimation; - QPropertyAnimation *m_zoomAnimation; + QPropertyAnimation *m_bearingAnimation{}; + QPropertyAnimation *m_zoomAnimation{}; - unsigned m_animationTicks = 0; - unsigned m_frameDraws = 0; + unsigned m_animationTicks{}; + unsigned m_frameDraws{}; QVariant m_symbolAnnotationId; QVariant m_lineAnnotationId; QVariant m_fillAnnotationId; - bool m_sourceAdded = false; + bool m_sourceAdded{}; }; #endif diff --git a/platform/qt/config.qdocconf b/platform/qt/config.qdocconf index 9d3b8a7ef..fa916dc3f 100644 --- a/platform/qt/config.qdocconf +++ b/platform/qt/config.qdocconf @@ -4,10 +4,10 @@ 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_MAPBOXGL_EXPORT +Cpp.ignoretokens = Q_MAPLIBRE_EXPORT -project = QMapboxGL -description = Mapbox Maps SDK for Qt +project = QMapLibreGL +description = MapLibre GL Maps SDK for Qt language = Cpp outputdir = docs diff --git a/platform/qt/include/QMapLibreGL/Map b/platform/qt/include/QMapLibreGL/Map new file mode 100644 index 000000000..37ff787a6 --- /dev/null +++ b/platform/qt/include/QMapLibreGL/Map @@ -0,0 +1 @@ +#include "map.hpp" diff --git a/platform/qt/include/QMapLibreGL/Settings b/platform/qt/include/QMapLibreGL/Settings new file mode 100644 index 000000000..4f6be8538 --- /dev/null +++ b/platform/qt/include/QMapLibreGL/Settings @@ -0,0 +1 @@ +#include "settings.hpp" diff --git a/platform/qt/include/QMapLibreGL/Types b/platform/qt/include/QMapLibreGL/Types new file mode 100644 index 000000000..0be9e32cf --- /dev/null +++ b/platform/qt/include/QMapLibreGL/Types @@ -0,0 +1 @@ +#include "types.hpp" diff --git a/platform/qt/include/QMapLibreGL/Utils b/platform/qt/include/QMapLibreGL/Utils new file mode 100644 index 000000000..0ee624c51 --- /dev/null +++ b/platform/qt/include/QMapLibreGL/Utils @@ -0,0 +1 @@ +#include "utils.hpp" diff --git a/platform/qt/include/QMapLibreGL/export.hpp b/platform/qt/include/QMapLibreGL/export.hpp new file mode 100644 index 000000000..9d4b14d36 --- /dev/null +++ b/platform/qt/include/QMapLibreGL/export.hpp @@ -0,0 +1,16 @@ +#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/qmapboxgl.hpp b/platform/qt/include/QMapLibreGL/map.hpp similarity index 51% rename from platform/qt/include/qmapboxgl.hpp rename to platform/qt/include/QMapLibreGL/map.hpp index 351a1d954..4b6450ca6 100644 --- a/platform/qt/include/qmapboxgl.hpp +++ b/platform/qt/include/QMapLibreGL/map.hpp @@ -1,8 +1,10 @@ -#ifndef QMAPBOXGL_H -#define QMAPBOXGL_H +#ifndef QMAPLIBREGL_MAP_H +#define QMAPLIBREGL_MAP_H + +#include +#include #include -#include #include #include #include @@ -13,113 +15,13 @@ #include #include -class QMapboxGLPrivate; +namespace QMapLibreGL { + +class MapPrivate; // 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; -} - -class Q_MAPBOXGL_EXPORT QMapboxGLSettings -{ -public: - QMapboxGLSettings(); - - 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 &); - - 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; - std::function m_resourceTransform; - - mbgl::TileServerOptions *m_tileServerOptionsInternal{}; -}; - -struct Q_MAPBOXGL_EXPORT QMapboxGLCameraOptions { - QVariant center; // Coordinate - QVariant anchor; // QPointF - QVariant zoom; // double - QVariant bearing; // double - QVariant pitch; // double -}; - -class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject +class Q_MAPLIBREGL_EXPORT Map : public QObject { Q_OBJECT Q_PROPERTY(double latitude READ latitude WRITE setLatitude) @@ -130,7 +32,7 @@ class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject 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(QMapbox::Coordinate coordinate READ coordinate WRITE setCoordinate) + Q_PROPERTY(QMapLibreGL::Coordinate coordinate READ coordinate WRITE setCoordinate) Q_PROPERTY(QMargins margins READ margins WRITE setMargins) public: @@ -168,11 +70,11 @@ public: NorthLeftwards, }; - QMapboxGL(QObject* parent = 0, - const QMapboxGLSettings& = QMapboxGLSettings(), - const QSize& size = QSize(), - qreal pixelRatio = 1); - virtual ~QMapboxGL(); + Map(QObject* parent = 0, + const Settings& = Settings(), + const QSize& size = QSize(), + qreal pixelRatio = 1); + virtual ~Map(); QString styleJson() const; QString styleUrl() const; @@ -206,11 +108,11 @@ public: NorthOrientation northOrientation() const; void setNorthOrientation(NorthOrientation); - QMapbox::Coordinate coordinate() const; - void setCoordinate(const QMapbox::Coordinate &); - void setCoordinateZoom(const QMapbox::Coordinate &, double zoom); + Coordinate coordinate() const; + void setCoordinate(const Coordinate &); + void setCoordinateZoom(const Coordinate &, double zoom); - void jumpTo(const QMapboxGLCameraOptions&); + void jumpTo(const CameraOptions&); void setGestureInProgress(bool inProgress); @@ -218,9 +120,9 @@ public: void addAnnotationIcon(const QString &name, const QImage &sprite); - QMapbox::AnnotationID addAnnotation(const QMapbox::Annotation &); - void updateAnnotation(QMapbox::AnnotationID, const QMapbox::Annotation &); - void removeAnnotation(QMapbox::AnnotationID); + 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); @@ -233,17 +135,14 @@ public: void resize(const QSize &size); - double metersPerPixelAtLatitude(double latitude, double zoom) const; - QMapbox::ProjectedMeters projectedMetersForCoordinate(const QMapbox::Coordinate &) const; - QMapbox::Coordinate coordinateForProjectedMeters(const QMapbox::ProjectedMeters &) const; - QPointF pixelForCoordinate(const QMapbox::Coordinate &) const; - QMapbox::Coordinate coordinateForPixel(const QPointF &) const; + QPointF pixelForCoordinate(const Coordinate &) const; + Coordinate coordinateForPixel(const QPointF &) const; - QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, const QMapbox::Coordinate &ne) const; - QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, - const QMapbox::Coordinate &ne, - double bearing, - double pitch); + 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; @@ -257,7 +156,7 @@ public: void removeImage(const QString &name); void addCustomLayer(const QString &id, - std::unique_ptr host, + std::unique_ptr host, const QString &before = QString()); void addLayer(const QVariantMap ¶ms, const QString& before = QString()); bool layerExists(const QString &id); @@ -285,19 +184,21 @@ public slots: signals: void needsRendering(); - void mapChanged(QMapboxGL::MapChange); - void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason); + 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(QMapboxGL) + Q_DISABLE_COPY(Map) - QMapboxGLPrivate *d_ptr; + MapPrivate *d_ptr; }; -Q_DECLARE_METATYPE(QMapboxGL::MapChange); -Q_DECLARE_METATYPE(QMapboxGL::MapLoadingFailure); +} // namespace QMapLibreGL -#endif // QMAPBOXGL_H +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 new file mode 100644 index 000000000..5091cbbfa --- /dev/null +++ b/platform/qt/include/QMapLibreGL/settings.hpp @@ -0,0 +1,112 @@ +#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 &); + + 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; + std::function m_resourceTransform; + + mbgl::TileServerOptions *m_tileServerOptionsInternal{}; +}; + +} // namespace QMapLibreGL + +#endif // QMAPLIBREGL_SETTINGS_H diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/QMapLibreGL/types.hpp similarity index 63% rename from platform/qt/include/qmapbox.hpp rename to platform/qt/include/QMapLibreGL/types.hpp index e9642343b..ce601d318 100644 --- a/platform/qt/include/qmapbox.hpp +++ b/platform/qt/include/QMapLibreGL/types.hpp @@ -1,5 +1,5 @@ -#ifndef QMAPBOX_H -#define QMAPBOX_H +#ifndef QMAPLIBREGL_TYPES_H +#define QMAPLIBREGL_TYPES_H #include #include @@ -7,19 +7,9 @@ #include #include -// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style +#include "export.hpp" -#if !defined(QT_MAPBOXGL_STATIC) -# if defined(QT_BUILD_MAPBOXGL_LIB) -# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT -# else -# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_MAPBOXGL_EXPORT -#endif - -namespace QMapbox { +namespace QMapLibreGL { typedef QPair Coordinate; typedef QPair CoordinateZoom; @@ -30,7 +20,7 @@ typedef QVector CoordinatesCollection; typedef QVector CoordinatesCollections; -struct Q_MAPBOXGL_EXPORT Feature { +struct Q_MAPLIBREGL_EXPORT Feature { enum Type { PointType = 1, LineStringType, @@ -48,7 +38,7 @@ struct Q_MAPBOXGL_EXPORT Feature { QVariant id; }; -struct Q_MAPBOXGL_EXPORT ShapeAnnotationGeometry { +struct Q_MAPLIBREGL_EXPORT ShapeAnnotationGeometry { enum Type { LineStringType = 1, PolygonType, @@ -64,12 +54,12 @@ struct Q_MAPBOXGL_EXPORT ShapeAnnotationGeometry { CoordinatesCollections geometry; }; -struct Q_MAPBOXGL_EXPORT SymbolAnnotation { +struct Q_MAPLIBREGL_EXPORT SymbolAnnotation { Coordinate geometry; QString icon; }; -struct Q_MAPBOXGL_EXPORT LineAnnotation { +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) @@ -81,7 +71,7 @@ struct Q_MAPBOXGL_EXPORT LineAnnotation { QColor color; }; -struct Q_MAPBOXGL_EXPORT FillAnnotation { +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()) @@ -97,16 +87,16 @@ typedef QVariant Annotation; typedef quint32 AnnotationID; typedef QVector AnnotationIDs; -enum NetworkMode { - Online, // Default - Offline, +struct Q_MAPLIBREGL_EXPORT CameraOptions { + QVariant center; // Coordinate + QVariant anchor; // QPointF + QVariant zoom; // double + QVariant bearing; // double + QVariant pitch; // double }; -Q_MAPBOXGL_EXPORT NetworkMode networkMode(); -Q_MAPBOXGL_EXPORT void setNetworkMode(NetworkMode); - // This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters. -struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters { +struct Q_MAPLIBREGL_EXPORT CustomLayerRenderParameters { double width; double height; double latitude; @@ -117,7 +107,7 @@ struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters { double fieldOfView; }; -class Q_MAPBOXGL_EXPORT CustomLayerHostInterface { +class Q_MAPLIBREGL_EXPORT CustomLayerHostInterface { public: virtual ~CustomLayerHostInterface() = default; virtual void initialize() = 0; @@ -125,21 +115,17 @@ public: virtual void deinitialize() = 0; }; -Q_MAPBOXGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom); -Q_MAPBOXGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &); -Q_MAPBOXGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &); +} // namespace QMapLibreGL -} // namespace QMapbox +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(QMapbox::Coordinate); -Q_DECLARE_METATYPE(QMapbox::Coordinates); -Q_DECLARE_METATYPE(QMapbox::CoordinatesCollection); -Q_DECLARE_METATYPE(QMapbox::CoordinatesCollections); -Q_DECLARE_METATYPE(QMapbox::Feature); +Q_DECLARE_METATYPE(QMapLibreGL::SymbolAnnotation); +Q_DECLARE_METATYPE(QMapLibreGL::ShapeAnnotationGeometry); +Q_DECLARE_METATYPE(QMapLibreGL::LineAnnotation); +Q_DECLARE_METATYPE(QMapLibreGL::FillAnnotation); -Q_DECLARE_METATYPE(QMapbox::SymbolAnnotation); -Q_DECLARE_METATYPE(QMapbox::ShapeAnnotationGeometry); -Q_DECLARE_METATYPE(QMapbox::LineAnnotation); -Q_DECLARE_METATYPE(QMapbox::FillAnnotation); - -#endif // QMAPBOX_H +#endif // QMAPLIBREGL_TYPES_H diff --git a/platform/qt/include/QMapLibreGL/utils.hpp b/platform/qt/include/QMapLibreGL/utils.hpp new file mode 100644 index 000000000..a1143a041 --- /dev/null +++ b/platform/qt/include/QMapLibreGL/utils.hpp @@ -0,0 +1,25 @@ +#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/include/QMapbox b/platform/qt/include/QMapbox deleted file mode 100644 index a8479c09a..000000000 --- a/platform/qt/include/QMapbox +++ /dev/null @@ -1 +0,0 @@ -#include "qmapbox.hpp" diff --git a/platform/qt/include/QMapboxGL b/platform/qt/include/QMapboxGL deleted file mode 100644 index 15b55a9ab..000000000 --- a/platform/qt/include/QMapboxGL +++ /dev/null @@ -1 +0,0 @@ -#include "qmapboxgl.hpp" diff --git a/platform/qt/ninja.exe b/platform/qt/ninja.exe deleted file mode 100755 index f86ef0738..000000000 Binary files a/platform/qt/ninja.exe and /dev/null differ diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 3f98b5b6a..031ca8083 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -7,25 +7,22 @@ set(MBGL_QT_VERSION_COMPATIBILITY 2.0.0) message(STATUS "Version ${MBGL_QT_VERSION}") option(MBGL_QT_LIBRARY_ONLY "Build only libraries" OFF) -option(MBGL_QT_STATIC "Build Mapbox GL Qt bindings staticly" OFF) -option(MBGL_QT_INSIDE_PLUGIN "Build qmapboxgl as OBJECT library, so it can be bundled into separate single plugin lib." OFF) -option(MBGL_WITH_QT_HEADLESS "Build Mapbox GL Qt with headless support" ON) -option(MBGL_QT_WITH_INTERNAL_SQLITE "Build Mapbox GL Qt bindings with internal sqlite" OFF) +option(MBGL_QT_STATIC "Build MapLibre GL Qt bindings staticly" OFF) +option(MBGL_QT_INSIDE_PLUGIN "Build QMapLibreGL as OBJECT library, so it can be bundled into separate single plugin lib." OFF) +option(MBGL_QT_WITH_HEADLESS "Build MapLibre GL Qt with headless support" ON) +option(MBGL_QT_WITH_INTERNAL_SQLITE "Build MapLibre GL Qt bindings with internal sqlite" OFF) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Network REQUIRED) -if (Qt6_FOUND) - find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED) -endif() -if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY) - find_package(Qt${QT_VERSION_MAJOR} - COMPONENTS OpenGL - Widgets - REQUIRED) +if(NOT MBGL_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 MBGL_QT_WITH_INTERNAL_SQLITE) @@ -36,7 +33,7 @@ else() endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - option(MBGL_QT_WITH_INTERNAL_ICU "Build Mapbox GL Qt bindings with internal ICU" OFF) + option(MBGL_QT_WITH_INTERNAL_ICU "Build MapLibre GL Qt bindings with internal ICU" OFF) if(NOT MBGL_QT_WITH_INTERNAL_ICU) find_package(ICU COMPONENTS uc REQUIRED) else() @@ -72,7 +69,7 @@ endif() target_sources( mbgl-core PRIVATE - ${PROJECT_SOURCE_DIR}/platform/$,default/src/mbgl/text/bidi.cpp,qt/src/bidi.cpp> + ${PROJECT_SOURCE_DIR}/platform/$,default/src/mbgl/text/bidi.cpp,qt/src/mbgl/bidi.cpp> ${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gfx/headless_backend.hpp ${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gfx/headless_frontend.hpp ${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gl/headless_backend.hpp @@ -94,43 +91,31 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp - ${PROJECT_SOURCE_DIR}/platform/$,default/src/mbgl/storage/sqlite3.cpp,qt/src/sqlite3.cpp> + ${PROJECT_SOURCE_DIR}/platform/$,default/src/mbgl/storage/sqlite3.cpp,qt/src/mbgl/sqlite3.cpp> ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/monotonic_timer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/async_task.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/async_task_impl.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/number_format.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/gl_functions.cpp - $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.cpp> - $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.hpp> - $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/http_request.cpp> - $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/http_request.hpp> - ${PROJECT_SOURCE_DIR}/platform/qt/src/local_glyph_rasterizer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qt_image.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qt_logging.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/run_loop.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/run_loop_impl.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/string_stdlib.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/thread.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/thread_local.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/timer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/timer_impl.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/utf.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/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> + $<$:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_request.hpp> + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/image.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/number_format.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/local_glyph_rasterizer.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/logging_qt.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/run_loop.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/run_loop_impl.hpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/string_stdlib.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/thread.cpp + ${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/thread_local.cpp + ${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 ) -if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY) - target_sources( - mbgl-core - PRIVATE - ${PROJECT_SOURCE_DIR}/platform/qt/src/headless_backend_qt.cpp - ) - target_link_libraries( - mbgl-core - PRIVATE - Qt${QT_VERSION_MAJOR}::OpenGL - ) -endif() - target_compile_definitions( mbgl-core PRIVATE QT_IMAGE_DECODERS @@ -159,84 +144,100 @@ target_link_libraries( mbgl-vendor-nunicode ) -set(qmapboxgl_headers - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapbox - ${PROJECT_SOURCE_DIR}/platform/qt/include/QMapboxGL - ${PROJECT_SOURCE_DIR}/platform/qt/include/qmapbox.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/include/qmapboxgl.hpp +set(qmaplibregl_headers + ${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 (MBGL_QT_INSIDE_PLUGIN) - add_library(qmapboxgl OBJECT) + add_library(qmaplibregl OBJECT) elseif(MBGL_QT_STATIC) - add_library(qmapboxgl STATIC) + add_library(qmaplibregl STATIC) else() - add_library(qmapboxgl SHARED) + add_library(qmaplibregl SHARED) endif() target_sources( - qmapboxgl + qmaplibregl PRIVATE - ${qmapboxgl_headers} - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapbox.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_observer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_observer.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_renderer.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_renderer.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_p.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_renderer_backend.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_renderer_backend.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_scheduler.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_scheduler.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qt_conversion.hpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qt_geojson.cpp - ${PROJECT_SOURCE_DIR}/platform/qt/src/qt_geojson.hpp + ${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( - qmapboxgl PROPERTIES + qmaplibregl PROPERTIES AUTOMOC ON - EXPORT_NAME QMapboxGL - OUTPUT_NAME QMapboxGL + EXPORT_NAME QMapLibreGL + OUTPUT_NAME QMapLibreGL VERSION ${MBGL_QT_VERSION} SOVERSION ${MBGL_QT_VERSION_COMPATIBILITY} - PUBLIC_HEADER "${qmapboxgl_headers}" + PUBLIC_HEADER "${qmaplibregl_headers}" ) -if (NOT MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN) +if (APPLE AND NOT MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN) set_target_properties( - qmapboxgl PROPERTIES + qmaplibregl PROPERTIES FRAMEWORK ON FRAMEWORK_VERSION A + MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.QMapLibreGL + MACOSX_FRAMEWORK_BUNDLE_VERSION ${MBGL_QT_VERSION} + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MBGL_QT_VERSION} + ) + target_include_directories( + qmaplibregl + INTERFACE + $ ) endif() include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapboxGL/) +set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapLibreGL/) configure_package_config_file( - "platform/qt/QMapboxGLConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake" - INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} - PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR - CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO) + "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}/QMapboxGLConfigVersion.cmake - VERSION ${MBGL_QT_VERSION} - COMPATIBILITY AnyNewerVersion) +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake + VERSION ${MBGL_QT_VERSION} + COMPATIBILITY AnyNewerVersion) -install(EXPORT QMapboxGLTargets - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) +install(EXPORT QMapLibreGLTargets + DESTINATION ${CMAKECONFIG_INSTALL_DIR} + COMPONENT development) -export(EXPORT QMapboxGLTargets) +export(EXPORT QMapLibreGLTargets) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake" - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) + "${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake" + DESTINATION ${CMAKECONFIG_INSTALL_DIR} + COMPONENT development) install( DIRECTORY include/mbgl @@ -246,43 +247,54 @@ install( # FIXME: Because of rapidjson conversion target_include_directories( - qmapboxgl + qmaplibregl PRIVATE - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/platform/qt/include - INTERFACE - "$" + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/platform/qt/include ) target_compile_definitions( - qmapboxgl + qmaplibregl PRIVATE - QT_BUILD_MAPBOXGL_LIB + QT_BUILD_MAPLIBREGL_LIB ) target_link_libraries( - qmapboxgl + qmaplibregl PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network PRIVATE - "$" - "$" - "$" - "$" - "$" + $ + $ + $ + $ + $ ) +# Do not use generator expressions for cleaner output +if (MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN) + target_link_libraries( + qmaplibregl + PUBLIC + $<$>:Qt${QT_VERSION_MAJOR}::Sql> + $<$,$>>:z> + ) + target_compile_definitions( + qmaplibregl + PUBLIC QT_MAPLIBREGL_STATIC + ) +endif() -install(TARGETS qmapboxgl - EXPORT QMapboxGLTargets +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}" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/QMapLibreGL" ) if(NOT MBGL_QT_LIBRARY_ONLY) @@ -302,12 +314,6 @@ if(NOT MBGL_QT_LIBRARY_ONLY) set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98) set_property(TARGET mbgl-qt PROPERTY AUTOMOC ON) - target_compile_definitions( - mbgl-qt - PRIVATE - $<$,$>:QT_MAPBOXGL_STATIC> - ) - target_link_libraries( mbgl-qt PRIVATE @@ -315,7 +321,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY) Qt${QT_VERSION_MAJOR}::Gui $<$:Qt${QT_VERSION_MAJOR}::OpenGLWidgets> mbgl-compiler-options - qmapboxgl + qmaplibregl ) target_include_directories( @@ -341,9 +347,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY) target_link_libraries( mbgl-test-runner PRIVATE - Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui - Qt${QT_VERSION_MAJOR}::OpenGL mbgl-compiler-options $<$>:pthread> ) diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/map.cpp similarity index 61% rename from platform/qt/src/qmapboxgl.cpp rename to platform/qt/src/map.cpp index 0d9413aa1..3672e5cc9 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/map.cpp @@ -1,11 +1,12 @@ -#include "qmapboxgl.hpp" -#include "qmapboxgl_p.hpp" +#include +#include -#include "qmapboxgl_map_observer.hpp" -#include "qmapboxgl_renderer_observer.hpp" +#include "map_p.hpp" -#include "qt_conversion.hpp" -#include "qt_geojson.hpp" +#include "utils/conversion.hpp" +#include "utils/geojson.hpp" +#include "utils/map_observer.hpp" +#include "utils/renderer_observer.hpp" #include #include @@ -49,52 +50,27 @@ #include #include -#include - +#include #include -#include -#include -#include -#include #include #include #include #include -#include #include #include #include -using namespace QMapbox; - #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4805) #endif -// mbgl::GLContextMode -static_assert(mbgl::underlying_type(QMapboxGLSettings::UniqueGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Unique), "error"); -static_assert(mbgl::underlying_type(QMapboxGLSettings::SharedGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Shared), "error"); - -// mbgl::MapMode -static_assert(mbgl::underlying_type(QMapboxGLSettings::Continuous) == mbgl::underlying_type(mbgl::MapMode::Continuous), "error"); -static_assert(mbgl::underlying_type(QMapboxGLSettings::Static) == mbgl::underlying_type(mbgl::MapMode::Static), "error"); - -// mbgl::ConstrainMode -static_assert(mbgl::underlying_type(QMapboxGLSettings::NoConstrain) == mbgl::underlying_type(mbgl::ConstrainMode::None), "error"); -static_assert(mbgl::underlying_type(QMapboxGLSettings::ConstrainHeightOnly) == mbgl::underlying_type(mbgl::ConstrainMode::HeightOnly), "error"); -static_assert(mbgl::underlying_type(QMapboxGLSettings::ConstrainWidthAndHeight) == mbgl::underlying_type(mbgl::ConstrainMode::WidthAndHeight), "error"); - -// mbgl::ViewportMode -static_assert(mbgl::underlying_type(QMapboxGLSettings::DefaultViewport) == mbgl::underlying_type(mbgl::ViewportMode::Default), "error"); -static_assert(mbgl::underlying_type(QMapboxGLSettings::FlippedYViewport) == mbgl::underlying_type(mbgl::ViewportMode::FlippedY), "error"); - // mbgl::NorthOrientation -static_assert(mbgl::underlying_type(QMapboxGL::NorthUpwards) == mbgl::underlying_type(mbgl::NorthOrientation::Upwards), "error"); -static_assert(mbgl::underlying_type(QMapboxGL::NorthRightwards) == mbgl::underlying_type(mbgl::NorthOrientation::Rightwards), "error"); -static_assert(mbgl::underlying_type(QMapboxGL::NorthDownwards) == mbgl::underlying_type(mbgl::NorthOrientation::Downwards), "error"); -static_assert(mbgl::underlying_type(QMapboxGL::NorthLeftwards) == mbgl::underlying_type(mbgl::NorthOrientation::Leftwards), "error"); +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) @@ -135,416 +111,106 @@ std::unique_ptr toStyleImage(const QString &id, const QImage 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::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 -/*! - \class QMapboxGLSettings - \brief The QMapboxGLSettings class stores the initial configuration for QMapboxGL. - \inmodule Mapbox Maps SDK for Qt - - QMapboxGLSettings is used to configure QMapboxGL at the moment of its creation. - Once created, the QMapboxGLSettings of a QMapboxGL can no longer be changed. - - Cache-related settings are shared between all QMapboxGL instances using the same cache path. - The first map to configure cache properties such as size will force the configuration - to all newly instantiated QMapboxGL objects using the same cache in the same process. - - \since 4.7 -*/ +namespace QMapLibreGL { /*! - \enum QMapboxGLSettings::GLContextMode + \class QMapLibreGL::Map + \brief The QMapLibreGL::Map class is a Qt wrapper for the MapLibre GL Native engine. - This enum sets the expectations for the OpenGL state. + \inmodule MapLibre Maps SDK for Qt - \value UniqueGLContext The OpenGL context is only used by QMapboxGL, 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 - QMapboxGL::render. The embedder is also responsible for resetting its own - GL state after QMapboxGL::render has finished, if needed. - - \sa contextMode() -*/ - -/*! - \enum QMapboxGLSettings::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 QMapboxGL::startStaticRender is called. After all the - resources are loaded, the QMapboxGL::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 QMapboxGLSettings::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 QMapboxGLSettings::ViewportMode - - This enum flips the map vertically. - - \value DefaultViewport Native orientation. - - \value FlippedYViewport Mirrored vertically. - - \sa viewportMode() -*/ - -/*! - Constructs a QMapboxGLSettings object with the default values. The default - configuration is valid for initializing a QMapboxGL. -*/ -QMapboxGLSettings::QMapboxGLSettings() - : m_contextMode(QMapboxGLSettings::SharedGLContext) - , m_mapMode(QMapboxGLSettings::Continuous) - , m_constrainMode(QMapboxGLSettings::ConstrainHeightOnly) - , m_viewportMode(QMapboxGLSettings::DefaultViewport) - , m_cacheMaximumSize(mbgl::util::DEFAULT_MAX_CACHE_SIZE) - , m_cacheDatabasePath(":memory:") - , m_assetPath(QCoreApplication::applicationDirPath()) - , m_apiKey(qgetenv("MGL_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 QMapboxGLSettings::SharedGLContext. -*/ -QMapboxGLSettings::GLContextMode QMapboxGLSettings::contextMode() const -{ - return m_contextMode; -} - -/*! - Sets the OpenGL context \a mode. -*/ -void QMapboxGLSettings::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 QMapboxGLSettings::Continuous. -*/ -QMapboxGLSettings::MapMode QMapboxGLSettings::mapMode() const -{ - return m_mapMode; -} - -/*! - Sets the map \a mode. -*/ -void QMapboxGLSettings::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 QMapboxGLSettings::ConstrainHeightOnly. -*/ -QMapboxGLSettings::ConstrainMode QMapboxGLSettings::constrainMode() const -{ - return m_constrainMode; -} - -/*! - Sets the map constrain \a mode. -*/ -void QMapboxGLSettings::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 QMapboxGLSettings::DefaultViewport. -*/ -QMapboxGLSettings::ViewportMode QMapboxGLSettings::viewportMode() const -{ - return m_viewportMode; -} - -/*! - Sets the viewport \a mode. -*/ -void QMapboxGLSettings::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 QMapboxGLSettings::cacheDatabaseMaximumSize() const -{ - return m_cacheMaximumSize; -} - -/*! - Returns the maximum allowed cache database \a size in bytes. -*/ -void QMapboxGLSettings::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 QMapboxGLSettings::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 QMapboxGLSettings::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 QMapboxGLSettings::assetPath() const -{ - return m_assetPath; -} - -/*! - Sets the asset \a path. -*/ -void QMapboxGLSettings::setAssetPath(const QString &path) -{ - m_assetPath = path; -} - -/*! - Returns the API key. - - By default, it is taken from the environment variable \c MGL_API_KEY - or empty if the variable is not set. -*/ -QString QMapboxGLSettings::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 QMapboxGLSettings::setApiKey(const QString &key) -{ - m_apiKey = key; -} - -/*! - Returns the API base URL. -*/ -QString QMapboxGLSettings::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 QMapboxGLSettings::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 QMapboxGLSettings::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 QMapboxGLSettings::setLocalFontFamily(const QString &family) -{ - m_localFontFamily = family; -} - -/*! - Returns resource transformation callback used to transform requested URLs. -*/ -std::function QMapboxGLSettings::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 QMapboxGLSettings::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 QMapboxGLSettings::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 > QMapboxGLSettings::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 *QMapboxGLSettings::tileServerOptionsInternal() const { - return m_tileServerOptionsInternal; -} - -/*! - \class QMapboxGL - \brief The QMapboxGL class is a Qt wrapper for the Mapbox GL Native engine. - - \inmodule Mapbox Maps SDK for Qt - - QMapboxGL is a Qt friendly version the Mapbox GL Native engine using Qt types - and deep integration with Qt event loop. QMapboxGL relies as much as possible + QMapLibreGL::Map is a Qt friendly version the MapLibre GL 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. - QMapboxGL is not thread-safe and it is assumed that it will be accessed from + 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. - - \since 4.7 */ /*! - \enum QMapboxGL::MapChange + \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 QMapboxGL. + \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 QMapboxGL. + \value MapChangeRegionDidChangeAnimated Not in use by QMapLibreGL::Map. \value MapChangeWillStartLoadingMap The map is getting loaded. This state - is set only once right after QMapboxGL is created and a style is set. + 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 @@ -566,7 +232,7 @@ mbgl::TileServerOptions *QMapboxGLSettings::tileServerOptionsInternal() const { \value MapChangeWillStartRenderingMap Set once when the map is about to get rendered for the first time. - \value MapChangeDidFinishRenderingMap Not in use by QMapboxGL. + \value MapChangeDidFinishRenderingMap Not in use by QMapLibreGL::Map. \value MapChangeDidFinishRenderingMapFullyRendered Map is fully loaded and rendered. @@ -578,7 +244,7 @@ mbgl::TileServerOptions *QMapboxGLSettings::tileServerOptionsInternal() const { */ /*! - \enum QMapboxGL::MapLoadingFailure + \enum QMapLibreGL::Map::MapLoadingFailure This enum represents map loading failure type. @@ -591,7 +257,7 @@ mbgl::TileServerOptions *QMapboxGLSettings::tileServerOptionsInternal() const { */ /*! - \enum QMapboxGL::NorthOrientation + \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). @@ -609,35 +275,35 @@ mbgl::TileServerOptions *QMapboxGLSettings::tileServerOptionsInternal() const { */ /*! - Constructs a QMapboxGL object with \a settings and sets \a parent_ as the parent + 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. */ -QMapboxGL::QMapboxGL(QObject *parent_, const QMapboxGLSettings &settings, const QSize& size, qreal pixelRatio) +Map::Map(QObject *parent_, const Settings &settings, const QSize& size, qreal pixelRatio) : QObject(parent_) { assert(!size.isEmpty()); - // Multiple QMapboxGL running on the same thread + // 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 QMapboxGLPrivate(this, settings, size, pixelRatio); + d_ptr = new MapPrivate(this, settings, size, pixelRatio); } /*! - Destroys this QMapboxGL. + Destroys this QMapLibreGL::Map. */ -QMapboxGL::~QMapboxGL() +Map::~Map() { delete d_ptr; } /*! - \property QMapboxGL::styleJson + \property QMapLibreGL::Map::styleJson \brief the map style JSON. Sets a new \a style from a JSON that must conform to the @@ -645,20 +311,20 @@ QMapboxGL::~QMapboxGL() {Mapbox style specification}. \note In case of a invalid style it will trigger a mapChanged - signal with QMapboxGL::MapChangeDidFailLoadingMap as argument. + signal with QMapLibreGL::Map::MapChangeDidFailLoadingMap as argument. */ -QString QMapboxGL::styleJson() const +QString Map::styleJson() const { return QString::fromStdString(d_ptr->mapObj->getStyle().getJSON()); } -void QMapboxGL::setStyleJson(const QString &style) +void Map::setStyleJson(const QString &style) { d_ptr->mapObj->getStyle().loadJSON(style.toStdString()); } /*! - \property QMapboxGL::styleUrl + \property QMapLibreGL::Map::styleUrl \brief the map style URL. Sets a URL for fetching a JSON that will be later fed to @@ -670,55 +336,55 @@ void QMapboxGL::setStyleJson(const QString &style) from anything that QNetworkAccessManager can handle. \note In case of a invalid style it will trigger a mapChanged - signal with QMapboxGL::MapChangeDidFailLoadingMap as argument. + signal with QMapLibreGL::Map::MapChangeDidFailLoadingMap as argument. */ -QString QMapboxGL::styleUrl() const +QString Map::styleUrl() const { return QString::fromStdString(d_ptr->mapObj->getStyle().getURL()); } -void QMapboxGL::setStyleUrl(const QString &url) +void Map::setStyleUrl(const QString &url) { d_ptr->mapObj->getStyle().loadURL(url.toStdString()); } /*! - \property QMapboxGL::latitude + \property QMapLibreGL::Map::latitude \brief the map's current latitude in degrees. - Setting a latitude doesn't necessarily mean it will be accepted since QMapboxGL + 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 QMapboxGL::latitude() const +double Map::latitude() const { return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->latitude(); } -void QMapboxGL::setLatitude(double latitude_) +void Map::setLatitude(double latitude_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude_, longitude() }).withPadding(d_ptr->margins)); } /*! - \property QMapboxGL::longitude + \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 QMapboxGL::longitude() const +double Map::longitude() const { return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->longitude(); } -void QMapboxGL::setLongitude(double longitude_) +void Map::setLongitude(double longitude_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude(), longitude_ }).withPadding(d_ptr->margins)); } /*! - \property QMapboxGL::scale + \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 @@ -730,18 +396,18 @@ void QMapboxGL::setLongitude(double longitude_) \sa zoom() */ -double QMapboxGL::scale() const +double Map::scale() const { return std::pow(2.0, zoom()); } -void QMapboxGL::setScale(double scale_, const QPointF ¢er) +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 QMapboxGL::zoom + \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 @@ -750,12 +416,12 @@ void QMapboxGL::setScale(double scale_, const QPointF ¢er) \sa scale() */ -double QMapboxGL::zoom() const +double Map::zoom() const { return *d_ptr->mapObj->getCameraOptions().zoom; } -void QMapboxGL::setZoom(double zoom_) +void Map::setZoom(double zoom_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withZoom(zoom_).withPadding(d_ptr->margins)); } @@ -765,7 +431,7 @@ void QMapboxGL::setZoom(double zoom_) \sa maximumZoom() */ -double QMapboxGL::minimumZoom() const +double Map::minimumZoom() const { return *d_ptr->mapObj->getBounds().minZoom; } @@ -775,26 +441,26 @@ double QMapboxGL::minimumZoom() const \sa minimumZoom() */ -double QMapboxGL::maximumZoom() const +double Map::maximumZoom() const { return *d_ptr->mapObj->getBounds().maxZoom; } /*! - \property QMapboxGL::coordinate + \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 QMapboxGL::coordinate() const +Coordinate Map::coordinate() const { const mbgl::LatLng latLng = *d_ptr->mapObj->getCameraOptions(d_ptr->margins).center; return Coordinate(latLng.latitude(), latLng.longitude()); } -void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_) +void Map::setCoordinate(const Coordinate &coordinate_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions() .withCenter(mbgl::LatLng { coordinate_.first, coordinate_.second }) @@ -802,7 +468,7 @@ void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_) } /*! - \fn QMapboxGL::setCoordinateZoom(const QMapbox::Coordinate &coordinate, double zoom) + \fn QMapLibreGL::Map::setCoordinateZoom(const Coordinate &coordinate, double zoom) Convenience method for setting the \a coordinate and \a zoom simultaneously. @@ -812,7 +478,7 @@ void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_) \sa zoom() \sa coordinate() */ -void QMapboxGL::setCoordinateZoom(const QMapbox::Coordinate &coordinate_, double zoom_) +void Map::setCoordinateZoom(const Coordinate &coordinate_, double zoom_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions() .withCenter(mbgl::LatLng { coordinate_.first, coordinate_.second }) @@ -823,7 +489,7 @@ void QMapboxGL::setCoordinateZoom(const QMapbox::Coordinate &coordinate_, double /*! Atomically jumps to the \a camera options. */ -void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera) +void Map::jumpTo(const CameraOptions& camera) { mbgl::CameraOptions mbglCamera; if (camera.center.isValid()) { @@ -850,7 +516,7 @@ void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera) } /*! - \property QMapboxGL::bearing + \property QMapLibreGL::Map::bearing \brief the map bearing in degrees. Set the angle in degrees. Negative values and values over 360 are @@ -861,19 +527,19 @@ void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera) \sa margins() */ -double QMapboxGL::bearing() const +double Map::bearing() const { return *d_ptr->mapObj->getCameraOptions().bearing; } -void QMapboxGL::setBearing(double degrees) +void Map::setBearing(double degrees) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions() .withBearing(degrees) .withPadding(d_ptr->margins)); } -void QMapboxGL::setBearing(double degrees, const QPointF ¢er) +void Map::setBearing(double degrees, const QPointF ¢er) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions() .withBearing(degrees) @@ -881,7 +547,7 @@ void QMapboxGL::setBearing(double degrees, const QPointF ¢er) } /*! - \property QMapboxGL::pitch + \property QMapLibreGL::Map::pitch \brief the map pitch in degrees. Pitch toward the horizon measured in degrees, with 0 resulting in a @@ -889,17 +555,17 @@ void QMapboxGL::setBearing(double degrees, const QPointF ¢er) \sa margins() */ -double QMapboxGL::pitch() const +double Map::pitch() const { return *d_ptr->mapObj->getCameraOptions().pitch; } -void QMapboxGL::setPitch(double pitch_) +void Map::setPitch(double pitch_) { d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withPitch(pitch_)); } -void QMapboxGL::pitchBy(double pitch_) +void Map::pitchBy(double pitch_) { d_ptr->mapObj->pitchBy(pitch_); } @@ -907,15 +573,15 @@ void QMapboxGL::pitchBy(double pitch_) /*! Returns the north orientation mode. */ -QMapboxGL::NorthOrientation QMapboxGL::northOrientation() const +Map::NorthOrientation Map::northOrientation() const { - return static_cast(d_ptr->mapObj->getMapOptions().northOrientation()); + return static_cast(d_ptr->mapObj->getMapOptions().northOrientation()); } /*! Sets the north orientation mode to \a orientation. */ -void QMapboxGL::setNorthOrientation(NorthOrientation orientation) +void Map::setNorthOrientation(NorthOrientation orientation) { d_ptr->mapObj->setNorthOrientation(static_cast(orientation)); } @@ -925,7 +591,7 @@ void QMapboxGL::setNorthOrientation(NorthOrientation orientation) affects how the map renders labels, as it will use different texture filters if a gesture is ongoing. */ -void QMapboxGL::setGestureInProgress(bool progress) +void Map::setGestureInProgress(bool progress) { d_ptr->mapObj->setGestureInProgress(progress); } @@ -934,7 +600,7 @@ void QMapboxGL::setGestureInProgress(bool 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 QMapboxGL::setTransitionOptions(qint64 duration, qint64 delay) { +void Map::setTransitionOptions(qint64 duration, qint64 delay) { static auto convert = [](qint64 value) -> mbgl::optional { return std::chrono::duration_cast(mbgl::Milliseconds(value)); }; @@ -942,49 +608,6 @@ void QMapboxGL::setTransitionOptions(qint64 duration, qint64 delay) { d_ptr->mapObj->getStyle().setTransitionOptions(mbgl::style::TransitionOptions{ convert(duration), convert(delay) }); } -mbgl::optional asMapboxGLAnnotation(const QMapbox::Annotation & annotation) { - auto asMapboxGLGeometry = [](const QMapbox::ShapeAnnotationGeometry &geometry) { - mbgl::ShapeAnnotationGeometry result; - switch (geometry.type) { - case QMapbox::ShapeAnnotationGeometry::LineStringType: - result = asMapboxGLLineString(geometry.geometry.first().first()); - break; - case QMapbox::ShapeAnnotationGeometry::PolygonType: - result = asMapboxGLPolygon(geometry.geometry.first()); - break; - case QMapbox::ShapeAnnotationGeometry::MultiLineStringType: - result = asMapboxGLMultiLineString(geometry.geometry.first()); - break; - case QMapbox::ShapeAnnotationGeometry::MultiPolygonType: - result = asMapboxGLMultiPolygon(geometry.geometry); - break; - } - return result; - }; - - if (annotation.canConvert()) { - QMapbox::SymbolAnnotation symbolAnnotation = annotation.value(); - QMapbox::Coordinate& pair = symbolAnnotation.geometry; - return { mbgl::SymbolAnnotation(mbgl::Point { pair.second, pair.first }, symbolAnnotation.icon.toStdString()) }; - } else if (annotation.canConvert()) { - QMapbox::LineAnnotation lineAnnotation = annotation.value(); - auto color = mbgl::Color::parse(mbgl::style::conversion::convertColor(lineAnnotation.color)); - return { mbgl::LineAnnotation(asMapboxGLGeometry(lineAnnotation.geometry), lineAnnotation.opacity, lineAnnotation.width, { *color }) }; - } else if (annotation.canConvert()) { - QMapbox::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(asMapboxGLGeometry(fillAnnotation.geometry), fillAnnotation.opacity, { *color }, { *outlineColor }) }; - } else { - return { mbgl::FillAnnotation(asMapboxGLGeometry(fillAnnotation.geometry), fillAnnotation.opacity, { *color }, {}) }; - } - } - - qWarning() << "Unable to convert annotation:" << annotation; - return {}; -} - /*! Adds an \a annotation to the map. @@ -992,9 +615,9 @@ mbgl::optional asMapboxGLAnnotation(const QMapbox::Annotation \sa addAnnotationIcon() */ -QMapbox::AnnotationID QMapboxGL::addAnnotation(const QMapbox::Annotation &annotation) +AnnotationID Map::addAnnotation(const Annotation &annotation) { - return static_cast(d_ptr->mapObj->addAnnotation(*asMapboxGLAnnotation(annotation))); + return static_cast(d_ptr->mapObj->addAnnotation(*asAnnotation(annotation))); } /*! @@ -1002,15 +625,15 @@ QMapbox::AnnotationID QMapboxGL::addAnnotation(const QMapbox::Annotation &annota \sa addAnnotationIcon() */ -void QMapboxGL::updateAnnotation(QMapbox::AnnotationID id, const QMapbox::Annotation &annotation) +void Map::updateAnnotation(AnnotationID id, const Annotation &annotation) { - d_ptr->mapObj->updateAnnotation(id, *asMapboxGLAnnotation(annotation)); + d_ptr->mapObj->updateAnnotation(id, *asAnnotation(annotation)); } /*! Removes an existing annotation referred by \a id. */ -void QMapboxGL::removeAnnotation(QMapbox::AnnotationID id) +void Map::removeAnnotation(AnnotationID id) { d_ptr->mapObj->removeAnnotation(id); } @@ -1054,7 +677,7 @@ void QMapboxGL::removeAnnotation(QMapbox::AnnotationID id) \li QVariantList \endtable */ -bool QMapboxGL::setLayoutProperty(const QString& layer, const QString& propertyName, const QVariant& value) +bool Map::setLayoutProperty(const QString& layer, const QString& propertyName, const QVariant& value) { return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); } @@ -1114,7 +737,7 @@ bool QMapboxGL::setLayoutProperty(const QString& layer, const QString& propertyN \endcode */ -bool QMapboxGL::setPaintProperty(const QString& layer, const QString& propertyName, const QVariant& value) +bool Map::setPaintProperty(const QString& layer, const QString& propertyName, const QVariant& value) { return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); } @@ -1123,7 +746,7 @@ bool QMapboxGL::setPaintProperty(const QString& layer, const QString& propertyNa 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 QMapboxGL::isFullyLoaded() const +bool Map::isFullyLoaded() const { return d_ptr->mapObj->isFullyLoaded(); } @@ -1133,18 +756,18 @@ bool QMapboxGL::isFullyLoaded() const The pixel coordinate origin is located at the upper left corner of the map. */ -void QMapboxGL::moveBy(const QPointF &offset) +void Map::moveBy(const QPointF &offset) { d_ptr->mapObj->moveBy(mbgl::ScreenCoordinate { offset.x(), offset.y() }); } /*! - \fn QMapboxGL::scaleBy(double scale, const QPointF ¢er) + \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 QMapboxGL::scaleBy(double scale_, const QPointF ¢er) { +void Map::scaleBy(double scale_, const QPointF ¢er) { d_ptr->mapObj->scaleBy(scale_, mbgl::ScreenCoordinate { center.x(), center.y() }); } @@ -1154,7 +777,7 @@ void QMapboxGL::scaleBy(double scale_, const QPointF ¢er) { being \a first the cursor coordinate at the last frame and \a second the cursor coordinate at the current frame. */ -void QMapboxGL::rotateBy(const QPointF &first, const QPointF &second) +void Map::rotateBy(const QPointF &first, const QPointF &second) { d_ptr->mapObj->rotateBy( mbgl::ScreenCoordinate { first.x(), first.y() }, @@ -1165,7 +788,7 @@ void QMapboxGL::rotateBy(const QPointF &first, const QPointF &second) 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 QMapboxGL::resize(const QSize& size_) +void Map::resize(const QSize& size_) { auto size = sanitizedSize(size_); @@ -1184,7 +807,7 @@ void QMapboxGL::resize(const QSize& size_) \sa addAnnotation() */ -void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon) +void Map::addAnnotationIcon(const QString &name, const QImage &icon) { if (icon.isNull()) return; @@ -1192,31 +815,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon) } /*! - Returns the amount of meters per pixel from a given \a latitude_ and \a zoom_. -*/ -double QMapboxGL::metersPerPixelAtLatitude(double latitude_, double zoom_) const -{ - return QMapbox::metersPerPixelAtLatitude(latitude_, zoom_); -} - -/*! - Return the projected meters for a given \a coordinate_ object. -*/ -QMapbox::ProjectedMeters QMapboxGL::projectedMetersForCoordinate(const QMapbox::Coordinate &coordinate_) const -{ - return QMapbox::projectedMetersForCoordinate(coordinate_); -} - -/*! - Returns the coordinate for a given \a projectedMeters object. -*/ -QMapbox::Coordinate QMapboxGL::coordinateForProjectedMeters(const QMapbox::ProjectedMeters &projectedMeters) const -{ - return QMapbox::coordinateForProjectedMeters(projectedMeters); -} - -/*! - \fn QMapboxGL::pixelForCoordinate(const QMapbox::Coordinate &coordinate) const + \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. @@ -1226,7 +825,7 @@ QMapbox::Coordinate QMapboxGL::coordinateForProjectedMeters(const QMapbox::Proje /note The return value is affected by the current zoom level, bearing and pitch. */ -QPointF QMapboxGL::pixelForCoordinate(const QMapbox::Coordinate &coordinate_) const +QPointF Map::pixelForCoordinate(const Coordinate &coordinate_) const { const mbgl::ScreenCoordinate pixel = d_ptr->mapObj->pixelForLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second }); @@ -1237,7 +836,7 @@ QPointF QMapboxGL::pixelForCoordinate(const QMapbox::Coordinate &coordinate_) co /*! Returns the geographic coordinate for the \a pixel coordinate. */ -QMapbox::Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const +Coordinate Map::coordinateForPixel(const QPointF &pixel) const { const mbgl::LatLng latLng = d_ptr->mapObj->latLngForPixel(mbgl::ScreenCoordinate { pixel.x(), pixel.y() }); @@ -1249,8 +848,8 @@ QMapbox::Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const Returns the coordinate and zoom combination needed in order to make the coordinate bounding box \a sw and \a ne visible. */ -QMapbox::CoordinateZoom QMapboxGL::coordinateZoomForBounds(const QMapbox::Coordinate &sw, - const QMapbox::Coordinate &ne) const { +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); @@ -1261,10 +860,10 @@ QMapbox::CoordinateZoom QMapboxGL::coordinateZoomForBounds(const QMapbox::Coordi 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. */ -QMapbox::CoordinateZoom QMapboxGL::coordinateZoomForBounds(const QMapbox::Coordinate &sw, - const QMapbox::Coordinate &ne, - double newBearing, - double 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 }); @@ -1273,12 +872,12 @@ QMapbox::CoordinateZoom QMapboxGL::coordinateZoomForBounds(const QMapbox::Coordi } /*! - \property QMapboxGL::margins + \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 QMapboxGL::setMargins(const QMargins &margins_) +void Map::setMargins(const QMargins &margins_) { d_ptr->margins = { static_cast(margins_.top()), @@ -1288,7 +887,7 @@ void QMapboxGL::setMargins(const QMargins &margins_) }; } -QMargins QMapboxGL::margins() const +QMargins Map::margins() const { return QMargins( d_ptr->margins.left(), @@ -1316,7 +915,7 @@ QMargins QMapboxGL::margins() const map->addSource("routeSource", routeSource); \endcode */ -void QMapboxGL::addSource(const QString &id, const QVariantMap ¶ms) +void Map::addSource(const QString &id, const QVariantMap ¶ms) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1334,7 +933,7 @@ void QMapboxGL::addSource(const QString &id, const QVariantMap ¶ms) /*! Returns true if the layer with given \a sourceID exists, false otherwise. */ -bool QMapboxGL::sourceExists(const QString& sourceID) +bool Map::sourceExists(const QString& sourceID) { return !!d_ptr->mapObj->getStyle().getSource(sourceID.toStdString()); } @@ -1345,7 +944,7 @@ bool QMapboxGL::sourceExists(const QString& sourceID) If the source does not exist, it will be added like in addSource(). Only image and GeoJSON sources can be updated. */ -void QMapboxGL::updateSource(const QString &id, const QVariantMap ¶ms) +void Map::updateSource(const QString &id, const QVariantMap ¶ms) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1379,7 +978,7 @@ void QMapboxGL::updateSource(const QString &id, const QVariantMap ¶ms) This method has no effect if the source does not exist. */ -void QMapboxGL::removeSource(const QString& id) +void Map::removeSource(const QString& id) { auto sourceIDStdString = id.toStdString(); @@ -1396,14 +995,14 @@ void QMapboxGL::removeSource(const QString& id) \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 QMapboxGL::addCustomLayer(const QString &id, - std::unique_ptr host, - const QString &before) +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) + std::unique_ptr ptr{}; + HostWrapper(std::unique_ptr p) : ptr(std::move(p)) { } @@ -1412,7 +1011,7 @@ void QMapboxGL::addCustomLayer(const QString &id, } void render(const mbgl::style::CustomLayerRenderParameters& params) { - QMapbox::CustomLayerRenderParameters renderParams; + CustomLayerRenderParameters renderParams; renderParams.width = params.width; renderParams.height = params.height; renderParams.latitude = params.latitude; @@ -1457,7 +1056,7 @@ void QMapboxGL::addCustomLayer(const QString &id, /note The source must exist prior to adding a layer. */ -void QMapboxGL::addLayer(const QVariantMap ¶ms, const QString& before) +void Map::addLayer(const QVariantMap ¶ms, const QString& before) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1476,7 +1075,7 @@ void QMapboxGL::addLayer(const QVariantMap ¶ms, const QString& before) /*! Returns true if the layer with given \a id exists, false otherwise. */ -bool QMapboxGL::layerExists(const QString& id) +bool Map::layerExists(const QString& id) { return !!d_ptr->mapObj->getStyle().getLayer(id.toStdString()); } @@ -1484,7 +1083,7 @@ bool QMapboxGL::layerExists(const QString& id) /*! Removes the layer with given \a id. */ -void QMapboxGL::removeLayer(const QString& id) +void Map::removeLayer(const QString& id) { d_ptr->mapObj->getStyle().removeLayer(id.toStdString()); } @@ -1492,7 +1091,7 @@ void QMapboxGL::removeLayer(const QString& id) /*! List of all existing layer ids from the current style. */ -QVector QMapboxGL::layerIds() const +QVector Map::layerIds() const { const auto &layers = d_ptr->mapObj->getStyle().getLayers(); @@ -1516,7 +1115,7 @@ QVector QMapboxGL::layerIds() const \sa addLayer() */ -void QMapboxGL::addImage(const QString &id, const QImage &image) +void Map::addImage(const QString &id, const QImage &image) { if (image.isNull()) return; @@ -1526,7 +1125,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image) /*! Removes the image \a id. */ -void QMapboxGL::removeImage(const QString &id) +void Map::removeImage(const QString &id) { d_ptr->mapObj->getStyle().removeImage(id.toStdString()); } @@ -1551,7 +1150,7 @@ void QMapboxGL::removeImage(const QString &id) map->setFilter(QLatin1String("marker"), filter); \endcode */ -void QMapboxGL::setFilter(const QString& layer, const QVariant& filter) +void Map::setFilter(const QString& layer, const QVariant& filter) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1612,7 +1211,7 @@ QVariant QVariantFromValue(const mbgl::Value &value) { Filter value types are described in the {https://www.mapbox.com/mapbox-gl-js/style-spec/#types}{Mapbox style specification}. */ -QVariant QMapboxGL::getFilter(const QString &layer) const { +QVariant Map::getFilter(const QString &layer) const { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1632,7 +1231,7 @@ QVariant QMapboxGL::getFilter(const QString &layer) const { Must be called on the render thread. */ -void QMapboxGL::createRenderer() +void Map::createRenderer() { d_ptr->createRenderer(); } @@ -1643,7 +1242,7 @@ void QMapboxGL::createRenderer() Must be called on the render thread. */ -void QMapboxGL::destroyRenderer() +void Map::destroyRenderer() { d_ptr->destroyRenderer(); } @@ -1652,9 +1251,9 @@ void QMapboxGL::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 QMapboxGLSettings::MapMode + \sa QMapLibreGL::Settings::MapMode */ -void QMapboxGL::startStaticRender() +void Map::startStaticRender() { d_ptr->mapObj->renderStill([this](std::exception_ptr err) { QString what; @@ -1682,19 +1281,19 @@ void QMapboxGL::startStaticRender() Must be called on the render thread. */ -void QMapboxGL::render() +void Map::render() { d_ptr->render(); } /*! - If Mapbox GL needs to rebind the default \a fbo, it will use the + If MapLibre GL 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 QMapboxGL::setFramebufferObject(quint32 fbo, const QSize& size) +void Map::setFramebufferObject(quint32 fbo, const QSize& size) { d_ptr->setFramebufferObject(fbo, size); } @@ -1703,7 +1302,7 @@ void QMapboxGL::setFramebufferObject(quint32 fbo, const QSize& size) Informs the map that the network connection has been established, causing all network requests that previously timed out to be retried immediately. */ -void QMapboxGL::connectionEstablished() +void Map::connectionEstablished() { mbgl::NetworkStatus::Reachable(); } @@ -1712,13 +1311,13 @@ void QMapboxGL::connectionEstablished() Returns a list containing a pair of string objects, representing the style URL and name, respectively. */ -const QVector> &QMapboxGL::defaultStyles() const +const QVector> &Map::defaultStyles() const { return d_ptr->defaultStyles; } /*! - \fn void QMapboxGL::needsRendering() + \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 @@ -1728,7 +1327,7 @@ const QVector> &QMapboxGL::defaultStyles() const */ /*! - \fn void QMapboxGL::staticRenderFinished(const QString &error) + \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 @@ -1738,7 +1337,7 @@ const QVector> &QMapboxGL::defaultStyles() const */ /*! - \fn void QMapboxGL::mapChanged(QMapboxGL::MapChange change) + \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 @@ -1746,14 +1345,14 @@ const QVector> &QMapboxGL::defaultStyles() const */ /*! - \fn void QMapboxGL::mapLoadingFailed(QMapboxGL::MapLoadingFailure type, const QString &description) + \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 QMapboxGL::copyrightsChanged(const QString ©rightsHtml); + \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. @@ -1761,40 +1360,22 @@ const QVector> &QMapboxGL::defaultStyles() const \a copyrightsHtml is a string with a HTML snippet. */ -mbgl::MapOptions mapOptionsFromQMapboxGLSettings(const QMapboxGLSettings &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 resourceOptionsFromQMapboxGLSettings(const QMapboxGLSettings &settings) { - return std::move(mbgl::ResourceOptions() - .withApiKey(settings.apiKey().toStdString()) - .withAssetPath(settings.assetPath().toStdString()) - .withTileServerOptions(*settings.tileServerOptionsInternal()) - .withCachePath(settings.cacheDatabasePath().toStdString()) - .withMaximumCacheSize(settings.cacheDatabaseMaximumSize())); -} - -QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio_) +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); + m_mapObserver = std::make_unique(this); - qRegisterMetaType("QMapboxGL::MapChange"); + qRegisterMetaType("Map::MapChange"); - connect(m_mapObserver.get(), &QMapboxGLMapObserver::mapChanged, q, &QMapboxGL::mapChanged); - connect(m_mapObserver.get(), &QMapboxGLMapObserver::mapLoadingFailed, q, &QMapboxGL::mapLoadingFailed); - connect(m_mapObserver.get(), &QMapboxGLMapObserver::copyrightsChanged, q, &QMapboxGL::copyrightsChanged); + 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 = resourceOptionsFromQMapboxGLSettings(settings); + auto resourceOptions = resourceOptionsFromSettings(settings); for (auto style : resourceOptions.tileServerOptions().defaultStyles()) { defaultStyles.append(QPair( QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName()))); @@ -1802,7 +1383,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin // Setup the Map object. mapObj = std::make_unique(*this, *m_mapObserver, - mapOptionsFromQMapboxGLSettings(settings, size, m_pixelRatio), + mapOptionsFromSettings(settings, size, m_pixelRatio), resourceOptions); if (settings.resourceTransform()) { @@ -1825,14 +1406,14 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin } // Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag. - connect(this, &QMapboxGLPrivate::needsRendering, q, &QMapboxGL::needsRendering, Qt::QueuedConnection); + connect(this, &MapPrivate::needsRendering, q, &Map::needsRendering, Qt::QueuedConnection); } -QMapboxGLPrivate::~QMapboxGLPrivate() +MapPrivate::~MapPrivate() { } -void QMapboxGLPrivate::update(std::shared_ptr parameters) +void MapPrivate::update(std::shared_ptr parameters) { std::lock_guard lock(m_mapRendererMutex); @@ -1847,9 +1428,9 @@ void QMapboxGLPrivate::update(std::shared_ptr parameters requestRendering(); } -void QMapboxGLPrivate::setObserver(mbgl::RendererObserver &observer) +void MapPrivate::setObserver(mbgl::RendererObserver &observer) { - m_rendererObserver = std::make_shared( + m_rendererObserver = std::make_shared( *mbgl::util::RunLoop::Get(), observer); std::lock_guard lock(m_mapRendererMutex); @@ -1859,7 +1440,7 @@ void QMapboxGLPrivate::setObserver(mbgl::RendererObserver &observer) } } -void QMapboxGLPrivate::createRenderer() +void MapPrivate::createRenderer() { std::lock_guard lock(m_mapRendererMutex); @@ -1867,13 +1448,13 @@ void QMapboxGLPrivate::createRenderer() return; } - m_mapRenderer = std::make_unique( + m_mapRenderer = std::make_unique( m_pixelRatio, m_mode, m_localFontFamily ); - connect(m_mapRenderer.get(), &QMapboxGLMapRenderer::needsRendering, this, &QMapboxGLPrivate::requestRendering); + connect(m_mapRenderer.get(), &MapRenderer::needsRendering, this, &MapPrivate::requestRendering); m_mapRenderer->setObserver(m_rendererObserver); @@ -1883,14 +1464,14 @@ void QMapboxGLPrivate::createRenderer() } } -void QMapboxGLPrivate::destroyRenderer() +void MapPrivate::destroyRenderer() { std::lock_guard lock(m_mapRendererMutex); m_mapRenderer.reset(); } -void QMapboxGLPrivate::render() +void MapPrivate::render() { std::lock_guard lock(m_mapRendererMutex); @@ -1902,7 +1483,7 @@ void QMapboxGLPrivate::render() m_mapRenderer->render(); } -void QMapboxGLPrivate::setFramebufferObject(quint32 fbo, const QSize& size) +void MapPrivate::setFramebufferObject(quint32 fbo, const QSize& size) { std::lock_guard lock(m_mapRendererMutex); @@ -1913,14 +1494,14 @@ void QMapboxGLPrivate::setFramebufferObject(quint32 fbo, const QSize& size) m_mapRenderer->updateFramebuffer(fbo, sanitizedSize(size)); } -void QMapboxGLPrivate::requestRendering() +void MapPrivate::requestRendering() { if (!m_renderQueued.test_and_set()) { emit needsRendering(); } } -bool QMapboxGLPrivate::setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value) { +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()); @@ -1958,3 +1539,5 @@ bool QMapboxGLPrivate::setProperty(const PropertySetter& setter, const QString& return true; } + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/map_p.hpp similarity index 65% rename from platform/qt/src/qmapboxgl_p.hpp rename to platform/qt/src/map_p.hpp index 19dcfbe9b..af5e0d485 100644 --- a/platform/qt/src/qmapboxgl_p.hpp +++ b/platform/qt/src/map_p.hpp @@ -1,8 +1,9 @@ #pragma once -#include "qmapboxgl.hpp" -#include "qmapboxgl_map_observer.hpp" -#include "qmapboxgl_map_renderer.hpp" +#include + +#include "utils/map_observer.hpp" +#include "utils/map_renderer.hpp" #include #include @@ -16,13 +17,15 @@ #include #include -class QMapboxGLPrivate : public QObject, public mbgl::RendererFrontend +namespace QMapLibreGL { + +class MapPrivate : public QObject, public mbgl::RendererFrontend { Q_OBJECT public: - explicit QMapboxGLPrivate(QMapboxGL *, const QMapboxGLSettings &, const QSize &size, qreal pixelRatio); - virtual ~QMapboxGLPrivate(); + explicit MapPrivate(Map *, const Settings &, const QSize &size, qreal pixelRatio); + virtual ~MapPrivate(); // mbgl::RendererFrontend implementation. void reset() final {} @@ -39,7 +42,7 @@ public: bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value); mbgl::EdgeInsets margins; - std::unique_ptr mapObj; + std::unique_ptr mapObj{}; QVector> defaultStyles; public slots: @@ -49,20 +52,22 @@ signals: void needsRendering(); private: - Q_DISABLE_COPY(QMapboxGLPrivate) + Q_DISABLE_COPY(MapPrivate) std::recursive_mutex m_mapRendererMutex; - std::shared_ptr m_rendererObserver; - std::shared_ptr m_updateParameters; + 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; + std::unique_ptr m_mapObserver{}; + std::unique_ptr m_mapRenderer{}; + std::unique_ptr> m_resourceTransform{}; - QMapboxGLSettings::GLContextMode m_mode; + 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/async_task.cpp b/platform/qt/src/mbgl/async_task.cpp similarity index 100% rename from platform/qt/src/async_task.cpp rename to platform/qt/src/mbgl/async_task.cpp diff --git a/platform/qt/src/async_task_impl.hpp b/platform/qt/src/mbgl/async_task_impl.hpp similarity index 100% rename from platform/qt/src/async_task_impl.hpp rename to platform/qt/src/mbgl/async_task_impl.hpp diff --git a/platform/qt/src/bidi.cpp b/platform/qt/src/mbgl/bidi.cpp similarity index 100% rename from platform/qt/src/bidi.cpp rename to platform/qt/src/mbgl/bidi.cpp diff --git a/platform/qt/src/gl_functions.cpp b/platform/qt/src/mbgl/gl_functions.cpp similarity index 100% rename from platform/qt/src/gl_functions.cpp rename to platform/qt/src/mbgl/gl_functions.cpp diff --git a/platform/qt/src/headless_backend_qt.cpp b/platform/qt/src/mbgl/headless_backend_qt.cpp similarity index 100% rename from platform/qt/src/headless_backend_qt.cpp rename to platform/qt/src/mbgl/headless_backend_qt.cpp diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/mbgl/http_file_source.cpp similarity index 100% rename from platform/qt/src/http_file_source.cpp rename to platform/qt/src/mbgl/http_file_source.cpp diff --git a/platform/qt/src/http_file_source.hpp b/platform/qt/src/mbgl/http_file_source.hpp similarity index 100% rename from platform/qt/src/http_file_source.hpp rename to platform/qt/src/mbgl/http_file_source.hpp diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/mbgl/http_request.cpp similarity index 97% rename from platform/qt/src/http_request.cpp rename to platform/qt/src/mbgl/http_request.cpp index 014a75162..a7d152ea4 100644 --- a/platform/qt/src/http_request.cpp +++ b/platform/qt/src/mbgl/http_request.cpp @@ -39,7 +39,7 @@ QNetworkRequest HTTPRequest::networkRequest() const QNetworkRequest req = QNetworkRequest(requestUrl()); req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - static const QByteArray agent = QString("MapboxGL/%1 (Qt %2)").arg(version::revision).arg(QT_VERSION_STR).toLatin1(); + static const QByteArray agent = QString("MapLibreGL/%1 (Qt %2)").arg(version::revision).arg(QT_VERSION_STR).toLatin1(); req.setRawHeader("User-Agent", agent); if (m_resource.priorEtag) { diff --git a/platform/qt/src/http_request.hpp b/platform/qt/src/mbgl/http_request.hpp similarity index 100% rename from platform/qt/src/http_request.hpp rename to platform/qt/src/mbgl/http_request.hpp diff --git a/platform/qt/src/qt_image.cpp b/platform/qt/src/mbgl/image.cpp similarity index 100% rename from platform/qt/src/qt_image.cpp rename to platform/qt/src/mbgl/image.cpp diff --git a/platform/qt/src/local_glyph_rasterizer.cpp b/platform/qt/src/mbgl/local_glyph_rasterizer.cpp similarity index 100% rename from platform/qt/src/local_glyph_rasterizer.cpp rename to platform/qt/src/mbgl/local_glyph_rasterizer.cpp diff --git a/platform/qt/src/qt_logging.cpp b/platform/qt/src/mbgl/logging_qt.cpp similarity index 100% rename from platform/qt/src/qt_logging.cpp rename to platform/qt/src/mbgl/logging_qt.cpp diff --git a/platform/qt/src/number_format.cpp b/platform/qt/src/mbgl/number_format.cpp similarity index 100% rename from platform/qt/src/number_format.cpp rename to platform/qt/src/mbgl/number_format.cpp diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/mbgl/run_loop.cpp similarity index 100% rename from platform/qt/src/run_loop.cpp rename to platform/qt/src/mbgl/run_loop.cpp diff --git a/platform/qt/src/run_loop_impl.hpp b/platform/qt/src/mbgl/run_loop_impl.hpp similarity index 100% rename from platform/qt/src/run_loop_impl.hpp rename to platform/qt/src/mbgl/run_loop_impl.hpp diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/mbgl/sqlite3.cpp similarity index 100% rename from platform/qt/src/sqlite3.cpp rename to platform/qt/src/mbgl/sqlite3.cpp diff --git a/platform/qt/src/string_stdlib.cpp b/platform/qt/src/mbgl/string_stdlib.cpp similarity index 100% rename from platform/qt/src/string_stdlib.cpp rename to platform/qt/src/mbgl/string_stdlib.cpp diff --git a/platform/qt/src/thread.cpp b/platform/qt/src/mbgl/thread.cpp similarity index 100% rename from platform/qt/src/thread.cpp rename to platform/qt/src/mbgl/thread.cpp diff --git a/platform/qt/src/thread_local.cpp b/platform/qt/src/mbgl/thread_local.cpp similarity index 100% rename from platform/qt/src/thread_local.cpp rename to platform/qt/src/mbgl/thread_local.cpp diff --git a/platform/qt/src/timer.cpp b/platform/qt/src/mbgl/timer.cpp similarity index 100% rename from platform/qt/src/timer.cpp rename to platform/qt/src/mbgl/timer.cpp diff --git a/platform/qt/src/timer_impl.hpp b/platform/qt/src/mbgl/timer_impl.hpp similarity index 100% rename from platform/qt/src/timer_impl.hpp rename to platform/qt/src/mbgl/timer_impl.hpp diff --git a/platform/qt/src/utf.cpp b/platform/qt/src/mbgl/utf.cpp similarity index 100% rename from platform/qt/src/utf.cpp rename to platform/qt/src/mbgl/utf.cpp diff --git a/platform/qt/src/qmapbox.cpp b/platform/qt/src/qmapbox.cpp deleted file mode 100644 index ad0b79036..000000000 --- a/platform/qt/src/qmapbox.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include "qmapbox.hpp" - -#include -#include -#include -#include - -#include - -// mbgl::NetworkStatus::Status -static_assert(mbgl::underlying_type(QMapbox::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online), "error"); -static_assert(mbgl::underlying_type(QMapbox::Offline) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline), "error"); - -// mbgl::FeatureType -static_assert(mbgl::underlying_type(QMapbox::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point), "error"); -static_assert(mbgl::underlying_type(QMapbox::Feature::LineStringType) == mbgl::underlying_type(mbgl::FeatureType::LineString), "error"); -static_assert(mbgl::underlying_type(QMapbox::Feature::PolygonType) == mbgl::underlying_type(mbgl::FeatureType::Polygon), "error"); - -namespace QMapbox { - -/*! - \namespace QMapbox - \inmodule Mapbox Maps SDK for Qt - - Contains miscellaneous Mapbox bindings used throughout QMapboxGL. -*/ - -/*! - \typedef QMapbox::Coordinate - - Alias for QPair. - Representation for geographical coordinates - latitude and longitude, respectively. -*/ - -/*! - \typedef QMapbox::CoordinateZoom - - Alias for QPair. - Used as return value in QMapboxGL::coordinateZoomForBounds. -*/ - -/*! - \typedef QMapbox::ProjectedMeters - - Alias for QPair. - Representation for projected meters - northing and easting, respectively. -*/ - -/*! - \typedef QMapbox::Coordinates - - Alias for QVector. - A list of QMapbox::Coordinate objects. -*/ - -/*! - \typedef QMapbox::CoordinatesCollection - - Alias for QVector. - A list of QMapbox::Coordinates objects. -*/ - -/*! - \typedef QMapbox::CoordinatesCollections - - Alias for QVector. - A list of QMapbox::CoordinatesCollection objects. -*/ - -/*! - \class QMapbox::Feature - - \inmodule Mapbox 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 QMapbox::Feature::Type - - This enum is used as basis for geometry disambiguation in QMapbox::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 QMapbox::ShapeAnnotationGeometry - - \inmodule Mapbox Maps SDK for Qt - - Represents a shape annotation geometry. -*/ - -/*! - \enum QMapbox::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 QMapbox::SymbolAnnotation - - \inmodule Mapbox Maps SDK for Qt - - A symbol annotation comprises of its geometry and an icon identifier. -*/ - -/*! - \class QMapbox::LineAnnotation - - \inmodule Mapbox 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 QMapbox::FillAnnotation - - \inmodule Mapbox 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 QMapbox::Annotation - - Alias for QVariant. - Container that encapsulates either a symbol, a line, a fill or a style sourced annotation. -*/ - -/*! - \typedef QMapbox::AnnotationID - - Alias for quint32 representing an annotation identifier. -*/ - -/*! - \typedef QMapbox::AnnotationIDs - - Alias for QVector representing a container of annotation identifiers. -*/ - -/*! - \class QMapbox::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. -*/ - -/*! - \enum QMapbox::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. -*/ - -/*! - \class QMapbox::CustomLayerRenderParameters - \inmodule Mapbox Maps SDK for Qt - - QMapbox::CustomLayerRenderParameters provides the data passed on each render - pass for a custom layer. -*/ - -/*! - \fn QMapbox::NetworkMode QMapbox::networkMode() - - Returns the current QMapbox::NetworkMode. -*/ -NetworkMode networkMode() -{ - return static_cast(mbgl::NetworkStatus::Get()); -} - -/*! - \fn void QMapbox::setNetworkMode(QMapbox::NetworkMode mode) - - Forwards the network status \a mode to Mapbox GL 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 QMapbox::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 QMapbox::Coordinate(latLng.latitude(), latLng.longitude()); -} - -} // namespace QMapbox diff --git a/platform/qt/src/qmapboxgl_map_observer.cpp b/platform/qt/src/qmapboxgl_map_observer.cpp deleted file mode 100644 index 00af666b0..000000000 --- a/platform/qt/src/qmapboxgl_map_observer.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "qmapboxgl_map_observer.hpp" - -#include "qmapboxgl_p.hpp" - -#include - -#include - -QMapboxGLMapObserver::QMapboxGLMapObserver(QMapboxGLPrivate *d) - : d_ptr(d) -{ -} - -QMapboxGLMapObserver::~QMapboxGLMapObserver() -{ -} - -void QMapboxGLMapObserver::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) -{ - if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) { - emit mapChanged(QMapboxGL::MapChangeRegionWillChange); - } else { - emit mapChanged(QMapboxGL::MapChangeRegionWillChangeAnimated); - } -} - -void QMapboxGLMapObserver::onCameraIsChanging() -{ - emit mapChanged(QMapboxGL::MapChangeRegionIsChanging); -} - -void QMapboxGLMapObserver::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode) -{ - if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) { - emit mapChanged(QMapboxGL::MapChangeRegionDidChange); - } else { - emit mapChanged(QMapboxGL::MapChangeRegionDidChangeAnimated); - } -} - -void QMapboxGLMapObserver::onWillStartLoadingMap() -{ - emit mapChanged(QMapboxGL::MapChangeWillStartLoadingMap); -} - -void QMapboxGLMapObserver::onDidFinishLoadingMap() -{ - emit mapChanged(QMapboxGL::MapChangeDidFinishLoadingMap); -} - -void QMapboxGLMapObserver::onDidFailLoadingMap(mbgl::MapLoadError error, const std::string& what) -{ - emit mapChanged(QMapboxGL::MapChangeDidFailLoadingMap); - - QMapboxGL::MapLoadingFailure type; - QString description(what.c_str()); - - switch (error) { - case mbgl::MapLoadError::StyleParseError: - type = QMapboxGL::MapLoadingFailure::StyleParseFailure; - break; - case mbgl::MapLoadError::StyleLoadError: - type = QMapboxGL::MapLoadingFailure::StyleLoadFailure; - break; - case mbgl::MapLoadError::NotFoundError: - type = QMapboxGL::MapLoadingFailure::NotFoundFailure; - break; - default: - type = QMapboxGL::MapLoadingFailure::UnknownFailure; - } - - emit mapLoadingFailed(type, description); -} - -void QMapboxGLMapObserver::onWillStartRenderingFrame() -{ - emit mapChanged(QMapboxGL::MapChangeWillStartRenderingFrame); -} - -void QMapboxGLMapObserver::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status) -{ - if (status.mode == mbgl::MapObserver::RenderMode::Partial) { - emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingFrame); - } else { - emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingFrameFullyRendered); - } -} - -void QMapboxGLMapObserver::onWillStartRenderingMap() -{ - emit mapChanged(QMapboxGL::MapChangeWillStartRenderingMap); -} - -void QMapboxGLMapObserver::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode) -{ - if (mode == mbgl::MapObserver::RenderMode::Partial) { - emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingMap); - } else { - emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingMapFullyRendered); - } -} - -void QMapboxGLMapObserver::onDidFinishLoadingStyle() -{ - emit mapChanged(QMapboxGL::MapChangeDidFinishLoadingStyle); -} - -void QMapboxGLMapObserver::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(QMapboxGL::MapChangeSourceDidChange); -} diff --git a/platform/qt/src/qmapboxgl_renderer_backend.cpp b/platform/qt/src/qmapboxgl_renderer_backend.cpp deleted file mode 100644 index 39b49fe48..000000000 --- a/platform/qt/src/qmapboxgl_renderer_backend.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "qmapboxgl_renderer_backend.hpp" - -#include -#include - -#include -#include - -class QMapboxGLRenderableResource final : public mbgl::gl::RenderableResource { -public: - QMapboxGLRenderableResource(QMapboxGLRendererBackend& backend_) : backend(backend_) { - } - - void bind() override { - assert(mbgl::gfx::BackendScope::exists()); - backend.restoreFramebufferBinding(); - backend.setViewport(0, 0, backend.getSize()); - } - -private: - QMapboxGLRendererBackend& backend; -}; - -QMapboxGLRendererBackend::QMapboxGLRendererBackend(const mbgl::gfx::ContextMode contextMode_) - : mbgl::gl::RendererBackend(contextMode_), - mbgl::gfx::Renderable({ 0, 0 }, std::make_unique(*this)) { -} - -QMapboxGLRendererBackend::~QMapboxGLRendererBackend() = default; - -void QMapboxGLRendererBackend::updateAssumedState() { - assumeFramebufferBinding(ImplicitFramebufferBinding); - assumeViewport(0, 0, size); -} - -void QMapboxGLRendererBackend::restoreFramebufferBinding() { - setFramebufferBinding(m_fbo); -} - -void QMapboxGLRendererBackend::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 Mapbox GL Native engine. -*/ -mbgl::gl::ProcAddress QMapboxGLRendererBackend::getExtensionFunctionPointer(const char* name) { - QOpenGLContext* thisContext = QOpenGLContext::currentContext(); - return thisContext->getProcAddress(name); -} diff --git a/platform/qt/src/qt_geojson.hpp b/platform/qt/src/qt_geojson.hpp deleted file mode 100644 index a7db3ba64..000000000 --- a/platform/qt/src/qt_geojson.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -#include -#include -#include - -#include - -namespace QMapbox { - -mbgl::Point asMapboxGLPoint(const QMapbox::Coordinate &coordinate); -mbgl::MultiPoint asMapboxGLMultiPoint(const QMapbox::Coordinates &multiPoint); -mbgl::LineString asMapboxGLLineString(const QMapbox::Coordinates &lineString); -mbgl::MultiLineString asMapboxGLMultiLineString(const QMapbox::CoordinatesCollection &multiLineString); -mbgl::Polygon asMapboxGLPolygon(const QMapbox::CoordinatesCollection &polygon); -mbgl::MultiPolygon asMapboxGLMultiPolygon(const QMapbox::CoordinatesCollections &multiPolygon); -mbgl::Value asMapboxGLPropertyValue(const QVariant &value); -mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id); -mbgl::GeoJSONFeature asMapboxGLFeature(const QMapbox::Feature &feature); - -} // namespace QMapbox diff --git a/platform/qt/src/settings.cpp b/platform/qt/src/settings.cpp new file mode 100644 index 000000000..abb5b0b6f --- /dev/null +++ b/platform/qt/src/settings.cpp @@ -0,0 +1,411 @@ +#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("MGL_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 MGL_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 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 new file mode 100644 index 000000000..b766e2553 --- /dev/null +++ b/platform/qt/src/types.cpp @@ -0,0 +1,172 @@ +#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 new file mode 100644 index 000000000..8210d7ae7 --- /dev/null +++ b/platform/qt/src/utils.cpp @@ -0,0 +1,74 @@ +#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 GL 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/qt_conversion.hpp b/platform/qt/src/utils/conversion.hpp similarity index 90% rename from platform/qt/src/qt_conversion.hpp rename to platform/qt/src/utils/conversion.hpp index 00a39c64b..f71a333ec 100644 --- a/platform/qt/src/qt_conversion.hpp +++ b/platform/qt/src/utils/conversion.hpp @@ -1,13 +1,15 @@ #pragma once +#include + +#include "geojson.hpp" + #include #include #include -#include #include -#include -#include "qt_geojson.hpp" +#include namespace mbgl { namespace style { @@ -46,9 +48,9 @@ public: return value.canConvert(QVariant::Map) || value.type() == QVariant::ByteArray #endif - || QString(value.typeName()) == QStringLiteral("QMapbox::Feature") - || value.userType() == qMetaTypeId>() - || value.userType() == qMetaTypeId>(); + || QString(value.typeName()) == QStringLiteral("QMapLibreGL::Feature") + || value.userType() == qMetaTypeId>() + || value.userType() == qMetaTypeId>(); } static optional objectMember(const QVariant& value, const char* key) { @@ -168,12 +170,12 @@ public: } static optional toGeoJSON(const QVariant& value, Error& error) { - if (value.typeName() == QStringLiteral("QMapbox::Feature")) { - return GeoJSON { asMapboxGLFeature(value.value()) }; - } else if (value.userType() == qMetaTypeId>()) { - return featureCollectionToGeoJSON(value.value>()); - } else if (value.userType() == qMetaTypeId>()) { - return featureCollectionToGeoJSON(value.value>()); + 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>()); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) } else if (value.typeId() != QMetaType::QByteArray) { #else @@ -193,7 +195,7 @@ private: mapbox::feature::feature_collection collection; collection.reserve(static_cast(features.size())); for (const auto &feature : features) { - collection.push_back(asMapboxGLFeature(feature)); + collection.push_back(QMapLibreGL::GeoJSON::asFeature(feature)); } return GeoJSON { std::move(collection) }; } diff --git a/platform/qt/src/qt_geojson.cpp b/platform/qt/src/utils/geojson.cpp similarity index 60% rename from platform/qt/src/qt_geojson.cpp rename to platform/qt/src/utils/geojson.cpp index 4198be6e8..a37e51520 100644 --- a/platform/qt/src/qt_geojson.cpp +++ b/platform/qt/src/utils/geojson.cpp @@ -1,69 +1,69 @@ -#include "qt_geojson.hpp" +#include "geojson.hpp" -#pragma clang diagnostic ignored "-Wenum-compare-switch" +#include -namespace QMapbox { +namespace QMapLibreGL::GeoJSON { -mbgl::Point asMapboxGLPoint(const QMapbox::Coordinate &coordinate) { +mbgl::Point asPoint(const Coordinate &coordinate) { return mbgl::Point { coordinate.second, coordinate.first }; } -mbgl::MultiPoint asMapboxGLMultiPoint(const QMapbox::Coordinates &multiPoint) { +mbgl::MultiPoint asMultiPoint(const Coordinates &multiPoint) { mbgl::MultiPoint mbglMultiPoint; mbglMultiPoint.reserve(multiPoint.size()); for (const auto &point: multiPoint) { - mbglMultiPoint.emplace_back(asMapboxGLPoint(point)); + mbglMultiPoint.emplace_back(asPoint(point)); } return mbglMultiPoint; }; -mbgl::LineString asMapboxGLLineString(const QMapbox::Coordinates &lineString) { +mbgl::LineString asLineString(const Coordinates &lineString) { mbgl::LineString mbglLineString; mbglLineString.reserve(lineString.size()); for (const auto &coordinate : lineString) { - mbglLineString.emplace_back(asMapboxGLPoint(coordinate)); + mbglLineString.emplace_back(asPoint(coordinate)); } return mbglLineString; }; -mbgl::MultiLineString asMapboxGLMultiLineString(const QMapbox::CoordinatesCollection &multiLineString) { +mbgl::MultiLineString asMultiLineString(const CoordinatesCollection &multiLineString) { mbgl::MultiLineString mbglMultiLineString; mbglMultiLineString.reserve(multiLineString.size()); for (const auto &lineString : multiLineString) { - mbglMultiLineString.emplace_back(std::forward>(asMapboxGLLineString(lineString))); + mbglMultiLineString.emplace_back(std::forward>(asLineString(lineString))); } return mbglMultiLineString; }; -mbgl::Polygon asMapboxGLPolygon(const QMapbox::CoordinatesCollection &polygon) { +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(asMapboxGLPoint(coordinate)); + mbglLinearRing.emplace_back(asPoint(coordinate)); } mbglPolygon.emplace_back(std::move(mbglLinearRing)); } return mbglPolygon; }; -mbgl::MultiPolygon asMapboxGLMultiPolygon(const QMapbox::CoordinatesCollections &multiPolygon) { +mbgl::MultiPolygon asMultiPolygon(const CoordinatesCollections &multiPolygon) { mbgl::MultiPolygon mbglMultiPolygon; mbglMultiPolygon.reserve(multiPolygon.size()); for (const auto &polygon : multiPolygon) { - mbglMultiPolygon.emplace_back(std::forward>(asMapboxGLPolygon(polygon))); + mbglMultiPolygon.emplace_back(std::forward>(asPolygon(polygon))); } return mbglMultiPolygon; }; -mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { +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(asMapboxGLPropertyValue(listValue)); + mbglList.emplace_back(asPropertyValue(listValue)); } return mbglList; }; @@ -72,7 +72,7 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { 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(), asMapboxGLPropertyValue(it.value()))); + mbglMap.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value()))); } return mbglMap; }; @@ -80,7 +80,7 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) switch (value.typeId()) { #else - switch (value.type()) { + switch (static_cast(value.type())) { #endif case QMetaType::UnknownType: return mbgl::NullValue {}; @@ -104,11 +104,11 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { } } -mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id) { +mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) switch (id.typeId()) { #else - switch (id.type()) { + switch (static_cast(id.type())) { #endif case QMetaType::UnknownType: return {}; @@ -126,37 +126,37 @@ mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id) { } } -mbgl::GeoJSONFeature asMapboxGLFeature(const QMapbox::Feature &feature) { +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(), asMapboxGLPropertyValue(it.value()))); + properties.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value()))); } - mbgl::FeatureIdentifier id = asMapboxGLFeatureIdentifier(feature.id); + mbgl::FeatureIdentifier id = asFeatureIdentifier(feature.id); - if (feature.type == QMapbox::Feature::PointType) { - const QMapbox::Coordinates &points = feature.geometry.first().first(); + if (feature.type == Feature::PointType) { + const Coordinates &points = feature.geometry.first().first(); if (points.size() == 1) { - return { asMapboxGLPoint(points.first()), std::move(properties), std::move(id) }; + return { asPoint(points.first()), std::move(properties), std::move(id) }; } else { - return { asMapboxGLMultiPoint(points), std::move(properties), std::move(id) }; + return { asMultiPoint(points), std::move(properties), std::move(id) }; } - } else if (feature.type == QMapbox::Feature::LineStringType) { - const QMapbox::CoordinatesCollection &lineStrings = feature.geometry.first(); + } else if (feature.type == Feature::LineStringType) { + const CoordinatesCollection &lineStrings = feature.geometry.first(); if (lineStrings.size() == 1) { - return { asMapboxGLLineString(lineStrings.first()), std::move(properties), std::move(id) }; + return { asLineString(lineStrings.first()), std::move(properties), std::move(id) }; } else { - return { asMapboxGLMultiLineString(lineStrings), std::move(properties), std::move(id) }; + return { asMultiLineString(lineStrings), std::move(properties), std::move(id) }; } } else { // PolygonType - const QMapbox::CoordinatesCollections &polygons = feature.geometry; + const CoordinatesCollections &polygons = feature.geometry; if (polygons.size() == 1) { - return { asMapboxGLPolygon(polygons.first()), std::move(properties), std::move(id) }; + return { asPolygon(polygons.first()), std::move(properties), std::move(id) }; } else { - return { asMapboxGLMultiPolygon(polygons), std::move(properties), std::move(id) }; + return { asMultiPolygon(polygons), std::move(properties), std::move(id) }; } } }; -} // namespace QMapbox +} // namespace QMapLibreGL::GeoJSON diff --git a/platform/qt/src/utils/geojson.hpp b/platform/qt/src/utils/geojson.hpp new file mode 100644 index 000000000..90aa38ec4 --- /dev/null +++ b/platform/qt/src/utils/geojson.hpp @@ -0,0 +1,25 @@ +#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 new file mode 100644 index 000000000..3773d6544 --- /dev/null +++ b/platform/qt/src/utils/map_observer.cpp @@ -0,0 +1,122 @@ +#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/qmapboxgl_map_observer.hpp b/platform/qt/src/utils/map_observer.hpp similarity index 70% rename from platform/qt/src/qmapboxgl_map_observer.hpp rename to platform/qt/src/utils/map_observer.hpp index d9e51db28..c45387d56 100644 --- a/platform/qt/src/qmapboxgl_map_observer.hpp +++ b/platform/qt/src/utils/map_observer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "qmapboxgl.hpp" +#include #include #include @@ -10,15 +10,17 @@ #include #include -class QMapboxGLPrivate; +namespace QMapLibreGL { -class QMapboxGLMapObserver : public QObject, public mbgl::MapObserver +class MapPrivate; + +class MapObserver : public QObject, public mbgl::MapObserver { Q_OBJECT public: - explicit QMapboxGLMapObserver(QMapboxGLPrivate *); - virtual ~QMapboxGLMapObserver(); + explicit MapObserver(MapPrivate *); + virtual ~MapObserver(); // mbgl::MapObserver implementation. void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final; @@ -35,12 +37,14 @@ public: void onSourceChanged(mbgl::style::Source&) final; signals: - void mapChanged(QMapboxGL::MapChange); - void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason); + void mapChanged(Map::MapChange); + void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason); void copyrightsChanged(const QString ©rightsHtml); private: - Q_DISABLE_COPY(QMapboxGLMapObserver) + Q_DISABLE_COPY(MapObserver) - QMapboxGLPrivate *d_ptr; + MapPrivate *d_ptr; }; + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/utils/map_renderer.cpp similarity index 71% rename from platform/qt/src/qmapboxgl_map_renderer.cpp rename to platform/qt/src/utils/map_renderer.cpp index 6451045a4..b2798d443 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.cpp +++ b/platform/qt/src/utils/map_renderer.cpp @@ -1,10 +1,11 @@ -#include "qmapboxgl_map_renderer.hpp" -#include "qmapboxgl_scheduler.hpp" +#include "map_renderer.hpp" +#include "scheduler.hpp" #include #include -#include + +namespace { static bool needsToForceScheduler() { static QThreadStorage force; @@ -17,16 +18,21 @@ static bool needsToForceScheduler() { }; static auto *getScheduler() { - static QThreadStorage> scheduler; + static QThreadStorage> scheduler; if (!scheduler.hasLocalData()) { - scheduler.setLocalData(std::make_shared()); + scheduler.setLocalData(std::make_shared()); } return scheduler.localData().get(); }; -QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily) +} // 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() ? mbgl::nullopt : mbgl::optional { localFontFamily.toStdString() })) @@ -43,29 +49,29 @@ QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings:: mbgl::Scheduler::SetCurrent(scheduler); } - connect(scheduler, &QMapboxGLScheduler::needsProcessing, this, &QMapboxGLMapRenderer::needsRendering); + connect(scheduler, &Scheduler::needsProcessing, this, &MapRenderer::needsRendering); } } -QMapboxGLMapRenderer::~QMapboxGLMapRenderer() +MapRenderer::~MapRenderer() { MBGL_VERIFY_THREAD(tid); } -void QMapboxGLMapRenderer::updateParameters(std::shared_ptr newParameters) +void MapRenderer::updateParameters(std::shared_ptr newParameters) { std::lock_guard lock(m_updateMutex); m_updateParameters = std::move(newParameters); } -void QMapboxGLMapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size) +void MapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size) { MBGL_VERIFY_THREAD(tid); m_backend.updateFramebuffer(fbo, size); } -void QMapboxGLMapRenderer::render() +void MapRenderer::render() { MBGL_VERIFY_THREAD(tid); @@ -91,7 +97,9 @@ void QMapboxGLMapRenderer::render() } } -void QMapboxGLMapRenderer::setObserver(std::shared_ptr observer) +void MapRenderer::setObserver(std::shared_ptr observer) { m_renderer->setObserver(observer.get()); } + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/utils/map_renderer.hpp similarity index 61% rename from platform/qt/src/qmapboxgl_map_renderer.hpp rename to platform/qt/src/utils/map_renderer.hpp index 2769b2b87..e37d384ee 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.hpp +++ b/platform/qt/src/utils/map_renderer.hpp @@ -1,13 +1,15 @@ #pragma once -#include "qmapboxgl.hpp" -#include "qmapboxgl_renderer_backend.hpp" +#include + +#include "renderer_backend.hpp" #include #include #include #include +#include #include #include @@ -17,15 +19,17 @@ class Renderer; class UpdateParameters; } // namespace mbgl -class QMapboxGLRendererBackend; +namespace QMapLibreGL { -class QMapboxGLMapRenderer : public QObject +class RendererBackend; + +class MapRenderer : public QObject { Q_OBJECT public: - QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode, const QString &localFontFamily); - virtual ~QMapboxGLMapRenderer(); + MapRenderer(qreal pixelRatio, Settings::GLContextMode, const QString &localFontFamily); + virtual ~MapRenderer(); void render(); void updateFramebuffer(quint32 fbo, const mbgl::Size &size); @@ -40,13 +44,15 @@ signals: private: MBGL_STORE_THREAD(tid) - Q_DISABLE_COPY(QMapboxGLMapRenderer) + Q_DISABLE_COPY(MapRenderer) std::mutex m_updateMutex; std::shared_ptr m_updateParameters; - QMapboxGLRendererBackend m_backend; - std::unique_ptr m_renderer; + RendererBackend m_backend; + std::unique_ptr m_renderer{}; - bool m_forceScheduler; + bool m_forceScheduler{}; }; + +} // namespace QMapLibreGL diff --git a/platform/qt/src/utils/renderer_backend.cpp b/platform/qt/src/utils/renderer_backend.cpp new file mode 100644 index 000000000..66f5b2e6c --- /dev/null +++ b/platform/qt/src/utils/renderer_backend.cpp @@ -0,0 +1,56 @@ +#include "renderer_backend.hpp" + +#include +#include + +#include +#include + +namespace QMapLibreGL { + +class RenderableResource final : public mbgl::gl::RenderableResource { +public: + RenderableResource(RendererBackend& backend_) : backend(backend_) { + } + + void bind() override { + assert(mbgl::gfx::BackendScope::exists()); + backend.restoreFramebufferBinding(); + backend.setViewport(0, 0, backend.getSize()); + } + +private: + RendererBackend& backend; +}; + +RendererBackend::RendererBackend(const mbgl::gfx::ContextMode contextMode_) + : mbgl::gl::RendererBackend(contextMode_), + mbgl::gfx::Renderable({ 0, 0 }, std::make_unique(*this)) { +} + +RendererBackend::~RendererBackend() = default; + +void RendererBackend::updateAssumedState() { + assumeFramebufferBinding(ImplicitFramebufferBinding); + assumeViewport(0, 0, size); +} + +void RendererBackend::restoreFramebufferBinding() { + setFramebufferBinding(m_fbo); +} + +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 GL Native engine. +*/ +mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char* name) { + QOpenGLContext* thisContext = QOpenGLContext::currentContext(); + return thisContext->getProcAddress(name); +} + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_renderer_backend.hpp b/platform/qt/src/utils/renderer_backend.hpp similarity index 72% rename from platform/qt/src/qmapboxgl_renderer_backend.hpp rename to platform/qt/src/utils/renderer_backend.hpp index f821eda96..678905ad8 100644 --- a/platform/qt/src/qmapboxgl_renderer_backend.hpp +++ b/platform/qt/src/utils/renderer_backend.hpp @@ -1,15 +1,17 @@ #pragma once -#include "qmapboxgl.hpp" - #include #include -class QMapboxGLRendererBackend final : public mbgl::gl::RendererBackend, +#include + +namespace QMapLibreGL { + +class RendererBackend final : public mbgl::gl::RendererBackend, public mbgl::gfx::Renderable { public: - QMapboxGLRendererBackend(mbgl::gfx::ContextMode); - ~QMapboxGLRendererBackend() override; + RendererBackend(mbgl::gfx::ContextMode); + ~RendererBackend() override; void updateFramebuffer(quint32 fbo, const mbgl::Size&); void restoreFramebufferBinding(); @@ -31,7 +33,9 @@ protected: void updateAssumedState() override; private: - quint32 m_fbo = 0; + quint32 m_fbo{}; - Q_DISABLE_COPY(QMapboxGLRendererBackend) + Q_DISABLE_COPY(RendererBackend) }; + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_renderer_observer.hpp b/platform/qt/src/utils/renderer_observer.hpp similarity index 83% rename from platform/qt/src/qmapboxgl_renderer_observer.hpp rename to platform/qt/src/utils/renderer_observer.hpp index 78dd6b91d..3fd515f99 100644 --- a/platform/qt/src/qmapboxgl_renderer_observer.hpp +++ b/platform/qt/src/utils/renderer_observer.hpp @@ -8,16 +8,18 @@ #include +namespace QMapLibreGL { + // Forwards RendererObserver signals to the given // Delegate RendererObserver on the given RunLoop -class QMapboxGLRendererObserver : public mbgl::RendererObserver { +class RendererObserver : public mbgl::RendererObserver { public: - QMapboxGLRendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_) + RendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_) : mailbox(std::make_shared(mapRunLoop)) , delegate(delegate_, mailbox) { } - ~QMapboxGLRendererObserver() { + ~RendererObserver() { mailbox->close(); } @@ -46,6 +48,8 @@ public: } private: - std::shared_ptr mailbox; + std::shared_ptr mailbox{}; mbgl::ActorRef delegate; }; + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_scheduler.cpp b/platform/qt/src/utils/scheduler.cpp similarity index 73% rename from platform/qt/src/qmapboxgl_scheduler.cpp rename to platform/qt/src/utils/scheduler.cpp index 5fc3ab13d..4b2c13225 100644 --- a/platform/qt/src/qmapboxgl_scheduler.cpp +++ b/platform/qt/src/utils/scheduler.cpp @@ -1,19 +1,21 @@ -#include "qmapboxgl_scheduler.hpp" +#include "scheduler.hpp" #include #include -QMapboxGLScheduler::QMapboxGLScheduler() +namespace QMapLibreGL { + +Scheduler::Scheduler() { } -QMapboxGLScheduler::~QMapboxGLScheduler() +Scheduler::~Scheduler() { MBGL_VERIFY_THREAD(tid); } -void QMapboxGLScheduler::schedule(std::function function) { +void Scheduler::schedule(std::function function) { std::lock_guard lock(m_taskQueueMutex); m_taskQueue.push(std::move(function)); @@ -22,7 +24,7 @@ void QMapboxGLScheduler::schedule(std::function function) { emit needsProcessing(); } -void QMapboxGLScheduler::processEvents() +void Scheduler::processEvents() { std::queue> taskQueue; { @@ -36,3 +38,5 @@ void QMapboxGLScheduler::processEvents() taskQueue.pop(); } } + +} // namespace QMapLibreGL diff --git a/platform/qt/src/qmapboxgl_scheduler.hpp b/platform/qt/src/utils/scheduler.hpp similarity index 67% rename from platform/qt/src/qmapboxgl_scheduler.hpp rename to platform/qt/src/utils/scheduler.hpp index 0b000b9fc..2b69ea769 100644 --- a/platform/qt/src/qmapboxgl_scheduler.hpp +++ b/platform/qt/src/utils/scheduler.hpp @@ -9,17 +9,19 @@ #include #include -class QMapboxGLScheduler : public QObject, public mbgl::Scheduler +namespace QMapLibreGL { + +class Scheduler : public QObject, public mbgl::Scheduler { Q_OBJECT public: - QMapboxGLScheduler(); - virtual ~QMapboxGLScheduler(); + Scheduler(); + virtual ~Scheduler(); // mbgl::Scheduler implementation. void schedule(std::function scheduled) final; - mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } + mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } void processEvents(); @@ -33,3 +35,5 @@ private: std::queue> m_taskQueue; mapbox::base::WeakPtrFactory weakFactory{this}; }; + +} // namepace QMapLibreGL diff --git a/platform/qt/test/main.cpp b/platform/qt/test/main.cpp index 92570ab09..58c22b1df 100644 --- a/platform/qt/test/main.cpp +++ b/platform/qt/test/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -15,7 +15,7 @@ #define str(s) #s int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QGuiApplication app(argc, argv); #ifdef WORK_DIRECTORY #ifdef _MSC_VER diff --git a/platform/qt/test/qmapboxgl.test.cpp b/platform/qt/test/qmapboxgl.test.cpp deleted file mode 100644 index 22ed9779d..000000000 --- a/platform/qt/test/qmapboxgl.test.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "qmapboxgl.test.hpp" - -#include - -#include -#include -#include -#include -#include - -#include - -QMapboxGLTest::QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) { - connect(&map, &QMapboxGL::mapChanged, this, &QMapboxGLTest::onMapChanged); - connect(&map, &QMapboxGL::needsRendering, this, &QMapboxGLTest::onNeedsRendering); - map.resize(fbo.size()); - map.setFramebufferObject(fbo.handle(), fbo.size()); - map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14); -} - -void QMapboxGLTest::runUntil(QMapboxGL::MapChange status) { - changeCallback = [&](QMapboxGL::MapChange change) { - if (change == status) { - qApp->exit(); - changeCallback = nullptr; - } - }; - - qApp->exec(); -} - -void QMapboxGLTest::onMapChanged(QMapboxGL::MapChange change) { - if (changeCallback) { - changeCallback(change); - } -} - -void QMapboxGLTest::onNeedsRendering() { - widget.makeCurrent(); - fbo.bind(); - QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo.width(), fbo.height()); - map.render(); -} - - -TEST_F(QMapboxGLTest, 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(QMapboxGL::MapChangeDidFinishLoadingMap); - - map.setStyleJson("invalid json"); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleJson("\"\""); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleJson(QString()); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); -} - -TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleUrl)) { - QString url(QMapbox::defaultStyles()[0].first); - - map.setStyleUrl(url); - ASSERT_EQ(map.styleUrl(), url); - runUntil(QMapboxGL::MapChangeDidFinishLoadingMap); - - map.setStyleUrl("invalid://url"); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleUrl(QString()); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); -} diff --git a/platform/qt/test/qmapboxgl.test.hpp b/platform/qt/test/qmapboxgl.test.hpp deleted file mode 100644 index 3591dbc9d..000000000 --- a/platform/qt/test/qmapboxgl.test.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#include -#include - -#include - -class QMapboxGLTest : public QObject, public ::testing::Test { - Q_OBJECT - -public: - QMapboxGLTest(); - - void runUntil(QMapboxGL::MapChange); - -private: - QGLWidget widget; - const QSize size; - QGLFramebufferObject fbo; - -protected: - QMapboxGLSettings settings; - QMapboxGL map; - - std::function changeCallback; - -private slots: - void onMapChanged(QMapboxGL::MapChange); - void onNeedsRendering(); -}; diff --git a/platform/qt/test/qmaplibregl.test.cpp b/platform/qt/test/qmaplibregl.test.cpp new file mode 100644 index 000000000..b5dd6ea9b --- /dev/null +++ b/platform/qt/test/qmaplibregl.test.cpp @@ -0,0 +1,80 @@ +#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 new file mode 100644 index 000000000..c57d6e6ec --- /dev/null +++ b/platform/qt/test/qmaplibregl.test.hpp @@ -0,0 +1,30 @@ +#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(); +};