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