diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2015-06-03 23:00:58 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-03 21:33:28 -0700 |
commit | 34b406556d083d9015cae9e553d6763a78fbd9cf (patch) | |
tree | 1d5bf76379ed8fbd61061ccd8b3f98d9c4bb9450 /qt-ui/globe.cpp | |
parent | fa373fd5444a8d72782424db5ba301d1b678821d (diff) | |
download | subsurface-34b406556d083d9015cae9e553d6763a78fbd9cf.tar.gz |
Use for_each_dive_site to populate the dives in the globe
When we didn't have a proper dive_site_table, the dive sites where
scattered across all dives and so we looped over all dives to find the
dive sites and add them to the tree. Now this is a bit cleaner, a bit
faster.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/globe.cpp')
-rw-r--r-- | qt-ui/globe.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index 3dc5c99ce..f75e582fc 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -187,29 +187,19 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) void GlobeGPS::repopulateLabels() { + if (!current_dive) + return; + struct dive_site *ds; + int idx; + QMap<QString, GeoDataPlacemark *> locationMap; if (loadedDives) { model()->treeModel()->removeDocument(loadedDives); delete loadedDives; } loadedDives = new GeoDataDocument; - QMap<QString, GeoDataPlacemark *> locationMap; - int idx = -2; - struct dive *dive; - // normally we use for_each_dive (idx, dive) to loop over all dives, - // but we need to include the displayed_dive while things are - // edited, so let's hand roll this loop - while (++idx < dive_table.nr) { - dive = (idx == -1 ? &displayed_dive : get_dive(idx)); - if (dive == current_dive) - // don't show that flag, it's either already shown as displayed_dive - // or it's the one that we are moving right now... - continue; - if (idx == -1) - ds = &displayed_dive_site; - else - ds = get_dive_site_for_dive(dive); + for_each_dive_site(idx, ds) { if (dive_site_has_gps_location(ds)) { GeoDataPlacemark *place = new GeoDataPlacemark(ds->name); place->setCoordinate(ds->longitude.udeg / 1000000.0, ds->latitude.udeg / 1000000.0, 0, GeoDataCoordinates::Degree); @@ -230,8 +220,12 @@ void GlobeGPS::repopulateLabels() loadedDives->append(place); } } + model()->treeModel()->addDocument(loadedDives); - centerOn(displayed_dive_site.longitude.udeg / 1000000.0, displayed_dive_site.latitude.udeg / 1000000.0, true); + struct dive_site *center = displayed_dive_site.uuid != 0 ? + &displayed_dive_site : get_dive_site_by_uuid(current_dive->dive_site_uuid); + if(center) + centerOn(displayed_dive_site.longitude.udeg / 1000000.0, displayed_dive_site.latitude.udeg / 1000000.0, true); } void GlobeGPS::reload() |