Changes: display route legs in table; removed message table/button
authorMax Waterman <david.waterman@nokia.com>
Thu, 22 Apr 2010 15:37:55 +0000 (18:37 +0300)
committerMax Waterman <david.waterman@nokia.com>
Thu, 22 Apr 2010 15:37:55 +0000 (18:37 +0300)
12 files changed:
zouba/src/main.cpp
zouba/src/messagehandler.cpp [deleted file]
zouba/src/messagehandler.h [deleted file]
zouba/src/messagetable.cpp [deleted file]
zouba/src/messagetable.h [deleted file]
zouba/src/route.cpp
zouba/src/route.h
zouba/src/ui.cpp
zouba/src/ui.h
zouba/src/uicontroller.cpp
zouba/src/uicontroller.h
zouba/zouba.pro

index ffe72e3..bd3898b 100644 (file)
@@ -5,8 +5,6 @@
 #include "location.h"
 #include "gpscontroller.h"
 #include "ytv.h"
-#include "messagetable.h"
-#include "messagehandler.h"
 
 #include <QDebug>
 #include <QObject>
@@ -15,7 +13,6 @@
 
 int main(int argc, char *argv[] )
 {
-  //qInstallMsgHandler( messageHandler );
   QApplication app(argc, argv);
 
   QMainWindow *mainWindow = new QMainWindow;
@@ -56,6 +53,11 @@ int main(int argc, char *argv[] )
       gpsController, SLOT( useLiveGps() )
     );
 
+  QObject::connect(
+      route, SIGNAL( busy( bool ) ),
+      ui, SLOT( setBusy( bool ) )
+    );
+
   mainWindow->show();
 
   return app.exec();
diff --git a/zouba/src/messagehandler.cpp b/zouba/src/messagehandler.cpp
deleted file mode 100644 (file)
index 7c03d9a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "messagehandler.h"
-
-#include "messagetable.h"
-#include <QString>
-#include <QtGlobal>
-#include <QTime>
-
-void messageHandler( QtMsgType type, const char *msg )
-{
-  Q_UNUSED( type );
-
-  if ( Ui::messageTable != 0 ) {
-    Ui::messageTable->displayMessage( 
-        QTime::currentTime().toString()+" "+QString::fromLatin1( msg )
-        );
-  }
-}
-
diff --git a/zouba/src/messagehandler.h b/zouba/src/messagehandler.h
deleted file mode 100644 (file)
index 1ab9263..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef MESSAGEHANDLER_H
-#define MESSAGEHANDLER_H
-
-#include "ui.h"
-
-#include <QtGlobal>
-
-void messageHandler( QtMsgType type, const char *msg );
-
-#endif //MESSAGEHANDLER_H
diff --git a/zouba/src/messagetable.cpp b/zouba/src/messagetable.cpp
deleted file mode 100644 (file)
index 8d0fa38..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "messagetable.h"
-
-#include <QHeaderView>
-#include <QString>
-#include <QStringList>
-#include <QDebug>
-#include <QResizeEvent>
-
-MessageTable::MessageTable( QWidget *parent ) :
-  QTableWidget( NumberOfRows, OneColumn, parent )
-{
-  setHorizontalHeaderLabels( QStringList() << "Messages" );
-  verticalHeader()->hide();
-  setSelectionMode( QAbstractItemView::NoSelection );
-
-  for ( int row=0; row<NumberOfRows; ++row ) {
-    QTableWidgetItem *newRow = new QTableWidgetItem();
-    setItem( row,0, newRow );
-  }
-}
-
-MessageTable::~MessageTable()
-{
-}
-
-void MessageTable::displayMessage( const QString &message )
-{
-  // scroll items down from bottom to top
-  for ( int row=NumberOfRows-1; row>0; --row ) {
-    QTableWidgetItem *fromItem = item(0,row-1);
-    QTableWidgetItem *toItem = item(0,row);
-    QString text=fromItem->text();
-    toItem->setText( text );
-  }
-
-  itemAt(0,0)->setText( message );
-}
-
-void MessageTable::resizeEvent( QResizeEvent *event )
-{
-  int width = event->size().width() / columnCount();
-  for ( int i = 0; i < columnCount(); ++i ) {
-    setColumnWidth( i, width );
-  }
-}
diff --git a/zouba/src/messagetable.h b/zouba/src/messagetable.h
deleted file mode 100644 (file)
index f8b768f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef MESSAGETABLE_H
-#define MESSAGETABLE_H
-
-#include <QWidget>
-#include <QTableWidget>
-class QResizeEvent;
-
-class MessageTable : public QTableWidget
-{
-  Q_OBJECT
-
-  enum {
-    NumberOfRows=100,
-    OneColumn=1
-  };
-
-public:
-  MessageTable( QWidget *parent=0 );
-  ~MessageTable();
-
-  void displayMessage( const QString &message );
-
-protected:
-  void resizeEvent( QResizeEvent *event );
-};
-#endif //MESSAGETABLE_H
index aefc185..5d5e794 100644 (file)
@@ -12,6 +12,7 @@
 #include <QStringList>
 #include <QString>
 #include <QXmlStreamReader>
