Feature: Show average speed in realtime.
authorToni Jussila <toni.jussila@fudeco.com>
Tue, 27 Apr 2010 10:07:04 +0000 (13:07 +0300)
committerToni Jussila <toni.jussila@fudeco.com>
Tue, 27 Apr 2010 10:07:04 +0000 (13:07 +0300)
Client/routedialog.cpp
Client/routedialog.h
Client/routedialog.ui
Client/routesavedialog.cpp
Client/routesavedialog.h
Client/routesavedialog.ui

index f0806c8..da4853e 100644 (file)
@@ -7,6 +7,7 @@
  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
 
+#include "routesavedialog.h"
 #include "routedialog.h"
 #include "ui_routedialog.h"
 #include "usersettings.h"
@@ -169,7 +170,8 @@ qreal countDistance(Vector *p1, Vector *p2)
 /**
   * Constructor of this class.
   */
-RouteDialog::RouteDialog(QWidget *parent) :
+//RouteDialog::RouteDialog(QWidget *parent) :
+RouteDialog::RouteDialog(RouteSaveDialog *parent) :
     QDialog(parent), ui(new Ui::RouteDialog)
 {
     qDebug() << "__RouteDialog";
@@ -189,9 +191,13 @@ RouteDialog::RouteDialog(QWidget *parent) :
     // Clear labels
     ui->labelInfoToUser->setText("");
     ui->speedValueLabel->setText("");
+    ui->avgSpeedValueLabel->setText("");
 
     // Check login
     checkLogin();
+
+    // Set average speed
+    ui->avgSpeedValueLabel->setText(QString::number(parent->getAverageSpeed()) + " km/h");
 }
 
 /**
@@ -411,7 +417,7 @@ void RouteDialog::paintEvent(QPaintEvent *)
 
         // Show max velocity point by yellow circle
         painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
-        painter.drawEllipse( 650, 225, 10, 10);
+        painter.drawEllipse( ui->maxSpeedLabel->geometry().x()-15, ui->maxSpeedLabel->geometry().y()+15, 10, 10);
 
         QString jono;
         //jono = QString("%1 km/h").arg(maxv);
index dd453dd..2b9aa4c 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <QDialog>
 #include <helproutingdialog.h>
+class RouteSaveDialog;
 
 namespace Ui {
     class RouteDialog;
@@ -21,7 +22,8 @@ class RouteDialog : public QDialog {
     Q_OBJECT
 
 public:
-    RouteDialog(QWidget *parent = 0);
+    //RouteDialog(QWidget *parent = 0);
+    RouteDialog(RouteSaveDialog *parent = 0);
     ~RouteDialog();
     bool readRouteFromFile( QString &routeFile);
     int getLeft();
index e0d9c77..d7fb136 100644 (file)
@@ -16,7 +16,7 @@
   <widget class="QPushButton" name="newPushButton">
    <property name="geometry">
     <rect>
-     <x>670</x>
+     <x>710</x>
      <y>150</y>
      <width>90</width>
      <height>90</height>
@@ -39,7 +39,7 @@
   <widget class="QPushButton" name="sendPushButton">
    <property name="geometry">
     <rect>
-     <x>670</x>
+     <x>710</x>
      <y>50</y>
      <width>90</width>
      <height>90</height>
     </size>
    </property>
   </widget>
-  <widget class="QWidget" name="layoutWidget">
-   <property name="geometry">
-    <rect>
-     <x>650</x>
-     <y>250</y>
-     <width>141</width>
-     <height>81</height>
-    </rect>
-   </property>
-   <layout class="QVBoxLayout" name="verticalLayout">
-    <item>
-     <widget class="QLabel" name="maxSpeedLabel">
-      <property name="text">
-       <string>Max speed</string>
-      </property>
-      <property name="alignment">
-       <set>Qt::AlignCenter</set>
-      </property>
-     </widget>
-    </item>
-    <item>
-     <widget class="QLabel" name="speedValueLabel">
-      <property name="text">
-       <string>TextLabel</string>
-      </property>
-      <property name="alignment">
-       <set>Qt::AlignCenter</set>
-      </property>
-     </widget>
-    </item>
-   </layout>
-  </widget>
   <widget class="QLabel" name="labelInfoToUser">
    <property name="geometry">
     <rect>
     </size>
    </property>
   </widget>
+  <widget class="QLabel" name="maxSpeedLabel">
+   <property name="geometry">
+    <rect>
+     <x>560</x>
+     <y>10</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Max:</string>
+   </property>
+   <property name="alignment">
+    <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+   </property>
+  </widget>
+  <widget class="QLabel" name="speedValueLabel">
+   <property name="geometry">
+    <rect>
+     <x>560</x>
+     <y>40</y>
+     <width>110</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>speedValueLabel</string>
+   </property>
+   <property name="alignment">
+    <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+   </property>
+  </widget>
+  <widget class="QLabel" name="avgSpeedlabel">
+   <property name="geometry">
+    <rect>
+     <x>560</x>
+     <y>130</y>
+     <width>131</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Average:</string>
+   </property>
+   <property name="alignment">
+    <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+   </property>
+  </widget>
+  <widget class="QLabel" name="avgSpeedValueLabel">
+   <property name="geometry">
+    <rect>
+     <x>560</x>
+     <y>160</y>
+     <width>135</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>avgSpeedValueLabel</string>
+   </property>
+   <property name="alignment">
+    <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+   </property>
+  </widget>
  </widget>
  <resources>
   <include location="graphics.qrc"/>
index ba7100a..3153b21 100644 (file)
@@ -26,6 +26,12 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
     gpsData = NULL;
     helpRoutingDialog = NULL;
 
+    //Clear variables
+    averageSpeed = 0.0;
+    speed = 0.0;
+    allSpeeds = 0.0;
+    speedCount = 0;
+
     //Button settings
     buttonStatus = true;
     pixmapRouteStop = new QPixmap("Graphics/route_stop.png");
@@ -53,6 +59,7 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
     ui->labelRouteStatus->setVisible(0);
     ui->labelRoutePicture->setVisible(0);
     ui->labelGpsSpeed->setVisible(0); //GPS speed label
+    ui->labelGpsAvgSpeed->setVisible(0); //GPS average speed label
     ui->labelSignalStrength->setText(""); //GPS signal strength label
     timerRoutePicture = new QTimer();
     timerRoutePicture->setInterval(400);
@@ -110,6 +117,13 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked()
     if ( buttonStatus == true )//If start button clicked
     {
         qDebug() << "__start button clicked";
+
+        //Clear variables
+        averageSpeed = 0.0;
+        speed = 0.0;
+        allSpeeds = 0.0;
+        speedCount = 1;
+
         buttonStatus = false;
         ui->buttonRouteStartStop->setIcon(*iconRouteStop);
         location->startPollingGPS();
@@ -137,13 +151,14 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked()
         if (routeDialog->readRouteFromFile( routeFile ) == true)
         {
             if(!routeDialog)
-                routeDialog = new RouteDialog;
+                routeDialog = new RouteDialog(this);
             connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
             routeDialog->show();
         }
 
-        //GPS speed label
+        //Set GPS speed labels in visible
         ui->labelGpsSpeed->setVisible(0);
+        ui->labelGpsAvgSpeed->setVisible(0);
 
         //Stop route recording
         gpsData->stopRouteRecording();
@@ -192,7 +207,7 @@ void RouteSaveDialog::timerRoutePictureTimeout()
 }
 
 /**
-  *
+  * This slot function is called when GPS update location.
   */
 void RouteSaveDialog::gpsStatus()
 {
@@ -217,11 +232,22 @@ void RouteSaveDialog::gpsStatus()
             ui->labelRoutePicture->setVisible(1);
             timerRoutePicture->start();
 
-            //Set GPS speed.
-            gpsSpeed.sprintf("%.0f",location->getSpeed());
+            //Get GPS speed
+            speed = location->getSpeed();
+
+            //Set GPS speed
+            gpsSpeed.sprintf("%.0f", speed);
             ui->labelGpsSpeed->setText(gpsSpeed + " km/h");
             ui->labelGpsSpeed->setVisible(1);
 
+            //Set GPS average speed
+            allSpeeds += speed;
+            averageSpeed = allSpeeds/speedCount;
+            gpsSpeed.sprintf("%.0f",averageSpeed);
+            ui->labelGpsAvgSpeed->setText("Average: " + gpsSpeed + " km/h");
+            ui->labelGpsAvgSpeed->setVisible(1);
+            speedCount++;
+
             //Start route recording
             gpsData->startRouteRecording();
         }
