b730a696ac20f9f6694711f5e34c9342ba05aa60
[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 }
17
18 /**
19   *Destructor of this class. Should be used to release all allocated resources.
20   */
21 CarMainWindow::~CarMainWindow()
22 {
23     delete ui;
24     delete result;
25     delete measure;
26     delete xmlreader;
27 }
28
29 /**
30   *This function is used to .
31   *@param
32   */
33 void CarMainWindow::changeEvent(QEvent *e)
34 {
35     QMainWindow::changeEvent(e);
36     switch (e->type()) {
37     case QEvent::LanguageChange:
38         ui->retranslateUi(this);
39         break;
40     default:
41         break;
42     }
43 }
44
45 /**
46   *This slot function is called when ever list view is update. Start-tab view.
47   */
48 void CarMainWindow::on_listView_clicked(QModelIndex index)
49 {
50     QString str = index.data().toString();
51     QStringList list = str.split("-");
52     QStringList list2 = list[1].split(" ");
53
54     ui->minLineEdit->setText(list[0]);
55     ui->maxLineEdit->setText(list2[0]);
56     updateUnitCompoBox(list2[1]);
57 }
58
59 /**
60   *This slot function is called when ever auto start button clicked. Start-tab view.
61   */
62 void CarMainWindow::on_autoStartButton_clicked()
63 {
64     if(measure)
65     {
66         delete measure;
67         measure = NULL;
68         measure = new MeasureDialog();
69     }
70
71     connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
72
73     // Show measure dialog.
74     measure->show();
75 }
76
77 /**
78   *This slot function is called when ever list view is update. Start-tab view.
79   *@param QString unit.
80   */
81 void CarMainWindow::updateUnitCompoBox(QString unit)
82 {
83     ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
84 }
85
86 /**
87   *This function is used to init unit combobox. Start-tab view.
88   */
89 void CarMainWindow::initUnitCompoBox()
90 {
91     units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd";
92     ui->unitComboBox->addItems(units);
93 }
94
95 /**
96   *This function is used to set items to unit combobox. Start-tab view.
97   *@param QStringlist numbers
98   */
99 void CarMainWindow::setUnitCompoBox(QStringList units)
100 {
101     ui->unitComboBox->addItems(units);
102 }
103
104 /**
105   *This function is used to init speed listview. Start-tab view.
106   */
107 void CarMainWindow::initSpeedListView()
108 {
109     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";
110     QAbstractItemModel *model = new StringListModel(numbers);
111     ui->listView->setModel(model);
112 }
113
114 /**
115   *This function is used to set items to speed listview. Start-tab view.
116   *@param QStringlist numbers
117   */
118 void CarMainWindow::setSpeedListView(QStringList numbers)
119 {
120     QAbstractItemModel *model = new StringListModel(numbers);
121     ui->listView->setModel(model);
122 }
123
124 /**
125   *This function is used to set items to category combobox. Top-tab view.
126   *@param
127   */
128 void CarMainWindow::setCategoryCompoBox()
129 {
130     ui->comboBoxTopCategory->addItems(xmlreader->getTop10List());
131 }
132
133 /**
134   *This function is used to set items to labelTopList. Top-tab view.
135   *@param QString category
136   */
137 void CarMainWindow::setListViewTopList(QString category)
138 {
139     QString topList;
140
141     if (category == "acceleration-0-100")
142     {
143         topList.append(xmlreader->getTop10AccelerationList());
144     }
145
146     else if (category == "Speed")
147     {
148         topList.append(xmlreader->getTop10SpeedList());
149     }
150
151     else if (category == "G-force")
152     {
153         topList.append(xmlreader->getTop10GforceList());
154     }
155     ui->labelTopList->setText(topList);
156 }
157
158 /**
159   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
160   */
161 void CarMainWindow::openResultView()
162 {
163     // Show result dialog.
164     result->show();
165 }
166
167 /**
168   *This slot function is called when ever refresh button clicked. Top-tab view.
169   */
170 void CarMainWindow::on_buttonTopRefresh_clicked()
171 {
172     setCategoryCompoBox();
173 }
174
175 /**
176   *This slot function is called when ever category combobox current index changed. Top-tab view.
177   *@param QString category
178   */
179 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
180 {
181     setListViewTopList(category);
182 }