mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
ef98a4ff5a
commit
243962a67a
4 changed files with 72 additions and 57 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue