1 #include "carmainwindow.h"
4 *Constructor of this class.
5 *@param QWidget pointer to parent object. By default the value is NULL.
7 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
10 result = new ResultDialog();
11 measure = new MeasureDialog();
12 xmlreader = new XmlReader();
17 myLogin = new LoginWindow(this);
18 myRegistration = new Registration(this);
19 manager = new QNetworkAccessManager(this);
20 connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*)));
24 *Destructor of this class. Should be used to release all allocated resources.
26 CarMainWindow::~CarMainWindow()
35 *This function is used to .
38 void CarMainWindow::changeEvent(QEvent *e)
40 QMainWindow::changeEvent(e);
42 case QEvent::LanguageChange:
43 ui->retranslateUi(this);
51 *This slot function is called when ever list view is update. Start-tab view.
53 void CarMainWindow::on_listView_clicked(QModelIndex index)
55 QString str = index.data().toString();
56 QStringList list = str.split("-");
57 QStringList list2 = list[1].split(" ");
59 ui->minLineEdit->setText(list[0]);
60 ui->maxLineEdit->setText(list2[0]);
61 updateUnitCompoBox(list2[1]);
65 *This slot function is called when ever auto start button clicked. Start-tab view.
67 void CarMainWindow::on_autoStartButton_clicked()
72 measure = new MeasureDialog();
74 connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
75 // Show measure dialog.
80 *This slot function is called when ever list view is update. Start-tab view.
83 void CarMainWindow::updateUnitCompoBox(QString unit)
85 ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
89 *This function is used to init unit combobox. Start-tab view.
91 void CarMainWindow::initUnitCompoBox()
93 units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd";
94 ui->unitComboBox->addItems(units);
98 *This function is used to set items to unit combobox. Start-tab view.
99 *@param QStringlist numbers
101 void CarMainWindow::setUnitCompoBox(QStringList units)
103 ui->unitComboBox->addItems(units);
107 *This function is used to init speed listview. Start-tab view.
109 void CarMainWindow::initSpeedListView()
111 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";
112 QAbstractItemModel *model = new StringListModel(numbers);
113 ui->listView->setModel(model);
117 *This function is used to set items to speed listview. Start-tab view.
118 *@param QStringlist numbers
120 void CarMainWindow::setSpeedListView(QStringList numbers)
122 QAbstractItemModel *model = new StringListModel(numbers);
123 ui->listView->setModel(model);
127 *This function is used to set items to category combobox. Top-tab view.
130 void CarMainWindow::setCategoryCompoBox()
132 ui->comboBoxTopCategory->addItems(xmlreader->getTop10List());
136 *This function is used to set items to labelTopList. Top-tab view.
137 *@param QString category
139 void CarMainWindow::setListViewTopList(QString category)
143 if (category == "acceleration-0-100")
145 topList.append(xmlreader->getTop10AccelerationList());
148 else if (category == "Speed")
150 topList.append(xmlreader->getTop10SpeedList());
153 else if (category == "G-force")
155 topList.append(xmlreader->getTop10GforceList());
157 ui->labelTopList->setText(topList);
161 *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
163 void CarMainWindow::openResultView()
165 result->saveMeasuresToArray(measure->measures);
166 // Show result dialog.
171 *This slot function is called when the server has finished guery.
173 void CarMainWindow::networkResponse(QNetworkReply *reply)
178 *This slot function is called when the user will to send data to server.
180 void CarMainWindow::on_pushButton_clicked()
182 QNetworkRequest postData;
183 postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
184 manager->get(postData);
189 *This slot function is called when login/logout button is clicked.
191 void CarMainWindow::on_loginLogoutButton_clicked()
193 //LoginWindow myLogin;
196 //ui->loginLogoutButton->setText("logout");
200 *This slot function is called when registrate button is clicked.
202 void CarMainWindow::on_registratePushButton_clicked()
204 myRegistration->show();
208 *This slot function is called when ever refresh button clicked. Top-tab view.
210 void CarMainWindow::on_buttonTopRefresh_clicked()
212 setCategoryCompoBox();
216 *This slot function is called when ever category combobox current index changed. Top-tab view.
217 *@param QString category
219 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
221 setListViewTopList(category);
225 *This slot function is called when ever category combobox activated. Top-tab view.
226 *@param QString category
228 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
230 setListViewTopList(category);