From 17526ded58703064dedebdf53669e12f0ab4f43e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 23 Apr 2020 23:32:42 +0200 Subject: [PATCH] cleanup: move clearing of device nodes to clear_dive_file_data() It makes no sense to keep the device nodes if all the other data is cleared. Let's do this automatically and not explicitly. This ensures that the function is also called on mobile. Currently it was only called on desktop. Weirdly, the parser-tests were expecting that the device nodes were not reset by clear_dive_file_data() and therefore divecomputers were accumulating in the test results. Thus, the additional computers had to be removed from the expected test results. Signed-off-by: Berthold Stoeger --- core/device.h | 1 + core/divecomputer.cpp | 5 +++++ core/divelist.c | 2 ++ desktop-widgets/mainwindow.cpp | 5 +---- dives/DL7.xml | 5 ----- dives/TestDiveDM5.xml | 1 - dives/TestDiveDivelogsDE.xml | 2 -- dives/TestDiveSeabearHUDC.xml | 2 -- dives/TestDiveSeabearNewFormat.xml | 2 -- dives/mergedVyperOstc.xml | 2 -- tests/testparse.cpp | 5 ----- 11 files changed, 9 insertions(+), 23 deletions(-) diff --git a/core/device.h b/core/device.h index c1e767bee..65b715ba1 100644 --- a/core/device.h +++ b/core/device.h @@ -14,6 +14,7 @@ extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid); extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname); extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t, const char *, const char *, const char *), bool select_only); +extern void clear_device_nodes(); #ifdef __cplusplus } diff --git a/core/divecomputer.cpp b/core/divecomputer.cpp index 9dfe5a373..369981d07 100644 --- a/core/divecomputer.cpp +++ b/core/divecomputer.cpp @@ -85,6 +85,11 @@ extern "C" void create_device_node(const char *model, uint32_t deviceid, const c dcList.addDC(model, deviceid, nickname, serial, firmware); } +extern "C" void clear_device_nodes() +{ + dcList.dcs.clear(); +} + static bool compareDCById(const DiveComputerNode &a, const DiveComputerNode &b) { return a.deviceId < b.deviceId; diff --git a/core/divelist.c b/core/divelist.c index 994170570..c53bcb983 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -3,6 +3,7 @@ #include "subsurface-string.h" #include "deco.h" +#include "device.h" #include "divesite.h" #include "divelist.h" #include "fulltext.h" @@ -1367,6 +1368,7 @@ void clear_dive_file_data() } clear_dive(&displayed_dive); + clear_device_nodes(); reset_min_datafile_version(); clear_git_id(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index d81a2f914..693d1f60f 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -18,7 +18,6 @@ #include "core/color.h" #include "core/device.h" -#include "core/divecomputer.h" #include "core/divesitehelpers.h" #include "core/errorhelper.h" #include "core/file.h" @@ -653,7 +652,7 @@ void MainWindow::closeCurrentFile() { /* free the dives and trips */ clear_git_id(); - MultiFilterSortModel::instance()->clear(); + MultiFilterSortModel::instance()->clear(); // this clears all the core data structures setCurrentFile(nullptr); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); MapWidget::instance()->reload(); @@ -663,8 +662,6 @@ void MainWindow::closeCurrentFile() setFileClean(); clear_events(); - - dcList.dcs.clear(); } void MainWindow::updateCloudOnlineStatus() diff --git a/dives/DL7.xml b/dives/DL7.xml index 0687afa07..869da0022 100644 --- a/dives/DL7.xml +++ b/dives/DL7.xml @@ -1,10 +1,5 @@ - - - - - diff --git a/dives/TestDiveDM5.xml b/dives/TestDiveDM5.xml index a18f97578..cee358bf2 100644 --- a/dives/TestDiveDM5.xml +++ b/dives/TestDiveDM5.xml @@ -1,7 +1,6 @@ - diff --git a/dives/TestDiveDivelogsDE.xml b/dives/TestDiveDivelogsDE.xml index fe56f858f..3baac8869 100644 --- a/dives/TestDiveDivelogsDE.xml +++ b/dives/TestDiveDivelogsDE.xml @@ -1,7 +1,5 @@ - - diff --git a/dives/TestDiveSeabearHUDC.xml b/dives/TestDiveSeabearHUDC.xml index 6c76492e7..0fde14fce 100644 --- a/dives/TestDiveSeabearHUDC.xml +++ b/dives/TestDiveSeabearHUDC.xml @@ -1,7 +1,5 @@ - - diff --git a/dives/TestDiveSeabearNewFormat.xml b/dives/TestDiveSeabearNewFormat.xml index 6c8dd3b66..1647e609d 100644 --- a/dives/TestDiveSeabearNewFormat.xml +++ b/dives/TestDiveSeabearNewFormat.xml @@ -1,7 +1,5 @@ - - diff --git a/dives/mergedVyperOstc.xml b/dives/mergedVyperOstc.xml index d35141a6e..c820fbed7 100644 --- a/dives/mergedVyperOstc.xml +++ b/dives/mergedVyperOstc.xml @@ -1,9 +1,7 @@ - - diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 06c110acb..39e8a605d 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -286,11 +286,6 @@ void TestParse::testParseDLD() fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr); // Compare output - /* - * DC is not cleared from previous tests with the - * clear_dive_file_data(), so we do have an additional DC nick - * name field on the log. - */ QCOMPARE(save_dives("./testdldout.ssrf"), 0); FILE_COMPARE("./testdldout.ssrf", SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.xml")