Changes: fixed buttons and table
authorMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Wed, 17 Mar 2010 16:33:33 +0000 (18:33 +0200)
committerMax Waterman <davidmaxwaterman+maemogit@fastmail.co.uk>
Wed, 17 Mar 2010 16:33:33 +0000 (18:33 +0200)
zouba/gpscontroller.cpp
zouba/location.h
zouba/main.cpp
zouba/ui.cpp
zouba/ui.h
zouba/uicontroller.cpp
zouba/uicontroller.h
zouba/ytv.h

index 618746a..61fbdbc 100644 (file)
@@ -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__;
index 82db0fc..a7b76cc 100644 (file)
@@ -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;
index 761cfcb..c65b91d 100644 (file)
@@ -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();
 }
index d36baab..ab82b1b 100644 (file)
@@ -5,10 +5,12 @@
 #include <QTableWidget>
 #include <QString>
 #include <QRect>
+#include <QButtonGroup>
+#include <QHeaderView>
 
 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();
 }
index a232ad9..886b50b 100644 (file)
@@ -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
index 9df97b2..d2c1c71 100644 (file)
@@ -1,22 +1,74 @@
 #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__;
@@ -28,5 +80,4 @@ void UiController::displayRoute( const RouteData &routeData )
 
   QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.lineCode );
   ui->table->setItem( 0, 1, lineItem );
-
 }
index f524a42..d7c2afb 100644 (file)
@@ -2,6 +2,7 @@
 #define UICONTROLLER_H
 
 #include "routedata.h"
+#include "location.h"
 
 #include <QObject>
 
@@ -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<Location*> destination;
   Ui *ui;
+  int currentDestination;
 };
 #endif // UICONTROLLER_H
 
index 16915f0..b0e1617 100644 (file)
@@ -1,4 +1,3 @@
-
 #include <QUrl>
 #include <QString>