10affdac2b451d8497704950d603ee5f1172deb5
[speedfreak] / Client / carmainwindow.cpp
1 #include "carmainwindow.h"
2 #include "ui_carmainwindow.h"
3 #include "stringlistmodel.h"
4 #include <QStandardItemModel>
5 #include <QStringList>
6 #include <QString>
7
8 /**
9   *Constructor of this class.
10   *@param QWidget pointer to parent object. By default the value is NULL.
11   */
12 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
13 {
14     ui->setupUi(this);
15     result = new ResultDialog();
16     measure = new MeasureDialog();
17
18     initUnitCompoBox();
19     initSpeedListView();
20     initCategoryCompoBox();
21 }
22
23 /**
24   *Destructor of this class. Should be used to release all allocated resources.
25   */
26 CarMainWindow::~CarMainWindow()
27 {
28     delete ui;
29     delete result;
30     delete measure;
31 }
32
33 /**
34   *This function is used to .
35   *@param
36   */
37 void CarMainWindow::changeEvent(QEvent *e)
38 {
39     QMainWindow::changeEvent(e);
40     switch (e->type()) {
41     case QEvent::LanguageChange:
42         ui->retranslateUi(this);
43         break;
44     default:
45         break;
46     }
47 }
48
49 /**
50   *This slot function is called when ever list view is update.
51   *@param QModelIndex index.
52   */
53 void CarMainWindow::on_listView_clicked(QModelIndex index)
54 {
55     QString str = index.data().toString();
56     QStringList list = str.split("-");
57     QStringList list2 = list[1].split(" ");
58
59     ui->minLineEdit->setText(list[0]);
60     ui->maxLineEdit->setText(list2[0]);
61     updateUnitCompoBox(list2[1]);
62 }
63
64 /**
65   *This slot function is called when ever auto start button clicked.
66   */
67 void CarMainWindow::on_autoStartButton_clicked()
68 {
69
70     delete measure;
71     measure = NULL;
72     measure = new MeasureDialog();
73
74     connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
75     // Show measure dialog.
76     measure->show();
77 }
78
79 /**
80   *This slot function is called when ever list view is update.
81   *@param QString unit.
82   */
83 void CarMainWindow::updateUnitCompoBox(QString unit)
84 {
85     ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
86 }
87
88 /**
89   *This function is used to init unit combobox.
90   */
91 void CarMainWindow::initUnitCompoBox()
92 {
93     units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
94     ui->unitComboBox->addItems(units);
95 }
96
97 /**
98   *This function is used to set items to unit combobox.
99   *@param QStringlist numbers
100   */
101 void CarMainWindow::setUnitCompoBox(QStringList units)
102 {
103     ui->unitComboBox->addItems(units);
104 }
105
106 /**
107   *This function is used to init speed listview.
108   */
109 void CarMainWindow::initSpeedListView()
110 {
111     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";
112     QAbstractItemModel *model = new StringListModel(numbers);
113     ui->listView->setModel(model);
114 }
115
116 /**
117 <<<<<<< HEAD:Client/carmainwindow.cpp
118   *This function is used to set items to speed listview.
119   *@param QStringlist numbers
120   */
121 void CarMainWindow::setSpeedListView(QStringList numbers)
122 {
123     QAbstractItemModel *model = new StringListModel(numbers);
124     ui->listView->setModel(model);
125 }
126
127 /**
128   *This function is used to init category combobox.
129   */
130 void CarMainWindow::initCategoryCompoBox()
131 {
132     categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car";
133     ui->comboBoxTopCategory->addItems(categories);
134 }
135
136 /**
137   *This function is used to set items to category combobox.
138   *@param QStringlist categories
139   */
140 void CarMainWindow::setCategoryCompoBox(QStringList categories)
141 {
142     ui->comboBoxTopCategory->addItems(categories);
143 }
144
145 /**
146   *This slot function is called when ever categories combobox is update.
147   *@param QString category
148   */
149 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
150 {
151     //TODO: get top list
152
153     QStringList topList;
154     topList << "1. Pertti 7,5s" << "2. Ville 10,2s";
155
156     QAbstractItemModel *model = new StringListModel(topList);
157     ui->listViewTopList->setModel(model);
158 }
159
160 /**
161   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
162   */
163 void CarMainWindow::openResultView()
164 {
165     result->saveMeasuresToArray(measure->measures);
166     // Show result dialog.
167     result->show();
168 }