diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-03-02 04:50:00 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-03-02 04:50:00 -0800 |
commit | 62f54b54a2aa625c9568ae1b3d954489a6cf08c0 (patch) | |
tree | db890d152d49dc62f04e5a110cfa981cc332e6ab /subsurface-core | |
parent | ce83357889659c11e71e09cc1830f26f8540c08e (diff) | |
download | subsurface-62f54b54a2aa625c9568ae1b3d954489a6cf08c0.tar.gz |
QML UI: create a chronological dive list when manually adding dive
The dive list might contain dives in the future, don't add the new dive to
then end but instead add it at the correct spot in the list
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core')
-rw-r--r-- | subsurface-core/divelist.c | 13 |
1 files changed, 11 insertions, 2 deletions
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; |