Changes in measuredialog.cpp, .h and carmainwindow.cpp, .h.
[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 }
21
22 /**
23   *Destructor of this class.  Should be used to release all allocated resources.
24   */
25 CarMainWindow::~CarMainWindow()
26 {
27     delete ui;
28 }
29
30 /**
31   *This function is used to .
32   *@param
33   */
34 void CarMainWindow::changeEvent(QEvent *e)
35 {
36     QMainWindow::changeEvent(e);
37     switch (e->type()) {
38     case QEvent::LanguageChange:
39         ui->retranslateUi(this);
40         break;
41     default:
42         break;
43     }
44 }
45
46 /**
47   *This slot function is called when ever list view is update.
48   *@param QModelIndex index.
49   */
50 void CarMainWindow::on_listView_clicked(QModelIndex index)
51 {
52     QString str = index.data().toString();
53     QStringList list = str.split("-");
54     QStringList list2 = list[1].split(" ");
55
56     ui->minLineEdit->setText(list[0]);
57     ui->maxLineEdit->setText(list2[0]);
58     updateUnitCompoBox(list2[1]);
59 }
60
61 /**
62   *This slot function is called when ever auto start button clicked.
63   */
64 void CarMainWindow::on_autoStartButton_clicked()
65 {
66     if(measure)
67     {
68         delete measure;
69         measure = NULL;
70         measure = new MeasureDialog();
71     }
72
73     connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
74
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 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 init listview.
99   */
100 void CarMainWindow::initSpeedListView()
101 {
102     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";
103     QAbstractItemModel *model = new StringListModel(numbers);
104     ui->listView->setModel(model);
105 }
106
107 /**
108   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
109   */
110 void CarMainWindow::openResultView()
111 {
112     // Show result dialog.
113     result->show();
114 }