diff options
-rw-r--r-- | core/divesite.c | 12 | ||||
-rw-r--r-- | core/divesite.h | 2 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 13 |
3 files changed, 14 insertions, 13 deletions
diff --git a/core/divesite.c b/core/divesite.c index d20421de7..79902d1ef 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -309,26 +309,26 @@ void clear_dive_site(struct dive_site *ds) free_taxonomy(&ds->taxonomy); } -void merge_dive_sites(uint32_t ref, uint32_t* uuids, int count) +void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count) { int curr_dive, i; struct dive *d; for(i = 0; i < count; i++){ - if (uuids[i] == ref) + if (dive_sites[i] == ref) continue; for_each_dive(curr_dive, d) { - if (d->dive_site_uuid != uuids[i] ) + if (d->dive_site_uuid != dive_sites[i]->uuid ) continue; - d->dive_site_uuid = ref; + d->dive_site_uuid = ref->uuid; invalidate_dive_cache(d); } } for(i = 0; i < count; i++) { - if (uuids[i] == ref) + if (dive_sites[i] == ref) continue; - delete_dive_site(get_dive_site_by_uuid(uuids[i])); + delete_dive_site(dive_sites[i]); } mark_divelist_changed(true); } diff --git a/core/divesite.h b/core/divesite.h index 7ea7c53cc..895412a4b 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -72,7 +72,7 @@ void merge_dive_site(struct dive_site *a, struct dive_site *b); void clear_dive_site(struct dive_site *ds); unsigned int get_distance(const location_t *loc1, const location_t *loc2); struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); -void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count); +void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count); #ifdef __cplusplus } diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 9d3eccb02..e24da5f7f 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -80,17 +80,18 @@ void LocationInformationWidget::mergeSelectedDiveSites() return; QModelIndexList selection = ui.diveSiteListView->selectionModel()->selectedIndexes(); - uint32_t *selected_dive_sites = (uint32_t *)malloc(sizeof(uint32_t) * selection.count()); - int i = 0; + // std::vector guarantees contiguous storage and can therefore be passed to C-code + std::vector<struct dive_site *> selected_dive_sites; + selected_dive_sites.reserve(selection.count()); Q_FOREACH (const QModelIndex &idx, selection) { - selected_dive_sites[i] = (uint32_t)idx.data(LocationInformationModel::UUID_ROLE).toInt(); - i++; + struct dive_site *ds = get_dive_site_by_uuid(idx.data(LocationInformationModel::UUID_ROLE).toUInt()); + if (ds) + selected_dive_sites.push_back(ds); } - merge_dive_sites(diveSite->uuid, selected_dive_sites, i); + merge_dive_sites(diveSite, selected_dive_sites.data(), (int)selected_dive_sites.size()); LocationInformationModel::instance()->update(); QSortFilterProxyModel *m = (QSortFilterProxyModel *)ui.diveSiteListView->model(); m->invalidate(); - free(selected_dive_sites); } void LocationInformationWidget::updateLabels() |