mobile/undo: compile undo commands and call undo command for deletion.

First steps towards full undo on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Berthold Stoeger 2019-11-14 21:38:30 +01:00 committed by Dirk Hohndel
parent 5601104ba5
commit c0095f690f
4 changed files with 18 additions and 26 deletions

View file

@ -49,7 +49,7 @@
#include "core/worldmap-save.h"
#include "core/uploadDiveLogsDE.h"
#include "core/uploadDiveShare.h"
#include "commands/command.h"
QMLManager *QMLManager::m_instance = NULL;
bool noCloudToCloud = false;
@ -1429,28 +1429,7 @@ void QMLManager::deleteDive(int id)
appendTextToLog("trying to delete non-existing dive");
return;
}
// create the storage for the deleted dive and trip (if applicable)
if (!deletedDive)
deletedDive = alloc_dive();
copy_dive(d, deletedDive);
if (!deletedTrip) {
deletedTrip = alloc_trip();
} else {
free(deletedTrip->location);
free(deletedTrip->notes);
memset(deletedTrip, 0, sizeof(struct dive_trip));
}
// if this is the last dive in that trip, remember the trip as well
if (d->divetrip && d->divetrip->dives.nr == 1) {
*deletedTrip = *d->divetrip;
deletedTrip->location = copy_string(d->divetrip->location);
deletedTrip->notes = copy_string(d->divetrip->notes);
deletedTrip->dives.nr = 0;
deletedDive->divetrip = deletedTrip;
}
DiveListModel::instance()->removeDiveById(id);
delete_single_dive(get_idx_by_uniq_id(id));
DiveListModel::instance()->resetInternalData();
Command::deleteDive(QVector<dive *>{ d });
changesNeedSaving();
}