diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2017-12-23 15:25:54 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-24 08:24:11 -0800 |
commit | 668635e98eb32e3c5ffd3cb3e65da51c71db2975 (patch) | |
tree | dc2356729fdac453a412c5c00c785c19c651ac23 /qt-models/filtermodels.h | |
parent | 7eed752ba15bcb152d448868d2d291abde8748aa (diff) | |
download | subsurface-668635e98eb32e3c5ffd3cb3e65da51c71db2975.tar.gz |
Move *FilterModel functions into base class
The *FilterModels had a number of of virtual functions, which only
accessed members of the base class. Moreover, these functions were
identical and generated with macros. Therefore, move these functions
to the base class.
The one excption is data(), which uses different count functions
(passed as a macro parameter). Thus, introduce a virtual countDives()
function and likewise move data() to the base class. A function pointer
might be even more clear, but since the rest of the code/Qt relies
heavily on runtime polymorphism, let's do the same here.
The only macros left are those creating the singleton accessors.
This could be more clearly realized by templates, but let's
likewise keep it the way is.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.h')
-rw-r--r-- | qt-models/filtermodels.h | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index b7d65aae2..d0c3a215a 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -10,57 +10,52 @@ class FilterModelBase : public QStringListModel { public: virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0; - virtual void clearFilter() = 0; + void clearFilter(); std::vector<char> checkState; bool anyChecked; protected: explicit FilterModelBase(QObject *parent = 0); void updateList(const QStringList &new_list); + 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); }; class TagFilterModel : public FilterModelBase { 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); + int countDives(const char *) const; }; class BuddyFilterModel : public FilterModelBase { 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); + int countDives(const char *) const; }; class LocationFilterModel : public FilterModelBase { 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(); @@ -69,23 +64,21 @@ slots: private: explicit LocationFilterModel(QObject *parent = 0); + int countDives(const char *) const; }; class SuitsFilterModel : public FilterModelBase { 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); + int countDives(const char *) const; }; class MultiFilterSortModel : public QSortFilterProxyModel { |