Added measures.h and measures.cpp files. Changed resultdialog.h, .cpp and measuredial...
authorJanne Änäkkälä <Janne_anakkala@hotmail.com>
Wed, 3 Mar 2010 13:08:59 +0000 (15:08 +0200)
committerJanne Änäkkälä <Janne_anakkala@hotmail.com>
Wed, 3 Mar 2010 13:08:59 +0000 (15:08 +0200)
Now measure dialog gets speed and time from accelerometer and when speed is raised to 100km/h
result dialog opens. Result dialog draws now diagram with real values which has got from accelerometer.

Client/UI.pro
Client/carmainwindow.cpp
Client/measuredialog.cpp
Client/measuredialog.h
Client/resultdialog.cpp
Client/resultdialog.h

index 97de2a2..dae4481 100644 (file)
@@ -11,15 +11,15 @@ SOURCES += main.cpp \
     stringlistmodel.cpp \
     measuredialog.cpp \
     calculate.cpp \
-    accelerometer.cpp
-
+    accelerometer.cpp \
+    measures.cpp
 HEADERS += carmainwindow.h \
     resultdialog.h \
     stringlistmodel.h \
     measuredialog.h \
     accelerometer.h \
-    calculate.h
-
+    calculate.h \
+    measures.h
 FORMS += carmainwindow.ui \
     resultdialog.ui \
     measuredialog.ui
index b8af9fe..10affda 100644 (file)
@@ -66,15 +66,12 @@ void CarMainWindow::on_listView_clicked(QModelIndex index)
   */
 void CarMainWindow::on_autoStartButton_clicked()
 {
-    if(measure)
-    {
-        delete measure;
-        measure = NULL;
-        measure = new MeasureDialog();
-    }
 
-    connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
+    delete measure;
+    measure = NULL;
+    measure = new MeasureDialog();
 
+    connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
     // Show measure dialog.
     measure->show();
 }
@@ -165,6 +162,7 @@ void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
   */
 void CarMainWindow::openResultView()
 {
+    result->saveMeasuresToArray(measure->measures);
     // Show result dialog.
     result->show();
 }
index 528018e..efec02b 100644 (file)
@@ -17,8 +17,12 @@ MeasureDialog::MeasureDialog(QWidget *parent) :
     timer = new QTimer();
 
     accelerometer = new Accelerometer();
+    accelerometer->setSampleRate(100);
     accelerometer->start();
 
+    measures = new Measures();
+    this->initializeMeasures();
+
     timer->setInterval(100);
     timer->start();
     connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
@@ -51,11 +55,67 @@ void MeasureDialog::after_timeout()
 {
     QString timeString, speedString;
     //time++;
-    time = accelerometer->getIntervalTime();
+    time = accelerometer->getTotalTime();
     speed = accelerometer->getCurrentSpeed();
+    //speed = speed +10;
+
+    if(speed > 9.7 && speed < 10.3)
+    {
+        measures->setTime10kmh(time);
+    }
+
+    else if (speed > 19.7 && speed < 20.3)
+    {
+        measures->setTime20kmh(time);
+    }
+
+    else if (speed > 29.7 && speed < 30.3)
+    {
+        measures->setTime30kmh(time);
+    }
+
+    else if (speed > 39.7 && speed < 40.3)
+    {
+        measures->setTime40kmh(time);
+    }
+
+    else if (speed > 49.7 && speed < 50.3)
+    {
+        measures->setTime50kmh(time);
+    }
+
+    else if (speed > 59.7 && speed < 60.3)
+    {
+        measures->setTime60kmh(time);
+    }
+
+    else if (speed > 69.7 && speed < 70.3)
+    {
+        measures->setTime70kmh(time);
+    }
+
+    else if (speed > 79.7 && speed < 80.3)
+    {
+        measures->setTime80kmh(time);
+    }
+
+    else if (speed > 89.7 && speed < 90.3)
+    {
+        measures->setTime90kmh(time);
+    }
+
+    else if (speed > 99.7 && speed < 100.3)
+    {
+        measures->setTime100kmh(time);
+    }
+
+    else
+    {
+
+    }
 
     // If speed is over 100 km/h emits speedAchieved() signal and close this dialog.
-    if(speed>=100.0)
+    if (speed >= 100.0)
     {
         timer->stop();
         accelerometer->stop();
@@ -75,6 +135,7 @@ void MeasureDialog::after_timeout()
         ui->labelTime->setText(timeString);
         timer->start();
     }
+
 }
 
 /**
@@ -82,9 +143,33 @@ void MeasureDialog::after_timeout()
   */
 void MeasureDialog::on_pushButtonAbort_clicked()
 {
+    measures->setTime10kmh(0);
+    measures->setTime20kmh(0);
+    measures->setTime30kmh(0);
+    measures->setTime40kmh(0);
+    measures->setTime50kmh(0);
+    measures->setTime60kmh(0);
+    measures->setTime70kmh(0);
+    measures->setTime80kmh(0);
+    measures->setTime90kmh(0);
+    measures->setTime100kmh(0);
     timer->stop();
     accelerometer->stop();
     time = 0;
     speed = 0;
     this->close();
 }
+
+void MeasureDialog::initializeMeasures()
+{
+    measures->setTime10kmh(0);
+    measures->setTime20kmh(0);
+    measures->setTime30kmh(0);
+    measures->setTime40kmh(0);
+    measures->setTime50kmh(0);
+    measures->setTime60kmh(0);
+    measures->setTime70kmh(0);
+    measures->setTime80kmh(0);
+    measures->setTime90kmh(0);
+    measures->setTime100kmh(0);
+}
index abddf06..893d61e 100644 (file)
@@ -2,6 +2,7 @@
 #define MEASUREDIALOG_H
 
 #include "accelerometer.h"
