2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-11-13 18:31:03 +00:00
|
|
|
#ifndef FILTERMODELS_H
|
|
|
|
#define FILTERMODELS_H
|
|
|
|
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
2015-05-26 20:42:45 +00:00
|
|
|
#include <stdint.h>
|
Replace bool * array by std::vector<char> in MultiFilterInterface
This replaces a dynamically allocated array of bool by std::vector<char>.
1) This makes the code shorter and less error prone, because memory
management has not to be done by hand.
2) It fixes a bug in the old code:
memset(checkState, false, list.count()) is wrong, because bool is
not guaranteed to be the same size as char!
Two notes:
1) QMap<>, QVector<>, etc. are used numerous times in the code, so
this doesn't introduce a new C++ concept. Here, the std:: version
is used, because there is no need for reference counting, COW
semantics, etc.
2) std::vector<char> is used instead of std::vector<bool>, because
the latter does a pessimization where a bitfield is used!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 14:04:38 +00:00
|
|
|
#include <vector>
|
2014-11-13 18:31:03 +00:00
|
|
|
|
|
|
|
class MultiFilterInterface {
|
|
|
|
public:
|
Replace bool * array by std::vector<char> in MultiFilterInterface
This replaces a dynamically allocated array of bool by std::vector<char>.
1) This makes the code shorter and less error prone, because memory
management has not to be done by hand.
2) It fixes a bug in the old code:
memset(checkState, false, list.count()) is wrong, because bool is
not guaranteed to be the same size as char!
Two notes:
1) QMap<>, QVector<>, etc. are used numerous times in the code, so
this doesn't introduce a new C++ concept. Here, the std:: version
is used, because there is no need for reference counting, COW
semantics, etc.
2) std::vector<char> is used instead of std::vector<bool>, because
the latter does a pessimization where a bitfield is used!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 14:04:38 +00:00
|
|
|
MultiFilterInterface() : anyChecked(false) {}
|
2014-11-13 18:31:03 +00:00
|
|
|
virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
|
|
|
|
virtual void clearFilter() = 0;
|
Replace bool * array by std::vector<char> in MultiFilterInterface
This replaces a dynamically allocated array of bool by std::vector<char>.
1) This makes the code shorter and less error prone, because memory
management has not to be done by hand.
2) It fixes a bug in the old code:
memset(checkState, false, list.count()) is wrong, because bool is
not guaranteed to be the same size as char!
Two notes:
1) QMap<>, QVector<>, etc. are used numerous times in the code, so
this doesn't introduce a new C++ concept. Here, the std:: version
is used, because there is no need for reference counting, COW
semantics, etc.
2) std::vector<char> is used instead of std::vector<bool>, because
the latter does a pessimization where a bitfield is used!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 14:04:38 +00:00
|
|
|
std::vector<char> checkState;
|
2014-11-13 18:31:03 +00:00
|
|
|
bool anyChecked;
|
|
|
|
};
|
|
|
|
|
2017-11-25 15:15:57 +00:00
|
|
|
class FilterModelBase : public QStringListModel, public MultiFilterInterface {
|
|
|
|
protected:
|
|
|
|
explicit FilterModelBase(QObject *parent = 0);
|
|
|
|
void updateList(const QStringList &new_list);
|
|
|
|
};
|
|
|
|
|
|
|
|
class TagFilterModel : public FilterModelBase {
|
2014-11-13 18:31:03 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static TagFilterModel *instance();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
|
|
|
|
void clearFilter();
|
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit TagFilterModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2017-11-25 15:15:57 +00:00
|
|
|
class BuddyFilterModel : public FilterModelBase {
|
2014-11-13 18:31:03 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static BuddyFilterModel *instance();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
|
|
|
|
void clearFilter();
|
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit BuddyFilterModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2017-11-25 15:15:57 +00:00
|
|
|
class LocationFilterModel : public FilterModelBase {
|
2014-11-13 18:31:03 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static LocationFilterModel *instance();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
|
|
|
|
void clearFilter();
|
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
2017-11-26 09:42:22 +00:00
|
|
|
void changeName(const QString &oldName, const QString &newName);
|
2017-11-26 21:21:58 +00:00
|
|
|
void addName(const QString &newName);
|
2014-11-13 18:31:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit LocationFilterModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2017-11-25 15:15:57 +00:00
|
|
|
class SuitsFilterModel : public FilterModelBase {
|
2014-11-13 19:07:05 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static SuitsFilterModel *instance();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
|
|
|
|
void clearFilter();
|
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit SuitsFilterModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2014-11-13 18:31:03 +00:00
|
|
|
class MultiFilterSortModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static MultiFilterSortModel *instance();
|
|
|
|
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
void addFilterModel(MultiFilterInterface *model);
|
|
|
|
void removeFilterModel(MultiFilterInterface *model);
|
2014-11-16 16:04:06 +00:00
|
|
|
int divesDisplayed;
|
2014-11-13 20:51:23 +00:00
|
|
|
public
|
|
|
|
slots:
|
2014-11-13 18:31:03 +00:00
|
|
|
void myInvalidate();
|
|
|
|
void clearFilter();
|
2015-05-26 20:42:45 +00:00
|
|
|
void startFilterDiveSite(uint32_t uuid);
|
2015-05-26 20:36:06 +00:00
|
|
|
void stopFilterDiveSite();
|
|
|
|
|
2014-11-16 16:04:06 +00:00
|
|
|
signals:
|
|
|
|
void filterFinished();
|
2014-11-13 18:31:03 +00:00
|
|
|
private:
|
|
|
|
MultiFilterSortModel(QObject *parent = 0);
|
2014-11-13 20:51:23 +00:00
|
|
|
QList<MultiFilterInterface *> models;
|
2014-11-13 18:31:03 +00:00
|
|
|
bool justCleared;
|
2015-05-26 20:36:06 +00:00
|
|
|
struct dive_site *curr_dive_site;
|
2014-11-13 18:31:03 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 21:45:32 +00:00
|
|
|
#endif
|