From 8858bfa1f8cf30cc4eb070fb6e709f7051e61241 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 19 Mar 2019 19:52:54 +0100 Subject: 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 --- desktop-widgets/command_divesite.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'desktop-widgets/command_divesite.cpp') 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) { -- cgit v1.2.3-70-g09d2