Re-factored routing to use the new coordinate classes
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 27 Jul 2010 10:37:05 +0000 (13:37 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 27 Jul 2010 10:37:05 +0000 (13:37 +0300)
 - Reviewed by Jussi Laitinen

 - modified Route, RoutingService & MapRouteItem

src/map/mapengine.cpp
src/map/maprouteitem.cpp
src/routing/route.cpp
src/routing/route.h
src/routing/routingservice.cpp
src/routing/routingservice.h
tests/routing/route/route.pro
tests/routing/route/testroute.cpp

index 7484fbf..0edebee 100644 (file)
@@ -468,8 +468,8 @@ void MapEngine::setRoute(Route &route)
     qDebug() << __PRETTY_FUNCTION__ << "distance:" << m_route.totalDistance();
     qDebug() << __PRETTY_FUNCTION__ << "estimated time:" << m_route.totalTime();
 
-    foreach (QPointF point, m_route.geometryPoints())
-        qDebug() << __PRETTY_FUNCTION__ << "geometry point:" << point.x() << point.y();
+    foreach (GeoCoordinate point, m_route.geometryPoints())
+        qDebug() << __PRETTY_FUNCTION__ << "geometry point:" << point;
 
     foreach (RouteSegment segment, m_route.segments()) {
         qDebug() << __PRETTY_FUNCTION__ << "segment:" << segment.instruction();
index 02129cb..0427d4d 100644 (file)
@@ -61,14 +61,12 @@ void MapRouteItem::setRoute(Route *route)
     pen.setColor(LINE_COLOR);
     pen.setCosmetic(true);
 
-    QList<QPointF> points = route->geometryPoints();
+    QList<GeoCoordinate> points = route->geometryPoints();
     for (int i = 1; i < points.count(); i++) {
-        GeoCoordinate begin = GeoCoordinate(points.at(i - 1).y(), points.at(i - 1).x());
-        SceneCoordinate sceneBegin = SceneCoordinate(begin);
-        GeoCoordinate end = GeoCoordinate(points.at(i).y(), points.at(i).x());
-        SceneCoordinate sceneEnd = SceneCoordinate(end);
-        QGraphicsLineItem *line = new QGraphicsLineItem(QLineF(sceneBegin.toPointF(),
-                                                               sceneEnd.toPointF()));
+        SceneCoordinate begin = SceneCoordinate(points.at(i - 1));
+        SceneCoordinate end = SceneCoordinate(points.at(i));
+        QGraphicsLineItem *line = new QGraphicsLineItem(QLineF(begin.toPointF(),
+                                                               end.toPointF()));
         line->setPen(pen);
         addToGroup(line);
     }
index 0e8d1ac..7213149 100644 (file)
@@ -32,7 +32,7 @@ Route::Route()
     qDebug() << __PRETTY_FUNCTION__;
 }
 
-void Route::appendGeometryPoint(QPointF geometryPoint)
+void Route::appendGeometryPoint(GeoCoordinate geometryPoint)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -53,7 +53,7 @@ const QString& Route::endPointName() const
     return m_endPointName;
 }
 
-const QList<QPointF>& Route::geometryPoints() const
+const QList<GeoCoordinate>& Route::geometryPoints() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index 08e52f2..76ac3dc 100644 (file)
@@ -24,9 +24,9 @@
 #define ROUTE_H
 
 #include <QList>
-#include <QPointF>
 #include <QString>
 
+#include "coordinates/geocoordinate.h"
 #include "routesegment.h"
 
 /**
@@ -52,7 +52,7 @@ public:
     *
     * @param geometryPoint Geometry point
     */
-    void appendGeometryPoint(QPointF geometryPoint);
+    void appendGeometryPoint(GeoCoordinate geometryPoint);
 
     /**
     * @brief Append a route segment to the route
@@ -76,7 +76,7 @@ public:
     *
     * @returns Reference to list of geometry points
     */
