1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Fixed the instant-resize-after-first-load issue

This commit is contained in:
Martin Tůma 2018-05-04 19:36:37 +02:00
parent 4463241e50
commit b0f4f2294a
18 changed files with 142 additions and 93 deletions

View File

@ -24,28 +24,33 @@ void CadenceGraph::setInfo()
clearInfo();
}
void CadenceGraph::loadData(const Data &data, const QList<PathItem *> &paths)
QList<GraphItem*> CadenceGraph::loadData(const Data &data)
{
QList<GraphItem*> 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

View File

@ -11,7 +11,7 @@ public:
CadenceGraph(QWidget *parent = 0);
QString label() const {return tr("Cadence");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> loadData(const Data &data);
void clear();
void showTracks(bool show);
void showRoutes(bool show) {Q_UNUSED(show);}

View File

@ -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<PathItem *> &paths)
QList<GraphItem*> ElevationGraph::loadData(const Data &data)
{
int p = 0;
QList<GraphItem*> 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()

View File

@ -11,7 +11,7 @@ public:
ElevationGraph(QWidget *parent = 0);
QString label() const {return tr("Elevation");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> 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;

View File

@ -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<PathItem *> &paths) = 0;
virtual QList<GraphItem*> 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);}

View File

@ -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);

View File

@ -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);

View File

@ -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<QList<GraphItem*> > graphs;
QList<PathItem*> 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)

View File

@ -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<GraphTab*> _tabs;

View File

@ -24,28 +24,33 @@ void HeartRateGraph::setInfo()
clearInfo();
}
void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
QList<GraphItem*> HeartRateGraph::loadData(const Data &data)
{
QList<GraphItem*> 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

View File

@ -11,7 +11,7 @@ public:
HeartRateGraph(QWidget *parent = 0);
QString label() const {return tr("Heart rate");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> loadData(const Data &data);
void clear();
void showTracks(bool show);

View File

@ -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<PathItem*> loadData(const Data &data);
QList<PathItem *> loadData(const Data &data);
void setPalette(const Palette &palette);
void setPOI(POI *poi);

View File

@ -24,28 +24,33 @@ void PowerGraph::setInfo()
clearInfo();
}
void PowerGraph::loadData(const Data &data, const QList<PathItem *> &paths)
QList<GraphItem*> PowerGraph::loadData(const Data &data)
{
QList<GraphItem*> 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

View File

@ -11,7 +11,7 @@ public:
PowerGraph(QWidget *parent = 0);
QString label() const {return tr("Power");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> loadData(const Data &data);
void clear();
void showTracks(bool show);

View File

@ -34,32 +34,37 @@ void SpeedGraph::setInfo()
clearInfo();
}
void SpeedGraph::loadData(const Data &data, const QList<PathItem *> &paths)
QList<GraphItem*> SpeedGraph::loadData(const Data &data)
{
QList<GraphItem*> 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

View File

@ -12,7 +12,7 @@ public:
SpeedGraph(QWidget *parent = 0);
QString label() const {return tr("Speed");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> loadData(const Data &data);
void clear();
void setUnits(Units units);
void setTimeType(TimeType type);

View File

@ -26,28 +26,34 @@ void TemperatureGraph::setInfo()
clearInfo();
}
void TemperatureGraph::loadData(const Data &data, const QList<PathItem *> &paths)
QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
{
QList<GraphItem*> 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

View File

@ -11,7 +11,7 @@ public:
TemperatureGraph(QWidget *parent = 0);
QString label() const {return tr("Temperature");}
void loadData(const Data &data, const QList<PathItem *> &paths);
QList<GraphItem*> loadData(const Data &data);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);