aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-06 16:33:34 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-06 13:46:41 -0800
commitdbddec59d3736a2e3ac9498528209a8397b897b7 (patch)
treeb600e32f2aff8d55adc8536e371e073b1ff56a99 /qt-models/divetripmodel.cpp
parenta88ab64cf80db7bde3e14ac41acf1ed2d73dbdf1 (diff)
downloadsubsurface-dbddec59d3736a2e3ac9498528209a8397b897b7.tar.gz
divetripmodel: add TRIP_HAS_CURRENT_ROLE
This role returns true if the given trip contains the current dive. This will be needed by the mobile list model to decide if a newly added trip should be expanded right away. 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, 11 insertions, 4 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 5b7f96ba1..63c111981 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -820,14 +820,21 @@ QVariant DiveTripModelTree::data(const QModelIndex &index, int role) const
return defaultModelFont();
dive_or_trip entry = tripOrDive(index);
- if (role == IS_TRIP_ROLE)
+ if (!entry.trip && !entry.dive)
+ return QVariant(); // That's an invalid index!
+ if (role == IS_TRIP_ROLE) {
return !!entry.trip;
+ } else if (role == TRIP_HAS_CURRENT_ROLE) {
+ if (!entry.trip)
+ return false;
+
+ const Item &item = items[index.row()];
+ return std::find(item.dives.begin(), item.dives.end(), current_dive) != item.dives.end();
+ }
if (entry.trip)
return tripData(entry.trip, index.column(), role);
- else if (entry.dive)
- return diveData(entry.dive, index.column(), role);
else
- return QVariant();
+ return diveData(entry.dive, index.column(), role);
}
// After a trip changed, the top level might need to be reordered.