mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Fix selection after downloading dives from the dive computer
If we successfully download dives, the old selection should be cleared and the one of the newly downloaded dives should be selected. I decided to pick the last dive downloaded, which for most dive computers (but for example not for the Uemis SDA) will be the first or earliest of the dives. That seems much more intuitive than keeping the previous selection around. Of course this is harder than it should be because of the way we track selections and because we need a consistent dive list model in order to change the selection. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b36c8f07c7
commit
5e3f7ba22f
4 changed files with 30 additions and 5 deletions
|
@ -189,6 +189,8 @@ void DiveListView::selectTrip(dive_trip_t *trip)
|
|||
void DiveListView::unselectDives()
|
||||
{
|
||||
selectionModel()->clearSelection();
|
||||
if (amount_selected != 0)
|
||||
qDebug() << "selection information inconsistent";
|
||||
}
|
||||
|
||||
QList<dive_trip_t *> DiveListView::selectedTrips()
|
||||
|
@ -211,6 +213,8 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
|
|||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QModelIndexList match = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive);
|
||||
QItemSelectionModel::SelectionFlags flags;
|
||||
if (match.isEmpty())
|
||||
return;
|
||||
QModelIndex idx = match.first();
|
||||
flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
|
||||
flags |= QItemSelectionModel::Rows;
|
||||
|
|
|
@ -382,8 +382,23 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
|
|||
// down in the dive_table
|
||||
for (int i = dive_table.nr - 1; i >= previousLast; i--)
|
||||
delete_single_dive(i);
|
||||
} else {
|
||||
} else if (dive_table.nr) {
|
||||
int i;
|
||||
struct dive *d;
|
||||
// remember the last downloaded dive (on most dive computers this will be the chronologically
|
||||
// first new dive) and select it again after processing all the dives
|
||||
MainWindow::instance()->dive_list()->unselectDives();
|
||||
get_dive(dive_table.nr - 1)->selected = true;
|
||||
process_dives(true, preferDownloaded());
|
||||
// after process_dives does any merging or resorting needed, we need
|
||||
// to recreate the model for the dive list so we can select the newest dive
|
||||
MainWindow::instance()->recreateDiveList();
|
||||
for_each_dive(i, d) {
|
||||
if (d->selected)
|
||||
break;
|
||||
}
|
||||
d->selected = false;
|
||||
MainWindow::instance()->dive_list()->selectDive(i, true);
|
||||
}
|
||||
} else if (currentState == CANCELLING || currentState == CANCELLED){
|
||||
if (import_thread_cancelled) {
|
||||
|
|
|
@ -124,14 +124,14 @@ MainWindow *MainWindow::instance()
|
|||
}
|
||||
|
||||
// this gets called after we download dives from a divecomputer
|
||||
void MainWindow::refreshDisplay(bool recreateDiveList)
|
||||
void MainWindow::refreshDisplay(bool doRecreateDiveList)
|
||||
{
|
||||
showError(get_error_string());
|
||||
ui.InfoWidget->reload();
|
||||
TankInfoModel::instance()->update();
|
||||
ui.globe->reload();
|
||||
if (recreateDiveList)
|
||||
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
||||
if (doRecreateDiveList)
|
||||
recreateDiveList();
|
||||
ui.ListWidget->setFocus();
|
||||
WSInfoModel::instance()->updateInfo();
|
||||
// refresh the yearly stats if the window has an instance
|
||||
|
@ -143,6 +143,11 @@ void MainWindow::refreshDisplay(bool recreateDiveList)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::recreateDiveList()
|
||||
{
|
||||
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
||||
}
|
||||
|
||||
void MainWindow::current_dive_changed(int divenr)
|
||||
{
|
||||
if (divenr >= 0) {
|
||||
|
|
|
@ -152,7 +152,8 @@ protected:
|
|||
public
|
||||
slots:
|
||||
void readSettings();
|
||||
void refreshDisplay(bool recreateDiveList = true);
|
||||
void refreshDisplay(bool doRecreateDiveList = true);
|
||||
void recreateDiveList();
|
||||
void showProfile();
|
||||
void editCurrentDive();
|
||||
|
||||
|
|
Loading…
Reference in a new issue