aboutsummaryrefslogtreecommitdiffstats
path: root/commands/command_edit_trip.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-13 15:08:40 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-11-14 21:02:07 +0100
commit5e29245e689fe9401ee1c33ebb07c601ce25e8c6 (patch)
treea656bcb0e9357b8cab78c5ad196fc6e5a4da4c31 /commands/command_edit_trip.h
parent685b92b9c2ddd6575ae5df7c95b928e60fcd7005 (diff)
downloadsubsurface-5e29245e689fe9401ee1c33ebb07c601ce25e8c6.tar.gz
Refactoring: move undo commands to top level
In the future we might want to use undo-commands for mobile as well (even if not implementing undo). Therefore, move the undo-command source from desktop-widgets to their own commands top-level folder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_edit_trip.h')
-rw-r--r--commands/command_edit_trip.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/commands/command_edit_trip.h b/commands/command_edit_trip.h
new file mode 100644
index 000000000..ae41ca252
--- /dev/null
+++ b/commands/command_edit_trip.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0
+// Note: this header file is used by the undo-machinery and should not be included elsewhere.
+
+#ifndef COMMAND_EDIT_TRIP_H
+#define COMMAND_EDIT_TRIP_H
+
+#include "command_base.h"
+#include "core/subsurface-qt/DiveListNotifier.h"
+
+#include <QVector>
+
+// These are commands that edit individual fields of a a trip.
+// The implementation follows the (rather verbose) OO-style of the dive-edit commands.
+// But here, no template is used as the two fields are both of string type.
+
+// We put everything in a namespace, so that we can shorten names without polluting the global namespace
+namespace Command {
+
+class EditTripBase : public Base {
+ bool workToBeDone() override;
+
+ dive_trip *trip; // Trip to be edited.
+public:
+ EditTripBase(dive_trip *trip, const QString &newValue);
+
+protected:
+ QString value; // Value to be set
+ void undo() override;
+ void redo() override;
+
+ // Get and set functions to be overriden by sub-classes.
+ virtual void set(struct dive_trip *t, const QString &) const = 0;
+ virtual QString data(struct dive_trip *t) const = 0;
+ virtual QString fieldName() const = 0; // Name of the field, used to create the undo menu-entry
+ virtual TripField fieldId() const = 0;
+};
+
+class EditTripLocation : public EditTripBase {
+public:
+ using EditTripBase::EditTripBase; // Use constructor of base class.
+ void set(dive_trip *t, const QString &s) const override;
+ QString data(dive_trip *t) const override;
+ QString fieldName() const override;
+ TripField fieldId() const override;
+};
+
+class EditTripNotes : public EditTripBase {
+public:
+ using EditTripBase::EditTripBase; // Use constructor of base class.
+ void set(dive_trip *t, const QString &s) const override;
+ QString data(dive_trip *t) const override;
+ QString fieldName() const override;
+ TripField fieldId() const override;
+};
+
+} // namespace Command
+
+#endif