-    const QList<QPointF>& geometryPoints() const;
+    const QList<GeoCoordinate>& geometryPoints() const;
 
     /**
     * @brief Get list of route segments
@@ -138,7 +138,7 @@ private:
     int m_totalDistance;                ///< route total distance in meters
     int m_totalTime;                    ///< estimated route total time in seconds
 
-    QList<QPointF> m_geometryPoints;    ///< lat/lon coordinates of the route points
+    QList<GeoCoordinate> m_geometryPoints;    ///< lat/lon coordinates of the route points
     QList<RouteSegment> m_segments;     ///< route segments
 
     QString m_endPointName;             ///< name of the route end point
index 678145d..e484af4 100644 (file)
@@ -24,7 +24,6 @@
 #include <QtGlobal>
 #include <QStringList>
 #include <QNetworkReply>
-#include <QPointF>
 #include <QCryptographicHash>
 
 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
@@ -33,6 +32,7 @@
 #endif
 
 #include "common.h"
+#include "coordinates/geocoordinate.h"
 #include "network/networkaccessmanager.h"
 #include "parser.h"
 #include "route.h"
@@ -90,7 +90,8 @@ void RoutingService::parseRouteData(const QByteArray &jsonReply)
 
             foreach(QVariant routeGeometry, result["route_geometry"].toList()) {
                 QStringList list = routeGeometry.toStringList();
-                route.appendGeometryPoint(QPointF(list.at(1).toDouble(), list.at(0).toDouble()));
+                route.appendGeometryPoint(GeoCoordinate(list.at(0).toDouble(),
+                                                        list.at(1).toDouble()));
             }
 
             foreach(QVariant routeInstructions, result["route_instructions"].toList()) {
@@ -177,15 +178,15 @@ void RoutingService::requestFinished(QNetworkReply *reply)
     }
 }
 
-void RoutingService::requestRoute(QPointF from, QPointF to)
+void RoutingService::requestRoute(GeoCoordinate from, GeoCoordinate to)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     QString url = "http://routes.cloudmade.com/";
     url.append(CLOUDMADE_API_KEY);
     url.append("/api/0.3/");
-    url.append(QString::number(from.x()) + "," + QString::number(from.y()) + ",");
-    url.append(QString::number(to.x()) + "," + QString::number(to.y()));
+    url.append(QString::number(from.latitude()) + "," + QString::number(from.longitude()) + ",");
+    url.append(QString::number(to.latitude()) + "," + QString::number(to.longitude()));
     url.append("/car/fastest.js?lang=en&units=km&token=");
 
     if(m_token.isEmpty()) {
index 1012593..b94b1bf 100644 (file)
@@ -32,6 +32,8 @@ class QNetworkReply;
 class QNetworkRequest;
 class QUrl;
 
+class GeoCoordinate;
+
 /**
 * @brief RoutingService class for communicating with CloudMade server
 *        and parsing routing data
@@ -70,7 +72,7 @@ public slots:
     * @param from Start point of the route
     * @param to End point of the route
     */
-    void requestRoute(QPointF from, QPointF to);
+    void requestRoute(GeoCoordinate from, GeoCoordinate to);
 
 private:
 
index 64df984..700a3b2 100644 (file)
@@ -16,7 +16,9 @@ TEMPLATE = app
 
 SOURCES += testroute.cpp \
     ../../../src/routing/route.cpp \
-    ../../../src/routing/routesegment.cpp
+    ../../../src/routing/routesegment.cpp \
+    ../../../src/coordinates/scenecoordinate.cpp \
+    ../../../src/coordinates/geocoordinate.cpp
 DEFINES += SRCDIR=\\\"$$PWD/\\\"
 
 INCLUDEPATH += . \
@@ -25,6 +27,8 @@ INCLUDEPATH += . \
 HEADERS += \
     ../../../src/routing/route.h \
     ../../../src/routing/routingcommon.h \
-    ../../../src/routing/routesegment.h
+    ../../../src/routing/routesegment.h \
+    ../../../src/coordinates/scenecoordinate.h \
+    ../../../src/coordinates/geocoordinate.h
 
 DEFINES += QT_NO_DEBUG_OUTPUT
index 12af447..31cedc0 100644 (file)
@@ -23,6 +23,7 @@
 #include <QtCore/QString>
 #include <QtTest/QtTest>
 
+#include "coordinates/geocoordinate.h"
 #include "routing/routesegment.h"
 
 #include "routing/route.h"
@@ -40,9 +41,9 @@ private Q_SLOTS:
 void TestRoute::geometryPoints()
 {
     // test points
-    QPointF point1(12.3456, 54.3210);
-    QPointF point2(65.5000, 25.0000);
-    QPointF point3(-123.4567, 43.0987);
+    GeoCoordinate point1(12.3456, 54.3210);
+    GeoCoordinate point2(65.5000, 25.0000);
+    GeoCoordinate point3(-23.4567, 43.0987);
 
     // create route with points
     Route route;
@@ -51,11 +52,17 @@ void TestRoute::geometryPoints()
     route.appendGeometryPoint(point3);
 
     // test points
-    const QList<QPointF> &points = route.geometryPoints();
+    const QList<GeoCoordinate> &points = route.geometryPoints();
     QVERIFY(points.count() == 3);
-    QCOMPARE(points.at(0), point1);
-    QCOMPARE(points.at(1), point2);
-    QCOMPARE(points.at(2), point3);
+
+    QCOMPARE(points.at(0).latitude(), point1.latitude());
+    QCOMPARE(points.at(0).longitude(), point1.longitude());
+
+    QCOMPARE(points.at(1).latitude(), point2.latitude());
+    QCOMPARE(points.at(1).longitude(), point2.longitude());
+
+    QCOMPARE(points.at(2).latitude(), point3.latitude());
+    QCOMPARE(points.at(2).longitude(), point3.longitude());
 }
 
 void TestRoute::segments()