summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-06 09:21:27 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-07 05:41:48 +0300
commitc32e71e64d97016d201aea26f0623de6cd65d74d (patch)
treed2dbd6a326701aba1e031a5f6508a5d811e2a34f /desktop-widgets
parentcec0b703652ffb4ab53fd792bee0cbf095b38cca (diff)
downloadsubsurface-c32e71e64d97016d201aea26f0623de6cd65d74d.tar.gz
Dive information: fix surface interval calculation
The old surface interval calculation had fundamental issues: 1) process_all_dives(), which calculates the statistics over *all* dives was used to get the pointer to the previous dive. 2) If two dives in the table had the same time, one of those would have been considered the "previous" dive. 3) If the dive, for which the surface interval is calculated is not yet in the table, no previous dive would be determined. Fix all this by creating a get_surface_interval() function and removing the "get previous dive" functionality of process_all_dives(). Remove the process_all_dives() call from TabDiveInformation::updateData(). Reported-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/tab-widgets/TabDiveInformation.cpp9
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp4
2 files changed, 4 insertions, 9 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp
index a4f8f455f..aff781a3b 100644
--- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp
@@ -77,12 +77,9 @@ void TabDiveInformation::updateData()
ui->diveTimeText->setText(get_dive_duration_string(displayed_dive.duration.seconds, tr("h"), tr("min"), tr("sec"),
" ", displayed_dive.dc.divemode == FREEDIVE));
- struct dive *prevd;
- process_all_dives(&displayed_dive, &prevd);
-
- if (prevd)
- ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (dive_endtime(prevd)), tr("d"), tr("h"), tr("min")));
-
+ timestamp_t surface_interval = get_surface_interval(displayed_dive.when);
+ if (surface_interval >= 0)
+ ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min")));
else
ui->surfaceIntervalText->clear();
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index eb8292b1a..ffcb70f5a 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -429,10 +429,8 @@ void MainTab::updateDiveInfo(bool clear)
// If exactly one trip has been selected, we show the location / notes
// for the trip in the Info tab, otherwise we show the info of the
// selected_dive
- struct dive *prevd;
-
process_selected_dives();
- process_all_dives(&displayed_dive, &prevd);
+ process_all_dives();
for (auto widget : extraWidgets) {
widget->updateData();