mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Added searching for POIs near waypoints
Refactoring
This commit is contained in:
parent
ee3a6adf2b
commit
72dda5fdd6
@ -141,10 +141,11 @@ QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
|
|||||||
qreal min[2], max[2];
|
qreal min[2], max[2];
|
||||||
|
|
||||||
for (int i = 0; i < path.count(); i++) {
|
for (int i = 0; i < path.count(); i++) {
|
||||||
min[0] = path.at(i).x() - radius;
|
const QPointF &p = path.at(i);
|
||||||
min[1] = path.at(i).y() - radius;
|
min[0] = p.x() - radius;
|
||||||
max[0] = path.at(i).x() + radius;
|
min[1] = p.y() - radius;
|
||||||
max[1] = path.at(i).y() + radius;
|
max[0] = p.x() + radius;
|
||||||
|
max[1] = p.y() + radius;
|
||||||
_tree.Search(min, max, cb, &set);
|
_tree.Search(min, max, cb, &set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void TrackView::addTrack(const QVector<QPointF> &track)
|
|||||||
|
|
||||||
|
|
||||||
pi = new QGraphicsPathItem(path);
|
pi = new QGraphicsPathItem(path);
|
||||||
_trackPaths.append(pi);
|
_paths.append(pi);
|
||||||
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
_zoom = qMin(_zoom, scale2zoom(trackScale()));
|
||||||
_scale = mapScale(_zoom);
|
_scale = mapScale(_zoom);
|
||||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
QBrush brush(_palette.color(), Qt::SolidPattern);
|
||||||
@ -89,7 +89,8 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
|
|||||||
wi->setZValue(1);
|
wi->setZValue(1);
|
||||||
_scene->addItem(wi);
|
_scene->addItem(wi);
|
||||||
|
|
||||||
_waypoints.append(wi);
|
_locations.append(wi);
|
||||||
|
_waypoints.append(waypoints.at(i).coordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
|
||||||
@ -108,11 +109,11 @@ void TrackView::loadGPX(const GPX &gpx)
|
|||||||
|
|
||||||
addWaypoints(gpx.waypoints());
|
addWaypoints(gpx.waypoints());
|
||||||
|
|
||||||
if (_trackPaths.empty() && _waypoints.empty())
|
if (_paths.empty() && _locations.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((_trackPaths.size() > 1 && _zoom < zoom)
|
if ((_paths.size() > 1 && _zoom < zoom)
|
||||||
|| (_waypoints.size() && _zoom < zoom))
|
|| (_locations.size() && _zoom < zoom))
|
||||||
rescale(_scale);
|
rescale(_scale);
|
||||||
|
|
||||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||||
@ -128,43 +129,35 @@ void TrackView::loadGPX(const GPX &gpx)
|
|||||||
|
|
||||||
QRectF TrackView::trackBoundingRect() const
|
QRectF TrackView::trackBoundingRect() const
|
||||||
{
|
{
|
||||||
qreal bottom, top, left, right;
|
if (_paths.empty())
|
||||||
|
|
||||||
if (_trackPaths.empty())
|
|
||||||
return QRectF();
|
return QRectF();
|
||||||
|
|
||||||
bottom = _trackPaths.at(0)->sceneBoundingRect().bottom();
|
QRectF br = _paths.at(0)->sceneBoundingRect();
|
||||||
top = _trackPaths.at(0)->sceneBoundingRect().top();
|
for (int i = 1; i < _paths.size(); i++)
|
||||||
left = _trackPaths.at(0)->sceneBoundingRect().left();
|
br |= _paths.at(i)->sceneBoundingRect();
|
||||||
right = _trackPaths.at(0)->sceneBoundingRect().right();
|
|
||||||
|
|
||||||
for (int i = 1; i < _trackPaths.size(); i++) {
|
return br;
|
||||||
bottom = qMax(bottom, _trackPaths.at(i)->sceneBoundingRect().bottom());
|
|
||||||
top = qMin(top, _trackPaths.at(i)->sceneBoundingRect().top());
|
|
||||||
right = qMax(right, _trackPaths.at(i)->sceneBoundingRect().right());
|
|
||||||
left = qMin(left, _trackPaths.at(i)->sceneBoundingRect().left());
|
|
||||||
}
|
|
||||||
|
|
||||||
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF TrackView::waypointBoundingRect() const
|
QRectF TrackView::waypointBoundingRect() const
|
||||||
{
|
{
|
||||||
qreal bottom, top, left, right;
|
qreal bottom, top, left, right;
|
||||||
|
|
||||||
if (_waypoints.empty())
|
if (_locations.empty())
|
||||||
return QRectF();
|
return QRectF();
|
||||||
|
|
||||||
bottom = _waypoints.at(0)->pos().y();
|
const QPointF &p = _locations.at(0)->pos();
|
||||||
top = _waypoints.at(0)->pos().y();
|
bottom = p.y();
|
||||||
left = _waypoints.at(0)->pos().x();
|
top = p.y();
|
||||||
right = _waypoints.at(0)->pos().x();
|
left = p.x();
|
||||||
|
right = p.x();
|
||||||
|
|
||||||
for (int i = 1; i < _waypoints.size(); i++) {
|
for (int i = 1; i < _locations.size(); i++) {
|
||||||
bottom = qMax(bottom, _waypoints.at(i)->pos().y());
|
const QPointF &p = _locations.at(i)->pos();
|
||||||
top = qMin(top, _waypoints.at(i)->pos().y());
|
bottom = qMax(bottom, p.y());
|
||||||
right = qMax(right, _waypoints.at(i)->pos().x());
|
top = qMin(top, p.y());
|
||||||
left = qMin(left, _waypoints.at(i)->pos().x());
|
right = qMax(right, p.x());
|
||||||
|
left = qMin(left, p.x());
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
return QRectF(QPointF(left, top), QPointF(right, bottom));
|
||||||
@ -172,24 +165,14 @@ QRectF TrackView::waypointBoundingRect() const
|
|||||||
|
|
||||||
qreal TrackView::trackScale() const
|
qreal TrackView::trackScale() const
|
||||||
{
|
{
|
||||||
qreal bottom, top, left, right;
|
if (_paths.empty())
|
||||||
|
|
||||||
if (_trackPaths.empty())
|
|
||||||
return mapScale(ZOOM_MAX);
|
return mapScale(ZOOM_MAX);
|
||||||
|
|
||||||
bottom = _trackPaths.at(0)->path().boundingRect().bottom();
|
QRectF br = _paths.at(0)->path().boundingRect();
|
||||||
top = _trackPaths.at(0)->path().boundingRect().top();
|
|
||||||
left = _trackPaths.at(0)->path().boundingRect().left();
|
|
||||||
right = _trackPaths.at(0)->path().boundingRect().right();
|
|
||||||
|
|
||||||
for (int i = 1; i < _trackPaths.size(); i++) {
|
for (int i = 1; i < _paths.size(); i++)
|
||||||
bottom = qMax(bottom, _trackPaths.at(i)->path().boundingRect().bottom());
|
br |= _paths.at(i)->path().boundingRect();
|
||||||
top = qMin(top, _trackPaths.at(i)->path().boundingRect().top());
|
|
||||||
right = qMax(right, _trackPaths.at(i)->path().boundingRect().right());
|
|
||||||
left = qMin(left, _trackPaths.at(i)->path().boundingRect().left());
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
|
||||||
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
|
||||||
br.height() / (viewport()->height() - MARGIN/2));
|
br.height() / (viewport()->height() - MARGIN/2));
|
||||||
|
|
||||||
@ -200,19 +183,21 @@ qreal TrackView::waypointScale() const
|
|||||||
{
|
{
|
||||||
qreal bottom, top, left, right;
|
qreal bottom, top, left, right;
|
||||||
|
|
||||||
if (_waypoints.count() < 2)
|
if (_locations.size() < 2)
|
||||||
return mapScale(ZOOM_MAX);
|
return mapScale(ZOOM_MAX);
|
||||||
|
|
||||||
bottom = _waypoints.at(0)->entry().coordinates().y();
|
const QPointF &p = _locations.at(0)->entry().coordinates();
|
||||||
top = _waypoints.at(0)->entry().coordinates().y();
|
bottom = p.y();
|
||||||
left = _waypoints.at(0)->entry().coordinates().x();
|
top = p.y();
|
||||||
right = _waypoints.at(0)->entry().coordinates().x();
|
left = p.x();
|
||||||
|
right = p.x();
|
||||||
|
|
||||||
for (int i = 1; i < _waypoints.size(); i++) {
|
for (int i = 1; i < _locations.size(); i++) {
|
||||||
bottom = qMax(bottom, _waypoints.at(i)->entry().coordinates().y());
|
const QPointF &p = _locations.at(i)->entry().coordinates();
|
||||||
top = qMin(top, _waypoints.at(i)->entry().coordinates().y());
|
bottom = qMax(bottom, p.y());
|
||||||
right = qMax(right, _waypoints.at(i)->entry().coordinates().x());
|
top = qMin(top, p.y());
|
||||||
left = qMin(left, _waypoints.at(i)->entry().coordinates().x());
|
right = qMax(right, p.x());
|
||||||
|
left = qMin(left, p.x());
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
QRectF br(QPointF(left, top), QPointF(right, bottom));
|
||||||
@ -229,17 +214,17 @@ qreal TrackView::mapScale(int zoom) const
|
|||||||
|
|
||||||
void TrackView::rescale(qreal scale)
|
void TrackView::rescale(qreal scale)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
for (int i = 0; i < _paths.size(); i++) {
|
||||||
_markers.at(i)->setScale(scale);
|
_markers.at(i)->setScale(scale);
|
||||||
_trackPaths.at(i)->setScale(1.0/scale);
|
_paths.at(i)->setScale(1.0/scale);
|
||||||
|
|
||||||
QPen pen(_trackPaths.at(i)->pen());
|
QPen pen(_paths.at(i)->pen());
|
||||||
pen.setWidthF(TRACK_WIDTH * scale);
|
pen.setWidthF(TRACK_WIDTH * scale);
|
||||||
_trackPaths.at(i)->setPen(pen);
|
_paths.at(i)->setPen(pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _waypoints.size(); i++)
|
for (int i = 0; i < _locations.size(); i++)
|
||||||
_waypoints.at(i)->setPos(_waypoints.at(i)->entry().coordinates()
|
_locations.at(i)->setPos(_locations.at(i)->entry().coordinates()
|
||||||
* 1.0/scale);
|
* 1.0/scale);
|
||||||
|
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||||
@ -259,32 +244,35 @@ void TrackView::rescale(qreal scale)
|
|||||||
_scale = scale;
|
_scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackView::loadPOI(const POI &poi)
|
void TrackView::addPOI(const QVector<Waypoint> &waypoints)
|
||||||
{
|
{
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
|
if (_pois.contains(waypoints.at(i)))
|
||||||
if (!_tracks.size())
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < _tracks.size(); i++) {
|
|
||||||
QVector<Waypoint> p = poi.points(_tracks.at(i));
|
|
||||||
|
|
||||||
for (int i = 0; i < p.size(); i++) {
|
|
||||||
if (_pois.contains(p.at(i)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
WaypointItem *pi = new WaypointItem(
|
WaypointItem *pi = new WaypointItem(
|
||||||
Waypoint(ll2mercator(QPointF(p.at(i).coordinates().x(),
|
Waypoint(ll2mercator(QPointF(waypoints.at(i).coordinates().x(),
|
||||||
-p.at(i).coordinates().y())), p.at(i).description()));
|
-waypoints.at(i).coordinates().y())), waypoints.at(i).description()));
|
||||||
|
|
||||||
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
pi->setPos(pi->entry().coordinates() * 1.0/_scale);
|
||||||
pi->setZValue(1);
|
pi->setZValue(1);
|
||||||
_scene->addItem(pi);
|
_scene->addItem(pi);
|
||||||
|
|
||||||
_pois.insert(p.at(i), pi);
|
_pois.insert(waypoints.at(i), pi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackView::loadPOI(const POI &poi)
|
||||||
|
{
|
||||||
|
QHash<Waypoint, WaypointItem*>::const_iterator it,jt;
|
||||||
|
|
||||||
|
if (!_tracks.size() && !_waypoints.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < _tracks.size(); i++)
|
||||||
|
addPOI(poi.points(_tracks.at(i)));
|
||||||
|
addPOI(poi.points(_waypoints));
|
||||||
|
|
||||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
||||||
@ -314,7 +302,7 @@ void TrackView::redraw()
|
|||||||
|
|
||||||
void TrackView::wheelEvent(QWheelEvent *event)
|
void TrackView::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (_tracks.isEmpty() && _waypoints.isEmpty())
|
if (_paths.isEmpty() && _locations.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPointF pos = mapToScene(event->pos());
|
QPointF pos = mapToScene(event->pos());
|
||||||
@ -341,10 +329,10 @@ void TrackView::wheelEvent(QWheelEvent *event)
|
|||||||
|
|
||||||
void TrackView::setTrackLineWidth(qreal width)
|
void TrackView::setTrackLineWidth(qreal width)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
for (int i = 0; i < _paths.size(); i++) {
|
||||||
QPen pen(_trackPaths.at(i)->pen());
|
QPen pen(_paths.at(i)->pen());
|
||||||
pen.setWidthF(width);
|
pen.setWidthF(width);
|
||||||
_trackPaths.at(i)->setPen(pen);
|
_paths.at(i)->setPen(pen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,13 +389,15 @@ void TrackView::clear()
|
|||||||
_scene->removeItem(_mapScale);
|
_scene->removeItem(_mapScale);
|
||||||
|
|
||||||
_pois.clear();
|
_pois.clear();
|
||||||
_tracks.clear();
|
_paths.clear();
|
||||||
_trackPaths.clear();
|
_locations.clear();
|
||||||
_waypoints.clear();
|
|
||||||
_markers.clear();
|
_markers.clear();
|
||||||
_scene->clear();
|
_scene->clear();
|
||||||
_palette.reset();
|
_palette.reset();
|
||||||
|
|
||||||
|
_tracks.clear();
|
||||||
|
_waypoints.clear();
|
||||||
|
|
||||||
_maxLen = 0;
|
_maxLen = 0;
|
||||||
_zoom = ZOOM_MAX;
|
_zoom = ZOOM_MAX;
|
||||||
_scale = mapScale(_zoom);
|
_scale = mapScale(_zoom);
|
||||||
@ -417,9 +407,9 @@ void TrackView::clear()
|
|||||||
|
|
||||||
void TrackView::movePositionMarker(qreal val)
|
void TrackView::movePositionMarker(qreal val)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _trackPaths.size(); i++) {
|
for (int i = 0; i < _paths.size(); i++) {
|
||||||
qreal f = _maxLen / _trackPaths.at(i)->path().length();
|
qreal f = _maxLen / _paths.at(i)->path().length();
|
||||||
QPointF pos = _trackPaths.at(i)->path().pointAtPercent(qMin(val * f,
|
QPointF pos = _paths.at(i)->path().pointAtPercent(qMin(val * f,
|
||||||
1.0));
|
1.0));
|
||||||
_markers.at(i)->setPos(pos);
|
_markers.at(i)->setPos(pos);
|
||||||
}
|
}
|
||||||
@ -427,7 +417,7 @@ void TrackView::movePositionMarker(qreal val)
|
|||||||
|
|
||||||
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
if ((_tracks.isEmpty() && _waypoints.isEmpty())|| !_map) {
|
if ((_paths.isEmpty() && _locations.isEmpty())|| !_map) {
|
||||||
painter->fillRect(rect, Qt::white);
|
painter->fillRect(rect, Qt::white);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -459,7 +449,7 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
void TrackView::resizeEvent(QResizeEvent *e)
|
void TrackView::resizeEvent(QResizeEvent *e)
|
||||||
{
|
{
|
||||||
if (_tracks.isEmpty() && _waypoints.isEmpty())
|
if (_paths.isEmpty() && _locations.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
QRectF br = trackBoundingRect() | waypointBoundingRect();
|
||||||
|
@ -46,6 +46,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void addTrack(const QVector<QPointF> &track);
|
void addTrack(const QVector<QPointF> &track);
|
||||||
void addWaypoints(const QList<Waypoint> &waypoints);
|
void addWaypoints(const QList<Waypoint> &waypoints);
|
||||||
|
void addPOI(const QVector<Waypoint> &waypoints);
|
||||||
|
|
||||||
QRectF trackBoundingRect() const;
|
QRectF trackBoundingRect() const;
|
||||||
QRectF waypointBoundingRect() const;
|
QRectF waypointBoundingRect() const;
|
||||||
@ -63,11 +64,13 @@ private:
|
|||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
|
|
||||||
QGraphicsScene *_scene;
|
QGraphicsScene *_scene;
|
||||||
QList<QVector<QPointF> > _tracks;
|
QList<QGraphicsPathItem*> _paths;
|
||||||
QList<QGraphicsPathItem*> _trackPaths;
|
|
||||||
QList<WaypointItem*> _waypoints;
|
|
||||||
QList<MarkerItem*> _markers;
|
QList<MarkerItem*> _markers;
|
||||||
|
QList<WaypointItem*> _locations;
|
||||||
QHash<Waypoint, WaypointItem*> _pois;
|
QHash<Waypoint, WaypointItem*> _pois;
|
||||||
|
QList<QVector<QPointF> > _tracks;
|
||||||
|
QVector<QPointF> _waypoints;
|
||||||
|
|
||||||
Map *_map;
|
Map *_map;
|
||||||
ScaleItem *_mapScale;
|
ScaleItem *_mapScale;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user