From a431840075fbba6f882627496f18a0fb80630e4f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 26 Nov 2019 00:08:35 +0100 Subject: Selection: move initialization of selection from view to model The goal here is to unify desktop and mobile by moving selection code from the desktop-only view. Currently, initialization of the selection still has to be called from the view after connecting the appropriate signals. This is due to the weird way in which create completely new models when resetting them. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 4354fdb26..b81b16557 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -86,8 +86,11 @@ void DiveListView::resetModel() MultiFilterSortModel::instance()->resetModel(currentLayout); // If the model was reset, we have to reconnect the signals and tell // the filter model to update its source model. - connect(DiveTripModelBase::instance(), &DiveTripModelBase::selectionChanged, this, &DiveListView::diveSelectionChanged); - connect(DiveTripModelBase::instance(), &DiveTripModelBase::currentDiveChanged, this, &DiveListView::currentDiveChanged); + DiveTripModelBase *m = DiveTripModelBase::instance(); + connect(m, &DiveTripModelBase::selectionChanged, this, &DiveListView::diveSelectionChanged); + connect(m, &DiveTripModelBase::currentDiveChanged, this, &DiveListView::currentDiveChanged); + // Get the initial selection + m->initSelection(); } void DiveListView::calculateInitialColumnWidth(int col) @@ -519,10 +522,6 @@ void DiveListView::reload() { resetModel(); - if (amount_selected && current_dive != NULL) - selectDive(get_divenr(current_dive), true); - else - select_newest_visible_dive(); if (selectedIndexes().count()) { QModelIndex curr = selectedIndexes().first(); curr = curr.parent().isValid() ? curr.parent() : curr; -- cgit v1.2.3-70-g09d2