ace503b6f21b52662f27412f52aee5c64a1d66e1
[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    result->show();
67 }
68
69 /**
70   *This slot function is called when ever list view is update.
71   *@param QString unit.
72   */
73 void CarMainWindow::updateUnitCompoBox(QString unit)
74 {
75     ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
76 }
77
78 /**
79   *This function is used to init combobox.
80   */
81 void CarMainWindow::initUnitCompoBox()
82 {
83     units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
84     ui->unitComboBox->addItems(units);
85 }
86
87 /**
88   *This function is used to init listview.
89   */
90 void CarMainWindow::initSpeedListView()
91 {
92     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";
93     QAbstractItemModel *model = new StringListModel(numbers);
94     ui->listView->setModel(model);
95 }