summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-05-30 15:28:14 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-06-07 11:12:51 +0000
commite8dedcd7c621715813b7b954bb7f64c88aa6523d (patch)
tree087f958ceaa0cb920eb889389afa291454ca09ab
parentf55629245259ba7364e258f92408823024423caa (diff)
downloadqtlocation-e8dedcd7c621715813b7b954bb7f64c88aa6523d.tar.gz
Add QGeoPath::size
A way to retrieve the size of the path is missing, as the path property turns out not to be accessible to QML. This patch adds a Q_INVOKABLE method to expose it. [ChangeLog][QtPositioning][QGeoPath] Add ::size() to QGeoPath to retrieve the number of coordinates in the path. Change-Id: Ifa7a640113cba71f23e36626a84c8b2fe473a07e Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/positioning/qgeopath.cpp16
-rw-r--r--src/positioning/qgeopath.h1
-rw-r--r--src/positioning/qgeopath_p.h1
-rw-r--r--tests/auto/qgeopath/tst_qgeopath.cpp27
4 files changed, 45 insertions, 0 deletions
diff --git a/src/positioning/qgeopath.cpp b/src/positioning/qgeopath.cpp
index ad3536af..858dc0bd 100644
--- a/src/positioning/qgeopath.cpp
+++ b/src/positioning/qgeopath.cpp
@@ -247,6 +247,17 @@ double QGeoPath::length(int indexFrom, int indexTo) const
}
/*!
+ Returns the number of elements in the path.
+
+ \since 5.10
+*/
+int QGeoPath::size() const
+{
+ Q_D(const QGeoPath);
+ return d->size();
+}
+
+/*!
Appends \a coordinate to the path.
*/
void QGeoPath::addCoordinate(const QGeoCoordinate &coordinate)
@@ -415,6 +426,11 @@ double QGeoPathPrivate::length(int indexFrom, int indexTo) const
return len;
}
+int QGeoPathPrivate::size() const
+{
+ return m_path.size();
+}
+
/*!
Returns true if coordinate is present in m_path.
*/
diff --git a/src/positioning/qgeopath.h b/src/positioning/qgeopath.h
index 09a53a49..ad41c23c 100644
--- a/src/positioning/qgeopath.h
+++ b/src/positioning/qgeopath.h
@@ -78,6 +78,7 @@ public:
Q_INVOKABLE void translate(double degreesLatitude, double degreesLongitude);
Q_INVOKABLE QGeoPath translated(double degreesLatitude, double degreesLongitude) const;
Q_INVOKABLE double length(int indexFrom = 0, int indexTo = -1) const;
+ Q_INVOKABLE int size() 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);
diff --git a/src/positioning/qgeopath_p.h b/src/positioning/qgeopath_p.h
index 2256796d..48334017 100644
--- a/src/positioning/qgeopath_p.h
+++ b/src/positioning/qgeopath_p.h
@@ -85,6 +85,7 @@ public:
qreal width() const;
void setWidth(const qreal &width);
double length(int indexFrom, int indexTo) const;
+ int size() const;
void addCoordinate(const QGeoCoordinate &coordinate);
void insertCoordinate(int index, const QGeoCoordinate &coordinate);
void replaceCoordinate(int index, const QGeoCoordinate &coordinate);
diff --git a/tests/auto/qgeopath/tst_qgeopath.cpp b/tests/auto/qgeopath/tst_qgeopath.cpp
index 9244394a..86ff137d 100644
--- a/tests/auto/qgeopath/tst_qgeopath.cpp
+++ b/tests/auto/qgeopath/tst_qgeopath.cpp
@@ -47,6 +47,7 @@ private slots:
void path();
void width();
+ void size();
void translate_data();
void translate();
@@ -188,6 +189,32 @@ void tst_QGeoPath::width()
QCOMPARE(p.width(), qreal(10.0));
}
+void tst_QGeoPath::size()
+{
+ QList<QGeoCoordinate> coords;
+
+ QGeoPath p1(coords, 3);
+ QCOMPARE(p1.size(), coords.size());
+
+ coords.append(QGeoCoordinate(1,1));
+ QGeoPath p2(coords, 3);
+ QCOMPARE(p2.size(), coords.size());
+
+ coords.append(QGeoCoordinate(2,2));
+ QGeoPath p3(coords, 3);
+ QCOMPARE(p3.size(), coords.size());
+
+ coords.append(QGeoCoordinate(3,0));
+ QGeoPath p4(coords, 3);
+ QCOMPARE(p4.size(), coords.size());
+
+ p4.removeCoordinate(2);
+ QCOMPARE(p4.size(), coords.size() - 1);
+
+ p4.removeCoordinate(coords.first());
+ QCOMPARE(p4.size(), coords.size() - 2);
+}
+
void tst_QGeoPath::translate_data()
{
QTest::addColumn<QGeoCoordinate>("c1");