summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-08 21:35:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-11 12:06:19 -0700
commit0c387549164d7eec3ea6647c54ada2fba7f8d5e6 (patch)
treedf8b9fe2c494f38ba6cd035c809e1bd89c66cedb /qt-models
parent29c6aea797f96e59eae621df3b35b4fd0f260e3f (diff)
downloadsubsurface-0c387549164d7eec3ea6647c54ada2fba7f8d5e6.tar.gz
Map: construct list of dive sites from dive site table
Instead of looping over the dive table and extract dive sites, loop over the dive site table. This makes it possible to show dive sites that have no dive associated with them. But we have to create to functions that check whether a dive site has any shown dives or has any selected dives. Moreover, change the code to add near dive sites of the same name if in edit mode. Other wise (erroneously added?) dive sites with the same name cannot be moved on the map. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/maplocationmodel.cpp53
1 files changed, 31 insertions, 22 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 1fdedf807..4cad06801 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: GPL-2.0
-#include <QDebug>
#include "maplocationmodel.h"
#include "core/divesite.h"
#ifndef SUBSURFACE_MOBILE
#include "qt-models/filtermodels.h"
#endif
+#include <QDebug>
+#include <algorithm>
+
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
const char *MapLocation::PROPERTY_NAME_DIVESITE = "divesite";
const char *MapLocation::PROPERTY_NAME_NAME = "name";
@@ -115,11 +117,20 @@ const QVector<dive_site *> &MapLocationModel::selectedDs() const
return m_selectedDs;
}
-void MapLocationModel::reload()
+static bool hasVisibleDive(const dive_site *ds)
+{
+ return std::any_of(&ds->dives.dives[0], &ds->dives.dives[ds->dives.nr],
+ [] (const dive *d) { return !d->hidden_by_filter; });
+}
+
+static bool hasSelectedDive(const dive_site *ds)
{
- int idx;
- struct dive *dive;
+ return std::any_of(&ds->dives.dives[0], &ds->dives.dives[ds->dives.nr],
+ [] (const dive *d) { return d->selected; });
+}
+void MapLocationModel::reload()
+{
beginResetModel();
qDeleteAll(m_mapLocations);
@@ -128,7 +139,6 @@ void MapLocationModel::reload()
QMap<QString, MapLocation *> locationNameMap;
MapLocation *location;
- QVector<struct dive_site *> locations;
qreal latitude, longitude;
#ifdef SUBSURFACE_MOBILE
@@ -142,34 +152,33 @@ void MapLocationModel::reload()
if (diveSiteMode)
m_selectedDs = MultiFilterSortModel::instance()->filteredDiveSites();
#endif
- for_each_dive(idx, dive) {
- // Don't show dive sites of hidden dives, unless this is the currently
- // displayed (edited) dive or we're in dive site edit mode.
- if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive)
+ for (int i = 0; i < dive_site_table.nr; ++i) {
+ struct dive_site *ds = dive_site_table.dive_sites[i];
+
+ // Don't show dive sites of hidden dives, unless we're in dive site edit mode.
+ if (!diveSiteMode && !hasVisibleDive(ds))
continue;
- struct dive_site *ds = get_dive_site_for_dive(dive);
if (!dive_site_has_gps_location(ds))
continue;
- if (!diveSiteMode && dive->selected && !m_selectedDs.contains(ds))
+ if (!diveSiteMode && hasSelectedDive(ds) && !m_selectedDs.contains(ds))
m_selectedDs.append(ds);
- if (locations.contains(ds))
- continue;
latitude = ds->location.lat.udeg * 0.000001;
longitude = ds->location.lon.udeg * 0.000001;
QGeoCoordinate dsCoord(latitude, longitude);
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.contains(name)) {
- MapLocation *existingLocation = locationNameMap[name];
- QGeoCoordinate coord = existingLocation->coordinate();
- if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
- continue;
+ if (!diveSiteMode) {
+ // don't add dive locations with the same name, unless they are
+ // at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
+ if (locationNameMap.contains(name)) {
+ MapLocation *existingLocation = locationNameMap[name];
+ QGeoCoordinate coord = existingLocation->coordinate();
+ if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
+ continue;
+ }
+ locationNameMap[name] = location;
}
location = new MapLocation(ds, dsCoord, name);
m_mapLocations.append(location);
- locations.append(ds);
- locationNameMap[name] = location;
}
endResetModel();