Implemented Arrival/Departures selection
[quandoparte] / application / stationlistview.cpp
1 /*
2
3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 */
21
22 #include "stationlistview.h"
23 #include "ui_stationlistview.h"
24
25 #include "settingsdialog.h"
26 #include "stationview.h"
27
28 #include <QActionGroup>
29 #include <QDebug>
30 #include <QStringListModel>
31
32 StationListView::StationListView(QWidget *parent) :
33     QMainWindow(parent),
34     ui(new Ui::StationListView),
35     viewSelectionGroup(new QActionGroup(0)),
36     stationListModel(new QStringListModel()),
37     stationView(0)
38
39 {
40 #ifdef Q_WS_MAEMO_5
41     setAttribute(Qt::WA_Maemo5StackedWindow);
42     setAttribute(Qt::WA_Maemo5AutoOrientation);
43 #endif
44     ui->setupUi(this);
45     viewSelectionGroup->addAction(ui->sortByNameAction);
46     viewSelectionGroup->addAction(ui->sortNearFirstAction);
47     viewSelectionGroup->addAction(ui->sortRecentFirstAction);
48     QStringList stationList;
49     stationList << "Genova Voltri"
50                 << "Genova Pra"
51                 << "Genova Pegli"
52                 << "Genova Sestri Ponente"
53                 << "Genova Cornigliano"
54                 << "Genova Sampierdarena"
55                 << "Genova Via di Francia"
56                 << "Genova Piazza Principe"
57                 << "Genova Brignole"
58                 << "Genova Sturla"
59                 << "Genova Quarto dei Mille"
60                 << "Genova Quinto al Mare"
61                 << "Genova Nervi";
62     stationListModel->setStringList(stationList);
63     ui->listView->setModel(stationListModel);
64     ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
65     ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
66
67     connect(ui->listView,
68             SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
69 }
70
71 StationListView::~StationListView()
72 {
73     delete ui;
74 }
75
76 void StationListView::showSettings(void)
77 {
78     qDebug() << "Show Settings";
79     SettingsDialog *settingsDialog = new SettingsDialog(this);
80     if (settingsDialog->exec() == QDialog::Accepted) {
81         // TODO Use new settings
82     }
83
84     delete settingsDialog;
85 }
86
87 void StationListView::showStation(const QModelIndex &index)
88 {
89     qDebug() << "Show Station" << index.data();
90     emit stationSelected(index.data().toString());
91 }