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

Improved track loading logic

This commit is contained in:
Martin Tůma 2016-03-03 09:15:56 +01:00
parent 4cba2ddefd
commit 919d53ade9
2 changed files with 62 additions and 50 deletions

View File

@ -33,7 +33,7 @@ TrackView::TrackView(QWidget *parent)
_mapScale->setZValue(2.0); _mapScale->setZValue(2.0);
_zoom = -1; _zoom = -1;
_scale = 1.0; _scale = -1.0;
_map = 0; _map = 0;
_maxLen = 0; _maxLen = 0;
} }
@ -43,21 +43,16 @@ TrackView::~TrackView()
delete _scene; delete _scene;
} }
void TrackView::loadGPX(const GPX &gpx) void TrackView::addTrack(const QVector<QPointF> &track)
{ {
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> track;
QPainterPath path; QPainterPath path;
QGraphicsPathItem *pi; QGraphicsPathItem *pi;
MarkerItem *mi; MarkerItem *mi;
QColor color = _palette.color(); QColor color = _palette.color();
qreal prevScale = _scale;
gpx.track(i).track(track);
if (track.size() < 2) if (track.size() < 2)
continue; return;
_tracks.append(track); _tracks.append(track);
@ -82,8 +77,21 @@ void TrackView::loadGPX(const GPX &gpx)
_markers.append(mi); _markers.append(mi);
mi->setPos(pi->path().pointAtPercent(0)); mi->setPos(pi->path().pointAtPercent(0));
mi->setScale(_scale); mi->setScale(_scale);
}
if (_trackPaths.size() > 1 && prevScale != _scale) void TrackView::loadGPX(const GPX &gpx)
{
qreal scale = _scale;
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> track;
gpx.track(i).track(track);
addTrack(track);
}
if (_trackPaths.empty())
return;
if (_trackPaths.size() > 1 && scale != _scale)
rescale(_scale); rescale(_scale);
QRectF br = trackBoundingRect(); QRectF br = trackBoundingRect();
@ -91,18 +99,19 @@ void TrackView::loadGPX(const GPX &gpx)
_scene->setSceneRect(ba); _scene->setSceneRect(ba);
centerOn(ba.center()); centerOn(ba.center());
_mapScale->setLatitude(-(br.center().ry() * _scale));
_mapScale->setZoom(_zoom);
if (_mapScale->scene() != _scene) if (_mapScale->scene() != _scene)
_scene->addItem(_mapScale); _scene->addItem(_mapScale);
_mapScale->setLatitude(track.at(track.size() / 2).y());
_mapScale->setZoom(_zoom);
}
} }
QRectF TrackView::trackBoundingRect() const QRectF TrackView::trackBoundingRect() const
{ {
qreal bottom, top, left, right; qreal bottom, top, left, right;
if (_trackPaths.empty())
return QRectF();
bottom = _trackPaths.at(0)->sceneBoundingRect().bottom(); bottom = _trackPaths.at(0)->sceneBoundingRect().bottom();
top = _trackPaths.at(0)->sceneBoundingRect().top(); top = _trackPaths.at(0)->sceneBoundingRect().top();
left = _trackPaths.at(0)->sceneBoundingRect().left(); left = _trackPaths.at(0)->sceneBoundingRect().left();
@ -322,8 +331,10 @@ void TrackView::clear()
_palette.reset(); _palette.reset();
_maxLen = 0; _maxLen = 0;
_zoom = -1;
_scale = -1.0;
_scene->setSceneRect(0, 0, 0, 0); _scene->setSceneRect(QRectF());
} }
void TrackView::movePositionMarker(qreal val) void TrackView::movePositionMarker(qreal val)

View File

@ -44,6 +44,7 @@ private slots:
void redraw(); void redraw();
private: private:
void addTrack(const QVector<QPointF> &track);
QRectF trackBoundingRect() const; QRectF trackBoundingRect() const;
qreal trackScale() const; qreal trackScale() const;
qreal mapScale() const; qreal mapScale() const;