selection: trickle down trip selection

The trip selection code was an awkward layering violation.
Whereas dive selections due to dive undo-commands trickled
down via DiveTripModel-->MultiFilterSortModel-->DiveListView,
for trip editing, the DiveListView directly intercepted the
TripEdited signal.

Instead, mimic the dive-selection code. This is a bit longer
but more consistent and logical. The undo/redo of trip changes
is now also a "programmatical" change of the selection.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-08-27 17:28:34 +02:00 committed by bstoeger
parent 9ccb940a1b
commit 8581e213ed
11 changed files with 113 additions and 57 deletions

View file

@ -27,6 +27,7 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
setSourceModel(model.get());
connect(model.get(), &DiveTripModelBase::selectionChanged, this, &MultiFilterSortModel::selectionChangedSlot);
connect(model.get(), &DiveTripModelBase::tripSelected, this, &MultiFilterSortModel::tripSelectedSlot);
model->initSelection();
LocationInformationModel::instance()->update();
}
@ -45,6 +46,16 @@ void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indi
emit selectionChanged(indicesLocal, mapFromSource(currentDive));
}
// Translate selection into local indices and re-emit signal
void MultiFilterSortModel::tripSelectedSlot(QModelIndex trip, QModelIndex currentDive)
{
QModelIndex local = mapFromSource(trip);
if (!local.isValid())
return;
emit tripSelected(local, mapFromSource(currentDive));
}
bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return true;