diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-06-19 16:33:44 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-07-26 13:38:02 +0000 |
commit | eca7cc8a260538fcccde97fe59d9580250600bf1 (patch) | |
tree | 6a87cc4391b1e0dbf65ee011d0314cfae4c8b19f /src/plugins | |
parent | d6fc6ba0f84c4cda0ccc2e1250da4a68441dd6ba (diff) | |
download | qtlocation-eca7cc8a260538fcccde97fe59d9580250600bf1.tar.gz |
Introduce Map.visibleArea
This will allow moving the visible map area to a subregion
of the viewport, allowing to maintain the desired visible
region visible when overlaying controls on top of the map.
Task-number: QTBUG-68966
Change-Id: Idf4b30f7c1e4062e5e1c0ddc01a31bc856c0bc0c
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins')
5 files changed, 67 insertions, 60 deletions
diff --git a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp index af0e263b..dede9dbc 100644 --- a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp +++ b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp @@ -70,10 +70,16 @@ public: #endif void updateObjectsGeometry(); + + void setVisibleArea(const QRectF &visibleArea) override; + QRectF visibleArea() const override; + protected: void changeViewportSize(const QSize &size) override; void changeCameraData(const QGeoCameraData &oldCameraData) override; void changeActiveMapType(const QGeoMapType mapType) override; + + QRectF m_visibleArea; }; QGeoMapItemsOverlay::QGeoMapItemsOverlay(QGeoMappingManagerEngineItemsOverlay *engine, QObject *parent) @@ -131,6 +137,24 @@ void QGeoMapItemsOverlay::removeMapObject(QGeoMapObject *obj) #endif } +void QGeoMapItemsOverlayPrivate::setVisibleArea(const QRectF &visibleArea) +{ + Q_Q(QGeoMapItemsOverlay); + const QRectF va = clampVisibleArea(visibleArea); + if (va == m_visibleArea) + return; + + m_visibleArea = va; + m_geoProjection->setVisibleArea(va); + + q->sgNodeChanged(); +} + +QRectF QGeoMapItemsOverlayPrivate::visibleArea() const +{ + return m_visibleArea; +} + QGeoMapItemsOverlayPrivate::QGeoMapItemsOverlayPrivate(QGeoMappingManagerEngineItemsOverlay *engine, QGeoMapItemsOverlay *map) : QGeoMapPrivate(engine, new QGeoProjectionWebMercator) { diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp index dfebc20d..575bf3b4 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp @@ -106,12 +106,12 @@ QSGNode *QGeoMapMapboxGLPrivate::updateSceneGraph(QSGNode *node, QQuickWindow *w if (m_useFBO) { QSGMapboxGLTextureNode *mbglNode = new QSGMapboxGLTextureNode(m_settings, m_viewportSize, window->devicePixelRatio(), q); QObject::connect(mbglNode->map(), &QMapboxGL::mapChanged, q, &QGeoMapMapboxGL::onMapChanged); - m_syncState = MapTypeSync | CameraDataSync | ViewportSync; + m_syncState = MapTypeSync | CameraDataSync | ViewportSync | VisibleAreaSync; node = mbglNode; } else { QSGMapboxGLRenderNode *mbglNode = new QSGMapboxGLRenderNode(m_settings, m_viewportSize, window->devicePixelRatio(), q); QObject::connect(mbglNode->map(), &QMapboxGL::mapChanged, q, &QGeoMapMapboxGL::onMapChanged); - m_syncState = MapTypeSync | CameraDataSync | ViewportSync; + m_syncState = MapTypeSync | CameraDataSync | ViewportSync | VisibleAreaSync; node = mbglNode; } } @@ -125,7 +125,15 @@ QSGNode *QGeoMapMapboxGLPrivate::updateSceneGraph(QSGNode *node, QQuickWindow *w map->setStyleUrl(m_activeMapType.name()); } - if (m_syncState & CameraDataSync) { + if (m_syncState & VisibleAreaSync) { + QMargins margins(m_visibleArea.x(), // left + m_visibleArea.y(), // top + m_viewportSize.width() - m_visibleArea.width() - m_visibleArea.x(), // right + m_viewportSize.height() - m_visibleArea.height() - m_visibleArea.y()); // bottom + map->setMargins(margins); + } + + if (m_syncState & CameraDataSync || m_syncState & VisibleAreaSync) { map->setZoom(zoomLevelFrom256(m_cameraData.zoomLevel() , MBGL_TILE_SIZE)); map->setBearing(m_cameraData.bearing()); map->setPitch(m_cameraData.tilt()); @@ -291,6 +299,25 @@ void QGeoMapMapboxGLPrivate::changeActiveMapType(const QGeoMapType) emit q->sgNodeChanged(); } +void QGeoMapMapboxGLPrivate::setVisibleArea(const QRectF &visibleArea) +{ + Q_Q(QGeoMapMapboxGL); + const QRectF va = clampVisibleArea(visibleArea); + if (va == m_visibleArea) + return; + + m_visibleArea = va; + m_geoProjection->setVisibleArea(va); + + m_syncState = m_syncState | VisibleAreaSync; + emit q->sgNodeChanged(); +} + +QRectF QGeoMapMapboxGLPrivate::visibleArea() const +{ + return m_visibleArea; +} + void QGeoMapMapboxGLPrivate::syncStyleChanges(QMapboxGL *map) { for (const auto& change : m_styleChanges) { @@ -376,7 +403,8 @@ QGeoMap::Capabilities QGeoMapMapboxGL::capabilities() const { return Capabilities(SupportsVisibleRegion | SupportsSetBearing - | SupportsAnchoringCoordinate); + | SupportsAnchoringCoordinate + | SupportsVisibleArea ); } QSGNode *QGeoMapMapboxGL::updateSceneGraph(QSGNode *oldNode, QQuickWindow *window) diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h index ffb06208..f07b4c98 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h @@ -43,6 +43,7 @@ #include <QtCore/QSharedPointer> #include <QtCore/QTimer> #include <QtCore/QVariant> +#include <QtCore/QRectF> #include <QtLocation/private/qgeomap_p_p.h> #include <QtLocation/private/qgeomapparameter_p.h> @@ -70,9 +71,10 @@ public: /* Data members */ enum SyncState : int { NoSync = 0, - ViewportSync = 1 << 0, - CameraDataSync = 1 << 1, - MapTypeSync = 1 << 2 + ViewportSync = 1 << 0, + CameraDataSync = 1 << 1, + MapTypeSync = 1 << 2, + VisibleAreaSync = 1 << 3 }; Q_DECLARE_FLAGS(SyncStates, SyncState); @@ -96,11 +98,16 @@ protected: void changeCameraData(const QGeoCameraData &oldCameraData) override; void changeActiveMapType(const QGeoMapType mapType) override; + void setVisibleArea(const QRectF &visibleArea) override; + QRectF visibleArea() const override; + private: Q_DISABLE_COPY(QGeoMapMapboxGLPrivate); void syncStyleChanges(QMapboxGL *map); void threadedRenderingHack(QQuickWindow *window, QMapboxGL *map); + + QRectF m_visibleArea; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoMapMapboxGLPrivate::SyncStates) diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp index 6c47d3ee..d9de5ba9 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp @@ -186,8 +186,7 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapParamete { static const QStringList acceptedParameterTypes = QStringList() << QStringLiteral("paint") << QStringLiteral("layout") << QStringLiteral("filter") - << QStringLiteral("layer") << QStringLiteral("source") << QStringLiteral("image") - << QStringLiteral("margins"); + << QStringLiteral("layer") << QStringLiteral("source") << QStringLiteral("image"); QList<QSharedPointer<QMapboxGLStyleChange>> changes; @@ -213,9 +212,6 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapParamete case 5: // image changes << QMapboxGLStyleAddImage::fromMapParameter(param); break; - case 6: // margins - changes << QMapboxGLMapMargins::fromMapParameter(param); - break; } return changes; @@ -641,38 +637,3 @@ QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddImage::fromMapParameter(QG return QSharedPointer<QMapboxGLStyleChange>(image); } - -// QMapboxGLMapMargins - -void QMapboxGLMapMargins::apply(QMapboxGL *map) -{ - // FIXME: Qt projection handlers are not yet aware of these margins, - // thus map items placement, {to,from}Coordinate, mouse area, etc. - // will require manual fixups. - map->setMargins(m_margins); -} - -QSharedPointer<QMapboxGLStyleChange> QMapboxGLMapMargins::fromMapParameter(QGeoMapParameter *param) -{ - Q_ASSERT(param->type() == "margins"); - - auto mapMargins = new QMapboxGLMapMargins(); - - QVariant leftMargin = param->property("left"); - if (leftMargin.isValid()) - mapMargins->m_margins.setLeft(leftMargin.toInt()); - - QVariant topMargin = param->property("top"); - if (topMargin.isValid()) - mapMargins->m_margins.setTop(topMargin.toInt()); - - QVariant rightMargin = param->property("right"); - if (rightMargin.isValid()) - mapMargins->m_margins.setRight(rightMargin.toInt()); - - QVariant bottomMargin = param->property("bottom"); - if (bottomMargin.isValid()) - mapMargins->m_margins.setBottom(bottomMargin.toInt()); - - return QSharedPointer<QMapboxGLStyleChange>(mapMargins); -} diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h index 38aa87f8..fd5b9af4 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h @@ -190,17 +190,4 @@ private: QImage m_sprite; }; -class QMapboxGLMapMargins : public QMapboxGLStyleChange -{ -public: - static QSharedPointer<QMapboxGLStyleChange> fromMapParameter(QGeoMapParameter *); - - void apply(QMapboxGL *map) override; - -private: - QMapboxGLMapMargins() = default; - - QMargins m_margins; -}; - #endif // QQMAPBOXGLSTYLECHANGE_P_H |