Dive list: split DiveTripModel into distinct models (tree and list)

The DiveTripModel was used to represent both, trip and list views.
Thus many functions had conditionals checking for the current mode
and both modes had to be represented by the same data structure.

Instead, split the model in two and derive them from a base class,
which implements common functions and defines an interface.

The model can be switched by a call to resetModel(), which invalidates
any pointer obtained by instance(). This is quite surprising
behavior. To handle it, straighten out the control flow:

DiveListView --> MultiFilterSortModel --> DiveTripModelBase

Before, DiveListView accessed DiveTripModelBase directly.

A goal of this commit is to enable usage of the same model by mobile
and desktop.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-12-27 10:06:11 +01:00 committed by Dirk Hohndel
parent b5704ddb57
commit f1fc89b978
8 changed files with 663 additions and 442 deletions

View file

@ -2,7 +2,7 @@
#ifndef FILTERMODELS_H
#define FILTERMODELS_H
#include "divetripmodel.h" // For DiveTripModel::Layout. TODO: remove in due course
#include "divetripmodel.h"
#include <QStringListModel>
#include <QSortFilterProxyModel>
@ -13,7 +13,6 @@
struct dive;
struct dive_trip;
class DiveTripModel;
struct FilterData {
bool validFilter = false;
@ -49,7 +48,7 @@ slots:
void startFilterDiveSite(struct dive_site *ds);
void stopFilterDiveSite();
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
void setLayout(DiveTripModel::Layout layout);
void resetModel(DiveTripModelBase::Layout layout);
void filterDataChanged(const FilterData& data);
signals: