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