mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
a88ab64cf8
commit
dbddec59d3
2 changed files with 13 additions and 5 deletions
|
@ -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.
|
||||
|
|
|
@ -50,7 +50,8 @@ public:
|
|||
TRIP_ROLE,
|
||||
DIVE_IDX,
|
||||
SELECTED_ROLE,
|
||||
CURRENT_ROLE
|
||||
CURRENT_ROLE,
|
||||
TRIP_HAS_CURRENT_ROLE // Returns true if this is a trip and it contains the current dive
|
||||
};
|
||||
enum Layout {
|
||||
TREE,
|
||||
|
|
Loading…
Add table
Reference in a new issue