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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-29 14:56:48 +01:00 committed by Dirk Hohndel
parent 4636fcc834
commit 803111ef02
5 changed files with 18 additions and 12 deletions

View file

@ -33,12 +33,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
setItemDelegate(new DiveListDelegate(this));
setUniformRowHeights(true);
setItemDelegateForColumn(DiveTripModel::RATING, new StarWidgetsDelegate(this));
MultiFilterSortModel *model = MultiFilterSortModel::instance();
model->setSortRole(DiveTripModel::SORT_ROLE);
model->setFilterKeyColumn(-1); // filter all columns
model->setFilterCaseSensitivity(Qt::CaseInsensitive);
model->setSourceModel(DiveTripModel::instance());
setModel(model);
setModel(MultiFilterSortModel::instance());
setSortingEnabled(false);
setContextMenuPolicy(Qt::DefaultContextMenu);
@ -503,8 +498,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
header()->setSectionsClickable(true);
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
DiveTripModel *tripModel = DiveTripModel::instance();
tripModel->setLayout(layout); // Note: setLayout() resets the whole model
MultiFilterSortModel::instance()->setLayout(layout);
if (!forceSort)
return;