From d57b981dbf653ab766f83f4c7e663a15002a2a79 Mon Sep 17 00:00:00 2001 From: Max Waterman Date: Wed, 17 Mar 2010 18:33:33 +0200 Subject: [PATCH] Changes: fixed buttons and table --- zouba/gpscontroller.cpp | 14 ++++++------ zouba/location.h | 8 +++---- zouba/main.cpp | 11 ++++------ zouba/ui.cpp | 27 ++++++++++++++++++----- zouba/ui.h | 9 ++++++-- zouba/uicontroller.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++-- zouba/uicontroller.h | 14 +++++++++++- zouba/ytv.h | 1 - 8 files changed, 110 insertions(+), 29 deletions(-) diff --git a/zouba/gpscontroller.cpp b/zouba/gpscontroller.cpp index 618746a..61fbdbc 100644 --- a/zouba/gpscontroller.cpp +++ b/zouba/gpscontroller.cpp @@ -7,13 +7,6 @@ QTM_USE_NAMESPACE -GpsController::~GpsController() -{ - qDebug() << __PRETTY_FUNCTION__; - delete m_location; - m_location = 0; -} - GpsController::GpsController() : m_location( QGeoPositionInfoSource::createDefaultSource(this) ) { @@ -28,6 +21,13 @@ GpsController::GpsController() : m_location->stopUpdates(); } +GpsController::~GpsController() +{ + qDebug() << __PRETTY_FUNCTION__; + delete m_location; + m_location = 0; +} + void GpsController::updateLocation( QGeoPositionInfo positionInfo ) { qDebug() << __PRETTY_FUNCTION__; diff --git a/zouba/location.h b/zouba/location.h index 82db0fc..a7b76cc 100644 --- a/zouba/location.h +++ b/zouba/location.h @@ -31,14 +31,14 @@ public: 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; diff --git a/zouba/main.cpp b/zouba/main.cpp index 761cfcb..c65b91d 100644 --- a/zouba/main.cpp +++ b/zouba/main.cpp @@ -22,7 +22,6 @@ int main(int argc, char *argv[] ) UiController *uiController = new UiController( &ui ); Route *route = new Route(); GpsController *gpsController = new GpsController(); - Location *to = new Location(); QObject::connect( route, SIGNAL( routeReady( RouteData ) ), @@ -35,18 +34,16 @@ int main(int argc, char *argv[] ) ); 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(); } diff --git a/zouba/ui.cpp b/zouba/ui.cpp index d36baab..ab82b1b 100644 --- a/zouba/ui.cpp +++ b/zouba/ui.cpp @@ -5,10 +5,12 @@ #include #include #include +#include +#include Ui::Ui() : centralWidget(0), - trigger(0), + destinationButtons(0), table(0) { } @@ -24,12 +26,27 @@ void Ui::setupUi( QMainWindow *mainWindow ) 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(); } diff --git a/zouba/ui.h b/zouba/ui.h index a232ad9..886b50b 100644 --- a/zouba/ui.h +++ b/zouba/ui.h @@ -3,8 +3,8 @@ class QMainWindow; class QWidget; -class QPushButton; class QTableWidget; +class QButtonGroup; class Ui { @@ -13,8 +13,13 @@ public: ~Ui(); void setupUi( QMainWindow *mainWindow ); + enum { + HomeButtonId=0, + WorkButtonId=1 + }; + QWidget *centralWidget; - QPushButton *trigger; + QButtonGroup *destinationButtons; QTableWidget *table; }; #endif //UI_H diff --git a/zouba/uicontroller.cpp b/zouba/uicontroller.cpp index 9df97b2..d2c1c71 100644 --- a/zouba/uicontroller.cpp +++ b/zouba/uicontroller.cpp @@ -1,22 +1,74 @@ #include "uicontroller.h" #include "route.h" #include "ui.h" +#include "ytv.h" +#include "location.h" #include #include #include #include +#include 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__; @@ -28,5 +80,4 @@ void UiController::displayRoute( const RouteData &routeData ) QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode ); ui->table->setItem( 0, 1, lineItem ); - } diff --git a/zouba/uicontroller.h b/zouba/uicontroller.h index f524a42..d7c2afb 100644 --- a/zouba/uicontroller.h +++ b/zouba/uicontroller.h @@ -2,6 +2,7 @@ #define UICONTROLLER_H #include "routedata.h" +#include "location.h" #include @@ -19,10 +20,21 @@ public Q_SLOTS: 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 destination; Ui *ui; + int currentDestination; }; #endif // UICONTROLLER_H diff --git a/zouba/ytv.h b/zouba/ytv.h index 16915f0..b0e1617 100644 --- a/zouba/ytv.h +++ b/zouba/ytv.h @@ -1,4 +1,3 @@ - #include #include -- 1.7.9.5