Merge branch 'master' of https://vcs.maemo.org/git/gpssportsniffer
[gpssportsniffer] / activityinfo.cpp
1 /****************************************************************************
2 **
3 **  Copyright (C) 2011  Tito Eritja Real <jtitoo@gmail.com>
4 **
5 **  This program is free software: you can redistribute it and/or modify
6 **  it under the terms of the GNU General Public License as published by
7 **  the Free Software Foundation, either version 3 of the License, or
8 **  (at your option) any later version.
9 **
10 **  This program is distributed in the hope that it will be useful,
11 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 **  GNU General Public License for more details.
14 **
15 **  You should have received a copy of the GNU General Public License
16 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 **
18 ****************************************************************************/
19
20 #include "activityinfo.h"
21 #include "ui_activityinfo.h"
22 #include "track.h"
23
24 #include "windowMap.h"
25 #include "settings.h"
26
27 ActivityInfo::ActivityInfo(WindowMap *parent, Settings* settings, Log *log):
28     QDialog(parent), log(log),windowMap(parent),settings(settings),
29     ui(new Ui::ActivityInfo)
30 {
31     ui->setupUi(this);
32
33     connect(ui->buttonBox, SIGNAL(accepted()), SLOT(accept()));
34
35 }
36
37
38
39
40 ActivityInfo::~ActivityInfo()
41 {
42     delete ui;
43 }
44
45 void ActivityInfo::accept(){
46
47     this->hide();
48 }
49
50
51 void ActivityInfo::getSummary(Track* trk){
52
53     // this is for yesterday... so it has to be
54     // corrected some day!
55
56         if(trk->getNumPoints()<=0)
57         return;
58
59
60     setWindowTitle(nameFromFile(trk->getFileName()));
61     //ui->windowTitle(trk->getName());
62
63     ui->startTimeValue->setText(trk->getStartTime().toString(CLEAN_DATE_FORMAT));
64
65     double duration=trk->getDuration();
66     double duration_2=trk->getStartTime().secsTo(trk->getEndTime());
67
68     ui->timeValue->setText(stringDateFromSeconds(duration));
69     ui->distanceValue->setText(QString::number(trk->getDistance(),'f',2).append(" m"));
70     ui->elevationValue->setText(QString::number(trk->getElevationGain(),'f',2).append(" m"));
71
72     ui->avgSpeedValue->setText(QString::number(trk->getAvgSpeed(),'f',2).append(" km/h"));
73     ui->maxSpeedValue->setText(QString::number(trk->getMaxSpeed(),'f',2).append(" km/h"));
74     ui->avgPaceLabel->setText(QString::number(trk->getAvgPace(),'f',2).append(" min/km"));
75     ui->bestPaceValue->setText(QString::number(trk->getBestPace(),'f',2).append(" min/km"));
76
77     ui->elevationGainValue->setText(QString::number(trk->getElevationGain(),'f',2).append(" m"));
78     ui->elevationLossValue->setText(QString::number(trk->getElevationLoss(),'f',2).append(" m"));
79     ui->minElevationValue->setText(QString::number(trk->getMinElevation(),'f',2).append(" m"));
80     ui->maxElevationValue->setText(QString::number(trk->getMaxElevation(),'f',2).append(" m"));
81     ui->lastElevationValue->setText(QString::number(trk->getLastElevation(),'f',2).append(" m"));
82
83 }
84
85 void ActivityInfo::updateSummary(){
86
87     log->debug("updating summary");
88
89     if(windowMap->getMode()==Mode_NewActivityMode){
90         log->debug("updating with track");
91         getSummary(windowMap->getTrack());
92     }else if(windowMap->getMode()==Mode_LoadTracksWindow){
93         log->debug("updating with trackToSniff");
94         log->debug(QString("track to summary:%1").arg(windowMap->getTrackToSniff()->toSumString()));
95         getSummary(windowMap->getTrackToSniff());
96
97     }
98
99 }