1 #include "carmainwindow.h"
2 #include "ui_carmainwindow.h"
3 #include "stringlistmodel.h"
4 #include "loginwindow.h"
5 #include <QStandardItemModel>
8 #include <QNetworkRequest>
11 *Constructor of this class.
12 *@param QWidget pointer to parent object. By default the value is NULL.
14 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
17 result = new ResultDialog();
18 measure = new MeasureDialog();
22 initCategoryCompoBox();
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*)));
32 *Destructor of this class. Should be used to release all allocated resources.
34 CarMainWindow::~CarMainWindow()
42 *This function is used to .
45 void CarMainWindow::changeEvent(QEvent *e)
47 QMainWindow::changeEvent(e);
49 case QEvent::LanguageChange:
50 ui->retranslateUi(this);
58 *This slot function is called when ever list view is update.
59 *@param QModelIndex index.
61 void CarMainWindow::on_listView_clicked(QModelIndex index)
63 QString str = index.data().toString();
64 QStringList list = str.split("-");
65 QStringList list2 = list[1].split(" ");
67 ui->minLineEdit->setText(list[0]);
68 ui->maxLineEdit->setText(list2[0]);
69 updateUnitCompoBox(list2[1]);
73 *This slot function is called when ever auto start button clicked.
75 void CarMainWindow::on_autoStartButton_clicked()
80 measure = new MeasureDialog();
82 connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
83 // Show measure dialog.
88 *This slot function is called when ever list view is update.
91 void CarMainWindow::updateUnitCompoBox(QString unit)
93 ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
97 *This function is used to init unit combobox.
99 void CarMainWindow::initUnitCompoBox()
101 units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
102 ui->unitComboBox->addItems(units);
106 *This function is used to set items to unit combobox.
107 *@param QStringlist numbers
109 void CarMainWindow::setUnitCompoBox(QStringList units)
111 ui->unitComboBox->addItems(units);
115 *This function is used to init speed listview.
117 void CarMainWindow::initSpeedListView()
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);
125 <<<<<<< HEAD:Client/carmainwindow.cpp
126 *This function is used to set items to speed listview.
127 *@param QStringlist numbers
129 void CarMainWindow::setSpeedListView(QStringList numbers)
131 QAbstractItemModel *model = new StringListModel(numbers);
132 ui->listView->setModel(model);
136 *This function is used to init category combobox.
138 void CarMainWindow::initCategoryCompoBox()
140 categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car";
141 ui->comboBoxTopCategory->addItems(categories);
145 *This function is used to set items to category combobox.
146 *@param QStringlist categories
148 void CarMainWindow::setCategoryCompoBox(QStringList categories)
150 ui->comboBoxTopCategory->addItems(categories);
154 *This slot function is called when ever categories combobox is update.
155 *@param QString category
157 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
162 topList << "1. Pertti 7,5s" << "2. Ville 10,2s";
164 QAbstractItemModel *model = new StringListModel(topList);
165 ui->listViewTopList->setModel(model);
169 *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
171 void CarMainWindow::openResultView()
173 result->saveMeasuresToArray(measure->measures);
174 // Show result dialog.
179 *This slot function is called when the server has finished guery.
181 void CarMainWindow::networkResponse(QNetworkReply *reply)
186 *This slot function is called when the user will to send data to server.
188 void CarMainWindow::on_pushButton_clicked()
190 QNetworkRequest postData;
191 postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
192 manager->get(postData);
197 *This slot function is called when login/logout button is clicked.
199 void CarMainWindow::on_loginLogoutButton_clicked()
201 //LoginWindow myLogin;
204 //ui->loginLogoutButton->setText("logout");
208 *This slot function is called when registrate button is clicked.
210 void CarMainWindow::on_registratePushButton_clicked()
212 myRegistration->show();