From 90527f16c3240acbaf237d1cd630580df590c9df Mon Sep 17 00:00:00 2001 From: Max Waterman Date: Thu, 22 Apr 2010 18:37:55 +0300 Subject: [PATCH] Changes: display route legs in table; removed message table/button --- zouba/src/main.cpp | 8 +-- zouba/src/messagehandler.cpp | 18 ------- zouba/src/messagehandler.h | 10 ---- zouba/src/messagetable.cpp | 45 ---------------- zouba/src/messagetable.h | 26 --------- zouba/src/route.cpp | 13 ++++- zouba/src/route.h | 1 + zouba/src/ui.cpp | 123 +++++++++++++++++------------------------- zouba/src/ui.h | 31 +++++------ zouba/src/uicontroller.cpp | 82 ++++++++++++++++++++++++---- zouba/src/uicontroller.h | 10 ++-- zouba/zouba.pro | 5 +- 12 files changed, 160 insertions(+), 212 deletions(-) delete mode 100644 zouba/src/messagehandler.cpp delete mode 100644 zouba/src/messagehandler.h delete mode 100644 zouba/src/messagetable.cpp delete mode 100644 zouba/src/messagetable.h diff --git a/zouba/src/main.cpp b/zouba/src/main.cpp index ffe72e3..bd3898b 100644 --- a/zouba/src/main.cpp +++ b/zouba/src/main.cpp @@ -5,8 +5,6 @@ #include "location.h" #include "gpscontroller.h" #include "ytv.h" -#include "messagetable.h" -#include "messagehandler.h" #include #include @@ -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 index 7c03d9a..0000000 --- a/zouba/src/messagehandler.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "messagehandler.h" - -#include "messagetable.h" -#include -#include -#include - -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 index 1ab9263..0000000 --- a/zouba/src/messagehandler.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MESSAGEHANDLER_H -#define MESSAGEHANDLER_H - -#include "ui.h" - -#include - -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 index 8d0fa38..0000000 --- a/zouba/src/messagetable.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "messagetable.h" - -#include -#include -#include -#include -#include - -MessageTable::MessageTable( QWidget *parent ) : - QTableWidget( NumberOfRows, OneColumn, parent ) -{ - setHorizontalHeaderLabels( QStringList() << "Messages" ); - verticalHeader()->hide(); - setSelectionMode( QAbstractItemView::NoSelection ); - - for ( int row=0; row0; --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 index f8b768f..0000000 --- a/zouba/src/messagetable.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MESSAGETABLE_H -#define MESSAGETABLE_H - -#include -#include -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 diff --git a/zouba/src/route.cpp b/zouba/src/route.cpp index aefc185..5d5e794 100644 --- a/zouba/src/route.cpp +++ b/zouba/src/route.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #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 = 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(); + } } } diff --git a/zouba/src/route.h b/zouba/src/route.h index 5cdccd4..9a311b5 100644 --- a/zouba/src/route.h +++ b/zouba/src/route.h @@ -51,6 +51,7 @@ public Q_SLOTS: Q_SIGNALS: void routeReady( QList ); + void busy( bool busy ); private Q_SLOTS: void replyFinished( QNetworkReply* ); diff --git a/zouba/src/ui.cpp b/zouba/src/ui.cpp index 1b6784f..4269013 100644 --- a/zouba/src/ui.cpp +++ b/zouba/src/ui.cpp @@ -1,6 +1,5 @@ #include "ui.h" -#include "messagetable.h" #include "locations.h" #include "ytv.h" @@ -20,15 +19,12 @@ #include #include -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; isetObjectName( "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); +} diff --git a/zouba/src/ui.h b/zouba/src/ui.h index 2a30cf8..94dc687 100644 --- a/zouba/src/ui.h +++ b/zouba/src/ui.h @@ -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 diff --git a/zouba/src/uicontroller.cpp b/zouba/src/uicontroller.cpp index f75b0a8..4108d2d 100644 --- a/zouba/src/uicontroller.cpp +++ b/zouba/src/uicontroller.cpp @@ -3,7 +3,6 @@ #include "ui.h" #include "ytv.h" #include "location.h" -#include "messagetable.h" #include "locations.h" #include @@ -12,9 +11,14 @@ #include #include #include +#include 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 &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 ) { + m_routeData = routeData; + qDebug() << "displaying route"; for ( int i=0; irouteStack->itemAt( i )->widget(); + QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget(); QRadioButton *button = qobject_cast(widget); if ( i &routeData ) button->setText( label ); } + QTableWidget *table = m_ui->m_routeDetailTable; + table->setRowCount( 0 ); + table->resizeColumnsToContents(); } diff --git a/zouba/src/uicontroller.h b/zouba/src/uicontroller.h index 9657b8e..a220031 100644 --- a/zouba/src/uicontroller.h +++ b/zouba/src/uicontroller.h @@ -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 destination; - Ui *ui; - int currentDestination; + QList m_routeData; + QList m_destination; + Ui *m_ui; + int m_currentDestination; + int m_currentRoute; }; #endif // UICONTROLLER_H diff --git a/zouba/zouba.pro b/zouba/zouba.pro index 57c19b1..845d0ff 100644 --- a/zouba/zouba.pro +++ b/zouba/zouba.pro @@ -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 -- 1.7.9.5