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

Merge branch 'feature/UIcommwithAccele2'

Conflicts:
Client/UI.pro

Client/UI.pro
Client/carmainwindow.cpp
Client/measuredialog.cpp
Client/measuredialog.h
Client/measures.cpp [new file with mode: 0644]
Client/measures.h [new file with mode: 0644]
Client/resultdialog.cpp
Client/resultdialog.h
Client/resultdialog.ui

index 2d5e8c6..8990d68 100644 (file)
@@ -14,6 +14,8 @@ SOURCES += main.cpp \
     accelerometer.cpp \
     loginwindow.cpp \
     registration.cpp
+    measures.cpp
+
 HEADERS += carmainwindow.h \
     resultdialog.h \
     stringlistmodel.h \
@@ -22,6 +24,8 @@ HEADERS += carmainwindow.h \
     calculate.h \
     loginwindow.h \
     registration.h
+    measures.h
+
 FORMS += carmainwindow.ui \
     resultdialog.ui \
     measuredialog.ui \
index 9b6c57e..c698f4c 100644 (file)
@@ -74,15 +74,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();
 }
@@ -119,7 +116,7 @@ void CarMainWindow::setUnitCompoBox(QStringList units)
   */
 void CarMainWindow::initSpeedListView()
 {
-    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";
+    numbers << "0-40 km/h" << "0-1/4 mil" << "0-50 km" << "50-100 mil" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
     QAbstractItemModel *model = new StringListModel(numbers);
     ui->listView->setModel(model);
 }
@@ -173,6 +170,7 @@ void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
   */
 void CarMainWindow::openResultView()
 {
+    result->saveMeasuresToArray(measure->measures);
     // Show result dialog.
     result->show();
 }
index 892b9b9..038116a 100644 (file)
@@ -17,9 +17,13 @@ MeasureDialog::MeasureDialog(QWidget *parent) :
     timer = new QTimer();
 
     accelerometer = new Accelerometer();
-    //accelerometer->start();
+    accelerometer->setSampleRate(100);
+    accelerometer->start();
 
-    timer->setInterval(1000);
+    measures = new Measures();
+    this->initializeMeasures();
+
+    timer->setInterval(100);
     timer->start();
     connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
 }
@@ -50,14 +54,71 @@ void MeasureDialog::changeEvent(QEvent *e)
 void MeasureDialog::after_timeout()
 {
     QString timeString, speedString;
-    time++;
+    //time++;
+    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 >= 40.0)
     {
         timer->stop();
-        //accelerometer->stop();
+        accelerometer->stop();
         time = 0;
         speed = 0;
         emit this->speedAchieved();
@@ -74,6 +135,7 @@ void MeasureDialog::after_timeout()
         ui->labelTime->setText(timeString);
         timer->start();
     }
