From 338c0f22aabefcfd5a5e87fceb4c82e73af3f5a9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 28 May 2015 14:40:07 -0300 Subject: Move the models to its own folder This is an attempt to help share code between the desktop version of Subsurface and the mobile version. More code will be moved around and the models will be split in a way that will help recompile times and also creation of different interfaces for different form-factors. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-models/filtermodels.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 qt-models/filtermodels.h (limited to 'qt-models/filtermodels.h') diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h new file mode 100644 index 000000000..3403b3031 --- /dev/null +++ b/qt-models/filtermodels.h @@ -0,0 +1,109 @@ +#ifndef FILTERMODELS_H +#define FILTERMODELS_H + +#include +#include +#include + +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 models; + bool justCleared; + struct dive_site *curr_dive_site; +}; + +#endif -- cgit v1.2.3-70-g09d2