From f2e5fab9dd8cbf7cc8fc8832a733e46c7172b830 Mon Sep 17 00:00:00 2001 From: Max Waterman Date: Fri, 26 Feb 2010 18:10:37 +0200 Subject: [PATCH] Moved the from and to locations out of HttpClient into main, and added set/get methods, and a Location class. --- zouba/qt/httpclient.cpp | 30 ++++++++++++++++----- zouba/qt/httpclient.h | 33 +++++++++++++++++++++++- zouba/qt/httpclient_p.cpp | 26 ++++++++++++++++++- zouba/qt/httpclient_p.h | 33 ++++++++++++++++++++++++ zouba/qt/location.h | 16 ++++++++++++ zouba/qt/main.cpp | 10 +++++++ zouba/qt/tests/ut_httpclient/ut_httpclient.cpp | 16 ++++++++++++ zouba/qt/tests/ut_httpclient/ut_httpclient.h | 2 ++ 8 files changed, 158 insertions(+), 8 deletions(-) create mode 100644 zouba/qt/location.h diff --git a/zouba/qt/httpclient.cpp b/zouba/qt/httpclient.cpp index b77c00f..8c4ff59 100644 --- a/zouba/qt/httpclient.cpp +++ b/zouba/qt/httpclient.cpp @@ -2,6 +2,7 @@ #include "httpclient.h" #include "routedata.h" +#include "location.h" #include "ui_zouba.h" @@ -22,10 +23,6 @@ namespace { QString homeKey( "taivaanvuohentie%207%2Chelsinki" ); QString workKey( "it%E4merenkatu%2011%2Chelsinki" ); - QString workX( "2551042" ); - QString workY( "6672829" ); - QString homeX( "2549183" ); - QString homeY( "6672570" ); } HttpClient::HttpClient( Ui::MainWindow *ui ) : @@ -47,9 +44,9 @@ void HttpClient::get() QUrl fullUrl( ytv ); QStringList a; - a << workX << workY; + a << q->fromLocation().x << q->fromLocation().y; QStringList b; - b << homeX << homeY; + b << q->toLocation().x << q->toLocation().y; fullUrl.addQueryItem( "a", a.join(",") ); fullUrl.addQueryItem( "b", b.join(",") ); @@ -66,3 +63,24 @@ void HttpClient::replyFinished( QNetworkReply * reply ) ui->BusNoDisplay->setText( routeData.lineCode ); ui->TimeDisplay->setText( routeData.arrivalTime ); } + +void HttpClient::setFromLocation( Location fromLocation ) +{ + q->setFromLocation( fromLocation ); +} + +Location HttpClient::fromLocation() +{ + return q->fromLocation(); +} + +void HttpClient::setToLocation( Location toLocation ) +{ + q->setToLocation( toLocation ); +} + +Location HttpClient::toLocation() +{ + return q->toLocation(); +} + diff --git a/zouba/qt/httpclient.h b/zouba/qt/httpclient.h index ab648de..9d12c2c 100644 --- a/zouba/qt/httpclient.h +++ b/zouba/qt/httpclient.h @@ -3,6 +3,8 @@ #include "ui_zouba.h" +#include "location.h" + #include #include #include @@ -17,8 +19,38 @@ public: HttpClient( Ui::MainWindow *ui ); ~HttpClient(); + Q_PROPERTY(Location fromLocation READ fromLocation WRITE setFromLocation); + Q_PROPERTY(Location toLocation READ toLocation WRITE setFromLocation); + + /*! + * \brief Gets the route data from the server + */ void get(); + /*! + * \brief Sets the from location + * \param fromLocation The from location + */ + void setFromLocation( Location fromLocation ); + + /*! + \brief Get the from location + \return The from location + */ + Location fromLocation(); + + /*! + * \brief Sets the to location + * \param toLocation The to location + */ + void setToLocation( Location toLocation ); + + /*! + \brief Get the to location + \return The to location + */ + Location toLocation(); + public Q_SLOTS: void replyFinished(QNetworkReply*); @@ -26,6 +58,5 @@ private: HttpClientPrivate *q; QNetworkAccessManager *manager; Ui::MainWindow *ui; - }; #endif // HTTPCLIENT_H diff --git a/zouba/qt/httpclient_p.cpp b/zouba/qt/httpclient_p.cpp index 25133f9..d9f7e3f 100644 --- a/zouba/qt/httpclient_p.cpp +++ b/zouba/qt/httpclient_p.cpp @@ -1,9 +1,12 @@ #include "httpclient_p.h" +#include "location.h" #include #include -HttpClientPrivate::HttpClientPrivate( QObject *parent ) +HttpClientPrivate::HttpClientPrivate( QObject *parent ) : + m_fromLocation(0,0), + m_toLocation(0,0) { } @@ -52,3 +55,24 @@ RouteData HttpClientPrivate::parseReply( const QByteArray &reply ) return retVal; } + +void HttpClientPrivate::setFromLocation( Location fromLocation ) +{ + m_fromLocation = fromLocation; +} + +Location HttpClientPrivate::fromLocation() +{ + return m_fromLocation; +} + +void HttpClientPrivate::setToLocation( Location toLocation ) +{ + m_toLocation = toLocation; +} + +Location HttpClientPrivate::toLocation() + +{ + return m_toLocation; +} diff --git a/zouba/qt/httpclient_p.h b/zouba/qt/httpclient_p.h index 9c04bd9..e0ee685 100644 --- a/zouba/qt/httpclient_p.h +++ b/zouba/qt/httpclient_p.h @@ -3,6 +3,8 @@ #include "routedata.h" +#include "location.h" + #include class HttpClientPrivate: public QObject @@ -13,6 +15,37 @@ public: HttpClientPrivate( QObject *parent=0 ); ~HttpClientPrivate(); + Q_PROPERTY(Location fromLocation READ fromLocation WRITE setFromLocation); + Q_PROPERTY(Location toLocation READ toLocation WRITE setFromLocation); + RouteData parseReply( const QByteArray &reply ); + + /*! + * \brief Sets the from location + * \param fromLocation The from location + */ + void setFromLocation( Location fromLocation ); + + /*! + \brief Get the from location + \return The from location + */ + Location fromLocation(); + + /*! + * \brief Sets the to location + * \param toLocation The to location + */ + void setToLocation( Location toLocation ); + + /*! + \brief Get the to location + \return The to location + */ + Location toLocation(); + +private: + Location m_fromLocation; + Location m_toLocation; }; #endif // HTTPCLIENT_P_H diff --git a/zouba/qt/location.h b/zouba/qt/location.h new file mode 100644 index 0000000..18f93b6 --- /dev/null +++ b/zouba/qt/location.h @@ -0,0 +1,16 @@ +#ifndef LOCATION_H +#define LOCATION_H + +class Location +{ +public: + Location( QString x, QString y ) : + x(x), + y(y) + { + }; + + QString x; + QString y; +}; +#endif // LOCATION_H diff --git a/zouba/qt/main.cpp b/zouba/qt/main.cpp index 8d3f976..3b93dda 100644 --- a/zouba/qt/main.cpp +++ b/zouba/qt/main.cpp @@ -1,8 +1,15 @@ #include "httpclient.h" #include "ui_zouba.h" +#include "location.h" + #include +namespace { + Location home( "2549183", "6672570" ); + Location work( "2551042", "6672829" ); +} + int main(int argc, char *argv[] ) { QApplication app(argc, argv); @@ -12,6 +19,9 @@ int main(int argc, char *argv[] ) HttpClient httpClient( &ui ); + httpClient.setFromLocation( work ); + httpClient.setToLocation( home ); + httpClient.get(); ui.TimeDisplay->setText( "HELLO" ); diff --git a/zouba/qt/tests/ut_httpclient/ut_httpclient.cpp b/zouba/qt/tests/ut_httpclient/ut_httpclient.cpp index 0e00e06..da8b80f 100644 --- a/zouba/qt/tests/ut_httpclient/ut_httpclient.cpp +++ b/zouba/qt/tests/ut_httpclient/ut_httpclient.cpp @@ -366,4 +366,20 @@ void Ut_HttpClient::testParseReply() QCOMPARE( routeData.arrivalTime, QString( "1834" ) ); } +void Ut_HttpClient::testSetFromLocation() +{ + Location work( "2551042", "6672829" ); + m_subject->setFromLocation( work ); + QCOMPARE( work.x, m_subject->fromLocation().x ); + QCOMPARE( work.y, m_subject->fromLocation().y ); +} + +void Ut_HttpClient::testSetToLocation() +{ + Location work( "2551042", "6672829" ); + m_subject->setToLocation( work ); + QCOMPARE( work.x, m_subject->toLocation().x ); + QCOMPARE( work.y, m_subject->toLocation().y ); +} + QTEST_MAIN(Ut_HttpClient) diff --git a/zouba/qt/tests/ut_httpclient/ut_httpclient.h b/zouba/qt/tests/ut_httpclient/ut_httpclient.h index b880e5a..9602ce9 100644 --- a/zouba/qt/tests/ut_httpclient/ut_httpclient.h +++ b/zouba/qt/tests/ut_httpclient/ut_httpclient.h @@ -20,6 +20,8 @@ private slots: void initTestCase(); void cleanupTestCase(); void testParseReply(); + void testSetFromLocation(); + void testSetToLocation(); private: HttpClientPrivate *m_subject; -- 1.7.9.5