Fold MultiFilterInterface into FilterModelBase

There were two classes, MultiFilterInterface and FiterModelBase.
The latter derives from the former and from QStringListModel.
The former was not used anywhere else. Moreover, in contradiction
to its name, MultiFilterInterface is not an interface (in the Java
sense), because it actually has (non-virtual) data members. All in
all, the data model is very weird.

Merge these two classes, since there seems to be no gain whatsoever
from keeping MultiFilterInterface separate.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-12-23 14:55:59 +01:00
parent d91971095a
commit af371b8de6
2 changed files with 9 additions and 12 deletions

View file

@ -79,6 +79,7 @@ CREATE_COMMON_METHODS_FOR_FILTER(SuitsFilterModel, count_dives_with_suit)
CREATE_INSTANCE_METHOD(MultiFilterSortModel) CREATE_INSTANCE_METHOD(MultiFilterSortModel)
FilterModelBase::FilterModelBase(QObject *parent) : QStringListModel(parent) FilterModelBase::FilterModelBase(QObject *parent) : QStringListModel(parent)
, anyChecked(false)
{ {
} }
@ -401,7 +402,7 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
} }
return showTrip; return showTrip;
} }
Q_FOREACH (MultiFilterInterface *model, models) { Q_FOREACH (FilterModelBase *model, models) {
if (!model->doFilter(d, index0, sourceModel())) if (!model->doFilter(d, index0, sourceModel()))
shouldShow = false; shouldShow = false;
} }
@ -456,7 +457,7 @@ void MultiFilterSortModel::myInvalidate()
#endif #endif
} }
void MultiFilterSortModel::addFilterModel(MultiFilterInterface *model) void MultiFilterSortModel::addFilterModel(FilterModelBase *model)
{ {
QAbstractItemModel *itemModel = dynamic_cast<QAbstractItemModel *>(model); QAbstractItemModel *itemModel = dynamic_cast<QAbstractItemModel *>(model);
Q_ASSERT(itemModel); Q_ASSERT(itemModel);
@ -464,7 +465,7 @@ void MultiFilterSortModel::addFilterModel(MultiFilterInterface *model)
connect(itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(myInvalidate())); connect(itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(myInvalidate()));
} }
void MultiFilterSortModel::removeFilterModel(MultiFilterInterface *model) void MultiFilterSortModel::removeFilterModel(FilterModelBase *model)
{ {
QAbstractItemModel *itemModel = dynamic_cast<QAbstractItemModel *>(model); QAbstractItemModel *itemModel = dynamic_cast<QAbstractItemModel *>(model);
Q_ASSERT(itemModel); Q_ASSERT(itemModel);
@ -475,7 +476,7 @@ void MultiFilterSortModel::removeFilterModel(MultiFilterInterface *model)
void MultiFilterSortModel::clearFilter() void MultiFilterSortModel::clearFilter()
{ {
justCleared = true; justCleared = true;
Q_FOREACH (MultiFilterInterface *iface, models) { Q_FOREACH (FilterModelBase *iface, models) {
iface->clearFilter(); iface->clearFilter();
} }
justCleared = false; justCleared = false;

View file

@ -7,16 +7,12 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
class MultiFilterInterface { class FilterModelBase : public QStringListModel {
public: public:
MultiFilterInterface() : anyChecked(false) {}
virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0; virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
virtual void clearFilter() = 0; virtual void clearFilter() = 0;
std::vector<char> checkState; std::vector<char> checkState;
bool anyChecked; bool anyChecked;
};
class FilterModelBase : public QStringListModel, public MultiFilterInterface {
protected: protected:
explicit FilterModelBase(QObject *parent = 0); explicit FilterModelBase(QObject *parent = 0);
void updateList(const QStringList &new_list); void updateList(const QStringList &new_list);
@ -97,8 +93,8 @@ class MultiFilterSortModel : public QSortFilterProxyModel {
public: public:
static MultiFilterSortModel *instance(); static MultiFilterSortModel *instance();
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
void addFilterModel(MultiFilterInterface *model); void addFilterModel(FilterModelBase *model);
void removeFilterModel(MultiFilterInterface *model); void removeFilterModel(FilterModelBase *model);
int divesDisplayed; int divesDisplayed;
public public
slots: slots:
@ -111,7 +107,7 @@ signals:
void filterFinished(); void filterFinished();
private: private:
MultiFilterSortModel(QObject *parent = 0); MultiFilterSortModel(QObject *parent = 0);
QList<MultiFilterInterface *> models; QList<FilterModelBase *> models;
bool justCleared; bool justCleared;
struct dive_site *curr_dive_site; struct dive_site *curr_dive_site;
}; };