summaryrefslogtreecommitdiff
path: root/src/imports
diff options
context:
space:
mode:
authorErik Mattsson <erik.mattsson@appello.com>2013-10-18 15:41:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-24 11:03:10 +0200
commit64ee46398e7285a8cd30f483ab730eb87bf01b33 (patch)
tree87732e868422cd190cd5af41cfebd78b664e2f3d /src/imports
parent41aaffee3845e02093c18417ebdbab68f8ab4c0f (diff)
downloadqtlocation-64ee46398e7285a8cd30f483ab730eb87bf01b33.tar.gz
Enabled setting max/min zoom level in declarative map
Created setters for max & min zoom level qproperty in declarative geo map. The new max/min values are set in the gesture area so the camera data values set by the plugin are still intact. Change-Id: I502159c1842238f41c2d598d2fb82c761af9535b Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp70
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h7
-rw-r--r--src/imports/location/qdeclarativegeomapgesturearea.cpp40
-rw-r--r--src/imports/location/qdeclarativegeomapgesturearea_p.h7
4 files changed, 97 insertions, 27 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index 9d98c187..a872d332 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -477,8 +477,15 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
map_ = mappingManager_->createMap(this);
gestureArea_->setMap(map_);
- gestureArea_->zoomLevelLimits(mappingManager_->cameraCapabilities().minimumZoomLevel(),
- mappingManager_->cameraCapabilities().maximumZoomLevel());
+
+ //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.
+ if (mappingManager_->cameraCapabilities().minimumZoomLevel() > gestureArea_->minimumZoomLevel())
+ setMinimumZoomLevel(mappingManager_->cameraCapabilities().minimumZoomLevel());
+
+ if (gestureArea_->maximumZoomLevel() < 0
+ || mappingManager_->cameraCapabilities().maximumZoomLevel() < gestureArea_->maximumZoomLevel())
+ setMaximumZoomLevel(mappingManager_->cameraCapabilities().maximumZoomLevel());
map_->setActiveMapType(QGeoMapType());
@@ -488,11 +495,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
copyrightsWPtr_.data(),
SLOT(copyrightsChanged(const QImage &, const QPoint &)));
- QGeoCameraCapabilities capabilities = mappingManager_->cameraCapabilities();
- if (zoomLevel_ < capabilities.minimumZoomLevel())
- setZoomLevel(capabilities.minimumZoomLevel());
- else if (zoomLevel_ > capabilities.maximumZoomLevel())
- setZoomLevel(capabilities.maximumZoomLevel());
connect(map_,
SIGNAL(updateRequired()),
this,
@@ -569,6 +571,23 @@ QDeclarativeGeoServiceProvider *QDeclarativeGeoMap::plugin() const
}
/*!
+ \internal
+ Sets the gesture areas minimum zoom level. If the camera capabilities
+ has been set this method honors the boundaries set by it.
+*/
+void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel)
+{
+ if (gestureArea_ && minimumZoomLevel >= 0) {
+ if (mappingManagerInitialized_
+ && minimumZoomLevel < mappingManager_->cameraCapabilities().minimumZoomLevel()) {
+ minimumZoomLevel = mappingManager_->cameraCapabilities().minimumZoomLevel();
+ }
+ gestureArea_->setMinimumZoomLevel(minimumZoomLevel);
+ setZoomLevel(qBound<qreal>(minimumZoomLevel, zoomLevel(), maximumZoomLevel()));
+ }
+}
+
+/*!
\qmlproperty real QtLocation::Map::minimumZoomLevel
This property holds the minimum valid zoom level for the map.
@@ -579,14 +598,33 @@ QDeclarativeGeoServiceProvider *QDeclarativeGeoMap::plugin() const
qreal QDeclarativeGeoMap::minimumZoomLevel() const
{
- if (mappingManager_ && mappingManagerInitialized_)
+ if (gestureArea_->minimumZoomLevel() != -1)
+ return gestureArea_->minimumZoomLevel();
+ else if (mappingManager_ && mappingManagerInitialized_)
return mappingManager_->cameraCapabilities().minimumZoomLevel();
else
return -1.0;
}
/*!
-\qmlproperty real QtLocation::Map::maximumZoomLevel
+ \internal
+ 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)
+{
+ if (gestureArea_ && maximumZoomLevel >= 0) {
+ if (mappingManagerInitialized_
+ && maximumZoomLevel > mappingManager_->cameraCapabilities().maximumZoomLevel()) {
+ maximumZoomLevel = mappingManager_->cameraCapabilities().maximumZoomLevel();
+ }
+ gestureArea_->setMaximumZoomLevel(maximumZoomLevel);
+ setZoomLevel(qBound<qreal>(minimumZoomLevel(), zoomLevel(), maximumZoomLevel));
+ }
+}
+
+/*!
+ \qmlproperty real QtLocation::Map::maximumZoomLevel
This property holds the maximum valid zoom level for the map.
@@ -596,7 +634,9 @@ qreal QDeclarativeGeoMap::minimumZoomLevel() const
qreal QDeclarativeGeoMap::maximumZoomLevel() const
{
- if (mappingManager_ && mappingManagerInitialized_)
+ if (gestureArea_->maximumZoomLevel() != -1)
+ return gestureArea_->maximumZoomLevel();
+ else if (mappingManager_ && mappingManagerInitialized_)
return mappingManager_->cameraCapabilities().maximumZoomLevel();
else
return -1.0;
@@ -690,13 +730,9 @@ void QDeclarativeGeoMap::setZoomLevel(qreal zoomLevel)
if (zoomLevel_ == zoomLevel || zoomLevel < 0)
return;
- if (mappingManagerInitialized_) {
- QGeoCameraCapabilities capabilities = mappingManager_->cameraCapabilities();
- if ((zoomLevel < capabilities.minimumZoomLevel() ||
- zoomLevel > capabilities.maximumZoomLevel())) {
- return;
- }
- }
+ if ((zoomLevel < minimumZoomLevel()
+ || (maximumZoomLevel() >= 0 && zoomLevel > maximumZoomLevel())))
+ return;
zoomLevel_ = zoomLevel;
if (mappingManagerInitialized_)
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 1305d96f..b024d006 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -99,8 +99,8 @@ class QDeclarativeGeoMap : public QQuickItem
Q_PROPERTY(QDeclarativeGeoMapGestureArea *gesture READ gesture CONSTANT)
Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
- Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel NOTIFY minimumZoomLevelChanged)
- Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel NOTIFY maximumZoomLevelChanged)
+ 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(QDeclarativeGeoMapType *activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged)
Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged)
@@ -131,7 +131,10 @@ public:
void setActiveMapType(QDeclarativeGeoMapType *mapType);
QDeclarativeGeoMapType *activeMapType() const;
+ void setMinimumZoomLevel(qreal minimumZoomLevel);
qreal minimumZoomLevel() const;
+
+ void setMaximumZoomLevel(qreal maximumZoomLevel);
qreal maximumZoomLevel() const;
void setZoomLevel(qreal zoomLevel);
diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp
index 9314b42b..87338136 100644
--- a/src/imports/location/qdeclarativegeomapgesturearea.cpp
+++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp
@@ -471,19 +471,45 @@ void QDeclarativeGeoMapGestureArea::setPanEnabled(bool enabled)
/*!
\internal
- called internally when plugin's limits change. somewhat dodgy but
- initialization order complicates the zoom limit settings a bit (for example when is
- it possible to check against mapping plugins' limits)
-*/
-void QDeclarativeGeoMapGestureArea::zoomLevelLimits(qreal min, qreal max)
+ Used internally to set the minimum zoom level of the gesture area.
+ The caller is responsible to only send values that are valid
+ for the map plugin. Negative values are ignored.
+ */
+void QDeclarativeGeoMapGestureArea::setMinimumZoomLevel(qreal min)
{
- if (pinch_.zoom.minimum == -1.0 || min > pinch_.zoom.minimum)
+ if (min >= 0)
pinch_.zoom.minimum = min;
- if (pinch_.zoom.maximum == -1.0 || max < pinch_.zoom.maximum)
+}
+
+/*!
+ \internal
+ */
+qreal QDeclarativeGeoMapGestureArea::minimumZoomLevel() const
+{
+ return pinch_.zoom.minimum;
+}
+
+/*!
+ \internal
+ Used internally to set the maximum zoom level of the gesture area.
+ The caller is responsible to only send values that are valid
+ for the map plugin. Negative values are ignored.
+ */
+void QDeclarativeGeoMapGestureArea::setMaximumZoomLevel(qreal max)
+{
+ if (max >= 0)
pinch_.zoom.maximum = max;
}
/*!
+ \internal
+ */
+qreal QDeclarativeGeoMapGestureArea::maximumZoomLevel() const
+{
+ return pinch_.zoom.maximum;
+}
+
+/*!
\internal
*/
qreal QDeclarativeGeoMapGestureArea::maximumZoomLevelChange() const
diff --git a/src/imports/location/qdeclarativegeomapgesturearea_p.h b/src/imports/location/qdeclarativegeomapgesturearea_p.h
index 0f0dc194..2bacc276 100644
--- a/src/imports/location/qdeclarativegeomapgesturearea_p.h
+++ b/src/imports/location/qdeclarativegeomapgesturearea_p.h
@@ -169,7 +169,12 @@ public:
bool filterMapChildMouseEvent(QMouseEvent *event);
bool filterMapChildTouchEvent(QTouchEvent *event);
- void zoomLevelLimits(qreal min, qreal max);
+ void setMinimumZoomLevel(qreal min);
+ qreal minimumZoomLevel() const;
+
+ void setMaximumZoomLevel(qreal max);
+ qreal maximumZoomLevel() const;
+
void setMap(QGeoMap *map);
Q_SIGNALS: