diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-08-31 21:45:31 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-08-31 18:43:43 -0700 |
commit | 1ef20ee5d8b13a5413ec5aabf16aaa1f1bdd65fd (patch) | |
tree | a3606c0fec918f5e1c51bf4c2f0b7ba2c3f0dfe0 | |
parent | e36e4d1faa95439a1806935de6dcbd04d2283d20 (diff) | |
download | subsurface-1ef20ee5d8b13a5413ec5aabf16aaa1f1bdd65fd.tar.gz |
Merge the dive sites selected.
Wee. :)
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | divesite.c | 21 | ||||
-rw-r--r-- | divesite.h | 2 | ||||
-rw-r--r-- | qt-ui/locationinformation.cpp | 2 |
3 files changed, 22 insertions, 3 deletions
diff --git a/divesite.c b/divesite.c index 2b5c48849..96c41d1bf 100644 --- a/divesite.c +++ b/divesite.c @@ -1,6 +1,7 @@ /* divesite.c */ #include "divesite.h" #include "dive.h" +#include "divelist.h" #include <math.h> @@ -276,9 +277,27 @@ void clear_dive_site(struct dive_site *ds) free_taxonomy(&ds->taxonomy); } -void merge_dive_sites(uint32_t* uuids, int count) +void merge_dive_sites(uint32_t ref, uint32_t* uuids, int count) { + int curr_dive, i; + struct dive *d; + for(i = 0; i < count; i++){ + if (uuids[i] == ref) + continue; + + for_each_dive(curr_dive, d) { + if (d->dive_site_uuid != uuids[i] ) + continue; + d->dive_site_uuid = ref; + } + } + for(int i = 0; i < count; i++) { + if (uuids[i] == ref) + continue; + delete_dive_site(uuids[i]); + } + mark_divelist_changed(true); } uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime) diff --git a/divesite.h b/divesite.h index 154788460..345b50448 100644 --- a/divesite.h +++ b/divesite.h @@ -66,7 +66,7 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy); void clear_dive_site(struct dive_site *ds); unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2); uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); -void merge_dive_sites(uint32_t *uuids, int count); +void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count); #define INVALID_DIVE_SITE_NAME "development use only - not a valid dive site name" diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index d029dd2a1..9e2821ceb 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -70,7 +70,7 @@ void LocationInformationWidget::mergeSelectedDiveSites() { Q_FOREACH(const QModelIndex& idx, selection) { selected_dive_sites[i] = (uint32_t) idx.data(LocationInformationModel::UUID_ROLE).toInt(); } - merge_dive_sites(selected_dive_sites, i); + merge_dive_sites(displayed_dive_site.uuid, selected_dive_sites, i); free(selected_dive_sites); } |