summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp136
1 files changed, 126 insertions, 10 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 2ed482e3..34885f54 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -46,6 +46,7 @@
#include <QtPositioning/QGeoCircle>
#include <QtPositioning/QGeoRectangle>
#include <QtPositioning/QGeoPath>
+#include <QtPositioning/QGeoPolygon>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGRectangleNode>
#include <QtQuick/private/qquickwindow_p.h>
@@ -190,7 +191,11 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
- tr("No Map"), false, false, 0, QByteArrayLiteral("")), this);
+ tr("No Map"),
+ false, false,
+ 0,
+ QByteArrayLiteral(""),
+ QGeoCameraCapabilities()), this);
m_cameraData.setCenter(QGeoCoordinate(51.5073,-0.1277)); //London city center
m_cameraData.setZoomLevel(8.0);
@@ -218,8 +223,18 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap()
m_map->clearMapItems();
}
- if (!m_mapViews.isEmpty())
- qDeleteAll(m_mapViews);
+ // This forces the destruction of the associated items now, not when QObject destructor is called, at which point
+ // QDeclarativeGeoMap is long gone
+ if (!m_mapViews.isEmpty()) {
+ for (QDeclarativeGeoMapItemView *v : qAsConst(m_mapViews)) {
+ if (!v)
+ continue;
+ if (v->parent() == this)
+ delete v;
+ else
+ v->removeInstantiatedItems();
+ }
+ }
// remove any map items associations
for (int i = 0; i < m_mapItems.count(); ++i) {
if (m_mapItems.at(i))
@@ -752,7 +767,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
} else {
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
- tr("No Map"), false, false, 0, QByteArrayLiteral("")), this);
+ tr("No Map"),
+ false,
+ false,
+ 0,
+ QByteArrayLiteral(""),
+ QGeoCameraCapabilities()), this);
}
}
@@ -1322,22 +1342,22 @@ QGeoShape QDeclarativeGeoMap::visibleRegion() const
return m_visibleRegion;
const QList<QDoubleVector2D> &visibleRegion = m_map->geoProjection().visibleRegion();
- QGeoPath path;
+ QGeoPolygon poly;
for (int i = 0; i < visibleRegion.size(); ++i) {
const QDoubleVector2D &c = visibleRegion.at(i);
// If a segment spans more than half of the map longitudinally, split in 2.
if (i && qAbs(visibleRegion.at(i-1).x() - c.x()) >= 0.5) { // This assumes a segment is never >= 1.0 (whole map span)
QDoubleVector2D extraPoint = (visibleRegion.at(i-1) + c) * 0.5;
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
}
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c));
}
if (visibleRegion.size() >= 2 && qAbs(visibleRegion.last().x() - visibleRegion.first().x()) >= 0.5) {
QDoubleVector2D extraPoint = (visibleRegion.last() + visibleRegion.first()) * 0.5;
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
}
- return path.boundingGeoRectangle();
+ return poly;
}
/*!
@@ -1454,6 +1474,61 @@ QQmlListProperty<QDeclarativeGeoMapType> QDeclarativeGeoMap::supportedMapTypes()
}
/*!
+ \qmlmethod void QtLocation::Map::setBearing(real bearing, coordinate coordinate)
+
+ Sets the bearing for the map to \a bearing, rotating it around \a coordinate.
+ If the Plugin used for the Map supports bearing, the valid range for \a bearing is between 0 and 360.
+ If the Plugin used for the Map does not support bearing, or if the map is tilted and \a coordinate happens
+ to be behind the camera, or if the map is not ready (see \l mapReady), calling this method will have no effect.
+
+ The release of this API with Qt 5.10 is a Technology Preview.
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::setBearing(qreal bearing, const QGeoCoordinate &coordinate)
+{
+ if (!m_map)
+ return;
+
+ const QDoubleVector2D coordWrapped = m_map->geoProjection().geoToWrappedMapProjection(coordinate);
+ if (!m_map->geoProjection().isProjectable(coordWrapped))
+ return;
+
+ const QPointF rotationPoint = m_map->geoProjection().wrappedMapProjectionToItemPosition(coordWrapped).toPointF();
+
+ // First set bearing
+ setBearing(bearing);
+ // then reanchor
+ setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, rotationPoint));
+}
+
+/*!
+ \qmlmethod void QtLocation::Map::alignCoordinateToPoint(coordinate coordinate, QPointF point)
+
+ Aligns \a coordinate to \a point.
+ This method effectively extends the functionality offered by the \l center qml property, allowing
+ to align a coordinate to point of the Map element other than its center.
+ This is useful in those applications where the center of the scene (e.g., a cursor) is not to be
+ placed exactly in the center of the map.
+
+ If the map is tilted, and \a coordinate happens to be behind the camera, or if the map is not ready
+ (see \l mapReady), calling this method will have no effect.
+
+ The release of this API with Qt 5.10 is a Technology Preview.
+
+ \sa center
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point)
+{
+ if (!m_map)
+ return;
+
+ setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, point));
+}
+
+/*!
\qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort)
Returns the coordinate which corresponds to the \a position relative to the map item.
@@ -1896,6 +1971,47 @@ void QDeclarativeGeoMap::removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGro
}
/*!
+ \qmlmethod void QtLocation::Map::removeMapItemView(MapItemView itemView)
+
+ Removes \a itemView and the items instantiated by it from the Map.
+
+ \sa MapItemView, addMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::removeMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_ != this) // can't remove a view that is already added to another map
+ return;
+
+ itemView->removeInstantiatedItems();
+ itemView->map_ = 0;
+ // it can be removed from the list at this point, since no operations that require a Map have to be done
+ // anymore on destruction.
+ m_mapViews.removeOne(itemView);
+}
+
+/*!
+ \qmlmethod void QtLocation::Map::addMapItemView(MapItemView itemView)
+
+ Adds \a itemView to the Map.
+
+ \sa MapItemView, removeMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::addMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_) // can't add a view twice
+ return;
+
+ // Not appending it to m_mapViews because it seems unnecessary even if the
+ // itemView is a child of this (in which case it would be destroyed
+ m_mapViews.append(itemView);
+ setupMapView(itemView);
+}
+
+/*!
\qmlproperty MapType QtLocation::Map::activeMapType
\brief Access to the currently active \l{MapType}{map type}.
@@ -2155,7 +2271,7 @@ bool QDeclarativeGeoMap::sendTouchEvent(QTouchEvent *event)
auto touchPointGrabberItem = [touchDevice, windowPriv](const QTouchEvent::TouchPoint &point) -> QQuickItem* {
if (QQuickEventPoint *eventPointer = windowPriv->pointerEventInstance(touchDevice)->pointById(point.id()))
- return eventPointer->grabber();
+ return eventPointer->grabberItem();
return nullptr;
};