1 #include "uicontroller.h"
11 #include <QButtonGroup>
12 #include <QRadioButton>
13 #include <QVBoxLayout>
14 #include <QTableWidgetItem>
17 #include <QMaemo5AbstractPickSelector>
18 #include <QMaemo5InformationBox>
21 UiController::UiController( UiClass *ui ) :
26 Locations *locations = Locations::GetInstance();
27 if (locations->size() == 0)
29 locations->addEditLocation(new Location("Home"));
30 locations->addEditLocation(new Location("Work"));
33 QObject::connect(m_ui->m_routeButton, SIGNAL(clicked()), this, SLOT(findRoute()));
35 QObject::connect(this->m_ui->m_fromButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeFrom()));
36 connect(m_ui->m_toButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeTo()));
38 connect(m_ui->m_routeButtons, SIGNAL(buttonClicked(int)), this, SLOT(displayRouteDetail(int)));
41 UiController::~UiController()
45 void UiController::changeRoute( int id )
47 bool routeHasChanged = ( m_currentRoute != id );
48 if ( routeHasChanged ) {
49 displayRouteDetail( id );
53 void UiController::displayRouteDetail( int id )
55 QTableWidget *table = m_ui->m_routeDetailTable;
57 if ( id < m_routeData.count() ) {
58 QList<LegData> &legDataList = m_routeData[ id ].m_legData;
59 table->setRowCount( legDataList.count() );
62 foreach( LegData thisLegData, legDataList ) {
63 QString thisHow = thisLegData.m_how;
65 bool thisIsLine = ( thisHow == "LINE" );
67 thisHow = thisLegData.m_lineCode;
70 QStringList tableStrings;
73 << thisLegData.m_tripTime
74 << thisLegData.m_tripDistance
75 << thisLegData.m_departureTime
76 << thisLegData.m_arrivalTime;
79 foreach( QString thisString, tableStrings ) {
80 QTableWidgetItem *newItem = new QTableWidgetItem();
81 newItem->setText( thisString );
82 table->setItem( row,col, newItem );
89 table->setRowCount( 0 );
92 table->resizeColumnsToContents();
95 void UiController::displayRoute( const QList<RouteData> &routeData )
97 m_routeData = routeData;
99 qDebug() << "displaying route";
101 for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
104 QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
105 QRadioButton *button = qobject_cast<QRadioButton *>(widget);
107 if ( i<routeData.count() ) {
108 RouteData thisRouteData = routeData.at(i);
109 label = ( QStringList()
110 << thisRouteData.m_departureTime
111 << thisRouteData.m_lineCode ).join( "/" );
112 button->setEnabled( true );
114 button->setEnabled( false );
118 button->setChecked( true );
120 button->setChecked( false );
123 button->setText( label );
126 displayRouteDetail( 0 );
129 void UiController::findRoute()
131 qDebug() << "Route search button clicked";
132 emit(routeSearchRequested());
135 /*void UiController::updateLocationSelectors()
137 m_ui->setLocations();
140 void UiController::changeFrom()
142 qDebug() << "From selection changed";
143 Locations *locations = Locations::GetInstance();
147 const QString newValue = m_ui->m_fromButton->valueText();
149 const QString newValue = "";
151 if (newValue == "GPS")
153 from = locations->getGpsLocation();
154 if (!from->isValid())
156 qDebug() << "GPS location is not valid.";
158 QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
160 connect(from, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
166 from = locations->getLocation(newValue);
168 qDebug() << "No location with label " << newValue << " was found.";
172 qDebug() << "Emitting signal of new from selection";
173 emit(fromChanged(from));
177 void UiController::gpsBecameValid()
180 QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location received.");
182 Location *gps = Locations::GetInstance()->getGpsLocation();
183 disconnect(gps, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
188 void UiController::changeTo()
190 qDebug() << "To selection changed";
191 Locations *locations = Locations::GetInstance();
195 const QString newValue = m_ui->m_toButton->valueText();
197 const QString newValue = "";
199 if (newValue == "GPS")
201 to = locations->getGpsLocation();
204 qDebug() << "GPS location is not valid.";
206 QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
208 connect(to, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
214 to = locations->getLocation(newValue);
216 qDebug() << "No location with label " << newValue << " was found.";
220 qDebug() << "Emitting signal of new to selection";