aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.h
blob: 3403b3031acdc9e5e38d66e6775bcf3ab4f36434 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef FILTERMODELS_H
#define FILTERMODELS_H

#include <QStringListModel>
#include <QSortFilterProxyModel>
#include <stdint.h>

class MultiFilterInterface {
public:
	MultiFilterInterface() : checkState(NULL), anyChecked(false) {}
	virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
	virtual void clearFilter() = 0;
	bool *checkState;
	bool anyChecked;
};

class TagFilterModel : public QStringListModel, public MultiFilterInterface {
	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);
};

class BuddyFilterModel : public QStringListModel, public MultiFilterInterface {
	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);
};

class LocationFilterModel : public QStringListModel, public MultiFilterInterface {
	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();

private:
	explicit LocationFilterModel(QObject *parent = 0);
};

class SuitsFilterModel : public QStringListModel, public MultiFilterInterface {
	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);
};

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);
	int divesDisplayed;
public
slots:
	void myInvalidate();
	void clearFilter();
	void startFilterDiveSite(uint32_t uuid);
	void stopFilterDiveSite();

signals:
	void filterFinished();
private:
	MultiFilterSortModel(QObject *parent = 0);
	QList<MultiFilterInterface *> models;
	bool justCleared;
	struct dive_site *curr_dive_site;
};

#endif