summaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-08-28 20:44:11 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-31 07:48:23 -0700
commit9b90c461a21a71b1cd97060eee5a3cfb540bedba (patch)
tree84cc1458986c5bd67f99a861adcf9ff18728949a /qt-models/filtermodels.h
parentb1fb578eb945c8add71f32dde1cdfc161c63d16c (diff)
downloadsubsurface-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.h10
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: