summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
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();