summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-10 09:07:42 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-18 16:50:09 -0800
commit243962a67a41c71f39a098e8f18dafdcd9adb37e (patch)
treec23806d69bf74a5e7d10f3176cc97c129384ad86 /qt-models/divetripmodel.h
parentef98a4ff5ad05b3a1fc51ffb5996d49d1c462a75 (diff)
downloadsubsurface-243962a67a41c71f39a098e8f18dafdcd9adb37e.tar.gz
Dive list: move sort-functionality into core
To make sorting more controlled, move all sorting functions into the core. For this, introduce a "dive_or_trip" structure, which represents a top-level item. Adapt the DiveTripModel accordingly. There are now three sorting functions: 1) dive_less_than 2) trip_less_than 3) dive_or_trip_less_than These should be used by all sorting code. By moving them to a single place, the mess can hopefully be cleaned up. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.h')
-rw-r--r--qt-models/divetripmodel.h27
1 files changed, 9 insertions, 18 deletions
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index 4993c855f..8ff4524b3 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -81,24 +81,15 @@ private slots:
private:
// The model has up to two levels. At the top level, we have either trips or dives
// that do not belong to trips. Such a top-level item is represented by the "Item"
- // struct. Two cases two consider:
- // 1) If "trip" is non-null, then this is a dive-trip and the dives are collected
- // in the dives vector. Note that in principle we could also get the dives in a
- // trip from the backend, but there they are collected in a linked-list, which is
- // quite inconvenient to access.
- // 2) If "trip" is null, this is a dive and dives is supposed to contain exactly
- // one element, which is the corresponding dive.
- //
- // Top-level items are ordered by timestamp. For dives, the core function
- // dive_less_than is used, which guarantees a stable ordering even in the
- // case of equal timestamps. For dives and trips, place dives before trips
- // in the case of an equal timestamp. For trips with equal timestamps, the
- // order is currently undefined. This is currently not a problem, because
- // the core doesn't have a list of sorted trips. But nevertheless something
- // to keep in mind.
+ // struct, which is based on the dive_or_trip structure.
+ // If it is a trip, additionally, the dives are collected in a vector.
+ // The items are ordered chronologically according to the dive_or_trip_less_than()
+ // function, which guarantees a stable ordering even in the case of equal timestamps.
+ // For dives and trips, it place dives chronologically after trips, so that in
+ // the default-descending view they are shown before trips.
struct Item {
- dive_trip *trip;
- std::vector<dive *> dives; // std::vector<> instead of QVector for insert() with three iterators
+ dive_or_trip d_or_t;
+ std::vector<dive *> dives; // std::vector<> instead of QVector for insert() with three iterators
Item(dive_trip *t, const QVector<dive *> &dives);
Item(dive_trip *t, dive *d); // Initialize a trip with one dive
Item(dive *d); // Initialize a top-level dive
@@ -126,7 +117,7 @@ private:
void addDivesToTrip(int idx, const QVector<dive *> &dives);
dive *diveOrNull(const QModelIndex &index) const; // Returns a dive if this index represents a dive, null otherwise
- QPair<dive_trip *, dive *> tripOrDive(const QModelIndex &index) const;
+ dive_or_trip tripOrDive(const QModelIndex &index) const;
// Returns either a pointer to a trip or a dive, or twice null of index is invalid
// null, something is really wrong
void setupModelData();