+#include <QWidget>
 
 #include "ytv.h"
 
@@ -50,6 +51,7 @@ void Route::getRoute()
   manager->get( QNetworkRequest( fullUrl ) );
   qDebug() << "getting url" << fullUrl.toEncoded();
   qDebug() << "waiting for reply from Ytv";
+  emit( busy( true ) );
 }
 
 void Route::replyFinished( QNetworkReply * reply )
@@ -58,6 +60,7 @@ void Route::replyFinished( QNetworkReply * reply )
   QList<RouteData> routeData = q->parseReply( reply->readAll() );
 
   emit( routeReady( routeData ) );
+  emit( busy( false ) );
 }
 
 void Route::setFromLocation( Location *location )
@@ -76,6 +79,9 @@ void Route::setFromLocation( Location *location )
   } else {
     qDebug() << "ERROR:From is not valid";
     qDebug() << "location=" << location;
+    if ( location ) {
+      qDebug() << "location->isValid()=" << location->isValid();
+    }
   }
 }
 
@@ -98,8 +104,11 @@ void Route::setToLocation( Location *location )
       qDebug() << "From not valid - waiting";
     }
   } else {
-    qDebug() << "To is not valid";
-    qDebug() << "ERROR:location is zero; cast failed";
+    qDebug() << "ERROR:From is not valid";
+    qDebug() << "location=" << location;
+    if ( location ) {
+      qDebug() << "location->isValid()=" << location->isValid();
+    }
   }
 }
 
index 5cdccd4..9a311b5 100644 (file)
@@ -51,6 +51,7 @@ public Q_SLOTS:
 
 Q_SIGNALS:
   void routeReady( QList<RouteData> );
+  void busy( bool busy );
 
 private Q_SLOTS:
   void replyFinished( QNetworkReply* );
index 1b6784f..4269013 100644 (file)
@@ -1,6 +1,5 @@
 #include "ui.h"
 
-#include "messagetable.h"
 #include "locations.h"
 #include "ytv.h"
 
 #include <QInputDialog>
 #include <QDebug>
 
-MessageTable *Ui::messageTable = 0;
-
 Ui::Ui() :
-  centralWidget(0),
-  destinationButtons(0),
-  routeStack(0),
-  usingFakeGps( false ),
-  messagesShown( false ),
-  fakeLocationLabel( "work" )
+  m_centralWidget(0),
+  m_destinationButtons(0),
+  m_routeStack(0),
+  m_usingFakeGps( false ),
+  m_fakeLocationLabel( "work" )
 {
 }
 
