summaryrefslogtreecommitdiff
path: root/src/imports
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-01-23 18:31:33 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-26 11:22:18 +0000
commit05c4125cd65e34d64befeef4c4c2aba1f3b86665 (patch)
tree5780220c30882f3097d1e6f9a1e2eb779105b56f /src/imports
parenta66306d3d8eab810b769a536095dbfa2a0eb6ce2 (diff)
downloadqtlocation-05c4125cd65e34d64befeef4c4c2aba1f3b86665.tar.gz
Add field of view support to QtLocation mapping
This patch introduces a new camera parameter, field of view, used in QGeoCameraCapabilities, QGeoCameraData and QDeclarativeGeoMap. This is necessary as now QtLocation supports map tilting, and different QGeoMap implementations support different ranges for the field of view of the camera. Through this API it becomes possible to query the supported range and current value, and to stack Map elements using different plugins while keeping a consistent camera projection across all of them. Change-Id: Ie061142bea090ec223d842efbe7924f924430496 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp82
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h11
2 files changed, 93 insertions, 0 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index fb5a2472..7182bb21 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -312,8 +312,11 @@ void QDeclarativeGeoMap::initialize()
bool centerHasChanged = false;
bool bearingHasChanged = false;
bool tiltHasChanged = false;
+ bool fovHasChanged = false;
bool minTiltHasChanged = false;
bool maxTiltHasChanged = false;
+ bool minFovHasChanged = false;
+ bool maxFovHasChanged = false;
QGeoCoordinate center = m_cameraData.center();
@@ -321,6 +324,11 @@ void QDeclarativeGeoMap::initialize()
double bearing = m_cameraData.bearing();
double tilt = m_cameraData.tilt();
+ double fov = m_cameraData.fieldOfView(); // Must be 45.0
+ if (m_map->cameraCapabilities().minimumFieldOfView() != 1)
+ minFovHasChanged = true;
+ if (m_map->cameraCapabilities().maximumFieldOfView() != 179)
+ maxFovHasChanged = true;
if (m_map->cameraCapabilities().minimumTilt() != 0)
minTiltHasChanged = true;
if (m_map->cameraCapabilities().maximumTilt() != 89)
@@ -334,6 +342,12 @@ void QDeclarativeGeoMap::initialize()
tiltHasChanged = true;
}
+ m_cameraData.setFieldOfView(qBound(m_map->cameraCapabilities().minimumFieldOfView(),
+ fov,
+ m_map->cameraCapabilities().maximumFieldOfView()));
+ if (fov != m_cameraData.fieldOfView())
+ fovHasChanged = true;
+
// set latitude boundary check
m_maximumViewportLatitude = m_map->maximumCenterLatitudeAtZoom(m_cameraData);
@@ -357,11 +371,20 @@ void QDeclarativeGeoMap::initialize()
if (tiltHasChanged)
emit tiltChanged(m_cameraData.tilt());
+ if (fovHasChanged)
+ emit fieldOfViewChanged(m_cameraData.fieldOfView());
+
if (minTiltHasChanged)
emit minimumTiltChanged(m_map->cameraCapabilities().minimumTilt());
if (maxTiltHasChanged)
emit maximumTiltChanged(m_map->cameraCapabilities().maximumTilt());
+
+ if (minFovHasChanged)
+ emit minimumFieldOfViewChanged(m_map->cameraCapabilities().minimumFieldOfView());
+
+ if (maxFovHasChanged)
+ emit maximumFieldOfViewChanged(m_map->cameraCapabilities().maximumFieldOfView());
}
/*!
@@ -842,6 +865,65 @@ qreal QDeclarativeGeoMap::tilt() const
}
/*!
+ \qmlproperty real QtLocation::Map::fieldOfView
+
+ This property holds the field of view of the camera used to look at the map, in degrees.
+ If the plugin property of the map is not set, or the plugin does not support mapping, the value is 45 degrees.
+
+ Note that changing this value implicitly changes also the distance between the camera and the map,
+ so that, at a tilting angle of 0 degrees, the resulting image is identical for any value used for this property.
+
+ For more information about this parameter, consult the Wikipedia articles about \l {https://en.wikipedia.org/wiki/Field_of_view} {Field of view} and
+ \l {https://en.wikipedia.org/wiki/Angle_of_view} {Angle of view}.
+
+ \since Qt Location 5.9
+*/
+void QDeclarativeGeoMap::setFieldOfView(qreal fieldOfView)
+{
+ fieldOfView = qBound(minimumFieldOfView(), fieldOfView, maximumFieldOfView());
+ if (m_cameraData.fieldOfView() == fieldOfView)
+ return;
+
+ m_cameraData.setFieldOfView(fieldOfView);
+ if (m_map)
+ m_map->setCameraData(m_cameraData);
+ emit fieldOfViewChanged(fieldOfView);
+}
+
+qreal QDeclarativeGeoMap::fieldOfView() const
+{
+ return m_cameraData.fieldOfView();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::minimumFieldOfView
+ This property holds the minimum field of view that the map supports.
+ If the plugin property of the map is not set, or the plugin does not support mapping, this property is 1.
+
+ \since Qt Location 5.9
+*/
+qreal QDeclarativeGeoMap::minimumFieldOfView() const
+{
+ if (!m_map)
+ return 1;
+ return m_map->cameraCapabilities().minimumFieldOfView();
+}
+
+/*!
+ \qmlproperty bool QtLocation::Map::maximumFieldOfView
+ This property holds the maximum field of view that the map supports.
+ If the plugin property of the map is not set, or the plugin does not support mapping, this property is 179.
+
+ \since Qt Location 5.9
+*/
+qreal QDeclarativeGeoMap::maximumFieldOfView() const
+{
+ if (!m_map)
+ return 179;
+ return m_map->cameraCapabilities().maximumFieldOfView();
+}
+
+/*!
\qmlproperty bool QtLocation::Map::bearingSupported
This property indicates if the Map supports bearing.
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 71538e42..b85daf1a 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -81,6 +81,9 @@ class QDeclarativeGeoMap : public QQuickItem
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(qreal fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
+ Q_PROPERTY(qreal minimumFieldOfView READ minimumFieldOfView NOTIFY minimumFieldOfViewChanged)
+ Q_PROPERTY(qreal maximumFieldOfView READ maximumFieldOfView NOTIFY minimumFieldOfViewChanged)
Q_PROPERTY(QDeclarativeGeoMapType *activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged)
Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged)
@@ -120,6 +123,11 @@ public:
void setTilt(qreal tilt);
qreal tilt() const;
+ void setFieldOfView(qreal fieldOfView);
+ qreal fieldOfView() const;
+ qreal minimumFieldOfView() const;
+ qreal maximumFieldOfView() const;
+
bool isBearingSupported() const;
bool isTiltingSupported() const;
qreal minimumTilt() const;
@@ -178,10 +186,13 @@ Q_SIGNALS:
void colorChanged(const QColor &color);
void bearingChanged(qreal bearing);
void tiltChanged(qreal tilt);
+ void fieldOfViewChanged(qreal fieldOfView);
void bearingSupportChanged(bool bearingSupport);
void tiltingSupportChanged(bool tiltingSupport);
void minimumTiltChanged(qreal minimumTilt);
void maximumTiltChanged(qreal maximumTilt);
+ void minimumFieldOfViewChanged(qreal minimumFieldOfView);
+ void maximumFieldOfViewChanged(qreal maximumFieldOfView);
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE ;