From 4f429bb5b56d861c5e35eeedf01b64287d66bd71 Mon Sep 17 00:00:00 2001 From: Max Waterman Date: Sat, 20 Mar 2010 23:29:26 +0200 Subject: [PATCH 1/1] 1) new status messages 2) new layout --- zouba/gpscontroller.cpp | 5 ++++ zouba/location.cpp | 5 ++++ zouba/location_p.cpp | 2 ++ zouba/main.cpp | 8 +++++- zouba/messagehandler.cpp | 18 ++++++++++++++ zouba/messagehandler.h | 10 ++++++++ zouba/messagetable.cpp | 50 +++++++++++++++++++++++++++++++++++++ zouba/messagetable.h | 25 +++++++++++++++++++ zouba/route.cpp | 17 +++++++++++++ zouba/route_p.cpp | 6 +++++ zouba/ui.cpp | 61 ++++++++++++++++++++++++++++++++++++++++------ zouba/ui.h | 26 +++++++++++++++++--- zouba/uicontroller.cpp | 7 ++++++ zouba/zouba.pro | 6 +++-- 14 files changed, 231 insertions(+), 15 deletions(-) create mode 100644 zouba/messagehandler.cpp create mode 100644 zouba/messagehandler.h create mode 100644 zouba/messagetable.cpp create mode 100644 zouba/messagetable.h diff --git a/zouba/gpscontroller.cpp b/zouba/gpscontroller.cpp index 49335c5..b031b61 100644 --- a/zouba/gpscontroller.cpp +++ b/zouba/gpscontroller.cpp @@ -29,15 +29,20 @@ GpsController::~GpsController() void GpsController::updateLocation( QGeoPositionInfo positionInfo ) { + qDebug() << "new GPS position"; + Location newLocation( positionInfo ); if ( updatesEnabled ) { + qDebug() << "from location changed"; emit locationChanged( newLocation ); updatesEnabled = false; + m_location->setUpdateInterval( 1*60*1000 ); } } void GpsController::startGps() { updatesEnabled = true; + m_location->setUpdateInterval( 1 ); } diff --git a/zouba/location.cpp b/zouba/location.cpp index 349777d..80a665c 100644 --- a/zouba/location.cpp +++ b/zouba/location.cpp @@ -100,6 +100,9 @@ Location &Location::operator=( const Location &from ) void Location::resolveAddress( QString address ) { + qDebug() << "resolving address"; + qDebug() << address; + QUrl fullUrl( Ytv::Url ); fullUrl.addEncodedQueryItem( "key", address.toAscii().toPercentEncoding() ); @@ -107,10 +110,12 @@ void Location::resolveAddress( QString address ) fullUrl.addQueryItem( "pass", Ytv::Password ); manager->get( QNetworkRequest( fullUrl ) ); + qDebug() << "waiting for reply from Ytv"; } void Location::replyFinished( QNetworkReply * reply ) { + qDebug() << "address resolved"; q->parseReply( reply->readAll() ); if ( isValid() ) { diff --git a/zouba/location_p.cpp b/zouba/location_p.cpp index 5e74595..79fb912 100644 --- a/zouba/location_p.cpp +++ b/zouba/location_p.cpp @@ -25,6 +25,7 @@ LocationPrivate::~LocationPrivate() void LocationPrivate::parseReply( const QByteArray &reply ) { + qDebug() << "parsing"; QXmlStreamReader xml( reply ); while ( !xml.atEnd() ) { @@ -45,6 +46,7 @@ void LocationPrivate::parseReply( const QByteArray &reply ) qDebug() << "xml error"; m_valid = false; } else { + qDebug() << "(" << m_x << "," << m_y << ")"; m_valid = true; } } diff --git a/zouba/main.cpp b/zouba/main.cpp index 97ef478..46632e2 100644 --- a/zouba/main.cpp +++ b/zouba/main.cpp @@ -4,8 +4,9 @@ #include "uicontroller.h" #include "location.h" #include "gpscontroller.h" - #include "ytv.h" +#include "messagehandler.h" +#include "messagetable.h" #include #include @@ -14,11 +15,16 @@ int main(int argc, char *argv[] ) { + qInstallMsgHandler( messageHandler ); QApplication app(argc, argv); QMainWindow *mainWindow = new QMainWindow; Ui ui; ui.setupUi(mainWindow); + qDebug() << "1"; + qDebug() << "2"; + qDebug() << "3"; + UiController *uiController = new UiController( &ui ); Route *route = new Route(); GpsController *gpsController = new GpsController(); diff --git a/zouba/messagehandler.cpp b/zouba/messagehandler.cpp new file mode 100644 index 0000000..7c03d9a --- /dev/null +++ b/zouba/messagehandler.cpp @@ -0,0 +1,18 @@ +#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/messagehandler.h b/zouba/messagehandler.h new file mode 100644 index 0000000..1ab9263 --- /dev/null +++ b/zouba/messagehandler.h @@ -0,0 +1,10 @@ +#ifndef MESSAGEHANDLER_H +#define MESSAGEHANDLER_H + +#include "ui.h" + +#include + +void messageHandler( QtMsgType type, const char *msg ); + +#endif //MESSAGEHANDLER_H diff --git a/zouba/messagetable.cpp b/zouba/messagetable.cpp new file mode 100644 index 0000000..d068bb9 --- /dev/null +++ b/zouba/messagetable.cpp @@ -0,0 +1,50 @@ +#include "messagetable.h" + +#include +#include +#include +#include + +MessageTable::MessageTable( QWidget *parent ) : + QTableWidget( NumberOfRows, OneColumn, parent ) +{ + setHorizontalHeaderLabels( QStringList() << "Messages" ); + verticalHeader()->hide(); + setMinimumSize( 250,0 ); + + 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 ); + + resizeColumnsToContents(); +} diff --git a/zouba/messagetable.h b/zouba/messagetable.h new file mode 100644 index 0000000..ea97a20 --- /dev/null +++ b/zouba/messagetable.h @@ -0,0 +1,25 @@ +#ifndef MESSAGETABLE_H +#define MESSAGETABLE_H + +#include +#include + +class MessageTable : public QTableWidget +{ + Q_OBJECT + + enum { + NumberOfRows=5, + OneColumn=1 + }; + +public: + MessageTable( QWidget *parent ); + ~MessageTable(); + + void displayMessage( const QString &message ); + + QSize minimumSizeHint() const; + QSize sizeHint() const; +}; +#endif //MESSAGETABLE_H diff --git a/zouba/route.cpp b/zouba/route.cpp index d38ac0e..1c3beda 100644 --- a/zouba/route.cpp +++ b/zouba/route.cpp @@ -30,6 +30,8 @@ Route::~Route() void Route::getRoute() { + qDebug() << "getting route from Ytv"; + QUrl fullUrl( Ytv::Url ); QStringList a; @@ -45,10 +47,12 @@ void Route::getRoute() fullUrl.addQueryItem( "pass", Ytv::Password ); manager->get( QNetworkRequest( fullUrl ) ); + qDebug() << "waiting for reply from Ytv"; } void Route::replyFinished( QNetworkReply * reply ) { + qDebug() << "have reply from Ytv"; QList routeData = q->parseReply( reply->readAll() ); emit( routeReady( routeData ) ); @@ -56,6 +60,8 @@ void Route::replyFinished( QNetworkReply * reply ) void Route::setFromLocation( const Location &location ) { + qDebug() << "setting new From location"; + if ( location.isValid() ) { q->setFromLocation( location ); if ( q->toValid() ) { @@ -81,17 +87,28 @@ const Location &Route::fromLocation() void Route::setToLocation( const Location &location ) { + qDebug() << "setting new To location"; + if ( location.isValid() ) { + qDebug() << "To is valid"; q->setToLocation( location ); if ( q->fromValid() ) { + qDebug() << "From is also valid"; getRoute(); + } else { + qDebug() << "From not valid - waiting"; } } else { + qDebug() << "To is not valid"; + qDebug() << "getting To from signal sender"; Location *locationPtr = qobject_cast(sender()); if ( locationPtr ) { q->setToLocation( *locationPtr ); if ( q->fromValid() ) { + qDebug() << "From is also valid"; getRoute(); + } else { + qDebug() << "From not valid - waiting"; } } else { qDebug() << "locationPtr is zero; cast failed"; diff --git a/zouba/route_p.cpp b/zouba/route_p.cpp index 19105a7..f041392 100644 --- a/zouba/route_p.cpp +++ b/zouba/route_p.cpp @@ -20,6 +20,8 @@ RoutePrivate::~RoutePrivate() QList RoutePrivate::parseReply( const QByteArray &reply ) { + qDebug() << "parsing route"; + QList retVal; RouteData routeData; @@ -73,6 +75,10 @@ QList RoutePrivate::parseReply( const QByteArray &reply ) qDebug() << "xml error"; } + if ( retVal.isEmpty() ) { + qDebug() << "no routes found"; + } + return retVal; } diff --git a/zouba/ui.cpp b/zouba/ui.cpp index e0ceae0..16d4616 100644 --- a/zouba/ui.cpp +++ b/zouba/ui.cpp @@ -1,5 +1,7 @@ #include "ui.h" +#include "messagetable.h" + #include #include #include @@ -7,6 +9,13 @@ #include #include #include +#include +#include +#include +#include +#include + +MessageTable *Ui::messageTable = 0; Ui::Ui() : centralWidget(0), @@ -22,31 +31,67 @@ Ui::~Ui() void Ui::setupUi( QMainWindow *mainWindow ) { mainWindow->resize(800,480); + QMenu *menu = mainWindow->menuBar()->addMenu("Settings"); + + QAction *setHomeAddressAction = new QAction("Set home address", this); + QAction *setWorkAddressAction = new QAction("Set work address", this); + menu->addAction(setHomeAddressAction); + menu->addAction(setWorkAddressAction); + + connect( + setHomeAddressAction, SIGNAL(triggered()), + this, SLOT(setHomeAddress()) + ); + connect( + setWorkAddressAction, SIGNAL(triggered()), + this, SLOT(setWorkAddress()) + ); centralWidget = new QWidget( mainWindow ); mainWindow->setCentralWidget(centralWidget); - QPushButton *homeButton = new QPushButton( centralWidget ); + QPushButton *homeButton = new QPushButton(); homeButton->setObjectName( QString::fromUtf8("homeButton") ); homeButton->setText( "HOME" ); - homeButton->setGeometry( QRect( 0, 0, ButtonWidth, ButtonHeight ) ); homeButton->setEnabled(false); + homeButton->setFixedSize( QSize( ButtonWidth, ButtonHeight ) ); - QPushButton *workButton = new QPushButton( centralWidget ); + QPushButton *workButton = new QPushButton(); workButton->setObjectName( QString::fromUtf8("workButton") ); workButton->setText( "WORK" ); - workButton->setGeometry( QRect( 0, ButtonHeight, ButtonWidth, ButtonHeight ) ); workButton->setEnabled(false); - destinationButtons = new QButtonGroup( centralWidget ); + destinationButtons = new QButtonGroup(); destinationButtons->addButton( homeButton, HomeButtonId ); destinationButtons->addButton( workButton, WorkButtonId ); - table = new QTableWidget( 1, 2, centralWidget ); - table->setObjectName( QString::fromUtf8("table") ); - table->setGeometry( QRect( ButtonWidth+1, 0, ScreenWidth-ButtonWidth, ScreenHeight ) ); + buttonLayout = new QVBoxLayout(); + buttonLayout->addWidget( homeButton ); + buttonLayout->addWidget( workButton ); + buttonLayout->addStretch(); + + table = new QTableWidget( 1, 2 ); QStringList columnHeaders; columnHeaders << "Time" << "Bus"; table->setHorizontalHeaderLabels( columnHeaders ); table->verticalHeader()->hide(); + + QHBoxLayout *topLayout = new QHBoxLayout(); + topLayout->addLayout( buttonLayout ); + topLayout->addWidget( table ); + + messageTable = new MessageTable( centralWidget ); + messageTable->setObjectName( QString::fromUtf8("messageTable") ); + + QVBoxLayout *mainLayout = new QVBoxLayout( centralWidget ); + mainLayout->addLayout( topLayout ); + mainLayout->addWidget( messageTable ); +} + +void Ui::setHomeAddress() +{ +} + +void Ui::setWorkAddress() +{ } diff --git a/zouba/ui.h b/zouba/ui.h index 77ba935..460dd88 100644 --- a/zouba/ui.h +++ b/zouba/ui.h @@ -1,13 +1,20 @@ #ifndef UI_H #define UI_H +#include + class QMainWindow; class QWidget; class QTableWidget; class QButtonGroup; +class MessageTable; +class QHBoxLayout; +class QVBoxLayout; -class Ui +class Ui : public QObject { + Q_OBJECT + public: Ui(); ~Ui(); @@ -22,14 +29,25 @@ public: ScreenWidth=800, ScreenHeight=480 }; - enum { - ButtonWidth=300, - ButtonHeight=70 + ButtonWidth=300, + ButtonHeight=70 }; + QWidget *centralWidget; QButtonGroup *destinationButtons; QTableWidget *table; + static MessageTable *messageTable; + QHBoxLayout *mainLayout; + QVBoxLayout *buttonLayout; + +Q_SIGNALS: + void homeAddressChanged( QString address ); + void workAddressChanged( QString address ); + +private Q_SLOTS: + void setHomeAddress(); + void setWorkAddress(); }; #endif //UI_H diff --git a/zouba/uicontroller.cpp b/zouba/uicontroller.cpp index cb49179..b599cbd 100644 --- a/zouba/uicontroller.cpp +++ b/zouba/uicontroller.cpp @@ -3,6 +3,7 @@ #include "ui.h" #include "ytv.h" #include "location.h" +#include "messagetable.h" #include #include @@ -59,6 +60,8 @@ void UiController::setButtonValid( int id ) void UiController::changeDestination( int id ) { + qDebug() << "Button "+QString::number(id)+" clicked"; + bool destinationHasChanged = ( currentDestination != id ); if ( destinationHasChanged ) { emit destinationChanged( *(destination[id]) ); @@ -71,6 +74,8 @@ void UiController::changeDestination( int id ) void UiController::displayRoute( const QList &routeData ) { + qDebug() << "displaying route"; + ui->table->setRowCount( routeData.count() ); for ( int i=0; i &routeData ) QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode ); ui->table->setItem( i, 1, lineItem ); } + + ui->table->resizeColumnsToContents(); } diff --git a/zouba/zouba.pro b/zouba/zouba.pro index 571eca3..a594ab5 100644 --- a/zouba/zouba.pro +++ b/zouba/zouba.pro @@ -17,8 +17,6 @@ QT += \ TEMPLATE = app -#FORMS = zouba.ui - SOURCES += \ main.cpp \ route.cpp \ @@ -28,6 +26,8 @@ SOURCES += \ location_p.cpp \ gpscontroller.cpp \ ui.cpp \ + messagetable.cpp \ + messagehandler.cpp \ HEADERS += \ route.h \ @@ -38,4 +38,6 @@ HEADERS += \ ytv.h \ gpscontroller.h \ ui.h \ + messagetable.h \ + messagehandler.h \ -- 1.7.9.5