summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp188
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h9
-rw-r--r--src/location/maps/qgeocameracapabilities.cpp29
-rw-r--r--src/location/maps/qgeocameracapabilities_p.h3
-rw-r--r--src/location/maps/qgeomap.cpp30
-rw-r--r--src/location/maps/qgeomap_p.h2
-rw-r--r--src/location/maps/qgeomap_p_p.h5
-rw-r--r--src/location/maps/qgeomappingmanager.cpp5
-rw-r--r--src/location/maps/qgeomappingmanager_p.h4
-rw-r--r--src/location/maps/qgeomappingmanagerengine.cpp3
-rw-r--r--src/location/maps/qgeomappingmanagerengine_p.h3
-rw-r--r--src/location/maps/qgeotiledmap.cpp31
-rw-r--r--src/location/maps/qgeotiledmap_p_p.h2
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmaposm.cpp3
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp26
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h1
-rw-r--r--src/plugins/geoservices/osm/qgeotileproviderosm.cpp21
-rw-r--r--src/plugins/geoservices/osm/qgeotileproviderosm.h8
-rw-r--r--tests/auto/declarative_ui/tst_map.qml41
-rw-r--r--tests/auto/declarative_ui/tst_map_maptype.qml94
-rw-r--r--tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h22
-rw-r--r--tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp80
22 files changed, 496 insertions, 114 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 65828581..e4a707ab 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -174,7 +174,9 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_pendingFitViewport(false),
m_copyrightsVisible(true),
m_maximumViewportLatitude(0.0),
- m_initialized(false)
+ m_initialized(false),
+ m_userMinimumZoomLevel(qQNaN()),
+ m_userMaximumZoomLevel(qQNaN())
{
setAcceptHoverEvents(false);
setAcceptedMouseButtons(Qt::LeftButton);
@@ -188,6 +190,16 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
tr("No Map"), false, false, 0), this);
m_cameraData.setCenter(QGeoCoordinate(51.5073,-0.1277)); //London city center
m_cameraData.setZoomLevel(8.0);
+
+ m_cameraCapabilities.setTileSize(256);
+ m_cameraCapabilities.setSupportsBearing(true);
+ m_cameraCapabilities.setSupportsTilting(true);
+ m_cameraCapabilities.setMinimumZoomLevel(0);
+ m_cameraCapabilities.setMaximumZoomLevel(30);
+ m_cameraCapabilities.setMinimumTilt(0);
+ m_cameraCapabilities.setMaximumTilt(89.5);
+ m_cameraCapabilities.setMinimumFieldOfView(1);
+ m_cameraCapabilities.setMaximumFieldOfView(179);
}
QDeclarativeGeoMap::~QDeclarativeGeoMap()
@@ -335,6 +347,10 @@ void QDeclarativeGeoMap::setError(QGeoServiceProvider::Error error, const QStrin
emit errorChanged();
}
+/*!
+ \internal
+ Called when the mapping manager is initialized AND the declarative element has a valid size > 0
+*/
void QDeclarativeGeoMap::initialize()
{
// try to keep change signals in the end
@@ -342,38 +358,30 @@ void QDeclarativeGeoMap::initialize()
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();
- setMinimumZoomLevel(m_map->minimumZoom());
+ if (qIsNaN(m_userMinimumZoomLevel))
+ setMinimumZoomLevel(m_map->minimumZoom(), false);
+ else
+ setMinimumZoomLevel(qMax<qreal>(m_map->minimumZoom(), m_userMinimumZoomLevel), false);
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)
- maxTiltHasChanged = true;
- if (!m_map->cameraCapabilities().supportsBearing() && bearing != 0.0) {
+
+ if (!m_cameraCapabilities.supportsBearing() && bearing != 0.0) {
m_cameraData.setBearing(0);
bearingHasChanged = true;
}
- if (!m_map->cameraCapabilities().supportsTilting() && tilt != 0.0) {
+ if (!m_cameraCapabilities.supportsTilting() && tilt != 0.0) {
m_cameraData.setTilt(0);
tiltHasChanged = true;
}
- m_cameraData.setFieldOfView(qBound(m_map->cameraCapabilities().minimumFieldOfView(),
+ m_cameraData.setFieldOfView(qBound(m_cameraCapabilities.minimumFieldOfView(),
fov,
- m_map->cameraCapabilities().maximumFieldOfView()));
+ m_cameraCapabilities.maximumFieldOfView()));
if (fov != m_cameraData.fieldOfView())
fovHasChanged = true;
@@ -402,18 +410,6 @@ void QDeclarativeGeoMap::initialize()
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());
}
/*!
@@ -631,6 +627,75 @@ void QDeclarativeGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plugin)
/*!
\internal
+*/
+void QDeclarativeGeoMap::onCameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities)
+{
+ if (m_map->cameraCapabilities() == oldCameraCapabilities)
+ return;
+ m_cameraCapabilities = m_map->cameraCapabilities();
+
+ bool minTiltHasChanged = false;
+ bool maxTiltHasChanged = false;
+ bool minFovHasChanged = false;
+ bool maxFovHasChanged = false;
+
+ if (m_cameraCapabilities.minimumFieldOfView() != oldCameraCapabilities.minimumFieldOfView())
+ minFovHasChanged = true;
+ if (m_cameraCapabilities.maximumFieldOfView() != oldCameraCapabilities.maximumFieldOfView())
+ maxFovHasChanged = true;
+ if (m_cameraCapabilities.minimumTilt() != oldCameraCapabilities.minimumTilt())
+ minTiltHasChanged = true;
+ if (m_cameraCapabilities.maximumTilt() != oldCameraCapabilities.maximumTilt())
+ maxTiltHasChanged = true;
+
+ //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
+ //This code assumes that plugins' maximum zoom level will never exceed 30.0
+ if (m_cameraCapabilities.maximumZoomLevelAt256() < m_gestureArea->maximumZoomLevel()) {
+ setMaximumZoomLevel(m_cameraCapabilities.maximumZoomLevelAt256(), false);
+ } else if (m_cameraCapabilities.maximumZoomLevelAt256() > m_gestureArea->maximumZoomLevel()) {
+ if (qIsNaN(m_userMaximumZoomLevel)) {
+ // If the user didn't set anything
+ setMaximumZoomLevel(m_cameraCapabilities.maximumZoomLevelAt256(), false);
+ } else if (m_userMaximumZoomLevel > m_gestureArea->maximumZoomLevel()) {
+ // Else if the user set something larger, but that got clamped by the previous camera caps
+ setMaximumZoomLevel(qMin<qreal>(m_cameraCapabilities.maximumZoomLevelAt256(),
+ m_userMaximumZoomLevel), false);
+ }
+ }
+
+ if (m_cameraCapabilities.minimumZoomLevelAt256() > m_gestureArea->minimumZoomLevel()) {
+ setMinimumZoomLevel(m_cameraCapabilities.minimumZoomLevelAt256(), false);
+ } else if (m_cameraCapabilities.minimumZoomLevelAt256() < m_gestureArea->minimumZoomLevel()) {
+ if (qIsNaN(m_userMinimumZoomLevel)) {
+ // If the user didn't set anything, trying to set the new caps.
+ setMinimumZoomLevel(m_cameraCapabilities.minimumZoomLevelAt256(), false);
+ } else if (m_userMinimumZoomLevel < m_gestureArea->minimumZoomLevel()) {
+ // Else if the user set a minimum, m_gestureArea->minimumZoomLevel() might be larger
+ // because of different reasons. Resetting it, as if it ends to be the same,
+ // no signal will be emitted.
+ setMinimumZoomLevel(qMax<qreal>(m_cameraCapabilities.minimumZoomLevelAt256(),
+ m_userMinimumZoomLevel), false);
+ }
+ }
+
+ if (minTiltHasChanged)
+ emit minimumTiltChanged(m_cameraCapabilities.minimumTilt());
+
+ if (maxTiltHasChanged)
+ emit maximumTiltChanged(m_cameraCapabilities.maximumTilt());
+
+ if (minFovHasChanged)
+ emit minimumFieldOfViewChanged(m_cameraCapabilities.minimumFieldOfView());
+
+ if (maxFovHasChanged)
+ emit maximumFieldOfViewChanged(m_cameraCapabilities.maximumFieldOfView());
+}
+
+
+/*!
+ \internal
this function will only be ever called once
*/
void QDeclarativeGeoMap::mappingManagerInitialized()
@@ -656,16 +721,8 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
m_map->setActiveMapType(m_activeMapType->mapType());
}
- //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
- //This code assumes that plugins' maximum zoom level will never exceed 30.0
- if (m_map->cameraCapabilities().maximumZoomLevelAt256() < m_gestureArea->maximumZoomLevel())
- setMaximumZoomLevel(m_map->cameraCapabilities().maximumZoomLevelAt256());
-
- if (m_map->cameraCapabilities().minimumZoomLevelAt256() > m_gestureArea->minimumZoomLevel())
- setMinimumZoomLevel(m_map->cameraCapabilities().minimumZoomLevelAt256());
-
+ // Update camera capabilities
+ onCameraCapabilitiesChanged(m_cameraCapabilities);
// Map tiles are built in this call. m_map->minimumZoom() becomes operational
// after this has been called at least once, after creation.
@@ -694,6 +751,7 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
connect(m_copyrights.data(), SIGNAL(linkActivated(QString)),
this, SIGNAL(copyrightLinkActivated(QString)));
connect(m_map, &QGeoMap::sgNodeChanged, this, &QQuickItem::update);
+ connect(m_map, &QGeoMap::cameraCapabilitiesChanged, this, &QDeclarativeGeoMap::onCameraCapabilitiesChanged);
// set visibility of copyright notice
m_copyrights->setCopyrightsVisible(m_copyrightsVisible);
@@ -748,18 +806,17 @@ QDeclarativeGeoServiceProvider *QDeclarativeGeoMap::plugin() const
The minimum zoom level will also have a lower bound dependent on the size
of the canvas, effectively preventing to display out of bounds areas.
*/
-void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel)
+void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel, bool userSet)
{
if (minimumZoomLevel >= 0) {
+ if (userSet)
+ m_userMinimumZoomLevel = 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)
- minimumZoomLevel = minimumViewportZoomLevel;
- }
+ minimumZoomLevel = qBound(qreal(m_cameraCapabilities.minimumZoomLevelAt256()), minimumZoomLevel, maximumZoomLevel());
+ if (m_map)
+ minimumZoomLevel = qMax<qreal>(minimumZoomLevel, m_map->minimumZoom());
m_gestureArea->setMinimumZoomLevel(minimumZoomLevel);
@@ -795,13 +852,14 @@ qreal QDeclarativeGeoMap::minimumZoomLevel() const
Sets the gesture areas maximum zoom level. If the camera capabilities
has been set this method honors the boundaries set by it.
*/
-void QDeclarativeGeoMap::setMaximumZoomLevel(qreal maximumZoomLevel)
+void QDeclarativeGeoMap::setMaximumZoomLevel(qreal maximumZoomLevel, bool userSet)
{
if (maximumZoomLevel >= 0) {
+ if (userSet)
+ m_userMaximumZoomLevel = maximumZoomLevel;
qreal oldMaximumZoomLevel = this->maximumZoomLevel();
- if (m_map)
- maximumZoomLevel = qBound(minimumZoomLevel(), maximumZoomLevel, qreal(m_map->cameraCapabilities().maximumZoomLevelAt256()));
+ maximumZoomLevel = qBound(minimumZoomLevel(), maximumZoomLevel, qreal(m_cameraCapabilities.maximumZoomLevelAt256()));
m_gestureArea->setMaximumZoomLevel(maximumZoomLevel);
@@ -882,7 +940,7 @@ void QDeclarativeGeoMap::setBearing(qreal bearing)
bearing = std::fmod(bearing, qreal(360.0));
if (bearing < 0.0)
bearing += 360.0;
- if (m_map && !m_map->cameraCapabilities().supportsBearing())
+ if (m_map && !m_cameraCapabilities.supportsBearing())
bearing = 0.0;
if (m_cameraData.bearing() == bearing || bearing < 0.0)
return;
@@ -966,9 +1024,7 @@ qreal QDeclarativeGeoMap::fieldOfView() const
*/
qreal QDeclarativeGeoMap::minimumFieldOfView() const
{
- if (!m_map)
- return 1;
- return m_map->cameraCapabilities().minimumFieldOfView();
+ return m_cameraCapabilities.minimumFieldOfView();
}
/*!
@@ -980,9 +1036,7 @@ qreal QDeclarativeGeoMap::minimumFieldOfView() const
*/
qreal QDeclarativeGeoMap::maximumFieldOfView() const
{
- if (!m_map)
- return 179;
- return m_map->cameraCapabilities().maximumFieldOfView();
+ return m_cameraCapabilities.maximumFieldOfView();
}
/*!
@@ -995,9 +1049,7 @@ qreal QDeclarativeGeoMap::maximumFieldOfView() const
*/
bool QDeclarativeGeoMap::isBearingSupported() const
{
- if (!m_map)
- return false;
- return m_map->cameraCapabilities().supportsBearing();
+ return m_cameraCapabilities.supportsBearing();
}
/*!
@@ -1010,9 +1062,7 @@ bool QDeclarativeGeoMap::isBearingSupported() const
*/
bool QDeclarativeGeoMap::isTiltingSupported() const
{
- if (!m_map)
- return false;
- return m_map->cameraCapabilities().supportsTilting();
+ return m_cameraCapabilities.supportsTilting();
}
/*!
@@ -1025,9 +1075,7 @@ bool QDeclarativeGeoMap::isTiltingSupported() const
*/
qreal QDeclarativeGeoMap::minimumTilt() const
{
- if (!m_map || !m_map->cameraCapabilities().supportsTilting())
- return 0.0;
- return m_map->cameraCapabilities().minimumTilt();
+ return m_cameraCapabilities.minimumTilt();
}
/*!
@@ -1041,11 +1089,7 @@ qreal QDeclarativeGeoMap::minimumTilt() const
*/
qreal QDeclarativeGeoMap::maximumTilt() const
{
- if (!m_map)
- return 89.0;
- else if (!m_map->cameraCapabilities().supportsTilting())
- return 0.0;
- return m_map->cameraCapabilities().maximumTilt();
+ return m_cameraCapabilities.maximumTilt();
}
/*!
@@ -1716,7 +1760,7 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF
if (!m_initialized) {
initialize();
} else {
- setMinimumZoomLevel(m_map->minimumZoom());
+ setMinimumZoomLevel(m_map->minimumZoom(), false);
// Update the center latitudinal threshold
double maximumCenterLatitudeAtZoom = m_map->maximumCenterLatitudeAtZoom(m_cameraData);
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index a7519a48..f69ca6a1 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -54,6 +54,7 @@
#include <QtLocation/private/qdeclarativegeomapitemgroup_p.h>
#include <QtLocation/qgeoserviceprovider.h>
#include <QtLocation/private/qgeocameradata_p.h>
+#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtQuick/QQuickItem>
#include <QtCore/QList>
#include <QtCore/QPointer>
@@ -111,10 +112,10 @@ public:
void setActiveMapType(QDeclarativeGeoMapType *mapType);
QDeclarativeGeoMapType *activeMapType() const;
- void setMinimumZoomLevel(qreal minimumZoomLevel);
+ void setMinimumZoomLevel(qreal minimumZoomLevel, bool userSet = true);
qreal minimumZoomLevel() const;
- void setMaximumZoomLevel(qreal maximumZoomLevel);
+ void setMaximumZoomLevel(qreal maximumZoomLevel, bool userSet = true);
qreal maximumZoomLevel() const;
void setZoomLevel(qreal zoomLevel);
@@ -227,6 +228,7 @@ private Q_SLOTS:
void pluginReady();
void onMapChildrenChanged();
void onSupportedMapTypesChanged();
+ void onCameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities);
private:
void setupMapView(QDeclarativeGeoMapItemView *view);
@@ -258,6 +260,9 @@ private:
double m_maximumViewportLatitude;
bool m_initialized;
QList<QDeclarativeGeoMapParameter *> m_mapParameters;
+ QGeoCameraCapabilities m_cameraCapabilities;
+ qreal m_userMinimumZoomLevel;
+ qreal m_userMaximumZoomLevel;
friend class QDeclarativeGeoMapItem;
friend class QDeclarativeGeoMapItemView;
diff --git a/src/location/maps/qgeocameracapabilities.cpp b/src/location/maps/qgeocameracapabilities.cpp
index 568476fd..6426b058 100644
--- a/src/location/maps/qgeocameracapabilities.cpp
+++ b/src/location/maps/qgeocameracapabilities.cpp
@@ -57,6 +57,8 @@ public:
QGeoCameraCapabilitiesPrivate &operator = (const QGeoCameraCapabilitiesPrivate &other);
+ bool operator == (const QGeoCameraCapabilitiesPrivate &rhs) const;
+
bool supportsBearing_;
bool supportsRolling_;
bool supportsTilting_;
@@ -125,6 +127,21 @@ QGeoCameraCapabilitiesPrivate &QGeoCameraCapabilitiesPrivate::operator = (const
return *this;
}
+bool QGeoCameraCapabilitiesPrivate::operator == (const QGeoCameraCapabilitiesPrivate &rhs) const
+{
+ return ((supportsBearing_ == rhs.supportsBearing_)
+ && (supportsRolling_ == rhs.supportsRolling_)
+ && (supportsTilting_ == rhs.supportsTilting_)
+ && (valid_ == rhs.valid_)
+ && (minZoom_ == rhs.minZoom_)
+ && (maxZoom_ == rhs.maxZoom_)
+ && (minTilt_ == rhs.minTilt_)
+ && (maxTilt_ == rhs.maxTilt_)
+ && (tileSize_ == rhs.tileSize_)
+ && (minimumFieldOfView_ == rhs.minimumFieldOfView_)
+ && (maximumFieldOfView_ == rhs.maximumFieldOfView_));
+}
+
/*!
\class QGeoCameraCapabilities
\inmodule QtLocation
@@ -171,6 +188,16 @@ QGeoCameraCapabilities &QGeoCameraCapabilities::operator = (const QGeoCameraCapa
return *this;
}
+bool QGeoCameraCapabilities::operator == (const QGeoCameraCapabilities &rhs) const
+{
+ return (*(d.constData()) == *(rhs.d.constData()));
+}
+
+bool QGeoCameraCapabilities::operator != (const QGeoCameraCapabilities &other) const
+{
+ return !(operator==(other));
+}
+
void QGeoCameraCapabilities::setTileSize(int tileSize)
{
if (tileSize < 1)
@@ -388,7 +415,7 @@ double QGeoCameraCapabilities::minimumFieldOfView() const
*/
void QGeoCameraCapabilities::setMaximumFieldOfView(double maximumFieldOfView)
{
- d->maximumFieldOfView_ = maximumFieldOfView;
+ d->maximumFieldOfView_ = qBound(1.0, maximumFieldOfView, 179.0);
d->valid_ = true;
}
diff --git a/src/location/maps/qgeocameracapabilities_p.h b/src/location/maps/qgeocameracapabilities_p.h
index c9da53e9..099ad76d 100644
--- a/src/location/maps/qgeocameracapabilities_p.h
+++ b/src/location/maps/qgeocameracapabilities_p.h
@@ -65,6 +65,9 @@ public:
QGeoCameraCapabilities &operator = (const QGeoCameraCapabilities &other);
+ bool operator == (const QGeoCameraCapabilities &other) const;
+ bool operator != (const QGeoCameraCapabilities &other) const;
+
void setTileSize(int tileSize);
int tileSize() const;
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index 9d3f4efa..2419b79a 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -92,6 +92,12 @@ void QGeoMap::setCameraData(const QGeoCameraData &cameraData)
emit cameraDataChanged(d->m_cameraData);
}
+void QGeoMap::setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities)
+{
+ Q_D(QGeoMap);
+ d->setCameraCapabilities(cameraCapabilities);
+}
+
QGeoCameraData QGeoMap::cameraData() const
{
Q_D(const QGeoMap);
@@ -104,6 +110,7 @@ void QGeoMap::setActiveMapType(const QGeoMapType type)
if (type == d->m_activeMapType)
return;
d->m_activeMapType = type;
+ d->setCameraCapabilities(d->m_engine->cameraCapabilities(type)); // emits
d->changeActiveMapType(type);
emit activeMapTypeChanged();
}
@@ -147,10 +154,7 @@ const QGeoProjection &QGeoMap::geoProjection() const
QGeoCameraCapabilities QGeoMap::cameraCapabilities() const
{
Q_D(const QGeoMap);
- if (!d->m_engine.isNull())
- return d->m_engine->cameraCapabilities();
- else
- return QGeoCameraCapabilities();
+ return d->m_cameraCapabilities;
}
void QGeoMap::prefetchData()
@@ -232,6 +236,9 @@ QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine, QGeoProjection
m_engine(engine),
m_activeMapType(QGeoMapType())
{
+ // Setting the default camera caps without emitting anything
+ if (engine)
+ m_cameraCapabilities = m_engine->cameraCapabilities(m_activeMapType);
}
QGeoMapPrivate::~QGeoMapPrivate()
@@ -240,6 +247,21 @@ QGeoMapPrivate::~QGeoMapPrivate()
delete m_geoProjection;
}
+void QGeoMapPrivate::setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities)
+{
+ Q_Q(QGeoMap);
+ if (m_cameraCapabilities == cameraCapabilities)
+ return;
+ QGeoCameraCapabilities oldCaps = m_cameraCapabilities;
+ m_cameraCapabilities = cameraCapabilities;
+ emit q->cameraCapabilitiesChanged(oldCaps);
+}
+
+const QGeoCameraCapabilities &QGeoMapPrivate::cameraCapabilities() const
+{
+ return m_cameraCapabilities;
+}
+
void QGeoMapPrivate::addParameter(QGeoMapParameter *param)
{
Q_UNUSED(param)
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index 7e2d4bbd..bb7ade55 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -127,12 +127,14 @@ public:
protected:
QGeoMap(QGeoMapPrivate &dd, QObject *parent = 0);
void setCameraData(const QGeoCameraData &cameraData);
+ void setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities);
virtual QSGNode *updateSceneGraph(QSGNode *node, QQuickWindow *window) = 0;
Q_SIGNALS:
void cameraDataChanged(const QGeoCameraData &cameraData);
void sgNodeChanged();
void activeMapTypeChanged();
+ void cameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities);
void copyrightsChanged(const QImage &copyrightsImage);
void copyrightsChanged(const QString &copyrightsHtml);
void copyrightsStyleSheetChanged(const QString &styleSheet);
diff --git a/src/location/maps/qgeomap_p_p.h b/src/location/maps/qgeomap_p_p.h
index 399fd75b..ec498484 100644
--- a/src/location/maps/qgeomap_p_p.h
+++ b/src/location/maps/qgeomap_p_p.h
@@ -51,6 +51,8 @@
#include <QtLocation/private/qgeocameradata_p.h>
#include <QtLocation/private/qgeomaptype_p.h>
#include <QtLocation/private/qgeoprojection_p.h>
+#include <QtLocation/private/qgeomap_p.h>
+#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtCore/private/qobject_p.h>
#include <QtCore/QSize>
#include <QtCore/QList>
@@ -73,6 +75,8 @@ public:
virtual ~QGeoMapPrivate();
const QGeoProjection *geoProjection() const;
+ void setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities);
+ const QGeoCameraCapabilities &cameraCapabilities() const;
protected:
/* Hooks into the actual map implementations */
virtual void addParameter(QGeoMapParameter *param);
@@ -94,6 +98,7 @@ protected:
QGeoMapType m_activeMapType;
QList<QGeoMapParameter *> m_mapParameters;
QList<QDeclarativeGeoMapItemBase *> m_mapItems;
+ QGeoCameraCapabilities m_cameraCapabilities;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp
index 7d829965..cf040beb 100644
--- a/src/location/maps/qgeomappingmanager.cpp
+++ b/src/location/maps/qgeomappingmanager.cpp
@@ -128,11 +128,6 @@ int QGeoMappingManager::managerVersion() const
return d_ptr->engine->managerVersion();
}
-QGeoCameraCapabilities QGeoMappingManager::cameraCapabilities() const
-{
- return d_ptr->engine->cameraCapabilities();
-}
-
/*!
Returns a new QGeoMap instance which will be managed by this manager.
*/
diff --git a/src/location/maps/qgeomappingmanager_p.h b/src/location/maps/qgeomappingmanager_p.h
index f536b15b..2f8e5283 100644
--- a/src/location/maps/qgeomappingmanager_p.h
+++ b/src/location/maps/qgeomappingmanager_p.h
@@ -52,7 +52,7 @@
#include <QSize>
#include <QPair>
#include <QtLocation/private/qlocationglobal_p.h>
-#include "qgeomaptype_p.h"
+#include <QtLocation/private/qgeomaptype_p.h>
QT_BEGIN_NAMESPACE
@@ -82,8 +82,6 @@ public:
bool isInitialized() const;
- QGeoCameraCapabilities cameraCapabilities() const;
-
void setLocale(const QLocale &locale);
QLocale locale() const;
diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp
index 5094c1b3..a385f8ce 100644
--- a/src/location/maps/qgeomappingmanagerengine.cpp
+++ b/src/location/maps/qgeomappingmanagerengine.cpp
@@ -150,8 +150,9 @@ void QGeoMappingManagerEngine::setSupportedMapTypes(const QList<QGeoMapType> &su
emit supportedMapTypesChanged();
}
-QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities() const
+QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities(const QGeoMapType &mapType) const
{
+ Q_UNUSED(mapType)
Q_D(const QGeoMappingManagerEngine);
return d->capabilities_;
}
diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h
index 13956141..b8ebb1ec 100644
--- a/src/location/maps/qgeomappingmanagerengine_p.h
+++ b/src/location/maps/qgeomappingmanagerengine_p.h
@@ -89,7 +89,8 @@ public:
QList<QGeoMapType> supportedMapTypes() const;
- QGeoCameraCapabilities cameraCapabilities() const;
+ // the class is private, so this can be virtual here for now.
+ virtual QGeoCameraCapabilities cameraCapabilities(const QGeoMapType &mapType) const;
void setLocale(const QLocale &locale);
QLocale locale() const;
diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp
index fc08fe62..68f150db 100644
--- a/src/location/maps/qgeotiledmap.cpp
+++ b/src/location/maps/qgeotiledmap.cpp
@@ -66,6 +66,10 @@ QGeoTiledMap::QGeoTiledMap(QGeoTiledMappingManagerEngine *engine, QObject *paren
QObject::connect(engine,&QGeoTiledMappingManagerEngine::tileVersionChanged,
this,&QGeoTiledMap::handleTileVersionChanged);
+ QObject::connect(this, &QGeoMap::cameraCapabilitiesChanged,
+ [d](const QGeoCameraCapabilities &oldCameraCapabilities) {
+ d->onCameraCapabilitiesChanged(oldCameraCapabilities);
+ });
}
QGeoTiledMap::QGeoTiledMap(QGeoTiledMapPrivate &dd, QGeoTiledMappingManagerEngine *engine, QObject *parent)
@@ -77,6 +81,10 @@ QGeoTiledMap::QGeoTiledMap(QGeoTiledMapPrivate &dd, QGeoTiledMappingManagerEngin
QObject::connect(engine,&QGeoTiledMappingManagerEngine::tileVersionChanged,
this,&QGeoTiledMap::handleTileVersionChanged);
+ QObject::connect(this, &QGeoMap::cameraCapabilitiesChanged,
+ [d](const QGeoCameraCapabilities &oldCameraCapabilities) {
+ d->onCameraCapabilitiesChanged(oldCameraCapabilities);
+ });
}
QGeoTiledMap::~QGeoTiledMap()
@@ -164,11 +172,11 @@ QGeoTiledMapPrivate::QGeoTiledMapPrivate(QGeoTiledMappingManagerEngine *engine)
m_prefetchTiles(new QGeoCameraTiles()),
m_mapScene(new QGeoTiledMapScene()),
m_tileRequests(0),
- m_maxZoomLevel(static_cast<int>(std::ceil(engine->cameraCapabilities().maximumZoomLevel()))),
- m_minZoomLevel(static_cast<int>(std::ceil(engine->cameraCapabilities().minimumZoomLevel()))),
+ m_maxZoomLevel(static_cast<int>(std::ceil(m_cameraCapabilities.maximumZoomLevel()))),
+ m_minZoomLevel(static_cast<int>(std::ceil(m_cameraCapabilities.minimumZoomLevel()))),
m_prefetchStyle(QGeoTiledMap::PrefetchTwoNeighbourLayers)
{
- int tileSize = engine->tileSize().width();
+ int tileSize = m_cameraCapabilities.tileSize();
QString pluginString(engine->managerName() + QLatin1Char('_') + QString::number(engine->managerVersion()));
m_visibleTiles->setTileSize(tileSize);
m_prefetchTiles->setTileSize(tileSize);
@@ -247,6 +255,23 @@ QGeoMapType QGeoTiledMapPrivate::activeMapType()
return m_visibleTiles->activeMapType();
}
+// Called before changeCameraData
+void QGeoTiledMapPrivate::onCameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities)
+{
+ // Handle varying min/maxZoomLevel
+ if (oldCameraCapabilities.minimumZoomLevel() != m_cameraCapabilities.minimumZoomLevel())
+ m_minZoomLevel = static_cast<int>(std::ceil(m_cameraCapabilities.minimumZoomLevel()));
+ if (oldCameraCapabilities.maximumZoomLevel() != m_cameraCapabilities.maximumZoomLevel())
+ m_maxZoomLevel = static_cast<int>(std::ceil(m_cameraCapabilities.maximumZoomLevel()));
+
+ // Handle varying tile size
+ if (oldCameraCapabilities.tileSize() != m_cameraCapabilities.tileSize()) {
+ m_visibleTiles->setTileSize(oldCameraCapabilities.tileSize());
+ m_prefetchTiles->setTileSize(oldCameraCapabilities.tileSize());
+ m_mapScene->setTileSize(oldCameraCapabilities.tileSize());
+ }
+}
+
void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &cameraData)
{
Q_Q(QGeoTiledMap);
diff --git a/src/location/maps/qgeotiledmap_p_p.h b/src/location/maps/qgeotiledmap_p_p.h
index 7106adf3..3dc589ae 100644
--- a/src/location/maps/qgeotiledmap_p_p.h
+++ b/src/location/maps/qgeotiledmap_p_p.h
@@ -66,6 +66,7 @@ class QGeoTileRequestManager;
class QGeoTileSpec;
class QSGNode;
class QQuickWindow;
+class QGeoCameraCapabilities;
class Q_LOCATION_PRIVATE_EXPORT QGeoTiledMapPrivate : public QGeoMapPrivate
{
@@ -79,6 +80,7 @@ public:
void updateTile(const QGeoTileSpec &spec);
void prefetchTiles();
QGeoMapType activeMapType();
+ void onCameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities);
protected:
void changeViewportSize(const QSize& size) Q_DECL_OVERRIDE;
diff --git a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp
index e31cbdd5..16799dc2 100644
--- a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp
@@ -109,6 +109,9 @@ void QGeoTiledMapOsm::onProviderDataUpdated(const QGeoTileProviderOsm *provider)
if (copyRights.isEmpty() && provider->mapType().style() == QGeoMapType::CustomMap)
copyRights = m_engine->customCopyright();
+ // Update CameraCapabilities
+ setCameraCapabilities(provider->cameraCapabilities());
+
emit copyrightsChanged(copyRights);
}
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
index e9e48008..0e1fb356 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
@@ -163,25 +163,25 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
/* QGeoTileProviderOsms setup */
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::StreetMap, tr("Street Map"), tr("Street map view in daylight mode"), false, false, 1),
- providers_street ));
+ providers_street, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Satellite Map"), tr("Satellite map view in daylight mode"), false, false, 2),
- providers_satellite ));
+ providers_satellite, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::CycleMap, tr("Cycle Map"), tr("Cycle map view in daylight mode"), false, false, 3),
- providers_cycle ));
+ providers_cycle, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::TransitMap, tr("Transit Map"), tr("Public transit map view in daylight mode"), false, false, 4),
- providers_transit ));
+ providers_transit, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::TransitMap, tr("Night Transit Map"), tr("Public transit map view in night mode"), false, true, 5),
- providers_nighttransit ));
+ providers_nighttransit, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::TerrainMap, tr("Terrain Map"), tr("Terrain map view"), false, false, 6),
- providers_terrain ));
+ providers_terrain, cameraCaps ));
m_providers.push_back( new QGeoTileProviderOsm( nm,
QGeoMapType(QGeoMapType::PedestrianMap, tr("Hiking Map"), tr("Hiking map view"), false, false, 7),
- providers_hiking ));
+ providers_hiking, cameraCaps ));
if (parameters.contains(QStringLiteral("osm.mapping.custom.host"))
|| parameters.contains(QStringLiteral("osm.mapping.host"))) {
@@ -208,7 +208,7 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
{ new TileProvider(tmsServer + QStringLiteral("%z/%x/%y.png"),
QStringLiteral("png"),
mapCopyright,
- dataCopyright) }
+ dataCopyright) }, cameraCaps
));
m_providers.last()->disableRedirection();
@@ -337,6 +337,16 @@ QString QGeoTiledMappingManagerEngineOsm::customCopyright() const
return m_customCopyright;
}
+QGeoCameraCapabilities QGeoTiledMappingManagerEngineOsm::cameraCapabilities(const QGeoMapType &mapType) const
+{
+ if (mapType.mapId() == 0)
+ return QGeoMappingManagerEngine::cameraCapabilities(mapType);
+ int idx = mapType.mapId() - 1;
+ if (idx >= m_providers.size())
+ return QGeoMappingManagerEngine::cameraCapabilities(QGeoMapType());
+ return m_providers[idx]->cameraCapabilities();
+}
+
void QGeoTiledMappingManagerEngineOsm::onProviderResolutionFinished(const QGeoTileProviderOsm *provider)
{
if (!provider->isResolved())
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
index b1f0a13c..db8b230c 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
@@ -62,6 +62,7 @@ public:
QGeoMap *createMap();
const QVector<QGeoTileProviderOsm *> &providers();
QString customCopyright() const;
+ QGeoCameraCapabilities cameraCapabilities(const QGeoMapType &mapType) const Q_DECL_OVERRIDE;
protected Q_SLOTS:
void onProviderResolutionFinished(const QGeoTileProviderOsm *provider);
diff --git a/src/plugins/geoservices/osm/qgeotileproviderosm.cpp b/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
index 1989c44f..1b48401c 100644
--- a/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
@@ -47,8 +47,9 @@ static const QDateTime defaultTs = QDateTime::fromString(QStringLiteral("2016-06
QGeoTileProviderOsm::QGeoTileProviderOsm(QNetworkAccessManager *nm,
const QGeoMapType &mapType,
- const QVector<TileProvider *> &providers)
-: m_nm(nm), m_provider(nullptr), m_mapType(mapType), m_status(Idle)
+ const QVector<TileProvider *> &providers,
+ const QGeoCameraCapabilities &cameraCapabilities)
+: m_nm(nm), m_provider(nullptr), m_mapType(mapType), m_status(Idle), m_cameraCapabilities(cameraCapabilities)
{
for (int i = 0; i < providers.size(); ++i) {
TileProvider *p = providers[i];
@@ -59,6 +60,8 @@ QGeoTileProviderOsm::QGeoTileProviderOsm(QNetworkAccessManager *nm,
if (!m_provider || m_provider->isValid())
m_status = Resolved;
+
+ connect(this, &QGeoTileProviderOsm::resolutionFinished, this, &QGeoTileProviderOsm::updateCameraCapabilities);
}
QGeoTileProviderOsm::~QGeoTileProviderOsm()
@@ -128,6 +131,11 @@ const QDateTime QGeoTileProviderOsm::timestamp() const
return m_provider->timestamp();
}
+QGeoCameraCapabilities QGeoTileProviderOsm::cameraCapabilities() const
+{
+ return m_cameraCapabilities;
+}
+
const QGeoMapType &QGeoTileProviderOsm::mapType() const
{
return m_mapType;
@@ -220,6 +228,15 @@ void QGeoTileProviderOsm::onResolutionError(TileProvider *provider)
}
}
+void QGeoTileProviderOsm::updateCameraCapabilities()
+{
+ // Set proper min/max ZoomLevel coming from the json, if available.
+ m_cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel());
+ m_cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel());
+
+ // Pushing the change
+}
+
void QGeoTileProviderOsm::addProvider(TileProvider *provider)
{
if (!provider)
diff --git a/src/plugins/geoservices/osm/qgeotileproviderosm.h b/src/plugins/geoservices/osm/qgeotileproviderosm.h
index b8647244..54f8049d 100644
--- a/src/plugins/geoservices/osm/qgeotileproviderosm.h
+++ b/src/plugins/geoservices/osm/qgeotileproviderosm.h
@@ -38,7 +38,7 @@
#define QTILEPROVIDEROSM_H
#include <QtLocation/private/qgeomaptype_p.h>
-
+#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtCore/QUrl>
#include <QtCore/QVector>
#include <QtNetwork/QNetworkAccessManager>
@@ -142,7 +142,8 @@ public:
QGeoTileProviderOsm(QNetworkAccessManager *nm,
const QGeoMapType &mapType,
- const QVector<TileProvider *> &providers);
+ const QVector<TileProvider *> &providers,
+ const QGeoCameraCapabilities &cameraCapabilities);
~QGeoTileProviderOsm();
QUrl tileAddress(int x, int y, int z) const;
@@ -157,6 +158,7 @@ public:
bool isValid() const;
bool isResolved() const;
const QDateTime timestamp() const;
+ QGeoCameraCapabilities cameraCapabilities() const;
Q_SIGNALS:
void resolutionFinished(const QGeoTileProviderOsm *provider);
@@ -170,6 +172,7 @@ public Q_SLOTS:
protected Q_SLOTS:
void onResolutionFinished(TileProvider *provider);
void onResolutionError(TileProvider *provider);
+ void updateCameraCapabilities();
protected:
void addProvider(TileProvider *provider);
@@ -182,6 +185,7 @@ protected:
int m_providerId;
QGeoMapType m_mapType;
Status m_status;
+ QGeoCameraCapabilities m_cameraCapabilities;
};
QT_END_NAMESPACE
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml
index ab1ddd8c..004e3b10 100644
--- a/tests/auto/declarative_ui/tst_map.qml
+++ b/tests/auto/declarative_ui/tst_map.qml
@@ -260,6 +260,47 @@ Item {
compare(map.maximumZoomLevel, 20)
}
+ function test_tilt_limits()
+ {
+ // Tilt limits are read only
+ map.tilt = 0
+
+ //initial plugin values
+ compare(map.minimumTilt, 0)
+ compare(map.maximumTilt, 60)
+
+ map.tilt = 18
+ compare(map.tilt, 18)
+
+ map.tilt = -2
+ compare(map.tilt, 0)
+
+ map.tilt = 2
+ compare(map.tilt, 2)
+
+ map.tilt = 62
+ compare(map.tilt, 60)
+
+ map.tilt = 0
+ compare(map.tilt, 0)
+ }
+
+ function test_fov_limits()
+ {
+ // Tilt limits are read only
+ map.fieldOfView = 45
+
+ //initial plugin values
+ compare(map.fieldOfView, 45)
+ compare(map.fieldOfView, 45)
+
+ map.fieldOfView = 18
+ compare(map.fieldOfView, 45)
+
+ map.fieldOfView = 62
+ compare(map.fieldOfView, 45)
+ }
+
function test_zoom()
{
wait(1000)
diff --git a/tests/auto/declarative_ui/tst_map_maptype.qml b/tests/auto/declarative_ui/tst_map_maptype.qml
index fa056c44..17e958d5 100644
--- a/tests/auto/declarative_ui/tst_map_maptype.qml
+++ b/tests/auto/declarative_ui/tst_map_maptype.qml
@@ -40,6 +40,12 @@ Item{
Map { id: map; anchors.fill: parent }
SignalSpy { id: supportedMapTypesSpy; target: map; signalName: "supportedMapTypesChanged" }
SignalSpy { id: activeMapTypeChangedSpy; target: map; signalName: "activeMapTypeChanged" }
+ SignalSpy { id: minimumZoomLevelChangedSpy; target: map; signalName: "minimumZoomLevelChanged" }
+ SignalSpy { id: maximumZoomLevelChangedSpy; target: map; signalName: "maximumZoomLevelChanged" }
+ SignalSpy { id: minimumTiltChangedSpy; target: map; signalName: "minimumTiltChanged" }
+ SignalSpy { id: maximumTiltChangedSpy; target: map; signalName: "maximumTiltChanged" }
+ SignalSpy { id: minimumFieldOfViewChangedSpy; target: map; signalName: "minimumFieldOfViewChanged" }
+ SignalSpy { id: maximumFieldOfViewChangedSpy; target: map; signalName: "maximumFieldOfViewChanged" }
TestCase {
id: testCase
@@ -52,7 +58,7 @@ Item{
compare(map.activeMapType.style, MapType.NoMap)
map.plugin = testPlugin
tryCompare(supportedMapTypesSpy, "count", 1)
- compare(map.supportedMapTypes.length,3)
+ compare(map.supportedMapTypes.length, 4)
compare(map.supportedMapTypes[0].style, MapType.StreetMap)
compare(map.supportedMapTypes[0].name, "StreetMap")
compare(map.supportedMapTypes[0].description, "StreetMap")
@@ -62,6 +68,9 @@ Item{
compare(map.supportedMapTypes[2].style, MapType.CycleMap)
compare(map.supportedMapTypes[2].name, "CycleMap")
compare(map.supportedMapTypes[2].description, "CycleMap")
+ compare(map.supportedMapTypes[3].style, MapType.CustomMap)
+ compare(map.supportedMapTypes[3].name, "AlternateCameraCapabilities")
+ compare(map.supportedMapTypes[3].description, "AlternateCameraCapabilities")
//default
compare(map.activeMapType.style, MapType.StreetMap)
}
@@ -87,6 +96,89 @@ Item{
tryCompare(activeMapTypeChangedSpy, "count", 2)
compare(map.supportedMapTypes[2].name, map.activeMapType.name)
compare(map.supportedMapTypes[2].style, map.activeMapType.style)
+
+ map.activeMapType = map.supportedMapTypes[3]
+ tryCompare(activeMapTypeChangedSpy, "count", 3)
+ compare(map.supportedMapTypes[3].name, map.activeMapType.name)
+ compare(map.supportedMapTypes[3].style, map.activeMapType.style)
+ }
+
+ function test_maptype_capabilities()
+ {
+ minimumZoomLevelChangedSpy.clear();
+ maximumZoomLevelChangedSpy.clear();
+ minimumTiltChangedSpy.clear();
+ maximumTiltChangedSpy.clear();
+ minimumFieldOfViewChangedSpy.clear();
+ maximumFieldOfViewChangedSpy.clear();
+
+ map.activeMapType = map.supportedMapTypes[0]
+
+ compare(map.minimumZoomLevel, 0)
+ compare(map.maximumZoomLevel, 20)
+ compare(map.minimumTilt, 0)
+ compare(map.maximumTilt, 60)
+ compare(map.minimumFieldOfView, 45)
+ compare(map.maximumFieldOfView, 45)
+
+ tryCompare(minimumZoomLevelChangedSpy, "count", 0)
+ tryCompare(maximumZoomLevelChangedSpy, "count", 0)
+ tryCompare(minimumTiltChangedSpy, "count", 0)
+ tryCompare(maximumTiltChangedSpy, "count", 0)
+ tryCompare(minimumFieldOfViewChangedSpy, "count", 0)
+ tryCompare(maximumFieldOfViewChangedSpy, "count", 0)
+
+
+ map.activeMapType = map.supportedMapTypes[1]
+
+ compare(map.minimumZoomLevel, 0)
+ compare(map.maximumZoomLevel, 20)
+ compare(map.minimumTilt, 0)
+ compare(map.maximumTilt, 60)
+ compare(map.minimumFieldOfView, 45)
+ compare(map.maximumFieldOfView, 45)
+
+ tryCompare(minimumZoomLevelChangedSpy, "count", 0)
+ tryCompare(maximumZoomLevelChangedSpy, "count", 0)
+ tryCompare(minimumTiltChangedSpy, "count", 0)
+ tryCompare(maximumTiltChangedSpy, "count", 0)
+ tryCompare(minimumFieldOfViewChangedSpy, "count", 0)
+ tryCompare(maximumFieldOfViewChangedSpy, "count", 0)
+
+
+ map.activeMapType = map.supportedMapTypes[3]
+
+ compare(map.minimumZoomLevel, 0)
+ compare(map.maximumZoomLevel, 19)
+ compare(map.minimumTilt, 0)
+ compare(map.maximumTilt, 80)
+ compare(map.minimumFieldOfView, 1)
+ compare(map.maximumFieldOfView, 179)
+
+ tryCompare(minimumZoomLevelChangedSpy, "count", 0)
+ tryCompare(maximumZoomLevelChangedSpy, "count", 1)
+ tryCompare(minimumTiltChangedSpy, "count", 0)
+ tryCompare(maximumTiltChangedSpy, "count", 1)
+ tryCompare(minimumFieldOfViewChangedSpy, "count", 1)
+ tryCompare(maximumFieldOfViewChangedSpy, "count", 1)
+
+
+ map.activeMapType = map.supportedMapTypes[0]
+
+ compare(map.minimumZoomLevel, 0)
+ compare(map.maximumZoomLevel, 20)
+ compare(map.minimumTilt, 0)
+ compare(map.maximumTilt, 60)
+ compare(map.minimumFieldOfView, 45)
+ compare(map.maximumFieldOfView, 45)
+
+ tryCompare(minimumZoomLevelChangedSpy, "count", 0)
+ tryCompare(maximumZoomLevelChangedSpy, "count", 2)
+ tryCompare(minimumTiltChangedSpy, "count", 0)
+ tryCompare(maximumTiltChangedSpy, "count", 2)
+ tryCompare(minimumFieldOfViewChangedSpy, "count", 2)
+ tryCompare(maximumFieldOfViewChangedSpy, "count", 2)
+
}
}
}
diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
index 015a203a..df729392 100644
--- a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
@@ -66,6 +66,7 @@ public:
mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("StreetMap"), tr("StreetMap"), false, false, 1);
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("SatelliteMapDay"), tr("SatelliteMapDay"), false, false, 2);
mapTypes << QGeoMapType(QGeoMapType::CycleMap, tr("CycleMap"), tr("CycleMap"), false, false, 3);
+ mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("AlternateCameraCapabilities"), tr("AlternateCameraCapabilities"), false, false, 4);
setSupportedMapTypes(mapTypes);
QGeoTileFetcherTest *fetcher = new QGeoTileFetcherTest(this);
@@ -90,6 +91,27 @@ public:
return new QGeoTiledMapTest(this);
}
+ QGeoCameraCapabilities cameraCapabilities(const QGeoMapType &mapType) const Q_DECL_OVERRIDE
+ {
+ switch (mapType.mapId()) {
+ case 4:
+ {
+ QGeoCameraCapabilities capabilities;
+ capabilities.setMinimumZoomLevel(0.0);
+ capabilities.setMaximumZoomLevel(19.0);
+ capabilities.setSupportsBearing(true);
+ capabilities.setSupportsTilting(true);
+ capabilities.setMinimumTilt(0);
+ capabilities.setMaximumTilt(80);
+ capabilities.setMinimumFieldOfView(1);
+ capabilities.setMaximumFieldOfView(179);
+ return capabilities;
+ }
+ default:
+ return QGeoMappingManagerEngine::cameraCapabilities(mapType);
+ }
+ }
+
};
#endif
diff --git a/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp b/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp
index 09d7293b..06d85e1e 100644
--- a/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp
+++ b/tests/auto/qgeocameracapabilities/tst_qgeocameracapabilities.cpp
@@ -54,6 +54,8 @@ private Q_SLOTS:
void supportsTiltingTest();
void minimumTiltTest();
void maximumTiltTest();
+ void minimumFieldOfViewTest();
+ void maximumFieldOfViewTest();
void operatorsTest_data();
void operatorsTest();
void isValidTest();
@@ -68,12 +70,14 @@ void tst_QGeoCameraCapabilities::populateGeoCameraCapabilitiesData(){
QTest::addColumn<double>("maximumZoomLevel");
QTest::addColumn<double>("minimumTilt");
QTest::addColumn<double>("maximumTilt");
+ QTest::addColumn<double>("minimumFieldOfView");
+ QTest::addColumn<double>("maximumFieldOfView");
QTest::addColumn<bool>("bearingSupport");
QTest::addColumn<bool>("rollingSupport");
QTest::addColumn<bool>("tiltingSupport");
- QTest::newRow("zeros") << 0.0 << 0.0 << 0.0 << 0.0 << false << false << false;
- QTest::newRow("valid") << 1.0 << 2.0 << 0.5 << 1.5 << true << true << true;
- QTest::newRow("negative values") << 0.0 << 0.5 << -0.5 << -0.1 << true << true << true;
+ QTest::newRow("zeros") << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << false << false << false;
+ QTest::newRow("valid") << 1.0 << 2.0 << 0.5 << 1.5 << 1.0 << 179.0 << true << true << true;
+ QTest::newRow("negative values") << 0.0 << 0.5 << -0.5 << -0.1 << -20.0 << -30.0 << true << true << true;
}
void tst_QGeoCameraCapabilities::constructorTest_data(){
@@ -86,10 +90,15 @@ void tst_QGeoCameraCapabilities::constructorTest()
QFETCH(double, maximumZoomLevel);
QFETCH(double, minimumTilt);
QFETCH(double, maximumTilt);
+ QFETCH(double, minimumFieldOfView);
+ QFETCH(double, maximumFieldOfView);
QFETCH(bool, bearingSupport);
QFETCH(bool, rollingSupport);
QFETCH(bool, tiltingSupport);
+ minimumFieldOfView = qBound(1.0, minimumFieldOfView, 179.0);
+ maximumFieldOfView = qBound(1.0, maximumFieldOfView, 179.0);
+
// contructor test with default values
QGeoCameraCapabilities cameraCapabilities;
QGeoCameraCapabilities cameraCapabilities2(cameraCapabilities);
@@ -100,12 +109,16 @@ void tst_QGeoCameraCapabilities::constructorTest()
QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Copy constructor failed for tilting support");
QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt());
QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt());
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView());
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView());
// constructor test after setting values
cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel);
cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel);
cameraCapabilities.setMinimumTilt(minimumTilt);
cameraCapabilities.setMaximumTilt(maximumTilt);
+ cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView);
+ cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView);
cameraCapabilities.setSupportsBearing(bearingSupport);
cameraCapabilities.setSupportsRolling(rollingSupport);
cameraCapabilities.setSupportsTilting(tiltingSupport);
@@ -116,6 +129,8 @@ void tst_QGeoCameraCapabilities::constructorTest()
QCOMPARE(cameraCapabilities3.maximumZoomLevel(), maximumZoomLevel);
QCOMPARE(cameraCapabilities3.minimumTilt(), minimumTilt);
QCOMPARE(cameraCapabilities3.maximumTilt(), maximumTilt);
+ QCOMPARE(cameraCapabilities3.minimumFieldOfView(), minimumFieldOfView);
+ QCOMPARE(cameraCapabilities3.maximumFieldOfView(), maximumFieldOfView);
QVERIFY2(cameraCapabilities3.supportsBearing() == bearingSupport, "Copy constructor failed for bearing support");
QVERIFY2(cameraCapabilities3.supportsRolling() == rollingSupport, "Copy constructor failed for rolling support ");
QVERIFY2(cameraCapabilities3.supportsTilting() == tiltingSupport, "Copy constructor failed for tilting support");
@@ -127,6 +142,8 @@ void tst_QGeoCameraCapabilities::constructorTest()
QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities3.supportsTilting(), "Copy constructor failed for tilting support");
QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities3.minimumTilt());
QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities3.maximumTilt());
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities3.minimumFieldOfView());
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities3.maximumFieldOfView());
}
void tst_QGeoCameraCapabilities::minimumZoomLevelTest()
@@ -213,6 +230,40 @@ void tst_QGeoCameraCapabilities::maximumTiltTest(){
QCOMPARE(cameraCapabilities2.maximumTilt(), 1.5);
}
+void tst_QGeoCameraCapabilities::minimumFieldOfViewTest()
+{
+ QGeoCameraCapabilities cameraCapabilities;
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), 45.0); // min/max default to 45
+ cameraCapabilities.setMinimumFieldOfView(1.5);
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.5);
+ cameraCapabilities.setMinimumFieldOfView(-1.5);
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), 1.0);
+ cameraCapabilities.setMinimumFieldOfView(245.5);
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), 179.0);
+
+ QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities;
+ QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0);
+ cameraCapabilities.setMinimumFieldOfView(2.5);
+ QCOMPARE(cameraCapabilities2.minimumFieldOfView(), 179.0);
+}
+
+void tst_QGeoCameraCapabilities::maximumFieldOfViewTest()
+{
+ QGeoCameraCapabilities cameraCapabilities;
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), 45.0); // min/max default to 45
+ cameraCapabilities.setMaximumFieldOfView(1.5);
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.5);
+ cameraCapabilities.setMaximumFieldOfView(-1.5);
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), 1.0);
+ cameraCapabilities.setMaximumFieldOfView(245.5);
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), 179.0);
+
+ QGeoCameraCapabilities cameraCapabilities2 = cameraCapabilities;
+ QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0);
+ cameraCapabilities.setMaximumFieldOfView(2.5);
+ QCOMPARE(cameraCapabilities2.maximumFieldOfView(), 179.0);
+}
+
void tst_QGeoCameraCapabilities::operatorsTest_data(){
populateGeoCameraCapabilitiesData();
}
@@ -223,15 +274,22 @@ void tst_QGeoCameraCapabilities::operatorsTest(){
QFETCH(double, maximumZoomLevel);
QFETCH(double, minimumTilt);
QFETCH(double, maximumTilt);
+ QFETCH(double, minimumFieldOfView);
+ QFETCH(double, maximumFieldOfView);
QFETCH(bool, bearingSupport);
QFETCH(bool, rollingSupport);
QFETCH(bool, tiltingSupport);
+ minimumFieldOfView = qBound(1.0, minimumFieldOfView, 179.0);
+ maximumFieldOfView = qBound(1.0, maximumFieldOfView, 179.0);
+
QGeoCameraCapabilities cameraCapabilities;
cameraCapabilities.setMinimumZoomLevel(minimumZoomLevel);
cameraCapabilities.setMaximumZoomLevel(maximumZoomLevel);
cameraCapabilities.setMinimumTilt(minimumTilt);
cameraCapabilities.setMaximumTilt(maximumTilt);
+ cameraCapabilities.setMinimumFieldOfView(minimumFieldOfView);
+ cameraCapabilities.setMaximumFieldOfView(maximumFieldOfView);
cameraCapabilities.setSupportsBearing(bearingSupport);
cameraCapabilities.setSupportsRolling(rollingSupport);
cameraCapabilities.setSupportsTilting(tiltingSupport);
@@ -242,17 +300,21 @@ void tst_QGeoCameraCapabilities::operatorsTest(){
QCOMPARE(cameraCapabilities2.maximumZoomLevel(), maximumZoomLevel);
QCOMPARE(cameraCapabilities2.minimumTilt(), minimumTilt);
QCOMPARE(cameraCapabilities2.maximumTilt(), maximumTilt);
- QVERIFY2(cameraCapabilities2.supportsBearing() == bearingSupport, "Copy constructor failed for bearing support");
- QVERIFY2(cameraCapabilities2.supportsRolling() == rollingSupport, "Copy constructor failed for rolling support ");
- QVERIFY2(cameraCapabilities2.supportsTilting() == tiltingSupport, "Copy constructor failed for tilting support");
+ QVERIFY2(cameraCapabilities2.supportsBearing() == bearingSupport, "Assignment operator failed for bearing support");
+ QVERIFY2(cameraCapabilities2.supportsRolling() == rollingSupport, "Assignment operator failed for rolling support ");
+ QVERIFY2(cameraCapabilities2.supportsTilting() == tiltingSupport, "Assignment operator failed for tilting support");
+ QCOMPARE(cameraCapabilities2.minimumFieldOfView(), minimumFieldOfView);
+ QCOMPARE(cameraCapabilities2.maximumFieldOfView(), maximumFieldOfView);
// verify that values have not changed after a constructor copy
QCOMPARE(cameraCapabilities.minimumZoomLevel(), cameraCapabilities2.minimumZoomLevel());
QCOMPARE(cameraCapabilities.maximumZoomLevel(), cameraCapabilities2.maximumZoomLevel());
- QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Copy constructor failed for bearing support");
- QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Copy constructor failed for rolling support ");
- QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Copy constructor failed for tilting support");
+ QVERIFY2(cameraCapabilities.supportsBearing() == cameraCapabilities2.supportsBearing(), "Assignment operator failed for bearing support");
+ QVERIFY2(cameraCapabilities.supportsRolling() == cameraCapabilities2.supportsRolling(), "Assignment operator failed for rolling support ");
+ QVERIFY2(cameraCapabilities.supportsTilting() == cameraCapabilities2.supportsTilting(), "Assignment operator failed for tilting support");
QCOMPARE(cameraCapabilities.minimumTilt(), cameraCapabilities2.minimumTilt());
QCOMPARE(cameraCapabilities.maximumTilt(), cameraCapabilities2.maximumTilt());
+ QCOMPARE(cameraCapabilities.minimumFieldOfView(), cameraCapabilities2.minimumFieldOfView());
+ QCOMPARE(cameraCapabilities.maximumFieldOfView(), cameraCapabilities2.maximumFieldOfView());
}
void tst_QGeoCameraCapabilities::isValidTest(){