summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-27 21:09:59 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commit2eeb5f4fc2d6da8a8c8950f0b479b7cb2055af07 (patch)
tree8992165c39f4926e2d5896e0549d3fc7ba9aa42c /commands
parent4e8a838f746d7319b97b56a209651a65655aca7f (diff)
downloadsubsurface-2eeb5f4fc2d6da8a8c8950f0b479b7cb2055af07.tar.gz
undo: more fine-grained editing of cylinder
Don't overwrite the full cylinder when editing a single field. Implement three "modes": editing of type, pressure and gasmix. Don't consider individual fields, because some of them are related. E.g. you can change the gasmix by setting the MOD. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands')
-rw-r--r--commands/command.cpp4
-rw-r--r--commands/command.h7
-rw-r--r--commands/command_edit.cpp38
-rw-r--r--commands/command_edit.h9
4 files changed, 49 insertions, 9 deletions
diff --git a/commands/command.cpp b/commands/command.cpp
index c173494c0..33c866e72 100644
--- a/commands/command.cpp
+++ b/commands/command.cpp
@@ -304,9 +304,9 @@ int removeCylinder(int index, bool currentDiveOnly)
return execute_edit(new RemoveCylinder(index, currentDiveOnly));
}
-int editCylinder(int index, cylinder_t cyl, bool currentDiveOnly)
+int editCylinder(int index, cylinder_t cyl, EditCylinderType type, bool currentDiveOnly)
{
- return execute_edit(new EditCylinder(index, cyl, currentDiveOnly));
+ return execute_edit(new EditCylinder(index, cyl, type, currentDiveOnly));
}
// Trip editing related commands
diff --git a/commands/command.h b/commands/command.h
index 66122ac99..fc1ddf582 100644
--- a/commands/command.h
+++ b/commands/command.h
@@ -92,7 +92,12 @@ int removeWeight(int index, bool currentDiveOnly);
int editWeight(int index, weightsystem_t ws, bool currentDiveOnly);
int addCylinder(bool currentDiveOnly);
int removeCylinder(int index, bool currentDiveOnly);
-int editCylinder(int index, cylinder_t cyl, bool currentDiveOnly);
+enum class EditCylinderType {
+ TYPE,
+ PRESSURE,
+ GASMIX
+};
+int editCylinder(int index, cylinder_t cyl, EditCylinderType type, bool currentDiveOnly);
#ifdef SUBSURFACE_MOBILE
// Edits a dive and creates a divesite (if createDs != NULL) or edits a divesite (if changeDs != NULL).
// Takes ownership of newDive and createDs!
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index d5e2d12d0..c81e67394 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -1151,9 +1151,23 @@ void RemoveCylinder::redo()
}
}
+static int editCylinderTypeToFlags(EditCylinderType type)
+{
+ switch (type) {
+ default:
+ case EditCylinderType::TYPE:
+ return SAME_TYPE | SAME_SIZE;
+ case EditCylinderType::PRESSURE:
+ return SAME_PRESS;
+ case EditCylinderType::GASMIX:
+ return SAME_GAS;
+ }
+}
+
// ***** Edit Cylinder *****
-EditCylinder::EditCylinder(int index, cylinder_t cylIn, bool currentDiveOnly) :
- EditCylinderBase(index, currentDiveOnly, false, SAME_TYPE | SAME_PRESS | SAME_GAS)
+EditCylinder::EditCylinder(int index, cylinder_t cylIn, EditCylinderType typeIn, bool currentDiveOnly) :
+ EditCylinderBase(index, currentDiveOnly, false, editCylinderTypeToFlags(typeIn)),
+ type(typeIn)
{
if (dives.empty())
return;
@@ -1184,9 +1198,23 @@ EditCylinder::EditCylinder(int index, cylinder_t cylIn, bool currentDiveOnly) :
// The base class copied the cylinders for us, let's edit them
for (int i = 0; i < (int)indexes.size(); ++i) {
- free_cylinder(cyl[i]);
- cyl[i] = cylIn;
- cyl[i].type.description = copy_qstring(description);
+ switch (type) {
+ case EditCylinderType::TYPE:
+ free((void *)cyl[i].type.description);
+ cyl[i].type = cylIn.type;
+ cyl[i].type.description = copy_qstring(description);
+ cyl[i].cylinder_use = cylIn.cylinder_use;
+ break;
+ case EditCylinderType::PRESSURE:
+ cyl[i].start.mbar = cylIn.start.mbar;
+ cyl[i].end.mbar = cylIn.end.mbar;
+ break;
+ case EditCylinderType::GASMIX:
+ cyl[i].gasmix = cylIn.gasmix;
+ cyl[i].bestmix_o2 = cylIn.bestmix_o2;
+ cyl[i].bestmix_he = cylIn.bestmix_he;
+ break;
+ }
}
}
diff --git a/commands/command_edit.h b/commands/command_edit.h
index d7c31f7f2..ab842a13c 100644
--- a/commands/command_edit.h
+++ b/commands/command_edit.h
@@ -5,6 +5,7 @@
#define COMMAND_EDIT_H
#include "command_base.h"
+#include "command.h" // for EditCylinderType
#include "core/subsurface-qt/divelistnotifier.h"
#include <QVector>
@@ -406,10 +407,16 @@ private:
void redo() override;
};
+// Instead of implementing an undo command for every single field in a cylinder,
+// we only have one and pass an edit "type". We either edit the type, pressure
+// or gasmix fields. This has mostly historical reasons rooted in the way the
+// CylindersModel code works. The model works for undo and also in the planner
+// without undo. Having a single undo-command simplifies the code there.
class EditCylinder : public EditCylinderBase {
public:
- EditCylinder(int index, cylinder_t cyl, bool currentDiveOnly); // Clones cylinder
+ EditCylinder(int index, cylinder_t cyl, EditCylinderType type, bool currentDiveOnly); // Clones cylinder
private:
+ EditCylinderType type;
void undo() override;
void redo() override;
};