[Qt] Add the QMapbox header with QMapbox datatypes

This commit is contained in:
Thiago Marcos P. Santos
2016-02-02 16:38:24 +02:00
parent dd075d53ed
commit 19e1129367
6 changed files with 59 additions and 41 deletions

View File

@@ -18,7 +18,7 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings)
connect(&m_map, SIGNAL(needsRendering()), this, SLOT(updateGL()));
// Set default location to Helsinki.
m_map.setCoordinateZoom(QMapboxGL::Coordinate(60.170448, 24.942046), 14);
m_map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
changeStyle();

View File

@@ -0,0 +1 @@
#include "qmapbox.hpp"

View File

@@ -0,0 +1,28 @@
#ifndef QMAPBOX_H
#define QMAPBOX_H
#include <QList>
#include <QPair>
#include <QString>
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
namespace QMapbox {
typedef QPair<double, double> Coordinate;
typedef QList<Coordinate> Coordinates;
typedef QList<Coordinates> CoordinateSegments;
typedef quint32 AnnotationID;
typedef QList<AnnotationID> AnnotationIDs;
typedef QPair<Coordinate, QString> PointAnnotation;
typedef QList<PointAnnotation> PointAnnotations;
// FIXME: We need to add support for custom style properties
typedef QPair<CoordinateSegments, QString> ShapeAnnotation;
typedef QList<ShapeAnnotation> ShapeAnnotations;
}
#endif // QMAPBOX_H

View File

