From d85fbe5b48df534b7818926b068e94158f4c4f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 6 Jul 2017 09:37:44 +0200 Subject: [PATCH] Do not duplicate Waypoints in POI search structures --- gpxsee.pro | 3 ++- src/pathview.cpp | 24 ++++++++++++------------ src/pathview.h | 3 ++- src/searchpointer.h | 24 ++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 src/searchpointer.h diff --git a/gpxsee.pro b/gpxsee.pro index 40b65ac6..70f6d8e1 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -95,7 +95,8 @@ HEADERS += src/config.h \ src/maplist.h \ src/albersequal.h \ src/oddspinbox.h \ - src/rectc.h + src/rectc.h \ + src/searchpointer.h SOURCES += src/main.cpp \ src/gui.cpp \ src/poi.cpp \ diff --git a/src/pathview.cpp b/src/pathview.cpp index 5baf2c93..3c99f08f 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -22,7 +22,7 @@ #define SCALE_OFFSET 7 PathView::PathView(Map *map, POI *poi, QWidget *parent) - : QGraphicsView(parent) +: QGraphicsView(parent) { Q_ASSERT(map != 0); Q_ASSERT(poi != 0); @@ -195,7 +195,7 @@ QPointF PathView::contentCenter() const void PathView::updatePOIVisibility() { - QHash::const_iterator it, jt; + QHash, WaypointItem*>::const_iterator it, jt; if (!_showPOI) return; @@ -226,7 +226,7 @@ void PathView::rescale() for (int i = 0; i < _waypoints.size(); i++) _waypoints.at(i)->setMap(_map); - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) it.value()->setMap(_map); @@ -269,7 +269,7 @@ void PathView::setMap(Map *map) for (int i = 0; i < _waypoints.size(); i++) _waypoints.at(i)->setMap(map); - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) it.value()->setMap(_map); updatePOIVisibility(); @@ -296,7 +296,7 @@ void PathView::setPOI(POI *poi) void PathView::updatePOI() { - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) { _scene->removeItem(it.value()); @@ -318,7 +318,7 @@ void PathView::addPOI(const QVector &waypoints) for (int i = 0; i < waypoints.size(); i++) { const Waypoint &w = waypoints.at(i); - if (_pois.contains(w)) + if (_pois.contains(SearchPointer(&w))) continue; WaypointItem *pi = new WaypointItem(w, _map); @@ -328,7 +328,7 @@ void PathView::addPOI(const QVector &waypoints) pi->setDigitalZoom(_digitalZoom); _scene->addItem(pi); - _pois.insert(w, pi); + _pois.insert(SearchPointer(&(pi->waypoint())), pi); } } @@ -345,7 +345,7 @@ void PathView::setUnits(enum Units units) for (int i = 0; i < _waypoints.size(); i++) _waypoints.at(i)->setUnits(units); - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) it.value()->setUnits(units); } @@ -357,7 +357,7 @@ void PathView::redraw() void PathView::resetDigitalZoom() { - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; _digitalZoom = 0; resetTransform(); @@ -376,7 +376,7 @@ void PathView::resetDigitalZoom() void PathView::digitalZoom(int zoom) { - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; _digitalZoom += zoom; scale(pow(2, zoom), pow(2, zoom)); @@ -580,7 +580,7 @@ void PathView::showPOI(bool show) { _showPOI = show; - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) it.value()->setVisible(show); @@ -591,7 +591,7 @@ void PathView::showPOILabels(bool show) { _showPOILabels = show; - QHash::const_iterator it; + QHash, WaypointItem*>::const_iterator it; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) it.value()->showLabel(show); diff --git a/src/pathview.h b/src/pathview.h index 973f6b15..56453df4 100644 --- a/src/pathview.h +++ b/src/pathview.h @@ -9,6 +9,7 @@ #include "palette.h" #include "waypoint.h" #include "rectc.h" +#include "searchpointer.h" class Data; class POI; @@ -96,7 +97,7 @@ private: QList _tracks; QList _routes; QList _waypoints; - QHash _pois; + QHash, WaypointItem*> _pois; RectC _tr, _rr, _wr; qreal _res; diff --git a/src/searchpointer.h b/src/searchpointer.h new file mode 100644 index 00000000..5504061d --- /dev/null +++ b/src/searchpointer.h @@ -0,0 +1,24 @@ +#ifndef SEARCHPOINTER_H +#define SEARCHPOINTER_H + +template +class SearchPointer +{ +public: + SearchPointer(const T *ptr) : _ptr(ptr) {} + + const T *data() const {return _ptr;} + bool operator==(const SearchPointer &other) const + {return *data() == *(other.data());} + +private: + const T *_ptr; +}; + +template +inline uint qHash(const SearchPointer &t) +{ + return ::qHash(*(t.data())); +} + +#endif // SEARCHPOINTER_H