summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
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/qmlmanager.cpp
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/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp30
1 files changed, 21 insertions, 9 deletions
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()