mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Code cleanup
This commit is contained in:
parent
c21ef0b587
commit
ac3614f81c
@ -15,13 +15,18 @@ ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
|
||||
Graph::setXScale(0.001);
|
||||
}
|
||||
|
||||
void ElevationGraph::loadData(const QVector<QPointF> &data)
|
||||
void ElevationGraph::loadGPX(const GPX &gpx)
|
||||
{
|
||||
qreal ascent = 0, descent = 0;
|
||||
qreal min = data.at(0).y();
|
||||
qreal max = data.at(0).y();
|
||||
QVector<QPointF> data;
|
||||
qreal min, max, ascent = 0, descent = 0;
|
||||
|
||||
|
||||
gpx.elevationGraph(data);
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
|
||||
min = max = data.at(0).y();
|
||||
|
||||
for (int i = 1; i < data.size(); i++) {
|
||||
qreal cur = data.at(i).y();
|
||||
qreal prev = data.at(i-1).y();
|
||||
@ -42,10 +47,10 @@ void ElevationGraph::loadData(const QVector<QPointF> &data)
|
||||
_max = qMax(_max, max);
|
||||
_min = qMin(_min, min);
|
||||
|
||||
addInfo(tr("Ascent"), QString::number((int)_ascent) + " " + _yUnits);
|
||||
addInfo(tr("Descent"), QString::number((int)_descent) + " " + _yUnits);
|
||||
addInfo(tr("Maximum"), QString::number((int)_max) + " " + _yUnits);
|
||||
addInfo(tr("Minimum"), QString::number((int)_min) + " " + _yUnits);
|
||||
addInfo(tr("Ascent"), QString::number(_ascent, 'f', 0) + " " + _yUnits);
|
||||
addInfo(tr("Descent"), QString::number(_descent, 'f', 0) + " " + _yUnits);
|
||||
addInfo(tr("Maximum"), QString::number(_max, 'f', 0) + " " + _yUnits);
|
||||
addInfo(tr("Minimum"), QString::number(_min, 'f', 0) + " " + _yUnits);
|
||||
|
||||
Graph::loadData(data);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define ELEVATIONGRAPH_H
|
||||
|
||||
#include "graph.h"
|
||||
#include "gpx.h"
|
||||
|
||||
class ElevationGraph : public Graph
|
||||
{
|
||||
@ -10,7 +11,7 @@ class ElevationGraph : public Graph
|
||||
public:
|
||||
ElevationGraph(QWidget *parent = 0);
|
||||
|
||||
void loadData(const QVector<QPointF> &data);
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
|
@ -234,7 +234,6 @@ void Graph::clear()
|
||||
|
||||
if (_info->scene() == _scene)
|
||||
_scene->removeItem(_info);
|
||||
|
||||
_sliderInfo->show();
|
||||
|
||||
_info->clear();
|
||||
@ -252,6 +251,9 @@ void Graph::clear()
|
||||
|
||||
void Graph::emitSliderPositionChanged(const QPointF &pos)
|
||||
{
|
||||
if (_graphs.isEmpty())
|
||||
return;
|
||||
|
||||
qreal val = pos.x() / _slider->area().width();
|
||||
emit sliderPositionChanged(val);
|
||||
|
||||
|
38
src/gui.cpp
38
src/gui.cpp
@ -218,33 +218,21 @@ void GUI::openFile()
|
||||
bool GUI::openFile(const QString &fileName)
|
||||
{
|
||||
GPX gpx;
|
||||
QVector<QPointF> elevation;
|
||||
QVector<QPointF> speed;
|
||||
QVector<QPointF> track;
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (gpx.loadFile(fileName)) {
|
||||
gpx.elevationGraph(elevation);
|
||||
gpx.speedGraph(speed);
|
||||
gpx.track(track);
|
||||
|
||||
_elevationGraph->loadData(elevation);
|
||||
_speedGraph->loadData(speed, gpx.time());
|
||||
_track->loadData(track);
|
||||
_elevationGraph->loadGPX(gpx);
|
||||
_speedGraph->loadGPX(gpx);
|
||||
_track->loadGPX(gpx);
|
||||
if (_showPOIAction->isChecked())
|
||||
_track->loadPOI(_poi);
|
||||
|
||||
_fileActionGroup->setEnabled(true);
|
||||
|
||||
if (++_files > 1)
|
||||
_fileNameLabel->setText(tr("%1 tracks").arg(_files));
|
||||
else
|
||||
_fileNameLabel->setText(fileName);
|
||||
_distance += gpx.distance();
|
||||
_distanceLabel->setText(QString::number(_distance / 1000, 'f', 1)
|
||||
+ " " + tr("km"));
|
||||
_time += gpx.time();
|
||||
_timeLabel->setText(timeSpan(_time));
|
||||
|
||||
updateStatusBarInfo(fileName);
|
||||
|
||||
_fileActionGroup->setEnabled(true);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@ -332,6 +320,18 @@ void GUI::showPOI()
|
||||
_track->clearPOI();
|
||||
}
|
||||
|
||||
void GUI::updateStatusBarInfo(const QString &fileName)
|
||||
{
|
||||
if (++_files > 1)
|
||||
_fileNameLabel->setText(tr("%1 tracks").arg(_files));
|
||||
else
|
||||
_fileNameLabel->setText(fileName);
|
||||
|
||||
_distanceLabel->setText(QString::number(_distance / 1000, 'f', 1)
|
||||
+ " " + tr("km"));
|
||||
_timeLabel->setText(timeSpan(_time));
|
||||
}
|
||||
|
||||
void GUI::graphChanged(int index)
|
||||
{
|
||||
if (_trackGraphs->widget(index) == _elevationGraph)
|
||||
|
@ -41,13 +41,13 @@ private:
|
||||
void createMenus();
|
||||
void createToolBars();
|
||||
void createStatusBar();
|
||||
|
||||
void createTrackView();
|
||||
void createTrackGraphs();
|
||||
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
|
||||
void saveFile(const QString &fileName);
|
||||
void updateStatusBarInfo(const QString &fileName);
|
||||
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
|
||||
QMenu *_fileMenu;
|
||||
QMenu *_aboutMenu;
|
||||
|
@ -15,17 +15,18 @@ SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
|
||||
Graph::setPrecision(1);
|
||||
}
|
||||
|
||||
void SpeedGraph::loadData(const QVector<QPointF> &data, qreal time)
|
||||
void SpeedGraph::loadGPX(const GPX &gpx)
|
||||
{
|
||||
QVector<QPointF> data;
|
||||
qreal max = 0, sum = 0, w = 0, avg;
|
||||
qreal dist;
|
||||
|
||||
if (data.size() < 2)
|
||||
|
||||
gpx.speedGraph(data);
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
|
||||
dist = data.at(data.size() - 1).x() - data.at(0).x();
|
||||
avg = dist / time;
|
||||
_avg.append(QPointF(dist, avg));
|
||||
avg = gpx.distance() / gpx.time();
|
||||
_avg.append(QPointF(gpx.distance(), avg));
|
||||
|
||||
for (int i = 0; i < data.size(); i++)
|
||||
max = qMax(max, data.at(i).y());
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QList>
|
||||
#include "graph.h"
|
||||
#include "gpx.h"
|
||||
|
||||
class SpeedGraph : public Graph
|
||||
{
|
||||
@ -11,7 +12,7 @@ class SpeedGraph : public Graph
|
||||
public:
|
||||
SpeedGraph(QWidget *parent = 0);
|
||||
|
||||
void loadData(const QVector<QPointF> &data, qreal time);
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
|
@ -26,13 +26,17 @@ Track::~Track()
|
||||
delete _scene;
|
||||
}
|
||||
|
||||
void Track::loadData(const QVector<QPointF> &track)
|
||||
void Track::loadGPX(const GPX &gpx)
|
||||
{
|
||||
QVector<QPointF> track;
|
||||
QPainterPath path;
|
||||
QGraphicsPathItem *pi;
|
||||
MarkerItem *mi;
|
||||
QColor color = _colorShop.color();
|
||||
|
||||
|
||||
gpx.track(track);
|
||||
|
||||
if (track.size() < 2)
|
||||
return;
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QList>
|
||||
#include <QPrinter>
|
||||
#include "poi.h"
|
||||
#include "gpx.h"
|
||||
#include "colorshop.h"
|
||||
|
||||
|
||||
@ -21,7 +22,7 @@ public:
|
||||
Track(QWidget *parent = 0);
|
||||
~Track();
|
||||
|
||||
void loadData(const QVector<QPointF> &track);
|
||||
void loadGPX(const GPX &gpx);
|
||||
void loadPOI(const POI &poi);
|
||||
|
||||
void clearPOI();
|
||||
|
Loading…
Reference in New Issue
Block a user