@@ -38,17 +34,17 @@ Ui::~Ui()
 
 void Ui::setupUi( QMainWindow *mainWindow )
 {
-  mainWindow->resize(800,480);
-  menu = mainWindow->menuBar()->addMenu("Settings");
+  m_mainWindow = mainWindow;
+  m_mainWindow->resize(800,480);
+
+  m_menu = mainWindow->menuBar()->addMenu("Settings");
 
   QAction *setHomeAddressAction = new QAction("Set home address", this);
   QAction *setWorkAddressAction = new QAction("Set work address", this);
-  toggleMessagesAction = new QAction("Show messages", this);
-  toggleFakeGpsAction  = new QAction("Use fake GPS", this);
-  menu->addAction(setHomeAddressAction);
-  menu->addAction(setWorkAddressAction);
-  menu->addAction(toggleMessagesAction);
-  menu->addAction(toggleFakeGpsAction);
+  m_toggleFakeGpsAction  = new QAction("Use fake GPS", this);
+  m_menu->addAction(setHomeAddressAction);
+  m_menu->addAction(setWorkAddressAction);
+  m_menu->addAction(m_toggleFakeGpsAction);
 
   connect(
       setHomeAddressAction, SIGNAL(triggered()),
@@ -59,16 +55,12 @@ void Ui::setupUi( QMainWindow *mainWindow )
       this, SLOT(setWorkAddress())
       );
   connect(
-      toggleMessagesAction, SIGNAL(triggered()),
-      this, SLOT(toggleMessages())
-      );
-  connect(
-      toggleFakeGpsAction, SIGNAL(triggered()),
+      m_toggleFakeGpsAction, SIGNAL(triggered()),
       this, SLOT(toggleFakeGps())
       );
 
-  centralWidget = new QWidget( mainWindow );
-  mainWindow->setCentralWidget(centralWidget);
+  m_centralWidget = new QWidget( m_mainWindow );
+  m_mainWindow->setCentralWidget( m_centralWidget);
 
   QRadioButton *homeButton = new QRadioButton();
   homeButton->setObjectName( QString::fromUtf8("homeButton") );
@@ -80,39 +72,40 @@ void Ui::setupUi( QMainWindow *mainWindow )
   workButton->setText( "GPS->WORK" );
   workButton->setEnabled(false);
 
-  destinationButtons = new QButtonGroup();
-  destinationButtons->addButton( homeButton, HomeButtonId );
-  destinationButtons->addButton( workButton, WorkButtonId );
-  destinationButtons->setExclusive( true );
+  m_destinationButtons = new QButtonGroup();
+  m_destinationButtons->addButton( homeButton, HomeButtonId );
+  m_destinationButtons->addButton( workButton, WorkButtonId );
+  m_destinationButtons->setExclusive( true );
 
-  routeStack = new QVBoxLayout();
+  m_routeButtons = new QButtonGroup();
+  m_routeButtons->setExclusive( true );
+  m_routeStack = new QVBoxLayout();
   for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
     QRadioButton *button = new QRadioButton();
     button->setObjectName( "routeButton"+i );
     button->setEnabled( false );
 
-    routeStack->addWidget( button, i );
+    m_routeStack->addWidget( button, i );
+    m_routeButtons->addButton( button, i );
   }
-  routeStack->addStretch();
+  m_routeStack->addStretch();
 
-  QHBoxLayout *topLayout = new QHBoxLayout();
-  topLayout->addLayout( routeStack );
-  topLayout->addStretch();
+  m_routeDetailTable = new QTableWidget();
+  m_routeDetailTable->setColumnCount(6);
 
-  buttonLayout = new QGridLayout();
-  buttonLayout->addWidget( homeButton, 0, 0 );
-  buttonLayout->addWidget( workButton, 0, 1 );
+  QHBoxLayout *topLayout = new QHBoxLayout();
+  topLayout->addLayout( m_routeStack );
+  topLayout->addWidget( m_routeDetailTable );
 
-  messageTable = new MessageTable();
-  messageTable->setObjectName( QString::fromUtf8("messageTable") );
-  messageTable->hide();
+  m_buttonLayout = new QGridLayout();
+  m_buttonLayout->addWidget( homeButton, 0, 0 );
+  m_buttonLayout->addWidget( workButton, 0, 1 );
 
-  QVBoxLayout *mainLayout = new QVBoxLayout();
-  mainLayout->addLayout( topLayout );
-  mainLayout->addWidget( messageTable );
-  mainLayout->addLayout( buttonLayout );
+  m_mainLayout = new QVBoxLayout();
+  m_mainLayout->addLayout( topLayout );
+  m_mainLayout->addLayout( m_buttonLayout );
 
-  centralWidget->setLayout( mainLayout );
+  m_centralWidget->setLayout( m_mainLayout );
 }
 
 void Ui::setHomeAddress()
@@ -125,34 +118,11 @@ void Ui::setWorkAddress()
   setAddress( "work" );
 }
 
