summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-02-24 10:57:36 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commitc4bf1ce8916c3549e51b455548f87508f3b5e23b (patch)
tree0b5909cbf63a9ef113af5c41bfacbdcab4f532c2
parent5b7a3165932d9b3fced80fec17de01eb1ad89bf7 (diff)
downloadsubsurface-c4bf1ce8916c3549e51b455548f87508f3b5e23b.tar.gz
undo: remove only "non-protected" cylinders
The undo-code must take care not to remove used cylinders. To do so, extend the constructor of EditCylinderBase, which collects the cylinders and dives to edit, by the "nonProtectedOnly" boolean argument. If true, only those cylinders for wich "is_cylinder_prot" returns false will be added. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--commands/command_edit.cpp16
-rw-r--r--commands/command_edit.h2
2 files changed, 10 insertions, 8 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index 3ba7a2823..fc5200b52 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -1053,7 +1053,7 @@ static int find_cylinder_index(const struct dive *d, const cylinder_t &cyl)
return -1;
}
-EditCylinderBase::EditCylinderBase(int index, bool currentDiveOnly) :
+EditCylinderBase::EditCylinderBase(int index, bool currentDiveOnly, bool nonProtectedOnly) :
EditDivesBase(currentDiveOnly),
cyl(empty_cylinder)
{
@@ -1070,15 +1070,17 @@ EditCylinderBase::EditCylinderBase(int index, bool currentDiveOnly) :
for (dive *d: dives) {
if (d == current) {
+ if (nonProtectedOnly && is_cylinder_prot(d, index))
+ continue;
divesNew.push_back(d);
indexes.push_back(index);
continue;
}
int idx = find_cylinder_index(d, cyl);
- if (idx >= 0) {
- divesNew.push_back(d);
- indexes.push_back(idx);
- }
+ if (idx < 0 || (nonProtectedOnly && is_cylinder_prot(d, idx)))
+ continue;
+ divesNew.push_back(d);
+ indexes.push_back(idx);
}
dives = std::move(divesNew);
}
@@ -1095,7 +1097,7 @@ bool EditCylinderBase::workToBeDone()
// ***** Remove Cylinder *****
RemoveCylinder::RemoveCylinder(int index, bool currentDiveOnly) :
- EditCylinderBase(index, currentDiveOnly)
+ EditCylinderBase(index, currentDiveOnly, true)
{
if (dives.size() == 1)
setText(tr("Remove cylinder"));
@@ -1124,7 +1126,7 @@ void RemoveCylinder::redo()
// ***** Edit Cylinder *****
EditCylinder::EditCylinder(int index, cylinder_t cylIn, bool currentDiveOnly) :
- EditCylinderBase(index, currentDiveOnly),
+ EditCylinderBase(index, currentDiveOnly, false),
new_cyl(empty_cylinder)
{
if (dives.empty())
diff --git a/commands/command_edit.h b/commands/command_edit.h
index 88f359fba..c0b79d073 100644
--- a/commands/command_edit.h
+++ b/commands/command_edit.h
@@ -390,7 +390,7 @@ private:
class EditCylinderBase : public EditDivesBase {
protected:
- EditCylinderBase(int index, bool currentDiveOnly);
+ EditCylinderBase(int index, bool currentDiveOnly, bool nonProtectedOnly);
~EditCylinderBase();
cylinder_t cyl;