summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-04-09 13:47:10 +0300
committerBruno de Oliveira Abinader <brunoabinader@gmail.com>2018-04-09 11:38:48 +0000
commit886776c496d8902b56d47f7e5253d2e3a540b1f5 (patch)
tree20f6adf06a1d4c040abf60b7ec87406b5f719ad7
parent730932ab648e4d455b4bc84fb05f9a78ce1576be (diff)
downloadqtlocation-886776c496d8902b56d47f7e5253d2e3a540b1f5.tar.gz
mapboxgl: Specify map margins in pixels via 'margins' map parameter
Change-Id: Ifa95aea264dc1807b90d7619a0946bf291df16ce Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
-rw-r--r--src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp41
-rw-r--r--src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h13
2 files changed, 53 insertions, 1 deletions
diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
index 4835c201..11421e03 100644
--- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
+++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
@@ -176,7 +176,8 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapParamete
{
static const QStringList acceptedParameterTypes = QStringList()
<< QStringLiteral("paint") << QStringLiteral("layout") << QStringLiteral("filter")
- << QStringLiteral("layer") << QStringLiteral("source") << QStringLiteral("image");
+ << QStringLiteral("layer") << QStringLiteral("source") << QStringLiteral("image")
+ << QStringLiteral("margins");
QList<QSharedPointer<QMapboxGLStyleChange>> changes;
@@ -202,6 +203,9 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapParamete
case 5: // image
changes << QMapboxGLStyleAddImage::fromMapParameter(param);
break;
+ case 6: // margins
+ changes << QMapboxGLMapMargins::fromMapParameter(param);
+ break;
}
return changes;
@@ -628,3 +632,38 @@ 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 fd5b9af4..38aa87f8 100644
--- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h
+++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h
@@ -190,4 +190,17 @@ 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