diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 14:55:16 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-22 14:55:16 +0100 |
commit | 7748c2a5c1cc29a8c69ea051174e31b02af4a208 (patch) | |
tree | 80e094dbc83b0fcff3dc7996d5159a349b57ea3f | |
parent | 78a299efd28792364b518e954cc3ae83769e06ab (diff) | |
download | sink-7748c2a5c1cc29a8c69ea051174e31b02af4a208.tar.gz sink-7748c2a5c1cc29a8c69ea051174e31b02af4a208.zip |
Some helper functions to avoid hardcoding collected property names
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 11 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 8 | ||||
-rw-r--r-- | common/query.h | 7 | ||||
-rw-r--r-- | common/standardqueries.h | 6 |
4 files changed, 29 insertions, 3 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 2a7f948..ff2990d 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -212,6 +212,12 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | |||
212 | return mAdaptor->getProperty(key); | 212 | return mAdaptor->getProperty(key); |
213 | } | 213 | } |
214 | 214 | ||
215 | QVariantList ApplicationDomainType::getCollectedProperty(const QByteArray &key) const | ||
216 | { | ||
217 | Q_ASSERT(mAdaptor); | ||
218 | return mAdaptor->getProperty(key + "Collected").toList(); | ||
219 | } | ||
220 | |||
215 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) | 221 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) |
216 | { | 222 | { |
217 | Q_ASSERT(mAdaptor); | 223 | Q_ASSERT(mAdaptor); |
@@ -283,6 +289,11 @@ QVector<QByteArray> &ApplicationDomainType::aggregatedIds() | |||
283 | return mAggreatedIds; | 289 | return mAggreatedIds; |
284 | } | 290 | } |
285 | 291 | ||
292 | int ApplicationDomainType::count() const | ||
293 | { | ||
294 | return qMax(mAggreatedIds.size(), 1); | ||
295 | } | ||
296 | |||
286 | SinkResource::SinkResource(const QByteArray &identifier) | 297 | SinkResource::SinkResource(const QByteArray &identifier) |
287 | : ApplicationDomainType("", identifier, 0, QSharedPointer<BufferAdaptor>(new MemoryBufferAdaptor())) | 298 | : ApplicationDomainType("", identifier, 0, QSharedPointer<BufferAdaptor>(new MemoryBufferAdaptor())) |
288 | { | 299 | { |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 986dd6d..27a7954 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -257,6 +257,13 @@ public: | |||
257 | bool hasProperty(const QByteArray &key) const; | 257 | bool hasProperty(const QByteArray &key) const; |
258 | 258 | ||
259 | QVariant getProperty(const QByteArray &key) const; | 259 | QVariant getProperty(const QByteArray &key) const; |
260 | QVariantList getCollectedProperty(const QByteArray &key) const; | ||
261 | |||
262 | template <typename Property> | ||
263 | QVariantList getCollectedProperty() const | ||
264 | { | ||
265 | return getCollectedProperty(Property::name); | ||
266 | } | ||
260 | 267 | ||
261 | /** | 268 | /** |
262 | * Set a property and record a changed property | 269 | * Set a property and record a changed property |
@@ -281,6 +288,7 @@ public: | |||
281 | bool isAggregate() const; | 288 | bool isAggregate() const; |
282 | QVector<QByteArray> aggregatedIds() const; | 289 | QVector<QByteArray> aggregatedIds() const; |
283 | QVector<QByteArray> &aggregatedIds(); | 290 | QVector<QByteArray> &aggregatedIds(); |
291 | int count() const; | ||
284 | 292 | ||
285 | private: | 293 | private: |
286 | friend QDebug operator<<(QDebug, const ApplicationDomainType &); | 294 | friend QDebug operator<<(QDebug, const ApplicationDomainType &); |
diff --git a/common/query.h b/common/query.h index fd79105..9030d7c 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -234,6 +234,13 @@ public: | |||
234 | return *this; | 234 | return *this; |
235 | } | 235 | } |
236 | 236 | ||
237 | template <typename T> | ||
238 | Reduce &collect() | ||
239 | { | ||
240 | aggregators << Aggregator(QByteArray{T::name} + QByteArray{"Collected"}, Aggregator::Collect, T::name); | ||
241 | return *this; | ||
242 | } | ||
243 | |||
237 | //Reduce on property | 244 | //Reduce on property |
238 | QByteArray property; | 245 | QByteArray property; |
239 | Selector selector; | 246 | Selector selector; |
diff --git a/common/standardqueries.h b/common/standardqueries.h index 70e03cb..10f66ae 100644 --- a/common/standardqueries.h +++ b/common/standardqueries.h | |||
@@ -53,9 +53,9 @@ namespace StandardQueries { | |||
53 | query.filter<ApplicationDomain::Mail::Folder>(folder); | 53 | query.filter<ApplicationDomain::Mail::Folder>(folder); |
54 | query.sort<ApplicationDomain::Mail::Date>(); | 54 | query.sort<ApplicationDomain::Mail::Date>(); |
55 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()) | 55 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()) |
56 | .count("count") | 56 | .count() |
57 | .collect<ApplicationDomain::Mail::Unread>("unreadCollected") | 57 | .collect<ApplicationDomain::Mail::Unread>() |
58 | .collect<ApplicationDomain::Mail::Important>("importantCollected"); | 58 | .collect<ApplicationDomain::Mail::Important>(); |
59 | return query; | 59 | return query; |
60 | } | 60 | } |
61 | 61 | ||