diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-08 22:15:01 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-11 12:06:19 -0700 |
commit | 0da86dfd8601edd33c47c787d42e4a687fff8aaf (patch) | |
tree | 3cb8c6b9acc358e17e1bb6e5b34c17b813f2bf7b /qt-models/maplocationmodel.cpp | |
parent | 0c387549164d7eec3ea6647c54ada2fba7f8d5e6 (diff) | |
download | subsurface-0da86dfd8601edd33c47c787d42e4a687fff8aaf.tar.gz |
Map: in edit mode place no-gps dive sites at center of map
Move the code to add the first selected dive site from
MapWidgetHelper::enterEditMode() to MapLocationModel::reload().
Thus, the list of sites is built only at one place. For this
it is necessary to pass a pointer to the map, so that new
dive sites can be added at the center of the map.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/maplocationmodel.cpp')
-rw-r--r-- | qt-models/maplocationmodel.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
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 |