diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:22:55 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:22:55 +0200 |
commit | 096d14f20f4dc39d20d35d605ca755b66bd48cf9 (patch) | |
tree | 4b28dd3b310ebcfa9cefa1b41992eeefa5456764 /common/query.h | |
parent | c1475df297975b403d991f69ef9436cd576c1e46 (diff) | |
download | sink-096d14f20f4dc39d20d35d605ca755b66bd48cf9.tar.gz sink-096d14f20f4dc39d20d35d605ca755b66bd48cf9.zip |
Account filter for resources and contains comparator in query
Diffstat (limited to 'common/query.h')
-rw-r--r-- | common/query.h | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/common/query.h b/common/query.h index 3a56c9f..ccac1e7 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include "sink_export.h" | ||
22 | #include <QByteArrayList> | 23 | #include <QByteArrayList> |
23 | #include <QHash> | 24 | #include <QHash> |
24 | #include <QSet> | 25 | #include <QSet> |
@@ -29,7 +30,7 @@ namespace Sink { | |||
29 | /** | 30 | /** |
30 | * A query that matches a set of entities. | 31 | * A query that matches a set of entities. |
31 | */ | 32 | */ |
32 | class Query | 33 | class SINK_EXPORT Query |
33 | { | 34 | { |
34 | public: | 35 | public: |
35 | enum Flag | 36 | enum Flag |
@@ -46,6 +47,13 @@ public: | |||
46 | return query; | 47 | return query; |
47 | } | 48 | } |
48 | 49 | ||
50 | static Query PropertyContainsFilter(const QByteArray &key, const QVariant &value) | ||
51 | { | ||
52 | Query query; | ||
53 | query.propertyFilter.insert(key, value); | ||
54 | return query; | ||
55 | } | ||
56 | |||
49 | static Query PropertyFilter(const QByteArray &key, const ApplicationDomain::Entity &entity) | 57 | static Query PropertyFilter(const QByteArray &key, const ApplicationDomain::Entity &entity) |
50 | { | 58 | { |
51 | return PropertyFilter(key, QVariant::fromValue(entity.identifier())); | 59 | return PropertyFilter(key, QVariant::fromValue(entity.identifier())); |
@@ -70,6 +78,18 @@ public: | |||
70 | return ResourceFilter(entity.identifier()); | 78 | return ResourceFilter(entity.identifier()); |
71 | } | 79 | } |
72 | 80 | ||
81 | static Query AccountFilter(const QByteArrayList &identifier) | ||
82 | { | ||
83 | Query query; | ||
84 | query.accounts = identifier; | ||
85 | return query; | ||
86 | } | ||
87 | |||
88 | static Query AccountFilter(const ApplicationDomain::SinkAccount &entity) | ||
89 | { | ||
90 | return AccountFilter(entity.identifier()); | ||
91 | } | ||
92 | |||
73 | static Query IdentityFilter(const QByteArray &identifier) | 93 | static Query IdentityFilter(const QByteArray &identifier) |
74 | { | 94 | { |
75 | Query query; | 95 | Query query; |
@@ -110,6 +130,7 @@ public: | |||
110 | Query &operator+=(const Query &rhs) | 130 | Query &operator+=(const Query &rhs) |
111 | { | 131 | { |
112 | resources += rhs.resources; | 132 | resources += rhs.resources; |
133 | accounts += rhs.accounts; | ||
113 | ids += rhs.ids; | 134 | ids += rhs.ids; |
114 | for (auto it = rhs.propertyFilter.constBegin(); it != rhs.propertyFilter.constEnd(); it++) { | 135 | for (auto it = rhs.propertyFilter.constBegin(); it != rhs.propertyFilter.constEnd(); it++) { |
115 | propertyFilter.insert(it.key(), it.value()); | 136 | propertyFilter.insert(it.key(), it.value()); |
@@ -128,9 +149,25 @@ public: | |||
128 | return lhs; | 149 | return lhs; |
129 | } | 150 | } |
130 | 151 | ||
152 | struct Comparator { | ||
153 | enum Comparators { | ||
154 | Invalid, | ||
155 | Equals, | ||
156 | Contains | ||
157 | }; | ||
158 | |||
159 | Comparator(); | ||
160 | Comparator(const QVariant &v); | ||
161 | bool matches(const QVariant &v) const; | ||
162 | |||
163 | QVariant value; | ||
164 | Comparators comparator; | ||
165 | }; | ||
166 | |||
131 | QByteArrayList resources; | 167 | QByteArrayList resources; |
168 | QByteArrayList accounts; | ||
132 | QByteArrayList ids; | 169 | QByteArrayList ids; |
133 | QHash<QByteArray, QVariant> propertyFilter; | 170 | QHash<QByteArray, Comparator> propertyFilter; |
134 | QByteArrayList requestedProperties; | 171 | QByteArrayList requestedProperties; |
135 | QByteArray parentProperty; | 172 | QByteArray parentProperty; |
136 | QByteArray sortProperty; | 173 | QByteArray sortProperty; |
@@ -139,4 +176,6 @@ public: | |||
139 | }; | 176 | }; |
140 | } | 177 | } |
141 | 178 | ||
179 | QDebug operator<<(QDebug dbg, const Sink::Query::Comparator &c); | ||
180 | |||
142 | Q_DECLARE_OPERATORS_FOR_FLAGS(Sink::Query::Flags) | 181 | Q_DECLARE_OPERATORS_FOR_FLAGS(Sink::Query::Flags) |