{
QUrl fullUrl( ytv );
- fullUrl.addEncodedQueryItem( "key", address.toAscii() );
+ fullUrl.addEncodedQueryItem( "key", address.toUtf8() );
fullUrl.addQueryItem( "user", username );
fullUrl.addQueryItem( "pass", password );
~Location();
- void resolveAddress( QString address );
-
QString x() const;
QString y() const;
bool isValid() const;
+public Q_SLOTS:
+ void resolveAddress( QString address );
+
Q_SIGNALS:
void becomeValid();
#include "uicontroller.h"
#include "location.h"
+#include "ytv.h"
+
#include <QDebug>
#include <QObject>
-namespace {
- Location home( "2549183", "6672570" );
- Location work( "2551042", "6672829" );
- QString homeKey( "taivaanvuohentie%207%2Chelsinki" );
- QString workKey( "it%E4merenkatu%2011%2Chelsinki" );
-}
-
int main(int argc, char *argv[] )
{
QApplication app(argc, argv);
route, SLOT( setToLocation() )
);
- from->resolveAddress( homeKey );
- to->resolveAddress( workKey );
+ ui.homeaddress->setText( home );
+ ui.workaddress->setText( work );
+
+ from->resolveAddress( home );
+ to->resolveAddress( work );
+
+ QObject::connect(
+ uiController, SIGNAL( homeAddressChanged( QString ) ),
+ from, SLOT( resolveAddress( QString ) )
+ );
+
+ QObject::connect(
+ uiController, SIGNAL( workAddressChanged( QString ) ),
+ to, SLOT( resolveAddress( QString ) )
+ );
+
+ /* toggle doesn't work yet because 'from' is connected to 'homeAddressChanged'
+ QObject::connect(
+ uiController, SIGNAL( directionChanged() ),
+ route, SLOT( toggleDirection() )
+ );
+ */
widget->show();
return app.exec();
return q->toLocation();
}
+void Route::toggleDirection()
+{
+ Location oldFromLocation = fromLocation();
+ setFromLocation( toLocation() );
+ setToLocation( oldFromLocation );
+
+ getRoute();
+}
*/
void setToLocation( const Location &location=Location() );
+ /*!
+ * \brief Toggles the route direction.
+ */
+ void toggleDirection();
+
Q_SIGNALS:
void routeReady( RouteData );
INCLUDEPATH += \
../.. \
+DEPENDPATH += $$INCLUDEPATH
+
TEMPLATE = app
SOURCES = \
INCLUDEPATH += \
../.. \
+DEPENDPATH += $INCLUDEPATH
+
TEMPLATE = app
SOURCES = \
#include "ui_zouba.h"
UiController::UiController( Ui::MainWindow *ui ) :
- ui(ui)
+ ui(ui),
+ route( HomeToWork )
{
+ connect( ui->sethomeaddress, SIGNAL( pressed() ), this, SLOT( setHomeAddress() ) );
+ connect( ui->setworkaddress, SIGNAL( pressed() ), this, SLOT( setWorkAddress() ) );
+ connect( ui->route, SIGNAL( pressed() ), this, SLOT( toggleRoute() ) );
}
UiController::~UiController()
{
}
+void UiController::setHomeAddress()
+{
+ emit homeAddressChanged( ui->homeaddress->text() );
+}
+
+void UiController::setWorkAddress()
+{
+ emit workAddressChanged( ui->workaddress->text() );
+}
+
+void UiController::toggleRoute()
+{
+ if ( route == HomeToWork ) {
+ route = WorkToHome;
+ ui->route->setText( "Home<-Work" );
+ } else {
+ route = HomeToWork;
+ ui->route->setText( "Home->Work" );
+ }
+
+ ui->busnodisplay->setText( "working" );
+ ui->timedisplay->setText( "working" );
+
+ emit directionChanged();
+}
+
void UiController::displayRoute( const RouteData &routeData )
{
- ui->BusNoDisplay->setText( routeData.lineCode );
- ui->TimeDisplay->setText( routeData.arrivalTime );
+ ui->busnodisplay->setText( routeData.lineCode );
+ ui->timedisplay->setText( routeData.arrivalTime );
}
public Q_SLOTS:
void displayRoute( const RouteData &routeData );
+Q_SIGNALS:
+ void homeAddressChanged( QString );
+ void workAddressChanged( QString );
+ void directionChanged();
+
+private Q_SLOTS:
+ void setHomeAddress();
+ void setWorkAddress();
+ void toggleRoute();
+
private:
Ui::MainWindow *ui;
+ enum Direction {
+ WorkToHome,
+ HomeToWork
+ };
+
+ Direction route;
};
#endif // UICONTROLLER_H
#include <QString>
namespace {
- QUrl ytv( "http://api.reittiopas.fi/public-ytv/fi/api/" );
- QString username( "zouba" );
- QString password( "caf9r3ee" );
-
- QString homeKey( "taivaanvuohentie%207%2Chelsinki" );
- QString workKey( "it%E4merenkatu%2011%2Chelsinki" );
+ const QUrl ytv( "http://api.reittiopas.fi/public-ytv/fi/api/" );
+ const QString username( "zouba" );
+ const QString password( "caf9r3ee" );
+
+ //const QString home( "Taivaanvuohentie 7, Helsinki" );
+ //const QString work( "Itämerenkatu 11, Helsinki" );
+ const QString home( "Taivaanvuohentie%207%2CHelsinki" );
+ const QString work( "It%E4merenkatu%2011%2CHelsinki" );
}
-CONFIG += \
- qt \
- debug \
-
-QT += \
- network \
-
+CONFIG += qt \
+ debug
+QT += network
TEMPLATE = app
-FORMS = zouba.ui
-
-SOURCES = \
- main.cpp \
- route.cpp \
- route_p.cpp \
- uicontroller.cpp \
- location.cpp \
- location_p.cpp \
-
-HEADERS += \
- route.h \
- route_p.h \
- uicontroller.h \
- location.h \
- location_p.h \
-
+FORMS = zouba.ui
+SOURCES = main.cpp \
+ route.cpp \
+ route_p.cpp \
+ uicontroller.cpp \
+ location.cpp \
+ location_p.cpp
+HEADERS += route.h \
+ route_p.h \
+ uicontroller.h \
+ location.h \
+ location_p.h \
+ ytv.h
<rect>
<x>0</x>
<y>0</y>
- <width>640</width>
- <height>480</height>
+ <width>231</width>
+ <height>167</height>
</rect>
</property>
<property name="windowTitle">
<x>0</x>
<y>0</y>
<width>230</width>
- <height>82</height>
+ <height>106</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
- <item row="1" column="0">
- <widget class="QLabel" name="TimeLabel">
- <property name="text">
- <string>Time</string>
- </property>
- </widget>
+ <item row="0" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="route">
+ <property name="text">
+ <string>Work->Home</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item row="1" column="1">
- <widget class="QLabel" name="TimeDisplay">
+ <widget class="QLabel" name="timedisplay">
<property name="text">
<string>TimeDisplay</string>
</property>
</widget>
</item>
<item row="2" column="0">
- <widget class="QLabel" name="BusNoLabel">
+ <widget class="QLabel" name="busnolabel">
<property name="text">
<string>BusNo</string>
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="timelabel">
+ <property name="text">
+ <string>Time</string>
+ </property>
+ </widget>
+ </item>
<item row="2" column="1">
- <widget class="QLabel" name="BusNoDisplay">
+ <widget class="QLabel" name="busnodisplay">
<property name="text">
<string>BusNoDisplay</string>
</property>
</widget>
</item>
- <item row="0" column="0" colspan="2">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QPushButton" name="pushButton_2">
- <property name="text">
- <string>Work</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton">
- <property name="text">
- <string>Home</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
</layout>
</item>
</layout>
</widget>
+ <widget class="QPushButton" name="sethomeaddress">
+ <property name="geometry">
+ <rect>
+ <x>130</x>
+ <y>90</y>
+ <width>92</width>
+ <height>28</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Set Home</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="setworkaddress">
+ <property name="geometry">
+ <rect>
+ <x>130</x>
+ <y>130</y>
+ <width>92</width>
+ <height>28</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Set Work</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="homeaddress">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>90</y>
+ <width>113</width>
+ <height>26</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="workaddress">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>130</y>
+ <width>113</width>
+ <height>26</height>
+ </rect>
+ </property>
+ </widget>
</widget>
- <widget class="QMenuBar" name="menubar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>640</width>
- <height>25</height>
- </rect>
- </property>
- </widget>
- <widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>