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