Route and Results buttons updated.
[speedfreak] / Client / routesavedialog.cpp
index 9f81e91..6d355e6 100644 (file)
@@ -8,31 +8,43 @@
 
 #include "routesavedialog.h"
 #include "ui_routesavedialog.h"
+#include <QDebug>
 
 /**
   *Constructor of this class.
   *@param QWidget pointer to parent object. By default the value is NULL.
   */
 RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::RouteSaveDialog)
-{
+    QDialog(parent), ui(new Ui::RouteSaveDialog){
+
+    qDebug() << "__RouteSaveDialog";
     ui->setupUi(this);
     this->setWindowTitle("Tracking");
 
-    routeDialog = new RouteDialog;
+    routeDialog = NULL;
+    location = NULL;
+    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");
-    pixmapRoutePlay = new QPixmap("Graphics/route_play.png");
+    pixmapRouteStart = new QPixmap("Graphics/route_start.png");
     iconRouteStop = new QIcon(*pixmapRouteStop);
-    iconRoutePlay = new QIcon(*pixmapRoutePlay);
+    iconRouteStart = new QIcon(*pixmapRouteStart);
     QSize iconSize(125, 125);
     ui->buttonRouteStartStop->setIconSize(iconSize);
-    ui->buttonRouteStartStop->setIcon(*iconRoutePlay);
+    ui->buttonRouteStartStop->setIcon(*iconRouteStart);
     ui->buttonRouteStartStop->setAutoFillBackground(true);
     ui->buttonRouteStartStop->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
+    ui->pushButtonInfo->setAutoFillBackground(true);
+    ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
 
     //Satellite picture and label
     ui->labelRouteSatelliteStatus->setVisible(0);
@@ -41,17 +53,19 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
     timerSatellitePicture = new QTimer();
     timerSatellitePicture->setInterval(400);
     connect(timerSatellitePicture, SIGNAL(timeout()),this, SLOT(timerSatellitePictureTimeout()));
+    ui->labelUserInfo->setText("Push start button");  //User info label
 
-    //Route picture and label
+    //Invisible or clear labels
     ui->labelRouteStatus->setVisible(0);
     ui->labelRoutePicture->setVisible(0);
+    ui->labelGpsSpeed->setVisible(0); //GPS speed label
+    ui->labelGpsAvgSpeed->setVisible(0); //GPS average speed label
+    ui->labelDistance->setVisible(0); //GPS distance label
+    ui->labelSignalStrength->setText(""); //GPS signal strength label
     timerRoutePicture = new QTimer();
     timerRoutePicture->setInterval(400);
     connect(timerRoutePicture, SIGNAL(timeout()),this, SLOT(timerRoutePictureTimeout()));
 
-    //GPS speed label
-    ui->labelGpsSpeed->setVisible(0);
-
     //GPS
     location = new Maemo5Location(this);
     gpsData = new GPSData(location);
@@ -63,18 +77,27 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
   */
 RouteSaveDialog::~RouteSaveDialog()
 {
-    delete ui;
+    qDebug() << "__~RouteSaveDialog";
+    if(ui)
+        delete ui;
+    if(gpsData)
+        delete gpsData;
+    if(location)
+        delete location;
+    if(routeDialog)
+        delete routeDialog;
+
     delete timerSatellitePicture;
     delete timerRoutePicture;
-    delete location;
-    delete gpsData;
-    delete routeDialog;
     delete pixmapRouteStop;
-    delete pixmapRoutePlay;
+    delete pixmapRouteStart;
     delete iconRouteStop;
-    delete iconRoutePlay;
+    delete iconRouteStart;
 }
 
+/**
+  *
+  */
 void RouteSaveDialog::changeEvent(QEvent *e)
 {
     QDialog::changeEvent(e);
@@ -92,18 +115,26 @@ void RouteSaveDialog::changeEvent(QEvent *e)
   */
 void RouteSaveDialog::on_buttonRouteStartStop_clicked()
 {
-    //If start button clicked
-    if ( buttonStatus == true )
+    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();
         gpsStatus();
     }
-    else
+    else //If stop button clicked
     {
+        qDebug() << "__stop button clicked";
         buttonStatus = true;
-        ui->buttonRouteStartStop->setIcon(*iconRoutePlay);
+        ui->buttonRouteStartStop->setIcon(*iconRouteStart);
 
         //Satellite picture and label
         ui->labelRouteSatelliteStatus->setText("Searching satellite");
@@ -116,13 +147,28 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked()
         ui->labelRoutePicture->setVisible(0);
         timerRoutePicture->stop();
         location->stopPollingGPS();
-        routeDialog->show();
 
-        //GPS speed label
+        QString routeFile = QString("routetemp.xml");
+        if (routeDialog->readRouteFromFile( routeFile ) == true)
+        {
+            if(!routeDialog)
+                routeDialog = new RouteDialog(this);
+            connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
+            routeDialog->show();
+        }
+
+        //Set GPS speed labels in visible
         ui->labelGpsSpeed->setVisible(0);
+        ui->labelGpsAvgSpeed->setVisible(0);
+
+        //GPS distance label
+        ui->labelDistance->setVisible(0);
 
         //Stop route recording
         gpsData->stopRouteRecording();
+
+        //User info label
+        ui->labelUserInfo->setText("Push start button");
     }
 }
 
@@ -164,13 +210,18 @@ void RouteSaveDialog::timerRoutePictureTimeout()
     timerRoutePicture->start();
 }
 
+/**
+  * This slot function is called when GPS update location.
+  */
 void RouteSaveDialog::gpsStatus()
 {
     //IF GPS start button clicked
     if (buttonStatus == false)
     {
-        //If GPS find 4 satellite.
-        if (location->getSatellitesInUse() >= 4)
+        //ui->labelSignalStrength->setText(QString::number(location->getSignalStrength()));    //Returns average signal strength of satellites which are in use.
+
+        //If GPS find 4 or more satellite and signal stregth is 30 or more.
+        if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
         {
             //Satellite picture and label
             ui->labelRouteSatelliteStatus->setText("GPS Ready");
@@ -180,24 +231,40 @@ void RouteSaveDialog::gpsStatus()
 
             //Route picture and label
             ui->labelRouteStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
+            ui->labelUserInfo->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
             ui->labelRouteStatus->setVisible(1);
             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++;
+
+            //Set distance traveled.
+            distanceString.sprintf("%.3f", gpsData->getDistanceTraveled());
+            ui->labelDistance->setText(distanceString + " km");
+            ui->labelDistance->setVisible(1);
+
             //Start route recording
             gpsData->startRouteRecording();
         }
-
-        //If GPS find less than 4 satellite.
-        else
+        else //If GPS find less than 4 satellite or signal strength is poor.
         {
             //Satellite picture and label
             ui->labelRouteSatelliteStatus->setText("Searching satellite");
+            ui->labelUserInfo->setText("Searching satellite");
             ui->labelRouteSatelliteStatus->setVisible(1);
             ui->labelRouteSatellitePicture->setVisible(1);
             timerSatellitePicture->start();
@@ -207,14 +274,19 @@ 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);
+
+            //GPS distance label
+            ui->labelDistance->setVisible(0);
         }
     }
-    else
+    else //If stop button clicked
     {
         //Satellite picture and label
         ui->labelRouteSatelliteStatus->setText("Searching satellite");
+        ui->labelUserInfo->setText("Push start button");
         ui->labelRouteSatelliteStatus->setVisible(0);
         ui->labelRouteSatellitePicture->setVisible(0);
         timerSatellitePicture->stop();
@@ -224,7 +296,63 @@ 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);
+
+        //GPS distance label
+        ui->labelDistance->setVisible(0);
+    }
+}
+
+/**
+  * This slot function is called when routeDialog emit sendroute (sendPushButton).
+  */
+void RouteSaveDialog::sendRoute()
+{
+    emit sendroute(); //Emit mainwindow clientSendRoute
+}
+
+/**
+  * This slot function called when ever info button clicked.
+  */
+void RouteSaveDialog::on_pushButtonInfo_clicked()
+{
+    if(!helpRoutingDialog)
+    {
+        helpRoutingDialog = new HelpRoutingDialog;
     }
+    connect(helpRoutingDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
+    helpRoutingDialog->show();
+}
+
+/**
+  * This slot function called when ever dialog rejected.
+  */
+void RouteSaveDialog::killHelpDialog()
+{
+    if(helpRoutingDialog)
+    {
+        qDebug() << "__Route save kill: helpRoutingDialog";
+        delete helpRoutingDialog;
+        helpRoutingDialog = NULL;
+    }
+}
+
+/**
+  * This function return speed average.
+  * @return double average speed
+  */
+double RouteSaveDialog::getAverageSpeed()
+{
+    return averageSpeed;
+}
+
+/**
+  * This function return distance traveled in QString.
+  * @return QString distance traveled
+  */
+QString RouteSaveDialog::getDistanceTraveled()
+{
+    return distanceString;
 }