+#include "measures.h"
 #include <QDialog>
 #include <QTimer>
 
@@ -14,7 +15,8 @@ class MeasureDialog : public QDialog {
 public:
     MeasureDialog(QWidget *parent = 0);
     ~MeasureDialog();
-
+    Measures *measures;
+    void initializeMeasures();
 protected:
     void changeEvent(QEvent *e);
 
@@ -24,9 +26,8 @@ private:
     QTimer *timer;
     Accelerometer *accelerometer;
 
-
-    qreal time;
-    qreal speed;
+    double time;
+    double speed;
 
     signals:
     void speedAchieved();
index a043767..12f95db 100644 (file)
@@ -10,12 +10,9 @@ const QPoint diagramHorizontalEnd(450, 350);
 
 const int diagramGap = 30;
 
-
 // Test arrays for changing speeds and times to the points in diagram
-static const int speedArray[10] = {12, 34, 56, 78, 90, 100, 104, 100, 90, 80};
-static const int timeArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12};
-
-
+static const int speedArray[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
+//static const int timeArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12};
 
 // Test point array for the diagram.
 QPoint points[10];
@@ -26,46 +23,8 @@ ResultDialog::ResultDialog(QWidget *parent) :
 {
     ui->setupUi(this);
 
-    QString time, timeInteger;
-    timeInteger.setNum(timeArray[9]);
-    time = "0 - 100 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult->setText(time);
-
-    timeInteger.setNum(timeArray[8]);
-    time = "0 - 90 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_2->setText(time);
-
-    timeInteger.setNum(timeArray[7]);
-    time = "0 - 80 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_3->setText(time);
-
-    timeInteger.setNum(timeArray[6]);
-    time = "0 - 70 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_4->setText(time);
-
-    timeInteger.setNum(timeArray[5]);
-    time = "0 - 60 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_5->setText(time);
 
-    timeInteger.setNum(timeArray[4]);
-    time = "0 - 50 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_6->setText(time);
 
-    timeInteger.setNum(timeArray[3]);
-    time = "0 - 40 km/h: ";
-    time.append(timeInteger);
-    ui->labelResult_7->setText(time);
-
-    for(int i = 0; i < 10; i++)
-    {
-        points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
-    }
    // ui->labelXLine->setText(ui->labelXLine->text().append(": time/ s"));
    // ui->labelYLine->setText(ui->labelYLine->text().append(": speed/ km/h"));
 }
@@ -130,7 +89,7 @@ void ResultDialog::paintEvent(QPaintEvent *)
   *@param aSpeed is speed which need to change, aTime is time in seconds which need to change.
   *@return point is calculated from aSpeed and aTime.
   **/
-QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, int aTime)
+QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, qreal aTime)
 {
     QPoint point;
 
@@ -143,3 +102,69 @@ QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, int aTime)
 
     return point;
 }
+
+/**
+  *Saves the given measures to array.
+  *@param pMeasures has information about acceleration.
+  **/
+void ResultDialog::saveMeasuresToArray(Measures *pMeasures)
+{
+    timeArray[0] = pMeasures->getTime10kmh();
+    timeArray[1] = pMeasures->getTime20kmh();
+    timeArray[2] = pMeasures->getTime30kmh();
+    timeArray[3] = pMeasures->getTime40kmh();
+    timeArray[4] = pMeasures->getTime50kmh();
+    timeArray[5] = pMeasures->getTime60kmh();
+    timeArray[6] = pMeasures->getTime70kmh();
+    timeArray[7] = pMeasures->getTime80kmh();
+    timeArray[8] = pMeasures->getTime90kmh();
+    timeArray[9] = pMeasures->getTime100kmh();
+
+    for(int i = 0; i < 10; i++)
+    {
+        points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
+    }
+
+    QString time, timeInteger;
+    timeInteger.setNum(timeArray[9]);
+    time = "0 - 100 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult->setText(time);
+
+    timeInteger.setNum(timeArray[8]);
+    time = "0 - 90 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_2->setText(time);
+
+    timeInteger.setNum(timeArray[7]);
+    time = "0 - 80 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_3->setText(time);
+
+    timeInteger.setNum(timeArray[6]);
+    time = "0 - 70 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_4->setText(time);
+
+    timeInteger.setNum(timeArray[5]);
+    time = "0 - 60 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_5->setText(time);
+
+    timeInteger.setNum(timeArray[4]);
+    time = "0 - 50 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_6->setText(time);
+
+    timeInteger.setNum(timeArray[3]);
+    time = "0 - 40 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult_7->setText(time);
+
+    this->repaint();
+
+    for(int i = 0; i < 10; i++)
+    {
+        timeArray[i] = 0;
+    }
+}
index daad7d3..efed840 100644 (file)
@@ -2,6 +2,7 @@
 #define RESULTDIALOG_H
 
 #include <QDialog>
+#include "measures.h"
 
 namespace Ui {
     class ResultDialog;
@@ -12,13 +13,15 @@ class ResultDialog : public QDialog {
 public:
     ResultDialog(QWidget *parent = 0);
     ~ResultDialog();
+    void saveMeasuresToArray(Measures *pMeasures);
 
 protected:
     void changeEvent(QEvent *e);
     void paintEvent(QPaintEvent *);
 
 private:
-    QPoint changeMeasuresToDiagramPoint(int aSpeed, int aTime);
+    QPoint changeMeasuresToDiagramPoint(int aSpeed, qreal aTime);
+    qreal timeArray[10];
 
 private:
     Ui::ResultDialog *ui;