summaryrefslogtreecommitdiff
path: root/src/imports
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-10-11 13:36:06 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-25 13:25:38 +0000
commita66306d3d8eab810b769a536095dbfa2a0eb6ce2 (patch)
tree61843e32114732b10c238d25535c89c95911d0c1 /src/imports
parentbe13464a488ccc2837b0c178ff16086be341e570 (diff)
downloadqtlocation-a66306d3d8eab810b769a536095dbfa2a0eb6ce2.tar.gz
Add rotation and tilt controls to QDeclarativeGeoMap
QDeclarativeGeoMap currently does not provide any mean to set bearing and tilt into qgeocameradata. It has been not a problem since QGeoTiledMap and sons did not support it. External renderers however support it, so this patch adds QML api calls to control these parameters, and adapt the existing logic to take them into consideration in camera-related calls, as well as in the afterViewportChange handlers of the Map Items. This patch also sligthly modifies the QML api to make the handling of all the bounded camera property more homogeneous. Minimum and maximum zoom levels prior plugin initialization aren't -1 anymore, but are some valid lower and upper bounds for this property, that is 0 and 30. in this way all the 2 bounded properties (zoomLevel and tilt) behave the same, in that they can be freely set before plugin initialization, within reasonable predefined bounds, and, after that, they may be clamped depending on the actual plugin capabilities. Autotests for the QML part of the API included. Change-Id: I9d09e32698a7330388e465e8ea7523ee39577d34 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/location/qdeclarativecirclemapitem.cpp12
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp191
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h25
-rw-r--r--src/imports/location/qdeclarativegeoserviceprovider.cpp3
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem.cpp12
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem.cpp11
-rw-r--r--src/imports/location/qdeclarativerectanglemapitem.cpp12
-rw-r--r--src/imports/location/qquickgeomapgesturearea.cpp1
-rw-r--r--src/imports/location/qquickgeomapgesturearea_p.h2
9 files changed, 197 insertions, 72 deletions
diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp
index e107091c..7961305f 100644
--- a/src/imports/location/qdeclarativecirclemapitem.cpp
+++ b/src/imports/location/qdeclarativecirclemapitem.cpp
@@ -518,17 +518,7 @@ void QDeclarativeCircleMapItem::afterViewportChanged(const QGeoMapViewportChange
return;
// if the scene is tilted, we must regenerate our geometry every frame
- if (map()->cameraCapabilities().supportsTilting()
- && (event.cameraData.tilt() > 0.1
- || event.cameraData.tilt() < -0.1)) {
- geometry_.markSourceDirty();
- borderGeometry_.markSourceDirty();
- }
-
- // if the scene is rolled, we must regen too
- if (map()->cameraCapabilities().supportsRolling()
- && (event.cameraData.roll() > 0.1
- || event.cameraData.roll() < -0.1)) {
+ if ((event.cameraData.tilt() > 0.0 || event.tiltChanged) && map()->cameraCapabilities().supportsTilting()) {
geometry_.markSourceDirty();
borderGeometry_.markSourceDirty();
}
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index d19f6929..fb5a2472 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -308,14 +308,35 @@ void QDeclarativeGeoMap::setError(QGeoServiceProvider::Error error, const QStrin
void QDeclarativeGeoMap::initialize()
{
- // try to keep center change signal in the end
+ // try to keep change signals in the end
bool centerHasChanged = false;
+ bool bearingHasChanged = false;
+ bool tiltHasChanged = false;
+ bool minTiltHasChanged = false;
+ bool maxTiltHasChanged = false;
+
+ QGeoCoordinate center = m_cameraData.center();
setMinimumZoomLevel(m_map->minimumZoom());
- // set latitude bundary check
- m_maximumViewportLatitude = m_map->maximumCenterLatitudeAtZoom(m_cameraData.zoomLevel());
- QGeoCoordinate center = m_cameraData.center();
+ double bearing = m_cameraData.bearing();
+ double tilt = m_cameraData.tilt();
+ if (m_map->cameraCapabilities().minimumTilt() != 0)
+ minTiltHasChanged = true;
+ if (m_map->cameraCapabilities().maximumTilt() != 89)
+ maxTiltHasChanged = true;
+ if (!m_map->cameraCapabilities().supportsBearing() && bearing != 0.0) {
+ m_cameraData.setBearing(0);
+ bearingHasChanged = true;
+ }
+ if (!m_map->cameraCapabilities().supportsTilting() && tilt != 0.0) {
+ m_cameraData.setTilt(0);
+ tiltHasChanged = true;
+ }
+
+ // set latitude boundary check
+ m_maximumViewportLatitude = m_map->maximumCenterLatitudeAtZoom(m_cameraData);
+
center.setLatitude(qBound(-m_maximumViewportLatitude, center.latitude(), m_maximumViewportLatitude));
if (center != m_cameraData.center()) {
@@ -329,6 +350,18 @@ void QDeclarativeGeoMap::initialize()
if (centerHasChanged)
emit centerChanged(m_cameraData.center());
+
+ if (bearingHasChanged)
+ emit bearingChanged(m_cameraData.bearing());
+
+ if (tiltHasChanged)
+ emit tiltChanged(m_cameraData.tilt());
+
+ if (minTiltHasChanged)
+ emit minimumTiltChanged(m_map->cameraCapabilities().minimumTilt());
+
+ if (maxTiltHasChanged)
+ emit maximumTiltChanged(m_map->cameraCapabilities().maximumTilt());
}
/*!
@@ -565,9 +598,8 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
//The zoom level limits are only restricted by the plugins values, if the user has set a more
//strict zoom level limit before initialization nothing is done here.
//minimum zoom level might be changed to limit gray bundaries
-
- if (m_gestureArea->maximumZoomLevel() < 0
- || m_mappingManager->cameraCapabilities().maximumZoomLevelAt256() < m_gestureArea->maximumZoomLevel())
+ //This code assumes that plugins' maximum zoom level will never exceed 30.0
+ if (m_mappingManager->cameraCapabilities().maximumZoomLevelAt256() < m_gestureArea->maximumZoomLevel())
setMaximumZoomLevel(m_mappingManager->cameraCapabilities().maximumZoomLevelAt256());
if (m_mappingManager->cameraCapabilities().minimumZoomLevelAt256() > m_gestureArea->minimumZoomLevel())
@@ -638,7 +670,6 @@ void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel)
qreal oldMinimumZoomLevel = this->minimumZoomLevel();
if (m_map) {
-
minimumZoomLevel = qBound(qreal(m_map->cameraCapabilities().minimumZoomLevelAt256()), minimumZoomLevel, maximumZoomLevel());
double minimumViewportZoomLevel = m_map->minimumZoom();
if (minimumZoomLevel < minimumViewportZoomLevel)
@@ -666,17 +697,12 @@ void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel)
defined by the plugin used, to prevent the map from being smaller than the
viewport in either dimension.
- If a plugin supporting mapping is not set, -1.0 is returned.
+ If a plugin supporting mapping is not set, 0.0 is returned.
*/
qreal QDeclarativeGeoMap::minimumZoomLevel() const
{
- if (m_gestureArea->minimumZoomLevel() != -1)
- return m_gestureArea->minimumZoomLevel();
- else if (m_map)
- return m_map->cameraCapabilities().minimumZoomLevelAt256();
- else
- return -1.0;
+ return m_gestureArea->minimumZoomLevel();
}
/*!
@@ -708,17 +734,12 @@ void QDeclarativeGeoMap::setMaximumZoomLevel(qreal maximumZoomLevel)
This property holds the maximum valid zoom level for the map.
The maximum zoom level is defined by the \l plugin used.
- If a plugin supporting mapping is not set, -1.0 is returned.
+ If a plugin supporting mapping is not set, 30.0 is returned.
*/
qreal QDeclarativeGeoMap::maximumZoomLevel() const
{
- if (m_gestureArea->maximumZoomLevel() != -1)
- return m_gestureArea->maximumZoomLevel();
- else if (m_map)
- return m_map->cameraCapabilities().minimumZoomLevelAt256();
- else
- return -1.0;
+ return m_gestureArea->maximumZoomLevel();
}
/*!
@@ -734,12 +755,12 @@ void QDeclarativeGeoMap::setZoomLevel(qreal zoomLevel)
if (m_cameraData.zoomLevel() == zoomLevel || zoomLevel < 0)
return;
- //small optiomatization to avoid double setCameraData
+ //small optimization to avoid double setCameraData
bool centerHasChanged = false;
if (m_initialized) {
m_cameraData.setZoomLevel(qBound(minimumZoomLevel(), zoomLevel, maximumZoomLevel()));
- m_maximumViewportLatitude = m_map->maximumCenterLatitudeAtZoom(m_cameraData.zoomLevel());
+ m_maximumViewportLatitude = m_map->maximumCenterLatitudeAtZoom(m_cameraData);
QGeoCoordinate coord = m_cameraData.center();
coord.setLatitude(qBound(-m_maximumViewportLatitude, coord.latitude(), m_maximumViewportLatitude));
if (coord != m_cameraData.center()) {
@@ -764,6 +785,126 @@ qreal QDeclarativeGeoMap::zoomLevel() const
}
/*!
+ \qmlproperty real QtLocation::Map::bearing
+
+ This property holds the bearing for the map.
+ The default value is 0.
+ If the Plugin used for the Map supports bearing, the valid range for this value is between 0 and 360.
+ If the Plugin used for the Map does not support bearing, changing this property will have no effect.
+
+ \since Qt Location 5.9
+*/
+void QDeclarativeGeoMap::setBearing(qreal bearing)
+{
+ bearing = std::fmod(bearing, qreal(360.0));
+ if (m_map && !m_map->cameraCapabilities().supportsBearing())
+ bearing = 0.0;
+ if (m_cameraData.bearing() == bearing || bearing < 0.0)
+ return;
+
+ m_cameraData.setBearing(bearing);
+ if (m_map)
+ m_map->setCameraData(m_cameraData);
+ emit bearingChanged(bearing);
+}
+
+qreal QDeclarativeGeoMap::bearing() const
+{
+ return m_cameraData.bearing();
+}
+
+/*!
+ \qmlproperty real QtLocation::Map::tilt
+
+ This property holds the tilt for the map.
+ The default value is 0.
+ If the Plugin used for the Map supports tilt, the valid range for this value is
+ [ plugin.minimumTilt, plugin.maximumTilt ].
+ If the Plugin used for the Map does not support tilting, changing this property will have no effect.
+
+ \since Qt Location 5.9
+*/
+void QDeclarativeGeoMap::setTilt(qreal tilt)
+{
+ tilt = qBound(minimumTilt(), tilt, maximumTilt());
+ if (m_cameraData.tilt() == tilt)
+ return;
+
+ m_cameraData.setTilt(tilt);
+ if (m_map)
+ m_map->setCameraData(m_cameraData);
+ emit tiltChanged(tilt);
+}
+
+qreal QDeclarativeGeoMap::tilt() const
+{
+ return m_cameraData.tilt();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::bearingSupported
+
+ This property indicates if the Map supports bearing.
+ If the plugin property of the map is not set, or the plugin does not support mapping, this property is false.
+
+ \since Qt Location 5.9
+*/
+bool QDeclarativeGeoMap::isBearingSupported() const
+{
+ if (!m_map)
+ return false;
+ return m_map->cameraCapabilities().supportsBearing();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::tiltingSupported
+
+ This property indicates if the Map supports tilting.
+ If the plugin property of the map is not set, or the plugin does not support mapping, this property is false.
+
+ \since Qt Location 5.9
+*/
+bool QDeclarativeGeoMap::isTiltingSupported() const
+{
+ if (!m_map)
+ return false;
+ return m_map->cameraCapabilities().supportsTilting();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::minimumTilt
+
+ This property holds the minimum tilt that the map supports.
+ If the plugin property of the map is not set, or the plugin does not support mapping, this property is 0.
+
+ \since Qt Location 5.9
+*/
+qreal QDeclarativeGeoMap::minimumTilt() const
+{
+ if (!m_map || !m_map->cameraCapabilities().supportsTilting())
+ return 0.0;
+ return m_map->cameraCapabilities().minimumTilt();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::maximumTilt
+
+ This property holds the maximum tilt that the map supports.
+ If the plugin property of the map is not set, this property is 89.
+ If the plugin is set and it does not support mapping, this property is 0.
+
+ \since Qt Location 5.9
+*/
+qreal QDeclarativeGeoMap::maximumTilt() const
+{
+ if (!m_map)
+ return 89.0;
+ else if (!m_map->cameraCapabilities().supportsTilting())
+ return 0.0;
+ return m_map->cameraCapabilities().maximumTilt();
+}
+
+/*!
\qmlproperty coordinate QtLocation::Map::center
This property holds the coordinate which occupies the center of the
@@ -1433,7 +1574,7 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF
setMinimumZoomLevel(m_map->minimumZoom());
// Update the center latitudinal threshold
- double maximumCenterLatitudeAtZoom = m_map->maximumCenterLatitudeAtZoom(m_cameraData.zoomLevel());
+ double maximumCenterLatitudeAtZoom = m_map->maximumCenterLatitudeAtZoom(m_cameraData);
if (maximumCenterLatitudeAtZoom != m_maximumViewportLatitude) {
m_maximumViewportLatitude = maximumCenterLatitudeAtZoom;
QGeoCoordinate coord = m_cameraData.center();
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index e0940f97..71538e42 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -74,6 +74,14 @@ class QDeclarativeGeoMap : public QQuickItem
Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged)
Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel WRITE setMaximumZoomLevel NOTIFY maximumZoomLevelChanged)
Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
+
+ Q_PROPERTY(bool bearingSupported READ isBearingSupported NOTIFY bearingSupportChanged)
+ Q_PROPERTY(bool tiltingSupported READ isTiltingSupported NOTIFY tiltingSupportChanged)
+ Q_PROPERTY(qreal minimumTilt READ minimumTilt NOTIFY minimumTiltChanged)
+ Q_PROPERTY(qreal maximumTilt READ maximumTilt NOTIFY maximumTiltChanged)
+ Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged)
+ Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged)
+
Q_PROPERTY(QDeclarativeGeoMapType *activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged)
Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged)
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
@@ -106,6 +114,17 @@ public:
void setZoomLevel(qreal zoomLevel);
qreal zoomLevel() const;
+ void setBearing(qreal bearing);
+ qreal bearing() const;
+
+ void setTilt(qreal tilt);
+ qreal tilt() const;
+
+ bool isBearingSupported() const;
+ bool isTiltingSupported() const;
+ qreal minimumTilt() const;
+ qreal maximumTilt() const;
+
void setCenter(const QGeoCoordinate &center);
QGeoCoordinate center() const;
@@ -157,6 +176,12 @@ Q_SIGNALS:
void copyrightLinkActivated(const QString &link);
void copyrightsVisibleChanged(bool visible);
void colorChanged(const QColor &color);
+ void bearingChanged(qreal bearing);
+ void tiltChanged(qreal tilt);
+ void bearingSupportChanged(bool bearingSupport);
+ void tiltingSupportChanged(bool tiltingSupport);
+ void minimumTiltChanged(qreal minimumTilt);
+ void maximumTiltChanged(qreal maximumTilt);
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE ;
diff --git a/src/imports/location/qdeclarativegeoserviceprovider.cpp b/src/imports/location/qdeclarativegeoserviceprovider.cpp
index 8ed6a7bf..994b4913 100644
--- a/src/imports/location/qdeclarativegeoserviceprovider.cpp
+++ b/src/imports/location/qdeclarativegeoserviceprovider.cpp
@@ -35,7 +35,6 @@
****************************************************************************/
#include "qdeclarativegeoserviceprovider_p.h"
-
#include <QtQml/QQmlInfo>
QT_BEGIN_NAMESPACE
@@ -421,7 +420,7 @@ void QDeclarativeGeoServiceProvider::setPreferred(const QStringList &val)
/*!
\qmlproperty bool Plugin::isAttached
- This property indicates if the Plugin is attached to another Plugin.
+ This property indicates if the Plugin item is attached to a geoservice provider plugin.
*/
bool QDeclarativeGeoServiceProvider::isAttached() const
{
diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp
index 0e11db79..2268c885 100644
--- a/src/imports/location/qdeclarativepolygonmapitem.cpp
+++ b/src/imports/location/qdeclarativepolygonmapitem.cpp
@@ -567,17 +567,7 @@ void QDeclarativePolygonMapItem::afterViewportChanged(const QGeoMapViewportChang
return;
// if the scene is tilted, we must regenerate our geometry every frame
- if (map()->cameraCapabilities().supportsTilting()
- && (event.cameraData.tilt() > 0.1
- || event.cameraData.tilt() < -0.1)) {
- geometry_.markSourceDirty();
- borderGeometry_.markSourceDirty();
- }
-
- // if the scene is rolled, we must regen too
- if (map()->cameraCapabilities().supportsRolling()
- && (event.cameraData.roll() > 0.1
- || event.cameraData.roll() < -0.1)) {
+ if ((event.cameraData.tilt() > 0.0 || event.tiltChanged) && map()->cameraCapabilities().supportsTilting()) {
geometry_.markSourceDirty();
borderGeometry_.markSourceDirty();
}
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp
index 5fe0535d..a31fcbad 100644
--- a/src/imports/location/qdeclarativepolylinemapitem.cpp
+++ b/src/imports/location/qdeclarativepolylinemapitem.cpp
@@ -873,16 +873,7 @@ void QDeclarativePolylineMapItem::afterViewportChanged(const QGeoMapViewportChan
return;
// if the scene is tilted, we must regenerate our geometry every frame
- if (map()->cameraCapabilities().supportsTilting()
- && (event.cameraData.tilt() > 0.1
- || event.cameraData.tilt() < -0.1)) {
- geometry_.markSourceDirty();
- }
-
- // if the scene is rolled, we must regen too
- if (map()->cameraCapabilities().supportsRolling()
- && (event.cameraData.roll() > 0.1
- || event.cameraData.roll() < -0.1)) {
+ if ((event.cameraData.tilt() > 0.0 || event.tiltChanged) && map()->cameraCapabilities().supportsTilting()) {
geometry_.markSourceDirty();
}
diff --git a/src/imports/location/qdeclarativerectanglemapitem.cpp b/src/imports/location/qdeclarativerectanglemapitem.cpp
index b91c4c08..a3b8db90 100644
--- a/src/imports/location/qdeclarativerectanglemapitem.cpp
+++ b/src/imports/location/qdeclarativerectanglemapitem.cpp
@@ -372,17 +372,7 @@ void QDeclarativeRectangleMapItem::afterViewportChanged(const QGeoMapViewportCha
return;
// if the scene is tilted, we must regenerate our geometry every frame
- if (map()->cameraCapabilities().supportsTilting()
- && (event.cameraData.tilt() > 0.1
- || event.cameraData.tilt() < -0.1)) {
- geometry_.markSourceDirty();
- borderGeometry_.markSourceDirty();
- }
-
- // if the scene is rolled, we must regen too
- if (map()->cameraCapabilities().supportsRolling()
- && (event.cameraData.roll() > 0.1
- || event.cameraData.roll() < -0.1)) {
+ if ((event.cameraData.tilt() > 0.0 || event.tiltChanged) && map()->cameraCapabilities().supportsTilting()) {
geometry_.markSourceDirty();
borderGeometry_.markSourceDirty();
}
diff --git a/src/imports/location/qquickgeomapgesturearea.cpp b/src/imports/location/qquickgeomapgesturearea.cpp
index 50709292..54c3019b 100644
--- a/src/imports/location/qquickgeomapgesturearea.cpp
+++ b/src/imports/location/qquickgeomapgesturearea.cpp
@@ -46,7 +46,6 @@
#include <QtQuick/QQuickWindow>
#include <QPropertyAnimation>
#include <QDebug>
-#include <QtPositioning/private/qwebmercator_p.h>
#include "math.h"
#include "qgeomap_p.h"
#include "qdoublevector2d_p.h"
diff --git a/src/imports/location/qquickgeomapgesturearea_p.h b/src/imports/location/qquickgeomapgesturearea_p.h
index 51c5cc1e..41d7706a 100644
--- a/src/imports/location/qquickgeomapgesturearea_p.h
+++ b/src/imports/location/qquickgeomapgesturearea_p.h
@@ -242,7 +242,7 @@ private:
bool m_enabled;
struct Zoom
{
- Zoom() : m_minimum(-1.0), m_maximum(20.0), m_start(0.0), m_previous(0.0),
+ Zoom() : m_minimum(0.0), m_maximum(30.0), m_start(0.0), m_previous(0.0),
maximumChange(4.0) {}
qreal m_minimum;
qreal m_maximum;