diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-28 20:44:11 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-31 07:48:23 -0700 |
commit | 9b90c461a21a71b1cd97060eee5a3cfb540bedba (patch) | |
tree | 84cc1458986c5bd67f99a861adcf9ff18728949a /qt-models/filtermodels.h | |
parent | b1fb578eb945c8add71f32dde1cdfc161c63d16c (diff) | |
download | subsurface-9b90c461a21a71b1cd97060eee5a3cfb540bedba.tar.gz |
Filter: Make FilterModelBase a proper Qt model (mostly)
Since FilterModelBase now contains complex data (counts and checked),
we might just as well make it a full model and keep track of
the name as well. I.e. do not derive from QStringListModel but from
QAbstractListModel and add the name to the item structure.
Implement proper reset / add / rename semantics. This is overkill at the
moment, as after all any modification the model will be reset, but
ultimately it will allow us to be smarter and only update rows when
needed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.h')
-rw-r--r-- | qt-models/filtermodels.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 846949809..7e5aae727 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -9,14 +9,20 @@ struct dive; -class FilterModelBase : public QStringListModel { +class FilterModelBase : public QAbstractListModel { Q_OBJECT +private: + int findInsertionIndex(const QString &name); protected: struct Item { + QString name; bool checked; int count; }; std::vector<Item> items; + int indexOf(const QString &name) const; + void addItem(const QString &name, bool checked, int count); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; public: virtual bool doFilter(const dive *d) const = 0; void clearFilter(); @@ -27,6 +33,7 @@ public: public slots: void setNegate(bool negate); + void changeName(const QString &oldName, const QString &newName); protected: explicit FilterModelBase(QObject *parent = 0); void updateList(const QStringList &new_list); @@ -73,7 +80,6 @@ public: public slots: void repopulate(); - void changeName(const QString &oldName, const QString &newName); void addName(const QString &newName); private: |