USA.
*/
+#include <QDebug>
+
#include "routingcommon.h"
#include "route.h"
: m_totalDistance(ROUTING_VALUE_UNDEFINED),
m_totalTime(ROUTING_VALUE_UNDEFINED)
{
+ qDebug() << __PRETTY_FUNCTION__;
}
-QString Route::endPointName() const
+Route::~Route()
{
- return m_endPointName;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qDeleteAll(m_segments);
}
-const QList<QPointF>& Route::geometryPoints() const
+void Route::appendGeometryPoint(QPointF geometryPoint)
{
- /// @todo implement
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_geometryPoints.append(geometryPoint);
}
-const QList<RouteSegment>& Route::segments() const
+void Route::appendSegment(RouteSegment *segment)
{
- /// @todo implement
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_segments.append(segment);
}
-void Route::setEndPointName(QString endPoint)
+QString Route::endPointName() const
{
- m_endPointName = endPoint;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_endPointName;
}
-void Route::setGeometryPoints(QList<QPointF> geometryPoints)
+const QList<QPointF>& Route::geometryPoints() const
{
- /// @todo implement
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_geometryPoints;
}
-void Route::setSegments(QList<RouteSegment> segments)
+const QList<RouteSegment *>& Route::segments() const
{
- /// @todo implement
+ qDebug() << __PRETTY_FUNCTION__;
+
+ return m_segments;
+}
+
+void Route::setEndPointName(QString endPoint)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_endPointName = endPoint;
}
void Route::setStartPointName(QString startPoint)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_startPointName = startPoint;
}
void Route::setTotalDistance(int meters)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_totalDistance = meters;
}
void Route::setTotalTime(int seconds)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_totalTime = seconds;
}
QString Route::startPointName() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_startPointName;
}
int Route::totalDistance() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_totalDistance;
}
int Route::totalTime() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_totalTime;
}
{
public:
Route();
+ ~Route();
+
+ void appendGeometryPoint(QPointF geometryPoint);
+
+ /**
+ * @brief Append a route segment to the route
+ *
+ * Takes the ownership of the segment object. Appending must be done in order starting from the
+ * begin of the route.
+ */
+ void appendSegment(RouteSegment *segment);
QString endPointName() const;
const QList<QPointF>& geometryPoints() const;
- const QList<RouteSegment>& segments() const;
+ const QList<RouteSegment *>& segments() const;
void setEndPointName(QString endPoint);
- /// @todo append segments & points, pointers?, takes ownership, no copying data
- void setGeometryPoints(QList<QPointF> geometryPoints);
- void setSegments(QList<RouteSegment> segments);
void setStartPointName(QString startPoint);
void setTotalDistance(int meters);
void setTotalTime(int seconds);
int m_totalTime; // estimated route total time in seconds
QList<QPointF> m_geometryPoints; // lat/lon coordinates of the route points
- QList<RouteSegment> m_segments; // route segments
+ QList<RouteSegment *> m_segments; // route segments
QString m_endPointName; // name of the route end point
QString m_startPointName; // name of the route starting point
USA.
*/
+#include <QDebug>
+
#include "routingcommon.h"
#include "routesegment.h"
m_length(ROUTING_VALUE_UNDEFINED),
m_turnAngle(ROUTING_VALUE_UNDEFINED)
{
+ qDebug() << __PRETTY_FUNCTION__;
}
qreal RouteSegment::azimuth() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_azimuth;
}
QString RouteSegment::earthDirection() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_earthDirection;
}
QString RouteSegment::instruction() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_instruction;
}
qreal RouteSegment::length() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_length;
}
QString RouteSegment::lengthCaption() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_lengthCaption;
}
int RouteSegment::positionIndex() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_positionIndex;
}
void RouteSegment::setAzimuth(qreal azimuth)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_azimuth = azimuth;
}
void RouteSegment::setEarthDirection(QString direction)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_earthDirection = direction;
}
void RouteSegment::setInstruction(QString instruction)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_instruction = instruction;
}
void RouteSegment::setLength(qreal meters)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_length = meters;
}
void RouteSegment::setLengthCaption(QString length)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_lengthCaption = length;
}
void RouteSegment::setPositionIndex(int index)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_positionIndex = index;
}
void RouteSegment::setTime(int seconds)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_timeSeconds = seconds;
}
void RouteSegment::setTurnAngle(qreal degrees)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_turnAngle = degrees;
}
void RouteSegment::setTurnType(QString type)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
m_turnType = type;
}
QString RouteSegment::street() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
/// @todo Implement parser
return QString();
}
int RouteSegment::time() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_timeSeconds;
}
qreal RouteSegment::turnAngle() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_turnAngle;
}
QString RouteSegment::turnType() const
{
+ qDebug() << __PRETTY_FUNCTION__;
+
return m_turnType;
}
SOURCES += testroute.cpp \
- ../../../src/routing/route.cpp
+ ../../../src/routing/route.cpp \
+ ../../../src/routing/routesegment.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
INCLUDEPATH += . \
HEADERS += \
../../../src/routing/route.h \
- ../../../src/routing/routingcommon.h
+ ../../../src/routing/routingcommon.h \
+ ../../../src/routing/routesegment.h
+
+DEFINES += QT_NO_DEBUG_OUTPUT
#include <QtCore/QString>
#include <QtTest/QtTest>
+#include "routing/routesegment.h"
+
#include "routing/route.h"
class TestRoute : public QObject
TestRoute();
private Q_SLOTS:
+ void geometryPoints();
+ void segments();
void settersAndGetters();
};
{
}
+void TestRoute::geometryPoints()
+{
+ // test points
+ QPointF point1(12.3456, 54.3210);
+ QPointF point2(65.5000, 25.0000);
+ QPointF point3(-123.4567, 43.0987);
+
+ // create route with points
+ Route route;
+ route.appendGeometryPoint(point1);
+ route.appendGeometryPoint(point2);
+ route.appendGeometryPoint(point3);
+
+ // test points
+ const QList<QPointF> &points = route.geometryPoints();
+ QVERIFY(points.count() == 3);
+ QCOMPARE(points.at(0), point1);
+ QCOMPARE(points.at(1), point2);
+ QCOMPARE(points.at(2), point3);
+}
+
+void TestRoute::segments()
+{
+ // test segments
+ RouteSegment *segment1 = new RouteSegment();
+ RouteSegment *segment2 = new RouteSegment();
+ RouteSegment *segment3 = new RouteSegment();
+
+ // create route with segments
+ Route route;
+ route.appendSegment(segment1);
+ route.appendSegment(segment2);
+ route.appendSegment(segment3);
+
+ // test segments
+ const QList<RouteSegment *> &segments = route.segments();
+ QVERIFY(segments.count() == 3);
+ QCOMPARE(segments.at(0), segment1);
+ QCOMPARE(segments.at(1), segment2);
+ QCOMPARE(segments.at(2), segment3);
+}
+
void TestRoute::settersAndGetters()
{
- QVERIFY(false);
+ // test data
+ QString endPoint = "Kiviharjunlenkki 1";
+ QString startPoint = "Kauppurienkatu 21";
+ int distance = 2534;
+ int time = 212;
+
+ Route route;
+
+ // setters
+ route.setEndPointName(endPoint);
+ route.setStartPointName(startPoint);
+ route.setTotalDistance(distance);
+ route.setTotalTime(time);
+
+ // compare values with getters
+ QCOMPARE(route.endPointName(), endPoint);
+ QCOMPARE(route.startPointName(), startPoint);
+ QCOMPARE(route.totalDistance(), distance);
+ QCOMPARE(route.totalTime(), time);
}
QTEST_APPLESS_MAIN(TestRoute);
HEADERS += \
../../../src/routing/routesegment.h
+
+DEFINES += QT_NO_DEBUG_OUTPUT