diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-16 14:46:08 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-16 20:31:35 -0800 |
commit | 7e9a7b6223990d5431a6177f3ccbabfac0c95bdb (patch) | |
tree | 63973dfbaed2b1d04819310bbde91d21181f721a | |
parent | 314cf4c628ac6e709de93f18be384fe819b46f81 (diff) | |
download | subsurface-7e9a7b6223990d5431a6177f3ccbabfac0c95bdb.tar.gz |
Fix dive merging
This limits merging dives to dives that have at most half an hour of
surface time between them. That "half hour" is kind of a random thing
to pick, but it's not horribly horribly wrong.
It also changes the semantics of "merge selected dives" to something
that actually works pretty well: you can select a whole range of
dives, and it will merge only the ones that makes sense to merge. I
tested it, and it's reasonable. I could select all my dives from one
dive trip, and then do "Merge selected dives", and it did the right
thing (Dirk: I selected the florida trip, and it merged the aborted
"missed the trench" dive with the _actual_ "trench" dive).
I'm _slightly_ hesitant about this in the sense that maybe some crazy
person actually would want to merge dives with more than half an hour
of surface time between them, but it really doesn't seem to make much
sense.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelistview.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 91201c5b5..9f7517308 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -388,6 +388,18 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS Q_EMIT currentDiveChanged(selected_dive); } +static bool can_merge(const struct dive *a, const struct dive *b) +{ + if (!a || !b) + return false; + if (a->when > b->when) + return false; + /* Don't merge dives if there's more than half an hour between them */ + if (a->when + a->duration.seconds + 30*60 < b->when) + return false; + return true; +} + void DiveListView::mergeDives() { int i; @@ -395,7 +407,7 @@ void DiveListView::mergeDives() for_each_dive(i, dive) { if (dive->selected) { - if (!maindive) { + if (!can_merge(maindive, dive)) { maindive = dive; } else { maindive = merge_two_dives(maindive, dive); |