From: Max Waterman Date: Sun, 28 Feb 2010 16:51:08 +0000 (+0200) Subject: Added a toggle button, and fields to set home and work addresses. X-Git-Url: http://vcs.maemo.org/git/?p=ptas;a=commitdiff_plain;h=a5c92f28d135a3037c6f677d4cea4ccd5a87e23b Added a toggle button, and fields to set home and work addresses. --- diff --git a/zouba/location.cpp b/zouba/location.cpp index 6ebab31..b41360c 100644 --- a/zouba/location.cpp +++ b/zouba/location.cpp @@ -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 ); diff --git a/zouba/location.h b/zouba/location.h index f04ad98..018d578 100644 --- a/zouba/location.h +++ b/zouba/location.h @@ -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(); diff --git a/zouba/main.cpp b/zouba/main.cpp index 65190f9..277faf1 100644 --- a/zouba/main.cpp +++ b/zouba/main.cpp @@ -4,16 +4,11 @@ #include "uicontroller.h" #include "location.h" +#include "ytv.h" + #include #include -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(); diff --git a/zouba/route.cpp b/zouba/route.cpp index 331ae54..5356702 100644 --- a/zouba/route.cpp +++ b/zouba/route.cpp @@ -92,3 +92,11 @@ const Location &Route::toLocation() return q->toLocation(); } +void Route::toggleDirection() +{ + Location oldFromLocation = fromLocation(); + setFromLocation( toLocation() ); + setToLocation( oldFromLocation ); + + getRoute(); +} diff --git a/zouba/route.h b/zouba/route.h index badebda..139b67f 100644 --- a/zouba/route.h +++ b/zouba/route.h @@ -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 ); diff --git a/zouba/tests/ut_location/ut_location.pro b/zouba/tests/ut_location/ut_location.pro index 8d8ba3c..0c07b8e 100644 --- a/zouba/tests/ut_location/ut_location.pro +++ b/zouba/tests/ut_location/ut_location.pro @@ -8,6 +8,8 @@ QT += \ INCLUDEPATH += \ ../.. \ +DEPENDPATH += $$INCLUDEPATH + TEMPLATE = app SOURCES = \ diff --git a/zouba/tests/ut_route/ut_route.pro b/zouba/tests/ut_route/ut_route.pro index 4b697df..3b6a4d7 100644 --- a/zouba/tests/ut_route/ut_route.pro +++ b/zouba/tests/ut_route/ut_route.pro @@ -9,6 +9,8 @@ QT += \ INCLUDEPATH += \ ../.. \ +DEPENDPATH += $INCLUDEPATH + TEMPLATE = app SOURCES = \ diff --git a/zouba/uicontroller.cpp b/zouba/uicontroller.cpp index f389d66..3a0fd65 100644 --- a/zouba/uicontroller.cpp +++ b/zouba/uicontroller.cpp @@ -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 ); } diff --git a/zouba/uicontroller.h b/zouba/uicontroller.h index 0ea3010..392962d 100644 --- a/zouba/uicontroller.h +++ b/zouba/uicontroller.h @@ -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 diff --git a/zouba/ytv.h b/zouba/ytv.h index 658262f..2bcc02b 100644 --- a/zouba/ytv.h +++ b/zouba/ytv.h @@ -3,11 +3,13 @@ #include 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" ); } diff --git a/zouba/zouba.pro b/zouba/zouba.pro index 4c32159..5f5f9f2 100644 --- a/zouba/zouba.pro +++ b/zouba/zouba.pro @@ -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 diff --git a/zouba/zouba.ui b/zouba/zouba.ui index 6eaa8b6..eb96990 100644 --- a/zouba/zouba.ui +++ b/zouba/zouba.ui @@ -6,8 +6,8 @@ 0 0 - 640 - 480 + 231 + 167 @@ -20,7 +20,7 @@ 0 0 230 - 82 + 106 @@ -29,68 +29,96 @@ QFormLayout::AllNonFixedFieldsGrow - - - - Time - - + + + + + + Work->Home + + + + - + TimeDisplay - + BusNo + + + + Time + + + - + BusNoDisplay - - - - - - Work - - - - - - - Home - - - - - + + + + 130 + 90 + 92 + 28 + + + + Set Home + + + + + + 130 + 130 + 92 + 28 + + + + Set Work + + + + + + 10 + 90 + 113 + 26 + + + + + + + 10 + 130 + 113 + 26 + + + - - - - 0 - 0 - 640 - 25 - - - -