1 #include "uicontroller.h"
6 #include "messagetable.h"
10 #include <QTableWidgetItem>
11 #include <QPushButton>
13 #include <QButtonGroup>
15 UiController::UiController( Ui *ui ) :
18 Locations *locations = Locations::instance();
19 Location *homeLocation = locations->location( "home" );
20 Location *workLocation = locations->location( "work" );
22 if ( homeLocation==0 ) {
23 homeLocation = new Location( "home" );
24 locations->addLocation( homeLocation );
25 } else if ( homeLocation->isValid() ) {
29 if ( workLocation==0 ) {
30 workLocation = new Location( "work" );
31 locations->addLocation( workLocation );
32 } else if ( workLocation->isValid() ) {
37 homeLocation, SIGNAL( becomeValid() ),
38 this, SLOT( setHomeButtonValid() )
41 homeLocation, SIGNAL( becomeValid() ),
42 locations, SLOT( saveLocation() )
46 workLocation, SIGNAL( becomeValid() ),
47 this, SLOT( setWorkButtonValid() )
50 workLocation, SIGNAL( becomeValid() ),
51 locations, SLOT( saveLocation() )
54 destination.append( homeLocation );
55 destination.append( workLocation );
58 ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
59 this, SLOT( changeDestination( int ) )
63 UiController::~UiController()
67 void UiController::setHomeButtonValid()
69 qDebug() << "setting home button valid";
70 setButtonValid( Ui::HomeButtonId );
73 void UiController::setWorkButtonValid()
75 setButtonValid( Ui::WorkButtonId );
78 void UiController::setButtonValid( int id )
80 ui->destinationButtons->button( id )->setEnabled(true);
83 void UiController::changeDestination( int id )
85 qDebug() << "Button "+QString::number(id)+" clicked";
87 bool destinationHasChanged = ( currentDestination != id );
88 if ( destinationHasChanged ) {
89 emit destinationChanged( destination[id] );
92 // always want to emit this so that the gps position is update
93 // and the user gets new information
97 void UiController::displayRoute( const QList<RouteData> &routeData )
99 qDebug() << "displaying route";
101 ui->routeTable->setRowCount( routeData.count() );
103 for ( int i=0; i<routeData.count(); i++ ) {
104 QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.at(i).arrivalTime );
105 ui->routeTable->setItem( i, 0, timeItem );
107 QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
108 ui->routeTable->setItem( i, 1, lineItem );