mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Added distance & time info
This commit is contained in:
24
src/gpx.cpp
24
src/gpx.cpp
@ -29,16 +29,15 @@ bool GPX::loadFile(const QString &fileName)
|
||||
|
||||
void GPX::elevationGraph(QVector<QPointF> &graph) const
|
||||
{
|
||||
qreal dist = 0, ds, dh, acc;
|
||||
qreal dist = 0, dh, acc;
|
||||
|
||||
if (!_data.size())
|
||||
return;
|
||||
|
||||
graph.append(QPointF(0, _data.at(0).elevation));
|
||||
for (int i = 1; i < _data.size(); i++) {
|
||||
ds = llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
||||
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
||||
dh = _data.at(i).elevation;
|
||||
dist += ds;
|
||||
acc = (i == 1) ? dh : (ALPHA_E * dh) + (1.0 - ALPHA_E) * acc;
|
||||
graph.append(QPointF(dist, acc));
|
||||
}
|
||||
@ -73,3 +72,22 @@ void GPX::track(QVector<QPointF> &track) const
|
||||
track.append(p);
|
||||
}
|
||||
}
|
||||
|
||||
qreal GPX::distance()
|
||||
{
|
||||
qreal dist = 0;
|
||||
|
||||
for (int i = 1; i < _data.size(); i++)
|
||||
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
qreal GPX::time()
|
||||
{
|
||||
if (_data.size() < 2)
|
||||
return 0;
|
||||
|
||||
return (_data.at(0).timestamp.msecsTo(_data.at(_data.size() - 1).timestamp)
|
||||
/ 1000.0);
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ public:
|
||||
void elevationGraph(QVector<QPointF> &graph) const;
|
||||
void speedGraph(QVector<QPointF> &graph) const;
|
||||
void track(QVector<QPointF> &track) const;
|
||||
qreal distance();
|
||||
qreal time();
|
||||
|
||||
private:
|
||||
Parser _parser;
|
||||
|
42
src/gui.cpp
42
src/gui.cpp
@ -20,6 +20,18 @@
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
static QString timeSpan(qreal time)
|
||||
{
|
||||
unsigned h, m, s;
|
||||
|
||||
h = time / 3600;
|
||||
m = (time - (h * 3600)) / 60;
|
||||
s = time - (h * 3600) - (m * 60);
|
||||
|
||||
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||
.arg(s,2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
GUI::GUI()
|
||||
{
|
||||
createActions();
|
||||
@ -47,6 +59,8 @@ GUI::GUI()
|
||||
|
||||
_dirIndex = -1;
|
||||
_files = 0;
|
||||
_distance = 0;
|
||||
_time = 0;
|
||||
|
||||
resize(600, 800);
|
||||
}
|
||||
@ -164,12 +178,15 @@ void GUI::createTrackGraphs()
|
||||
|
||||
void GUI::createStatusBar()
|
||||
{
|
||||
_fileName = new QLabel();
|
||||
_zoom = new QLabel();
|
||||
_zoom->setAlignment(Qt::AlignHCenter);
|
||||
_fileNameLabel = new QLabel();
|
||||
_distanceLabel = new QLabel();
|
||||
_timeLabel = new QLabel();
|
||||
_distanceLabel->setAlignment(Qt::AlignHCenter);
|
||||
_timeLabel->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
statusBar()->addPermanentWidget(_fileName, 9);
|
||||
statusBar()->addPermanentWidget(_zoom, 1);
|
||||
statusBar()->addPermanentWidget(_fileNameLabel, 8);
|
||||
statusBar()->addPermanentWidget(_distanceLabel, 1);
|
||||
statusBar()->addPermanentWidget(_timeLabel, 1);
|
||||
statusBar()->setSizeGripEnabled(false);
|
||||
}
|
||||
|
||||
@ -220,9 +237,14 @@ bool GUI::openFile(const QString &fileName)
|
||||
_fileActionGroup->setEnabled(true);
|
||||
|
||||
if (++_files > 1)
|
||||
_fileName->setText(tr("%1 tracks").arg(_files));
|
||||
_fileNameLabel->setText(tr("%1 tracks").arg(_files));
|
||||
else
|
||||
_fileName->setText(fileName);
|
||||
_fileNameLabel->setText(fileName);
|
||||
_distance += gpx.distance();
|
||||
_distanceLabel->setText(QString::number(_distance / 1000, 'f', 1)
|
||||
+ " " + tr("km"));
|
||||
_time += gpx.time();
|
||||
_timeLabel->setText(timeSpan(_time));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@ -289,11 +311,15 @@ void GUI::saveFile(const QString &fileName)
|
||||
void GUI::closeFile()
|
||||
{
|
||||
_files = 0;
|
||||
_distance = 0;
|
||||
_time = 0;
|
||||
|
||||
_elevationGraph->clear();
|
||||
_speedGraph->clear();
|
||||
_track->clear();
|
||||
_fileName->clear();
|
||||
_fileNameLabel->clear();
|
||||
_distanceLabel->clear();
|
||||
_timeLabel->clear();
|
||||
|
||||
_fileActionGroup->setEnabled(false);
|
||||
}
|
||||
|
@ -68,8 +68,9 @@ private:
|
||||
QAction *_openPOIAction;
|
||||
QAction *_showPOIAction;
|
||||
|
||||
QLabel *_fileName;
|
||||
QLabel *_zoom;
|
||||
QLabel *_fileNameLabel;
|
||||
QLabel *_distanceLabel;
|
||||
QLabel *_timeLabel;
|
||||
|
||||
ElevationGraph *_elevationGraph;
|
||||
SpeedGraph *_speedGraph;
|
||||
@ -82,6 +83,9 @@ private:
|
||||
|
||||
QString _saveFileName;
|
||||
unsigned _files;
|
||||
|
||||
qreal _distance;
|
||||
qreal _time;
|
||||
};
|
||||
|
||||
#endif // GUI_H
|
||||
|
Reference in New Issue
Block a user