From 3629a87fccdccc730ef47aecb995942e0d1fc01e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 8 Jun 2022 13:47:13 -0700 Subject: [PATCH] Change semantic for editing cylinders for multiple dives Instead of trying to find matching cylinders, trigger on the cylinder number first and then only edit that n-th cylinder if it matches the one in the current dive. Signed-off-by: Dirk Hohndel --- CHANGELOG.md | 1 + commands/command_edit.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d091e49..481317a79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- core: when modifying cylinders across multiple dives, match cylinder number before comparing type - core: merge all properties in a dive, including current, waveheight, etc - core: prevent crash when merging dives without cylinders (as we might get when importing from divelogs.de) - core: work around bug in TecDiving dive computer reporting spurious 0 deg C water temperature in first sample diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 7fbbc927c..8de9ddc63 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1222,12 +1222,19 @@ EditCylinderBase::EditCylinderBase(int index, bool currentDiveOnly, bool nonProt cyl.reserve(dives.size()); for (dive *d: dives) { - int idx = d == current ? index : find_cylinder_index(d, orig, sameCylinderFlags); - if (idx < 0 || (nonProtectedOnly && is_cylinder_prot(d, idx))) + if (nonProtectedOnly && is_cylinder_prot(d, index)) continue; + if (d != current && + (!same_cylinder_size(orig, *get_cylinder(d, index)) || !same_cylinder_type(orig, *get_cylinder(d, index)))) + // when editing cylinders, we assume that the user wanted to edit the 'n-th' cylinder + // and we only do edit that cylinder, if it was the same type as the one in the current dive + continue; + divesNew.push_back(d); - indexes.push_back(idx); - cyl.push_back(clone_cylinder(*get_cylinder(d, idx))); + // that's silly as it's always the same value - but we need this vector of indices in the case where we add + // a cylinder to several dives as the spot will potentially be different in different dives + indexes.push_back(index); + cyl.push_back(clone_cylinder(*get_cylinder(d, index))); } dives = std::move(divesNew); }