From b61732da42b8df3900a889a4e7177a633cd14c29 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 12 Nov 2022 09:14:00 +0100 Subject: [PATCH] core: remove autogroup global Use the flag in the divelog structure, since this will be saved in the dive log. Signed-off-by: Berthold Stoeger --- core/dive.h | 3 --- core/divelist.c | 11 +---------- core/load-git.c | 5 ++--- core/parse-xml.c | 10 +++++----- core/save-git.c | 2 +- core/save-xml.c | 2 +- desktop-widgets/mainwindow.cpp | 14 ++++++++++---- desktop-widgets/mainwindow.h | 1 + mobile-widgets/qmlmanager.cpp | 2 +- qt-models/diveplannermodel.cpp | 2 +- 10 files changed, 23 insertions(+), 29 deletions(-) diff --git a/core/dive.h b/core/dive.h index d1df22193..91b20b785 100644 --- a/core/dive.h +++ b/core/dive.h @@ -110,8 +110,6 @@ extern int mbar_to_depth(int mbar, const struct dive *dive); extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto); extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto); -extern bool autogroup; - extern struct dive displayed_dive; extern unsigned int dc_number; extern struct dive *current_dive; @@ -208,7 +206,6 @@ extern bool cylinder_with_sensor_sample(const struct dive *dive, int cylinder_id extern void invalidate_dive_cache(struct dive *dc); -extern void set_autogroup(bool value); extern int total_weight(const struct dive *); extern const char *existing_filename; diff --git a/core/divelist.c b/core/divelist.c index ce1aae538..e4d68b616 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -22,15 +22,6 @@ #include "table.h" #include "trip.h" -bool autogroup = false; - -void set_autogroup(bool value) -{ - /* if we keep the UI paradigm, this needs to toggle - * the checkbox on the autogroup menu item */ - autogroup = value; -} - /* * Get "maximal" dive gas for a dive. * Rules: @@ -724,7 +715,7 @@ static void autogroup_dives(struct dive_table *table, struct trip_table *trip_ta int i, j; bool alloc; - if (!autogroup) + if (!divelog.autogroup) return; for (i = 0; (trip = get_dives_to_autogroup(table, i, &from, &to, &alloc)) != NULL; i = to) { diff --git a/core/load-git.c b/core/load-git.c index 47c769b7d..4485250ec 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -901,12 +901,11 @@ static void parse_trip_location(char *line, struct membuffer *str, struct git_pa static void parse_trip_notes(char *line, struct membuffer *str, struct git_parser_state *state) { UNUSED(line); state->active_trip->notes = detach_cstring(str); } -static void parse_settings_autogroup(char *line, struct membuffer *str, struct git_parser_state *_unused) +static void parse_settings_autogroup(char *line, struct membuffer *str, struct git_parser_state *state) { UNUSED(line); UNUSED(str); - UNUSED(_unused); - set_autogroup(true); + state->log->autogroup = true; } static void parse_settings_units(char *line, struct membuffer *str, struct git_parser_state *unused) diff --git a/core/parse-xml.c b/core/parse-xml.c index b0385eafa..9ca16772f 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -690,13 +690,13 @@ static void eventtime(char *buffer, duration_t *duration, struct parser_state *s duration->seconds += state->cur_sample->time.seconds; } -static void try_to_match_autogroup(const char *name, char *buf) +static void try_to_match_autogroup(const char *name, char *buf, struct parser_state *state) { - bool autogroupvalue; + bool autogroup; start_match("autogroup", name, buf); - if (MATCH("state.autogroup", get_bool, &autogroupvalue)) { - set_autogroup(autogroupvalue); + if (MATCH("state.autogroup", get_bool, &autogroup)) { + state->log->autogroup = autogroup; return; } nonmatch("autogroup", name, buf); @@ -1503,7 +1503,7 @@ static bool entry(const char *name, char *buf, struct parser_state *state) if (state->in_settings) { try_to_fill_fingerprint(name, buf, state); try_to_fill_dc_settings(name, buf, state); - try_to_match_autogroup(name, buf); + try_to_match_autogroup(name, buf, state); return true; } if (state->cur_dive_site) { diff --git a/core/save-git.c b/core/save-git.c index deb958603..a6f3e25cf 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -890,7 +890,7 @@ static void save_settings(git_repository *repo, struct dir *tree) for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++) save_one_fingerprint(&b, i); - cond_put_format(autogroup, &b, "autogroup\n"); + cond_put_format(divelog.autogroup, &b, "autogroup\n"); save_units(&b); if (prefs.tankbar) put_string(&b, "prefs TANKBAR\n"); diff --git a/core/save-xml.c b/core/save-xml.c index 979e9aa4d..463f7372a 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -692,7 +692,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym for (int i = 0; i < nr_fingerprints(&fingerprint_table); i++) save_one_fingerprint(b, i); - if (autogroup) + if (divelog.autogroup) put_format(b, " \n"); put_format(b, "\n"); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 9ea55a218..ec7beaba2 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -323,7 +323,11 @@ void MainWindow::refreshDisplay() setApplicationState(ApplicationState::Default); diveList->setEnabled(true); diveList->setFocus(); - ui.actionAutoGroup->setChecked(autogroup); +} + +void MainWindow::updateAutogroup() +{ + ui.actionAutoGroup->setChecked(divelog.autogroup); } void MainWindow::selectionChanged() @@ -419,6 +423,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() process_loaded_dives(); hideProgressBar(); refreshDisplay(); + updateAutogroup(); } // Return whether saving to cloud is OK. If it isn't, show an error return false. @@ -695,7 +700,7 @@ void MainWindow::on_actionAddDive_triggered() fake_dc(&d.dc); fixup_dive(&d); - Command::addDive(&d, autogroup, true); + Command::addDive(&d, divelog.autogroup, true); } void MainWindow::on_actionRenumber_triggered() @@ -706,8 +711,8 @@ void MainWindow::on_actionRenumber_triggered() void MainWindow::on_actionAutoGroup_triggered() { - set_autogroup(ui.actionAutoGroup->isChecked()); - if (autogroup) + divelog.autogroup = ui.actionAutoGroup->isChecked(); + if (divelog.autogroup) Command::autogroupDives(); else Command::removeAutogenTrips(); @@ -1308,6 +1313,7 @@ void MainWindow::loadFiles(const QStringList fileNames) process_loaded_dives(); refreshDisplay(); + updateAutogroup(); int min_datafile_version = get_min_datafile_version(); if (min_datafile_version >0 && min_datafile_version < DATAFORMAT_VERSION) { diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index 8b9a62820..a88ae9f34 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -189,6 +189,7 @@ private: void hideProgressBar(); void writeSettings(); void refreshDisplay(); + void updateAutogroup(); void showProfile(); int file_save(); int file_save_as(); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 81155c8cf..4c46a8434 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1720,7 +1720,7 @@ int QMLManager::addDive() // addDive takes over the dive and clears out the structure passed in // we do NOT save the modified data at this stage because of the UI flow here... this will // be saved once the user finishes editing the newly added dive - Command::addDive(&d, autogroup, true); + Command::addDive(&d, divelog.autogroup, true); if (verbose) appendTextToLog(QString("Adding new dive with id '%1'").arg(diveId)); diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index d6b7e95f9..79e6afa84 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1338,7 +1338,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy) // we were planning a new dive, not re-planning an existing one d->divetrip = nullptr; // Should not be necessary, just in case! #if !defined(SUBSURFACE_TESTING) - Command::addDive(d, autogroup, true); + Command::addDive(d, divelog.autogroup, true); #endif // !SUBSURFACE_TESTING } else { copy_events_until(current_dive, d, preserved_until.seconds);