summaryrefslogtreecommitdiffstats
path: root/qt-models/divelistmodel.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-29 11:53:22 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-29 11:26:16 -0800
commit16c082112c6d057d734d4765b466e315389ce694 (patch)
tree361151e47b28f5d120fe38f4c0c6351cccbc7698 /qt-models/divelistmodel.cpp
parenta1aa83fcfd9a3a365c12974b6956e4f9b8323cf1 (diff)
downloadsubsurface-16c082112c6d057d734d4765b466e315389ce694.tar.gz
QML UI: pick new highest dive number when manually adding dive
It's possible that this will create an out of order dive list, but it seems the most consistent way to do things and to avoid more than one dive with the same dive number (which could have happened if you add several dives manually that are not the newest dives in the dive list). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/divelistmodel.cpp')
-rw-r--r--qt-models/divelistmodel.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 9ddf05dbc..bef2c5158 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -119,10 +119,15 @@ QString DiveListModel::startAddDive()
struct dive *d;
d = alloc_dive();
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;
+
+ // find the highest dive nr we have and pick the next one
+ struct dive *pd;
+ int i, nr = 0;
+ for_each_dive(i, pd) {
+ if (pd->number > nr)
+ nr = pd->number;
+ }
+ nr++;
d->number = nr;
d->dc.model = strdup("manually added dive");
add_single_dive(-1, d);