Changeset View
Changeset View
Standalone View
Standalone View
src/query.cpp
Show All 14 Lines | |||||
15 | * Lesser General Public License for more details. | 15 | * Lesser General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | 17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. | 18 | * License along with this library. | ||
19 | * If not, see <http://www.gnu.org/licenses/>. | 19 | * If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "query.h" | 22 | #include "query.h" | ||
23 | #include <QDate> | ||||
23 | #include <QDebug> | 24 | #include <QDebug> | ||
24 | 25 | | |||
25 | namespace KActivities { | 26 | namespace KActivities { | ||
26 | namespace Stats { | 27 | namespace Stats { | ||
27 | 28 | | |||
28 | namespace details { | 29 | namespace details { | ||
29 | inline void validateTypes(QStringList &types) | 30 | inline void validateTypes(QStringList &types) | ||
30 | { | 31 | { | ||
Show All 35 Lines | 61 | public: | |||
66 | } | 67 | } | ||
67 | 68 | | |||
68 | Terms::Select selection; | 69 | Terms::Select selection; | ||
69 | QStringList types; | 70 | QStringList types; | ||
70 | QStringList agents; | 71 | QStringList agents; | ||
71 | QStringList activities; | 72 | QStringList activities; | ||
72 | QStringList urlFilters; | 73 | QStringList urlFilters; | ||
73 | Terms::Order ordering; | 74 | Terms::Order ordering; | ||
75 | QDate date; | ||||
74 | int limit; | 76 | int limit; | ||
75 | int offset; | 77 | int offset; | ||
76 | }; | 78 | }; | ||
77 | 79 | | |||
78 | Query::Query(Terms::Select selection) | 80 | Query::Query(Terms::Select selection) | ||
79 | : d(new QueryPrivate()) | 81 | : d(new QueryPrivate()) | ||
80 | { | 82 | { | ||
81 | d->selection = selection; | 83 | d->selection = selection; | ||
Show All 24 Lines | |||||
106 | 108 | | |||
107 | bool Query::operator== (const Query &right) const | 109 | bool Query::operator== (const Query &right) const | ||
108 | { | 110 | { | ||
109 | return selection() == right.selection() && | 111 | return selection() == right.selection() && | ||
110 | types() == right.types() && | 112 | types() == right.types() && | ||
111 | agents() == right.agents() && | 113 | agents() == right.agents() && | ||
112 | activities() == right.activities() && | 114 | activities() == right.activities() && | ||
113 | selection() == right.selection() && | 115 | selection() == right.selection() && | ||
114 | urlFilters() == right.urlFilters(); | 116 | urlFilters() == right.urlFilters() && | ||
117 | date() == right.date(); | ||||
115 | } | 118 | } | ||
116 | 119 | | |||
117 | bool Query::operator!= (const Query &right) const | 120 | bool Query::operator!= (const Query &right) const | ||
118 | { | 121 | { | ||
119 | return !(*this == right); | 122 | return !(*this == right); | ||
120 | } | 123 | } | ||
121 | 124 | | |||
122 | #define IMPLEMENT_QUERY_LIST_FIELD(WHAT, What, Default) \ | 125 | #define IMPLEMENT_QUERY_LIST_FIELD(WHAT, What, Default) \ | ||
Show All 35 Lines | 160 | { | |||
158 | d->limit = limit; | 161 | d->limit = limit; | ||
159 | } | 162 | } | ||
160 | 163 | | |||
161 | void Query::setOffset(int offset) | 164 | void Query::setOffset(int offset) | ||
162 | { | 165 | { | ||
163 | d->offset = offset; | 166 | d->offset = offset; | ||
164 | } | 167 | } | ||
165 | 168 | | |||
169 | void Query::setDate(QDate date) | ||||
170 | { | ||||
171 | d->date = date; | ||||
172 | } | ||||
173 | | ||||
166 | Terms::Order Query::ordering() const | 174 | Terms::Order Query::ordering() const | ||
167 | { | 175 | { | ||
168 | return d->ordering; | 176 | return d->ordering; | ||
169 | } | 177 | } | ||
170 | 178 | | |||
171 | Terms::Select Query::selection() const | 179 | Terms::Select Query::selection() const | ||
172 | { | 180 | { | ||
173 | return d->selection; | 181 | return d->selection; | ||
174 | } | 182 | } | ||
175 | 183 | | |||
176 | int Query::limit() const | 184 | int Query::limit() const | ||
177 | { | 185 | { | ||
178 | return d->limit; | 186 | return d->limit; | ||
179 | } | 187 | } | ||
180 | 188 | | |||
181 | int Query::offset() const | 189 | int Query::offset() const | ||
182 | { | 190 | { | ||
183 | Q_ASSERT_X(d->limit > 0, "Query::offset", "Offset can only be specified if limit is set"); | 191 | Q_ASSERT_X(d->limit > 0, "Query::offset", "Offset can only be specified if limit is set"); | ||
184 | return d->offset; | 192 | return d->offset; | ||
185 | } | 193 | } | ||
186 | 194 | | |||
195 | QDate Query::date() const | ||||
196 | { | ||||
197 | return d->date; | ||||
198 | } | ||||
199 | | ||||
187 | } // namespace Stats | 200 | } // namespace Stats | ||
188 | } // namespace KActivities | 201 | } // namespace KActivities | ||
189 | 202 | | |||
190 | namespace KAStats = KActivities::Stats; | 203 | namespace KAStats = KActivities::Stats; | ||
191 | 204 | | |||
192 | QDebug operator<<(QDebug dbg, const KAStats::Query &query) | 205 | QDebug operator<<(QDebug dbg, const KAStats::Query &query) | ||
193 | { | 206 | { | ||
194 | using namespace KAStats::Terms; | 207 | using namespace KAStats::Terms; | ||
195 | 208 | | |||
196 | dbg.nospace() | 209 | dbg.nospace() | ||
197 | << "Query { " | 210 | << "Query { " | ||
198 | << query.selection() | 211 | << query.selection() | ||
199 | << ", " << Type(query.types()) | 212 | << ", " << Type(query.types()) | ||
200 | << ", " << Agent(query.agents()) | 213 | << ", " << Agent(query.agents()) | ||
201 | << ", " << Activity(query.activities()) | 214 | << ", " << Activity(query.activities()) | ||
202 | << ", " << Url(query.urlFilters()) | 215 | << ", " << Url(query.urlFilters()) | ||
216 | << ", " << Date(query.date()) | ||||
203 | << ", " << query.ordering() | 217 | << ", " << query.ordering() | ||
204 | << ", Limit: " << query.limit() | 218 | << ", Limit: " << query.limit() | ||
205 | << " }"; | 219 | << " }"; | ||
206 | return dbg; | 220 | return dbg; | ||
207 | } | 221 | } |