mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
ce83357889
commit
62f54b54a2
2 changed files with 12 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue