diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-12-02 18:22:12 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-16 16:18:27 +0000 |
commit | 762dc9dd2b47f908c3739173aa1e108dd7386717 (patch) | |
tree | 201747076f1ee6deda535a6e58cafc4edaa37cbe /src/location/maps/qgeomap.cpp | |
parent | 45b1f2c23cf0e782c0b99f38e4d01a88da765753 (diff) | |
download | qtlocation-762dc9dd2b47f908c3739173aa1e108dd7386717.tar.gz |
Move the coordinate <-> item position conversion to QGeoProjection
This patch simplifies the QGeoMap API removing all the API
necessary to convert to and from screen.
This is now demanded to a specific QGeoProjection class, that will
be independent of the map, except for using the same Geo projection
(currently only WebMercator, or EPSG:3857, although we use a sphere
instead of an ellipsoid, i believe)
The benefits are
- This relieves subclasses of QGeoMap from implementing a
GeoProjection API, especially since QtLocation currently supports
only WebMercator, and reimplementations would have to anyway
produce the same results as the inbuilt one.
- This avoids the several indirection steps previously necessary
to perform a map projection (qgeotiledmap -> private->mapscene->
private). Since these operation are quite frequent one per
map item coordinate at every redraw, shortening the indirection
chain is beneficial
- It simplifies the highly complex QGeoTiledMapScene, separating
all the logic that is not needed to draw the scene, but only
to perform geo coordinate <-> screen coordinate conversion
Change-Id: I9e3ca5280166f2d6430a32deb44c030d02d9d4e1
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps/qgeomap.cpp')
-rw-r--r-- | src/location/maps/qgeomap.cpp | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp index f30dbce7..325ca83f 100644 --- a/src/location/maps/qgeomap.cpp +++ b/src/location/maps/qgeomap.cpp @@ -57,6 +57,7 @@ void QGeoMap::setViewportSize(const QSize& size) if (size == d->m_viewportSize) return; d->m_viewportSize = size; + d->m_geoProjection->setViewportSize(size); d->changeViewportSize(size); } @@ -84,6 +85,7 @@ void QGeoMap::setCameraData(const QGeoCameraData &cameraData) if (cameraData == d->m_cameraData) return; d->m_cameraData = cameraData; + d->m_geoProjection->setCameraData(cameraData); d->changeCameraData(cameraData); emit cameraDataChanged(d->m_cameraData); } @@ -110,48 +112,44 @@ const QGeoMapType QGeoMap::activeMapType() const return d->m_activeMapType; } - -QGeoCameraCapabilities QGeoMap::cameraCapabilities() const +double QGeoMap::minimumZoom() const { Q_D(const QGeoMap); - if (!d->m_engine.isNull()) - return d->m_engine->cameraCapabilities(); - else - return QGeoCameraCapabilities(); + return d->m_geoProjection->minimumZoom(); } -/* Default implementations */ -QGeoCoordinate QGeoMap::itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport) const +double QGeoMap::maximumCenterLatitudeAtZoom(double zoomLevel) const { - if (clipToViewport) { - int w = viewportWidth(); - int h = viewportHeight(); - - if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y())) - return QGeoCoordinate(); - } + Q_D(const QGeoMap); + return d->m_geoProjection->maximumCenterLatitudeAtZoom(zoomLevel); +} - QDoubleVector2D wrappedMapProjection = itemPositionToWrappedMapProjection(pos); - // With rotation/tilting, a screen position might end up outside the projection space. - // TODO: test for it - return mapProjectionToGeo(unwrapMapProjection(wrappedMapProjection)); +double QGeoMap::mapWidth() const +{ + Q_D(const QGeoMap); + return d->m_geoProjection->mapWidth(); } -QDoubleVector2D QGeoMap::coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const +double QGeoMap::mapHeight() const { - QDoubleVector2D pos = wrappedMapProjectionToItemPosition(wrapMapProjection(geoToMapProjection(coordinate))); + Q_D(const QGeoMap); + return d->m_geoProjection->mapHeight(); +} - if (clipToViewport) { - int w = viewportWidth(); - int h = viewportHeight(); - double x = pos.x(); - double y = pos.y(); - if ((x < -0.5) || (x > w + 0.5) || (y < -0.5) || (y > h + 0.5) || qIsNaN(x) || qIsNaN(y)) - return QDoubleVector2D(qQNaN(), qQNaN()); - } - return pos; +const QGeoProjection &QGeoMap::geoProjection() const +{ + Q_D(const QGeoMap); + return *(d->m_geoProjection); } +QGeoCameraCapabilities QGeoMap::cameraCapabilities() const +{ + Q_D(const QGeoMap); + if (!d->m_engine.isNull()) + return d->m_engine->cameraCapabilities(); + else + return QGeoCameraCapabilities(); +} void QGeoMap::prefetchData() { @@ -189,8 +187,9 @@ void QGeoMap::clearParameters() d->m_mapParameters.clear(); } -QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine) +QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine, QGeoProjection *geoProjection) : QObjectPrivate(), + m_geoProjection(geoProjection), m_engine(engine), m_activeMapType(QGeoMapType()) { @@ -198,6 +197,8 @@ QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine) QGeoMapPrivate::~QGeoMapPrivate() { + if (m_geoProjection) + delete m_geoProjection; } void QGeoMapPrivate::addParameter(QGeoMapParameter *param) |