summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_edit.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-23 20:27:19 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-15 11:20:49 -0700
commit03d5e641e1284b9613f605690d04faf48ac40715 (patch)
treea58f1a8157af423f9a50f0030f5ed96b86508623 /desktop-widgets/command_edit.h
parent1641147e7b77db69f829cf9b41de4c313d45e3ed (diff)
downloadsubsurface-03d5e641e1284b9613f605690d04faf48ac40715.tar.gz
Undo: return number of changed dives from undo commands
To enable a "multiple dives edited" message, return the number of edited dives from dive edit undo commands. Since there are two kinds of these commands, viz. normal fields and tag fields, and the former use templates, create a common base class that can return the number of dives. Yes, the class hierarchy is getting scarily deep! At least, this gives a tiny bit of code-reuse. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_edit.h')
-rw-r--r--desktop-widgets/command_edit.h30
1 files changed, 17 insertions, 13 deletions
diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h
index a1050d65e..13f1e3bbf 100644
--- a/desktop-widgets/command_edit.h
+++ b/desktop-widgets/command_edit.h
@@ -23,8 +23,23 @@
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {
+// Base class for commands that have a list of dives.
+// This is used for extracting the number of dives and show a
+// warning message when multiple dives are edited.
+class EditDivesBase : public Base {
+protected:
+ EditDivesBase(bool currentDiveOnly);
+ std::vector<dive *> dives; // Dives to be edited.
+
+ // On undo, we set the selection and current dive at the time of the operation.
+ std::vector<dive *> selectedDives;
+ struct dive *current;
+public:
+ int numDives() const;
+};
+
template <typename T>
-class EditBase : public Base {
+class EditBase : public EditDivesBase {
protected:
T value; // Value to be set
T old; // Previous value
@@ -33,10 +48,6 @@ protected:
void redo() override;
bool workToBeDone() override;
- std::vector<dive *> dives; // Dives to be edited.
- // On undo, we set the selection and current dive at the time of the operation.
- std::vector<dive *> selectedDives;
- struct dive *current;
public:
EditBase(T newValue, bool currentDiveOnly);
@@ -166,16 +177,9 @@ public:
// Fields that work with tag-lists (tags, buddies, divemasters) work differently and therefore
// have their own base class. In this case, it's not a template, as all these lists are base
// on strings.
-class EditTagsBase : public Base {
+class EditTagsBase : public EditDivesBase {
bool workToBeDone() override;
- // Dives to be edited. For historical reasons, the *last* entry was
- // the active dive when the user initialized the action. This dive
- // will be made the current dive on redo / undo.
- std::vector<dive *> dives;
- // On undo, we set the selection and current dive at the time of the operation.
- std::vector<dive *> selectedDives;
- struct dive *current;
QStringList newList; // Temporary until initialized
public:
EditTagsBase(const QStringList &newList, bool currentDiveOnly);