From 2650becbf772dc623f16cf29f236fd19df335334 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janne=20=C3=84n=C3=A4kk=C3=A4l=C3=A4?= Date: Mon, 1 Mar 2010 15:06:31 +0200 Subject: [PATCH] Changes in measuredialog.cpp, .h and carmainwindow.cpp, .h. Added timer in measuredialog which updates labels when interval time expires. Added slot function speedAchieved() in carmainwindow which opens result dialog when speed has been achieved. --- Client/UI.pro | 8 ++++-- Client/carmainwindow.cpp | 21 +++++++++++++++- Client/carmainwindow.h | 1 + Client/measuredialog.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ Client/measuredialog.h | 16 ++++++++++++ Client/measuredialog.ui | 26 +++++-------------- 6 files changed, 112 insertions(+), 23 deletions(-) diff --git a/Client/UI.pro b/Client/UI.pro index c9c3c77..6c55c45 100644 --- a/Client/UI.pro +++ b/Client/UI.pro @@ -9,11 +9,15 @@ SOURCES += main.cpp \ carmainwindow.cpp \ resultdialog.cpp \ stringlistmodel.cpp \ - measuredialog.cpp + measuredialog.cpp \ + accelerometer.cpp \ + calculate.cpp HEADERS += carmainwindow.h \ resultdialog.h \ stringlistmodel.h \ - measuredialog.h + measuredialog.h \ + accelerometer.h \ + calculate.h FORMS += carmainwindow.ui \ resultdialog.ui \ measuredialog.ui diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index ace503b..60b80e6 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -63,7 +63,17 @@ void CarMainWindow::on_listView_clicked(QModelIndex index) */ void CarMainWindow::on_autoStartButton_clicked() { - result->show(); + if(measure) + { + delete measure; + measure = NULL; + measure = new MeasureDialog(); + } + + connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView())); + + // Show measure dialog. + measure->show(); } /** @@ -93,3 +103,12 @@ void CarMainWindow::initSpeedListView() QAbstractItemModel *model = new StringListModel(numbers); ui->listView->setModel(model); } + +/** + *This slot function is called when speed is achieved in measure dialog. Opens result dialog. + */ +void CarMainWindow::openResultView() +{ + // Show result dialog. + result->show(); +} diff --git a/Client/carmainwindow.h b/Client/carmainwindow.h index 054b075..1e1e83d 100644 --- a/Client/carmainwindow.h +++ b/Client/carmainwindow.h @@ -41,6 +41,7 @@ private slots: void on_autoStartButton_clicked(); void on_listView_clicked(QModelIndex index); void updateUnitCompoBox(QString unit); + void openResultView(); }; #endif // CARMAINWINDOW_H diff --git a/Client/measuredialog.cpp b/Client/measuredialog.cpp index 11944f2..892b9b9 100644 --- a/Client/measuredialog.cpp +++ b/Client/measuredialog.cpp @@ -1,13 +1,32 @@ #include "measuredialog.h" #include "ui_measuredialog.h" + +/** + *Constructor of this class. + *@param QWidget pointer to parent object. By default the value is NULL. + */ MeasureDialog::MeasureDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MeasureDialog) { ui->setupUi(this); + ui->labelInfo->setText("Accelerate to 100 km/h"); + time = 0; + speed = 0; + timer = new QTimer(); + + accelerometer = new Accelerometer(); + //accelerometer->start(); + + timer->setInterval(1000); + timer->start(); + connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout())); } +/** + *Destructor of this class. Should be used to release all allocated resources. + */ MeasureDialog::~MeasureDialog() { delete ui; @@ -24,3 +43,47 @@ void MeasureDialog::changeEvent(QEvent *e) break; } } + +/** + *This slot function is called when timer gives timeout signal. + */ +void MeasureDialog::after_timeout() +{ + QString timeString, speedString; + time++; + speed = accelerometer->getCurrentSpeed(); + + // If speed is over 100 km/h emits speedAchieved() signal and close this dialog. + if(speed>=100.0) + { + timer->stop(); + //accelerometer->stop(); + time = 0; + speed = 0; + emit this->speedAchieved(); + this->close(); + + } + + // Updates speed and time. + else + { + timeString.setNum(time); + speedString.setNum(speed); + ui->labelSpeed->setText(speedString); + ui->labelTime->setText(timeString); + timer->start(); + } +} + +/** + *This slot function is called when Abort button is clicked. + */ +void MeasureDialog::on_pushButtonAbort_clicked() +{ + timer->stop(); + //accelerometer->stop(); + time = 0; + speed = 0; + this->close(); +} diff --git a/Client/measuredialog.h b/Client/measuredialog.h index 24a3773..b33450a 100644 --- a/Client/measuredialog.h +++ b/Client/measuredialog.h @@ -1,7 +1,9 @@ #ifndef MEASUREDIALOG_H #define MEASUREDIALOG_H +#include "accelerometer.h" #include +#include namespace Ui { class MeasureDialog; @@ -18,6 +20,20 @@ protected: private: Ui::MeasureDialog *ui; + + QTimer *timer; + Accelerometer *accelerometer; + + + int time; + qreal speed; + + signals: + void speedAchieved(); + +private slots: + void on_pushButtonAbort_clicked(); + void after_timeout(); }; #endif // MEASUREDIALOG_H diff --git a/Client/measuredialog.ui b/Client/measuredialog.ui index cda5b05..5f7954d 100644 --- a/Client/measuredialog.ui +++ b/Client/measuredialog.ui @@ -13,7 +13,7 @@ Dialog - + 130 @@ -39,51 +39,37 @@ - + Time: - + Speed: - - - - Distance: - - - - + - 14 s + 0 - + 86 km/h - - - - 120 m - - - -- 1.7.9.5