Location newLocation( positionInfo );
emit locationChanged( newLocation );
+ m_location->stopUpdates();
}
void GpsController::startGps()
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 );
#include "routedata.h"
#include "route.h"
-#include "ui_zouba.h"
+#include "ui.h"
#include "uicontroller.h"
#include "location.h"
#include "gpscontroller.h"
#include <QDebug>
#include <QObject>
+#include <QApplication>
+#include <QMainWindow>
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();
}
void Route::getRoute()
{
+ qDebug() << __PRETTY_FUNCTION__;
QUrl fullUrl( ytv );
QStringList a;
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 );
void Route::replyFinished( QNetworkReply * reply )
{
+ qDebug() << __PRETTY_FUNCTION__;
RouteData routeData = q->parseReply( reply->readAll() );
emit( routeReady( routeData ) );
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
--- /dev/null
+#include "ui.h"
+
+#include <QMainWindow>
+#include <QPushButton>
+#include <QTableWidget>
+#include <QString>
+#include <QRect>
+
+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 ) );
+}
--- /dev/null
+#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
#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 <QObject>
+#include <QTableWidgetItem>
+#include <QPushButton>
+#include <QDebug>
-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 );
}
#ifndef UICONTROLLER_H
#define UICONTROLLER_H
-#include "ui_zouba.h"
#include "routedata.h"
#include <QObject>
+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
TEMPLATE = app
-FORMS = zouba.ui
+#FORMS = zouba.ui
SOURCES += \
main.cpp \
location.cpp \
location_p.cpp \
gpscontroller.cpp \
+ ui.cpp \
HEADERS += \
route.h \
location_p.h \
ytv.h \
gpscontroller.h \
+ ui.h \