summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-23 15:18:59 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-09 20:58:04 -0800
commitf8327ed51bc2298e2c7ef69a1ef0f82509e8d8d4 (patch)
tree932758970f9967a25d7958ad830cd0ab08594a00
parent7923507e76e8d64c6c457664ec59f10c884a9fb0 (diff)
downloadsubsurface-f8327ed51bc2298e2c7ef69a1ef0f82509e8d8d4.tar.gz
Core: move autogroup() into divelist.c
After loading or importing, the caller usually called autogroup() to autogroup dives if so wished by the user. This has already led to bugs, when autogroup() was forgotten. Instead, call autogroup() directly in the process_loaded_dives() and process_imported_dives() functions. Not only does this prevent forgetting the call - it also means that autogrouping can be changed without changing every caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/divelist.c9
-rw-r--r--core/divelist.h1
-rw-r--r--desktop-widgets/divelogimportdialog.cpp1
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp1
-rw-r--r--desktop-widgets/mainwindow.cpp3
-rw-r--r--qt-models/diveimportedmodel.cpp1
6 files changed, 7 insertions, 9 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 3ce2d4704..8934624c4 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -25,7 +25,6 @@
* dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive)
* dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated)
* dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated)
- * void autogroup_dives(void)
* void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b)
* dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b)
* struct dive *unregister_dive(int idx)
@@ -1042,7 +1041,7 @@ 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.
* But only do this when the user selected autogrouping.
*/
-void autogroup_dives(void)
+static void autogroup_dives(void)
{
int from, to;
dive_trip_t *trip;
@@ -1354,6 +1353,9 @@ void process_loaded_dives()
set_dc_nickname(dive);
sort_table(&dive_table);
+
+ /* Autogroup dives if desired by user. */
+ autogroup_dives();
}
/*
@@ -1502,6 +1504,9 @@ void process_imported_dives(struct dive_table *import_table, bool prefer_importe
if (!sequence_changed)
try_to_renumber(preexisting);
+ /* Autogroup dives if desired by user. */
+ autogroup_dives();
+
/* We might have deleted the old selected dive.
* Choose the newest dive as selected (if any) */
current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL;
diff --git a/core/divelist.h b/core/divelist.h
index d926886b6..c276c941a 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -35,7 +35,6 @@ extern dive_trip_t *create_trip_from_dive(struct dive *dive);
extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive);
extern dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated);
extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated);
-extern void autogroup_dives(void);
extern bool consecutive_selected();
extern void select_dive(struct dive *dive);
extern void deselect_dive(struct dive *dive);
diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp
index f4f9311ff..eb551217e 100644
--- a/desktop-widgets/divelogimportdialog.cpp
+++ b/desktop-widgets/divelogimportdialog.cpp
@@ -1011,7 +1011,6 @@ void DiveLogImportDialog::on_buttonBox_accepted()
}
process_imported_dives(&table, false, false);
- autogroup_dives();
Command::clear();
MainWindow::instance()->refreshDisplay();
}
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index f92fdbb70..4221f5bf4 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -525,7 +525,6 @@ void DownloadFromDCWidget::on_ok_clicked()
// first new dive) and select it again after processing all the dives
int uniqId = table->dives[table->nr - 1]->id;
process_imported_dives(table, preferDownloaded(), true);
- autogroup_dives();
Command::clear();
// after process_imported_dives does any merging or resorting needed, we need
// to recreate the model for the dive list so we can select the newest dive
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index d836e8e61..d53d4f97e 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -617,7 +617,6 @@ void MainWindow::on_actionCloudstorageopen_triggered()
if (!parse_file(fileNamePtr.data(), &dive_table))
setCurrentFile(fileNamePtr.data());
process_loaded_dives();
- autogroup_dives();
Command::clear();
hideProgressBar();
refreshDisplay();
@@ -1715,7 +1714,6 @@ void MainWindow::importFiles(const QStringList fileNames)
parse_file(fileNamePtr.data(), &table);
}
process_imported_dives(&table, false, false);
- autogroup_dives();
Command::clear();
refreshDisplay();
}
@@ -1739,7 +1737,6 @@ void MainWindow::loadFiles(const QStringList fileNames)
hideProgressBar();
updateRecentFiles();
process_loaded_dives();
- autogroup_dives();
Command::clear();
refreshDisplay();
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index 3e8386b94..ec450d53f 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -157,7 +157,6 @@ void DiveImportedModel::recordDives()
}
process_imported_dives(diveTable, true, true);
- autogroup_dives();
}
QHash<int, QByteArray> DiveImportedModel::roleNames() const {