Autogroup only when selected

Comits f427226b3b and 43c3885249 of the undo series introduced 2 calls
of autogroup_dives() without checking the autogroup global boolean.
This is a bug. An import from DC (for example) then triggers an
autogrouping, the divelist is autogrouped, and the UI button
is off.

This commit solves this. I've chosen for a guard in the autogroup_dives()
that now is a no-op when called when the user did not select autogrouping.
In additon, simplified the other calls to this function, as we do
not need to check before calling any more.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2018-10-14 08:20:59 +02:00
parent 068b01aef2
commit ac9bab7e2f
3 changed files with 9 additions and 9 deletions

View file

@ -1023,7 +1023,8 @@ dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocat
} }
/* /*
* Walk the dives from the oldest dive, and see if we can autogroup them * Walk the dives from the oldest dive, and see if we can autogroup them.
* But only do this when the user selected autogrouping.
*/ */
void autogroup_dives(void) void autogroup_dives(void)
{ {
@ -1032,6 +1033,9 @@ void autogroup_dives(void)
int i, j; int i, j;
bool alloc; bool alloc;
if (!autogroup)
return;
for(i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) { for(i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) {
/* If this was newly allocated, add trip to list */ /* If this was newly allocated, add trip to list */
if (alloc) if (alloc)

View file

@ -612,8 +612,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
if (!parse_file(fileNamePtr.data(), &dive_table)) if (!parse_file(fileNamePtr.data(), &dive_table))
setCurrentFile(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
process_loaded_dives(); process_loaded_dives();
if (autogroup) autogroup_dives();
autogroup_dives();
Command::clear(); Command::clear();
hideProgressBar(); hideProgressBar();
refreshDisplay(); refreshDisplay();
@ -1713,8 +1712,7 @@ void MainWindow::importFiles(const QStringList fileNames)
parse_file(fileNamePtr.data(), &table); parse_file(fileNamePtr.data(), &table);
} }
process_imported_dives(&table, false, false); process_imported_dives(&table, false, false);
if (autogroup) autogroup_dives();
autogroup_dives();
Command::clear(); Command::clear();
refreshDisplay(); refreshDisplay();
} }
@ -1738,8 +1736,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
hideProgressBar(); hideProgressBar();
updateRecentFiles(); updateRecentFiles();
process_loaded_dives(); process_loaded_dives();
if (autogroup) autogroup_dives();
autogroup_dives();
Command::clear(); Command::clear();
refreshDisplay(); refreshDisplay();

View file

@ -174,8 +174,7 @@ void DiveImportedModel::recordDives()
} }
process_imported_dives(diveTable, true, true); process_imported_dives(diveTable, true, true);
if (autogroup) autogroup_dives();
autogroup_dives();
} }
QHash<int, QByteArray> DiveImportedModel::roleNames() const { QHash<int, QByteArray> DiveImportedModel::roleNames() const {