diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-05 12:21:13 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-06 15:20:46 +0200 |
commit | bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c (patch) | |
tree | 743018b0719338cf0fc560c2a59ecc2219bb4aed /framework/src/entitymodel.cpp | |
parent | 0d929de1743e9574f7972c9f5b84592202601a00 (diff) | |
download | kube-bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c.tar.gz kube-bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c.zip |
A calendar filter
Diffstat (limited to 'framework/src/entitymodel.cpp')
-rw-r--r-- | framework/src/entitymodel.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/framework/src/entitymodel.cpp b/framework/src/entitymodel.cpp index 5a79fdf2..e2a4ea2d 100644 --- a/framework/src/entitymodel.cpp +++ b/framework/src/entitymodel.cpp | |||
@@ -36,7 +36,7 @@ EntityModel::~EntityModel() | |||
36 | 36 | ||
37 | } | 37 | } |
38 | 38 | ||
39 | QHash< int, QByteArray > EntityModel::roleNames() const | 39 | QHash<int, QByteArray> EntityModel::roleNames() const |
40 | { | 40 | { |
41 | return mRoleNames; | 41 | return mRoleNames; |
42 | } | 42 | } |
@@ -152,3 +152,48 @@ QVariantMap EntityModel::data(int row) const | |||
152 | } | 152 | } |
153 | return map; | 153 | return map; |
154 | } | 154 | } |
155 | |||
156 | |||
157 | CheckableEntityModel::CheckableEntityModel(QObject *parent) : EntityModel(parent) | ||
158 | { | ||
159 | } | ||
160 | |||
161 | CheckableEntityModel::~CheckableEntityModel() | ||
162 | { | ||
163 | |||
164 | } | ||
165 | |||
166 | QHash<int, QByteArray > CheckableEntityModel::roleNames() const | ||
167 | { | ||
168 | auto roleNames = EntityModel::roleNames(); | ||
169 | roleNames.insert(Qt::CheckStateRole, "checked"); | ||
170 | return roleNames; | ||
171 | } | ||
172 | |||
173 | QVariant CheckableEntityModel::data(const QModelIndex &index, int role) const | ||
174 | { | ||
175 | if (role == Qt::CheckStateRole) { | ||
176 | const auto identifier = EntityModel::data(index, Qt::UserRole + 1).toByteArray(); | ||
177 | return mCheckedEntities.contains(identifier); | ||
178 | } | ||
179 | return EntityModel::data(index, role); | ||
180 | } | ||
181 | |||
182 | bool CheckableEntityModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
183 | { | ||
184 | if (role == Qt::CheckStateRole) { | ||
185 | const auto identifier = EntityModel::data(index, Qt::UserRole + 1).toByteArray(); | ||
186 | if (value.toBool()) { | ||
187 | mCheckedEntities.insert(identifier); | ||
188 | } else { | ||
189 | mCheckedEntities.remove(identifier); | ||
190 | } | ||
191 | emit checkedEntitiesChanged(); | ||
192 | } | ||
193 | return EntityModel::setData(index, value, role); | ||
194 | } | ||
195 | |||
196 | QSet<QByteArray> CheckableEntityModel::checkedEntities() const | ||
197 | { | ||
198 | return mCheckedEntities; | ||
199 | } | ||