mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Do not duplicate Waypoints in POI search structures
This commit is contained in:
parent
141e0cb404
commit
d85fbe5b48
@ -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 \
|
||||
|
@ -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<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint> &waypoints)
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
const Waypoint &w = waypoints.at(i);
|
||||
|
||||
if (_pois.contains(w))
|
||||
if (_pois.contains(SearchPointer<Waypoint>(&w)))
|
||||
continue;
|
||||
|
||||
WaypointItem *pi = new WaypointItem(w, _map);
|
||||
@ -328,7 +328,7 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
|
||||
pi->setDigitalZoom(_digitalZoom);
|
||||
_scene->addItem(pi);
|
||||
|
||||
_pois.insert(w, pi);
|
||||
_pois.insert(SearchPointer<Waypoint>(&(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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
|
||||
_digitalZoom = 0;
|
||||
resetTransform();
|
||||
@ -376,7 +376,7 @@ void PathView::resetDigitalZoom()
|
||||
|
||||
void PathView::digitalZoom(int zoom)
|
||||
{
|
||||
QHash<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, 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<Waypoint, WaypointItem*>::const_iterator it;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
it.value()->showLabel(show);
|
||||
|
||||
|
@ -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<TrackItem*> _tracks;
|
||||
QList<RouteItem*> _routes;
|
||||
QList<WaypointItem*> _waypoints;
|
||||
QHash<Waypoint, WaypointItem*> _pois;
|
||||
QHash<SearchPointer<Waypoint>, WaypointItem*> _pois;
|
||||
|
||||
RectC _tr, _rr, _wr;
|
||||
qreal _res;
|
||||
|
24
src/searchpointer.h
Normal file
24
src/searchpointer.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef SEARCHPOINTER_H
|
||||
#define SEARCHPOINTER_H
|
||||
|
||||
template <class T>
|
||||
class SearchPointer
|
||||
{
|
||||
public:
|
||||
SearchPointer(const T *ptr) : _ptr(ptr) {}
|
||||
|
||||
const T *data() const {return _ptr;}
|
||||
bool operator==(const SearchPointer<T> &other) const
|
||||
{return *data() == *(other.data());}
|
||||
|
||||
private:
|
||||
const T *_ptr;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline uint qHash(const SearchPointer<T> &t)
|
||||
{
|
||||
return ::qHash(*(t.data()));
|
||||
}
|
||||
|
||||
#endif // SEARCHPOINTER_H
|
Loading…
Reference in New Issue
Block a user