QTM_USE_NAMESPACE
-GpsController::~GpsController()
-{
- qDebug() << __PRETTY_FUNCTION__;
- delete m_location;
- m_location = 0;
-}
-
GpsController::GpsController() :
m_location( QGeoPositionInfoSource::createDefaultSource(this) )
{
m_location->stopUpdates();
}
+GpsController::~GpsController()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ delete m_location;
+ m_location = 0;
+}
+
void GpsController::updateLocation( QGeoPositionInfo positionInfo )
{
qDebug() << __PRETTY_FUNCTION__;
bool isValid() const;
- public Q_SLOTS:
- void resolveAddress( QString address );
+public Q_SLOTS:
+ void resolveAddress( QString address );
Q_SIGNALS:
void becomeValid();
- private Q_SLOTS:
- void replyFinished( QNetworkReply * reply );
+private Q_SLOTS:
+ void replyFinished( QNetworkReply * reply );
private:
LocationPrivate *q;
UiController *uiController = new UiController( &ui );
Route *route = new Route();
GpsController *gpsController = new GpsController();
- Location *to = new Location();
QObject::connect(
route, SIGNAL( routeReady( RouteData ) ),
);
QObject::connect(
- to, SIGNAL( becomeValid() ),
- route, SLOT( setToLocation() )
- );
+ uiController, SIGNAL( destinationChanged( Location ) ),
+ route, SLOT( setToLocation( Location ) )
+ );
QObject::connect(
- uiController, SIGNAL( homePressed() ),
+ uiController, SIGNAL( buttonClicked() ),
gpsController, SLOT( startGps() )
);
mainWindow->show();
- to->resolveAddress( work );
-
return app.exec();
}
#include <QTableWidget>
#include <QString>
#include <QRect>
+#include <QButtonGroup>
+#include <QHeaderView>
Ui::Ui() :
centralWidget(0),
- trigger(0),
+ destinationButtons(0),
table(0)
{
}
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 ) );
+ QPushButton *homeButton = new QPushButton( centralWidget );
+ homeButton->setObjectName( QString::fromUtf8("homeButton") );
+ homeButton->setText( "HOME" );
+ homeButton->setGeometry( QRect( 0, 0, 150, 40 ) );
+ homeButton->setEnabled(false);
+
+ QPushButton *workButton = new QPushButton( centralWidget );
+ workButton->setObjectName( QString::fromUtf8("workButton") );
+ workButton->setText( "WORK" );
+ workButton->setGeometry( QRect( 0, 40, 150, 40 ) );
+ workButton->setEnabled(false);
+
+ destinationButtons = new QButtonGroup( centralWidget );
+ destinationButtons->addButton( homeButton, HomeButtonId );
+ destinationButtons->addButton( workButton, WorkButtonId );
table = new QTableWidget( 1, 2, centralWidget );
table->setObjectName( QString::fromUtf8("table") );
table->setGeometry( QRect( 151, 0, 650, 480 ) );
+ QStringList columnHeaders;
+ columnHeaders << "Time" << "Bus";
+ table->setHorizontalHeaderLabels( columnHeaders );
+ table->verticalHeader()->hide();
}
class QMainWindow;
class QWidget;
-class QPushButton;
class QTableWidget;
+class QButtonGroup;
class Ui
{
~Ui();
void setupUi( QMainWindow *mainWindow );
+ enum {
+ HomeButtonId=0,
+ WorkButtonId=1
+ };
+
QWidget *centralWidget;
- QPushButton *trigger;
+ QButtonGroup *destinationButtons;
QTableWidget *table;
};
#endif //UI_H
#include "uicontroller.h"
#include "route.h"
#include "ui.h"
+#include "ytv.h"
+#include "location.h"
#include <QObject>
#include <QTableWidgetItem>
#include <QPushButton>
#include <QDebug>
+#include <QButtonGroup>
UiController::UiController( Ui *ui ) :
ui(ui)
{
- connect( ui->trigger, SIGNAL( pressed() ), this, SIGNAL( homePressed() ) );
+ Location *homeLocation = new Location();
+ Location *workLocation = new Location();
+
+ connect(
+ homeLocation, SIGNAL( becomeValid() ),
+ this, SLOT( setHomeButtonValid() )
+ );
+ connect(
+ workLocation, SIGNAL( becomeValid() ),
+ this, SLOT( setWorkButtonValid() )
+ );
+
+ homeLocation->resolveAddress( home );
+ workLocation->resolveAddress( work );
+
+ destination.append( homeLocation );
+ destination.append( workLocation );
+
+ connect(
+ ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
+ this, SLOT( changeDestination( int ) )
+ );
+
}
UiController::~UiController()
{
}
+void UiController::setHomeButtonValid()
+{
+ setButtonValid( Ui::HomeButtonId );
+}
+
+void UiController::setWorkButtonValid()
+{
+ setButtonValid( Ui::WorkButtonId );
+}
+
+void UiController::setButtonValid( int id )
+{
+ ui->destinationButtons->button( id )->setEnabled(true);
+}
+
+void UiController::changeDestination( int id )
+{
+ bool destinationHasChanged = ( currentDestination != id );
+ if ( destinationHasChanged ) {
+ emit destinationChanged( *(destination[id]) );
+ }
+
+ // always want to emit this so that the gps position is update
+ // and the user gets new information
+ emit buttonClicked();
+}
+
void UiController::displayRoute( const RouteData &routeData )
{
qDebug() << __PRETTY_FUNCTION__;
QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode );
ui->table->setItem( 0, 1, lineItem );
-
}
#define UICONTROLLER_H
#include "routedata.h"
+#include "location.h"
#include <QObject>
void displayRoute( const RouteData &routeData );
Q_SIGNALS:
- void homePressed();
+ void buttonClicked();
+ void destinationChanged( Location newDestination );
+
+private Q_SLOTS:
+ void changeDestination( int id );
+ void setHomeButtonValid();
+ void setWorkButtonValid();
+
+private:
+ void setButtonValid( int id );
private:
+ QList<Location*> destination;
Ui *ui;
+ int currentDestination;
};
#endif // UICONTROLLER_H
-
#include <QUrl>
#include <QString>