summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp28
-rw-r--r--qt-ui/models.cpp17
-rw-r--r--qt-ui/models.h1
3 files changed, 31 insertions, 15 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index da4229de8..7689f06a9 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -495,25 +495,23 @@ void DiveListView::deleteDive()
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
if (!d)
return;
- // after a dive is deleted the ones following it move forward in the dive_table
- // so instead of using the for_each_dive macro I'm using an explicit for loop
- // to make this easier to understand
- for (i = 0; i < dive_table.nr; i++) {
- d = get_dive(i);
- if (!d->selected)
- continue;
- delete_single_dive(i);
- i--; // so the next dive isn't skipped... it's now #i
- }
+
+ QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(model());
+ DiveTripModel *realModel = qobject_cast<DiveTripModel*>(proxy->sourceModel());
+ realModel->deleteSelectedDives();
+
+ struct dive* next_dive = 0;
if (amount_selected == 0) {
- if (i > 0)
- select_dive(nr - 1);
- else
+ if (i > 0){
+ next_dive = get_dive(nr -1);
+ }
+ else{
mainWindow()->cleanUpEmpty();
+ }
}
mark_divelist_changed(TRUE);
- mainWindow()->refreshDisplay();
- reload(currentLayout, false);
+ if (next_dive)
+ selectDive(next_dive);
}
void DiveListView::testSlot()
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 14c3cb5ea..dd69e45c2 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1198,6 +1198,23 @@ QVariant DiveComputerModel::data(const QModelIndex& index, int role) const
return ret;
}
+void DiveTripModel::deleteSelectedDives()
+{
+ // after a dive is deleted the ones following it move forward in the dive_table
+ // so instead of using the for_each_dive macro I'm using an explicit for loop
+ // to make this easier to understand
+ beginRemoveRows(index(0,0), 0, rowCount()-1);
+ for (int i = 0; i < dive_table.nr; i++) {
+ struct dive *d = get_dive(i);
+ if (!d->selected)
+ continue;
+ delete_single_dive(i);
+ i--; // so the next dive isn't skipped... it's now #i
+ }
+ endRemoveRows();
+ setupModelData();
+}
+
int DiveComputerModel::rowCount(const QModelIndex& parent) const
{
return numRows;
diff --git a/qt-ui/models.h b/qt-ui/models.h
index af4659e9e..f212a18aa 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -200,6 +200,7 @@ public:
DiveTripModel(QObject* parent = 0);
Layout layout() const;
void setLayout(Layout layout);
+ void deleteSelectedDives();
private:
void setupModelData();