Moved the from and to locations out of HttpClient into main, and added set/get method...
authorMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Fri, 26 Feb 2010 16:10:37 +0000 (18:10 +0200)
committerMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Fri, 26 Feb 2010 16:40:03 +0000 (18:40 +0200)
zouba/qt/httpclient.cpp
zouba/qt/httpclient.h
zouba/qt/httpclient_p.cpp
zouba/qt/httpclient_p.h
zouba/qt/location.h [new file with mode: 0644]
zouba/qt/main.cpp
zouba/qt/tests/ut_httpclient/ut_httpclient.cpp
zouba/qt/tests/ut_httpclient/ut_httpclient.h

index b77c00f..8c4ff59 100644 (file)
@@ -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();
+}
+
index ab648de..9d12c2c 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "ui_zouba.h"
 
+#include "location.h"
+
 #include <QObject>
 #include <QNetworkReply>
 #include <QNetworkAccessManager>
@@ -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
index 25133f9..d9f7e3f 100644 (file)
@@ -1,9 +1,12 @@
 #include "httpclient_p.h"
+#include "location.h"
 
 #include <QXmlStreamReader>
 #include <QDebug>
 
-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;
+}
index 9c04bd9..e0ee685 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "routedata.h"
 
+#include "location.h"
+
 #include <QObject>
 
 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 (file)
index 0000000..18f93b6
--- /dev/null
@@ -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
index 8d3f976..3b93dda 100644 (file)
@@ -1,8 +1,15 @@
 #include "httpclient.h"
 #include "ui_zouba.h"
 
+#include "location.h"
+
 #include <QDebug>
 
+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" );
index 0e00e06..da8b80f 100644 (file)
@@ -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)
index b880e5a..9602ce9 100644 (file)
@@ -20,6 +20,8 @@ private slots:
     void initTestCase();
     void cleanupTestCase();
     void testParseReply();
+    void testSetFromLocation();
+    void testSetToLocation();
 
 private:
     HttpClientPrivate *m_subject;