aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--map-widget/qmlmapwidgethelper.cpp10
-rw-r--r--qt-models/maplocationmodel.cpp21
-rw-r--r--qt-models/maplocationmodel.h3
3 files changed, 17 insertions, 17 deletions
diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp
index a7ef00bf8..9aba7f27a 100644
--- a/map-widget/qmlmapwidgethelper.cpp
+++ b/map-widget/qmlmapwidgethelper.cpp
@@ -100,7 +100,7 @@ void MapWidgetHelper::reloadMapLocations()
else
exitEditMode();
#endif
- m_mapLocationModel->reload();
+ m_mapLocationModel->reload(m_map);
}
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
@@ -239,14 +239,6 @@ void MapWidgetHelper::enterEditMode()
return;
m_editMode = true;
- // if divesite of the first selected dive doesn't exist in the model, add a new MapLocation.
- const QVector<dive_site *> selDs = m_mapLocationModel->selectedDs();
- if (!selDs.isEmpty() && ! m_mapLocationModel->getMapLocation(selDs[0])) {
- // If the dive site doesn't have a GPS location, use the centre of the map
- QGeoCoordinate coord = has_location(&selDs[0]->location) ? getCoordinates(selDs[0])
- : m_map->property("center").value<QGeoCoordinate>();
- m_mapLocationModel->add(new MapLocation(selDs[0], coord, QString(selDs[0]->name)));
- }
emit editModeChanged();
}
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 4cad06801..295f514eb 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -129,7 +129,7 @@ static bool hasSelectedDive(const dive_site *ds)
[] (const dive *d) { return d->selected; });
}
-void MapLocationModel::reload()
+void MapLocationModel::reload(QObject *map)
{
beginResetModel();
@@ -139,7 +139,6 @@ void MapLocationModel::reload()
QMap<QString, MapLocation *> locationNameMap;
MapLocation *location;
- qreal latitude, longitude;
#ifdef SUBSURFACE_MOBILE
bool diveSiteMode = false;
@@ -154,17 +153,25 @@ void MapLocationModel::reload()
#endif
for (int i = 0; i < dive_site_table.nr; ++i) {
struct dive_site *ds = dive_site_table.dive_sites[i];
+ QGeoCoordinate dsCoord;
// Don't show dive sites of hidden dives, unless we're in dive site edit mode.
if (!diveSiteMode && !hasVisibleDive(ds))
continue;
- if (!dive_site_has_gps_location(ds))
- continue;
+ if (!dive_site_has_gps_location(ds)) {
+ // Dive sites that do not have a gps location are not shown in normal mode.
+ // In dive-edit mode, selected sites are placed at the center of the map,
+ // so that the user can drag them somewhere without having to enter coordinates.
+ if (!diveSiteMode || !m_selectedDs.contains(ds) || !map)
+ continue;
+ dsCoord = map->property("center").value<QGeoCoordinate>();
+ } else {
+ qreal latitude = ds->location.lat.udeg * 0.000001;
+ qreal longitude = ds->location.lon.udeg * 0.000001;
+ dsCoord = QGeoCoordinate(latitude, longitude);
+ }
if (!diveSiteMode && hasSelectedDive(ds) && !m_selectedDs.contains(ds))
m_selectedDs.append(ds);
- latitude = ds->location.lat.udeg * 0.000001;
- longitude = ds->location.lon.udeg * 0.000001;
- QGeoCoordinate dsCoord(latitude, longitude);
QString name(ds->name);
if (!diveSiteMode) {
// don't add dive locations with the same name, unless they are
diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h
index b1b13896a..404c76d4a 100644
--- a/qt-models/maplocationmodel.h
+++ b/qt-models/maplocationmodel.h
@@ -60,7 +60,8 @@ public:
int rowCount(const QModelIndex &parent) const override;
int count();
void add(MapLocation *);
- void reload();
+ // If map is not null, it will be used to place new dive sites without GPS location at the center of the map
+ void reload(QObject *map);
MapLocation *getMapLocation(const struct dive_site *ds);
const QVector<dive_site *> &selectedDs() const;
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);