Dive list: propagate current-item to frontend

The command-objects select a current item, but this selection
was not propagated to the front-end. The current item is the
base for keyboard-navigation through the dive-list and therefore
should be set correctly.

It took some experimentation to get the flags right:
 QItemSelectionModel::Current
Hopefully, these are the correct flags across all supported
Qt versions!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-14 09:12:21 -04:00 committed by Dirk Hohndel
parent b16be29595
commit 3c6cdfd8c0
6 changed files with 74 additions and 5 deletions

View file

@ -45,6 +45,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
setSelectionMode(ExtendedSelection);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(DiveTripModel::instance(), &DiveTripModel::selectionChanged, this, &DiveListView::diveSelectionChanged);
connect(DiveTripModel::instance(), &DiveTripModel::newCurrentDive, this, &DiveListView::currentDiveChanged);
header()->setStretchLastSection(true);
@ -207,6 +208,21 @@ void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indexes, boo
}
}
void DiveListView::currentDiveChanged(QModelIndex index)
{
// Transform the index into a local index, since
// there might be sorting or filtering in effect.
MultiFilterSortModel *m = MultiFilterSortModel::instance();
QModelIndex localIndex = m->mapFromSource(index);
// Then, set the currently activated row.
// Note, we have to use the QItemSelectionModel::Current mode to avoid
// changing our selection (in contrast to Qt's documentation, which
// instructs to use QItemSelectionModel::NoUpdate, which results in
// funny side-effects).
selectionModel()->setCurrentIndex(localIndex, QItemSelectionModel::Current);
}
// If rows are added, check which of these rows is a trip and expand the first column
void DiveListView::rowsInserted(const QModelIndex &parent, int start, int end)
{