diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-14 09:12:21 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 3c6cdfd8c02e215f98986cbb74b33f58e47fe632 (patch) | |
tree | 206a1eb2bb427df36abe4b08160673dde9bf667b /desktop-widgets | |
parent | b16be29595f09daa422c2c07075d3b8b60e7fad9 (diff) | |
download | subsurface-3c6cdfd8c02e215f98986cbb74b33f58e47fe632.tar.gz |
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>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 7 | ||||
-rw-r--r-- | desktop-widgets/divelistview.cpp | 16 | ||||
-rw-r--r-- | desktop-widgets/divelistview.h | 1 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 14 |
4 files changed, 33 insertions, 5 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index d3ecfb796..7fbda35dc 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -423,7 +423,12 @@ void DiveListBase::restoreSelection(const std::vector<dive *> &selection, dive * }); bool currentDiveChanged = false; - if (current_dive != currentDive) { + // If currentDive is null, we have no current dive. In such a case always + // signal the frontend. + if (!currentDive) { + currentDiveChanged = true; + emit diveListNotifier.currentDiveChanged(); + } else if (current_dive != currentDive) { currentDiveChanged = true; // We cannot simply change the currentd dive to the given dive. diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 4bfc6ea60..eb65e9e6e 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -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) { diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h index effde2ece..5c9ac2f25 100644 --- a/desktop-widgets/divelistview.h +++ b/desktop-widgets/divelistview.h @@ -59,6 +59,7 @@ slots: void loadImages(); void loadWebImages(); void diveSelectionChanged(const QVector<QModelIndex> &indexes, bool select); + void currentDiveChanged(QModelIndex index); private: bool mouseClickSelection; QList<int> expandedRows; diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 72b4e4720..625c094c1 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -530,10 +530,16 @@ void MainWindow::configureToolbar() { void MainWindow::selectionChanged() { - graphics()->plotDive(nullptr, false, true); - information()->updateDiveInfo(); - configureToolbar(); - MapWidget::instance()->reload(); + if (!current_dive) { + information()->clearTabs(); + information()->updateDiveInfo(true); + graphics()->setEmptyState(); + } else { + graphics()->plotDive(nullptr, false, true); + information()->updateDiveInfo(); + configureToolbar(); + MapWidget::instance()->reload(); + } } void MainWindow::on_actionNew_triggered() |