diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-23 20:27:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-06-15 11:20:49 -0700 |
commit | 03d5e641e1284b9613f605690d04faf48ac40715 (patch) | |
tree | a58f1a8157af423f9a50f0030f5ed96b86508623 /desktop-widgets/command.cpp | |
parent | 1641147e7b77db69f829cf9b41de4c313d45e3ed (diff) | |
download | subsurface-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.cpp')
-rw-r--r-- | desktop-widgets/command.cpp | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index df1ae299d..4bbd5e059 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -145,80 +145,88 @@ void purgeUnusedDiveSites() execute(new PurgeUnusedDiveSites); } +// Execute an edit-command and return number of edited dives +static int execute_edit(EditDivesBase *cmd) +{ + int res = cmd->numDives(); + execute(cmd); + return res; +} + // Dive editing related commands -void editNotes(const QString &newValue, bool currentDiveOnly) +int editNotes(const QString &newValue, bool currentDiveOnly) { - execute(new EditNotes(newValue, currentDiveOnly)); + return execute_edit(new EditNotes(newValue, currentDiveOnly)); } -void editMode(int index, int newValue, bool currentDiveOnly) +int editMode(int index, int newValue, bool currentDiveOnly) { - execute(new EditMode(index, newValue, currentDiveOnly)); + return execute_edit(new EditMode(index, newValue, currentDiveOnly)); } -void editSuit(const QString &newValue, bool currentDiveOnly) +int editSuit(const QString &newValue, bool currentDiveOnly) { - execute(new EditSuit(newValue, currentDiveOnly)); + return execute_edit(new EditSuit(newValue, currentDiveOnly)); } -void editRating(int newValue, bool currentDiveOnly) +int editRating(int newValue, bool currentDiveOnly) { - execute(new EditRating(newValue, currentDiveOnly)); + return execute_edit(new EditRating(newValue, currentDiveOnly)); } -void editVisibility(int newValue, bool currentDiveOnly) +int editVisibility(int newValue, bool currentDiveOnly) { - execute(new EditVisibility(newValue, currentDiveOnly)); + return execute_edit(new EditVisibility(newValue, currentDiveOnly)); } -void editAirTemp(int newValue, bool currentDiveOnly) +int editAirTemp(int newValue, bool currentDiveOnly) { - execute(new EditAirTemp(newValue, currentDiveOnly)); + return execute_edit(new EditAirTemp(newValue, currentDiveOnly)); } -void editWaterTemp(int newValue, bool currentDiveOnly) +int editWaterTemp(int newValue, bool currentDiveOnly) { - execute(new EditWaterTemp(newValue, currentDiveOnly)); + return execute_edit(new EditWaterTemp(newValue, currentDiveOnly)); } -void editAtmPress(int newValue, bool currentDiveOnly) +int editAtmPress(int newValue, bool currentDiveOnly) { - execute(new EditAtmPress(newValue, currentDiveOnly)); + return execute_edit(new EditAtmPress(newValue, currentDiveOnly)); } -void editDepth(int newValue, bool currentDiveOnly) +int editDepth(int newValue, bool currentDiveOnly) { - execute(new EditDepth(newValue, currentDiveOnly)); + return execute_edit(new EditDepth(newValue, currentDiveOnly)); } -void editDuration(int newValue, bool currentDiveOnly) +int editDuration(int newValue, bool currentDiveOnly) { - execute(new EditDuration(newValue, currentDiveOnly)); + return execute_edit(new EditDuration(newValue, currentDiveOnly)); } -void editDiveSite(struct dive_site *newValue, bool currentDiveOnly) +int editDiveSite(struct dive_site *newValue, bool currentDiveOnly) { - execute(new EditDiveSite(newValue, currentDiveOnly)); + return execute_edit(new EditDiveSite(newValue, currentDiveOnly)); } -void editDiveSiteNew(const QString &newName, bool currentDiveOnly) +int editDiveSiteNew(const QString &newName, bool currentDiveOnly) { - execute(new EditDiveSiteNew(newName, currentDiveOnly)); + return execute_edit(new EditDiveSiteNew(newName, currentDiveOnly)); } -void editTags(const QStringList &newList, bool currentDiveOnly) +int editTags(const QStringList &newList, bool currentDiveOnly) { - execute(new EditTags(newList, currentDiveOnly)); + return execute_edit(new EditTags(newList, currentDiveOnly)); } -void editBuddies(const QStringList &newList, bool currentDiveOnly) +int editBuddies(const QStringList &newList, bool currentDiveOnly) { - execute(new EditBuddies(newList, currentDiveOnly)); + return execute_edit(new EditBuddies(newList, currentDiveOnly)); } -void editDiveMaster(const QStringList &newList, bool currentDiveOnly) +int editDiveMaster(const QStringList &newList, bool currentDiveOnly) { - execute(new EditDiveMaster(newList, currentDiveOnly)); + return execute_edit(new EditDiveMaster(newList, currentDiveOnly)); } void pasteDives(const dive *d, dive_components what) |