From 98c4242f31b99c8ad48d7140edb45b5c14da617f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 8 Jun 2024 14:33:30 +0200 Subject: [PATCH] fix divetable to owning Signed-off-by: Berthold Stoeger --- backend-shared/exportfuncs.cpp | 10 +- commands/command_base.cpp | 2 +- commands/command_divelist.cpp | 26 +++--- commands/command_edit.cpp | 4 +- core/cochran.cpp | 6 +- core/datatrak.cpp | 4 +- core/dive.cpp | 8 +- core/divefilter.cpp | 14 +-- core/divelist.cpp | 98 ++++++++++---------- core/divelog.cpp | 21 ++--- core/divelog.h | 6 +- core/downloadfromdcthread.cpp | 4 +- core/equipment.cpp | 2 +- core/fulltext.cpp | 6 +- core/import-csv.cpp | 4 +- core/libdivecomputer.cpp | 6 +- core/liquivision.cpp | 6 +- core/load-git.cpp | 2 +- core/ostctools.cpp | 2 +- core/parse.cpp | 4 +- core/picture.cpp | 4 +- core/qthelper.cpp | 4 +- core/save-git.cpp | 8 +- core/save-html.cpp | 4 +- core/save-profiledata.cpp | 2 +- core/save-xml.cpp | 4 +- core/selection.cpp | 20 ++-- core/statistics.cpp | 6 +- core/string-format.cpp | 2 +- core/trip.cpp | 2 +- core/uemis-downloader.cpp | 56 +++++------ core/uploadDiveLogsDE.cpp | 2 +- core/worldmap-save.cpp | 2 +- desktop-widgets/downloadfromdivecomputer.cpp | 2 +- desktop-widgets/findmovedimagesdialog.cpp | 2 +- desktop-widgets/mainwindow.cpp | 2 +- desktop-widgets/printer.cpp | 4 +- desktop-widgets/simplewidgets.cpp | 2 +- map-widget/qmlmapwidgethelper.cpp | 4 +- mobile-widgets/qmlmanager.cpp | 34 +++---- profile-widget/qmlprofile.cpp | 6 +- qt-models/completionmodels.cpp | 4 +- qt-models/diveimportedmodel.cpp | 26 +++--- qt-models/diveplannermodel.cpp | 4 +- qt-models/divesummarymodel.cpp | 5 +- qt-models/divetripmodel.cpp | 8 +- smtk-import/smartrak.cpp | 4 +- stats/statsvariables.cpp | 2 +- tests/testparse.cpp | 38 ++++---- tests/testrenumber.cpp | 4 +- 50 files changed, 249 insertions(+), 253 deletions(-) diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index 33beedbe7..d0f0a2ec9 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -62,10 +62,10 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb) filename = filename.append(".png"); QFileInfo fi(filename); - int todo = selected_only ? amount_selected : static_cast(divelog.dives->size()); + int todo = selected_only ? amount_selected : static_cast(divelog.dives.size()); int done = 0; auto profile = getPrintProfile(); - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (cb.canceled()) return; if (selected_only && !dive->selected) @@ -129,10 +129,10 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall put_format(&buf, "\n%%%%%%%%%% Begin Dive Data: %%%%%%%%%%\n"); - int todo = selected_only ? amount_selected : static_cast(divelog.dives->size()); + int todo = selected_only ? amount_selected : static_cast(divelog.dives.size()); int done = 0; auto profile = getPrintProfile(); - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (cb.canceled()) return; if (selected_only && !dive->selected) @@ -269,7 +269,7 @@ void export_depths(const char *filename, bool selected_only) membuffer buf; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (selected_only && !dive->selected) continue; diff --git a/commands/command_base.cpp b/commands/command_base.cpp index 7072951e9..447ffc9b9 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -66,7 +66,7 @@ QString diveNumberOrDate(struct dive *d) QString getListOfDives(const std::vector &dives) { QString listOfDives; - if (dives.size() == divelog.dives->size()) + if (dives.size() == divelog.dives.size()) return Base::tr("all dives"); int i = 0; for (dive *d: dives) { diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index eeb827df9..16880587d 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -44,13 +44,13 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vectorget_idx(d); + size_t idx = divelog.dives.get_idx(d); if (idx == std::string::npos) qWarning("Deletion of unknown dive!"); DiveFilter::instance()->diveRemoved(d); - res.dive = std::move(divelog.dives->unregister_dive(idx)); // Remove dive from backend + res.dive = std::move(divelog.dives.unregister_dive(idx)); // Remove dive from backend return res; } @@ -417,7 +417,7 @@ AddDive::AddDive(dive *d, bool autogroup, bool newNumber) allocTrip = std::move(allocated); } - int idx = divelog.dives->get_insertion_index(divePtr.get()); + int idx = divelog.dives.get_insertion_index(divePtr.get()); if (newNumber) divePtr->number = get_dive_nr_at_idx(idx); @@ -456,7 +456,7 @@ void AddDive::undoit() ImportDives::ImportDives(struct divelog *log, int flags, const QString &source) { - setText(Command::Base::tr("import %n dive(s) from %1", "", log->dives->size()).arg(source)); + setText(Command::Base::tr("import %n dive(s) from %1", "", log->dives.size()).arg(source)); // this only matters if undoit were called before redoit currentDive = nullptr; @@ -621,7 +621,7 @@ void ShiftTime::redoit() } // Changing times may have unsorted the dive and trip tables - divelog.dives->sort(); + divelog.dives.sort(); divelog.trips->sort(); for (dive_trip *trip: trips) trip->sort_dives(); @@ -728,7 +728,7 @@ RemoveAutogenTrips::RemoveAutogenTrips() { setText(Command::Base::tr("remove autogenerated trips")); // TODO: don't touch core-innards directly - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (d->divetrip && d->divetrip->autogen) divesToMove.divesToMove.push_back( {d.get(), nullptr} ); } @@ -758,11 +758,11 @@ AutogroupDives::AutogroupDives() { setText(Command::Base::tr("autogroup dives")); - for (auto &entry: get_dives_to_autogroup(*divelog.dives)) { + for (auto &entry: get_dives_to_autogroup(divelog.dives)) { // If this is an allocated trip, take ownership if (entry.created_trip) divesToMove.tripsToAdd.push_back(std::move(entry.created_trip)); - for (auto it = divelog.dives->begin() + entry.from; it != divelog.dives->begin() + entry.to; ++it) + for (auto it = divelog.dives.begin() + entry.from; it != divelog.dives.begin() + entry.to; ++it) divesToMove.divesToMove.push_back( { it->get(), entry.trip } ); } } @@ -951,7 +951,7 @@ MergeDives::MergeDives(const QVector &dives) // We will only renumber the remaining dives if the joined dives are consecutive. // Otherwise all bets are off concerning what the user wanted and doing nothing seems // like the best option. - size_t idx = divelog.dives->get_idx(dives[0]); + size_t idx = divelog.dives.get_idx(dives[0]); size_t num = dives.count(); if (idx == std::string::npos) { // It was the callers responsibility to pass only known dives. @@ -961,7 +961,7 @@ MergeDives::MergeDives(const QVector &dives) } // std::equal compares two ranges. The parameters are (begin_range1, end_range1, begin_range2). // Here, we can compare C-arrays, because QVector guarantees contiguous storage. - if (std::equal(&dives[0], &dives[0] + num, divelog.dives->begin() + idx, [](dive *d1, + if (std::equal(&dives[0], &dives[0] + num, divelog.dives.begin() + idx, [](dive *d1, const std::unique_ptr &d2) { return d1 == d2.get(); }) && dives[0]->number && dives.last()->number && dives[0]->number < dives.last()->number) { // We have a consecutive set of dives. Rename all following dives according to the @@ -979,13 +979,13 @@ MergeDives::MergeDives(const QVector &dives) // above example is not supposed to be normal. int diff = dives.last()->number - dives[0]->number; int previousnr = dives[0]->number; - for (size_t i = idx + num; i < divelog.dives->size(); ++i) { - int newnr = (*divelog.dives)[i]->number - diff; + for (size_t i = idx + num; i < divelog.dives.size(); ++i) { + int newnr = divelog.dives[i]->number - diff; // Stop renumbering if stuff isn't in order (see also core/divelist.c) if (newnr <= previousnr) break; - divesToRenumber.append(QPair((*divelog.dives)[i].get(), newnr)); + divesToRenumber.append(QPair(divelog.dives[i].get(), newnr)); previousnr = newnr; } } diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 765a8cb0b..ac7bcea1c 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -62,7 +62,7 @@ static std::vector getDives(bool currentDiveOnly) : std::vector { }; std::vector res; - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (d->selected) res.push_back(d.get()); } @@ -1441,7 +1441,7 @@ void EditDive::exchangeDives() QVector dives = { oldDive }; timestamp_t delta = oldDive->when - newDive->when; if (delta != 0) { - divelog.dives->sort(); + divelog.dives.sort(); divelog.trips->sort(); if (newDive->divetrip != oldDive->divetrip) qWarning("Command::EditDive::redo(): This command does not support moving between trips!"); diff --git a/core/cochran.cpp b/core/cochran.cpp index bedd4e696..64fe90599 100644 --- a/core/cochran.cpp +++ b/core/cochran.cpp @@ -601,7 +601,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log, static void cochran_parse_dive(const unsigned char *decode, unsigned mod, const unsigned char *in, unsigned size, - struct dive_table *table) + struct dive_table &table) { unsigned char *buf = (unsigned char *)malloc(size); struct divecomputer *dc; @@ -784,7 +784,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod, dc->duration.seconds = duration; } - table->record_dive(std::move(dive)); + table.record_dive(std::move(dive)); free(buf); } @@ -819,7 +819,7 @@ int try_to_open_cochran(const char *, std::string &mem, struct divelog *log) break; cochran_parse_dive(decode, mod, (unsigned char *)mem.data() + dive1, - dive2 - dive1, log->dives.get()); + dive2 - dive1, log->dives); } return 1; // no further processing needed diff --git a/core/datatrak.cpp b/core/datatrak.cpp index 89a8909ee..3cdd36a4c 100644 --- a/core/datatrak.cpp +++ b/core/datatrak.cpp @@ -699,12 +699,12 @@ int datatrak_import(std::string &mem, std::string &wl_mem, struct divelog *log) rc = 1; goto out; } else { - log->dives->record_dive(std::move(ptdive)); + log->dives.record_dive(std::move(ptdive)); } i++; } out: - log->dives->sort(); + log->dives.sort(); return rc; bail: return 1; diff --git a/core/dive.cpp b/core/dive.cpp index edc8de895..30d6d4b20 100644 --- a/core/dive.cpp +++ b/core/dive.cpp @@ -2377,7 +2377,7 @@ static void force_fixup_dive(struct dive *d) */ static std::array, 2> split_dive_at(const struct dive &dive, int a, int b) { - size_t nr = divelog.dives->get_idx(&dive); + size_t nr = divelog.dives.get_idx(&dive); /* if we can't find the dive in the dive list, don't bother */ if (nr == std::string::npos) @@ -2462,7 +2462,7 @@ static std::array, 2> split_dive_at(const struct dive &div * Otherwise the tail is unnumbered. */ if (d2->number) { - if (divelog.dives->size() == nr + 1) + if (divelog.dives.size() == nr + 1) d2->number++; else d2->number = 0; @@ -2894,9 +2894,9 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou struct dive *get_dive(int nr) { - if (nr < 0 || static_cast(nr) >= divelog.dives->size()) + if (nr < 0 || static_cast(nr) >= divelog.dives.size()) return nullptr; - return (*divelog.dives)[nr].get(); + return divelog.dives[nr].get(); } struct dive_site *get_dive_site_for_dive(const struct dive *dive) diff --git a/core/divefilter.cpp b/core/divefilter.cpp index 34ce8f0a6..e4fe83ae8 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -74,8 +74,8 @@ ShownChange DiveFilter::update(const QVector &dives) const void DiveFilter::reset() { - shown_dives = static_cast(divelog.dives->size()); - for (auto &d: *divelog.dives) + shown_dives = static_cast(divelog.dives.size()); + for (auto &d: divelog.dives) d->hidden_by_filter = false; updateAll(); } @@ -87,18 +87,18 @@ ShownChange DiveFilter::updateAll() const std::vector removeFromSelection; // There are three modes: divesite, fulltext, normal if (diveSiteMode()) { - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { bool newStatus = range_contains(dive_sites, d->dive_site); updateDiveStatus(d.get(), newStatus, res, removeFromSelection); } } else if (filterData.fullText.doit()) { FullTextResult ft = fulltext_find_dives(filterData.fullText, filterData.fulltextStringMode); - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { bool newStatus = ft.dive_matches(d.get()) && showDive(d.get()); updateDiveStatus(d.get(), newStatus, res, removeFromSelection); } } else { - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { bool newStatus = showDive(d.get()); updateDiveStatus(d.get(), newStatus, res, removeFromSelection); } @@ -200,7 +200,7 @@ bool DiveFilter::diveSiteMode() const QString DiveFilter::shownText() const { - size_t num = divelog.dives->size(); + size_t num = divelog.dives.size(); if (diveSiteMode() || filterData.validFilter()) return gettextFromC::tr("%L1/%L2 shown").arg(shown_dives).arg(num); else @@ -226,7 +226,7 @@ std::vector DiveFilter::visibleDives() const std::vector res; res.reserve(shown_dives); - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (!d->hidden_by_filter) res.push_back(d.get()); } diff --git a/core/divelist.cpp b/core/divelist.cpp index 9d4894804..dcfb784c8 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -213,10 +213,10 @@ static int calculate_cns(struct dive *dive) if (dive->cns) return dive->cns; - size_t divenr = divelog.dives->get_idx(dive); + size_t divenr = divelog.dives.get_idx(dive); int i = divenr != std::string::npos ? static_cast(divenr) - : static_cast(divelog.dives->size()); - int nr_dives = static_cast(divelog.dives->size()); + : static_cast(divelog.dives.size()); + int nr_dives = static_cast(divelog.dives.size()); #if DECO_CALC_DEBUG & 2 if (static_cast(i) < divelog.table->size()) printf("\n\n*** CNS for dive #%d %d\n", i, (*divelog.table)[i]->number); @@ -427,10 +427,10 @@ int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_p if (!dive) return false; - int nr_dives = static_cast(divelog.dives->size()); - size_t divenr = divelog.dives->get_idx(dive); + int nr_dives = static_cast(divelog.dives.size()); + size_t divenr = divelog.dives.get_idx(dive); int i = divenr != std::string::npos ? static_cast(divenr) - : static_cast(divelog.dives->size()); + : static_cast(divelog.dives.size()); #if DECO_CALC_DEBUG & 2 if (i < dive_table.nr) printf("\n\n*** Init deco for dive #%d %d\n", i, get_dive(i)->number); @@ -719,18 +719,18 @@ struct dive *register_dive(std::unique_ptr d) fulltext_register(d.get()); // Register the dive's fulltext cache invalidate_dive_cache(d.get()); // Ensure that dive is written in git_save() - auto [res, idx] = divelog.dives->put(std::move(d)); + auto [res, idx] = divelog.dives.put(std::move(d)); return res; } void process_loaded_dives() { - divelog.dives->sort(); + divelog.dives.sort(); divelog.trips->sort(); /* Autogroup dives if desired by user. */ - autogroup_dives(*divelog.dives, *divelog.trips); + autogroup_dives(divelog.dives, *divelog.trips); fulltext_populate(); @@ -807,9 +807,9 @@ static bool try_to_merge_into(struct dive &dive_to_add, struct dive *old_dive, b /* Check if a dive is ranked after the last dive of the global dive list */ static bool dive_is_after_last(const struct dive &d) { - if (divelog.dives->empty()) + if (divelog.dives.empty()) return true; - return dive_less_than(*divelog.dives->back(), d); + return dive_less_than(*divelog.dives.back(), d); } /* Merge dives from "dives_from", owned by "delete" into the owned by "dives_to". @@ -921,7 +921,7 @@ void add_imported_dives(struct divelog &import_log, int flags) /* Add new dives */ for (auto &d: dives_to_add) - divelog.dives->put(std::move(d)); + divelog.dives.put(std::move(d)); dives_to_add.clear(); /* Add new trips */ @@ -939,7 +939,7 @@ void add_imported_dives(struct divelog &import_log, int flags) /* We might have deleted the old selected dive. * Choose the newest dive as selected (if any) */ - current_dive = !divelog.dives->empty() ? divelog.dives->back().get() : nullptr; + current_dive = !divelog.dives.empty() ? divelog.dives.back().get() : nullptr; /* Inform frontend of reset data. This should reset all the models. */ emit_reset_signal(); @@ -1022,13 +1022,13 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, process_imported_dives_result res; /* If no dives were imported, don't bother doing anything */ - if (import_log.dives->empty()) + if (import_log.dives.empty()) return res; /* Check if any of the new dives has a number. This will be * important later to decide if we want to renumber the added * dives */ - bool new_dive_has_number = std::any_of(import_log.dives->begin(), import_log.dives->end(), + bool new_dive_has_number = std::any_of(import_log.dives.begin(), import_log.dives.end(), [](auto &d) { return d->number > 0; }); /* Add only the devices that we don't know about yet. */ @@ -1038,18 +1038,18 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, } /* Sort the table of dives to be imported and combine mergable dives */ - import_log.dives->sort(); - merge_imported_dives(*import_log.dives); + import_log.dives.sort(); + merge_imported_dives(import_log.dives); /* Autogroup tripless dives if desired by user. But don't autogroup * if tripless dives should be added to a new trip. */ if (!(flags & IMPORT_ADD_TO_NEW_TRIP)) - autogroup_dives(*import_log.dives, *import_log.trips); + autogroup_dives(import_log.dives, *import_log.trips); /* If dive sites already exist, use the existing versions. */ for (auto &new_ds: *import_log.sites) { /* Check if it dive site is actually used by new dives. */ - if (std::none_of(import_log.dives->begin(), import_log.dives->end(), [ds=new_ds.get()] + if (std::none_of(import_log.dives.begin(), import_log.dives.end(), [ds=new_ds.get()] (auto &d) { return d->dive_site == ds; })) continue; @@ -1060,7 +1060,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, res.sites_to_add.put(std::move(new_ds)); } else { /* Dive site already exists - use the old one. */ - for (auto &d: *import_log.dives) { + for (auto &d: import_log.dives) { if (d->dive_site == new_ds.get()) d->dive_site = old_ds; } @@ -1074,7 +1074,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, */ for (auto &trip_import: *import_log.trips) { if ((flags & IMPORT_MERGE_ALL_TRIPS) || trip_import->autogen) { - if (try_to_merge_trip(*trip_import, *import_log.dives, flags & IMPORT_PREFER_IMPORTED, + if (try_to_merge_trip(*trip_import, import_log.dives, flags & IMPORT_PREFER_IMPORTED, res.dives_to_add, res.dives_to_remove, sequence_changed, start_renumbering_at)) continue; @@ -1084,7 +1084,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, * First, add dives to list of dives to add */ for (struct dive *d: trip_import->dives) { /* Add dive to list of dives to-be-added. */ - auto [owned, idx] = import_log.dives->pull(d); + auto [owned, idx] = import_log.dives.pull(d); if (!owned) continue; sequence_changed |= !dive_is_after_last(*owned); @@ -1098,27 +1098,27 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, } import_log.trips->clear(); /* All trips were consumed */ - if ((flags & IMPORT_ADD_TO_NEW_TRIP) && !import_log.dives->empty()) { + if ((flags & IMPORT_ADD_TO_NEW_TRIP) && !import_log.dives.empty()) { /* Create a new trip for unassigned dives, if desired. */ auto [new_trip, idx] = res.trips_to_add.put( - create_trip_from_dive(import_log.dives->front().get()) + create_trip_from_dive(import_log.dives.front().get()) ); /* Add all remaining dives to this trip */ - for (auto &d: *import_log.dives) { + for (auto &d: import_log.dives) { sequence_changed |= !dive_is_after_last(*d); d->divetrip = new_trip; res.dives_to_add.put(std::move(d)); } - import_log.dives->clear(); /* All dives were consumed */ - } else if (!import_log.dives->empty()) { + import_log.dives.clear(); /* All dives were consumed */ + } else if (!import_log.dives.empty()) { /* The remaining dives in import_log.dives are those that don't belong to * a trip and the caller does not want them to be associated to a * new trip. Merge them into the global table. */ - sequence_changed |= merge_dive_tables(dive_table_to_non_owning(*import_log.dives), - *import_log.dives, - dive_table_to_non_owning(*divelog.dives), + sequence_changed |= merge_dive_tables(dive_table_to_non_owning(import_log.dives), + import_log.dives, + dive_table_to_non_owning(divelog.dives), flags & IMPORT_PREFER_IMPORTED, NULL, res.dives_to_add, res.dives_to_remove, start_renumbering_at); } @@ -1128,13 +1128,13 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, * - The last dive in the old dive table had a number itself (if there is a last dive). * - None of the new dives has a number. */ - last_old_dive_is_numbered = divelog.dives->empty() || divelog.dives->back()->number > 0; + last_old_dive_is_numbered = divelog.dives.empty() || divelog.dives.back()->number > 0; /* We counted the number of merged dives that were added to dives_to_add. * Skip those. Since sequence_changed is false all added dives are *after* * all merged dives. */ if (!sequence_changed && last_old_dive_is_numbered && !new_dive_has_number) { - int nr = !divelog.dives->empty() ? divelog.dives->back()->number : 0; + int nr = !divelog.dives.empty() ? divelog.dives.back()->number : 0; for (auto it = res.dives_to_add.begin() + start_renumbering_at; it < res.dives_to_add.end(); ++it) (*it)->number = ++nr; } @@ -1144,9 +1144,9 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, static struct dive *get_last_valid_dive() { - auto it = std::find_if(divelog.dives->rbegin(), divelog.dives->rend(), + auto it = std::find_if(divelog.dives.rbegin(), divelog.dives.rend(), [](auto &d) { return !d->invalid; }); - return it != divelog.dives->rend() ? it->get() : nullptr; + return it != divelog.dives.rend() ? it->get() : nullptr; } /* return the number a dive gets when inserted at the given index. @@ -1158,7 +1158,7 @@ static struct dive *get_last_valid_dive() */ int get_dive_nr_at_idx(int idx) { - if (static_cast(idx) < divelog.dives->size()) + if (static_cast(idx) < divelog.dives.size()) return 0; struct dive *last_dive = get_last_valid_dive(); if (!last_dive) @@ -1195,18 +1195,18 @@ void report_datafile_version(int version) int get_dive_id_closest_to(timestamp_t when) { // deal with pathological cases - if (divelog.dives->empty()) + if (divelog.dives.empty()) return 0; - else if (divelog.dives->size() == 1) - return divelog.dives->front()->id; + else if (divelog.dives.size() == 1) + return divelog.dives.front()->id; - auto it = std::find_if(divelog.dives->begin(), divelog.dives->end(), + auto it = std::find_if(divelog.dives.begin(), divelog.dives.end(), [when] (auto &d) { return d->when > when; }); // again, capture the two edge cases first - if (it == divelog.dives->end()) - return divelog.dives->back()->id; - else if (it == divelog.dives->begin()) + if (it == divelog.dives.end()) + return divelog.dives.back()->id; + else if (it == divelog.dives.begin()) return (*it)->id; if (when - (*std::prev(it))->when < (*it)->when - when) @@ -1298,9 +1298,9 @@ timestamp_t get_surface_interval(timestamp_t when) timestamp_t prev_end; /* find previous dive. might want to use a binary search. */ - auto it = std::find_if(divelog.dives->rbegin(), divelog.dives->rend(), + auto it = std::find_if(divelog.dives.rbegin(), divelog.dives.rend(), [when] (auto &d) { return d->when < when; }); - if (it == divelog.dives->rend()) + if (it == divelog.dives.rend()) return -1; prev_end = (*it)->endtime(); @@ -1313,19 +1313,19 @@ timestamp_t get_surface_interval(timestamp_t when) * then newer dives. */ struct dive *find_next_visible_dive(timestamp_t when) { - if (divelog.dives->empty()) + if (divelog.dives.empty()) return nullptr; /* we might want to use binary search here */ - auto it = std::find_if(divelog.dives->begin(), divelog.dives->end(), + auto it = std::find_if(divelog.dives.begin(), divelog.dives.end(), [when] (auto &d) { return d->when <= when; }); - for (auto it2 = it; it2 != divelog.dives->begin(); --it2) { + for (auto it2 = it; it2 != divelog.dives.begin(); --it2) { if (!(*std::prev(it2))->hidden_by_filter) return it2->get(); } - for (auto it2 = it; it2 != divelog.dives->end(); ++it2) { + for (auto it2 = it; it2 != divelog.dives.end(); ++it2) { if (!(*it2)->hidden_by_filter) return it2->get(); } @@ -1335,7 +1335,7 @@ struct dive *find_next_visible_dive(timestamp_t when) bool has_dive(unsigned int deviceid, unsigned int diveid) { - return std::any_of(divelog.dives->begin(), divelog.dives->end(), [deviceid,diveid] (auto &d) { + return std::any_of(divelog.dives.begin(), divelog.dives.end(), [deviceid,diveid] (auto &d) { return std::any_of(d->dcs.begin(), d->dcs.end(), [deviceid,diveid] (auto &dc) { return dc.deviceid == deviceid && dc.diveid == diveid; }); diff --git a/core/divelog.cpp b/core/divelog.cpp index c97cf11a0..b19785dec 100644 --- a/core/divelog.cpp +++ b/core/divelog.cpp @@ -11,7 +11,6 @@ struct divelog divelog; divelog::divelog() : - dives(std::make_unique()), trips(std::make_unique()), sites(std::make_unique()), filter_presets(std::make_unique()), @@ -27,11 +26,11 @@ struct divelog &divelog::operator=(divelog &&) = default; * dive log and the trip, but doesn't deal with updating dive trips, etc */ void divelog::delete_single_dive(int idx) { - if (idx < 0 || static_cast(idx) >= dives->size()) { + if (idx < 0 || static_cast(idx) >= dives.size()) { report_info("Warning: deleting non-existing dive with index %d", idx); return; } - struct dive *dive = (*dives)[idx].get(); + struct dive *dive = dives[idx].get(); struct dive_trip *trip = unregister_dive_from_trip(dive); // Deleting a dive may change the order of trips! @@ -41,7 +40,7 @@ void divelog::delete_single_dive(int idx) if (trip && trip->dives.empty()) trips->pull(trip); unregister_dive_from_dive_site(dive); - dives->erase(dives->begin() + idx); + dives.erase(dives.begin() + idx); } void divelog::delete_multiple_dives(const std::vector &dives_to_delete) @@ -57,7 +56,7 @@ void divelog::delete_multiple_dives(const std::vector &dives_to_delete) } unregister_dive_from_dive_site(d); - dives->pull(d); + dives.pull(d); } // Deleting a dive may change the order of trips! @@ -67,7 +66,7 @@ void divelog::delete_multiple_dives(const std::vector &dives_to_delete) void divelog::clear() { - dives->clear(); + dives.clear(); sites->clear(); trips->clear(); devices.clear(); @@ -77,22 +76,22 @@ void divelog::clear() /* check if we have a trip right before / after this dive */ bool divelog::is_trip_before_after(const struct dive *dive, bool before) const { - auto it = std::find_if(dives->begin(), dives->end(), + auto it = std::find_if(dives.begin(), dives.end(), [dive](auto &d) { return d.get() == dive; }); - if (it == dives->end()) + if (it == dives.end()) return false; if (before) { do { - if (it == dives->begin()) + if (it == dives.begin()) return false; --it; } while ((*it)->invalid); return (*it)->divetrip != nullptr; } else { ++it; - while (it != dives->end() && (*it)->invalid) + while (it != dives.end() && (*it)->invalid) ++it; - return it != dives->end() && (*it)->divetrip != nullptr; + return it != dives.end() && (*it)->divetrip != nullptr; } } diff --git a/core/divelog.h b/core/divelog.h index 7d17f68e2..18017d84e 100644 --- a/core/divelog.h +++ b/core/divelog.h @@ -3,18 +3,18 @@ #ifndef DIVELOG_H #define DIVELOG_H +#include "divelist.h" + #include #include -struct dive; -struct dive_table; struct trip_table; class dive_site_table; struct device; struct filter_preset_table; struct divelog { - std::unique_ptr dives; + dive_table dives; std::unique_ptr trips; std::unique_ptr sites; std::vector devices; diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 170513a42..671b6cbb0 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -112,9 +112,9 @@ void DownloadThread::run() internalData->vendor.c_str(), internalData->product.c_str()); report_info("Finishing download thread: %s", error.c_str()); } else { - if (log.dives->empty()) + if (log.dives.empty()) error = tr("No new dives downloaded from dive computer").toStdString(); - report_info("Finishing download thread: %d dives downloaded", static_cast(log.dives->size())); + report_info("Finishing download thread: %d dives downloaded", static_cast(log.dives.size())); } qPrefDiveComputer::set_vendor(internalData->vendor.c_str()); qPrefDiveComputer::set_product(internalData->product.c_str()); diff --git a/core/equipment.cpp b/core/equipment.cpp index c3f331eee..16d28b235 100644 --- a/core/equipment.cpp +++ b/core/equipment.cpp @@ -284,7 +284,7 @@ void reset_tank_info_table(std::vector &table) add_default_tank_infos(table); /* Add cylinders from dive list */ - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { for (auto &cyl: dive->cylinders) add_cylinder_description(cyl.type); } diff --git a/core/fulltext.cpp b/core/fulltext.cpp index 61e9b8e69..1437d3eae 100644 --- a/core/fulltext.cpp +++ b/core/fulltext.cpp @@ -143,9 +143,9 @@ void FullText::populate() // we want this to be two calls as the second text is overwritten below by the lines starting with "\r" uiNotification(QObject::tr("Create full text index")); uiNotification(QObject::tr("start processing")); - for (auto &d: *divelog.dives) + for (auto &d: divelog.dives) registerDive(d.get()); - uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->size())); + uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives.size())); } void FullText::registerDive(struct dive *d) @@ -168,7 +168,7 @@ void FullText::unregisterDive(struct dive *d) void FullText::unregisterAll() { - for (auto &d: *divelog.dives) + for (auto &d: divelog.dives) d->full_text.reset(); words.clear(); } diff --git a/core/import-csv.cpp b/core/import-csv.cpp index 72eebac89..29d8840fa 100644 --- a/core/import-csv.cpp +++ b/core/import-csv.cpp @@ -443,7 +443,7 @@ int try_to_open_csv(std::string &mem, enum csv_format type, struct divelog *log) break; p = end + 1; } - log->dives->record_dive(std::move(dive)); + log->dives.record_dive(std::move(dive)); return 1; } @@ -749,7 +749,7 @@ int parse_txt_file(const char *filename, const char *csv, struct divelog *log) if (!lineptr || !*lineptr) break; } - log->dives->record_dive(std::move(dive)); + log->dives.record_dive(std::move(dive)); return 1; } else { return 0; diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp index 0a59d409b..29cb4a1d1 100644 --- a/core/libdivecomputer.cpp +++ b/core/libdivecomputer.cpp @@ -564,7 +564,7 @@ static bool match_one_dive(const struct divecomputer &a, const struct dive &dive */ static bool find_dive(const struct divecomputer &match) { - return std::any_of(divelog.dives->rbegin(), divelog.dives->rend(), + return std::any_of(divelog.dives.rbegin(), divelog.dives.rend(), [&match] (auto &old) { return match_one_dive(match, *old);} ); } @@ -864,7 +864,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, dive->dcs[0].samples[1].temperature.mkelvin > dive->dcs[0].samples[0].temperature.mkelvin) dive->dcs[0].samples[0].temperature.mkelvin = dive->dcs[0].samples[1].temperature.mkelvin; - devdata->log->dives->record_dive(std::move(dive)); + devdata->log->dives.record_dive(std::move(dive)); return true; error_exit: @@ -1502,7 +1502,7 @@ std::string do_libdivecomputer_import(device_data_t *data) dc_device_close(data->device); data->device = NULL; - if (data->log->dives->empty()) + if (data->log->dives.empty()) dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer")); } dc_iostream_close(data->iostream); diff --git a/core/liquivision.cpp b/core/liquivision.cpp index e611b61ca..6403b46a8 100644 --- a/core/liquivision.cpp +++ b/core/liquivision.cpp @@ -131,7 +131,7 @@ static int handle_event_ver3(int code, const unsigned char *ps, unsigned int ps_ return skip; } -static void parse_dives(int log_version, const unsigned char *buf, unsigned int buf_size, struct dive_table *table, dive_site_table &sites) +static void parse_dives(int log_version, const unsigned char *buf, unsigned int buf_size, struct dive_table &table, dive_site_table &sites) { unsigned int ptr = 0; unsigned char model; @@ -407,7 +407,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int } // End dive - table->record_dive(std::move(dive)); + table.record_dive(std::move(dive)); // Advance ptr for next dive ptr += ps_ptr + 4; @@ -437,7 +437,7 @@ int try_to_open_liquivision(const char *, std::string &mem, struct divelog *log) } ptr += 4; - parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives.get(), *log->sites); + parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, *log->sites); return 1; } diff --git a/core/load-git.cpp b/core/load-git.cpp index 96caca5e2..159c51f8b 100644 --- a/core/load-git.cpp +++ b/core/load-git.cpp @@ -1386,7 +1386,7 @@ static void finish_active_trip(struct git_parser_state *state) static void finish_active_dive(struct git_parser_state *state) { if (state->active_dive) - state->log->dives->record_dive(std::move(state->active_dive)); + state->log->dives.record_dive(std::move(state->active_dive)); } static void create_new_dive(timestamp_t when, struct git_parser_state *state) diff --git a/core/ostctools.cpp b/core/ostctools.cpp index 4fa4fa839..a288d9a8d 100644 --- a/core/ostctools.cpp +++ b/core/ostctools.cpp @@ -169,5 +169,5 @@ void ostctools_import(const char *file, struct divelog *log) else if (it == ostcdive->dcs[0].extra_data.end()) add_extra_data(&ostcdive->dcs[0], "Serial", ostcdive->dcs[0].serial); - log->dives->record_dive(std::move(ostcdive)); + log->dives.record_dive(std::move(ostcdive)); } diff --git a/core/parse.cpp b/core/parse.cpp index 2e1057515..5b2f83fe2 100644 --- a/core/parse.cpp +++ b/core/parse.cpp @@ -265,9 +265,9 @@ void dive_end(struct parser_state *state) // Note: we add dives in an unsorted way. The caller of the parsing // function must sort dives. fixup_dive(state->cur_dive.get()); - state->log->dives->push_back(std::move(state->cur_dive)); + state->log->dives.push_back(std::move(state->cur_dive)); // This would add dives in a sorted way: - // state->log->dives->record_dive(std::move(state->cur_dive)); + // state->log->dives.record_dive(std::move(state->cur_dive)); } state->cur_dive.reset(); state->cur_dc = NULL; diff --git a/core/picture.cpp b/core/picture.cpp index 9a999508a..a932d78ee 100644 --- a/core/picture.cpp +++ b/core/picture.cpp @@ -49,7 +49,7 @@ static struct dive *nearest_selected_dive(timestamp_t timestamp) struct dive *res = NULL; timestamp_t min = 0; - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (!d->selected) continue; timestamp_t offset = time_from_dive(*d, timestamp); @@ -106,7 +106,7 @@ std::pair, dive *> create_picture(const std::string &file bool picture_check_valid_time(timestamp_t timestamp, timestamp_t shift_time) { - return std::any_of(divelog.dives->begin(), divelog.dives->end(), + return std::any_of(divelog.dives.begin(), divelog.dives.end(), [t = timestamp + shift_time] (auto &d) { return d->selected && dive_check_picture_time(*d, t); }); } diff --git a/core/qthelper.cpp b/core/qthelper.cpp index e799f56a6..92c16319e 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -988,13 +988,13 @@ static QString get_dive_only_date_string(timestamp_t when) QString get_first_dive_date_string() { - const dive_table &dives = *divelog.dives; + const dive_table &dives = divelog.dives; return !dives.empty() ? get_dive_only_date_string(dives[0]->when) : gettextFromC::tr("no dives"); } QString get_last_dive_date_string() { - const dive_table &dives = *divelog.dives; + const dive_table &dives = divelog.dives; return !dives.empty() ? get_dive_only_date_string(dives.back()->when) : gettextFromC::tr("no dives"); } diff --git a/core/save-git.cpp b/core/save-git.cpp index e7d7095db..ac0e24306 100644 --- a/core/save-git.cpp +++ b/core/save-git.cpp @@ -797,7 +797,7 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip *trip /* Make sure we write out the dates to the dives consistently */ first = MAX_TIMESTAMP; last = MIN_TIMESTAMP; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (dive->divetrip != trip) continue; if (dive->when < first) @@ -809,7 +809,7 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip *trip verify_shared_date(last, tm); /* Save each dive in the directory */ - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (dive->divetrip == trip) save_one_dive(repo, subdir, *dive, tm, cached_ok); } @@ -990,7 +990,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o /* save the dives */ git_storage_update_progress(translate("gettextFromC", "Start saving dives")); - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { struct tm tm; struct dir *tree; @@ -1090,7 +1090,7 @@ int get_authorship(git_repository *repo, git_signature **authorp) static void create_commit_message(struct membuffer *msg, bool create_empty) { - int nr = static_cast(divelog.dives->size()); + int nr = static_cast(divelog.dives.size()); struct dive *dive = get_dive(nr-1); std::string changes_made = get_changes_made(); diff --git a/core/save-html.cpp b/core/save-html.cpp index 7741e1e8e..c263cf572 100644 --- a/core/save-html.cpp +++ b/core/save-html.cpp @@ -383,7 +383,7 @@ static void write_no_trip(struct membuffer *b, int *dive_no, bool selected_only, const char *separator = ""; bool found_sel_dive = 0; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { // write dive if it doesn't belong to any trip and the dive is selected // or we are in exporting all dives mode. if (!dive->divetrip && (dive->selected || !selected_only)) { @@ -439,7 +439,7 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select for (auto &trip: *divelog.trips) trip->saved = 0; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { dive_trip *trip = dive->divetrip; /*Continue if the dive have no trips or we have seen this trip before*/ diff --git a/core/save-profiledata.cpp b/core/save-profiledata.cpp index 99c779188..3fa989a17 100644 --- a/core/save-profiledata.cpp +++ b/core/save-profiledata.cpp @@ -207,7 +207,7 @@ static void save_profiles_buffer(struct membuffer *b, bool select_only) { struct deco_state *planner_deco_state = NULL; - for(auto &dive: *divelog.dives) { + for(auto &dive: divelog.dives) { if (select_only && !dive->selected) continue; plot_info pi = create_plot_info_new(dive.get(), &dive->dcs[0], planner_deco_state); diff --git a/core/save-xml.cpp b/core/save-xml.cpp index d144cfbd6..85ed6cc21 100644 --- a/core/save-xml.cpp +++ b/core/save-xml.cpp @@ -556,7 +556,7 @@ static void save_trip(struct membuffer *b, dive_trip &trip, bool anonymize) * list in the trip, we just traverse the global dive array and * check the divetrip pointer.. */ - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (dive->divetrip == &trip) save_one_dive_to_mb(b, *dive, anonymize); } @@ -685,7 +685,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym save_filter_presets(b); /* save the dives */ - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (select_only) { if (!dive->selected) continue; diff --git a/core/selection.cpp b/core/selection.cpp index b50480864..1b7707292 100644 --- a/core/selection.cpp +++ b/core/selection.cpp @@ -16,16 +16,16 @@ static int amount_trips_selected; struct dive *first_selected_dive() { - auto it = std::find_if(divelog.dives->begin(), divelog.dives->end(), + auto it = std::find_if(divelog.dives.begin(), divelog.dives.end(), [](auto &d) { return d->selected; }); - return it != divelog.dives->end() ? it->get() : nullptr; + return it != divelog.dives.end() ? it->get() : nullptr; } struct dive *last_selected_dive() { - auto it = std::find_if(divelog.dives->rbegin(), divelog.dives->rend(), + auto it = std::find_if(divelog.dives.rbegin(), divelog.dives.rend(), [](auto &d) { return d->selected; }); - return it != divelog.dives->rend() ? it->get() : nullptr; + return it != divelog.dives.rend() ? it->get() : nullptr; } bool consecutive_selected() @@ -37,7 +37,7 @@ bool consecutive_selected() if (amount_selected == 0 || amount_selected == 1) return true; - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (d->selected) { if (!firstfound) firstfound = true; @@ -54,7 +54,7 @@ bool consecutive_selected() void dump_selection() { printf("currently selected are %u dives:", amount_selected); - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (dive->selected) printf(" %d", i); } @@ -123,7 +123,7 @@ QVector setSelectionCore(const std::vector &selection, dive *cur // TODO: We might want to keep track of selected dives in a more efficient way! amount_selected = 0; // We recalculate amount_selected - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { // We only modify dives that are currently visible. if (d->hidden_by_filter) { d->selected = false; // Note, not necessary, just to be sure @@ -200,7 +200,7 @@ void setTripSelection(dive_trip *trip, dive *currentDive) return; current_dive = currentDive; - for (auto &d: *divelog.dives) + for (auto &d: divelog.dives) d->selected = d->divetrip == trip; for (auto &t: *divelog.trips) t->selected = t.get() == trip; @@ -226,7 +226,7 @@ std::vector getDiveSelection() std::vector res; res.reserve(amount_selected); - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (d->selected) res.push_back(d.get()); } @@ -262,7 +262,7 @@ void updateSelection(std::vector &selection, const std::vector & // Select the first dive that is visible void select_newest_visible_dive() { - for (auto it = divelog.dives->rbegin(); it != divelog.dives->rend(); ++it) { + for (auto it = divelog.dives.rbegin(); it != divelog.dives.rend(); ++it) { if (!(*it)->hidden_by_filter) return select_single_dive(it->get()); } diff --git a/core/statistics.cpp b/core/statistics.cpp index 221b761e9..55b2538aa 100644 --- a/core/statistics.cpp +++ b/core/statistics.cpp @@ -126,7 +126,7 @@ stats_summary calculate_stats_summary(bool selected_only) /* this relies on the fact that the dives in the dive_table * are in chronological order */ - for (auto &dp: *divelog.dives) { + for (auto &dp: divelog.dives) { if (selected_only && !dp->selected) continue; if (dp->invalid) @@ -237,7 +237,7 @@ stats_t calculate_stats_selected() stats_t stats_selection; unsigned int nr = 0; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (dive->selected && !dive->invalid) { process_dive(*dive, stats_selection); nr++; @@ -328,7 +328,7 @@ static std::pair get_gas_parts(struct gasmix mix, volume_t v std::pair selected_dives_gas_parts() { volume_t o2_tot, he_tot; - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (!d->selected || d->invalid) continue; int j = 0; diff --git a/core/string-format.cpp b/core/string-format.cpp index cdddd5e59..71d21f8e2 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -137,7 +137,7 @@ static void addStringToSortedList(QStringList &l, const std::string &s) QStringList formatFullCylinderList() { QStringList cylinders; - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { for (const cylinder_t &cyl: d->cylinders) addStringToSortedList(cylinders, cyl.type.description); } diff --git a/core/trip.cpp b/core/trip.cpp index c7ba54b56..311fc5b78 100644 --- a/core/trip.cpp +++ b/core/trip.cpp @@ -99,7 +99,7 @@ std::unique_ptr create_trip_from_dive(const struct dive *dive) std::pair> get_trip_for_new_dive(const struct divelog &log, const struct dive *new_dive) { /* Find dive that is within TRIP_THRESHOLD of current dive */ - for (auto &d: *log.dives) { + for (auto &d: log.dives) { /* Check if we're past the range of possible dives */ if (d->when >= new_dive->when + TRIP_THRESHOLD) break; diff --git a/core/uemis-downloader.cpp b/core/uemis-downloader.cpp index f73042282..c2f583cf4 100644 --- a/core/uemis-downloader.cpp +++ b/core/uemis-downloader.cpp @@ -190,7 +190,7 @@ static std::unique_ptr uemis_start_dive(uint32_t deviceid) static struct dive *get_dive_by_uemis_diveid(device_data_t *devdata, uint32_t object_id) { - for (auto &d: *devdata->log->dives) { + for (auto &d: devdata->log->dives) { if (object_id == d->dcs[0].diveid) return d.get(); } @@ -767,12 +767,12 @@ static void parse_tag(struct dive *dive, std::string_view tag, std::string_view static bool uemis_delete_dive(device_data_t *devdata, uint32_t diveid) { - auto it = std::find_if(devdata->log->dives->begin(), devdata->log->dives->end(), + auto it = std::find_if(devdata->log->dives.begin(), devdata->log->dives.end(), [diveid] (auto &d) { return d->dcs[0].diveid == diveid; }); - if (it == devdata->log->dives->end()) + if (it == devdata->log->dives.end()) return false; - devdata->log->dives->erase(it); + devdata->log->dives.erase(it); return true; } @@ -900,7 +900,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s bp = bp.substr(1); if (bp[0] != '{' && bp.find("{{") != std::string::npos) { done = false; - devdata->log->dives->record_dive(std::move(owned_dive)); + devdata->log->dives.record_dive(std::move(owned_dive)); owned_dive = uemis_start_dive(deviceid); } } @@ -933,7 +933,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s } if (is_log) { if (owned_dive->dcs[0].diveid) - devdata->log->dives->record_dive(std::move(owned_dive)); + devdata->log->dives.record_dive(std::move(owned_dive)); else /* partial dive */ return false; } @@ -957,7 +957,7 @@ static std::pair uemis_get_divenr(uint32_t deviceid, struct * Otherwise, use the global dive table. */ if (!force && table->empty()) - table = divelog.dives.get(); + table = &divelog.dives; for (auto &d: *table) { if (!d) @@ -1021,19 +1021,19 @@ static bool do_dump_buffer_to_file(std::string_view buf, const char *prefix) * return : ok if there is enough memory for a full round * full if the memory is exhausted */ -static uemis_mem_status get_memory(struct dive_table *td, uemis_checkpoint checkpoint) +static uemis_mem_status get_memory(struct dive_table &td, uemis_checkpoint checkpoint) { - if (td->empty()) + if (td.empty()) return uemis_mem_status::ok; switch (checkpoint) { case uemis_checkpoint::log: - if (filenr / static_cast(td->size()) > max_mem_used) - max_mem_used = filenr / static_cast(td->size()); + if (filenr / static_cast(td.size()) > max_mem_used) + max_mem_used = filenr / static_cast(td.size()); /* check if a full block of dive logs + dive details and dive spot fit into the UEMIS buffer */ #if UEMIS_DEBUG & 4 - report_info("max_mem_used %d (from td->size() %d) * block_size %d > max_files %d - filenr %d?\n", max_mem_used, static_cast(td->size()), uemis_log_block_size, uemis_max_files, filenr); + report_info("max_mem_used %d (from td.size() %d) * block_size %d > max_files %d - filenr %d?\n", max_mem_used, static_cast(td.size()), uemis_log_block_size, uemis_max_files, filenr); #endif if (max_mem_used * uemis_log_block_size > uemis_max_files - filenr) return uemis_mem_status::full; @@ -1053,9 +1053,9 @@ static uemis_mem_status get_memory(struct dive_table *td, uemis_checkpoint check /* we misuse the hidden_by_filter flag to mark a dive as deleted. * this will be picked up by some cleaning statement later. */ -static void do_delete_dives(struct dive_table *td, size_t idx) +static void do_delete_dives(struct dive_table &td, size_t idx) { - for (auto it = td->begin() + idx; it != td->end(); ++it) + for (auto it = td.begin() + idx; it != td.end(); ++it) (*it)->hidden_by_filter = true; } @@ -1114,7 +1114,7 @@ static void get_uemis_divespot(device_data_t *devdata, const std::string &mountp static bool get_matching_dive(size_t idx, int &newmax, uemis_mem_status &mem_status, device_data_t *data, const std::string &mountpath, const char deviceidnr) { - auto &dive = (*data->log->dives)[idx]; + auto &dive = data->log->dives[idx]; char log_file_no_to_find[20]; bool found = false; bool found_below = false; @@ -1135,7 +1135,7 @@ static bool get_matching_dive(size_t idx, int &newmax, uemis_mem_status &mem_sta #if UEMIS_DEBUG & 16 do_dump_buffer_to_file(mbuf, "Dive"); #endif - mem_status = get_memory(data->log->dives.get(), uemis_checkpoint::single_dive); + mem_status = get_memory(data->log->dives, uemis_checkpoint::single_dive); if (mem_status == uemis_mem_status::ok) { /* if the memory isn's completely full we can try to read more dive log vs. dive details * and the dive spots should fit into the UEMIS memory @@ -1199,7 +1199,7 @@ static bool get_matching_dive(size_t idx, int &newmax, uemis_mem_status &mem_sta } else { /* At this point the memory of the UEMIS is full, let's cleanup all dive log files were * we could not match the details to. */ - do_delete_dives(data->log->dives.get(), idx); + do_delete_dives(data->log->dives, idx); return false; } } @@ -1257,7 +1257,7 @@ std::string do_uemis_import(device_data_t *data) param_buff[1] = "notempty"; { - auto [mindiveid, maxdiveid] = uemis_get_divenr(deviceidnr, data->log->dives.get(), force_download); + auto [mindiveid, maxdiveid] = uemis_get_divenr(deviceidnr, &data->log->dives, force_download); newmax = maxdiveid; if (verbose) report_info("Uemis downloader: start looking at dive nr %d", newmax); @@ -1275,13 +1275,13 @@ std::string do_uemis_import(device_data_t *data) report_info("d_u_i inner loop start %d end %d newmax %d\n", start, end, newmax); #endif /* start at the last filled download table index */ - size_t match_dive_and_log = data->log->dives->size(); + size_t match_dive_and_log = data->log->dives.size(); newmax = start; std::string newmax_str = std::to_string(newmax); param_buff[2] = newmax_str.c_str(); param_buff[3].clear(); std::string mbuf = uemis_get_answer(mountpath, "getDivelogs", 3, 0, result); - mem_status = get_memory(data->log->dives.get(), uemis_checkpoint::details); + mem_status = get_memory(data->log->dives, uemis_checkpoint::details); /* first, remove any leading garbage... this needs to start with a '{' */ std::string_view realmbuf = mbuf; size_t pos = realmbuf.find('{'); @@ -1324,7 +1324,7 @@ std::string do_uemis_import(device_data_t *data) * What the following part does is to optimize the mapping by using * dive_to_read = the dive details entry that need to be read using the object_id * logFileNoToFind = map the logfilenr of the dive details with the object_id = diveid from the get dive logs */ - for (size_t i = match_dive_and_log; i < data->log->dives->size(); i++) { + for (size_t i = match_dive_and_log; i < data->log->dives.size(); i++) { if (!get_matching_dive(i, newmax, mem_status, data, mountpath, deviceidnr)) break; if (import_thread_cancelled) @@ -1334,7 +1334,7 @@ std::string do_uemis_import(device_data_t *data) start = end; /* Do some memory checking here */ - mem_status = get_memory(data->log->dives.get(), uemis_checkpoint::log); + mem_status = get_memory(data->log->dives, uemis_checkpoint::log); if (mem_status != uemis_mem_status::ok) { #if UEMIS_DEBUG & 4 report_info("d_u_i out of memory, bailing\n"); @@ -1348,7 +1348,7 @@ std::string do_uemis_import(device_data_t *data) // Resetting to original state filenr = 0; max_mem_used = -1; - mem_status = get_memory(data->log->dives.get(), uemis_checkpoint::details); + mem_status = get_memory(data->log->dives, uemis_checkpoint::details); if (uemis_get_answer(mountpath, "getDeviceId", 0, 1, result).empty()) goto bail; if (deviceid != param_buff[0]) { @@ -1391,7 +1391,7 @@ std::string do_uemis_import(device_data_t *data) * be deleted from the download_table. */ if (mem_status == uemis_mem_status::full) - do_delete_dives(data->log->dives.get(), match_dive_and_log); + do_delete_dives(data->log->dives, match_dive_and_log); #if UEMIS_DEBUG & 4 report_info("d_u_i out of memory, bailing instead of processing\n"); #endif @@ -1408,9 +1408,9 @@ std::string do_uemis_import(device_data_t *data) /* Regardless on where we are with the memory situation, it's time now * to see if we have to clean some dead bodies from our download table */ - for (size_t next_table_index = 0; next_table_index < data->log->dives->size(); ) { - if ((*data->log->dives)[next_table_index]->hidden_by_filter) - uemis_delete_dive(data, (*data->log->dives)[next_table_index]->dcs[0].diveid); + for (size_t next_table_index = 0; next_table_index < data->log->dives.size(); ) { + if (data->log->dives[next_table_index]->hidden_by_filter) + uemis_delete_dive(data, data->log->dives[next_table_index]->dcs[0].diveid); else next_table_index++; } @@ -1429,7 +1429,7 @@ bail: else result = param_buff[2]; } - if (data->log->dives->empty()) + if (data->log->dives.empty()) result = translate("gettextFromC", ERR_NO_FILES); return result; } diff --git a/core/uploadDiveLogsDE.cpp b/core/uploadDiveLogsDE.cpp index 9a5af43d4..ab12b00e4 100644 --- a/core/uploadDiveLogsDE.cpp +++ b/core/uploadDiveLogsDE.cpp @@ -90,7 +90,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected) } /* walk the dive list in chronological order */ - for (auto [i, dive]: enumerated_range(*divelog.dives)) { + for (auto [i, dive]: enumerated_range(divelog.dives)) { char filename[PATH_MAX]; int streamsize; char *membuf; diff --git a/core/worldmap-save.cpp b/core/worldmap-save.cpp index 93baae3ce..e6c134c26 100644 --- a/core/worldmap-save.cpp +++ b/core/worldmap-save.cpp @@ -32,7 +32,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only) { int dive_no = 0; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (selected_only && !dive->selected) continue; struct dive_site *ds = get_dive_site_for_dive(dive.get()); diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 96a95ae6c..461ec9987 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -456,7 +456,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() qPrefDiveComputer::set_device(data->devName()); // before we start, remember where the dive_table ended - previousLast = static_cast(divelog.dives->size()); + previousLast = static_cast(divelog.dives.size()); diveImportedModel->startDownload(); // FIXME: We should get the _actual_ device info instead of whatever diff --git a/desktop-widgets/findmovedimagesdialog.cpp b/desktop-widgets/findmovedimagesdialog.cpp index 4f9db564d..3f432d922 100644 --- a/desktop-widgets/findmovedimagesdialog.cpp +++ b/desktop-widgets/findmovedimagesdialog.cpp @@ -186,7 +186,7 @@ void FindMovedImagesDialog::on_scanButton_clicked() // We have to collect the names of the image filenames in the main thread bool onlySelected = ui.onlySelectedDives->isChecked(); QVector imagePaths; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { if (!onlySelected || dive->selected) { for (auto &picture: dive->pictures) imagePaths.append(QString::fromStdString(picture.filename)); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 529a47cf0..17acd5acf 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -430,7 +430,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() // Return whether saving to cloud is OK. If it isn't, show an error return false. static bool saveToCloudOK() { - if (divelog.dives->empty()) { + if (divelog.dives.empty()) { report_error("%s", qPrintable(gettextFromC::tr("Don't save an empty log to the cloud"))); return false; } diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index dbbf8237c..c1a46177c 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -130,7 +130,7 @@ void Printer::render(int pages) // dive id field should be dive_{{dive_no}} se we remove the first 5 characters QString diveIdString = collection.at(elemNo).attribute("id"); int diveId = diveIdString.remove(0, 5).toInt(0, 10); - putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, divelog.dives->get_by_uniq_id(diveId), profile.get()); + putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, divelog.dives.get_by_uniq_id(diveId), profile.get()); elemNo++; } @@ -161,7 +161,7 @@ std::vector Printer::getDives() const return getDiveSelection(); } else { std::vector res; - for (auto &d: *divelog.dives) + for (auto &d: divelog.dives) res.push_back(d.get()); return res; } diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index 1a16be1d0..31c46d314 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -32,7 +32,7 @@ void RenumberDialog::buttonClicked(QAbstractButton *button) // we remember a list from dive uuid to a new number QVector> renumberedDives; int newNr = ui.spinBox->value(); - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { if (!selectedOnly || d->selected) renumberedDives.append({ d.get(), newNr++ }); } diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp index a5ea07918..bd28b2105 100644 --- a/map-widget/qmlmapwidgethelper.cpp +++ b/map-widget/qmlmapwidgethelper.cpp @@ -134,7 +134,7 @@ void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in) return; QGeoCoordinate locationCoord = location->coordinate; - for (auto [idx, dive]: enumerated_range(*divelog.dives)) { + for (auto [idx, dive]: enumerated_range(divelog.dives)) { struct dive_site *ds = get_dive_site_for_dive(dive.get()); if (!dive_site_has_gps_location(ds)) continue; @@ -162,7 +162,7 @@ void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in) void MapWidgetHelper::selectVisibleLocations() { QList selectedDiveIds; - for (auto [idx, dive]: enumerated_range(*divelog.dives)) { + for (auto [idx, dive]: enumerated_range(divelog.dives)) { struct dive_site *ds = get_dive_site_for_dive(dive.get()); if (!dive_site_has_gps_location(ds)) continue; diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 7fd56c286..b8292c7ea 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -413,9 +413,9 @@ void QMLManager::openLocalThenRemote(QString url) qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors); qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2); // the following steps can take a long time, so provide updates - setNotificationText(tr("Processing %1 dives").arg(divelog.dives->size())); + setNotificationText(tr("Processing %1 dives").arg(divelog.dives.size())); process_loaded_dives(); - setNotificationText(tr("%1 dives loaded from local dive data file").arg(divelog.dives->size())); + setNotificationText(tr("%1 dives loaded from local dive data file").arg(divelog.dives.size())); } if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NEED_TO_VERIFY) { appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN")); @@ -588,7 +588,7 @@ void QMLManager::finishSetup() // successfully opened the local file, now add thigs to the dive list consumeFinishedLoad(); updateHaveLocalChanges(true); - appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(divelog.dives->size()).arg(existing_filename.c_str())); + appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(divelog.dives.size()).arg(existing_filename.c_str())); } } else { qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_UNKNOWN); @@ -672,7 +672,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne qPrefCloudStorage::set_cloud_storage_email(email); qPrefCloudStorage::set_cloud_storage_password(newPassword); - if (m_oldStatus == qPrefCloudStorage::CS_NOCLOUD && cloudCredentialsChanged && divelog.dives->size()) { + if (m_oldStatus == qPrefCloudStorage::CS_NOCLOUD && cloudCredentialsChanged && divelog.dives.size()) { // we came from NOCLOUD and are connecting to a cloud account; // since we already have dives in the table, let's remember that so we can keep them noCloudToCloud = true; @@ -830,7 +830,7 @@ void QMLManager::loadDivesWithValidCredentials() if (noCloudToCloud) { git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); mergeLocalRepo(); - appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(divelog.dives->size())); + appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(divelog.dives.size())); noCloudToCloud = false; mark_divelist_changed(true); emit syncStateChanged(); @@ -894,8 +894,8 @@ void QMLManager::consumeFinishedLoad() prefs.show_ccr_sensors = git_prefs.show_ccr_sensors; prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2; process_loaded_dives(); - appendTextToLog(QStringLiteral("%1 dives loaded").arg(divelog.dives->size())); - if (divelog.dives->empty()) + appendTextToLog(QStringLiteral("%1 dives loaded").arg(divelog.dives.size())); + if (divelog.dives.empty()) setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); } @@ -1168,7 +1168,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt QString airtemp, QString watertemp, QString suit, QString buddy, QString diveGuide, QString tags, QString weight, QString notes, QStringList startpressure, QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state) { - struct dive *orig = divelog.dives->get_by_uniq_id(diveId.toInt()); + struct dive *orig = divelog.dives.get_by_uniq_id(diveId.toInt()); if (!orig) { appendTextToLog("cannot commit changes: no dive"); @@ -1389,7 +1389,7 @@ void QMLManager::updateTripDetails(QString tripIdString, QString tripLocation, Q void QMLManager::removeDiveFromTrip(int id) { - struct dive *d = divelog.dives->get_by_uniq_id(id); + struct dive *d = divelog.dives.get_by_uniq_id(id); if (!d) { appendTextToLog(QString("Asked to remove non-existing dive with id %1 from its trip.").arg(id)); return; @@ -1406,7 +1406,7 @@ void QMLManager::removeDiveFromTrip(int id) void QMLManager::addTripForDive(int id) { - struct dive *d = divelog.dives->get_by_uniq_id(id); + struct dive *d = divelog.dives.get_by_uniq_id(id); if (!d) { appendTextToLog(QString("Asked to create trip for non-existing dive with id %1").arg(id)); return; @@ -1423,7 +1423,7 @@ void QMLManager::addTripForDive(int id) void QMLManager::addDiveToTrip(int id, int tripId) { - struct dive *d = divelog.dives->get_by_uniq_id(id); + struct dive *d = divelog.dives.get_by_uniq_id(id); if (!d) { appendTextToLog(QString("Asked to add non-existing dive with id %1 to trip %2.").arg(id).arg(tripId)); return; @@ -1578,7 +1578,7 @@ void QMLManager::selectDive(int id) extern int amount_selected; amount_selected = 0; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { dive->selected = (dive->id == id); if (dive->selected) amount_selected++; @@ -1589,7 +1589,7 @@ void QMLManager::selectDive(int id) void QMLManager::deleteDive(int id) { - struct dive *d = divelog.dives->get_by_uniq_id(id); + struct dive *d = divelog.dives.get_by_uniq_id(id); if (!d) { appendTextToLog("trying to delete non-existing dive"); return; @@ -1600,7 +1600,7 @@ void QMLManager::deleteDive(int id) void QMLManager::toggleDiveInvalid(int id) { - struct dive *d = divelog.dives->get_by_uniq_id(id); + struct dive *d = divelog.dives.get_by_uniq_id(id); if (!d) { appendTextToLog("trying to toggle invalid flag of non-existing dive"); return; @@ -1691,7 +1691,7 @@ bool QMLManager::toggleWeights(bool toggle) void QMLManager::copyDiveData(int id) { - m_copyPasteDive = divelog.dives->get_by_uniq_id(id); + m_copyPasteDive = divelog.dives.get_by_uniq_id(id); if (!m_copyPasteDive) { appendTextToLog("trying to copy non-existing dive"); return; @@ -1779,7 +1779,7 @@ void QMLManager::setStartPageText(const QString& text) QString QMLManager::getNumber(const QString& diveId) { int dive_id = diveId.toInt(); - struct dive *d = divelog.dives->get_by_uniq_id(dive_id); + struct dive *d = divelog.dives.get_by_uniq_id(dive_id); QString number; if (d) number = QString::number(d->number); @@ -1789,7 +1789,7 @@ QString QMLManager::getNumber(const QString& diveId) QString QMLManager::getDate(const QString& diveId) { int dive_id = diveId.toInt(); - struct dive *d = divelog.dives->get_by_uniq_id(dive_id); + struct dive *d = divelog.dives.get_by_uniq_id(dive_id); QString datestring; if (d) datestring = get_short_dive_date_string(d->when); diff --git a/profile-widget/qmlprofile.cpp b/profile-widget/qmlprofile.cpp index f388d5c16..3260014e6 100644 --- a/profile-widget/qmlprofile.cpp +++ b/profile-widget/qmlprofile.cpp @@ -61,7 +61,7 @@ void QMLProfile::paint(QPainter *painter) painter->resetTransform(); if (m_diveId < 0) return; - struct dive *d = divelog.dives->get_by_uniq_id(m_diveId); + struct dive *d = divelog.dives.get_by_uniq_id(m_diveId); if (!d) return; m_profileWidget->draw(painter, painterRect, d, m_dc, nullptr, false); @@ -144,7 +144,7 @@ void QMLProfile::prevDC() void QMLProfile::rotateDC(int dir) { - struct dive *d = divelog.dives->get_by_uniq_id(m_diveId); + struct dive *d = divelog.dives.get_by_uniq_id(m_diveId); if (!d) return; int numDC = number_of_computers(d); @@ -158,6 +158,6 @@ void QMLProfile::rotateDC(int dir) int QMLProfile::numDC() const { - struct dive *d = divelog.dives->get_by_uniq_id(m_diveId); + struct dive *d = divelog.dives.get_by_uniq_id(m_diveId); return d ? number_of_computers(d) : 0; } diff --git a/qt-models/completionmodels.cpp b/qt-models/completionmodels.cpp index 9ff3caa0e..b50e26da6 100644 --- a/qt-models/completionmodels.cpp +++ b/qt-models/completionmodels.cpp @@ -33,7 +33,7 @@ void CompletionModelBase::divesChanged(const QVector &, DiveField field) static QStringList getCSVList(const std::string dive::*item) { QSet set; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { QString str = QString::fromStdString(dive.get()->*item); for (const QString &value: str.split(",", SKIP_EMPTY)) set.insert(value.trimmed()); @@ -66,7 +66,7 @@ bool DiveGuideCompletionModel::relevantDiveField(const DiveField &f) QStringList SuitCompletionModel::getStrings() { QStringList list; - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { QString suit = QString::fromStdString(dive->suit); if (!list.contains(suit)) list.append(suit); diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index 5b41dc5f6..796e82818 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -16,7 +16,7 @@ int DiveImportedModel::columnCount(const QModelIndex&) const int DiveImportedModel::rowCount(const QModelIndex&) const { - return static_cast(log.dives->size()); + return static_cast(log.dives.size()); } QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -46,10 +46,10 @@ QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation, QVariant DiveImportedModel::data(const QModelIndex &index, int role) const { - if (index.row() < 0 || static_cast(index.row()) >= log.dives->size()) + if (index.row() < 0 || static_cast(index.row()) >= log.dives.size()) return QVariant(); - const struct dive &d = *(*log.dives)[index.row()]; + const struct dive &d = *log.dives[index.row()]; // widgets access the model via index.column(), qml via role. int column = index.column(); @@ -85,10 +85,10 @@ void DiveImportedModel::changeSelected(QModelIndex clickedIndex) void DiveImportedModel::selectAll() { - if (log.dives->empty()) + if (log.dives.empty()) return; std::fill(checkStates.begin(), checkStates.end(), true); - dataChanged(index(0, 0), index(log.dives->size() - 1, 0), QVector() << Qt::CheckStateRole << Selected); + dataChanged(index(0, 0), index(log.dives.size() - 1, 0), QVector() << Qt::CheckStateRole << Selected); } void DiveImportedModel::selectRow(int row) @@ -99,10 +99,10 @@ void DiveImportedModel::selectRow(int row) void DiveImportedModel::selectNone() { - if (log.dives->empty()) + if (log.dives.empty()) return; std::fill(checkStates.begin(), checkStates.end(), false); - dataChanged(index(0, 0), index(log.dives->size() - 1, 0 ), QVector() << Qt::CheckStateRole << Selected); + dataChanged(index(0, 0), index(log.dives.size() - 1, 0 ), QVector() << Qt::CheckStateRole << Selected); } Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const @@ -128,7 +128,7 @@ void DiveImportedModel::downloadThreadFinished() log.clear(); std::swap(log, thread.log); - checkStates.resize(log.dives->size()); + checkStates.resize(log.dives.size()); std::fill(checkStates.begin(), checkStates.end(), true); endResetModel(); @@ -165,24 +165,24 @@ struct divelog DiveImportedModel::consumeTables() int DiveImportedModel::numDives() const { - return static_cast(log.dives->size()); + return static_cast(log.dives.size()); } // Delete non-selected dives void DiveImportedModel::deleteDeselected() { - size_t total = log.dives->size(); + size_t total = log.dives.size(); size_t j = 0; for (size_t i = 0; i < total; i++) { if (checkStates[i]) { j++; } else { beginRemoveRows(QModelIndex(), j, j); - log.dives->erase(log.dives->begin() + j); + log.dives.erase(log.dives.begin() + j); endRemoveRows(); } } - checkStates.resize(log.dives->size()); + checkStates.resize(log.dives.size()); std::fill(checkStates.begin(), checkStates.end(), true); } @@ -193,7 +193,7 @@ void DiveImportedModel::recordDives(int flags) deleteDeselected(); struct divelog log = consumeTables(); - if (!log.dives->empty()) { + if (!log.dives.empty()) { auto data = thread.data(); Command::importDives(&log, flags, data->devName()); } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 49b34874e..65644ab9d 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -102,8 +102,8 @@ void DivePlannerPointsModel::setupStartTime() // if the latest dive is in the future, then start an hour after it ends // otherwise start an hour from now startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset()); - if (!divelog.dives->empty()) { - time_t ends = divelog.dives->back()->endtime(); + if (!divelog.dives.empty()) { + time_t ends = divelog.dives.back()->endtime(); time_t diff = ends - dateTimeToTimestamp(startTime); if (diff > 0) startTime = startTime.addSecs(diff + 3600); diff --git a/qt-models/divesummarymodel.cpp b/qt-models/divesummarymodel.cpp index bdcf3ab1d..fa5a1ddee 100644 --- a/qt-models/divesummarymodel.cpp +++ b/qt-models/divesummarymodel.cpp @@ -162,10 +162,7 @@ static void calculateDive(struct dive *dive, Stats &stats) static Stats loopDives(timestamp_t start) { Stats stats; - struct dive *dive; - int i; - - for (auto &dive: *divelog.dives) { + for (auto &dive: divelog.dives) { // check if dive is newer than primaryStart (add to first column) if (dive->when > start) calculateDive(dive.get(), stats); diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 32ade0c1a..c65d090b3 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -707,7 +707,7 @@ void DiveTripModelTree::populate() // we want this to be two calls as the second text is overwritten below by the lines starting with "\r" uiNotification(QObject::tr("populate data model")); uiNotification(QObject::tr("start processing")); - for (auto &d: *divelog.dives) { + for (auto &d: divelog.dives) { update_cylinder_related_info(d.get()); if (d->hidden_by_filter) continue; @@ -734,7 +734,7 @@ void DiveTripModelTree::populate() // Remember the index of the current dive oldCurrent = current_dive; - uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives->size())); + uiNotification(QObject::tr("%1 dives processed").arg(divelog.dives.size())); } int DiveTripModelTree::rowCount(const QModelIndex &parent) const @@ -1482,8 +1482,8 @@ void DiveTripModelList::populate() DiveFilter::instance()->reset(); // The data was reset - update filter status. TODO: should this really be done here? // Fill model - items.reserve(divelog.dives->size()); - for (auto &d: *divelog.dives) { + items.reserve(divelog.dives.size()); + for (auto &d: divelog.dives) { if (!d || d->hidden_by_filter) continue; items.push_back(d.get()); diff --git a/smtk-import/smartrak.cpp b/smtk-import/smartrak.cpp index ddf96d0cd..43ce9ef07 100644 --- a/smtk-import/smartrak.cpp +++ b/smtk-import/smartrak.cpp @@ -1016,11 +1016,11 @@ void smartrak_import(const char *file, struct divelog *log) smtk_parse_bookmarks(mdb_clon, smtkdive.get(), (char *)col[0]->bind_ptr); concat(smtkdive->notes, "\n", std::string((char *)col[coln(REMARKS)]->bind_ptr)); - log->dives->record_dive(std::move(smtkdive)); + log->dives.record_dive(std::move(smtkdive)); } mdb_free_catalog(mdb_clon); mdb->catalog = NULL; mdb_close(mdb_clon); mdb_close(mdb); - log->dives->sort(); + log->dives.sort(); } diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index 8d44708a8..e0fa377ea 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -1381,7 +1381,7 @@ struct DiveNrVariable : public StatsVariableTemplate binners() const override { - if (divelog.dives->size() > 1000) + if (divelog.dives.size() > 1000) return { &dive_nr_binner_20, &dive_nr_binner_50, &dive_nr_binner_100, &dive_nr_binner_200 }; else return { &dive_nr_binner_5, &dive_nr_binner_10, &dive_nr_binner_20, &dive_nr_binner_50 }; diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 1835b47b3..39c753f4f 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -121,16 +121,16 @@ void TestParse::testParse() // On some platforms (Windows) size_t has a different format string. // Let's just cast to int. QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0); - fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives.size())); QCOMPARE(parseDivingLog(), 0); - fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives.size())); QCOMPARE(parseV2NoQuestion(), 0); - fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives.size())); QCOMPARE(parseV3(), 0); - fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives.size())); QCOMPARE(save_dives("./testout.ssrf"), 0); FILE_COMPARE("./testout.ssrf", @@ -182,14 +182,14 @@ void TestParse::testParseHUDC() ¶ms, "csv", &divelog), 0); - QCOMPARE(divelog.dives->size(), 1); + QCOMPARE(divelog.dives.size(), 1); /* * CSV import uses time and date stamps relative to current * time, thus we need to use a static (random) timestamp */ - if (!divelog.dives->empty()) { - struct dive &dive = *divelog.dives->back(); + if (!divelog.dives.empty()) { + struct dive &dive = *divelog.dives.back(); dive.when = 1255152761; dive.dcs[0].when = 1255152761; } @@ -226,10 +226,10 @@ void TestParse::testParseNewFormat() .toLatin1() .data(), &divelog), 0); - QCOMPARE(divelog.dives->size(), i + 1); + QCOMPARE(divelog.dives.size(), i + 1); } - fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives %d \n", static_cast(divelog.dives.size())); QCOMPARE(save_dives("./testsbnewout.ssrf"), 0); // Currently the CSV parse fails @@ -245,7 +245,7 @@ void TestParse::testParseDLD() QVERIFY(err > 0); QVERIFY(try_to_open_zip(filename.toLatin1().data(), &divelog) > 0); - fprintf(stderr, "number of dives from DLD: %d \n", static_cast(divelog.dives->size())); + fprintf(stderr, "number of dives from DLD: %d \n", static_cast(divelog.dives.size())); // Compare output QCOMPARE(save_dives("./testdldout.ssrf"), 0); @@ -311,15 +311,15 @@ void TestParse::exportCSVDiveDetails() export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false); - if (!divelog.dives->empty()) - saved_sac = divelog.dives->back()->sac; + if (!divelog.dives.empty()) + saved_sac = divelog.dives.back()->sac; clear_dive_file_data(); parseCSVmanual(1, "testcsvexportmanualimperial.csv"); // We do not currently support reading SAC, thus faking it - if (!divelog.dives->empty()) - divelog.dives->back()->sac = saved_sac; + if (!divelog.dives.empty()) + divelog.dives.back()->sac = saved_sac; export_dives_xslt("testcsvexportmanual2.csv", 0, 0, "xml2manualcsv.xslt", false); @@ -340,8 +340,8 @@ void TestParse::exportSubsurfaceCSV() export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false); - if (!divelog.dives->empty()) - saved_sac = divelog.dives->back()->sac; + if (!divelog.dives.empty()) + saved_sac = divelog.dives.back()->sac; clear_dive_file_data(); @@ -350,8 +350,8 @@ void TestParse::exportSubsurfaceCSV() parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &divelog); // We do not currently support reading SAC, thus faking it - if (!divelog.dives->empty()) - divelog.dives->back()->sac = saved_sac; + if (!divelog.dives.empty()) + divelog.dives.back()->sac = saved_sac; export_dives_xslt("testcsvexportmanual2-cyl.csv", 0, 0, "xml2manualcsv.xslt", false); @@ -453,7 +453,7 @@ void TestParse::parseDL7() QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu", ¶ms, "DL7", &divelog), 0); - QCOMPARE(divelog.dives->size(), 3); + QCOMPARE(divelog.dives.size(), 3); QCOMPARE(save_dives("./testdl7out.ssrf"), 0); FILE_COMPARE("./testdl7out.ssrf", diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp index c675f597a..e520f9ebf 100644 --- a/tests/testrenumber.cpp +++ b/tests/testrenumber.cpp @@ -21,7 +21,7 @@ void TestRenumber::testMerge() struct divelog log; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &log), 0); add_imported_dives(log, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(divelog.dives->size(), 1); + QCOMPARE(divelog.dives.size(), 1); } void TestRenumber::testMergeAndAppend() @@ -29,7 +29,7 @@ void TestRenumber::testMergeAndAppend() struct divelog log; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &log), 0); add_imported_dives(log, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(divelog.dives->size(), 2); + QCOMPARE(divelog.dives.size(), 2); struct dive *d = get_dive(1); QVERIFY(d != NULL); if (d)