+
 }
 
 /**
@@ -81,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();
+    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 b33450a..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;
 
-
-    int time;
-    qreal speed;
+    double time;
+    double speed;
 
     signals:
     void speedAchieved();
diff --git a/Client/measures.cpp b/Client/measures.cpp
new file mode 100644 (file)
index 0000000..c840ec0
--- /dev/null
@@ -0,0 +1,105 @@
+#include "measures.h"
+
+Measures::Measures()
+{
+}
+
+qreal Measures::getTime10kmh()
+{
+    return time10kmh;
+}
+
+qreal Measures::getTime20kmh()
+{
+    return time20kmh;
+}
+
+qreal Measures::getTime30kmh()
+{
+    return time30kmh;
+}
+
+qreal Measures::getTime40kmh()
+{
+    return time40kmh;
+}
+
+qreal Measures::getTime50kmh()
+{
+    return time50kmh;
+}
+
+qreal Measures::getTime60kmh()
+{
+    return time60kmh;
+}
+
+qreal Measures::getTime70kmh()
+{
+    return time70kmh;
+}
+
+qreal Measures::getTime80kmh()
+{
+    return time80kmh;
+}
+
+qreal Measures::getTime90kmh()
+{
+    return time90kmh;
+}
+
+qreal Measures::getTime100kmh()
+{
+    return time100kmh;
+}
+
+void Measures::setTime10kmh(qreal pTime)
+{
+    time10kmh = pTime;
+}
+
+void Measures::setTime20kmh(qreal pTime)
+{
+    time20kmh = pTime;
+}
+
+void Measures::setTime30kmh(qreal pTime)
+{
+    time30kmh = pTime;
+}
+
+void Measures::setTime40kmh(qreal pTime)
+{
+    time40kmh = pTime;
+}
+
+void Measures::setTime50kmh(qreal pTime)
+{
+    time50kmh = pTime;
+}
+
+void Measures::setTime60kmh(qreal pTime)
+{
+    time60kmh = pTime;
+}
+
+void Measures::setTime70kmh(qreal pTime)
+{
+    time70kmh = pTime;
+}
+
+void Measures::setTime80kmh(qreal pTime)
+{
+    time80kmh = pTime;
+}
+
+void Measures::setTime90kmh(qreal pTime)
+{
+    time90kmh = pTime;
+}
+
+void Measures::setTime100kmh(qreal pTime)
+{
+    time100kmh = pTime;
+}
diff --git a/Client/measures.h b/Client/measures.h
new file mode 100644 (file)
index 0000000..009e868
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef MEASURES_H
+#define MEASURES_H
+
+#include <QObject>
+
+class Measures
+{
+public:
+    Measures();
+    qreal getTime10kmh();
+    qreal getTime20kmh();
+    qreal getTime30kmh();
+    qreal getTime40kmh();
+    qreal getTime50kmh();
+    qreal getTime60kmh();
+    qreal getTime70kmh();
+    qreal getTime80kmh();
+    qreal getTime90kmh();
+    qreal getTime100kmh();
+
+    void setTime10kmh(qreal pTime);
+    void setTime20kmh(qreal pTime);
+    void setTime30kmh(qreal pTime);
+    void setTime40kmh(qreal pTime);
+    void setTime50kmh(qreal pTime);
+    void setTime60kmh(qreal pTime);
+    void setTime70kmh(qreal pTime);
+    void setTime80kmh(qreal pTime);
+    void setTime90kmh(qreal pTime);
+    void setTime100kmh(qreal pTime);
+
+
+private:
+    qreal time10kmh;
+    qreal time20kmh;
+    qreal time30kmh;
+    qreal time40kmh;
+    qreal time50kmh;
+    qreal time60kmh;
+    qreal time70kmh;
+    qreal time80kmh;
+    qreal time90kmh;
+    qreal time100kmh;
+};
+
+#endif // MEASURES_H
index a043767..c3b3a74 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"));
 }
@@ -121,7 +80,7 @@ void ResultDialog::paintEvent(QPaintEvent *)
             painter.drawLine(currentX, currentY, currentX+10, currentY);
         }
 
-        painter.drawPolyline(points, 10);
+        painter.drawPolyline(points, 4);
 
 }
 
@@ -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 < 4; i++)
+    {
+        points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
+    }
+
+    QString time, timeInteger;
+    timeInteger.setNum(timeArray[3]);
+    time = "0 - 40 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult40kmh->setText(time);
+
+    timeInteger.setNum(timeArray[2]);
+    time = "0 - 30 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult30kmh->setText(time);
+
+    timeInteger.setNum(timeArray[1]);
+    time = "0 - 20 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult20kmh->setText(time);
+
+    timeInteger.setNum(timeArray[0]);
+    time = "0 - 10 km/h: ";
+    time.append(timeInteger);
+    ui->labelResult10kmh->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;
index 81ee877..c0c3a73 100644 (file)
   <property name="windowTitle">
    <string>Dialog</string>
   </property>
-  <widget class="QLabel" name="labelResult_4">
+  <widget class="QLabel" name="labelResult10kmh">
    <property name="geometry">
     <rect>
-     <x>520</x>
-     <y>120</y>
+     <x>410</x>
+     <y>230</y>
      <width>191</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
-    <string>0 - 50 km/h: 5,6 s</string>
+    <string>0 - 10 km/h: 5,6 s</string>
    </property>
   </widget>
-  <widget class="QLabel" name="labelResult_7">
+  <widget class="QLabel" name="labelResult40kmh">
    <property name="geometry">
     <rect>
-     <x>520</x>
-     <y>240</y>
+     <x>410</x>
+     <y>90</y>
      <width>191</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
-    <string>0 - 20 km/h: 1,1 s</string>
+    <string>0 - 40 km/h: 9,8 s</string>
    </property>
   </widget>
-  <widget class="QLabel" name="labelResult">
+  <widget class="QLabel" name="labelResult20kmh">
    <property name="geometry">
     <rect>
-     <x>520</x>
-     <y>10</y>
-     <width>191</width>
-     <height>31</height>
-    </rect>
-   </property>
-   <property name="text">
-    <string>0 - 100 km/h: 9,8 s</string>
-   </property>
-  </widget>
-  <widget class="QLabel" name="labelResult_6">
-   <property name="geometry">
-    <rect>
-     <x>520</x>
-     <y>200</y>
-     <width>191</width>
-     <height>31</height>
-    </rect>
-   </property>
-   <property name="text">
-    <string>0 - 30 km/h: 3,2 s</string>
-   </property>
-  </widget>
-  <widget class="QLabel" name="labelResult_5">
-   <property name="geometry">
-    <rect>
-     <x>520</x>
-     <y>160</y>
+     <x>410</x>
+     <y>180</y>
      <width>191</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
-    <string>0 - 40 km/h:4,5 s</string>
+    <string>0 - 20 km/h: 6,9 s</string>
    </property>
   </widget>
-  <widget class="QLabel" name="labelResult_3">
+  <widget class="QLabel" name="labelResult30kmh">
    <property name="geometry">
     <rect>
-     <x>520</x>
-     <y>80</y>
-     <width>191</width>
-     <height>31</height>
-    </rect>
-   </property>
-   <property name="text">
-    <string>0 - 60 km/h: 6,9 s</string>
-   </property>
-  </widget>
-  <widget class="QLabel" name="labelResult_2">
-   <property name="geometry">
-    <rect>
-     <x>520</x>
-     <y>40</y>
+     <x>410</x>
+     <y>140</y>
      <width>191</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
-    <string>0 - 80 km/h: 8,6 s</string>
+    <string>0 - 30 km/h: 8,6 s</string>
    </property>
   </widget>
   <widget class="QLabel" name="labelY2">