Debian Codegraph @

maz-db/src/MazDBListModel.h

raw symbols SCIP
1 /* Copyright (C) 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef MAZDBLISTMODEL_H
19 #define MAZDBLISTMODEL_H
20
21 #include <QObject>
22 #include <QAbstractListModel>
23 #include <QStringList>
24 #include <QJSValue>
25 #include <MazDBQuery.h>
26
27 class MazDB;
28
29 class MazDBListModel : public QAbstractListModel
30 {
31 Q_OBJECT
32 Q_PROPERTY(int count READ count NOTIFY countChanged)
33 Q_PROPERTY(Range *range READ range)
34 Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
35 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
36 Q_PROPERTY(FilterPolicy filterPolicy READ filterPolicy WRITE setFilterPolicy NOTIFY filterPolicyChanged)
37 Q_PROPERTY(QStringList customRoles READ customRoles WRITE setCustomRoles NOTIFY customRolesChanged)
38 Q_PROPERTY(QJSValue rolesCallBack READ rolesCallBack WRITE setRolesCallBack NOTIFY rolesCallBackChanged)
39 Q_PROPERTY(QStringList excludeKeys READ excludeKeys WRITE setExcludeKeys NOTIFY excludeKeysChanged)
40 Q_ENUMS(FilterPolicy)
41 public:
42 explicit MazDBListModel(QObject *parent = 0);
43
44 enum Roles {
45 KeyRole,
46 ValueRole
47 };
48
49 enum FilterPolicy {
50 ExactMatch,
51 Contains
52 };
53
54 int count() const;
55 Range *range();
56 QString source() const;
57 QString filter() const;
58 QHash<int, QByteArray> roleNames() const override;
59 QVariant data(const QModelIndex &index, int role) const override;
60 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
61 FilterPolicy filterPolicy() const;
62 QStringList customRoles() const;
63 QStringList excludeKeys() const;
64 QJSValue rolesCallBack() const;
65
66 signals:
67 void sourceChanged();
68 void countChanged();
69 void filterChanged();
70 void filterPolicyChanged(FilterPolicy filterPolicy);
71 void customRolesChanged(QStringList customRoles);
72 void rolesCallBackChanged(QJSValue rolesCallBack);
73 void excludeKeysChanged();
74
75 public slots:
76 void setSource(const QString &src);
77 void setFilter(const QString &filter);
78 void close();
79 void clear();
80 void reload();
81 void setFilterPolicy(FilterPolicy filterPolicy);
82 void setCustomRoles(QStringList customRoles);
83 void setRolesCallBack(QJSValue rolesCallBack);
84 void setExcludeKeys(QStringList keys);
85
86 private slots:
87 void handleKeyValueChange(const QString &key, const QVariant &value);
88 void handleKeyValueRemoved(const QString &key);
89
90 private:
91 void load();
92 void emitDataChanged(const QString &key);
93 bool insertAllowed(const QString &key);
94 MazDB *m_db;
95 QStringList m_keys;
96 QString m_filter;
97 FilterPolicy m_filterPolicy;
98 QStringList m_customRoles;
99 QStringList m_excludeKeys;
100 QJSValue m_rolesCallBack;
101 Range m_range;
102 };
103
104 #endif // MAZDBLISTMODEL_H