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()
81 measure = new MeasureDialog();
84 connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
86 // Show measure dialog.
91 *This slot function is called when ever list view is update.
94 void CarMainWindow::updateUnitCompoBox(QString unit)
96 ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
100 *This function is used to init unit combobox.
102 void CarMainWindow::initUnitCompoBox()
104 units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
105 ui->unitComboBox->addItems(units);
109 *This function is used to set items to unit combobox.
110 *@param QStringlist numbers
112 void CarMainWindow::setUnitCompoBox(QStringList units)
114 ui->unitComboBox->addItems(units);
118 *This function is used to init speed listview.
120 void CarMainWindow::initSpeedListView()
122 numbers << "0-100 km/h" << "0-1/4 mil" << "0-50 km" << "50-100 mil" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
123 QAbstractItemModel *model = new StringListModel(numbers);
124 ui->listView->setModel(model);
128 <<<<<<< HEAD:Client/carmainwindow.cpp
129 *This function is used to set items to speed listview.
130 *@param QStringlist numbers
132 void CarMainWindow::setSpeedListView(QStringList numbers)
134 QAbstractItemModel *model = new StringListModel(numbers);
135 ui->listView->setModel(model);
139 *This function is used to init category combobox.
141 void CarMainWindow::initCategoryCompoBox()
143 categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car";
144 ui->comboBoxTopCategory->addItems(categories);
148 *This function is used to set items to category combobox.
149 *@param QStringlist categories
151 void CarMainWindow::setCategoryCompoBox(QStringList categories)
153 ui->comboBoxTopCategory->addItems(categories);
157 *This slot function is called when ever categories combobox is update.
158 *@param QString category
160 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
165 topList << "1. Pertti 7,5s" << "2. Ville 10,2s";
167 QAbstractItemModel *model = new StringListModel(topList);
168 ui->listViewTopList->setModel(model);
172 *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
174 void CarMainWindow::openResultView()
176 // Show result dialog.
181 *This slot function is called when the server has finished guery.
183 void CarMainWindow::networkResponse(QNetworkReply *reply)
188 *This slot function is called when the user will to send data to server.
190 void CarMainWindow::on_pushButton_clicked()
192 QNetworkRequest postData;
193 postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
194 manager->get(postData);
199 *This slot function is called when login/logout button is clicked.
201 void CarMainWindow::on_loginLogoutButton_clicked()
203 //LoginWindow myLogin;
206 //ui->loginLogoutButton->setText("logout");
210 *This slot function is called when registrate button is clicked.
212 void CarMainWindow::on_registratePushButton_clicked()
214 myRegistration->show();