diff --git a/src/GUI/cadencegraph.cpp b/src/GUI/cadencegraph.cpp index feee3770..e72524ad 100644 --- a/src/GUI/cadencegraph.cpp +++ b/src/GUI/cadencegraph.cpp @@ -24,28 +24,33 @@ void CadenceGraph::setInfo() clearInfo(); } -void CadenceGraph::loadData(const Data &data, const QList &paths) +QList CadenceGraph::loadData(const Data &data) { + QList graphs; + for (int i = 0; i < data.tracks().count(); i++) { const Graph &graph = data.tracks().at(i)->cadence(); if (graph.size() < 2) { skipColor(); - continue; + graphs.append(0); + } else { + CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType); + GraphView::addGraph(gi); + _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); + graphs.append(gi); } - - CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType); - GraphView::addGraph(gi, paths.at(i)); - - _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); } - for (int i = 0; i < data.routes().count(); i++) + for (int i = 0; i < data.routes().count(); i++) { skipColor(); + graphs.append(0); + } setInfo(); - redraw(); + + return graphs; } qreal CadenceGraph::avg() const diff --git a/src/GUI/cadencegraph.h b/src/GUI/cadencegraph.h index 362575fe..a50aa984 100644 --- a/src/GUI/cadencegraph.h +++ b/src/GUI/cadencegraph.h @@ -11,7 +11,7 @@ public: CadenceGraph(QWidget *parent = 0); QString label() const {return tr("Cadence");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void showTracks(bool show); void showRoutes(bool show) {Q_UNUSED(show);} diff --git a/src/GUI/elevationgraph.cpp b/src/GUI/elevationgraph.cpp index 4611a872..ab6bbedd 100644 --- a/src/GUI/elevationgraph.cpp +++ b/src/GUI/elevationgraph.cpp @@ -65,15 +65,15 @@ void ElevationGraph::setInfo() } } -void ElevationGraph::loadGraph(const Graph &graph, Type type, PathItem *path) +GraphItem *ElevationGraph::loadGraph(const Graph &graph, Type type) { if (graph.size() < 2) { skipColor(); - return; + return 0; } ElevationGraphItem *gi = new ElevationGraphItem(graph, _graphType); - GraphView::addGraph(gi, path, type); + GraphView::addGraph(gi, type); if (type == Track) { _trackAscent += gi->ascent(); @@ -86,20 +86,23 @@ void ElevationGraph::loadGraph(const Graph &graph, Type type, PathItem *path) _routeMax = nMax(_routeMax, gi->max()); _routeMin = nMin(_routeMin, gi->min()); } + + return gi; } -void ElevationGraph::loadData(const Data &data, const QList &paths) +QList ElevationGraph::loadData(const Data &data) { - int p = 0; + QList graphs; for (int i = 0; i < data.tracks().count(); i++) - loadGraph(data.tracks().at(i)->elevation(), Track, paths.at(p++)); + graphs.append(loadGraph(data.tracks().at(i)->elevation(), Track)); for (int i = 0; i < data.routes().count(); i++) - loadGraph(data.routes().at(i)->elevation(), Route, paths.at(p++)); + graphs.append(loadGraph(data.routes().at(i)->elevation(), Route)); setInfo(); - redraw(); + + return graphs; } void ElevationGraph::clear() diff --git a/src/GUI/elevationgraph.h b/src/GUI/elevationgraph.h index 404ee370..d4902030 100644 --- a/src/GUI/elevationgraph.h +++ b/src/GUI/elevationgraph.h @@ -11,7 +11,7 @@ public: ElevationGraph(QWidget *parent = 0); QString label() const {return tr("Elevation");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void setUnits(enum Units units); void showTracks(bool show); @@ -28,7 +28,7 @@ private: void setYUnits(Units units); void setInfo(); - void loadGraph(const Graph &graph, Type type, PathItem *path); + GraphItem *loadGraph(const Graph &graph, Type type); qreal _trackAscent, _trackDescent; qreal _routeAscent, _routeDescent; diff --git a/src/GUI/graphtab.h b/src/GUI/graphtab.h index 558c4d87..89fa27a0 100644 --- a/src/GUI/graphtab.h +++ b/src/GUI/graphtab.h @@ -7,7 +7,7 @@ #include "timetype.h" class Data; -class PathItem; +class GraphItem; class GraphTab : public GraphView { @@ -19,7 +19,7 @@ public: virtual ~GraphTab() {} virtual QString label() const = 0; - virtual void loadData(const Data &data, const QList &paths) = 0; + virtual QList loadData(const Data &data) = 0; virtual void clear() {GraphView::clear();} virtual void setUnits(enum Units units) {GraphView::setUnits(units);} virtual void setGraphType(GraphType type) {GraphView::setGraphType(type);} diff --git a/src/GUI/graphview.cpp b/src/GUI/graphview.cpp index 8fd5e73c..0d8bc904 100644 --- a/src/GUI/graphview.cpp +++ b/src/GUI/graphview.cpp @@ -187,7 +187,7 @@ void GraphView::showSliderInfo(bool show) _sliderInfo->setVisible(show); } -void GraphView::addGraph(GraphItem *graph, PathItem *path, int id) +void GraphView::addGraph(GraphItem *graph, int id) { QColor color(_palette.nextColor()); color.setAlpha(255); @@ -199,10 +199,6 @@ void GraphView::addGraph(GraphItem *graph, PathItem *path, int id) connect(this, SIGNAL(sliderPositionChanged(qreal)), graph, SLOT(emitSliderPositionChanged(qreal))); - connect(graph, SIGNAL(sliderPositionChanged(qreal)), path, - SLOT(moveMarker(qreal))); - connect(path, SIGNAL(selected(bool)), graph, SLOT(hover(bool))); - connect(graph, SIGNAL(selected(bool)), path, SLOT(hover(bool))); _graphs.append(graph); diff --git a/src/GUI/graphview.h b/src/GUI/graphview.h index 1234b1be..e9963cbc 100644 --- a/src/GUI/graphview.h +++ b/src/GUI/graphview.h @@ -44,7 +44,7 @@ signals: void sliderPositionChanged(qreal); protected: - void addGraph(GraphItem *graph, PathItem *path, int id = 0); + void addGraph(GraphItem *graph, int id = 0); void showGraph(bool show, int id = 0); void setGraphType(GraphType type); diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index 9c951e2a..511e7792 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -41,6 +41,8 @@ #include "filebrowser.h" #include "cpuarch.h" #include "graphtab.h" +#include "graphitem.h" +#include "pathitem.h" #include "gui.h" @@ -58,15 +60,15 @@ GUI::GUI() createBrowser(); - QSplitter *splitter = new QSplitter(); - splitter->setOrientation(Qt::Vertical); - splitter->setChildrenCollapsible(false); - splitter->addWidget(_mapView); - splitter->addWidget(_graphTabWidget); - splitter->setContentsMargins(0, 0, 0, 0); - splitter->setStretchFactor(0, 255); - splitter->setStretchFactor(1, 1); - setCentralWidget(splitter); + _splitter = new QSplitter(); + _splitter->setOrientation(Qt::Vertical); + _splitter->setChildrenCollapsible(false); + _splitter->addWidget(_mapView); + _splitter->addWidget(_graphTabWidget); + _splitter->setContentsMargins(0, 0, 0, 0); + _splitter->setStretchFactor(0, 255); + _splitter->setStretchFactor(1, 1); + setCentralWidget(_splitter); setWindowIcon(QIcon(QPixmap(APP_ICON))); setWindowTitle(APP_NAME); @@ -688,8 +690,6 @@ bool GUI::openFile(const QString &fileName) updateNavigationActions(); updateStatusBarInfo(); updateWindowTitle(); - updateGraphTabs(); - updateMapView(); return true; } else { @@ -703,13 +703,10 @@ bool GUI::openFile(const QString &fileName) bool GUI::loadFile(const QString &fileName) { Data data; + QList > graphs; QList paths; if (data.loadFile(fileName)) { - paths = _mapView->loadData(data); - for (int i = 0; i < _tabs.count(); i++) - _tabs.at(i)->loadData(data, paths); - for (int i = 0; i < data.tracks().count(); i++) { _trackDistance += data.tracks().at(i)->distance(); _time += data.tracks().at(i)->time(); @@ -736,6 +733,25 @@ bool GUI::loadFile(const QString &fileName) } else _pathName = QString(); + for (int i = 0; i < _tabs.count(); i++) + graphs.append(_tabs.at(i)->loadData(data)); + if (updateGraphTabs() | updateMapView()) + _splitter->refresh(); + paths = _mapView->loadData(data); + + for (int i = 0; i < paths.count(); i++) { + const PathItem *pi = paths.at(i); + for (int j = 0; j < graphs.count(); j++) { + const GraphItem *gi = graphs.at(j).at(i); + if (!gi) + continue; + connect(gi, SIGNAL(sliderPositionChanged(qreal)), pi, + SLOT(moveMarker(qreal))); + connect(pi, SIGNAL(selected(bool)), gi, SLOT(hover(bool))); + connect(gi, SIGNAL(selected(bool)), pi, SLOT(hover(bool))); + } + } + return true; } else { updateNavigationActions(); @@ -1010,8 +1026,6 @@ void GUI::reloadFile() updateStatusBarInfo(); updateWindowTitle(); - updateGraphTabs(); - updateMapView(); if (_files.isEmpty()) _fileActionGroup->setEnabled(false); else @@ -1276,10 +1290,11 @@ void GUI::updateNavigationActions() } } -void GUI::updateGraphTabs() +bool GUI::updateGraphTabs() { int index; GraphTab *tab; + bool hidden = _graphTabWidget->isHidden(); for (int i = 0; i < _tabs.size(); i++) { tab = _tabs.at(i); @@ -1303,14 +1318,20 @@ void GUI::updateGraphTabs() _graphTabWidget->setHidden(true); _showGraphsAction->setEnabled(false); } + + return (hidden != _graphTabWidget->isHidden()); } -void GUI::updateMapView() +bool GUI::updateMapView() { + bool hidden = _mapView->isHidden(); + if (_options.alwaysShowMap) _mapView->setHidden(false); else _mapView->setHidden(!(_trackCount + _routeCount + _waypointCount)); + + return (hidden != _mapView->isHidden()); } void GUI::setTimeType(TimeType type) diff --git a/src/GUI/gui.h b/src/GUI/gui.h index a7fb699e..4e12bb70 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -20,6 +20,7 @@ class QTabWidget; class QActionGroup; class QAction; class QLabel; +class QSplitter; class QSignalMapper; class QPrinter; class FileBrowser; @@ -109,8 +110,8 @@ private: void updateStatusBarInfo(); void updateWindowTitle(); void updateNavigationActions(); - void updateGraphTabs(); - void updateMapView(); + bool updateGraphTabs(); + bool updateMapView(); TimeType timeType() const; Units units() const; @@ -196,6 +197,7 @@ private: QLabel *_distanceLabel; QLabel *_timeLabel; + QSplitter *_splitter; MapView *_mapView; QTabWidget *_graphTabWidget; QList _tabs; diff --git a/src/GUI/heartrategraph.cpp b/src/GUI/heartrategraph.cpp index 61bb4a14..a18ac518 100644 --- a/src/GUI/heartrategraph.cpp +++ b/src/GUI/heartrategraph.cpp @@ -24,28 +24,33 @@ void HeartRateGraph::setInfo() clearInfo(); } -void HeartRateGraph::loadData(const Data &data, const QList &paths) +QList HeartRateGraph::loadData(const Data &data) { + QList graphs; + for (int i = 0; i < data.tracks().count(); i++) { const Graph &graph = data.tracks().at(i)->heartRate(); if (graph.size() < 2) { skipColor(); - continue; + graphs.append(0); + } else { + HeartRateGraphItem *gi = new HeartRateGraphItem(graph, _graphType); + GraphView::addGraph(gi); + _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); + graphs.append(gi); } - - HeartRateGraphItem *gi = new HeartRateGraphItem(graph, _graphType); - GraphView::addGraph(gi, paths.at(i)); - - _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); } - for (int i = 0; i < data.routes().count(); i++) + for (int i = 0; i < data.routes().count(); i++) { skipColor(); + graphs.append(0); + } setInfo(); - redraw(); + + return graphs; } qreal HeartRateGraph::avg() const diff --git a/src/GUI/heartrategraph.h b/src/GUI/heartrategraph.h index 2e06bb80..1c6dce9a 100644 --- a/src/GUI/heartrategraph.h +++ b/src/GUI/heartrategraph.h @@ -11,7 +11,7 @@ public: HeartRateGraph(QWidget *parent = 0); QString label() const {return tr("Heart rate");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void showTracks(bool show); diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 9e55e841..a59c4f61 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -22,6 +22,7 @@ class RouteItem; class WaypointItem; class ScaleItem; class PathItem; +class GraphItem; class MapView : public QGraphicsView { @@ -30,7 +31,7 @@ class MapView : public QGraphicsView public: MapView(Map *map, POI *poi, QWidget *parent = 0); - QList loadData(const Data &data); + QList loadData(const Data &data); void setPalette(const Palette &palette); void setPOI(POI *poi); diff --git a/src/GUI/powergraph.cpp b/src/GUI/powergraph.cpp index 3bd41aad..58067bf8 100644 --- a/src/GUI/powergraph.cpp +++ b/src/GUI/powergraph.cpp @@ -24,28 +24,33 @@ void PowerGraph::setInfo() clearInfo(); } -void PowerGraph::loadData(const Data &data, const QList &paths) +QList PowerGraph::loadData(const Data &data) { + QList graphs; + for (int i = 0; i < data.tracks().count(); i++) { const Graph &graph = data.tracks().at(i)->power(); if (graph.size() < 2) { skipColor(); - continue; + graphs.append(0); + } else { + PowerGraphItem *gi = new PowerGraphItem(graph, _graphType); + GraphView::addGraph(gi); + _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); + graphs.append(gi); } - - PowerGraphItem *gi = new PowerGraphItem(graph, _graphType); - GraphView::addGraph(gi, paths.at(i)); - - _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); } - for (int i = 0; i < data.routes().count(); i++) + for (int i = 0; i < data.routes().count(); i++) { skipColor(); + graphs.append(0); + } setInfo(); - redraw(); + + return graphs; } qreal PowerGraph::avg() const diff --git a/src/GUI/powergraph.h b/src/GUI/powergraph.h index 58553a11..ddd0a770 100644 --- a/src/GUI/powergraph.h +++ b/src/GUI/powergraph.h @@ -11,7 +11,7 @@ public: PowerGraph(QWidget *parent = 0); QString label() const {return tr("Power");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void showTracks(bool show); diff --git a/src/GUI/speedgraph.cpp b/src/GUI/speedgraph.cpp index 0bc77937..2b9938ba 100644 --- a/src/GUI/speedgraph.cpp +++ b/src/GUI/speedgraph.cpp @@ -34,32 +34,37 @@ void SpeedGraph::setInfo() clearInfo(); } -void SpeedGraph::loadData(const Data &data, const QList &paths) +QList SpeedGraph::loadData(const Data &data) { + QList graphs; + for (int i = 0; i < data.tracks().count(); i++) { const Track *track = data.tracks().at(i); const Graph &graph = track->speed(); if (graph.size() < 2) { skipColor(); - continue; + graphs.append(0); + } else { + SpeedGraphItem *gi = new SpeedGraphItem(graph, _graphType, + track->movingTime()); + gi->setTimeType(_timeType); + GraphView::addGraph(gi); + _avg.append(QPointF(track->distance(), gi->avg())); + _mavg.append(QPointF(track->distance(), gi->mavg())); + graphs.append(gi); } - - SpeedGraphItem *gi = new SpeedGraphItem(graph, _graphType, - track->movingTime()); - gi->setTimeType(_timeType); - GraphView::addGraph(gi, paths.at(i)); - - _avg.append(QPointF(track->distance(), gi->avg())); - _mavg.append(QPointF(track->distance(), gi->mavg())); } - for (int i = 0; i < data.routes().count(); i++) + for (int i = 0; i < data.routes().count(); i++) { skipColor(); + graphs.append(0); + } setInfo(); - redraw(); + + return graphs; } qreal SpeedGraph::avg() const diff --git a/src/GUI/speedgraph.h b/src/GUI/speedgraph.h index 537b40b2..e7e657fc 100644 --- a/src/GUI/speedgraph.h +++ b/src/GUI/speedgraph.h @@ -12,7 +12,7 @@ public: SpeedGraph(QWidget *parent = 0); QString label() const {return tr("Speed");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void setUnits(Units units); void setTimeType(TimeType type); diff --git a/src/GUI/temperaturegraph.cpp b/src/GUI/temperaturegraph.cpp index 31ab3a30..281d8632 100644 --- a/src/GUI/temperaturegraph.cpp +++ b/src/GUI/temperaturegraph.cpp @@ -26,28 +26,34 @@ void TemperatureGraph::setInfo() clearInfo(); } -void TemperatureGraph::loadData(const Data &data, const QList &paths) +QList TemperatureGraph::loadData(const Data &data) { + QList graphs; + for (int i = 0; i < data.tracks().count(); i++) { const Graph &graph = data.tracks().at(i)->temperature(); if (graph.size() < 2) { skipColor(); - continue; + graphs.append(0); + } else { + TemperatureGraphItem *gi = new TemperatureGraphItem(graph, + _graphType); + GraphView::addGraph(gi); + _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); + graphs.append(gi); } - - TemperatureGraphItem *gi = new TemperatureGraphItem(graph, _graphType); - GraphView::addGraph(gi, paths.at(i)); - - _avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg())); } - for (int i = 0; i < data.routes().count(); i++) + for (int i = 0; i < data.routes().count(); i++) { skipColor(); + graphs.append(0); + } setInfo(); - redraw(); + + return graphs; } qreal TemperatureGraph::avg() const diff --git a/src/GUI/temperaturegraph.h b/src/GUI/temperaturegraph.h index 2cfd17b3..a30e513d 100644 --- a/src/GUI/temperaturegraph.h +++ b/src/GUI/temperaturegraph.h @@ -11,7 +11,7 @@ public: TemperatureGraph(QWidget *parent = 0); QString label() const {return tr("Temperature");} - void loadData(const Data &data, const QList &paths); + QList loadData(const Data &data); void clear(); void setUnits(enum Units units); void showTracks(bool show);