-void Ui::toggleMessages()
-{
-  messagesShown = !messagesShown;
-
-  if ( messagesShown ) {
-    showMessages();
-  } else {
-    hideMessages();
-  }
-}
-
-void Ui::hideMessages()
-{
-  messageTable->hide();
-  toggleMessagesAction->setText( "Show messages" );
-}
-
-void Ui::showMessages()
-{
-  messageTable->show();
-  toggleMessagesAction->setText( "Hide messages" );
-}
-
 void Ui::toggleFakeGps()
 {
-  usingFakeGps = !usingFakeGps;
+  m_usingFakeGps = !m_usingFakeGps;
 
-  if ( usingFakeGps ) {
+  if ( m_usingFakeGps ) {
     useFakeGps();
   } else {
     useLiveGps();
@@ -161,14 +131,14 @@ void Ui::toggleFakeGps()
 
 void Ui::useFakeGps()
 {
-  emit fakeGpsPressed( fakeLocationLabel );
-  toggleFakeGpsAction->setText( "Use Live GPS" );
+  emit fakeGpsPressed( m_fakeLocationLabel );
+  m_toggleFakeGpsAction->setText( "Use Live GPS" );
 }
 
 void Ui::useLiveGps()
 {
   emit liveGpsPressed();
-  toggleFakeGpsAction->setText( "Use Fake GPS" );
+  m_toggleFakeGpsAction->setText( "Use Fake GPS" );
 }
 
 void Ui::setAddress( const QString &label )
@@ -178,7 +148,7 @@ void Ui::setAddress( const QString &label )
 
   bool ok;
   QString address = QInputDialog::getText(
-     centralWidget,
+     m_centralWidget,
      tr("Enter address for \""+QString(label).toLatin1()+"\""),
      tr("Address"),
      QLineEdit::Normal,
@@ -196,3 +166,8 @@ void Ui::setAddress( const QString &label )
     }
   }
 }
+
+void Ui::setBusy( bool busy )
+{
+  m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+}
index 2a30cf8..94dc687 100644 (file)
@@ -7,7 +7,6 @@ class QMainWindow;
 class QWidget;
 class QTableWidget;
 class QButtonGroup;
-class MessageTable;
 class QHBoxLayout;
 class QVBoxLayout;
 class QGridLayout;
@@ -34,19 +33,19 @@ public:
     ScreenHeight=480
   };
 
-  QWidget *centralWidget;
-  QButtonGroup *destinationButtons;
-  QVBoxLayout *routeStack;
-  static MessageTable *messageTable;
-  QHBoxLayout *mainLayout;
-  QGridLayout *buttonLayout;
-  QMenu       *menu;
-  QAction     *toggleMessagesAction;
-  QAction     *toggleFakeGpsAction;
-  QAction     *useLiveGpsAction;
-  bool        usingFakeGps;
-  bool        messagesShown;
-  QString     fakeLocationLabel;
+  QMainWindow *m_mainWindow;
+  QWidget *m_centralWidget;
+  QButtonGroup *m_destinationButtons;
+  QButtonGroup *m_routeButtons;
+  QVBoxLayout *m_routeStack;
+  QTableWidget *m_routeDetailTable;
+  QVBoxLayout *m_mainLayout;
+  QGridLayout *m_buttonLayout;
+  QMenu       *m_menu;
+  QAction     *m_toggleFakeGpsAction;
+  QAction     *m_useLiveGpsAction;
+  bool        m_usingFakeGps;
+  QString     m_fakeLocationLabel;
 
 Q_SIGNALS:
   void homeAddressChanged( QString address );
@@ -57,14 +56,12 @@ Q_SIGNALS:
 private Q_SLOTS:
   void setHomeAddress();
   void setWorkAddress();
-  void toggleMessages();
   void toggleFakeGps();
+  void setBusy( bool busy );
 
 private:
   void useFakeGps();
   void useLiveGps();
-  void hideMessages();
-  void showMessages();
   void setAddress( const QString &label );
 };
 #endif //UI_H
index f75b0a8..4108d2d 100644 (file)
@@ -3,7 +3,6 @@
 #include "ui.h"
 #include "ytv.h"
 #include "location.h"
-#include "messagetable.h"
 #include "locations.h"
 
 #include <QObject>
 #include <QButtonGroup>
 #include <QRadioButton>
 #include <QVBoxLayout>
+#include <QTableWidgetItem>
 
 UiController::UiController( Ui *ui ) :
-  ui(ui)
+  m_routeData(),
+  m_destination(),
+  m_ui(ui),
+  m_currentDestination(-1),
+  m_currentRoute(-1)
 {
   Locations *locations = Locations::instance();
   Location *homeLocation = locations->location( "home" );
@@ -52,13 +56,18 @@ UiController::UiController( Ui *ui ) :
       locations, SLOT( saveLocation() )
       );
 
-  destination.append( homeLocation );
-  destination.append( workLocation );
+  m_destination.append( homeLocation );
+  m_destination.append( workLocation );
 
   connect(
-      ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
+      m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ),
       this, SLOT( changeDestination( int ) )
   );
+
+  connect(
+      m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ),
+      this, SLOT( changeRoute( int ) )
+  );
 }
 
 UiController::~UiController()
