From 4511bc9b9bc85a0021ce59feab1a28c711dec691 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Thu, 8 Jun 2017 20:12:56 +0200 Subject: Add setPath overload to QDeclarativePolylineMapItem This patch adds a Q_INVOKABLE setPath overload that takes a QGeoPath. This can be beneficial when a path is already available and should be set without going through javascript array conversion. This method should come handy also when pushing polyline data from C++. [ChangeLog][QtLocation][MapPolyline] Added setPath overload taking a QGeoPath. Change-Id: I6916500473865b8234b48e8df08dfb465a2a75d2 Reviewed-by: Alex Blasche --- .../qdeclarativepolylinemapitem.cpp | 21 ++++++++++++ .../qdeclarativepolylinemapitem_p.h | 1 + tests/auto/declarative_ui/tst_map_item_details.qml | 38 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index aedb9811..72c43a49 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -606,6 +606,27 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value) setPathFromGeoList(pathList); } +/*! + \qmlmethod int MapPolyline::setPath(geopath path) + + Sets the \l path using a \l QGeoPath type. + + \since 5.10 + + \sa path +*/ +void QDeclarativePolylineMapItem::setPath(const QGeoPath &path) +{ + if (geopath_.path() == path.path()) + return; + + geopath_ = path; + regenerateCache(); + geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); + markSourceDirtyAndUpdate(); + emit pathChanged(); +} + /*! \internal */ diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h index ec57c980..6b3c42e9 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h @@ -141,6 +141,7 @@ public: QJSValue path() const; virtual void setPath(const QJSValue &value); + Q_INVOKABLE void setPath(const QGeoPath &path); bool contains(const QPointF &point) const Q_DECL_OVERRIDE; const QGeoShape &geoShape() const Q_DECL_OVERRIDE; diff --git a/tests/auto/declarative_ui/tst_map_item_details.qml b/tests/auto/declarative_ui/tst_map_item_details.qml index 80225c16..e7695288 100644 --- a/tests/auto/declarative_ui/tst_map_item_details.qml +++ b/tests/auto/declarative_ui/tst_map_item_details.qml @@ -156,6 +156,17 @@ Item { } } + MapPolyline { + id: polylineForSetpath + line.width: 3 + path: [ + { latitude: 20, longitude: 175 }, + { latitude: 20, longitude: -175 }, + { latitude: 10, longitude: -175 }, + { latitude: 10, longitude: 175 } + ] + } + MapPolyline { id: extMapPolylineDateline line.width : 3 @@ -395,6 +406,33 @@ Item { verify(extMapPolyline.path.length == 0) } + function test_polyline_setpath() + { + compare (polylineForSetpath.line.width, 3.0) + verify(polylineForSetpath.path.length == 4) + compare(polylineForSetpath.path[0], QtPositioning.coordinate(20, 175)) + compare(polylineForSetpath.path[3], QtPositioning.coordinate(10, 175)) + + + var originalPath = QtPositioning.shapeToPath(polylineForSetpath.geoShape) + + var geoPath = QtPositioning.path([ { latitude: 20, longitude: -15 }, + { latitude: 20, longitude: -5 }, + { latitude: 10, longitude: -5 }, + { latitude: 10, longitude: -15 }, + { latitude: 10, longitude: -105 } ], 50) + + polylineForSetpath.setPath(geoPath) + verify(polylineForSetpath.path.length == 5) + compare(polylineForSetpath.path[0], QtPositioning.coordinate(20, -15)) + compare(polylineForSetpath.path[3], QtPositioning.coordinate(10, -15)) + + polylineForSetpath.setPath(originalPath) + verify(polylineForSetpath.path.length == 4) + compare(polylineForSetpath.path[0], QtPositioning.coordinate(20, 175)) + compare(polylineForSetpath.path[3], QtPositioning.coordinate(10, 175)) + } + /* (0,0) ---------------------------------------------------- (600,0) -- cgit v1.2.1