summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-01-01 23:45:52 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-10 09:25:57 -0700
commit5493e7cbf696c79758f2dacaba6d7109d00dea6b (patch)
tree8ed0c6b332bd7dd734c1e83811a879f9be583745 /mobile-widgets
parent2ad7b26f4b6b2fc131c57f0a014bd174b303aa90 (diff)
downloadsubsurface-5493e7cbf696c79758f2dacaba6d7109d00dea6b.tar.gz
mobile UI: use undo-command for adding dive.
Instead of using the model, copy the code we have in the desktop version which manually creates a 15m/40min dive and passes that to the addDive undo command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r--mobile-widgets/qml/DiveDetails.qml3
-rw-r--r--mobile-widgets/qmlmanager.cpp30
-rw-r--r--mobile-widgets/qmlmanager.h3
3 files changed, 22 insertions, 14 deletions
diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml
index 6f4c5e129..ef102542e 100644
--- a/mobile-widgets/qml/DiveDetails.qml
+++ b/mobile-widgets/qml/DiveDetails.qml
@@ -228,9 +228,6 @@ Kirigami.Page {
}
function endEditMode() {
- // if we were adding a dive, we need to remove it
- if (state === "add")
- manager.addDiveAborted(dive_id)
// just cancel the edit/add state
state = "view";
focus = false;
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index c5b025dde..b7a36f156 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -1557,16 +1557,28 @@ void QMLManager::cancelDownloadDC()
import_thread_cancelled = true;
}
-QString QMLManager::addDive()
-{
- appendTextToLog("Adding new dive.");
- return DiveListModel::instance()->startAddDive();
-}
+int QMLManager::addDive()
+{
+ // TODO: Duplicate code with desktop-widgets/mainwindow.cpp
+ // create a dive an hour from now with a default depth (15m/45ft) and duration (40 minutes)
+ // as a starting point for the user to edit
+ struct dive d = { 0 };
+ int diveId = d.id = dive_getUniqID();
+ d.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
+ d.dc.duration.seconds = 40 * 60;
+ d.dc.maxdepth.mm = M_OR_FT(15, 45);
+ d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
+ d.dc.model = strdup("manually added dive"); // don't translate! this is stored in the XML file
+ fake_dc(&d.dc);
+ fixup_dive(&d);
+
+ // addDive takes over the dive and clears out the structure passed in
+ Command::addDive(&d, autogroup, true);
-void QMLManager::addDiveAborted(int id)
-{
- DiveListModel::instance()->removeDiveById(id);
- delete_single_dive(get_idx_by_uniq_id(id));
+ if (verbose)
+ appendTextToLog(QString("Adding new dive with id '%1'").arg(diveId));
+ // the QML UI uses the return value to set up the edit screen
+ return diveId;
}
QString QMLManager::getCurrentPosition()
diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h
index c5d480283..8916e9d42 100644
--- a/mobile-widgets/qmlmanager.h
+++ b/mobile-widgets/qmlmanager.h
@@ -200,8 +200,7 @@ public slots:
bool toggleCylinders(bool toggle);
bool toggleWeights(bool toggle);
void undoDelete(int id);
- QString addDive();
- void addDiveAborted(int id);
+ int addDive();
void applyGpsData();
void populateGpsData();
void cancelDownloadDC();