summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-06 22:15:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-16 16:57:14 -0800
commit49d11443362eaa7e6185a1dda6d11c8b8d11fc60 (patch)
tree9313f8e3431d13e209ad9bc11ae7fbc694532e87
parent7046c8b34264532b74c667be60ce985b2c9dc147 (diff)
downloadsubsurface-49d11443362eaa7e6185a1dda6d11c8b8d11fc60.tar.gz
Dive list: use dive trip time as additional sort criterion
The DiveTripModel places dives after trips in chronologically ascending mode if the dive and the trip start at the same instant. But in the core the sort order was undefined. This could lead to a discrepancy. Therefore, implement the same sort-criterion in the core code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/divelist.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/core/divelist.c b/core/divelist.c
index a87c1f001..6eb2b2389 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -1742,8 +1742,12 @@ void clear_table(struct dive_table *table)
* probably want to unify the models.
* After editing a key used in this sort-function, the order of
* the dives must be re-astablished.
- * Currently, this does a lexicographic sort on the (start-time, id)
- * tuple. "id" is a stable, strictly increasing unique number, that
+ * Currently, this does a lexicographic sort on the
+ * (start-time, trip-time, id) tuple.
+ * trip-time is defined such that dives that do not belong to
+ * a trip are sorted *after* dives that do. Thus, in the default
+ * chronologically-descending sort order, they are shown *before*.
+ * "id" is a stable, strictly increasing unique number, that
* is handed out when a dive is added to the system.
* We might also consider sorting by end-time and other criteria,
* but see the caveat above (editing means rearrangement of the dives).
@@ -1754,6 +1758,16 @@ static int comp_dives(const struct dive *a, const struct dive *b)
return -1;
if (a->when > b->when)
return 1;
+ if (a->divetrip != b->divetrip) {
+ if (!b->divetrip)
+ return -1;
+ if (!a->divetrip)
+ return 1;
+ if (a->divetrip->when < b->divetrip->when)
+ return -1;
+ if (a->divetrip->when > b->divetrip->when)
+ return 1;
+ }
if (a->id < b->id)
return -1;
if (a->id > b->id)