From 803111ef02f84119f762ce495710edb2e7f40bdb Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 29 Oct 2018 14:56:48 +0100 Subject: Dive list: make filter model aware of its source The data-flow from C-core to list-view is as follows: C-core --> DiveTripModel --> MultiSortFilterModel --> DiveListView The control-flow, on the other hand, differs as DiveListView accesses both MultiSortFilterModel and DiveTripModel, whereas MultiSortFilterModel is mostly unaware of its source model. This is in principle legitimate, as the MultiSortFilterModel might be used for different sources. In our particular case, this is not so. MultiSortFilterModel is written for a particular use case. Therefore, model control-flow follow after data-flow: Let MultiSortFilterModel set its own source model and DiveListView access the MultiSortFilterModel, which then manages its source model. This is not bike-shedding, but will enable a more flexible and higher-performance sorting. Signed-off-by: Berthold Stoeger --- qt-models/filtermodels.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'qt-models/filtermodels.cpp') diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index ce0c2528c..857c5d698 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -562,6 +562,16 @@ MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyMo divesDisplayed(0), curr_dive_site(NULL) { + setSortRole(DiveTripModel::SORT_ROLE); + setFilterKeyColumn(-1); // filter all columns + setFilterCaseSensitivity(Qt::CaseInsensitive); + setSourceModel(DiveTripModel::instance()); +} + +void MultiFilterSortModel::setLayout(DiveTripModel::Layout layout) +{ + DiveTripModel *tripModel = DiveTripModel::instance(); + tripModel->setLayout(layout); // Note: setLayout() resets the whole model } void MultiFilterSortModel::divesAdded(const QVector &dives) @@ -656,6 +666,8 @@ void MultiFilterSortModel::myInvalidate() invalidateFilter(); + // Tell the dive trip model to update the displayed-counts + DiveTripModel::instance()->filterFinished(); emit filterFinished(); #if !defined(SUBSURFACE_MOBILE) -- cgit v1.2.3-70-g09d2