diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-07-27 23:49:28 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-28 07:31:11 -0700 |
commit | 5e57e428748d8c9876dc607ba32bafafb33e797d (patch) | |
tree | 81e8c074b50b3eae1bbbd564543bcceade0bcf35 /mobile-widgets | |
parent | ff4924f650361695587e750fc4c3713107b94cfa (diff) | |
download | subsurface-5e57e428748d8c9876dc607ba32bafafb33e797d.tar.gz |
mapwidgethelper: add the same logic for markers as in globe.cpp
The marble globe tracks dive sites with the same name and discards
such that are less than 50 meters apart.
We already store names in MapLocation objects, but using a
QMap<QString, MapLocation *> to check the names is probably faster
with the expense of using more memory.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qmlmapwidgethelper.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp index 7a17feaa0..81c92e708 100644 --- a/mobile-widgets/qmlmapwidgethelper.cpp +++ b/mobile-widgets/qmlmapwidgethelper.cpp @@ -37,26 +37,38 @@ void MapWidgetHelper::reloadMapLocations() {
struct dive_site *ds;
int idx;
+ QMap<QString, MapLocation *> locationNameMap;
m_mapLocationModel->clear();
+ MapLocation *location;
QVector<MapLocation *> locationList;
+ qreal latitude, longitude;
+ if (displayed_dive_site.uuid && dive_site_has_gps_location(&displayed_dive_site)) {
+ latitude = displayed_dive_site.latitude.udeg * 0.000001;
+ longitude = displayed_dive_site.longitude.udeg * 0.000001;
+ location = new MapLocation(displayed_dive_site.uuid, QGeoCoordinate(latitude, longitude),
+ QString(displayed_dive_site.name));
+ locationList.append(location);
+ locationNameMap[QString(displayed_dive_site.name)] = location;
+ }
for_each_dive_site(idx, ds) {
- if (!dive_site_has_gps_location(ds))
+ if (!dive_site_has_gps_location(ds) || ds->uuid == displayed_dive_site.uuid)
continue;
- const qreal latitude = ds->latitude.udeg * 0.000001;
- const qreal longitude = ds->longitude.udeg * 0.000001;
+ latitude = ds->latitude.udeg * 0.000001;
+ longitude = ds->longitude.udeg * 0.000001;
QGeoCoordinate dsCoord(latitude, longitude);
- // check if there are no locations too close to the current dive site
- bool diveSiteTooClose = false;
- foreach(MapLocation *location, locationList) {
- QGeoCoordinate coord = qvariant_cast<QGeoCoordinate>(location->getRole(MapLocation::Roles::RoleCoordinate));
- if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M) {
- diveSiteTooClose = true;
- break;
- }
+ QString name(ds->name);
+ // don't add dive locations with the same name, unless they are
+ // at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
+ if (locationNameMap[name]) {
+ MapLocation *existingLocation = locationNameMap[name];
+ QGeoCoordinate coord = qvariant_cast<QGeoCoordinate>(existingLocation->getRole(MapLocation::Roles::RoleCoordinate));
+ if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
+ continue;
}
- if (!diveSiteTooClose)
- locationList.append(new MapLocation(ds->uuid, QGeoCoordinate(latitude, longitude), QString(ds->name)));
+ location = new MapLocation(ds->uuid, dsCoord, name);
+ locationList.append(location);
+ locationNameMap[name] = location;
}
m_mapLocationModel->addList(locationList);
}
|