From 07255aa8ae591f5df10438b6453de8621b167845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 13 May 2016 18:48:42 +0200 Subject: [PATCH] Some more code cleanup --- src/gui.cpp | 34 +++++++++++++++++----------------- src/gui.h | 6 +++++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index 3c4b6147..98d85503 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -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()) { diff --git a/src/gui.h b/src/gui.h index 1957bca6..d9ddbfde 100644 --- a/src/gui.h +++ b/src/gui.h @@ -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 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 _tabs; POI _poi; QList _maps;