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
|
|
|
|
2018-08-14 18:09:30 +00:00
|
|
|
struct dive;
|
|
|
|
|
2018-08-28 18:44:11 +00:00
|
|
|
class FilterModelBase : public QAbstractListModel {
|
2017-12-24 13:35:59 +00:00
|
|
|
Q_OBJECT
|
2018-08-28 18:44:11 +00:00
|
|
|
private:
|
|
|
|
int findInsertionIndex(const QString &name);
|
2018-08-27 09:49:16 +00:00
|
|
|
protected:
|
|
|
|
struct Item {
|
2018-08-28 18:44:11 +00:00
|
|
|
QString name;
|
2018-08-27 09:49:16 +00:00
|
|
|
bool checked;
|
2018-08-27 10:53:46 +00:00
|
|
|
int count;
|
2018-08-27 09:49:16 +00:00
|
|
|
};
|
|
|
|
std::vector<Item> items;
|
2018-08-28 18:44:11 +00:00
|
|
|
int indexOf(const QString &name) const;
|
|
|
|
void addItem(const QString &name, bool checked, int count);
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2014-11-13 18:31:03 +00:00
|
|
|
public:
|
2018-08-14 18:09:30 +00:00
|
|
|
virtual bool doFilter(const dive *d) const = 0;
|
2017-12-23 14:25:54 +00:00
|
|
|
void clearFilter();
|
2017-12-23 14:49:21 +00:00
|
|
|
void selectAll();
|
|
|
|
void invertSelection();
|
2014-11-13 18:31:03 +00:00
|
|
|
bool anyChecked;
|
2017-12-24 13:35:59 +00:00
|
|
|
bool negate;
|
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void setNegate(bool negate);
|
2018-08-28 18:44:11 +00:00
|
|
|
void changeName(const QString &oldName, const QString &newName);
|
2017-11-25 15:15:57 +00:00
|
|
|
protected:
|
|
|
|
explicit FilterModelBase(QObject *parent = 0);
|
2018-08-28 18:54:53 +00:00
|
|
|
void updateList(QStringList &new_list);
|
2017-12-23 14:25:54 +00:00
|
|
|
virtual int countDives(const char *) const = 0;
|
|
|
|
private:
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
2017-11-25 15:15:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TagFilterModel : public FilterModelBase {
|
2014-11-13 18:31:03 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static TagFilterModel *instance();
|
2018-08-14 18:09:30 +00:00
|
|
|
bool doFilter(const dive *d) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit TagFilterModel(QObject *parent = 0);
|
2017-12-23 14:25:54 +00:00
|
|
|
int countDives(const char *) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2018-08-14 18:09:30 +00:00
|
|
|
bool doFilter(const dive *d) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit BuddyFilterModel(QObject *parent = 0);
|
2017-12-23 14:25:54 +00:00
|
|
|
int countDives(const char *) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2018-08-14 18:09:30 +00:00
|
|
|
bool doFilter(const dive *d) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
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-12-23 14:25:54 +00:00
|
|
|
int countDives(const char *) const;
|
2014-11-13 18:31:03 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2018-08-14 18:09:30 +00:00
|
|
|
bool doFilter(const dive *d) const;
|
2014-11-13 19:07:05 +00:00
|
|
|
public
|
|
|
|
slots:
|
|
|
|
void repopulate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit SuitsFilterModel(QObject *parent = 0);
|
2017-12-23 14:25:54 +00:00
|
|
|
int countDives(const char *) const;
|
2014-11-13 19:07:05 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 18:31:03 +00:00
|
|
|
class MultiFilterSortModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static MultiFilterSortModel *instance();
|
2018-08-01 09:01:26 +00:00
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
2017-12-23 13:55:59 +00:00
|
|
|
void addFilterModel(FilterModelBase *model);
|
|
|
|
void removeFilterModel(FilterModelBase *model);
|
2018-08-14 18:16:25 +00:00
|
|
|
bool showDive(const struct dive *d) const;
|
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);
|
2017-12-23 13:55:59 +00:00
|
|
|
QList<FilterModelBase *> models;
|
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
|