summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-01-30 20:59:59 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2019-03-11 12:10:54 +0000
commita52dae6a79c1c19ee2391037cfdc6d557381bb88 (patch)
tree0308df23ee4097132a8dc34a05ea326bb9adda58 /src/plugins
parentb1f6028c2aba51b898ce380f7b584ae603a06382 (diff)
downloadqtlocation-a52dae6a79c1c19ee2391037cfdc6d557381bb88.tar.gz
Introduce Qt.labs.location QtLocationLabs singleton type
This singleton is meant to offer tech-preview map-related API. It starts with a mapObjectsAt invokable, that can be used to probe MapObjects at a specific coordinate of a map. Reference implementation for Q*ObjectQSG, based on QGeoShape::contains, included. Change-Id: Ief692eb5a43115ca02d4642c82023d1b2e217400 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp39
-rw-r--r--src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.h1
2 files changed, 40 insertions, 0 deletions
diff --git a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp
index f6520484..1ebad08d 100644
--- a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp
+++ b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.cpp
@@ -65,6 +65,7 @@ public:
virtual QList<QGeoMapObject *> mapObjects() const override;
void removeMapObject(QGeoMapObject *obj);
void updateMapObjects(QSGNode *root, QQuickWindow *window);
+ QList<QObject *>mapObjectsAt(const QGeoCoordinate &coordinate) const;
QGeoMapObjectQSGSupport m_qsgSupport;
#endif
@@ -137,6 +138,16 @@ void QGeoMapItemsOverlay::removeMapObject(QGeoMapObject *obj)
#endif
}
+QList<QObject *> QGeoMapItemsOverlay::mapObjectsAt(const QGeoCoordinate &coordinate) const
+{
+#ifdef LOCATIONLABS
+ Q_D(const QGeoMapItemsOverlay);
+ return d->mapObjectsAt(coordinate);
+#else
+ return QGeoMap::mapObjectsAt(coordinate);
+#endif
+}
+
void QGeoMapItemsOverlayPrivate::setVisibleArea(const QRectF &visibleArea)
{
Q_Q(QGeoMapItemsOverlay);
@@ -185,6 +196,34 @@ void QGeoMapItemsOverlayPrivate::updateMapObjects(QSGNode *root, QQuickWindow *w
{
m_qsgSupport.updateMapObjects(root, window);
}
+
+QList<QObject *> QGeoMapItemsOverlayPrivate::mapObjectsAt(const QGeoCoordinate &coordinate) const
+{
+ // ToDo: use a space partitioning strategy
+ QList<QObject *> res;
+ for (const auto o: mapObjects()) {
+ // explicitly handle lines
+ bool contains = false;
+ if (o->type() == QGeoMapObject::PolylineType ) {
+ QMapPolylineObject *mpo = static_cast<QMapPolylineObject *>(o);
+ qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate);
+ QGeoPath path = o->geoShape();
+ path.setWidth(mpp * mpo->border()->width());
+ contains = path.contains(coordinate);
+ } else if (o->type() == QGeoMapObject::RouteType) {
+ qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate);
+ QGeoPath path = o->geoShape();
+ path.setWidth(mpp * 4); // MapRouteObjectQSG has a hardcoded 4 pixels width;
+ contains = path.contains(coordinate);
+ } else {
+ contains = o->geoShape().contains(coordinate);
+ }
+
+ if (contains)
+ res.append(o);
+ }
+ return res;
+}
#endif
void QGeoMapItemsOverlayPrivate::updateObjectsGeometry()
diff --git a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.h b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.h
index 1594ffb3..c287345c 100644
--- a/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.h
+++ b/src/plugins/geoservices/itemsoverlay/qgeomapitemsoverlay.h
@@ -56,6 +56,7 @@ public:
QGeoMap::Capabilities capabilities() const override;
bool createMapObjectImplementation(QGeoMapObject *obj) override;
void removeMapObject(QGeoMapObject *obj) override;
+ QList<QObject *> mapObjectsAt(const QGeoCoordinate &coordinate) const override;
protected:
QSGNode *updateSceneGraph(QSGNode *node, QQuickWindow *window) override;