From a4043401c90c41322aa257cec7dee70592db59d8 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 20 Feb 2020 13:24:38 -0800 Subject: [PATCH] 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 --- mobile-widgets/qmlmanager.cpp | 18 ++++++++++++++++++ mobile-widgets/qmlmanager.h | 1 + 2 files changed, 19 insertions(+) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index c4ddac44e..81990efe8 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1299,6 +1299,24 @@ void QMLManager::removeDiveFromTrip(int id) 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 dives; + dives.append(d); + Command::addDivesToTrip(dives, dt); + changesNeedSaving(); +} + void QMLManager::changesNeedSaving() { // we no longer save right away on iOS because file access is so slow; on the other hand, diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index f368ea99d..45c32664f 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -178,6 +178,7 @@ public slots: QString diveMaster, QString weight, QString notes, QStringList startpressure, QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state); void removeDiveFromTrip(int id); + void addDiveToTrip(int id, int tripId); void changesNeedSaving(); void openNoCloudRepo(); void saveChangesLocal();