diff options
-rw-r--r-- | qt-models/divelistmodel.cpp | 2 | ||||
-rw-r--r-- | subsurface-core/divelist.c | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 7e1844f3e..5275ca2bb 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -141,7 +141,7 @@ QString DiveListModel::startAddDive() d->number = nr; d->dc.model = strdup("manually added dive"); add_single_dive(-1, d); - addDive(d); + insertDive(dive_table.nr - 1 - get_idx_by_uniq_id(d->id), new DiveObjectHelper(d)); return QString::number(d->id); } diff --git a/subsurface-core/divelist.c b/subsurface-core/divelist.c index 400867882..7b10d5c99 100644 --- a/subsurface-core/divelist.c +++ b/subsurface-core/divelist.c @@ -790,9 +790,18 @@ void add_single_dive(int idx, struct dive *dive) dive_table.nr++; if (dive->selected) amount_selected++; - if (idx < 0) - // convert an idx of -1 so we do insert-at-end: + + if (idx < 0) { + // convert an idx of -1 so we do insert-in-chronological-order idx = dive_table.nr - 1; + for (int i = 0; i < dive_table.nr; i++) { + if (dive->when <= dive_table.dives[i]->when) { + idx = i; + break; + } + } + } + for (i = idx; i < dive_table.nr; i++) { struct dive *tmp = dive_table.dives[i]; dive_table.dives[i] = dive; |