aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_divesite.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-19 19:52:54 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit8858bfa1f8cf30cc4eb070fb6e709f7051e61241 (patch)
tree02c40484ff879ce3bba48085c6fab2809cef43ea /desktop-widgets/command_divesite.cpp
parentfde80eeaa5f4ee4150f9292c5783eb790b0fcb96 (diff)
downloadsubsurface-8858bfa1f8cf30cc4eb070fb6e709f7051e61241.tar.gz
Dive site: implement purge of unused dive sites
Add a "purge unused dive sites" button to the dive site list. Connect it to a new PurgeUnusedDiveSites command. Implementation was trivial: simply copy the DeleteDiveSites command. 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.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp
index a5dce00d1..3b35ddcc2 100644
--- a/desktop-widgets/command_divesite.cpp
+++ b/desktop-widgets/command_divesite.cpp
@@ -105,6 +105,31 @@ void DeleteDiveSites::undo()
sitesToRemove = std::move(addDiveSites(sitesToAdd));
}
+PurgeUnusedDiveSites::PurgeUnusedDiveSites()
+{
+ setText(tr("purge unused dive sites"));
+ for (int i = 0; i < dive_site_table.nr; ++i) {
+ dive_site *ds = dive_site_table.dive_sites[i];
+ if (ds->dives.nr == 0)
+ sitesToRemove.push_back(ds);
+ }
+}
+
+bool PurgeUnusedDiveSites::workToBeDone()
+{
+ return !sitesToRemove.empty();
+}
+
+void PurgeUnusedDiveSites::redo()
+{
+ sitesToAdd = std::move(removeDiveSites(sitesToRemove));
+}
+
+void PurgeUnusedDiveSites::undo()
+{
+ sitesToRemove = std::move(addDiveSites(sitesToAdd));
+}
+
// Helper function: swap C and Qt string
static void swap(char *&c, QString &q)
{