summaryrefslogtreecommitdiffstats
path: root/app/qcheapruler.cpp
diff options
context:
space:
mode:
authorwanglu <wang_lu@dl.cn.nexty-ele.com>2019-03-25 09:42:49 +0800
committerwanglu <wang_lu@dl.cn.nexty-ele.com>2019-03-25 09:52:02 +0800
commit4a8b7a6301e4b093c99329d0a16fbee6c535f312 (patch)
treefe9f589e1723e8f173b50dfa617374042f4cf7a7 /app/qcheapruler.cpp
parentfb539bbd9f7b36d26cd56fe09b804e18b3b3d984 (diff)
Change-Id: I0866a7d9ffa347c0935b4d00259ad1a74cd00d6e Signed-off-by: wanglu <wang_lu@dl.cn.nexty-ele.com>
Diffstat (limited to 'app/qcheapruler.cpp')
-rw-r--r--app/qcheapruler.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/app/qcheapruler.cpp b/app/qcheapruler.cpp
new file mode 100644
index 0000000..890fd63
--- /dev/null
+++ b/app/qcheapruler.cpp
@@ -0,0 +1,117 @@
+#include "qcheapruler.hpp"
+#include "naviapi_adaptor.h"
+
+#include <QString>
+
+QCheapRuler::QCheapRuler()
+{
+ //set the default current position
+ // m_currentPosition = QGeoCoordinate(36.136261, -115.151254);
+ m_currentPosition = QGeoCoordinate(35.692396, 139.691102);
+}
+
+QCheapRuler::~QCheapRuler()
+{
+}
+
+//get route distance
+double QCheapRuler::distance() const
+{
+ return m_distance;
+}
+
+//get current distance along the route
+double QCheapRuler::currentDistance() const
+{
+ return m_currentDistance;
+}
+
+//set current position below the coordinate info from navigation service
+void QCheapRuler::setCurrentPosition(double latitude, double longitude)
+{
+ //set coordinate info and notify the changes when latitude or longitude info has changed
+ if((m_currentPosition.latitude() != latitude)
+ ||(m_currentPosition.longitude() != longitude))
+ {
+ m_currentPosition.setLatitude(latitude);
+ m_currentPosition.setLongitude(longitude);
+ emit currentPositionChanged();
+ }
+}
+
+void QCheapRuler::setCurrentDistance(double distance)
+{
+ //set current distance info and notify the changes when the info has changed
+ //but it will not send notify when it start or stop demo
+ if((m_currentDistance != distance)
+ &&(distance != 0.0))
+ {
+ m_currentDistance = distance;
+ emit currentDistanceChanged();
+ }
+}
+
+//get current position(coordinate)
+QGeoCoordinate QCheapRuler::currentPosition() const
+{
+ return m_currentPosition;
+}
+
+QJSValue QCheapRuler::path() const
+{
+ // Should neveer be called.
+ return QJSValue();
+}
+
+//set route path and get the total distance
+void QCheapRuler::setPath(const QJSValue &value)
+{
+ if (!value.isArray())
+ return;
+
+ m_path.clear();
+ quint32 length = value.property(QStringLiteral("length")).toUInt();
+
+ //push back the coordinate info along the route
+ for (unsigned i = 0; i < length; ++i) {
+ auto property = value.property(i);
+ cr::point coordinate = { 0., 0. };
+
+ if (property.hasProperty(QStringLiteral("latitude")))
+ coordinate.y = property.property(QStringLiteral("latitude")).toNumber();
+
+ if (property.hasProperty(QStringLiteral("longitude")))
+ coordinate.x = property.property(QStringLiteral("longitude")).toNumber();
+
+ m_path.push_back(coordinate);
+ }
+
+ //count the total distance along the route
+ double distance = ruler().lineDistance(m_path);
+ if (m_distance != distance) {
+ m_distance = distance;
+ }
+
+ emit pathChanged();
+}
+
+//init the route and postion info when start in the first time.(can be called by qml)
+void QCheapRuler::initRouteInfo()
+{
+ //send "getRouteInfo" message to the navigation service
+ QDBusMessage message = QDBusMessage::createSignal("/", "org.agl.naviapi", "getRouteInfo");
+ if(!QDBusConnection::sessionBus().send(message))
+ {
+ qDebug() << "initRouteInfo" << "sessionBus.send(): getRouteInfo failed";
+ }
+}
+
+//init the CheapRuler class
+cr::CheapRuler QCheapRuler::ruler() const
+{
+ if (m_path.empty()) {
+ return cr::CheapRuler(0., cr::CheapRuler::Kilometers);
+ } else {
+ return cr::CheapRuler(m_currentPosition.latitude(), cr::CheapRuler::Kilometers);
+ }
+}