From dba16202c498d4432bc20181b0084f54b7abdba1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 22 Sep 2013 22:24:28 -0700 Subject: [PATCH] Correctly handle empty dive list after delete Things need to be cleared out and disabled. But fixing this bug leaves another issue - while the newly selected dive after a delete acts as if it was selected, it doesn't show up as selected in the dive list. Reported-by: Henrik Brautaset Aronsen Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 15 +++++++++++++-- qt-ui/mainwindow.cpp | 25 ++++++++++++++----------- qt-ui/mainwindow.h | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 2e40678ad..639e988fd 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -7,6 +7,7 @@ #include "divelistview.h" #include "models.h" #include "modeldelegates.h" +#include "mainwindow.h" #include "../display.h" #include #include @@ -72,7 +73,7 @@ void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle) expand(parent); flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select; flags |= QItemSelectionModel::Rows; - selectionModel()->select( idx, flags); + selectionModel()->select(idx, flags); if (scrollto) scrollTo(idx, PositionAtCenter); } @@ -330,9 +331,19 @@ void DiveListView::removeFromTrip() void DiveListView::deleteDive() { + int nr; struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value(); - if (d) + if (d) { + nr = get_divenr(d); delete_single_dive(get_index_for_dive(d)); + if (amount_selected == 0) { + if (nr > 0) + select_dive(nr - 1); + else + mainWindow()->cleanUpEmpty(); + } + } + mainWindow()->refreshDisplay(); reload(currentLayout, false); } diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 9fa4a35dc..cb65b3dd2 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -134,6 +134,19 @@ void MainWindow::on_actionSaveAs_triggered() { file_save_as(); } + +void MainWindow::cleanUpEmpty() +{ + ui->InfoWidget->clearStats(); + ui->InfoWidget->clearInfo(); + ui->InfoWidget->clearEquipment(); + ui->InfoWidget->updateDiveInfo(-1); + ui->ProfileWidget->clear(); + ui->ListWidget->reload(DiveTripModel::TREE); + ui->globe->reload(); + setTitle(MWTF_DEFAULT); +} + void MainWindow::on_actionClose_triggered() { if (unsaved_changes() && (askSaveChanges() == FALSE)) @@ -146,17 +159,7 @@ void MainWindow::on_actionClose_triggered() /* clear the selection and the statistics */ selected_dive = -1; - //WARNING: Port this to Qt. - //process_selected_dives(); - - ui->InfoWidget->clearStats(); - ui->InfoWidget->clearInfo(); - ui->InfoWidget->clearEquipment(); - ui->InfoWidget->updateDiveInfo(-1); - ui->ProfileWidget->clear(); - ui->ListWidget->reload(DiveTripModel::TREE); - ui->globe->reload(); - setTitle(MWTF_DEFAULT); + cleanUpEmpty(); mark_divelist_changed(FALSE); clear_events(); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index b30f10a03..3d5b9ab4a 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -52,6 +52,7 @@ public: void enableDcShortcuts(); void loadFiles(const QStringList files); void importFiles(const QStringList importFiles); + void cleanUpEmpty(); private slots: /* file menu action */