diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-13 20:58:25 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 56dcbd9588fa3b7d70a4b639b71cb18e1c462067 (patch) | |
tree | 7a82e3bcc5e56d8c755f1e0244b5ef296bebaa39 /desktop-widgets/command_divesite.cpp | |
parent | 2dcc0a7d1ebf6435060168f343df2adb5f0abb3c (diff) | |
download | subsurface-56dcbd9588fa3b7d70a4b639b71cb18e1c462067.tar.gz |
Undo: implement undo of dive site addition
Implement a dive site addition undo command and connect it to
the add dive site button. The added dive site has a default
name ("new dive site").
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_divesite.cpp')
-rw-r--r-- | desktop-widgets/command_divesite.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp index 28d47d603..b3a4911e5 100644 --- a/desktop-widgets/command_divesite.cpp +++ b/desktop-widgets/command_divesite.cpp @@ -62,6 +62,28 @@ static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> & return res; } +AddDiveSite::AddDiveSite(const QString &name) +{ + setText(tr("add dive site")); + sitesToAdd.emplace_back(alloc_dive_site()); + sitesToAdd.back()->name = copy_qstring(name); +} + +bool AddDiveSite::workToBeDone() +{ + return true; +} + +void AddDiveSite::redo() +{ + sitesToRemove = std::move(addDiveSites(sitesToAdd)); +} + +void AddDiveSite::undo() +{ + sitesToAdd = std::move(removeDiveSites(sitesToRemove)); +} + DeleteDiveSites::DeleteDiveSites(const QVector<dive_site *> &sites) : sitesToRemove(sites.toStdVector()) { setText(tr("delete %n dive site(s)", "", sites.size())); |