mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Undo: fix multi-level undo of delete-dive and remove-dive-from-trip
The original undo-code was fundamentally broken. Not only did it leak resources (copied trips were never freed), it also kept references to trips or dives that could be changed by other commands. Thus, anything more than a single undo could lead to crashes. Two ways of fixing this were considered 1) Don't store pointers, but unique dive-ids and trip-ids. Whereas such unique ids exist for dives, they would have to be implemented for trips. 2) Don't free objects in the backend. Instead, take ownership of deleted objects in the undo-object. Thus, all references in previous undo-objects are guaranteed to still exist (unless the objects are deleted elsewhere). After some contemplation, the second method was chosen, because it is significantly less intrusive. While touching the undo-objects, clearly separate backend from ui-code, such that they can ultimately be reused for mobile. Note that if other parts of the code delete dives, crashes can still be provoked. Notable examples are split/merge dives. These will have to be fixed later. Nevertheless, the new code is a significant improvement over the old state. While touching the code, implement proper translation string based on Qt's plural-feature (using %n). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8074f12b91
commit
403dd5a891
7 changed files with 329 additions and 153 deletions
|
@ -679,10 +679,10 @@ void DiveListView::removeFromTrip()
|
|||
//TODO: move this to C-code.
|
||||
int i;
|
||||
struct dive *d;
|
||||
QMap<struct dive*, dive_trip*> divesToRemove;
|
||||
QVector<struct dive *> divesToRemove;
|
||||
for_each_dive (i, d) {
|
||||
if (d->selected && d->divetrip)
|
||||
divesToRemove.insert(d, d->divetrip);
|
||||
divesToRemove.append(d);
|
||||
}
|
||||
if (divesToRemove.isEmpty())
|
||||
return;
|
||||
|
@ -797,7 +797,7 @@ void DiveListView::deleteDive()
|
|||
|
||||
int i;
|
||||
int lastDiveNr = -1;
|
||||
QList<struct dive*> deletedDives; //a list of all deleted dives to be stored in the undo command
|
||||
QVector<struct dive*> deletedDives; //a list of all deleted dives to be stored in the undo command
|
||||
for_each_dive (i, d) {
|
||||
if (!d->selected)
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue