summaryrefslogtreecommitdiffstats
path: root/common/query.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/query.h')
-rw-r--r--common/query.h120
1 files changed, 99 insertions, 21 deletions
diff --git a/common/query.h b/common/query.h
index 0d0f382..1df32da 100644
--- a/common/query.h
+++ b/common/query.h
@@ -22,42 +22,120 @@
22#include <QByteArrayList> 22#include <QByteArrayList>
23#include <QHash> 23#include <QHash>
24#include <QSet> 24#include <QSet>
25#include "applicationdomaintype.h"
25 26
26namespace Akonadi2 { 27namespace Akonadi2 {
27 28
28/** 29/**
29 * A query that matches a set of objects 30 * A query that matches a set of entities.
30 *
31 * The query will have to be updated regularly similary to the domain objects.
32 * It probably also makes sense to have a domain specific part of the query,
33 * such as what properties we're interested in (necessary information for on-demand
34 * loading of data).
35 *
36 * The query defines:
37 * * what resources to search
38 * * filters on various properties (parent collection, startDate range, ....)
39 * * properties we need (for on-demand querying)
40 *
41 * syncOnDemand: Execute a source sync before executing the query
42 * processAll: Ensure all local messages are processed before querying to guarantee an up-to date dataset.
43 */ 31 */
44class Query 32class Query
45{ 33{
46public: 34public:
47 Query() : syncOnDemand(true), processAll(false), liveQuery(false) {} 35 enum Flag {
48 //Could also be a propertyFilter 36 /** Leave the query running an contiously update the result set. */
37 LiveQuery
38 };
39 Q_DECLARE_FLAGS(Flags, Flag)
40
41 static Query PropertyFilter(const QByteArray &key, const QVariant &value)
42 {
43 Query query;
44 query.propertyFilter.insert(key, value);
45 return query;
46 }
47
48 static Query PropertyFilter(const QByteArray &key, const ApplicationDomain::Entity &entity)
49 {
50 return PropertyFilter(key, QVariant::fromValue(entity.identifier()));
51 }
52
53 static Query ResourceFilter(const QByteArray &identifier)
54 {
55 Query query;
56 query.resources.append(identifier);
57 return query;
58 }
59
60 static Query ResourceFilter(const QByteArrayList &identifier)
61 {
62 Query query;
63 query.resources = identifier;
64 return query;
65 }
66
67 static Query ResourceFilter(const ApplicationDomain::AkonadiResource &entity)
68 {
69 return ResourceFilter(entity.identifier());
70 }
71
72 static Query IdentityFilter(const QByteArray &identifier)
73 {
74 Query query;
75 query.ids << identifier;
76 return query;
77 }
78
79 static Query IdentityFilter(const QByteArrayList &identifier)
80 {
81 Query query;
82 query.ids = identifier;
83 return query;
84 }
85
86 static Query IdentityFilter(const ApplicationDomain::Entity &entity)
87 {
88 return IdentityFilter(entity.identifier());
89 }
90
91 static Query RequestedProperties(const QByteArrayList &properties)
92 {
93 Query query;
94 query.requestedProperties = properties;
95 return query;
96 }
97
98 static Query RequestTree(const QByteArray &parentProperty)
99 {
100 Query query;
101 query.parentProperty = parentProperty;
102 return query;
103 }
104
105 Query(Flags flags = Flags())
106 {}
107
108 Query& operator+=(const Query& rhs)
109 {
110 resources += rhs.resources;
111 ids += rhs.ids;
112 for (auto it = rhs.propertyFilter.constBegin(); it != rhs.propertyFilter.constEnd(); it++) {
113 propertyFilter.insert(it.key(), it.value());
114 }
115 requestedProperties += rhs.requestedProperties;
116 parentProperty = rhs.parentProperty;
117 liveQuery = rhs.liveQuery;
118 syncOnDemand = rhs.syncOnDemand;
119 processAll = rhs.processAll;
120 return *this;
121 }
122
123 friend Query operator+(Query lhs, const Query& rhs)
124 {
125 lhs += rhs;
126 return lhs;
127 }
128
49 QByteArrayList resources; 129 QByteArrayList resources;
50 //Could also be a propertyFilter
51 QByteArrayList ids; 130 QByteArrayList ids;
52 //Filters to apply
53 QHash<QByteArray, QVariant> propertyFilter; 131 QHash<QByteArray, QVariant> propertyFilter;
54 //Properties to retrieve
55 QByteArrayList requestedProperties; 132 QByteArrayList requestedProperties;
56 QByteArray parentProperty; 133 QByteArray parentProperty;
134 bool liveQuery;
57 bool syncOnDemand; 135 bool syncOnDemand;
58 bool processAll; 136 bool processAll;
59 //If live query is false, this query will not continuously be updated
60 bool liveQuery;
61}; 137};
62 138
63} 139}
140
141Q_DECLARE_OPERATORS_FOR_FLAGS(Akonadi2::Query::Flags)