mobile/trip-handling: add helper to add dive to a trip

This again uses an undo command and should be completely symmetrical to removing
a dive from a trip.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-02-20 13:24:38 -08:00
parent ccf5bf6445
commit a4043401c9
2 changed files with 19 additions and 0 deletions

View file

@ -1299,6 +1299,24 @@ void QMLManager::removeDiveFromTrip(int id)
changesNeedSaving(); changesNeedSaving();
} }
void QMLManager::addDiveToTrip(int id, int tripId)
{
struct dive *d = get_dive_by_uniq_id(id);
if (!d) {
appendTextToLog(QString("Asked to add non-existing dive with id %1 to trip %2.").arg(id).arg(tripId));
return;
}
struct dive_trip *dt = get_trip_by_uniq_id(tripId);
if (!dt) {
appendTextToLog(QString("Asked to add dive with id %1 to trip with id %2 which cannot be found.").arg(id).arg(tripId));
return;
}
QVector <dive *> dives;
dives.append(d);
Command::addDivesToTrip(dives, dt);
changesNeedSaving();
}
void QMLManager::changesNeedSaving() void QMLManager::changesNeedSaving()
{ {
// we no longer save right away on iOS because file access is so slow; on the other hand, // we no longer save right away on iOS because file access is so slow; on the other hand,

View file

@ -178,6 +178,7 @@ public slots:
QString diveMaster, QString weight, QString notes, QStringList startpressure, QString diveMaster, QString weight, QString notes, QStringList startpressure,
QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state); QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state);
void removeDiveFromTrip(int id); void removeDiveFromTrip(int id);
void addDiveToTrip(int id, int tripId);
void changesNeedSaving(); void changesNeedSaving();
void openNoCloudRepo(); void openNoCloudRepo();
void saveChangesLocal(); void saveChangesLocal();