1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +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" #include "gui.h"
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
struct GraphTab {
GraphView *view;
QString label;
};
static QString timeSpan(qreal time) static QString timeSpan(qreal time)
{ {
unsigned h, m, s; unsigned h, m, s;
@ -102,6 +95,14 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
readSettings(); 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() void GUI::loadMaps()
{ {
if (QFile::exists(USER_MAP_FILE)) if (QFile::exists(USER_MAP_FILE))
@ -419,6 +420,10 @@ void GUI::createTrackGraphs()
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
_trackGraphs->setDocumentMode(true); _trackGraphs->setDocumentMode(true);
#endif // Q_OS_WIN32 #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() void GUI::createStatusBar()
@ -927,24 +932,19 @@ void GUI::updateNavigationActions()
void GUI::updateGraphTabs() void GUI::updateGraphTabs()
{ {
struct GraphTab tabs[] = {
{_elevationGraph, tr("Elevation")},
{_speedGraph, tr("Speed")},
{_heartRateGraph, tr("Heart rate")}
};
int index; int index;
GraphView *gv; GraphView *gv;
for (int i = 0; i < (int)ARRAY_SIZE(tabs); i++) { for (int i = 0; i < _tabs.size(); i++) {
gv = tabs[i].view; gv = _tabs.at(i).first;
if (!gv->count() && (index = _trackGraphs->indexOf(gv)) >= 0) if (!gv->count() && (index = _trackGraphs->indexOf(gv)) >= 0)
_trackGraphs->removeTab(index); _trackGraphs->removeTab(index);
} }
for (int i = 0; i < (int)ARRAY_SIZE(tabs); i++) { for (int i = 0; i < _tabs.size(); i++) {
gv = tabs[i].view; gv = _tabs.at(i).first;
if (gv->count() && _trackGraphs->indexOf(gv) < 0) 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()) { if (_trackGraphs->count()) {

View File

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