@@ -1,8 +1,8 @@
#ifndef QMAPBOXGL_H
#define QMAPBOXGL_H
#include <QMapbox>
#include <QObject>
#include <QPair>
#include <QPointF>
class QImage;
@@ -77,20 +77,6 @@ class Q_DECL_EXPORT QMapboxGL : public QObject
Q_PROPERTY(double pitch READ pitch WRITE setPitch)
public:
typedef QPair<double, double> Coordinate;
typedef QList<Coordinate> Coordinates;
typedef QList<Coordinates> CoordinateSegments;
typedef quint32 AnnotationID;
typedef QList<AnnotationID> AnnotationIDs;
typedef QPair<Coordinate, QString> PointAnnotation;
typedef QList<PointAnnotation> PointAnnotations;
// FIXME: We need to add support for custom style properties
typedef QPair<CoordinateSegments, QString> ShapeAnnotation;
typedef QList<ShapeAnnotation> ShapeAnnotations;
// Determines the orientation of the map.
enum NorthOrientation {
NorthUpwards, // Default
@@ -135,9 +121,9 @@ public:
NorthOrientation northOrientation() const;
void setNorthOrientation(NorthOrientation);
Coordinate coordinate() const;
void setCoordinate(const Coordinate &);
void setCoordinateZoom(const Coordinate &, double zoom);
QMapbox::Coordinate coordinate() const;
void setCoordinate(const QMapbox::Coordinate &);
void setCoordinateZoom(const QMapbox::Coordinate &, double zoom);
void setGestureInProgress(bool inProgress);
@@ -147,14 +133,14 @@ public:
void setClasses(const QStringList &);
QStringList getClasses() const;
AnnotationID addPointAnnotation(const PointAnnotation &);
AnnotationIDs addPointAnnotations(const PointAnnotations &);
QMapbox::AnnotationID addPointAnnotation(const QMapbox::PointAnnotation &);
QMapbox::AnnotationIDs addPointAnnotations(const QMapbox::PointAnnotations &);
AnnotationID addShapeAnnotation(const ShapeAnnotation &);
AnnotationIDs addShapeAnnotations(const ShapeAnnotations &);
QMapbox::AnnotationID addShapeAnnotation(const QMapbox::ShapeAnnotation &);
QMapbox::AnnotationIDs addShapeAnnotations(const QMapbox::ShapeAnnotations &);
void removeAnnotation(AnnotationID);
void removeAnnotations(const AnnotationIDs &);
void removeAnnotation(QMapbox::AnnotationID);
void removeAnnotations(const QMapbox::AnnotationIDs &);
bool isRotating() const;
bool isScaling() const;
@@ -169,8 +155,8 @@ public:
void addAnnotationIcon(const QString &name, const QImage &sprite);
QPointF pixelForCoordinate(const Coordinate &) const;
Coordinate coordinateForPixel(const QPointF &) const;
QPointF pixelForCoordinate(const QMapbox::Coordinate &) const;
QMapbox::Coordinate coordinateForPixel(const QPointF &) const;
void setMargins(const QMargins &margins);
QMargins margins() const;

View File

@@ -42,6 +42,7 @@
'../default/sqlite3.cpp',
'../default/string_stdlib.cpp',
'../default/thread.cpp',
'include/qmapbox.hpp',
'include/qmapboxgl.hpp',
'qmapbox.qrc',
'src/async_task.cpp',

View File

@@ -18,6 +18,8 @@
#include <memory>
using namespace QMapbox;
QMapboxGLSettings::QMapboxGLSettings()
: m_mapMode(QMapboxGLSettings::ContinuousMap)
, m_contextMode(QMapboxGLSettings::UniqueGLContext)
@@ -189,7 +191,7 @@ double QMapboxGL::maximumZoom() const
return d_ptr->mapObj->getMaxZoom();
}
QMapboxGL::Coordinate QMapboxGL::coordinate() const
Coordinate QMapboxGL::coordinate() const
{
const mbgl::LatLng& latLng = d_ptr->mapObj->getLatLng(d_ptr->margins);
return Coordinate(latLng.latitude, latLng.longitude);
@@ -294,24 +296,24 @@ QStringList QMapboxGL::getClasses() const
return classNames;
}
mbgl::PointAnnotation fromQMapboxGLPointAnnotation(const QMapboxGL::PointAnnotation &pointAnnotation) {
const QMapboxGL::Coordinate &coordinate = pointAnnotation.first;
mbgl::PointAnnotation fromPointAnnotation(const PointAnnotation &pointAnnotation) {
const Coordinate &coordinate = pointAnnotation.first;
const QString &icon = pointAnnotation.second;
return { { coordinate.first, coordinate.second }, icon.toStdString() };
}
QMapboxGL::AnnotationID QMapboxGL::addPointAnnotation(const PointAnnotation &pointAnnotation)
AnnotationID QMapboxGL::addPointAnnotation(const PointAnnotation &pointAnnotation)
{
return d_ptr->mapObj->addPointAnnotation(fromQMapboxGLPointAnnotation(pointAnnotation));
return d_ptr->mapObj->addPointAnnotation(fromPointAnnotation(pointAnnotation));
}
QMapboxGL::AnnotationIDs QMapboxGL::addPointAnnotations(const PointAnnotations &pointAnnotations)
AnnotationIDs QMapboxGL::addPointAnnotations(const PointAnnotations &pointAnnotations)
{
std::vector<mbgl::PointAnnotation> mbglPointAnnotations;
mbglPointAnnotations.reserve(pointAnnotations.size());
for (const PointAnnotation &pointAnnotation : pointAnnotations) {
mbglPointAnnotations.emplace_back(fromQMapboxGLPointAnnotation(pointAnnotation));
mbglPointAnnotations.emplace_back(fromPointAnnotation(pointAnnotation));
}
AnnotationIDs ids;
@@ -322,18 +324,18 @@ QMapboxGL::AnnotationIDs QMapboxGL::addPointAnnotations(const PointAnnotations &
return ids;
}
mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const QMapboxGL::ShapeAnnotation &shapeAnnotation) {
const QMapboxGL::CoordinateSegments &segments = shapeAnnotation.first;
mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const ShapeAnnotation &shapeAnnotation) {
const CoordinateSegments &segments = shapeAnnotation.first;
const QString &styleLayer = shapeAnnotation.second;
mbgl::AnnotationSegments mbglAnnotationSegments;
mbglAnnotationSegments.reserve(segments.size());
for (const QMapboxGL::Coordinates &coordinates : segments) {
for (const Coordinates &coordinates : segments) {
mbgl::AnnotationSegment mbglAnnotationSegment;
mbglAnnotationSegment.reserve(coordinates.size());
for (const QMapboxGL::Coordinate &coordinate : coordinates) {
for (const Coordinate &coordinate : coordinates) {
mbgl::LatLng mbglCoordinate(coordinate.first, coordinate.second);
mbglAnnotationSegment.emplace_back(mbglCoordinate);
}
@@ -344,12 +346,12 @@ mbgl::ShapeAnnotation fromQMapboxGLShapeAnnotation(const QMapboxGL::ShapeAnnotat
return { mbglAnnotationSegments, styleLayer.toStdString() };
}
QMapboxGL::AnnotationID QMapboxGL::addShapeAnnotation(const ShapeAnnotation &shapeAnnotation)
AnnotationID QMapboxGL::addShapeAnnotation(const ShapeAnnotation &shapeAnnotation)
{
return d_ptr->mapObj->addShapeAnnotation(fromQMapboxGLShapeAnnotation(shapeAnnotation));
}
QMapboxGL::AnnotationIDs QMapboxGL::addShapeAnnotations(const ShapeAnnotations &shapeAnnotations)
AnnotationIDs QMapboxGL::addShapeAnnotations(const ShapeAnnotations &shapeAnnotations)
{
std::vector<mbgl::ShapeAnnotation> mbglShapeAnnotations;
mbglShapeAnnotations.reserve(shapeAnnotations.size());
@@ -450,7 +452,7 @@ QPointF QMapboxGL::pixelForCoordinate(const Coordinate &coordinate_) const
return QPointF(pixel.x, pixel.y);
}
QMapboxGL::Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const
Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const
{
const mbgl::LatLng latLng =
d_ptr->mapObj->latLngForPixel(mbgl::ScreenCoordinate { pixel.x(), pixel.y() });