mapwidgethelper: obtain a list of nearby dives

Based on a current location (MapLocation), iterate the dive list
and add nearby dives (distance smaller than m_smallCircleRadius) to
a local QList property (m_selectedDiveIds).

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-07-24 21:15:23 +03:00 committed by Dirk Hohndel
parent 5ea702199b
commit 50f42cfdef
2 changed files with 17 additions and 1 deletions

View file

@ -59,7 +59,22 @@ void MapWidgetHelper::reloadMapLocations()
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
{
qDebug() << location;
int idx;
struct dive *dive;
m_selectedDiveIds.clear();
QGeoCoordinate locationCoord = qvariant_cast<QGeoCoordinate>(location->getRole(MapLocation::Roles::RoleCoordinate));
for_each_dive (idx, dive) {
struct dive_site *ds = get_dive_site_for_dive(dive);
if (!dive_site_has_gps_location(ds))
continue;
const qreal latitude = ds->latitude.udeg * 0.000001;
const qreal longitude = ds->longitude.udeg * 0.000001;
QGeoCoordinate dsCoord(latitude, longitude);
if (locationCoord.distanceTo(dsCoord) < m_smallCircleRadius)
m_selectedDiveIds.append(idx);
}
qDebug() << "selectedDiveIds:" << m_selectedDiveIds;
}
/*

View file

@ -27,6 +27,7 @@ private:
QObject *m_map;
MapLocationModel *m_mapLocationModel;
qreal m_smallCircleRadius;
QList<int> m_selectedDiveIds;
private slots:
void selectedLocationChanged(MapLocation *);