Added routedialog to read route data from file.
[speedfreak] / Client / carmainwindow.cpp
1 /*
2  * CarMainWindow main class
3  *
4  * @author     Toni Jussila <toni.jussila@fudeco.com>
5  * @author     Janne Änäkkälä <janne.anakkala@fudeco.com>
6  * @author     Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
7  * @author     Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
8  * @author     Rikhard Kuutti <rikhard.kuutti@fudeco.com>
9  * @author     Kai Rasilainen <kai.rasilainen@fudeco.com>
10  * @copyright  (c) 2010 Speed Freak team
11  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
12  */
13
14 #include "carmainwindow.h"
15 #include "math.h"
16
17 #define kAccelerometerSampleRate    50
18 #define kFilteringFactor            0.2
19 #define kSecondsInHour              3600
20
21 /**
22   *Constructor of this class.
23   *@param QWidget pointer to parent object. By default the value is NULL.
24   */
25 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
26 {
27     ui->setupUi(this);
28     ui->tabWidget->setCurrentWidget(this->ui->StartTab);
29     result = new ResultDialog();
30     //measure = new MeasureDialog();
31     welcomeDialog = new WelcomeDialog();
32     welcomeDialog->show();
33
34     initComboBoxStartTabUnits();
35     initListViewStartTabAccelerationCategories();
36
37     myLogin = new LoginWindow(this);
38     myCategorylist = new CategoryList();
39     myHttpClient = new HttpClient(this);
40     myRegistration = new Registration(this);
41     connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
42     connect(myLogin,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
43     connect(myHttpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
44     connect(myHttpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
45     myRoute = new RouteDialog( this);
46
47     //GPS
48     location = new Maemo5Location(this);
49     gpsData = new GPSData(location);
50     connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
51     gpsTime = new QDateTime();
52
53     this->time = 0;
54     this->speed = 0;
55     counterForSaveResults = 0;
56     timer = new QTimer();
57
58     // Accelerometer
59     accelerometer = new Accelerometer();
60
61     reverseAccelerationFlag = false;
62     vehicleStartedMoving = false;
63     isNewRun = true;
64     isSetup = false;
65     stopTime = 0;
66     accelerationStartThreshold = 0.02;
67
68     accelerometerTimer = new QTimer(this);
69 //tkk  connect(accelerometerTimer, SIGNAL(timeout()), this, SLOT(readAccelerometerData()));
70     //accelerometerTimer->start(kAccelerometerSampleRate);
71
72     // Calculate
73     calculate = new Calculate();
74     connect(calculate, SIGNAL(checkPointReached()), this, SLOT(handleCheckPoint()));
75
76     resetAccelerometerMeasurements();
77
78     measures = new Measures();
79     this->initializeMeasures();
80
81     this->timer->setInterval(300);
82
83     connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
84     connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName()));
85
86     ui->labelMeasureTabResult->hide();
87     ui->pushButtonShowResultDialog->setEnabled(false);
88
89     this->setWindowTitle("Speed Freak");
90
91 }
92
93 /**
94   *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
95   */
96 CarMainWindow::~CarMainWindow()
97 {
98     delete ui;
99     ui = NULL;
100     //delete result;
101     //delete measure;
102     delete myCategorylist;
103     myCategorylist = NULL;
104     delete welcomeDialog;
105     welcomeDialog = NULL;
106     delete myRoute;
107     myRoute = NULL;
108     delete gpsData;
109     gpsData = NULL;
110     delete gpsTime;
111     gpsTime = NULL;
112 }
113
114 /**
115   *This function is used to .
116   *@param
117   */
118 void CarMainWindow::changeEvent(QEvent *e)
119 {
120     QMainWindow::changeEvent(e);
121     switch (e->type()) {
122     case QEvent::LanguageChange:
123         ui->retranslateUi(this);
124         break;
125     default:
126         break;
127     }
128 }
129
130 /**
131   *This slot function is called when ever list view is update. Start-tab view.
132   */
133 void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelIndex index)
134 {
135     QString str = index.data().toString();
136     QStringList list = str.split("-");
137     QStringList list2 = list[1].split(" ");
138
139     ui->lineEditStartTabMin->setText(list[0]);
140     ui->lineEditStartTabMax->setText(list2[0]);
141     updateComboBoxStartTabUnits(list2[1]);
142 }
143
144 /**
145   *This slot function is called when ever auto start button clicked. Start-tab view.
146   *@todo Check setDiagramGapStem(100) <- (choiceInt == 2)
147   */
148 void CarMainWindow::on_autoStartButton_clicked()
149 {
150     initializeMeasures();
151     resetAccelerometerMeasurements();
152     ui->pushButtonSendResult->setEnabled(false);
153     ui->pushButtonShowResultDialog->setEnabled(false);
154     choice = ui->listViewStartTabAccelerationCategories->currentIndex();
155     choiceInt = choice.row();
156     qDebug() << "choiceInt" << choiceInt << " " << catList.at(choiceInt);
157     if (choiceInt == 0)
158     {
159         ui->labelMeasureTabHeader->setText("Accelerate to 40 km/h");
160         result->setDiagramGapStem(75);
161     }
162     else if (choiceInt == 1)
163     {
164         ui->labelMeasureTabHeader->setText("Accelerate to 100 km/h");
165         result->setDiagramGapStem(30);
166     }   
167     else if (choiceInt == 2)
168     {
169         ui->labelMeasureTabHeader->setText("Accelerate to 10 km/h");
170         result->setDiagramGapStem(100);
171     }
172     else
173     {
174         ui->labelMeasureTabHeader->setText("Accelerate to 80 km/h");
175         result->setDiagramGapStem(37.5);
176     }
177     ui->labelMeasureTabResult->setText("");
178
179     this->accelerometerTimer->start(kAccelerometerSampleRate);
180     this->timer->start();
181     this->time = 0;
182     this->speed = 0;
183     ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
184 }
185
186 /**
187   *This slot function is called when ever list view is update. Start-tab view.
188   *@param QString unit.
189   */
190 void CarMainWindow::updateComboBoxStartTabUnits(QString unit)
191 {
192     ui->comboBoxStartTabUnits->setCurrentIndex(ui->comboBoxStartTabUnits->findText(unit, Qt::MatchExactly));
193 }
194
195 /**
196   *This function is used to init unit combobox. Start-tab view.
197   */
198 void CarMainWindow::initComboBoxStartTabUnits()
199 {
200     units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd";
201     ui->comboBoxStartTabUnits->addItems(units);
202 }
203
204 /**
205   *This function is used to set items to unit combobox. Start-tab view.
206   *@param QStringlist units
207   */
208 void CarMainWindow::setComboBoxStartTabUnits(QStringList units)
209 {
210     ui->comboBoxStartTabUnits->addItems(units);
211 }
212
213 /**
214   *This function is used to init listViewStartTabAccelerationCategories. Start-tab view.
215   *@todo During development categories index values that are used for measuring are hardcoded
216   *@todo and accelerationCategoriesStartTab and catList are used instead of using
217   *@todo CategoryList::categoryList and CategoryList::cats.
218   */
219 void CarMainWindow::initListViewStartTabAccelerationCategories()
220 {
221     //Connect the user`s choice fron GUI to a correct variable name
222     catList.insert(0,"acceleration-0-40");
223     catList.insert(1,"acceleration-0-100");
224     catList.insert(2,"acceleration-0-10");
225
226     accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h" << "0-10 km/h"; //<< "0-1/4 Mile" << "0-1/8 Mile" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
227     QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
228     ui->listViewStartTabAccelerationCategories->setModel(model);
229 }
230
231 /**
232   *This function is used to set items to listViewStartTabAccelerationCategories. Start-tab view.
233   *@param QStringlist accelerationCategoriesStartTab
234   */
235 void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accelerationCategoriesStartTab)
236 {
237     QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
238     ui->listViewStartTabAccelerationCategories->setModel(model);
239 }
240
241 /**
242   *This function is used to set items to category combobox. Top-tab view.
243   *@param
244   */
245 void CarMainWindow::setCategoryCompoBox()
246 {
247     qDebug() << "_setCategoryCompoBox";
248     ui->comboBoxTopCategory->addItems(myHttpClient->myXmlreader->myCategoryList->getCategoryList());
249 }
250
251 /**
252   *This function prcesses UI updating after a new top10List has been received.
253   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
254   */
255 void CarMainWindow::showTop10()
256 {
257     int limitNr = 5;
258     setListViewTopList(recentCategory, limitNr);
259 }
260
261 /**
262   *This function is used to set items to labelTopList. Top-tab view.
263   *@param Category
264   *@param Size, number of results.
265   */
266 void CarMainWindow::setListViewTopList(QString category, int size)
267 {
268     qDebug() << "_setListViewTopList";
269     QString topList;
270     topList.append(myHttpClient->myXmlreader->myCategoryList->getTopList(category, size));
271     ui->labelTopList->setText(topList);
272 }
273
274 /**
275   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
276   */
277 void CarMainWindow::openResultView()
278 {
279
280 }
281
282 /**
283   *This slot function is called when registrate button is clicked.
284   */
285 void CarMainWindow::on_registratePushButton_clicked()
286 {
287     myRegistration->show();
288 }
289
290 /**
291   *This slot function is called when ever refresh button clicked. Top-tab view.
292   */
293 void CarMainWindow::on_buttonTopRefresh_clicked()
294 {
295     myHttpClient->requestCategories();
296 }
297
298 /**
299   *This slot function is called when ever category combobox current index changed. Top-tab view.
300   *@param QString category.
301   *@todo Check where limitNr is taken, fixed or user input, see showTop10.
302   */
303 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
304 {
305     qDebug() << "_on_comboBoxTopCategory_currentIndexChanged: " << category;
306     recentCategory = category;      //for showTop10()
307     int limitNr = 5;
308     QString limit = QString::number(limitNr);
309     myHttpClient->requestTopList(category, limit);
310 }
311
312 /**
313   *This slot function is called when set/change user button is clicked.
314   */
315 void CarMainWindow::on_setUserPushButton_clicked()
316 {
317     myLogin->show();
318 }
319
320 /**
321   *@brief Just for development, for the real button is not shown until
322   *measurin started and there are results.
323   *@todo Implement with real code and yet leave sendXml in the bottom in use.
324   */
325 void CarMainWindow::on_manualStartButton_clicked()
326 {
327
328 }
329
330 /**
331   * This slot function is called when timer gives timeout signal. Checks current speed
332   * and stores times in measure class.
333   */
334 void CarMainWindow::after_timeout()
335 {
336     QString timeString, speedString;
337     //time++;
338     //speed = speed +10;
339     timeString.setNum(time);
340     speedString.setNum(speed);
341     ui->labelMeasureTabTime->setText(timeString);
342     ui->labelMeasureTabSpeed->setText(speedString);
343
344     //handleCheckPoint(time, speed);
345 }
346
347 /**
348   * Initializes measures class's member variables.
349   */
350 void CarMainWindow::initializeMeasures()
351 {
352     measures->setTime10kmh(0);
353     measures->setTime20kmh(0);
354     measures->setTime30kmh(0);
355     measures->setTime40kmh(0);
356     measures->setTime50kmh(0);
357     measures->setTime60kmh(0);
358     measures->setTime70kmh(0);
359     measures->setTime80kmh(0);
360     measures->setTime90kmh(0);
361     measures->setTime100kmh(0);
362 }
363
364 /**
365   * This slot function is called when Abort button is clicked.
366   */
367 void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
368 {
369     ui->pushButtonSendResult->setEnabled(false);
370     ui->pushButtonShowResultDialog->setEnabled(false);
371     ui->labelMeasureTabResult->hide();
372     ui->labelMeasureTabTime->setText("");
373     ui->labelMeasureTabSpeed->setText("");
374     measures->setTime10kmh(0);
375     measures->setTime20kmh(0);
376     measures->setTime30kmh(0);
377     measures->setTime40kmh(0);
378     measures->setTime50kmh(0);
379     measures->setTime60kmh(0);
380     measures->setTime70kmh(0);
381     measures->setTime80kmh(0);
382     measures->setTime90kmh(0);
383     measures->setTime100kmh(0);
384     this->accelerometerTimer->stop();
385     this->timer->stop();
386     this->time = 0;
387     this->speed = 0;
388     ui->tabWidget->setCurrentWidget(this->ui->StartTab);
389     //this->close();
390 }
391
392 /**
393   *This slot function is called when pushButtonSendResult is clicked.
394   *@todo Use real category value.
395   */
396 void CarMainWindow::on_pushButtonSendResult_clicked()
397 {
398     //Pick up relevant category name and pass it to the server
399     myHttpClient->sendResultXml(catList.at(choiceInt));
400     ui->pushButtonSendResult->setEnabled(false);
401 }
402
403 void CarMainWindow::updateUserName()
404 {
405     QString newUserName;
406
407     newUserName = myLogin->getUserName();
408     ui->userNameLabel->setText( "User: " + newUserName);
409
410     if (newUserName.length())
411     {
412        ui->setUserPushButton->setText( "Change User");
413        this->setWindowTitle("Speed Freak - " + newUserName);
414     }
415     else
416     {
417         ui->setUserPushButton->setText( "Set User");
418         this->setWindowTitle("Speed Freak");
419     }
420 }
421
422 void CarMainWindow::regUserToServer()
423 {
424     myHttpClient->requestRegistration();
425 }
426
427
428 void CarMainWindow::on_drawRoutePushButton_clicked()
429 {
430     QString routeFile = QString("route.txt");
431     if (myRoute->readRouteFromFile( routeFile) == true)
432     {
433         myRoute->show();
434     }
435 }
436
437 /**
438   * Opens result dialog when show result button is clicked.
439   * Sends measures as parameter to the resultdialogs saveMeasuresToArray-function.
440   */
441 void CarMainWindow::on_pushButtonShowResultDialog_clicked()
442 {
443     result->saveMeasuresToArray(measures);
444     this->result->show();
445 }
446
447 void CarMainWindow::userLogin()
448 {
449     myHttpClient->checkLogin();
450 }
451
452 /**
453   * Resets Accelerometer measurement variables
454   */
455 void CarMainWindow::resetAccelerometerMeasurements()
456 {
457     currentAcceleration = 0;
458     currentAccelerationString = "";
459     currentSpeed = "";
460     currentTime = 0;
461     distanceTraveled = "";
462     firstAcceleration = 0;
463     //horsepower = null;
464     isNewRun = true;
465     //lastScreenUpdateInSeconds = 0;
466     previousTime = 0;
467     reverseAccelerationFlag = false;
468     stopWatch.setHMS(0, 0, 0, 0);
469     //accelerometer->stop();
470     totalTime = "";
471     vehicleStartedMoving = false;
472     calculate->reset();
473 }
474
475 /**
476   * This function is called to handle checkpoints
477   *@param totalTime total time elapsed since starting measurements
478   *@param currentSpeed current speed of the device
479   */
480 void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
481 {
482     switch (counterForSaveResults)
483     {
484     case 0:
485         measures->setTime10kmh(totalTime);
486         break;
487
488     case 1:
489         measures->setTime20kmh(totalTime);
490         break;
491
492     case 2:
493         measures->setTime30kmh(totalTime);
494         break;
495
496     case 3:
497         measures->setTime40kmh(totalTime);
498         break;
499
500     case 4:
501         measures->setTime50kmh(totalTime);
502         break;
503
504     case 5:
505         measures->setTime60kmh(totalTime);
506         break;
507
508     case 6:
509         measures->setTime70kmh(totalTime);
510         break;
511
512     case 7:
513         measures->setTime80kmh(totalTime);
514         break;
515
516     case 8:
517         measures->setTime90kmh(totalTime);
518         break;
519
520     case 9:
521         measures->setTime100kmh(totalTime);
522         break;
523
524     default:
525         break;
526     }
527     counterForSaveResults++;
528
529     if (choiceInt == 0 && measures->getTime40kmh() != 0)
530     {
531         setTimeAxisGapAndShowResult(measures->getTime40kmh());
532         this->timer->stop();
533         this->accelerometerTimer->stop();
534         this->time = 0;
535         this->speed = 0;
536         counterForSaveResults = 0;
537     }
538     else if (choiceInt == 1 && measures->getTime100kmh() != 0)
539     {
540         setTimeAxisGapAndShowResult(measures->getTime100kmh());
541         this->timer->stop();
542         this->accelerometerTimer->stop();
543         this->time = 0;
544         this->speed = 0;
545         counterForSaveResults = 0;
546     }
547     else if (choiceInt == 2 && measures->getTime10kmh() != 0)
548     {
549         setTimeAxisGapAndShowResult(measures->getTime10kmh());
550         this->timer->stop();
551         this->accelerometerTimer->stop();
552         this->time = 0;
553         this->speed = 0;
554         counterForSaveResults = 0;
555     }
556     else if (choiceInt != 1 && choiceInt != 0 && measures->getTime80kmh() != 0)
557     {
558         setTimeAxisGapAndShowResult(measures->getTime80kmh());
559         this->timer->stop();
560         this->accelerometerTimer->stop();
561         this->time = 0;
562         this->speed = 0;
563         counterForSaveResults = 0;
564     }
565     else
566     {
567         qDebug() << "something wrong in handleCheckPoint()";
568     }
569 }
570
571 /**
572   *This function is called to read (and process) data from the accelerometer
573   */
574 void CarMainWindow::readAccelerometerData()
575 {
576     QString s;
577     double changeInAcceleration = 0;
578     qreal x, y, z;
579
580     accelerometer->getAcceleration(x, y, z);
581     accelerometer->smoothData(x, y, z);
582
583     // Apply calibration
584     x -= accelerometer->getCalibrationX();
585     y -= accelerometer->getCalibrationY();
586     z -= accelerometer->getCalibrationZ();
587
588     QString str = QString("acc x: " + QString::number(x) + "\n" +
589                           "acc y: " + QString::number(y) + "\n" +
590                           "acc z: " + QString::number(z) + "\n");
591
592     if (!vehicleStartedMoving)
593     {
594         if (isNewRun)
595         {
596             firstAcceleration = sqrt(x*x + y*y + z*z);
597             //firstAcceleration = y; // first read
598             isNewRun = false;
599         }
600     }
601
602     currentAcceleration = sqrt(x*x + y*y + z*z);
603     changeInAcceleration = (currentAcceleration - firstAcceleration); // firstAcceleration only gets set once
604
605     if (((fabs(changeInAcceleration) <= accelerationStartThreshold)
606                 && !vehicleStartedMoving))
607     {
608         return;
609     }
610
611     if (reverseAccelerationFlag)
612     {
613         // will be false until after 1st calculation
614         if ((changeInAcceleration <= 0))
615         {
616             // actually increasing here...
617             changeInAcceleration = fabs(changeInAcceleration);
618         }
619         else
620         {
621             // actually decreasing here...
622             changeInAcceleration = (changeInAcceleration * -1);
623         }
624     }
625     if (!vehicleStartedMoving)
626     {
627         if ((changeInAcceleration < 0))
628         {
629             // we started to move backwards first time through
630             reverseAccelerationFlag = true;
631             changeInAcceleration = fabs(changeInAcceleration);
632         }
633         vehicleStartedMoving = true;
634
635         stopWatch.setHMS(0, 0, 0, 0);
636         stopWatch.start();
637     }
638     //  keep the following line as close to the SetKinematicsProperties method as possible
639     currentTime = stopWatch.elapsed();
640     calculate->calculateParameters(changeInAcceleration, (currentTime - previousTime)/1000);
641     previousTime = currentTime;
642
643     s.sprintf("%.2f", changeInAcceleration);
644     currentAccelerationString = s;
645
646     speed = 0.0;
647     speed = calculate->getCurrentSpeed();
648     speed = ((speed*1000)/kSecondsInHour);
649     s.sprintf("%.2f", speed);
650     currentSpeed = s;
651
652     s.sprintf("%.2f", calculate->getDistanceTraveled());
653     distanceTraveled = s;
654
655     // TODO
656     //distanceTraveled;
657     //horsepower;
658
659     time = calculate->getTotalTime();
660
661     s.sprintf("%.2f", time);
662     totalTime = s;
663
664     str.append("ca: " + currentAccelerationString + " G\n" );
665     str.append("cspeed: " + currentSpeed + " km/h \n" );
666     str.append("dist: " + distanceTraveled + " m \n" );
667     str.append("time: " + totalTime + " s \n" );
668
669     if ((stopTime > 0) && (previousTime >= stopTime))
670     {
671         // we want to end at a stopping point that the user chose
672         // output results
673         resetAccelerometerMeasurements();
674     }
675 }
676
677 /**
678   *This function is used to calibrate accelerometer
679   */
680 void CarMainWindow::calibrateAccelerometer()
681 {
682     resetAccelerometerMeasurements();
683     accelerometer->calibrate();
684 }
685
686 /**
687   *This slot function is called when GPS on checkbox state changed.  Route-tab view.
688   *@param int GPSState
689   */
690 void CarMainWindow::on_gpsOnCheckBox_stateChanged(int GPSState)
691 {
692     if (GPSState == 0)
693     {
694         ui->labelRouteTabGPSStatus->setText("GPS off");//testing
695         location->stopPollingGPS();
696     }
697     else
698     {
699         ui->labelRouteTabGPSStatus->setText("GPS on");//testing
700         location->startPollingGPS();
701     }
702 }
703
704 /**
705   *This slot function is called when GPS status changed.  Route-tab view.
706   */
707 void CarMainWindow::gpsStatus()
708 {
709     if (ui->gpsOnCheckBox->isChecked())
710     {
711         if (location->getSatellitesInUse() >= 4)
712         {
713             //Set status
714             //ui->labelRouteTabGPSStatus->setText("GPS ready");
715             ui->labelRouteTabGPSStatus->setText(QString::number(gpsData->roundCounter));
716
717             //Set time
718             gpsTime->setTime_t(location->getTime());
719             ui->labelRouteTabGPSTime->setText(gpsTime->toString());
720
721             //Set latitude & longitude
722             ui->labelRouteTabLatitude->setText("Lat: " + QString::number(location->getLatitude()));
723             ui->labelRouteTabLongitude->setText("Lon: " + QString::number(location->getLongitude()));
724         }
725
726         else
727         {
728             ui->labelRouteTabGPSStatus->setText("Waiting for GPS");
729         }
730     }
731     ui->labelRouteTabSpeed->setText(QString::number(location->getSpeed()));
732 }
733
734 void CarMainWindow::on_startRecPushButton_clicked()
735 {
736     ui->labelRouteTabRecStatus->setText("Recording started");
737     gpsData->startRouteRecording(ui->labelRouteTabGPSTime->text());
738 }
739
740 void CarMainWindow::on_stopRecPushButton_clicked()
741 {
742     ui->labelRouteTabRecStatus->setText("Recording stopped");
743     gpsData->stopRouteRecording(ui->labelRouteTabGPSTime->text());
744 }
745
746 /**
747   *Sets time axis right way in result dialog and shows target speed result.
748   *@param double pTime is the target speed result time which is shown to the user.
749   */
750 void CarMainWindow::setTimeAxisGapAndShowResult(double pTime)
751 {
752     ui->pushButtonShowResultDialog->setEnabled(true);
753     ui->pushButtonSendResult->setEnabled(true);
754     QString timeInteger;
755     timeInteger.setNum(pTime);
756     ui->labelMeasureTabResult->show();
757     ui->labelMeasureTabResult->setText(timeInteger);
758
759     if (floor(pTime) <= 5)
760     {
761         result->setDiagramGapHorizontal(80);
762     }
763
764     else if (floor(pTime) <= 10)
765     {
766         result->setDiagramGapHorizontal(40);
767     }
768
769     else
770     {
771         result->setDiagramGapHorizontal(20);
772     }
773 }