summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_edit.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-07-17 15:49:45 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-07-19 21:44:13 -0700
commit726d08c2f71920acd8e5cc9b2d6850d1249466aa (patch)
tree3f9e03edb013a0c5f994efce607740fdacf80261 /desktop-widgets/command_edit.cpp
parent658ac2bb788bb3617972d6108ef6fe6a277ef3ae (diff)
downloadsubsurface-726d08c2f71920acd8e5cc9b2d6850d1249466aa.tar.gz
Undo: make editing of dive number undoable
When pressing F2 in the dive list, the number can be edited. Make this action undoable by implementing a EditNumber command. This command is differs from the other undo commands, as not the currently selected dives are changed. This means that the EditCommand needs an alternative constructor taking a single dive. This constructor was implemented in the base class so that all edit commands can now be called with a single dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_edit.cpp')
-rw-r--r--desktop-widgets/command_edit.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp
index 6f69f8d8a..16fc4034e 100644
--- a/desktop-widgets/command_edit.cpp
+++ b/desktop-widgets/command_edit.cpp
@@ -33,6 +33,13 @@ EditDivesBase::EditDivesBase(bool currentDiveOnly) :
{
}
+EditDivesBase::EditDivesBase(dive *d) :
+ dives({ d }),
+ selectedDives(getDiveSelection()),
+ current(current_dive)
+{
+}
+
int EditDivesBase::numDives() const
{
return dives.size();
@@ -45,6 +52,13 @@ EditBase<T>::EditBase(T newValue, bool currentDiveOnly) :
{
}
+template<typename T>
+EditBase<T>::EditBase(T newValue, dive *d) :
+ EditDivesBase(d),
+ value(std::move(newValue))
+{
+}
+
// This is quite hackish: we can't use virtual functions in the constructor and
// therefore can't initialize the list of dives [the values of the dives are
// accessed by virtual functions]. Therefore, we (mis)use the fact that workToBeDone()
@@ -445,6 +459,28 @@ DiveField EditMode::fieldId() const
return DiveField::MODE;
}
+// ***** Number *****
+void EditNumber::set(struct dive *d, int number) const
+{
+ d->number = number;
+}
+
+int EditNumber::data(struct dive *d) const
+{
+ return d->number;
+}
+
+QString EditNumber::fieldName() const
+{
+ return tr("number");
+}
+
+DiveField EditNumber::fieldId() const
+{
+ return DiveField::NR;
+}
+
+
// ***** Tag based commands *****
EditTagsBase::EditTagsBase(const QStringList &newListIn, bool currentDiveOnly) :
EditDivesBase(currentDiveOnly),