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
|
|
|
|
|
2018-12-27 09:06:11 +00:00
|
|
|
#include "divetripmodel.h"
|
2018-10-29 13:56:48 +00:00
|
|
|
|
2014-11-13 18:31:03 +00:00
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
2018-12-06 19:07:47 +00:00
|
|
|
#include <QDateTime>
|
|
|
|
|
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-09-06 07:52:02 +00:00
|
|
|
struct dive_trip;
|
2018-08-14 18:09:30 +00:00
|
|
|
|
2018-12-06 19:07:47 +00:00
|
|
|
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;
|
2019-01-01 17:49:56 +00:00
|
|
|
bool logged = true;
|
|
|
|
bool planned = true;
|
2018-12-06 19:07:47 +00:00
|
|
|
bool invertFilter;
|
|
|
|
};
|
|
|
|
|
2014-11-13 18:31:03 +00:00
|
|
|
class MultiFilterSortModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static MultiFilterSortModel *instance();
|
2018-09-29 20:13:44 +00:00
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
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;
|
2018-10-29 19:17:53 +00:00
|
|
|
bool lessThan(const QModelIndex &, const QModelIndex &) const override;
|
2014-11-13 20:51:23 +00:00
|
|
|
public
|
|
|
|
slots:
|
2014-11-13 18:31:03 +00:00
|
|
|
void myInvalidate();
|
|
|
|
void clearFilter();
|
2018-10-26 14:57:08 +00:00
|
|
|
void startFilterDiveSite(struct dive_site *ds);
|
2015-05-26 20:36:06 +00:00
|
|
|
void stopFilterDiveSite();
|
2018-09-06 20:03:03 +00:00
|
|
|
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
2018-12-27 09:06:11 +00:00
|
|
|
void resetModel(DiveTripModelBase::Layout layout);
|
2018-12-16 19:43:01 +00:00
|
|
|
void filterDataChanged(const FilterData &data);
|
2015-05-26 20:36:06 +00:00
|
|
|
|
2014-11-16 16:04:06 +00:00
|
|
|
signals:
|
|
|
|
void filterFinished();
|
2018-12-06 19:07:47 +00:00
|
|
|
|
2014-11-13 18:31:03 +00:00
|
|
|
private:
|
|
|
|
MultiFilterSortModel(QObject *parent = 0);
|
2015-05-26 20:36:06 +00:00
|
|
|
struct dive_site *curr_dive_site;
|
2018-12-06 19:07:47 +00:00
|
|
|
FilterData filterData;
|
2014-11-13 18:31:03 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 21:45:32 +00:00
|
|
|
#endif
|