diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-06-23 12:13:25 +0200 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-06-23 20:08:46 +0200 |
commit | 4716c820322dd654e43dc47087866b066b2e5910 (patch) | |
tree | fe35e14b3da25e8dad84427cf1b0de2f4de86396 /desktop-widgets/command_divelist.cpp | |
parent | e1abf9485cf59f1b8cb79d827fa386af48f095a4 (diff) | |
download | subsurface-4716c820322dd654e43dc47087866b066b2e5910.tar.gz |
Cleanup: remove selectionChanged logic from dive-list commands
Since all commands now fully reset the selection, there is no point
in keeping track of whether the selection changed on addition or
removal of dives. This can be done in the function that sets the
selection.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_divelist.cpp')
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 56 |
1 files changed, 16 insertions, 40 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 26708e07d..5a318e8a3 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -21,17 +21,10 @@ namespace Command { // set and that the trips are added before they are used! DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<OwningTripPtr> &tripsToAdd) { - // If the dive to be removed is selected, we will inform the frontend - // later via a signal that the dive changed. - if (d->selected) - selectionChanged = true; - // If the dive was the current dive, reset the current dive. The calling // command is responsible of finding a new dive. - if (d == current_dive) { - selectionChanged = true; // Should have been set above, as current dive is always selected. + if (d == current_dive) current_dive = nullptr; - } // remove dive from trip and site - if this is the last dive in the trip // remove the whole trip. @@ -81,11 +74,6 @@ dive *DiveListBase::addDive(DiveToAdd &d) add_to_dive_table(&dive_table, idx, res); // Return ownership to backend invalidate_dive_cache(res); // Ensure that dive is written in git_save() - // If the dive to be removed is selected, we will inform the frontend - // later via a signal that the dive changed. - if (res->selected) - selectionChanged = true; - return res; } @@ -363,26 +351,14 @@ static void moveDivesBetweenTrips(DivesToTrip &dives) void DiveListBase::initWork() { - selectionChanged = false; } void DiveListBase::finishWork() { - if (selectionChanged) // If the selection changed -> tell the frontend - emit diveListNotifier.selectionChanged(); for (dive_site *ds: sitesCountChanged) emit diveListNotifier.diveSiteDiveCountChanged(ds); } -// Rese the selection to the dives of the "selection" vector and send the appropriate signals. -// Set the current dive to "currentDive". "currentDive" must be an element of "selection" (or -// null if "seletion" is empty). -void DiveListBase::restoreSelection(const std::vector<dive *> &selection, dive *currentDive) -{ - // If anything changed (selection or current dive), send a final signal. - selectionChanged |= setSelection(selection, currentDive); -} - void DiveListBase::undo() { auto marker = diveListNotifier.enterCommand(); @@ -452,7 +428,7 @@ void AddDive::redoit() sort_trip_table(&trip_table); // Though unlikely, adding a dive may reorder trips // Select the newly added dive - restoreSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0]); + setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0]); // Exit from edit mode, but don't recalculate dive list // TODO: Remove edit mode @@ -466,7 +442,7 @@ void AddDive::undoit() sort_trip_table(&trip_table); // Though unlikely, removing a dive may reorder trips // ...and restore the selection - restoreSelection(selection, currentDive); + setSelection(selection, currentDive); // Exit from edit mode, but don't recalculate dive list // TODO: Remove edit mode @@ -529,7 +505,7 @@ void ImportDives::redoit() divesToAdd = removeDives(divesAndSitesToRemove); // Select the newly added dives - restoreSelection(divesAndSitesToRemoveNew.dives, divesAndSitesToRemoveNew.dives.back()); + setSelection(divesAndSitesToRemoveNew.dives, divesAndSitesToRemoveNew.dives.back()); // Remember dives and sites to remove divesAndSitesToRemove = std::move(divesAndSitesToRemoveNew); @@ -547,7 +523,7 @@ void ImportDives::undoit() divesAndSitesToRemove = std::move(divesAndSitesToRemoveNew); // ...and restore the selection - restoreSelection(selection, currentDive); + setSelection(selection, currentDive); } DeleteDive::DeleteDive(const QVector<struct dive*> &divesToDeleteIn) @@ -568,7 +544,7 @@ void DeleteDive::undoit() // Select all re-added dives and make the first one current dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr; - restoreSelection(divesToDelete.dives, currentDive); + setSelection(divesToDelete.dives, currentDive); } void DeleteDive::redoit() @@ -583,9 +559,9 @@ void DeleteDive::redoit() newCurrent = find_next_visible_dive(when); } if (newCurrent) - restoreSelection(std::vector<dive *>{ newCurrent }, newCurrent); + setSelection(std::vector<dive *>{ newCurrent }, newCurrent); else - restoreSelection(std::vector<dive *>(), nullptr); + setSelection(std::vector<dive *>(), nullptr); } @@ -615,7 +591,7 @@ void ShiftTime::redoit() emit diveListNotifier.divesChanged(diveList, DiveField::DATETIME); // Select the changed dives - restoreSelection(diveList.toStdVector(), diveList[0]); + setSelection(diveList.toStdVector(), diveList[0]); // Negate the time-shift so that the next call does the reverse timeChanged = -timeChanged; @@ -647,7 +623,7 @@ void RenumberDives::undoit() dives.reserve(divesToRenumber.size()); for (const QPair<dive *, int> &item: divesToRenumber) dives.push_back(item.first); - restoreSelection(dives, dives[0]); + setSelection(dives, dives[0]); } bool RenumberDives::workToBeDone() @@ -676,7 +652,7 @@ void TripBase::redoit() dives.reserve(divesToMove.divesToMove.size()); for (const DiveToTrip &item: divesToMove.divesToMove) dives.push_back(item.dive); - restoreSelection(dives, dives[0]); + setSelection(dives, dives[0]); } void TripBase::undoit() @@ -799,7 +775,7 @@ void SplitDivesBase::redoit() unsplitDive = removeDives(diveToSplit); // Select split dives and make first dive current - restoreSelection(divesToUnsplit.dives, divesToUnsplit.dives[0]); + setSelection(divesToUnsplit.dives, divesToUnsplit.dives[0]); } void SplitDivesBase::undoit() @@ -809,7 +785,7 @@ void SplitDivesBase::undoit() splitDives = removeDives(divesToUnsplit); // Select unsplit dive and make it current - restoreSelection(diveToSplit.dives, diveToSplit.dives[0] ); + setSelection(diveToSplit.dives, diveToSplit.dives[0] ); } static std::array<dive *, 2> doSplitDives(const dive *d, duration_t time) @@ -883,7 +859,7 @@ void DiveComputerBase::redoit() diveToRemove = std::move(addedDive); // Select added dive and make it current - restoreSelection(diveToRemove.dives, diveToRemove.dives[0]); + setSelection(diveToRemove.dives, diveToRemove.dives[0]); // Update the profile to show the first dive computer dc_number = dc_nr_after; @@ -1006,7 +982,7 @@ void MergeDives::redoit() unmergedDives = removeDives(divesToMerge); // Select merged dive and make it current - restoreSelection(diveToUnmerge.dives, diveToUnmerge.dives[0]); + setSelection(diveToUnmerge.dives, diveToUnmerge.dives[0]); } void MergeDives::undoit() @@ -1016,7 +992,7 @@ void MergeDives::undoit() renumberDives(divesToRenumber); // Select unmerged dives and make first one current - restoreSelection(divesToMerge.dives, divesToMerge.dives[0]); + setSelection(divesToMerge.dives, divesToMerge.dives[0]); } } // namespace Command |