diff options
Diffstat (limited to 'src/imports/location/qdeclarativegeomap.cpp')
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 139 |
1 files changed, 131 insertions, 8 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 0450bf56..d432e776 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -42,6 +42,7 @@ #include "qgeomappingmanager_p.h" #include "qgeocameracapabilities_p.h" #include "qgeomap_p.h" +#include "qdeclarativegeomapparameter_p.h" #include <QtPositioning/QGeoCircle> #include <QtPositioning/QGeoRectangle> #include <QtQuick/QQuickWindow> @@ -158,7 +159,6 @@ static const qreal EARTH_MEAN_RADIUS = 6371007.2; QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) : QQuickItem(parent), m_plugin(0), - m_serviceProvider(0), m_mappingManager(0), m_activeMapType(0), m_gestureArea(new QQuickGeoMapGestureArea(this)), @@ -331,11 +331,11 @@ void QDeclarativeGeoMap::initialize() */ void QDeclarativeGeoMap::pluginReady() { - m_serviceProvider = m_plugin->sharedGeoServiceProvider(); - m_mappingManager = m_serviceProvider->mappingManager(); + QGeoServiceProvider *provider = m_plugin->sharedGeoServiceProvider(); + m_mappingManager = provider->mappingManager(); - if (m_serviceProvider->error() != QGeoServiceProvider::NoError) { - setError(m_serviceProvider->error(), m_serviceProvider->errorString()); + if (provider->error() != QGeoServiceProvider::NoError) { + setError(provider->error(), provider->errorString()); return; } @@ -360,6 +360,7 @@ void QDeclarativeGeoMap::pluginReady() void QDeclarativeGeoMap::componentComplete() { m_componentCompleted = true; + populateParameters(); populateMap(); QQuickItem::componentComplete(); } @@ -455,6 +456,19 @@ void QDeclarativeGeoMap::populateMap() } } +void QDeclarativeGeoMap::populateParameters() +{ + QObjectList kids = children(); + QList<QQuickItem *> quickKids = childItems(); + for (int i = 0; i < quickKids.count(); ++i) + kids.append(quickKids.at(i)); + for (int i = 0; i < kids.size(); ++i) { + QDeclarativeGeoMapParameter *mapParameter = qobject_cast<QDeclarativeGeoMapParameter *>(kids.at(i)); + if (mapParameter) + addMapParameter(mapParameter); + } +} + /*! \internal */ @@ -590,6 +604,11 @@ void QDeclarativeGeoMap::mappingManagerInitialized() if (item) item.data()->setMap(this, m_map); } + + // All map parameters that were added before the plugin was ready + // need to be added to m_map + for (QDeclarativeGeoMapParameter *p : m_mapParameters) + m_map->addParameter(p); } /*! @@ -803,7 +822,7 @@ void QDeclarativeGeoMap::setVisibleRegion(const QGeoShape &shape) return; } - if (!width() || !height()) { + if (!m_map || !width() || !height()) { m_pendingFitViewport = true; return; } @@ -1210,6 +1229,95 @@ void QDeclarativeGeoMap::addMapItem(QDeclarativeGeoMapItemBase *item) } /*! + \qmlmethod void QtLocation::Map::addMapParameter(MapParameter parameter) + + Adds a MapParameter object to the map. The effect of this call is dependent + on the combination of the content of the MapParameter and the type of + underlying QGeoMap. If a MapParameter that is not supported by the underlying + QGeoMap gets added, the call has no effect. + + The release of this API with Qt 5.9 is a Technology Preview. + + \sa MapParameter, removeMapParameter, mapParameters, clearMapParameters + + \since 5.9 +*/ +void QDeclarativeGeoMap::addMapParameter(QDeclarativeGeoMapParameter *parameter) +{ + if (!parameter->isComponentComplete()) { + connect(parameter, &QDeclarativeGeoMapParameter::completed, this, &QDeclarativeGeoMap::addMapParameter); + return; + } + + disconnect(parameter); + if (m_mapParameters.contains(parameter)) + return; + parameter->setParent(this); + m_mapParameters.insert(parameter); // parameter now owned by QDeclarativeGeoMap + if (m_map) + m_map->addParameter(parameter); +} + +/*! + \qmlmethod void QtLocation::Map::removeMapParameter(MapParameter parameter) + + Removes the given MapParameter object from the map. + + The release of this API with Qt 5.9 is a Technology Preview. + + \sa MapParameter, addMapParameter, mapParameters, clearMapParameters + + \since 5.9 +*/ +void QDeclarativeGeoMap::removeMapParameter(QDeclarativeGeoMapParameter *parameter) +{ + if (!m_mapParameters.contains(parameter)) + return; + if (m_map) + m_map->removeParameter(parameter); + m_mapParameters.remove(parameter); +} + +/*! + \qmlmethod void QtLocation::Map::clearMapParameters() + + Removes all map parameters from the map. + + The release of this API with Qt 5.9 is a Technology Preview. + + \sa MapParameter, mapParameters, addMapParameter, removeMapParameter, clearMapParameters + + \since 5.9 +*/ +void QDeclarativeGeoMap::clearMapParameters() +{ + if (m_map) + m_map->clearParameters(); + m_mapParameters.clear(); +} + +/*! + \qmlproperty list<MapParameters> QtLocation::Map::mapParameters + + Returns the list of all map parameters in no particular order. + These items include map parameters that were declared statically as part of + the type declaration, as well as dynamical map parameters (\l addMapParameter). + + The release of this API with Qt 5.9 is a Technology Preview. + + \sa MapParameter, addMapParameter, removeMapParameter, clearMapParameters + + \since 5.9 +*/ +QList<QObject *> QDeclarativeGeoMap::mapParameters() +{ + QList<QObject *> ret; + for (QDeclarativeGeoMapParameter *p : m_mapParameters) + ret << p; + return ret; +} + +/*! \qmlproperty list<MapItem> QtLocation::Map::mapItems Returns the list of all map items in no particular order. @@ -1312,11 +1420,26 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF m_map->setViewportSize(newGeometry.size().toSize()); - if (!m_initialized) + if (!m_initialized) { initialize(); - else + } else { setMinimumZoomLevel(m_map->minimumZoomAtViewportSize(newGeometry.width(), newGeometry.height())); + // Update the center latitudinal threshold + double maximumCenterLatitudeAtZoom = m_map->maximumCenterLatitudeAtZoom(m_cameraData.zoomLevel()); + if (maximumCenterLatitudeAtZoom != m_maximumViewportLatitude) { + m_maximumViewportLatitude = maximumCenterLatitudeAtZoom; + QGeoCoordinate coord = m_cameraData.center(); + coord.setLatitude(qBound(-m_maximumViewportLatitude, coord.latitude(), m_maximumViewportLatitude)); + + if (coord != m_cameraData.center()) { + m_cameraData.setCenter(coord); + m_map->setCameraData(m_cameraData); + emit centerChanged(m_cameraData.center()); + } + } + } + /*! The fitViewportTo*() functions depend on a valid map geometry. If they were called prior to the first resize they cause |