Added measures.h and measures.cpp files. Changed resultdialog.h, .cpp and measuredial...
[speedfreak] / Client / carmainwindow.cpp
1 #include "carmainwindow.h"
2 #include "ui_carmainwindow.h"
3 #include "stringlistmodel.h"
4 #include "loginwindow.h"
5 #include <QStandardItemModel>
6 #include <QStringList>
7 #include <QString>
8 #include <QNetworkRequest>
9
10 /**
11   *Constructor of this class.
12   *@param QWidget pointer to parent object. By default the value is NULL.
13   */
14 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
15 {
16     ui->setupUi(this);
17     result = new ResultDialog();
18     measure = new MeasureDialog();
19
20     initUnitCompoBox();
21     initSpeedListView();
22     initCategoryCompoBox();
23
24     myLogin = new LoginWindow(this);
25     myRegistration = new Registration(this);
26     manager = new QNetworkAccessManager(this);
27     connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*)));
28
29 }
30
31 /**
32   *Destructor of this class. Should be used to release all allocated resources.
33   */
34 CarMainWindow::~CarMainWindow()
35 {
36     delete ui;
37     delete result;
38     delete measure;
39 }
40
41 /**
42   *This function is used to .
43   *@param
44   */
45 void CarMainWindow::changeEvent(QEvent *e)
46 {
47     QMainWindow::changeEvent(e);
48     switch (e->type()) {
49     case QEvent::LanguageChange:
50         ui->retranslateUi(this);
51         break;
52     default:
53         break;
54     }
55 }
56
57 /**
58   *This slot function is called when ever list view is update.
59   *@param QModelIndex index.
60   */
61 void CarMainWindow::on_listView_clicked(QModelIndex index)
62 {
63     QString str = index.data().toString();
64     QStringList list = str.split("-");
65     QStringList list2 = list[1].split(" ");
66
67     ui->minLineEdit->setText(list[0]);
68     ui->maxLineEdit->setText(list2[0]);
69     updateUnitCompoBox(list2[1]);
70 }
71
72 /**
73   *This slot function is called when ever auto start button clicked.
74   */
75 void CarMainWindow::on_autoStartButton_clicked()
76 {
77
78     delete measure;
79     measure = NULL;
80     measure = new MeasureDialog();
81
82     connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
83     // Show measure dialog.
84     measure->show();
85 }
86
87 /**
88   *This slot function is called when ever list view is update.
89   *@param QString unit.
90   */
91 void CarMainWindow::updateUnitCompoBox(QString unit)
92 {
93     ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
94 }
95
96 /**
97   *This function is used to init unit combobox.
98   */
99 void CarMainWindow::initUnitCompoBox()
100 {
101     units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
102     ui->unitComboBox->addItems(units);
103 }
104
105 /**
106   *This function is used to set items to unit combobox.
107   *@param QStringlist numbers
108   */
109 void CarMainWindow::setUnitCompoBox(QStringList units)
110 {
111     ui->unitComboBox->addItems(units);
112 }
113
114 /**
115   *This function is used to init speed listview.
116   */
117 void CarMainWindow::initSpeedListView()
118 {
119     numbers << "0-40 km/h" << "0-1/4 mil" << "0-50 km" << "50-100 mil" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
120     QAbstractItemModel *model = new StringListModel(numbers);
121     ui->listView->setModel(model);
122 }
123
124 /**
125 <<<<<<< HEAD:Client/carmainwindow.cpp
126   *This function is used to set items to speed listview.
127   *@param QStringlist numbers
128   */
129 void CarMainWindow::setSpeedListView(QStringList numbers)
130 {
131     QAbstractItemModel *model = new StringListModel(numbers);
132     ui->listView->setModel(model);
133 }
134
135 /**
136   *This function is used to init category combobox.
137   */
138 void CarMainWindow::initCategoryCompoBox()
139 {
140     categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car";
141     ui->comboBoxTopCategory->addItems(categories);
142 }
143
144 /**
145   *This function is used to set items to category combobox.
146   *@param QStringlist categories
147   */
148 void CarMainWindow::setCategoryCompoBox(QStringList categories)
149 {
150     ui->comboBoxTopCategory->addItems(categories);
151 }
152
153 /**
154   *This slot function is called when ever categories combobox is update.
155   *@param QString category
156   */
157 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
158 {
159     //TODO: get top list
160
161     QStringList topList;
162     topList << "1. Pertti 7,5s" << "2. Ville 10,2s";
163
164     QAbstractItemModel *model = new StringListModel(topList);
165     ui->listViewTopList->setModel(model);
166 }
167
168 /**
169   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
170   */
171 void CarMainWindow::openResultView()
172 {
173     result->saveMeasuresToArray(measure->measures);
174     // Show result dialog.
175     result->show();
176 }
177
178 /**
179   *This slot function is called when the server has finished guery.
180   */
181 void CarMainWindow::networkResponse(QNetworkReply *reply)
182 {
183 }
184
185 /**
186   *This slot function is called when the user will to send data to server.
187   */
188 void CarMainWindow::on_pushButton_clicked()
189 {
190      QNetworkRequest postData;
191      postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
192      manager->get(postData);
193
194 }
195
196 /**
197   *This slot function is called when login/logout button is clicked.
198   */
199 void CarMainWindow::on_loginLogoutButton_clicked()
200 {
201     //LoginWindow myLogin;
202
203     myLogin->show();
204     //ui->loginLogoutButton->setText("logout");
205 }
206
207 /**
208   *This slot function is called when registrate button is clicked.
209   */
210 void CarMainWindow::on_registratePushButton_clicked()
211 {
212     myRegistration->show();
213 }