aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.h
blob: b16ce4a3b90b69139db306017dc0fc663bb68c40 (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
// SPDX-License-Identifier: GPL-2.0
#ifndef FILTERMODELS_H
#define FILTERMODELS_H

#include "divetripmodel.h"

#include <QStringListModel>
#include <QSortFilterProxyModel>
#include <QDateTime>

#include <stdint.h>
#include <vector>

struct dive;
struct dive_trip;

struct FilterData {
	bool validFilter = false;
	int minVisibility = 0;
	int maxVisibility = 5;
	int minRating = 0;
	int maxRating = 5;
	double minWaterTemp = 0;
	double maxWaterTemp = 100;
	double minAirTemp = 0;
	double maxAirTemp = 100;
	QDateTime from;
	QDateTime to = QDateTime::currentDateTime();
	QStringList tags;
	QStringList people;
	QStringList location;
	QStringList equipment;
	bool logged = true;
	bool planned = true;
	bool invertFilter;
};

class MultiFilterSortModel : public QSortFilterProxyModel {
	Q_OBJECT
public:
	static MultiFilterSortModel *instance();
	bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
	bool showDive(const struct dive *d) const;
	int divesDisplayed;
	bool lessThan(const QModelIndex &, const QModelIndex &) const override;
public
slots:
	void myInvalidate();
	void clearFilter();
	void startFilterDiveSite(struct dive_site *ds);
	void stopFilterDiveSite();
	void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
	void resetModel(DiveTripModelBase::Layout layout);
	void filterDataChanged(const FilterData& data);

signals:
	void filterFinished();

private:
	MultiFilterSortModel(QObject *parent = 0);
	struct dive_site *curr_dive_site;
	FilterData filterData;
};

#endif