mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Code cleanup
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
#include "elevationgraph.h"
|
||||
|
||||
|
||||
ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
||||
ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_ascent = 0;
|
||||
_descent = 0;
|
||||
|
@ -1,28 +1,28 @@
|
||||
#ifndef ELEVATIONGRAPH_H
|
||||
#define ELEVATIONGRAPH_H
|
||||
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
#include "graphtab.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class ElevationGraph : public GraphView
|
||||
class ElevationGraph : public GraphTab
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ElevationGraph(QWidget *parent = 0);
|
||||
|
||||
QString label() const {return tr("Elevation");}
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
private:
|
||||
qreal ascent() const {return _ascent;}
|
||||
qreal descent() const {return _descent;}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
qreal min() const {return bounds().top();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void setYUnits();
|
||||
void addInfo();
|
||||
|
23
src/graphtab.h
Normal file
23
src/graphtab.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef GRAPHTAB_H
|
||||
#define GRAPHTAB_H
|
||||
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class GraphTab : public GraphView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GraphTab(QWidget *parent = 0) : GraphView(parent)
|
||||
{setFrameShape(QFrame::NoFrame);}
|
||||
|
||||
virtual QString label() const = 0;
|
||||
virtual void loadGPX(const GPX &gpx) = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void setUnits(enum Units units) = 0;
|
||||
};
|
||||
|
||||
#endif // GRAPHTAB_H
|
75
src/gui.cpp
75
src/gui.cpp
@ -34,6 +34,7 @@
|
||||
#include "filebrowser.h"
|
||||
#include "cpuarch.h"
|
||||
#include "exportdialog.h"
|
||||
#include "graphtab.h"
|
||||
#include "gui.h"
|
||||
|
||||
|
||||
@ -101,8 +102,8 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
|
||||
GUI::~GUI()
|
||||
{
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
if (_trackGraphs->indexOf(_tabs.at(i).first) < 0)
|
||||
delete _tabs.at(i).first;
|
||||
if (_trackGraphs->indexOf(_tabs.at(i)) < 0)
|
||||
delete _tabs.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -400,15 +401,6 @@ void GUI::createTrackView()
|
||||
|
||||
void GUI::createTrackGraphs()
|
||||
{
|
||||
_elevationGraph = new ElevationGraph;
|
||||
_elevationGraph->setFrameShape(QFrame::NoFrame);
|
||||
_speedGraph = new SpeedGraph;
|
||||
_speedGraph->setFrameShape(QFrame::NoFrame);
|
||||
_heartRateGraph = new HeartRateGraph;
|
||||
_heartRateGraph->setFrameShape(QFrame::NoFrame);
|
||||
_temperatureGraph = new TemperatureGraph;
|
||||
_temperatureGraph->setFrameShape(QFrame::NoFrame);
|
||||
|
||||
_trackGraphs = new QTabWidget;
|
||||
connect(_trackGraphs, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(graphChanged(int)));
|
||||
@ -420,19 +412,14 @@ void GUI::createTrackGraphs()
|
||||
_trackGraphs->setDocumentMode(true);
|
||||
#endif // Q_OS_WIN32
|
||||
|
||||
_tabs.append(GraphTab(_elevationGraph, tr("Elevation")));
|
||||
_tabs.append(GraphTab(_speedGraph, tr("Speed")));
|
||||
_tabs.append(GraphTab(_heartRateGraph, tr("Heart rate")));
|
||||
_tabs.append(GraphTab(_temperatureGraph, tr("Temperature")));
|
||||
_tabs.append(new ElevationGraph);
|
||||
_tabs.append(new SpeedGraph);
|
||||
_tabs.append(new HeartRateGraph);
|
||||
_tabs.append(new TemperatureGraph);
|
||||
|
||||
connect(_elevationGraph, SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
SLOT(sliderPositionChanged(qreal)));
|
||||
connect(_speedGraph, SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
SLOT(sliderPositionChanged(qreal)));
|
||||
connect(_heartRateGraph, SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
SLOT(sliderPositionChanged(qreal)));
|
||||
connect(_temperatureGraph, SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
SLOT(sliderPositionChanged(qreal)));
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
connect(_tabs.at(i), SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
SLOT(sliderPositionChanged(qreal)));
|
||||
}
|
||||
|
||||
void GUI::createStatusBar()
|
||||
@ -565,10 +552,8 @@ bool GUI::loadFile(const QString &fileName)
|
||||
GPX gpx;
|
||||
|
||||
if (gpx.loadFile(fileName)) {
|
||||
_elevationGraph->loadGPX(gpx);
|
||||
_speedGraph->loadGPX(gpx);
|
||||
_heartRateGraph->loadGPX(gpx);
|
||||
_temperatureGraph->loadGPX(gpx);
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->loadGPX(gpx);
|
||||
updateGraphTabs();
|
||||
_track->setHidden(false);
|
||||
_track->loadGPX(gpx);
|
||||
@ -740,10 +725,8 @@ void GUI::reloadFile()
|
||||
_dateRange = DateRange(QDate(), QDate());
|
||||
_trackCount = 0;
|
||||
|
||||
_elevationGraph->clear();
|
||||
_speedGraph->clear();
|
||||
_heartRateGraph->clear();
|
||||
_temperatureGraph->clear();
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->clear();
|
||||
_track->clear();
|
||||
|
||||
_sliderPos = 0;
|
||||
@ -774,10 +757,8 @@ void GUI::closeFiles()
|
||||
|
||||
_sliderPos = 0;
|
||||
|
||||
_elevationGraph->clear();
|
||||
_speedGraph->clear();
|
||||
_heartRateGraph->clear();
|
||||
_temperatureGraph->clear();
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
_tabs.at(i)->clear();
|
||||
_track->clear();
|
||||
|
||||
_files.clear();
|
||||
@ -977,18 +958,18 @@ void GUI::updateNavigationActions()
|
||||
void GUI::updateGraphTabs()
|
||||
{
|
||||
int index;
|
||||
GraphView *gv;
|
||||
GraphTab *tab;
|
||||
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
gv = _tabs.at(i).first;
|
||||
if (!gv->count() && (index = _trackGraphs->indexOf(gv)) >= 0)
|
||||
tab = _tabs.at(i);
|
||||
if (!tab->count() && (index = _trackGraphs->indexOf(tab)) >= 0)
|
||||
_trackGraphs->removeTab(index);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _tabs.size(); i++) {
|
||||
gv = _tabs.at(i).first;
|
||||
if (gv->count() && _trackGraphs->indexOf(gv) < 0)
|
||||
_trackGraphs->insertTab(i, gv, _tabs.at(i).second);
|
||||
tab = _tabs.at(i);
|
||||
if (tab->count() && _trackGraphs->indexOf(tab) < 0)
|
||||
_trackGraphs->insertTab(i, tab, _tabs.at(i)->label());
|
||||
}
|
||||
|
||||
if (_trackGraphs->count()) {
|
||||
@ -1009,20 +990,16 @@ void GUI::updateTrackView()
|
||||
void GUI::setMetricUnits()
|
||||
{
|
||||
_track->setUnits(Metric);
|
||||
_elevationGraph->setUnits(Metric);
|
||||
_speedGraph->setUnits(Metric);
|
||||
_heartRateGraph->setUnits(Metric);
|
||||
_temperatureGraph->setUnits(Metric);
|
||||
for (int i = 0; i <_tabs.count(); i++)
|
||||
_tabs.at(i)->setUnits(Metric);
|
||||
updateStatusBarInfo();
|
||||
}
|
||||
|
||||
void GUI::setImperialUnits()
|
||||
{
|
||||
_track->setUnits(Imperial);
|
||||
_elevationGraph->setUnits(Imperial);
|
||||
_speedGraph->setUnits(Imperial);
|
||||
_heartRateGraph->setUnits(Imperial);
|
||||
_temperatureGraph->setUnits(Imperial);
|
||||
for (int i = 0; i <_tabs.count(); i++)
|
||||
_tabs.at(i)->setUnits(Imperial);
|
||||
updateStatusBarInfo();
|
||||
}
|
||||
|
||||
|
13
src/gui.h
13
src/gui.h
@ -18,11 +18,7 @@ class QLabel;
|
||||
class QSignalMapper;
|
||||
class QPrinter;
|
||||
class FileBrowser;
|
||||
class GraphView;
|
||||
class ElevationGraph;
|
||||
class SpeedGraph;
|
||||
class HeartRateGraph;
|
||||
class TemperatureGraph;
|
||||
class GraphTab;
|
||||
class TrackView;
|
||||
class Map;
|
||||
|
||||
@ -71,7 +67,6 @@ private slots:
|
||||
void sliderPositionChanged(qreal pos);
|
||||
|
||||
private:
|
||||
typedef QPair<GraphView *, QString> GraphTab;
|
||||
typedef QPair<QDate, QDate> DateRange;
|
||||
|
||||
void loadMaps();
|
||||
@ -156,11 +151,7 @@ private:
|
||||
QLabel *_timeLabel;
|
||||
|
||||
TrackView *_track;
|
||||
ElevationGraph *_elevationGraph;
|
||||
SpeedGraph *_speedGraph;
|
||||
HeartRateGraph *_heartRateGraph;
|
||||
TemperatureGraph *_temperatureGraph;
|
||||
QList<GraphTab> _tabs;
|
||||
QList<GraphTab*> _tabs;
|
||||
|
||||
POI _poi;
|
||||
QList<Map*> _maps;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "heartrategraph.h"
|
||||
|
||||
|
||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent)
|
||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
|
||||
|
@ -1,26 +1,25 @@
|
||||
#ifndef HEARTRATEGRAPH_H
|
||||
#define HEARTRATEGRAPH_H
|
||||
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
#include "graphtab.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class HeartRateGraph : public GraphView
|
||||
class HeartRateGraph : public GraphTab
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HeartRateGraph(QWidget *parent = 0);
|
||||
|
||||
QString label() const {return tr("Heart rate");}
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
qreal max() const {return bounds().bottom();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void addInfo();
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "speedgraph.h"
|
||||
|
||||
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphView(parent)
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
|
||||
|
@ -2,26 +2,25 @@
|
||||
#define SPEEDGRAPH_H
|
||||
|
||||
#include <QList>
|
||||
#include "graphview.h"
|
||||
#include "units.h"
|
||||
#include "graphtab.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class SpeedGraph : public GraphView
|
||||
class SpeedGraph : public GraphTab
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpeedGraph(QWidget *parent = 0);
|
||||
|
||||
QString label() const {return tr("Speed");}
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
qreal max() const {return bounds().bottom();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void setYUnits();
|
||||
void addInfo();
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "temperaturegraph.h"
|
||||
|
||||
|
||||
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphView(parent)
|
||||
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_units = Metric;
|
||||
|
||||
|
@ -1,27 +1,26 @@
|
||||
#ifndef TEMPERATUREGRAPH_H
|
||||
#define TEMPERATUREGRAPH_H
|
||||
|
||||
#include "units.h"
|
||||
#include "graphview.h"
|
||||
#include "graphtab.h"
|
||||
|
||||
class GPX;
|
||||
|
||||
class TemperatureGraph : public GraphView
|
||||
class TemperatureGraph : public GraphTab
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TemperatureGraph(QWidget *parent = 0);
|
||||
|
||||
QString label() const {return tr("Temperature");}
|
||||
void loadGPX(const GPX &gpx);
|
||||
void clear();
|
||||
void setUnits(enum Units units);
|
||||
|
||||
private:
|
||||
qreal avg() const;
|
||||
qreal min() const {return bounds().top();}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
|
||||
private:
|
||||
void setXUnits();
|
||||
void setYUnits();
|
||||
void addInfo();
|
||||
|
Reference in New Issue
Block a user