@@ -79,16 +88,18 @@ void UiController::setWorkButtonValid()
 
 void UiController::setButtonValid( int id )
 {
-  ui->destinationButtons->button( id )->setEnabled(true);
+  m_ui->m_destinationButtons->button( id )->setEnabled(true);
 }
 
 void UiController::changeDestination( int id )
 {
-  qDebug() << "Button "+QString::number(id)+" clicked";
+  qDebug() << "Destination button "+QString::number(id)+" clicked";
 
-  bool destinationHasChanged = ( currentDestination != id );
+  bool destinationHasChanged = ( m_currentDestination != id );
+  qDebug() << "Destination has changed=" << destinationHasChanged;
   if ( destinationHasChanged ) {
-    emit destinationChanged( destination[id] );
+    qDebug() << "Emitting destination changed (" << m_destination[id]->label() << ")";
+    emit destinationChanged( m_destination[id] );
   }
 
   // always want to emit this so that the gps position is update
@@ -96,14 +107,62 @@ void UiController::changeDestination( int id )
   emit buttonClicked();
 }
 
+void UiController::changeRoute( int id )
+{
+  qDebug() << "Route button "+QString::number(id)+" clicked";
+
+  bool routeHasChanged = ( m_currentRoute != id );
+  if ( routeHasChanged ) {
+    displayRouteDetail( id );
+  }
+}
+
+void UiController::displayRouteDetail( int id )
+{
+  QTableWidget *table = m_ui->m_routeDetailTable;
+
+  if ( id < m_routeData.count() ) {
+    QList<LegData> &legDataList = m_routeData[ id ].m_legData;
+    table->setRowCount( legDataList.count() );
+
+    int row=0;
+    foreach( LegData thisLegData, legDataList ) {
+
+      QStringList tableStrings;
+      tableStrings
+        << thisLegData.m_how
+        << thisLegData.m_tripTime
+        << thisLegData.m_tripDistance
+        << thisLegData.m_departureTime
+        << thisLegData.m_arrivalTime
+        << thisLegData.m_lineCode;
+
+      int col=0;
+      foreach( QString thisString, tableStrings ) {
+        QTableWidgetItem *newItem = new QTableWidgetItem();
+        newItem->setText( thisString );
+        table->setItem( row,col, newItem );
+        ++col;
+      }
+
+      ++row;
+    }
+  } else {
+    table->setRowCount( 0 );
+  }
+  table->resizeColumnsToContents();
+}
+
 void UiController::displayRoute( const QList<RouteData> &routeData )
 {
+  m_routeData = routeData;
+
   qDebug() << "displaying route";
 
   for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
     QString label;
 
-    QWidget *widget = ui->routeStack->itemAt( i )->widget();
+    QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
     QRadioButton *button = qobject_cast<QRadioButton *>(widget);
 
     if ( i<routeData.count() ) {
@@ -119,4 +178,7 @@ void UiController::displayRoute( const QList<RouteData> &routeData )
     button->setText( label );
   }
 
+  QTableWidget *table = m_ui->m_routeDetailTable;
+  table->setRowCount( 0 );
+  table->resizeColumnsToContents();
 }
index 9657b8e..a220031 100644 (file)
@@ -25,16 +25,20 @@ Q_SIGNALS:
 
 private Q_SLOTS:
   void changeDestination( int id );
+  void changeRoute( int id );
   void setHomeButtonValid();
   void setWorkButtonValid();
+  void displayRouteDetail( int id );
 
 private:
   void setButtonValid( int id );
 
 private:
-  QList<Location*> destination;
-  Ui *ui;
-  int currentDestination;
+  QList<RouteData> m_routeData;
+  QList<Location*> m_destination;
+  Ui *m_ui;
+  int m_currentDestination;
+  int m_currentRoute;
 };
 #endif // UICONTROLLER_H
 
index 57c19b1..845d0ff 100644 (file)
@@ -10,8 +10,6 @@ SOURCES += \
     gpscontroller.cpp \
     gpscontroller_p.cpp \
     ui.cpp \
-    messagetable.cpp \
-    messagehandler.cpp \
 
 HEADERS += \
     route.h \
@@ -24,14 +22,13 @@ HEADERS += \
     gpscontroller.h \
     gpscontroller_p.h \
     ui.h \
-    messagetable.h \
-    messagehandler.h \
 
 FORMS       +=
 LEXSOURCES  += #LEXS#
 YACCSOURCES += #YACCS#
 
 INCLUDEPATH += include
+DEPENDSPATH += INCLUDEPATH
 #QMAKE_LIBDIR_QT = qt4-maemo5/lib
 #QMAKE_INCDIR_QT = qt4-maemo5/include
 LIBS        += -Llib -lQtBearer -lQtLocation