+
+/**
+ * This slot function is called when route picture timer timeout(400ms).
+ */
+void RouteSaveDialog::timerRoutePictureTimeout()
+{
+ //If route picture visible.
+ if (ui->labelRoutePicture->isVisible() == 1)
+ {
+ ui->labelRouteStatus->setVisible(0);
+ ui->labelRoutePicture->setVisible(0);
+ }
+ else
+ {
+ ui->labelRouteStatus->setVisible(1);
+ ui->labelRoutePicture->setVisible(1);
+ }
+ timerRoutePicture->start();
+}
+
+/**
+ * This slot function is called when GPS update location.
+ */
+void RouteSaveDialog::gpsStatus()
+{
+ //IF GPS start button clicked
+ if (buttonStatus == false)
+ {
+ //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");
+ ui->labelRouteSatelliteStatus->setVisible(1);
+ ui->labelRouteSatellitePicture->setVisible(1);
+ timerSatellitePicture->stop();
+
+ //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();
+
+ //Get GPS speed
+ speed = location->getSpeed();
+
+ //Get GPS track means direction
+ direction = gpsData->getDirection();
+ repaint();
+
+ //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("Avg: " + 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();
+ }
+ 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();
+
+ //Route picture and label
+ ui->labelRouteStatus->setVisible(0);
+ ui->labelRoutePicture->setVisible(0);
+ timerRoutePicture->stop();
+
+ //Set GPS speed labels in visible
+ ui->labelGpsSpeed->setVisible(0);
+ ui->labelGpsAvgSpeed->setVisible(0);
+
+ //GPS distance label
+ ui->labelDistance->setVisible(0);
+ }
+ }
+ 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();
+
+ //Route picture and label
+ ui->labelRouteStatus->setVisible(0);
+ ui->labelRoutePicture->setVisible(0);
+ timerRoutePicture->stop();
+
+ //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(QString s,int i)
+{
+ emit sendroute(s,i); //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 slot function called when ever route dialog rejected.
+ */
+void RouteSaveDialog::killRouteDialog()
+{
+ if(routeDialog)
+ {
+ qDebug() << "__Route save kill: routeDialog";
+ delete routeDialog;
+ routeDialog = NULL;
+ }
+ if(calibrateDialog)
+ {
+ qDebug() << "__Route save kill: calibrateDialog";
+ delete calibrateDialog;
+ calibrateDialog = 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;
+}
+
+/**
+ * This function
+ */
+void RouteSaveDialog::setProgressbar(int i)
+{
+ qDebug() << "__setProgressbar " ;
+ qDebug() << i;
+ calibrateDialog->setProgressValue(i);
+ progressbarIteration++;
+}
+
+/**
+ * This slot function called when ever load route button clicked.
+ */
+void RouteSaveDialog::on_buttonLoadRoute_clicked()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open route"), QDir::currentPath());
+ qDebug() << "__Opening: " + fileName;
+ openRouteDialog(fileName);
+}
+
+/**
+ * This function open route.
+ * @param QString file name
+ */
+void RouteSaveDialog::openRouteDialog(QString fileName)
+{
+ // Progress bar
+ if(!calibrateDialog)
+ {
+ calibrateDialog = new CalibrateDialog();
+ }
+
+ progressbarPoints = 100;
+ progressbarIteration = 0;
+ calibrateDialog->resetProgressValue();
+ calibrateDialog->setMaxValue( progressbarPoints );
+ calibrateDialog->setTitle("Calculating route...");
+ calibrateDialog->show();
+
+ if(!routeDialog)
+ {
+ routeDialog = new RouteDialog(this);
+ }
+
+ connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
+ connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
+ connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog()));
+
+ if (routeDialog->readRouteFromFile( fileName ) == true)
+ {
+ calibrateDialog->close();
+ routeDialog->show();
+ }
+ else
+ {
+ calibrateDialog->close();
+ }
+}