aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-30 09:20:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commitec7d85835fb26ee9c0a9c780907441c312d7ac3f (patch)
tree1ecb5231abdc50929ba6ba308c25196eb408c381 /desktop-widgets/divelistview.cpp
parent6ac4ddbeeda5286faacac9633b622dcf298eea7b (diff)
downloadsubsurface-ec7d85835fb26ee9c0a9c780907441c312d7ac3f.tar.gz
Dive list: implement proper Qt-model semantics for DiveTripModel
Previously, each dive-list modifying function would lead to a full model reset. Instead, implement proper Qt-model semantics using beginInsertRows()/endInsertRows(), beginRemoveRows()/ endRemoveRows(), dataChange(). To do so, a DiveListNotifer singleton is generatated, which broadcasts all changes to the dive-list. Signals are sent by the commands and received by the DiveTripModel. Signals are batched by dive-trip. This seems to be an adequate compromise for the two kinds of list-views (tree and list). In the common usecase mostly dives of a single trip are affected. Thus, batching of dives is performed in two positions: - At command-level to batch by trip - In DiveTripModel to feed batches of contiguous elements to Qt's begin*/end*-functions. This is conceptually simple, but rather complex code. To avoid repetition of complex loops, the batching is implemented in templated-functions, which are passed lambda-functions, which are called for each batch. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r--desktop-widgets/divelistview.cpp38
1 files changed, 2 insertions, 36 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 4d68baca2..e8c6ea0dc 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -668,11 +668,6 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset)
if (trip_a == trip_b || !trip_a || !trip_b)
return;
Command::mergeTrips(trip_a, trip_b);
- rememberSelection();
- reload(currentLayout, false);
- restoreSelection();
- mark_divelist_changed(true);
- //TODO: emit a signal to signalize that the divelist changed?
}
void DiveListView::mergeTripAbove()
@@ -696,11 +691,6 @@ void DiveListView::removeFromTrip()
divesToRemove.append(d);
}
Command::removeDivesFromTrip(divesToRemove);
-
- rememberSelection();
- reload(currentLayout, false);
- restoreSelection();
- mark_divelist_changed(true);
}
void DiveListView::newTripAbove()
@@ -717,10 +707,6 @@ void DiveListView::newTripAbove()
dives.append(d);
}
Command::createTrip(dives);
-
- reload(currentLayout, false);
- mark_divelist_changed(true);
- restoreSelection();
}
void DiveListView::addToTripBelow()
@@ -765,9 +751,6 @@ void DiveListView::addToTrip(int delta)
}
}
Command::addDivesToTrip(dives, trip);
-
- reload(currentLayout, false);
- restoreSelection();
}
void DiveListView::markDiveInvalid()
@@ -783,9 +766,6 @@ void DiveListView::markDiveInvalid()
// now mark the dive invalid... how do we do THAT?
// d->invalid = true;
}
- if (amount_selected == 0) {
- MainWindow::instance()->cleanUpEmpty();
- }
mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay();
if (prefs.display_invalid_dives == false) {
@@ -802,26 +782,12 @@ void DiveListView::deleteDive()
return;
int i;
- int lastDiveNr = -1;
QVector<struct dive*> deletedDives;
for_each_dive (i, d) {
- if (!d->selected)
- continue;
- deletedDives.append(d);
- lastDiveNr = i;
+ if (d->selected)
+ deletedDives.append(d);
}
- // the actual dive deletion is happening in the redo command that is implicitly triggered
Command::deleteDive(deletedDives);
- if (amount_selected == 0) {
- MainWindow::instance()->cleanUpEmpty();
- }
- mark_divelist_changed(true);
- MainWindow::instance()->refreshDisplay();
- if (lastDiveNr != -1) {
- clearSelection();
- selectDive(lastDiveNr);
- rememberSelection();
- }
}
void DiveListView::contextMenuEvent(QContextMenuEvent *event)