From d559f9332d2b5d523f0b47bef5b39c2639cb5de5 Mon Sep 17 00:00:00 2001 From: Max Waterman Date: Tue, 16 Mar 2010 21:31:34 +0200 Subject: [PATCH] Changes: changed UI, walking speed, time format --- zouba/gpscontroller.cpp | 1 + zouba/gpscontroller.h | 8 ++++---- zouba/main.cpp | 36 ++++++++++++++++------------------ zouba/route.cpp | 4 ++++ zouba/route_p.cpp | 16 +++++++++++---- zouba/ui.cpp | 35 +++++++++++++++++++++++++++++++++ zouba/ui.h | 20 +++++++++++++++++++ zouba/uicontroller.cpp | 50 ++++++++++++++++------------------------------- zouba/uicontroller.h | 22 +++++---------------- zouba/zouba.pro | 4 +++- 10 files changed, 118 insertions(+), 78 deletions(-) create mode 100644 zouba/ui.cpp create mode 100644 zouba/ui.h diff --git a/zouba/gpscontroller.cpp b/zouba/gpscontroller.cpp index 932c0cf..618746a 100644 --- a/zouba/gpscontroller.cpp +++ b/zouba/gpscontroller.cpp @@ -34,6 +34,7 @@ void GpsController::updateLocation( QGeoPositionInfo positionInfo ) Location newLocation( positionInfo ); emit locationChanged( newLocation ); + m_location->stopUpdates(); } void GpsController::startGps() diff --git a/zouba/gpscontroller.h b/zouba/gpscontroller.h index e68bcb6..8628828 100644 --- a/zouba/gpscontroller.h +++ b/zouba/gpscontroller.h @@ -14,15 +14,15 @@ class GpsController : public QObject Q_OBJECT public: - GpsController(); + GpsController(); - ~GpsController(); + ~GpsController(); - void startGps(); - void stopGps(); + void stopGps(); public Q_SLOTS: void updateLocation( QGeoPositionInfo positionInfo ); + void startGps(); Q_SIGNALS: void locationChanged( const Location &newLocation ); diff --git a/zouba/main.cpp b/zouba/main.cpp index 182e723..761cfcb 100644 --- a/zouba/main.cpp +++ b/zouba/main.cpp @@ -1,6 +1,6 @@ #include "routedata.h" #include "route.h" -#include "ui_zouba.h" +#include "ui.h" #include "uicontroller.h" #include "location.h" #include "gpscontroller.h" @@ -9,46 +9,44 @@ #include #include +#include +#include int main(int argc, char *argv[] ) { QApplication app(argc, argv); - QMainWindow *widget = new QMainWindow; - Ui::MainWindow ui; - ui.setupUi(widget); + QMainWindow *mainWindow = new QMainWindow; + Ui ui; + ui.setupUi(mainWindow); - UiController *uiController = new UiController( &ui ); - - Route *route = new Route(); + UiController *uiController = new UiController( &ui ); + Route *route = new Route(); + GpsController *gpsController = new GpsController(); + Location *to = new Location(); QObject::connect( route, SIGNAL( routeReady( RouteData ) ), uiController, SLOT( displayRoute( RouteData ) ) ); - GpsController *gpsController = new GpsController(); - Location *to = new Location(); - QObject::connect( gpsController, SIGNAL( locationChanged( Location ) ), route, SLOT( setFromLocation( Location ) ) ); + QObject::connect( to, SIGNAL( becomeValid() ), route, SLOT( setToLocation() ) ); - ui.homeaddress->setText( "GPS" ); - ui.workaddress->setText( work ); - - gpsController->startGps(); - to->resolveAddress( work ); - QObject::connect( - uiController, SIGNAL( workAddressChanged( QString ) ), - to, SLOT( resolveAddress( QString ) ) + uiController, SIGNAL( homePressed() ), + gpsController, SLOT( startGps() ) ); - widget->show(); + mainWindow->show(); + + to->resolveAddress( work ); + return app.exec(); } diff --git a/zouba/route.cpp b/zouba/route.cpp index 6206492..e8a2790 100644 --- a/zouba/route.cpp +++ b/zouba/route.cpp @@ -30,6 +30,7 @@ Route::~Route() void Route::getRoute() { + qDebug() << __PRETTY_FUNCTION__; QUrl fullUrl( ytv ); QStringList a; @@ -39,6 +40,8 @@ void Route::getRoute() fullUrl.addQueryItem( "a", a.join(",") ); fullUrl.addQueryItem( "b", b.join(",") ); + fullUrl.addQueryItem( "show", "1" ); + fullUrl.addQueryItem( "walkspeed", "3" ); fullUrl.addQueryItem( "user", username ); fullUrl.addQueryItem( "pass", password ); @@ -47,6 +50,7 @@ void Route::getRoute() void Route::replyFinished( QNetworkReply * reply ) { + qDebug() << __PRETTY_FUNCTION__; RouteData routeData = q->parseReply( reply->readAll() ); emit( routeReady( routeData ) ); diff --git a/zouba/route_p.cpp b/zouba/route_p.cpp index f2cb747..9e91620 100644 --- a/zouba/route_p.cpp +++ b/zouba/route_p.cpp @@ -19,28 +19,36 @@ RoutePrivate::~RoutePrivate() RouteData RoutePrivate::parseReply( const QByteArray &reply ) { + qDebug() << __PRETTY_FUNCTION__; RouteData retVal; QXmlStreamReader xml( reply ); + bool haveLine = false; + bool haveTime = false; + bool inLine = false; bool inStop = false; - while ( !xml.atEnd() ) { + while ( !(haveLine && haveTime) && !xml.atEnd() ) { xml.readNext(); - if ( xml.isStartElement() && xml.name() == "LINE" ) { + if ( !haveLine && xml.isStartElement() && xml.name() == "LINE" ) { QString lineCode( xml.attributes().value("code").toString() ); + qDebug() << "lineCode" << lineCode; retVal.lineCode = parseJORECode( lineCode ); + haveLine = true; inLine = true; } else if ( inLine && xml.name() == "STOP" ) { inStop = true; } else - if ( inLine && inStop && xml.name() == "ARRIVAL" ) { + if ( !haveTime && inLine && inStop && xml.name() == "ARRIVAL" ) { QString arrivalTime( xml.attributes().value("time").toString() ); + qDebug() << "arrivalTime" << arrivalTime; - retVal.arrivalTime = arrivalTime; + retVal.arrivalTime = arrivalTime.rightJustified(4).insert(2,":"); + haveTime = true; inLine = false; } else diff --git a/zouba/ui.cpp b/zouba/ui.cpp new file mode 100644 index 0000000..d36baab --- /dev/null +++ b/zouba/ui.cpp @@ -0,0 +1,35 @@ +#include "ui.h" + +#include +#include +#include +#include +#include + +Ui::Ui() : + centralWidget(0), + trigger(0), + table(0) +{ +} + +Ui::~Ui() +{ +} + +void Ui::setupUi( QMainWindow *mainWindow ) +{ + mainWindow->resize(800,480); + + centralWidget = new QWidget( mainWindow ); + mainWindow->setCentralWidget(centralWidget); + + trigger = new QPushButton( centralWidget ); + trigger->setObjectName( QString::fromUtf8("trigger") ); + trigger->setText( "HOME" ); + trigger->setGeometry( QRect( 0, 0, 150, 40 ) ); + + table = new QTableWidget( 1, 2, centralWidget ); + table->setObjectName( QString::fromUtf8("table") ); + table->setGeometry( QRect( 151, 0, 650, 480 ) ); +} diff --git a/zouba/ui.h b/zouba/ui.h new file mode 100644 index 0000000..a232ad9 --- /dev/null +++ b/zouba/ui.h @@ -0,0 +1,20 @@ +#ifndef UI_H +#define UI_H + +class QMainWindow; +class QWidget; +class QPushButton; +class QTableWidget; + +class Ui +{ +public: + Ui(); + ~Ui(); + void setupUi( QMainWindow *mainWindow ); + + QWidget *centralWidget; + QPushButton *trigger; + QTableWidget *table; +}; +#endif //UI_H diff --git a/zouba/uicontroller.cpp b/zouba/uicontroller.cpp index 3a0fd65..9df97b2 100644 --- a/zouba/uicontroller.cpp +++ b/zouba/uicontroller.cpp @@ -1,48 +1,32 @@ #include "uicontroller.h" #include "route.h" -#include "ui_zouba.h" +#include "ui.h" -UiController::UiController( Ui::MainWindow *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() -{ -} +#include +#include +#include +#include -void UiController::setHomeAddress() +UiController::UiController( Ui *ui ) : + ui(ui) { - emit homeAddressChanged( ui->homeaddress->text() ); + connect( ui->trigger, SIGNAL( pressed() ), this, SIGNAL( homePressed() ) ); } -void UiController::setWorkAddress() +UiController::~UiController() { - emit workAddressChanged( ui->workaddress->text() ); } -void UiController::toggleRoute() +void UiController::displayRoute( const RouteData &routeData ) { - if ( route == HomeToWork ) { - route = WorkToHome; - ui->route->setText( "Home<-Work" ); - } else { - route = HomeToWork; - ui->route->setText( "Home->Work" ); - } + qDebug() << __PRETTY_FUNCTION__; + qDebug() << "routeData.arrivalTime" << routeData.arrivalTime; + qDebug() << "routeData.lineCode" << routeData.lineCode; - ui->busnodisplay->setText( "working" ); - ui->timedisplay->setText( "working" ); + QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.arrivalTime ); + ui->table->setItem( 0, 0, timeItem ); - emit directionChanged(); -} + QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode ); + ui->table->setItem( 0, 1, lineItem ); -void UiController::displayRoute( const RouteData &routeData ) -{ - ui->busnodisplay->setText( routeData.lineCode ); - ui->timedisplay->setText( routeData.arrivalTime ); } diff --git a/zouba/uicontroller.h b/zouba/uicontroller.h index 392962d..f524a42 100644 --- a/zouba/uicontroller.h +++ b/zouba/uicontroller.h @@ -1,40 +1,28 @@ #ifndef UICONTROLLER_H #define UICONTROLLER_H -#include "ui_zouba.h" #include "routedata.h" #include +class Ui; + class UiController : public QObject { Q_OBJECT public: - UiController( Ui::MainWindow *ui ); + UiController( Ui *ui ); ~UiController(); 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(); + void homePressed(); private: - Ui::MainWindow *ui; - enum Direction { - WorkToHome, - HomeToWork - }; - - Direction route; + Ui *ui; }; #endif // UICONTROLLER_H diff --git a/zouba/zouba.pro b/zouba/zouba.pro index 68580cf..571eca3 100644 --- a/zouba/zouba.pro +++ b/zouba/zouba.pro @@ -17,7 +17,7 @@ QT += \ TEMPLATE = app -FORMS = zouba.ui +#FORMS = zouba.ui SOURCES += \ main.cpp \ @@ -27,6 +27,7 @@ SOURCES += \ location.cpp \ location_p.cpp \ gpscontroller.cpp \ + ui.cpp \ HEADERS += \ route.h \ @@ -36,4 +37,5 @@ HEADERS += \ location_p.h \ ytv.h \ gpscontroller.h \ + ui.h \ -- 1.7.9.5