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 );
}
void Location::resolveAddress( QString address )
{
+ qDebug() << "resolving address";
+ qDebug() << address;
+
QUrl fullUrl( Ytv::Url );
fullUrl.addEncodedQueryItem( "key", address.toAscii().toPercentEncoding() );
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() ) {
void LocationPrivate::parseReply( const QByteArray &reply )
{
+ qDebug() << "parsing";
QXmlStreamReader xml( reply );
while ( !xml.atEnd() ) {
qDebug() << "xml error";
m_valid = false;
} else {
+ qDebug() << "(" << m_x << "," << m_y << ")";
m_valid = true;
}
}
#include "uicontroller.h"
#include "location.h"
#include "gpscontroller.h"
-
#include "ytv.h"
+#include "messagehandler.h"
+#include "messagetable.h"
#include <QDebug>
#include <QObject>
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();
--- /dev/null
+#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 )
+ );
+ }
+}
+
--- /dev/null
+#ifndef MESSAGEHANDLER_H
+#define MESSAGEHANDLER_H
+
+#include "ui.h"
+
+#include <QtGlobal>
+
+void messageHandler( QtMsgType type, const char *msg );
+
+#endif //MESSAGEHANDLER_H
--- /dev/null
+#include "messagetable.h"
+
+#include <QHeaderView>
+#include <QString>
+#include <QStringList>
+#include <QDebug>
+
+MessageTable::MessageTable( QWidget *parent ) :
+ QTableWidget( NumberOfRows, OneColumn, parent )
+{
+ setHorizontalHeaderLabels( QStringList() << "Messages" );
+ verticalHeader()->hide();
+ setMinimumSize( 250,0 );
+
+ for ( int row=0; row<NumberOfRows; ++row ) {
+ QTableWidgetItem *newRow = new QTableWidgetItem();
+ setItem( row,0, newRow );
+ }
+}
+QSize MessageTable::minimumSizeHint() const
+{
+ QSize size( QTableWidget::sizeHint() );
+
+ size.setWidth( 250 );
+ return size;
+}
+
+QSize MessageTable::sizeHint() const
+{
+ return minimumSizeHint();
+}
+
+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 );
+
+ resizeColumnsToContents();
+}
--- /dev/null
+#ifndef MESSAGETABLE_H
+#define MESSAGETABLE_H
+
+#include <QWidget>
+#include <QTableWidget>
+
+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
void Route::getRoute()
{
+ qDebug() << "getting route from Ytv";
+
QUrl fullUrl( Ytv::Url );
QStringList a;
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> routeData = q->parseReply( reply->readAll() );
emit( routeReady( routeData ) );
void Route::setFromLocation( const Location &location )
{
+ qDebug() << "setting new From location";
+
if ( location.isValid() ) {
q->setFromLocation( location );
if ( q->toValid() ) {
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<Location*>(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";
QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
{
+ qDebug() << "parsing route";
+
QList<RouteData> retVal;
RouteData routeData;
qDebug() << "xml error";
}
+ if ( retVal.isEmpty() ) {
+ qDebug() << "no routes found";
+ }
+
return retVal;
}
#include "ui.h"
+#include "messagetable.h"
+
#include <QMainWindow>
#include <QPushButton>
#include <QTableWidget>
#include <QRect>
#include <QButtonGroup>
#include <QHeaderView>
+#include <QObject>
+#include <QMenuBar>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QSizePolicy>
+
+MessageTable *Ui::messageTable = 0;
Ui::Ui() :
centralWidget(0),
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()
+{
}
#ifndef UI_H
#define UI_H
+#include <QObject>
+
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();
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
#include "ui.h"
#include "ytv.h"
#include "location.h"
+#include "messagetable.h"
#include <QObject>
#include <QTableWidgetItem>
void UiController::changeDestination( int id )
{
+ qDebug() << "Button "+QString::number(id)+" clicked";
+
bool destinationHasChanged = ( currentDestination != id );
if ( destinationHasChanged ) {
emit destinationChanged( *(destination[id]) );
void UiController::displayRoute( const QList<RouteData> &routeData )
{
+ qDebug() << "displaying route";
+
ui->table->setRowCount( routeData.count() );
for ( int i=0; i<routeData.count(); i++ ) {
QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
ui->table->setItem( i, 1, lineItem );
}
+
+ ui->table->resizeColumnsToContents();
}
TEMPLATE = app
-#FORMS = zouba.ui
-
SOURCES += \
main.cpp \
route.cpp \
location_p.cpp \
gpscontroller.cpp \
ui.cpp \
+ messagetable.cpp \
+ messagehandler.cpp \
HEADERS += \
route.h \
ytv.h \
gpscontroller.h \
ui.h \
+ messagetable.h \
+ messagehandler.h \