Changes in measuredialog.cpp, .h and carmainwindow.cpp and .h
authorJanne Änäkkälä <Janne_anakkala@hotmail.com>
Tue, 2 Mar 2010 07:30:47 +0000 (09:30 +0200)
committerJanne Änäkkälä <Janne_anakkala@hotmail.com>
Tue, 2 Mar 2010 07:30:47 +0000 (09:30 +0200)
Added timer in measure dialog which makes timeout every second and updates
speed and time to the UI. When target speed is achieved emits signal
speedAchieved() and then carmainwindow opens result dialog.

Merge branch 'testiBranch'

Conflicts:
Client/UI.pro
Client/carmainwindow.cpp

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

index c48d029..97de2a2 100644 (file)
@@ -12,12 +12,14 @@ SOURCES += main.cpp \
     measuredialog.cpp \
     calculate.cpp \
     accelerometer.cpp
+
 HEADERS += carmainwindow.h \
     resultdialog.h \
     stringlistmodel.h \
     measuredialog.h \
-    calculate.h \
-    accelerometer.h
+    accelerometer.h \
+    calculate.h
+
 FORMS += carmainwindow.ui \
     resultdialog.ui \
     measuredialog.ui
index 50a24e0..b8af9fe 100644 (file)
@@ -66,7 +66,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();
 }
 
 /**
@@ -107,6 +117,7 @@ void CarMainWindow::initSpeedListView()
 }
 
 /**
+<<<<<<< HEAD:Client/carmainwindow.cpp
   *This function is used to set items to speed listview.
   *@param QStringlist numbers
   */
@@ -148,3 +159,12 @@ void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
     QAbstractItemModel *model = new StringListModel(topList);
     ui->listViewTopList->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();
+}
index f284446..198bb30 100644 (file)
@@ -49,6 +49,7 @@ private slots:
     void on_autoStartButton_clicked();
     void on_listView_clicked(QModelIndex index);
     void updateUnitCompoBox(QString unit);
+    void openResultView();
 };
 
 #endif // CARMAINWINDOW_H
index 11944f2..892b9b9 100644 (file)
@@ -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();
+}
index 24a3773..b33450a 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef MEASUREDIALOG_H
 #define MEASUREDIALOG_H
 
+#include "accelerometer.h"
 #include <QDialog>
+#include <QTimer>
 
 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
index cda5b05..5f7954d 100644 (file)
@@ -13,7 +13,7 @@
   <property name="windowTitle">
    <string>Dialog</string>
   </property>
-  <widget class="QLabel" name="label_7">
+  <widget class="QLabel" name="labelInfo">
    <property name="geometry">
     <rect>
      <x>130</x>
     <item>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
-       <widget class="QLabel" name="label">
+       <widget class="QLabel" name="labelTimeHeader">
         <property name="text">
          <string>Time:</string>
         </property>
        </widget>
       </item>
       <item>
-       <widget class="QLabel" name="label_2">
+       <widget class="QLabel" name="labelSpeedHeader">
         <property name="text">
          <string>Speed:</string>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLabel" name="label_3">
-        <property name="text">
-         <string>Distance:</string>
-        </property>
-       </widget>
-      </item>
      </layout>
     </item>
     <item>
      <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
-       <widget class="QLabel" name="label_6">
+       <widget class="QLabel" name="labelTime">
         <property name="text">
-         <string>14 s</string>
+         <string>0</string>
         </property>
        </widget>
       </item>
       <item>
-       <widget class="QLabel" name="label_4">
+       <widget class="QLabel" name="labelSpeed">
         <property name="text">
          <string>86 km/h</string>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QLabel" name="label_5">
-        <property name="text">
-         <string>120 m</string>
-        </property>
-       </widget>
-      </item>
      </layout>
     </item>
    </layout>