mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:43:23 +00:00
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>
This commit is contained in:
parent
314cf4c628
commit
7e9a7b6223
1 changed files with 13 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue