Added a toggle button, and fields to set home and work addresses.
authorMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Sun, 28 Feb 2010 16:51:08 +0000 (18:51 +0200)
committerMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Sun, 28 Feb 2010 16:51:08 +0000 (18:51 +0200)
12 files changed:
zouba/location.cpp
zouba/location.h
zouba/main.cpp
zouba/route.cpp
zouba/route.h
zouba/tests/ut_location/ut_location.pro
zouba/tests/ut_route/ut_route.pro
zouba/uicontroller.cpp
zouba/uicontroller.h
zouba/ytv.h
zouba/zouba.pro
zouba/zouba.ui

index 6ebab31..b41360c 100644 (file)
@@ -63,7 +63,7 @@ void Location::resolveAddress( QString address )
 {
   QUrl fullUrl( ytv );
 
-  fullUrl.addEncodedQueryItem( "key", address.toAscii() );
+  fullUrl.addEncodedQueryItem( "key", address.toUtf8() );
   fullUrl.addQueryItem( "user", username );
   fullUrl.addQueryItem( "pass", password );
 
index f04ad98..018d578 100644 (file)
@@ -20,14 +20,15 @@ public:
 
   ~Location();
 
-  void resolveAddress( QString address );
-
   QString x() const;
 
   QString y() const;
 
   bool isValid() const;
 
+public Q_SLOTS:
+  void resolveAddress( QString address );
+
 Q_SIGNALS:
   void becomeValid();
 
index 65190f9..277faf1 100644 (file)
@@ -4,16 +4,11 @@
 #include "uicontroller.h"
 #include "location.h"
 
+#include "ytv.h"
+
 #include <QDebug>
 #include <QObject>
 
-namespace {
-  Location home( "2549183", "6672570" );
-  Location work( "2551042", "6672829" );
-  QString homeKey( "taivaanvuohentie%207%2Chelsinki" );
-  QString workKey( "it%E4merenkatu%2011%2Chelsinki" );
-}
-
 int main(int argc, char *argv[] )
 {
   QApplication app(argc, argv);
@@ -42,8 +37,28 @@ int main(int argc, char *argv[] )
       route, SLOT( setToLocation() )
       );
 
-  from->resolveAddress( homeKey );
-  to->resolveAddress( workKey );
+  ui.homeaddress->setText( home );
+  ui.workaddress->setText( work );
+
+  from->resolveAddress( home );
+  to->resolveAddress( work );
+
+  QObject::connect(
+      uiController, SIGNAL( homeAddressChanged( QString ) ),
+      from, SLOT( resolveAddress( QString ) )
+    );
+
+  QObject::connect(
+      uiController, SIGNAL( workAddressChanged( QString ) ),
+      to, SLOT( resolveAddress( QString ) )
+    );
+
+  /* toggle doesn't work yet because 'from' is connected to 'homeAddressChanged'
+  QObject::connect(
+      uiController, SIGNAL( directionChanged() ),
+      route, SLOT( toggleDirection() )
+    );
+    */
 
   widget->show();
   return app.exec();
index 331ae54..5356702 100644 (file)
@@ -92,3 +92,11 @@ const Location &Route::toLocation()
   return q->toLocation();
 }
 
+void Route::toggleDirection()
+{
+  Location oldFromLocation = fromLocation();
+  setFromLocation( toLocation() );
+  setToLocation( oldFromLocation );
+
+  getRoute();
+}
index badebda..139b67f 100644 (file)
@@ -52,6 +52,11 @@ public Q_SLOTS:
     */
   void setToLocation( const Location &location=Location() );
 
+  /*!
+    * \brief Toggles the route direction.
+    */
+  void toggleDirection();
+
 Q_SIGNALS:
   void routeReady( RouteData );
 
index 8d8ba3c..0c07b8e 100644 (file)
@@ -8,6 +8,8 @@ QT += \
 INCLUDEPATH += \
   ../.. \
 
+DEPENDPATH += $$INCLUDEPATH
+
 TEMPLATE = app
 
 SOURCES  = \
index 4b697df..3b6a4d7 100644 (file)
@@ -9,6 +9,8 @@ QT += \
 INCLUDEPATH += \
   ../.. \
 
+DEPENDPATH += $INCLUDEPATH
+
 TEMPLATE = app
 
 SOURCES  = \
index f389d66..3a0fd65 100644 (file)
@@ -3,16 +3,46 @@
 #include "ui_zouba.h"
 
 UiController::UiController( Ui::MainWindow *ui ) :
-  ui(ui)
+  ui(ui),
+  route( HomeToWork )
 {
+  connect( ui->sethomeaddress, SIGNAL( pressed() ), this, SLOT( setHomeAddress() ) );
+  connect( ui->setworkaddress, SIGNAL( pressed() ), this, SLOT( setWorkAddress() ) );
+  connect( ui->route, SIGNAL( pressed() ), this, SLOT( toggleRoute() ) );
 }
 
 UiController::~UiController()
 {
 }
 
+void UiController::setHomeAddress()
+{
+  emit homeAddressChanged( ui->homeaddress->text() );
+}
+
+void UiController::setWorkAddress()
+{
+  emit workAddressChanged( ui->workaddress->text() );
+}
+
+void UiController::toggleRoute()
+{
+  if ( route == HomeToWork ) {
+    route = WorkToHome;
+    ui->route->setText( "Home<-Work" );
+  } else {
+    route = HomeToWork;
+    ui->route->setText( "Home->Work" );
+  }
+
+  ui->busnodisplay->setText( "working" );
+  ui->timedisplay->setText( "working" );
+
+  emit directionChanged();
+}
+
 void UiController::displayRoute( const RouteData &routeData )
 {
-  ui->BusNoDisplay->setText( routeData.lineCode );
-  ui->TimeDisplay->setText( routeData.arrivalTime );
+  ui->busnodisplay->setText( routeData.lineCode );
+  ui->timedisplay->setText( routeData.arrivalTime );
 }
