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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QStringListModel>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QSortFilterProxyModel>
							 | 
						
					
						
							
								
									
										
										
										
											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
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 14:55:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class FilterModelBase : public QStringListModel {
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-24 14:35:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void clearFilter();
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:49:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void selectAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void invertSelection();
							 | 
						
					
						
							
								
									
										
										
											
												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
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									std::vector<char> checkState;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool anyChecked;
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-24 14:35:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									bool negate;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void setNegate(bool negate);
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-25 16:15:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								protected:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									explicit FilterModelBase(QObject *parent = 0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void updateList(const QStringList &new_list);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01: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 16:15:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class TagFilterModel : public FilterModelBase {
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static TagFilterModel *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void repopulate();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									explicit TagFilterModel(QObject *parent = 0);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									int countDives(const char *) const;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-25 16:15:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class BuddyFilterModel : public FilterModelBase {
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static BuddyFilterModel *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void repopulate();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									explicit BuddyFilterModel(QObject *parent = 0);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									int countDives(const char *) const;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-25 16:15:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class LocationFilterModel : public FilterModelBase {
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static LocationFilterModel *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void repopulate();
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-26 10:42:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void changeName(const QString &oldName, const QString &newName);
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-26 22:21:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void addName(const QString &newName);
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									explicit LocationFilterModel(QObject *parent = 0);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									int countDives(const char *) const;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-25 16:15:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class SuitsFilterModel : public FilterModelBase {
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 17:07:05 -02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static SuitsFilterModel *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void repopulate();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									explicit SuitsFilterModel(QObject *parent = 0);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 15:25:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									int countDives(const char *) const;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 17:07:05 -02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class MultiFilterSortModel : public QSortFilterProxyModel {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static MultiFilterSortModel *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 14:55:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void addFilterModel(FilterModelBase *model);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void removeFilterModel(FilterModelBase *model);
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									int divesDisplayed;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 12:51:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								public
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								slots:
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void myInvalidate();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void clearFilter();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 17:42:45 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void startFilterDiveSite(uint32_t uuid);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 17:36:06 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void stopFilterDiveSite();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								signals:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void filterFinished();
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									MultiFilterSortModel(QObject *parent = 0);
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-23 14:55:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QList<FilterModelBase *> models;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bool justCleared;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 17:36:06 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct dive_site *curr_dive_site;
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-13 13:45:32 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 |