map-widget: add support for filtering of map locations

If the dive list is filtered the map should hide dive locations
that do not match the dive list filter.

To achieve that, loop over dives instead of dive sites in
MapWidgetHelper::reloadMapLocations() and discard
dives that are hidden by the filter. Then check if a dive
has a dive site attached to it and re-use the old functionality.

Suggested-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2018-08-17 20:37:30 +03:00 committed by bstoeger
parent 7cf05897a2
commit b4f10553cc

View file

@ -116,12 +116,13 @@ void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
void MapWidgetHelper::reloadMapLocations()
{
struct dive_site *ds;
int idx;
struct dive *dive;
QMap<QString, MapLocation *> locationNameMap;
m_mapLocationModel->clear();
MapLocation *location;
QVector<MapLocation *> locationList;
QVector<uint32_t> locationUuids;
qreal latitude, longitude;
if (displayed_dive_site.uuid && dive_site_has_gps_location(&displayed_dive_site)) {
@ -132,8 +133,11 @@ void MapWidgetHelper::reloadMapLocations()
locationList.append(location);
locationNameMap[QString(displayed_dive_site.name)] = location;
}
for_each_dive_site(idx, ds) {
if (!dive_site_has_gps_location(ds) || ds->uuid == displayed_dive_site.uuid)
for_each_dive(idx, dive) {
if (dive->hidden_by_filter)
continue;
struct dive_site *ds = get_dive_site_for_dive(dive);
if (!dive_site_has_gps_location(ds) || ds->uuid == displayed_dive_site.uuid || locationUuids.contains(ds->uuid))
continue;
latitude = ds->latitude.udeg * 0.000001;
longitude = ds->longitude.udeg * 0.000001;
@ -149,6 +153,7 @@ void MapWidgetHelper::reloadMapLocations()
}
location = new MapLocation(ds->uuid, dsCoord, name);
locationList.append(location);
locationUuids.append(ds->uuid);
locationNameMap[name] = location;
}
m_mapLocationModel->addList(locationList);