From dc0be271bd0d4f9823eb5212287f1a74cbecc2f7 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 26 Dec 2015 21:34:45 -0800 Subject: QML UI: set up time and dive number when adding dive Most likely when you manually add a dive on a device it is just about to happen or just ended, so starting out with the current time is likely a good guess. Which makes it the last dive in the dive list, so give it the next sequential number. Signed-off-by: Dirk Hohndel --- qt-models/divelistmodel.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'qt-models/divelistmodel.cpp') diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 114cd6d1f..fcdc0dfab 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -1,5 +1,6 @@ #include "divelistmodel.h" #include "helpers.h" +#include DiveListModel *DiveListModel::m_instance = NULL; @@ -118,11 +119,18 @@ QHash DiveListModel::roleNames() const return roles; } +// create a new dive. set the current time and add it to the end of the dive list void DiveListModel::startAddDive() { struct dive *d; d = alloc_dive(); - add_single_dive(get_divenr(d), d); + d->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); + struct dive *pd = get_dive(dive_table.nr - 1); + int nr = 1; + if (pd && pd->number > 0) + nr = pd->number + 1; + d->number = nr; + add_single_dive(-1, d); addDive(d); } -- cgit v1.2.3-70-g09d2