diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-10-01 16:23:02 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-02 07:35:23 -0700 |
commit | e0b60167f2366092f2e38436d443f0e2bcfe417d (patch) | |
tree | 17e3dd326d1b0062df3a9058c712b65c6ee9aed6 /qt-ui/models.h | |
parent | 28800622f00b07724b3395eacc49f1ee87b42d08 (diff) | |
download | subsurface-e0b60167f2366092f2e38436d443f0e2bcfe417d.tar.gz |
Add possibility to filter by more than one criteria at a time
This new version of the TagFilterSortModel actually accepts
*any* new MultiFilterInterface.
So, how to use it to create a new filter:
Implement a class that inherits from MultiFilterInterface
Implement the filterRow method
TagFilterSortModel::instance->add( myClass );
and you are done.
[Dirk Hohndel: removed some debug code and did whitespace cleanup]
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.h')
-rw-r--r-- | qt-ui/models.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/qt-ui/models.h b/qt-ui/models.h index 18c26df44..bf13063c8 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -417,13 +417,19 @@ private: QStringList languages; }; -class TagFilterModel : public QStringListModel { +class MultiFilterInterface { +public: + virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const = 0; +}; + +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; + virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const; bool *checkState; bool anyChecked; public @@ -437,7 +443,14 @@ private: class TagFilterSortModel : public QSortFilterProxyModel { Q_OBJECT public: - TagFilterSortModel(QObject *parent = 0); + static TagFilterSortModel *instance(); virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + void addFilterModel(MultiFilterInterface *model); + void removeFilterModel(MultiFilterInterface *model); +public slots: + void myInvalidate(); +private: + TagFilterSortModel(QObject *parent = 0); + QList<MultiFilterInterface*> models; }; #endif // MODELS_H |