summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Meyer <dev@meh.at>2015-12-02 09:21:05 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-12-14 12:09:30 +0000
commitd75c0469c05809a4c6ff85a4c78784b397cbfcc0 (patch)
tree7db7582193abd015aa5fa8cfa4ea4ab657120b3b
parent6976c13e327bb739f44b650ac9998e2e56c910f1 (diff)
downloadqtlocation-d75c0469c05809a4c6ff85a4c78784b397cbfcc0.tar.gz
Added methods for modifying QDeclarativePolylineMapItem.v5.6.0-beta1
Added the methods insertCoordinate(index, coordinate), replaceCoordinate(index, coordinate), removeCoordinate(index), pathLength(), coordinateAt(index) to the QDeclarativePolylineMapItem. Change-Id: I8b1f7e01cf814fe6fdb9f2da376793891514b5f0 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem.cpp117
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem_p.h6
-rw-r--r--tests/auto/declarative_geoshape/tst_locationsingleton.qml59
3 files changed, 177 insertions, 5 deletions
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp
index 71a205d3..0708fe2d 100644
--- a/src/imports/location/qdeclarativepolylinemapitem.cpp
+++ b/src/imports/location/qdeclarativepolylinemapitem.cpp
@@ -534,7 +534,6 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value)
setPathFromGeoList(pathList);
}
-
/*!
\internal
*/
@@ -551,13 +550,26 @@ void QDeclarativePolylineMapItem::setPathFromGeoList(const QList<QGeoCoordinate>
}
/*!
- \qmlmethod void MapPolyline::addCoordinate(coordinate)
+ \qmlmethod int MapPolyline::pathLength()
+
+ Returns the number of coordinates of the polyline.
- Adds a coordinate to the path.
+ \since Qt Location 5.6
- \sa removeCoordinate, path
+ \sa path
*/
+int QDeclarativePolylineMapItem::pathLength() const
+{
+ return path_.size();
+}
+
+/*!
+ \qmlmethod void MapPolyline::addCoordinate(coordinate)
+
+ Adds a coordinate to the end of the path.
+ \sa insertCoordinate, removeCoordinate, path
+*/
void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate)
{
path_.append(coordinate);
@@ -568,6 +580,78 @@ void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate
}
/*!
+ \qmlmethod void MapPolyline::insertCoordinate(index, coordinate)
+
+ Inserts a \a coordinate to the path at the given \a index.
+
+ \since Qt Location 5.6
+
+ \sa addCoordinate, removeCoordinate, path
+*/
+void QDeclarativePolylineMapItem::insertCoordinate(int index, const QGeoCoordinate &coordinate)
+{
+ if (index < 0 || index > path_.size())
+ return;
+
+ path_.insert(index, coordinate);
+
+ geometry_.markSourceDirty();
+ polishAndUpdate();
+ emit pathChanged();
+}
+
+/*!
+ \qmlmethod void MapPolyline::replaceCoordinate(index, coordinate)
+
+ Replaces the coordinate in the current path at the given \a index
+ with the new \a coordinate.
+
+ \since Qt Location 5.6
+
+ \sa addCoordinate, insertCoordinate, removeCoordinate, path
+*/
+void QDeclarativePolylineMapItem::replaceCoordinate(int index, const QGeoCoordinate &coordinate)
+{
+ if (index < 0 || index >= path_.size())
+ return;
+
+ path_[index] = coordinate;
+
+ geometry_.markSourceDirty();
+ polishAndUpdate();
+ emit pathChanged();
+}
+
+/*!
+ \qmlmethod coordinate MapPolyline::coordinateAt(index)
+
+ Gets the coordinate of the polyline at the given \a index.
+ If the index is outside the path's bounds then an invalid
+ coordinate is returned.
+
+ \since Qt Location 5.6
+*/
+QGeoCoordinate QDeclarativePolylineMapItem::coordinateAt(int index) const
+{
+ if (index < 0 || index >= path_.size())
+ return QGeoCoordinate();
+
+ return path_.at(index);
+}
+
+/*!
+ \qmlmethod coordinate MapPolyline::containsCoordinate(coordinate)
+
+ Returns true if the given \a coordinate is part of the path.
+
+ \since Qt Location 5.6
+*/
+bool QDeclarativePolylineMapItem::containsCoordinate(const QGeoCoordinate &coordinate)
+{
+ return path_.indexOf(coordinate) > -1;
+}
+
+/*!
\qmlmethod void MapPolyline::removeCoordinate(coordinate)
Removes \a coordinate from the path. If there are multiple instances of the
@@ -575,7 +659,7 @@ void QDeclarativePolylineMapItem::addCoordinate(const QGeoCoordinate &coordinate
If \a coordinate is not in the path this method does nothing.
- \sa addCoordinate, path
+ \sa addCoordinate, insertCoordinate, path
*/
void QDeclarativePolylineMapItem::removeCoordinate(const QGeoCoordinate &coordinate)
{
@@ -591,6 +675,29 @@ void QDeclarativePolylineMapItem::removeCoordinate(const QGeoCoordinate &coordin
}
/*!
+ \qmlmethod void MapPolyline::removeCoordinate(index)
+
+ Removes a coordinate from the path at the given \a index.
+
+ If \a index is invalid then this method does nothing.
+
+ \since Qt Location 5.6
+
+ \sa addCoordinate, insertCoordinate, path
+*/
+void QDeclarativePolylineMapItem::removeCoordinate(int index)
+{
+ if (index < 0 || index >= path_.size())
+ return;
+
+ path_.removeAt(index);
+
+ geometry_.markSourceDirty();
+ polishAndUpdate();
+ emit pathChanged();
+}
+
+/*!
\qmlpropertygroup Location::MapPolyline::line
\qmlproperty int MapPolyline::line.width
\qmlproperty color MapPolyline::line.color
diff --git a/src/imports/location/qdeclarativepolylinemapitem_p.h b/src/imports/location/qdeclarativepolylinemapitem_p.h
index a7b7f167..298dc3bc 100644
--- a/src/imports/location/qdeclarativepolylinemapitem_p.h
+++ b/src/imports/location/qdeclarativepolylinemapitem_p.h
@@ -116,8 +116,14 @@ public:
//from QuickItem
virtual QSGNode *updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE;
+ Q_INVOKABLE int pathLength() const;
Q_INVOKABLE void addCoordinate(const QGeoCoordinate &coordinate);
+ Q_INVOKABLE void insertCoordinate(int index, const QGeoCoordinate &coordinate);
+ Q_INVOKABLE void replaceCoordinate(int index, const QGeoCoordinate &coordinate);
+ Q_INVOKABLE QGeoCoordinate coordinateAt(int index) const;
+ Q_INVOKABLE bool containsCoordinate(const QGeoCoordinate &coordinate);
Q_INVOKABLE void removeCoordinate(const QGeoCoordinate &coordinate);
+ Q_INVOKABLE void removeCoordinate(int index);
QJSValue path() const;
virtual void setPath(const QJSValue &value);
diff --git a/tests/auto/declarative_geoshape/tst_locationsingleton.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
index f01ee5e2..5e37d9eb 100644
--- a/tests/auto/declarative_geoshape/tst_locationsingleton.qml
+++ b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
@@ -34,6 +34,7 @@
import QtQuick 2.0
import QtTest 1.0
import QtPositioning 5.2
+import QtLocation 5.5
Item {
id: testCase
@@ -191,4 +192,62 @@ Item {
verify(rectangle.isValid)
}
}
+
+
+ MapPolyline {
+ id: mapPolyline
+ path: [
+ { latitude: -27, longitude: 153.0 },
+ { latitude: -27, longitude: 154.1 },
+ { latitude: -28, longitude: 153.5 },
+ { latitude: -29, longitude: 153.5 }
+ ]
+ }
+
+ TestCase {
+ name: "MapPolyline path"
+ function test_path_operations() {
+ compare(mapPolyline.path[1].latitude, -27)
+ compare(mapPolyline.path[1].longitude, 154.1)
+ compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(27, 154.1))
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.removeCoordinate(1);
+ compare(mapPolyline.path[1].latitude, -28)
+ compare(mapPolyline.path[1].longitude, 153.5)
+ compare(mapPolyline.coordinateAt(1), QtPositioning.coordinate(-28, 153.5))
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.addCoordinate(QtPositioning.coordinate(30, 153.1))
+ compare(mapPolyline.path[mapPolyline.path.length-1].latitude, 30)
+ compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.1)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), true)
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.removeCoordinate(QtPositioning.coordinate(30, 153.1))
+ compare(mapPolyline.path[mapPolyline.path.length-1].latitude, -29)
+ compare(mapPolyline.path[mapPolyline.path.length-1].longitude, 153.5)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(30, 153.1)), false)
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1))
+ compare(mapPolyline.path[2].latitude, 35)
+ compare(mapPolyline.path[2].longitude, 153.1)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true)
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.replaceCoordinate(2, QtPositioning.coordinate(45, 150.1))
+ compare(mapPolyline.path[2].latitude, 45)
+ compare(mapPolyline.path[2].longitude, 150.1)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), false)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(45, 150.1)), true)
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+
+ mapPolyline.insertCoordinate(2, QtPositioning.coordinate(35, 153.1))
+ compare(mapPolyline.coordinateAt(2).latitude, 35)
+ compare(mapPolyline.coordinateAt(2).longitude, 153.1)
+ compare(mapPolyline.containsCoordinate(QtPositioning.coordinate(35, 153.1)), true)
+ compare(mapPolyline.path.length, mapPolyline.pathLength())
+ }
+ }
}