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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-12 09:14:00 +01:00 committed by bstoeger
parent aa34afc3f7
commit b61732da42
10 changed files with 23 additions and 29 deletions

View file

@ -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;

View file

@ -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) {

View file

@ -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)

View file

@ -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) {

View file

@ -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");

View file

@ -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, " <autogroup state='1' />\n");
put_format(b, "</settings>\n");

View file

@ -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) {

View file

@ -189,6 +189,7 @@ private:
void hideProgressBar();
void writeSettings();
void refreshDisplay();
void updateAutogroup();
void showProfile();
int file_save();
int file_save_as();

View file

@ -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));

View file

@ -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);