@@ -239,8 +265,9 @@ void RouteSaveDialog::gpsStatus()
             ui->labelRoutePicture->setVisible(0);
             timerRoutePicture->stop();
 
-            //GPS speed label
+            //Set GPS speed labels in visible
             ui->labelGpsSpeed->setVisible(0);
+            ui->labelGpsAvgSpeed->setVisible(0);
         }
     }
     else //If stop button clicked
@@ -257,8 +284,9 @@ void RouteSaveDialog::gpsStatus()
         ui->labelRoutePicture->setVisible(0);
         timerRoutePicture->stop();
 
-        //GPS speed label
+        //Set GPS speed labels in visible
         ui->labelGpsSpeed->setVisible(0);
+        ui->labelGpsAvgSpeed->setVisible(0);
     }
 }
 
@@ -295,3 +323,12 @@ void RouteSaveDialog::killHelpDialog()
         helpRoutingDialog = NULL;
     }
 }
+
+/**
+  * This function return speed average.
+  * @return double average speed
+  */
+double RouteSaveDialog::getAverageSpeed()
+{
+    return averageSpeed;
+}
index 186cbf8..1dda5ff 100644 (file)
@@ -30,6 +30,7 @@ public:
     ~RouteSaveDialog();
     RouteDialog *routeDialog;
     HelpRoutingDialog *helpRoutingDialog;
+    double getAverageSpeed();
 
 protected:
     void changeEvent(QEvent *e);
@@ -46,6 +47,10 @@ private:
     QIcon *iconRouteStop;
     QIcon *iconRouteStart;
     bool buttonStatus;
+    double averageSpeed;
+    double speed;
+    double allSpeeds;
+    int speedCount;
 
 private slots:
     void on_pushButtonInfo_clicked();
index 4638a5f..7c4ccbd 100644 (file)
    <property name="geometry">
     <rect>
      <x>550</x>
-     <y>120</y>
+     <y>10</y>
      <width>151</width>
      <height>51</height>
     </rect>
     </size>
    </property>
   </widget>
+  <widget class="QLabel" name="labelGpsAvgSpeed">
+   <property name="geometry">
+    <rect>
+     <x>540</x>
+     <y>100</y>
+     <width>241</width>
+     <height>91</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <pointsize>20</pointsize>
+    </font>
+   </property>
+   <property name="text">
+    <string>GPS avg speed</string>
+   </property>
+   <property name="alignment">
+    <set>Qt::AlignCenter</set>
+   </property>
+  </widget>
  </widget>
  <resources>
   <include location="graphics.qrc"/>