summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-11 13:09:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-18 16:50:09 -0800
commit64e6e435f82801f4f440ef5b1caf58a91a7c9929 (patch)
tree0f2c662daab035463de05c1564af7026c7edbd7e /qt-models/divetripmodel.cpp
parent431b2bb84542d4f45952b48aa91231f979762e00 (diff)
downloadsubsurface-64e6e435f82801f4f440ef5b1caf58a91a7c9929.tar.gz
Core: remove "when" field of struct dive_trip
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.cpp')
-rw-r--r--qt-models/divetripmodel.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index c6b4ae228..c83a14e7b 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -62,14 +62,14 @@ QVariant DiveTripModel::tripData(const dive_trip *trip, int column, int role)
struct dive *d = trip->dives.dives[i];
if (!d->hidden_by_filter)
countShown++;
- oneDayTrip &= is_same_day (trip->when, d->when);
+ oneDayTrip &= is_same_day(trip_date(trip), d->when);
}
if (countShown < trip->dives.nr)
shownText = tr("(%1 shown)").arg(countShown);
if (!empty_string(trip->location))
- return QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->dives.nr, oneDayTrip) + " "+ shownText;
+ return QString(trip->location) + ", " + get_trip_date_string(trip_date(trip), trip->dives.nr, oneDayTrip) + " "+ shownText;
else
- return get_trip_date_string(trip->when, trip->dives.nr, oneDayTrip) + shownText;
+ return get_trip_date_string(trip_date(trip), trip->dives.nr, oneDayTrip) + shownText;
}
}
@@ -463,7 +463,7 @@ dive *DiveTripModel::Item::getDive() const
timestamp_t DiveTripModel::Item::when() const
{
- return d_or_t.trip ? d_or_t.trip->when : d_or_t.dive->when;
+ return d_or_t.trip ? trip_date(d_or_t.trip) : d_or_t.dive->when;
}
// Find a range of matching elements in a vector.
@@ -678,10 +678,11 @@ int DiveTripModel::findDiveInTrip(int tripIdx, const dive *d) const
return -1;
}
-int DiveTripModel::findInsertionIndex(timestamp_t when) const
+int DiveTripModel::findInsertionIndex(const dive_trip *trip) const
{
+ dive_or_trip d_or_t{ nullptr, (dive_trip *)trip };
for (int i = 0; i < (int)items.size(); ++i) {
- if (when <= items[i].when())
+ if (dive_or_trip_less_than(d_or_t, items[i].d_or_t))
return i;
}
return items.size();
@@ -765,7 +766,7 @@ void DiveTripModel::divesAdded(dive_trip *trip, bool addTrip, const QVector<dive
});
} else if (addTrip) {
// We're supposed to add the whole trip. Just insert the trip.
- int idx = findInsertionIndex(trip->when); // Find the place where we have to insert the thing
+ int idx = findInsertionIndex(trip); // Find the place where to insert the trip
beginInsertRows(QModelIndex(), idx, idx);
items.insert(items.begin() + idx, { trip, dives });
endInsertRows();