Skip to content

Commit

Permalink
[qt] Rename QMapboxGL to QMapLibreGL (maplibre#338)
Browse files Browse the repository at this point in the history
* Rename QMapboxGL to QMapLibreGL

* Add missing QDebug includes

* Fix Qt CMake config

* Fix geojson warning

* Remove redundant OpenGL dependency

* Put everything under QMapLibreGL namespace

* Reorganise headers

Co-authored-by: Rinigus <[email protected]>
  • Loading branch information
ntadej and rinigus authored Jul 3, 2022
1 parent 7a40d4c commit 5b3d936
Show file tree
Hide file tree
Showing 66 changed files with 1,732 additions and 1,629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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@
2 changes: 1 addition & 1 deletion platform/qt/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
60 changes: 30 additions & 30 deletions platform/qt/app/mapwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<QMapbox::SymbolAnnotation>(symbol));
m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::SymbolAnnotation>(symbol));
} else {
m_map->removeAnnotation(m_symbolAnnotationId.toUInt());
m_symbolAnnotationId.clear();
Expand All @@ -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<QMapbox::LineAnnotation>(line));
m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::LineAnnotation>(line));
} else {
m_map->removeAnnotation(m_lineAnnotationId.toUInt());
m_lineAnnotationId.clear();
Expand All @@ -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>(QColor(Qt::black));
m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::FillAnnotation>(fill));
m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::FillAnnotation>(fill));
} else {
m_map->removeAnnotation(m_fillAnnotationId.toUInt());
m_fillAnnotationId.clear();
Expand All @@ -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<QMapbox::Feature>(feature);
circleSource["data"] = QVariant::fromValue<QMapLibreGL::Feature>(feature);
m_map->addSource("circleSource", circleSource);

QVariantMap circle;
Expand All @@ -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<QMapbox::Feature>
QVector<QMapbox::Feature> inner{
// multiple features by QVector<QMapLibreGL::Feature>
QVector<QMapLibreGL::Feature> inner{
makePoint(0.001, 0, "red"),
makePoint(0, 0.001, "green"),
makePoint(0, -0.001, "blue")
Expand All @@ -376,8 +376,8 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
{"source", "innerCirclesSource"}
});

// multiple features by QList<QMapbox::Feature>
QList<QMapbox::Feature> outer{
// multiple features by QList<QMapLibreGL::Feature>
QList<QMapLibreGL::Feature> outer{
makePoint( 0.002, 0.002, "cyan"),
makePoint(-0.002, 0.002, "magenta"),
makePoint( 0.002, -0.002, "yellow"),
Expand Down Expand Up @@ -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()) {
Expand Down
21 changes: 11 additions & 10 deletions platform/qt/app/mapwindow.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef MAPWINDOW_H
#define MAPWINDOW_H

#include <QMapboxGL>
#include <QMapLibreGL/Map>
#include <QMapLibreGL/Settings>

#include <QtGlobal>
#include <QOpenGLWidget>
#include <QPropertyAnimation>
#include <QtGlobal>

#include <memory>

Expand All @@ -18,7 +19,7 @@ class MapWindow : public QOpenGLWidget
Q_OBJECT

public:
MapWindow(const QMapboxGLSettings &);
MapWindow(const QMapLibreGL::Settings &);
~MapWindow();

void selfTest();
Expand All @@ -43,20 +44,20 @@ protected slots:

QPointF m_lastPos;

QMapboxGLSettings m_settings;
std::unique_ptr<QMapboxGL> m_map{};
QMapLibreGL::Settings m_settings;
std::unique_ptr<QMapLibreGL::Map> 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
6 changes: 3 additions & 3 deletions platform/qt/config.qdocconf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions platform/qt/include/QMapLibreGL/Map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "map.hpp"
1 change: 1 addition & 0 deletions platform/qt/include/QMapLibreGL/Settings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "settings.hpp"
1 change: 1 addition & 0 deletions platform/qt/include/QMapLibreGL/Types
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "types.hpp"
1 change: 1 addition & 0 deletions platform/qt/include/QMapLibreGL/Utils
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "utils.hpp"
16 changes: 16 additions & 0 deletions platform/qt/include/QMapLibreGL/export.hpp
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 5b3d936

Please sign in to comment.