1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Some more code cleanup

This commit is contained in:
Martin Tůma 2016-05-13 18:48:42 +02:00
parent e73f9448e9
commit 07255aa8ae
2 changed files with 22 additions and 18 deletions

View File

@ -32,13 +32,6 @@
#include "gui.h"
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
struct GraphTab {
GraphView *view;
QString label;
};
static QString timeSpan(qreal time)
{
unsigned h, m, s;
@ -102,6 +95,14 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
readSettings();
}
GUI::~GUI()
{
for (int i = 0; i < _tabs.size(); i++) {
if (_trackGraphs->indexOf(_tabs.at(i).first) < 0)
delete _tabs.at(i).first;
}
}
void GUI::loadMaps()
{
if (QFile::exists(USER_MAP_FILE))
@ -419,6 +420,10 @@ void GUI::createTrackGraphs()
#ifdef Q_OS_WIN32
_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")));
}
void GUI::createStatusBar()
@ -927,24 +932,19 @@ void GUI::updateNavigationActions()
void GUI::updateGraphTabs()
{
struct GraphTab tabs[] = {
{_elevationGraph, tr("Elevation")},
{_speedGraph, tr("Speed")},
{_heartRateGraph, tr("Heart rate")}
};
int index;
GraphView *gv;
for (int i = 0; i < (int)ARRAY_SIZE(tabs); i++) {
gv = tabs[i].view;
for (int i = 0; i < _tabs.size(); i++) {
gv = _tabs.at(i).first;
if (!gv->count() && (index = _trackGraphs->indexOf(gv)) >= 0)
_trackGraphs->removeTab(index);
}
for (int i = 0; i < (int)ARRAY_SIZE(tabs); i++) {
gv = tabs[i].view;
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[i].label);
_trackGraphs->insertTab(i, gv, _tabs.at(i).second);
}
if (_trackGraphs->count()) {

View File

@ -27,6 +27,7 @@ class GUI : public QMainWindow
public:
GUI(QWidget *parent = 0);
~GUI();
bool openFile(const QString &fileName);
@ -65,6 +66,8 @@ private slots:
void sliderPositionChanged(qreal pos);
private:
typedef QPair<GraphView *, QString> GraphTab;
void loadMaps();
void loadPOIs();
void closeFiles();
@ -145,10 +148,11 @@ private:
QLabel *_distanceLabel;
QLabel *_timeLabel;
TrackView *_track;
ElevationGraph *_elevationGraph;
SpeedGraph *_speedGraph;
HeartRateGraph *_heartRateGraph;
TrackView *_track;
QList<GraphTab> _tabs;
POI _poi;
QList<Map*> _maps;