index 0ea3010..392962d 100644 (file)
@@ -17,8 +17,24 @@ public:
 public Q_SLOTS:
   void displayRoute( const RouteData &routeData );
 
+Q_SIGNALS:
+  void homeAddressChanged( QString );
+  void workAddressChanged( QString );
+  void directionChanged();
+
+private Q_SLOTS:
+  void setHomeAddress();
+  void setWorkAddress();
+  void toggleRoute();
+
 private:
   Ui::MainWindow *ui;
+  enum Direction {
+    WorkToHome,
+    HomeToWork
+  };
+
+  Direction route;
 };
 #endif // UICONTROLLER_H
 
index 658262f..2bcc02b 100644 (file)
@@ -3,11 +3,13 @@
 #include <QString>
 
 namespace {
-  QUrl ytv( "http://api.reittiopas.fi/public-ytv/fi/api/" );
-  QString username( "zouba" );
-  QString password( "caf9r3ee" );
-
-  QString homeKey( "taivaanvuohentie%207%2Chelsinki" );
-  QString workKey( "it%E4merenkatu%2011%2Chelsinki" );
+  const QUrl ytv( "http://api.reittiopas.fi/public-ytv/fi/api/" );
+  const QString username( "zouba" );
+  const QString password( "caf9r3ee" );
+
+  //const QString home( "Taivaanvuohentie 7, Helsinki" );
+  //const QString work( "Itämerenkatu 11, Helsinki" );
+  const QString home( "Taivaanvuohentie%207%2CHelsinki" );
+  const QString work( "It%E4merenkatu%2011%2CHelsinki" );
 }
 
index 4c32159..5f5f9f2 100644 (file)
@@ -1,25 +1,17 @@
-CONFIG += \
-  qt \
-  debug \
-
-QT += \
-  network \
-
+CONFIG += qt \
+    debug
+QT += network
 TEMPLATE = app
-FORMS    = zouba.ui
-
-SOURCES  = \
-  main.cpp \
-  route.cpp \
-  route_p.cpp \
-  uicontroller.cpp \
-  location.cpp \
-  location_p.cpp \
-
-HEADERS += \
-  route.h \
-  route_p.h \
-  uicontroller.h \
-  location.h \
-  location_p.h \
-
+FORMS = zouba.ui
+SOURCES = main.cpp \
+    route.cpp \
+    route_p.cpp \
+    uicontroller.cpp \
+    location.cpp \
+    location_p.cpp
+HEADERS += route.h \
+    route_p.h \
+    uicontroller.h \
+    location.h \
+    location_p.h \
+    ytv.h
index 6eaa8b6..eb96990 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>480</height>
+    <width>231</width>
+    <height>167</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -20,7 +20,7 @@
       <x>0</x>
       <y>0</y>
       <width>230</width>
-      <height>82</height>
+      <height>106</height>
      </rect>
     </property>
     <layout class="QVBoxLayout" name="verticalLayout">
        <property name="fieldGrowthPolicy">
         <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
        </property>
-       <item row="1" column="0">
-        <widget class="QLabel" name="TimeLabel">
-         <property name="text">
-          <string>Time</string>
-         </property>
-        </widget>
+       <item row="0" column="0" colspan="2">
+        <layout class="QHBoxLayout" name="horizontalLayout">
+         <item>
+          <widget class="QPushButton" name="route">
+           <property name="text">
+            <string>Work-&gt;Home</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
        </item>
        <item row="1" column="1">
-        <widget class="QLabel" name="TimeDisplay">
+        <widget class="QLabel" name="timedisplay">
          <property name="text">
           <string>TimeDisplay</string>
          </property>
         </widget>
        </item>
        <item row="2" column="0">
-        <widget class="QLabel" name="BusNoLabel">
+        <widget class="QLabel" name="busnolabel">
          <property name="text">
           <string>BusNo</string>
          </property>
         </widget>
        </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="timelabel">
+         <property name="text">
+          <string>Time</string>
+         </property>
+        </widget>
+       </item>
        <item row="2" column="1">
-        <widget class="QLabel" name="BusNoDisplay">
+        <widget class="QLabel" name="busnodisplay">
          <property name="text">
           <string>BusNoDisplay</string>
          </property>
         </widget>
        </item>
-       <item row="0" column="0" colspan="2">
-        <layout class="QHBoxLayout" name="horizontalLayout">
-         <item>
-          <widget class="QPushButton" name="pushButton_2">
-           <property name="text">
-            <string>Work</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="pushButton">
-           <property name="text">
-            <string>Home</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
-       </item>
       </layout>
      </item>
     </layout>
    </widget>
+   <widget class="QPushButton" name="sethomeaddress">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>90</y>
+      <width>92</width>
+      <height>28</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Set Home</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="setworkaddress">
+    <property name="geometry">
+     <rect>
+      <x>130</x>
+      <y>130</y>
+      <width>92</width>
+      <height>28</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Set Work</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="homeaddress">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>90</y>
+      <width>113</width>
+      <height>26</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="workaddress">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>130</y>
+      <width>113</width>
+      <height>26</height>
+     </rect>
+    </property>
+   </widget>
   </widget>
-  <widget class="QMenuBar" name="menubar">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>640</width>
-     <height>25</height>
-    </rect>
-   </property>
-  </widget>
-  <widget class="QStatusBar" name="statusbar"/>
  </widget>
  <resources/>
  <connections/>