diff options
Diffstat (limited to 'src/location/declarativemaps')
8 files changed, 106 insertions, 51 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp index 43ce95a9..a73f9341 100644 --- a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp @@ -42,6 +42,7 @@ #include <QtPositioning/QGeoCircle> #include <QtLocation/QGeoServiceProvider> #include <QtLocation/QGeoCodingManager> +#include <QtLocation/private/qgeocodereply_p.h> #include <QtPositioning/QGeoPolygon> QT_BEGIN_NAMESPACE @@ -389,6 +390,7 @@ void QDeclarativeGeocodeModel::geocodeFinished(QGeoCodeReply *reply) reply->deleteLater(); reply_ = 0; int oldCount = declarativeLocations_.count(); + // const QVariantMap &extraData = QGeoCodeReplyPrivate::get(*reply)->extraData(); setLocations(reply->locations()); setError(NoError, QString()); setStatus(QDeclarativeGeocodeModel::Ready); diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel_p.h b/src/location/declarativemaps/qdeclarativegeocodemodel_p.h index 6c8f533b..e2361045 100644 --- a/src/location/declarativemaps/qdeclarativegeocodemodel_p.h +++ b/src/location/declarativemaps/qdeclarativegeocodemodel_p.h @@ -52,8 +52,8 @@ #include <QtLocation/private/qdeclarativegeoserviceprovider_p.h> #include <QtLocation/qgeocodereply.h> -#include <QtPositioning/private/qdeclarativegeoaddress_p.h> -#include <QtPositioning/private/qdeclarativegeolocation_p.h> +#include <QtPositioningQuick/private/qdeclarativegeoaddress_p.h> +#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h> #include <QtQml/qqml.h> #include <QtQml/QQmlParserStatus> diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index 63587efe..3c73ca12 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -1305,7 +1305,7 @@ void QDeclarativeGeoMap::setVisibleRegion(const QGeoShape &shape) return; } - fitViewportToGeoShape(); + fitViewportToGeoShape(m_visibleRegion); } QGeoShape QDeclarativeGeoMap::visibleRegion() const @@ -1445,39 +1445,6 @@ QMargins QDeclarativeGeoMap::mapMargins() const , height() - va.height() - va.y()); } -// TODO: offer the possibility to specify the margins. -void QDeclarativeGeoMap::fitViewportToGeoShape() -{ - if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) { - // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle, - // in order to honor animations on center and zoomLevel - const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); - const int borderSize = 10; - const QMargins borders(borderSize, borderSize, borderSize, borderSize); - - if (!m_map || !m_visibleRegion.isValid()) - return; - - const QMargins margins = borders + mapMargins(); - const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(m_visibleRegion, - margins); - if (!fitData.first.isValid()) - return; - - // position camera to the center of bounding box - setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property - - if (!qIsFinite(fitData.second)) - return; - double newZoom = qMax<double>(minimumZoomLevel(), fitData.second); - setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property - } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) { - // Animations cannot be honored in this case, as m_map acts as a black box - m_map->fitViewportToGeoRectangle(m_visibleRegion); - } -} - - /*! \qmlproperty list<MapType> QtLocation::Map::supportedMapTypes @@ -1604,6 +1571,64 @@ void QDeclarativeGeoMap::clearData() } /*! + \qmlmethod void QtLocation::Map::fitViewportToGeoShape(geoShape, margins) + + Fits the viewport to a specific geo shape. + The margins are in screen pixels. + + \note If the projection used by the plugin is not WebMercator, and the plugin does not have fitting to + shape capability, this method will do nothing. + + \sa visibleRegion + \since 5.13 +*/ +void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, QVariant margins) +{ + QMargins m(10, 10, 10, 10); // lets defaults to 10 if margins is invalid + switch (margins.type()) { + case QMetaType::Int: + case QMetaType::Double: { + const int value = int(margins.toDouble()); + m = QMargins(value, value, value, value); + } + break; + // ToDo: Support distinct margins in some QML form. Perhaps QRect? + default: + break; + } + fitViewportToGeoShape(shape, m); +} + +void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders) +{ + if (!m_map || !shape.isValid()) + return; + + if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) { + // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle, + // in order to honor animations on center and zoomLevel + const QMargins margins = borders + mapMargins(); + const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); + const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(shape.boundingGeoRectangle(), + margins); + if (!fitData.first.isValid()) + return; + + // position camera to the center of bounding box + setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property + + if (!qIsFinite(fitData.second)) + return; + double newZoom = qMax<double>(minimumZoomLevel(), fitData.second); + setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property + } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) { + // Animations cannot be honored in this case, as m_map acts as a black box + m_map->fitViewportToGeoRectangle(m_visibleRegion, borders); + } + // else out of luck +} + +/*! \qmlproperty string QtLocation::Map::errorString This read-only property holds the textual presentation of the latest mapping provider error. @@ -2205,7 +2230,7 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF Multiple fitViewportTo*() calls replace each other. */ if (m_pendingFitViewport && width() && height()) { - fitViewportToGeoShape(); + fitViewportToGeoShape(m_visibleRegion); m_pendingFitViewport = false; } diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h index f59f6f54..3cbefe79 100644 --- a/src/location/declarativemaps/qdeclarativegeomap_p.h +++ b/src/location/declarativemaps/qdeclarativegeomap_p.h @@ -198,6 +198,8 @@ public: Q_INVOKABLE void pan(int dx, int dy); Q_INVOKABLE void prefetchData(); // optional hint for prefetch Q_INVOKABLE void clearData(); + Q_INVOKABLE void fitViewportToGeoShape(const QGeoShape &shape, QVariant margins); + void fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders = QMargins(10, 10, 10, 10)); QString errorString() const; QGeoServiceProvider::Error error() const; @@ -278,7 +280,6 @@ private: void populateMap(); void populateParameters(); void fitViewportToMapItemsRefine(bool refine, bool onlyVisible); - void fitViewportToGeoShape(); bool isInteractive(); void attachCopyrightNotice(bool initialVisibility); void detachCopyrightNotice(bool currentVisibility); diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp index 09ed46ab..64aeb656 100644 --- a/src/location/declarativemaps/qdeclarativegeoroute.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp @@ -352,6 +352,35 @@ QList<QObject *> QDeclarativeGeoRoute::legs() } /*! + \qmlproperty Object Route::extendedAttributes + + This property holds the extended attributes of the route and is a map. + These attributes are plugin specific, and can be empty. + + Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation} + for what attributes are supported and how they should be used. + + Note, due to limitations of the QQmlPropertyMap, it is not possible + to declaratively specify the attributes in QML, assignment of attributes keys + and values can only be accomplished by JavaScript. + + \since QtLocation 5.13 +*/ +QQmlPropertyMap *QDeclarativeGeoRoute::extendedAttributes() const +{ + if (!m_extendedAttributes) { + QDeclarativeGeoRoute *self = const_cast<QDeclarativeGeoRoute *>(this); + self->m_extendedAttributes = new QQmlPropertyMap(self); + // Fill it + const QVariantMap &xAttrs = route_.extendedAttributes(); + const QStringList &keys = xAttrs.keys(); + for (const QString &key: keys) + self->m_extendedAttributes->insert(key, xAttrs.value(key)); + } + return m_extendedAttributes; +} + +/*! \qmlmethod bool QtLocation::Route::equals(Route other) This method performs deep comparison. diff --git a/src/location/declarativemaps/qdeclarativegeoroute_p.h b/src/location/declarativemaps/qdeclarativegeoroute_p.h index 98d08e98..767e21ea 100644 --- a/src/location/declarativemaps/qdeclarativegeoroute_p.h +++ b/src/location/declarativemaps/qdeclarativegeoroute_p.h @@ -69,6 +69,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoRoute : public QObject Q_PROPERTY(QQmlListProperty<QDeclarativeGeoRouteSegment> segments READ segments CONSTANT) Q_PROPERTY(QDeclarativeGeoRouteQuery *routeQuery READ routeQuery REVISION 11) Q_PROPERTY(QList<QObject *> legs READ legs CONSTANT REVISION 12) + Q_PROPERTY(QObject *extendedAttributes READ extendedAttributes CONSTANT REVISION 12) public: explicit QDeclarativeGeoRoute(QObject *parent = 0); @@ -91,6 +92,7 @@ public: const QGeoRoute &route() const; QDeclarativeGeoRouteQuery *routeQuery(); QList<QObject *> legs(); + QQmlPropertyMap *extendedAttributes() const; Q_INVOKABLE bool equals(QDeclarativeGeoRoute *other) const; @@ -111,6 +113,8 @@ private: QList<QDeclarativeGeoRouteSegment *> segments_; QList<QObject *> legs_; bool segmentsDirty_ = true; + QQmlPropertyMap *m_extendedAttributes = nullptr; + friend class QDeclarativeRouteMapItem; }; diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp index f4cdc6bf..23ea5666 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp @@ -50,6 +50,7 @@ #include <QtPositioning/private/qdoublevector2d_p.h> #include <QtPositioning/private/qclipperutils_p.h> +#include <QtPositioning/private/qgeopolygon_p.h> /* poly2tri triangulator includes */ #include <clip2tri.h> @@ -318,6 +319,7 @@ QDeclarativePolygonMapItem::QDeclarativePolygonMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), border_(this), color_(Qt::transparent), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPolygonEager(); setFlag(ItemHasContents, true); QObject::connect(&border_, SIGNAL(colorChanged(QColor)), this, SLOT(markSourceDirtyAndUpdate())); @@ -611,7 +613,7 @@ void QDeclarativePolygonMapItem::setGeoShape(const QGeoShape &shape) if (shape == geopath_) return; - geopath_ = shape; + geopath_ = QGeoPathEager(shape); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); borderGeometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index 2fb3098d..2bed0896 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -54,6 +54,7 @@ #include <QtGui/private/qtriangulator_p.h> #include <QtPositioning/private/qclipperutils_p.h> +#include <QtPositioning/private/qgeopath_p.h> #include <array> QT_BEGIN_NAMESPACE @@ -738,6 +739,7 @@ bool QGeoMapPolylineGeometry::contains(const QPointF &point) const QDeclarativePolylineMapItem::QDeclarativePolylineMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), line_(this), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPathEager(); setFlag(ItemHasContents, true); QObject::connect(&line_, SIGNAL(colorChanged(QColor)), this, SLOT(updateAfterLinePropertiesChanged())); @@ -806,7 +808,7 @@ void QDeclarativePolylineMapItem::setPath(const QGeoPath &path) if (geopath_.path() == path.path()) return; - geopath_ = path; + geopath_ = QGeoPathEager(path); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); markSourceDirtyAndUpdate(); @@ -1135,18 +1137,8 @@ const QGeoShape &QDeclarativePolylineMapItem::geoShape() const void QDeclarativePolylineMapItem::setGeoShape(const QGeoShape &shape) { - if (shape == geopath_) - return; - const QGeoPath geopath(shape); // if shape isn't a path, path will be created as a default-constructed path - const bool pathHasChanged = geopath.path() != geopath_.path(); - geopath_ = geopath; - - regenerateCache(); - geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); - markSourceDirtyAndUpdate(); - if (pathHasChanged) - emit pathChanged(); + setPath(geopath); } QGeoMap::ItemType QDeclarativePolylineMapItem::itemType() const |