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>
This commit is contained in:
Berthold Stoeger 2020-01-01 23:45:52 +01:00 committed by Dirk Hohndel
parent 2ad7b26f4b
commit 5493e7cbf6
3 changed files with 21 additions and 13 deletions

View file

@ -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;

View file

@ -1557,16 +1557,28 @@ void QMLManager::cancelDownloadDC()
import_thread_cancelled = true;
}
QString QMLManager::addDive()
int QMLManager::addDive()
{
appendTextToLog("Adding new dive.");
return DiveListModel::instance()->startAddDive();
}
// 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);
void QMLManager::addDiveAborted(int id)
{
DiveListModel::instance()->removeDiveById(id);
delete_single_dive(get_idx_by_uniq_id(id));
// addDive takes over the dive and clears out the structure passed in
Command::addDive(&d, autogroup, true);
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()

View file

@ -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();