diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-11-15 21:08:25 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-15 15:13:53 -0800 |
commit | 8827ea6f5d029e6b433ed5622ac7258db512f0ae (patch) | |
tree | fde14be0625b4826f5dcdf70c126ca57263a4ee1 /qt-ui/divelistview.cpp | |
parent | 06bf0e1849559e0109c419beae627b44f477dc88 (diff) | |
download | subsurface-8827ea6f5d029e6b433ed5622ac7258db512f0ae.tar.gz |
This moves the removal code to the model.
It's very important when programming via Model/View, in gtk or qt,
to not mess with the model data outside of the model. We were
deleting stuff that the model controlled outside of the model, so
it thought that there was still data there. This fixes the deletion
part, but there are also lots of other parts that I'll tackle in
the next commits.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 28 |
1 files changed, 13 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() |