85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: caquery.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QStringList>
|
|
19 |
#include <QDebug>
|
|
20 |
|
|
21 |
#include "caquery.h"
|
|
22 |
#include "caquery_p.h"
|
|
23 |
|
|
24 |
// ======== MEMBER FUNCTIONS ========
|
|
25 |
|
|
26 |
|
|
27 |
/*!
|
|
28 |
\class CaQuery
|
|
29 |
\brief This class contains data describing a query used by CaService.
|
|
30 |
|
|
31 |
Thanks to CaQuery object, it's possible to create objects easly
|
|
32 |
using this one like CaNotifierFilter for example or define criteria during
|
|
33 |
geting entries via service. CaQuery anable set usufull data to do that,
|
|
34 |
including entry roles, type names, parent id, sort ordering
|
|
35 |
and set on/off flags quickly.
|
|
36 |
|
|
37 |
\example
|
|
38 |
\code
|
|
39 |
CaQuery query;
|
|
40 |
query.setEntryRoles( ItemEntryRole | GroupEntryRole );
|
|
41 |
query.setSort( MostUsedSortAttribute, Qt::DescendingOrder );
|
|
42 |
query.setFlagsOn( UsedEntryFlag | RemovableEntryFlag | RunningEntryFlag );
|
|
43 |
query.setFlagsOff( SystemEntryFlag | VisibleEntryFlag );
|
|
44 |
// using CaQuery to get data from DB
|
|
45 |
QList<CaEntry *> entries = CaService::instance()->getEntries( query );
|
|
46 |
...
|
|
47 |
// using CaQuery to create notifier
|
|
48 |
CaQuery queryNot( query );
|
|
49 |
CaNotifierFilter notifierFilter( queryNot );
|
|
50 |
CaNotifier * notifier = CaService::instance()->createNotifier( notifierFilter );
|
|
51 |
...
|
|
52 |
|
|
53 |
\endcode
|
|
54 |
*/
|
|
55 |
|
|
56 |
/*!
|
93
|
57 |
\var CaQueryPrivate::m_q
|
|
58 |
Points to the CaQuery instance that uses this private implementation.
|
|
59 |
*/
|
|
60 |
|
|
61 |
/*!
|
85
|
62 |
Default constructor.
|
|
63 |
*/
|
|
64 |
CaQuery::CaQuery() :
|
|
65 |
m_d(new CaQueryPrivate(this))
|
|
66 |
{
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
/*!
|
|
71 |
Copy constructor.
|
|
72 |
\param query reference to CaQuery.
|
|
73 |
*/
|
|
74 |
CaQuery::CaQuery(const CaQuery &query) :
|
|
75 |
m_d(new CaQueryPrivate(this))
|
|
76 |
{
|
|
77 |
*m_d = *(query.m_d);
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
Copy assignment operator.
|
|
82 |
\param query const reference to CaQuery.
|
|
83 |
\retval reference to CaQuery.
|
|
84 |
*/
|
|
85 |
CaQuery &CaQuery::operator=(const CaQuery &query)
|
|
86 |
{
|
|
87 |
if (this != &query) {
|
|
88 |
*m_d = *(query.m_d);
|
|
89 |
}
|
|
90 |
return *this;
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
|
94 |
Destructor.
|
|
95 |
*/
|
|
96 |
CaQuery::~CaQuery()
|
|
97 |
{
|
|
98 |
delete m_d;
|
|
99 |
}
|
|
100 |
|
|
101 |
/*!
|
|
102 |
Sets entry roles.
|
|
103 |
\param entryRoles role of the entry.
|
|
104 |
*/
|
|
105 |
void CaQuery::setEntryRoles(EntryRoles entryRoles)
|
|
106 |
{
|
|
107 |
m_d->setEntryRoles(entryRoles);
|
|
108 |
}
|
|
109 |
|
|
110 |
/*!
|
|
111 |
Returns an entry role.
|
|
112 |
\retval entry role.
|
|
113 |
*/
|
|
114 |
EntryRoles CaQuery::entryRoles() const
|
|
115 |
{
|
|
116 |
return m_d->entryRoles();
|
|
117 |
}
|
|
118 |
|
|
119 |
/*!
|
|
120 |
Sets parent id.
|
|
121 |
\param id id of the parent.
|
|
122 |
*/
|
|
123 |
void CaQuery::setParentId(int id)
|
|
124 |
{
|
|
125 |
m_d->setParentId(id);
|
|
126 |
}
|
|
127 |
|
|
128 |
/*!
|
|
129 |
Returns parent id.
|
|
130 |
\retval parent id.
|
|
131 |
*/
|
|
132 |
int CaQuery::parentId() const
|
|
133 |
{
|
|
134 |
return m_d->parentId();
|
|
135 |
}
|
|
136 |
|
|
137 |
/*!
|
99
|
138 |
Sets child id.
|
|
139 |
\param id id of the child.
|
|
140 |
*/
|
|
141 |
void CaQuery::setChildId(int id)
|
|
142 |
{
|
|
143 |
m_d->setChildId(id);
|
|
144 |
}
|
|
145 |
|
|
146 |
/*!
|
|
147 |
Returns child id.
|
|
148 |
\retval child id.
|
|
149 |
*/
|
|
150 |
int CaQuery::childId() const
|
|
151 |
{
|
|
152 |
return m_d->childId();
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
85
|
156 |
Sets names of entry types.
|
|
157 |
\param entryTypeNames list of entry type names (strings).
|
|
158 |
*/
|
|
159 |
void CaQuery::setEntryTypeNames(const QStringList &entryTypeNames)
|
|
160 |
{
|
|
161 |
m_d->setEntryTypeNames(entryTypeNames);
|
|
162 |
}
|
|
163 |
|
|
164 |
/*!
|
|
165 |
Returns a list of entry type names.
|
|
166 |
\retval list of names of entry types.
|
|
167 |
*/
|
|
168 |
QStringList CaQuery::entryTypeNames() const
|
|
169 |
{
|
|
170 |
return m_d->entryTypeNames();
|
|
171 |
}
|
|
172 |
|
|
173 |
/*!
|
|
174 |
Adds the next entry type name.
|
|
175 |
\param entryTypeName name of an entry type.
|
|
176 |
*/
|
|
177 |
void CaQuery::addEntryTypeName(const QString &entryTypeName)
|
|
178 |
{
|
|
179 |
m_d->addEntryTypeName(entryTypeName);
|
|
180 |
}
|
|
181 |
|
|
182 |
/*!
|
|
183 |
Sets flags which should be enabled.
|
|
184 |
\param onFlags flags.
|
|
185 |
*/
|
87
|
186 |
void CaQuery::setFlagsOn(const EntryFlags &onFlags)
|
85
|
187 |
{
|
|
188 |
m_d->setFlagsOn(onFlags);
|
|
189 |
}
|
|
190 |
|
|
191 |
/*!
|
|
192 |
Returns enabled flags.
|
|
193 |
\retval flags which should be enabled.
|
|
194 |
*/
|
|
195 |
EntryFlags CaQuery::flagsOn() const
|
|
196 |
{
|
|
197 |
return m_d->flagsOn();
|
|
198 |
}
|
|
199 |
|
|
200 |
/*!
|
|
201 |
Sets flags which should be disabled.
|
|
202 |
\param offFlags flags.
|
|
203 |
*/
|
87
|
204 |
void CaQuery::setFlagsOff(const EntryFlags &offFlags)
|
85
|
205 |
{
|
|
206 |
m_d->setFlagsOff(offFlags);
|
|
207 |
}
|
|
208 |
|
|
209 |
/*!
|
|
210 |
Returns disabled flags.
|
|
211 |
\retval flags which should be disabled.
|
|
212 |
*/
|
|
213 |
EntryFlags CaQuery::flagsOff() const
|
|
214 |
{
|
|
215 |
return m_d->flagsOff();
|
|
216 |
}
|
|
217 |
|
|
218 |
/*!
|
|
219 |
Sets type of sorting.
|
|
220 |
\param sortAttribute enum describing what is taken into account to sort.
|
|
221 |
\param sortOrder sort order (ascending, descending).
|
|
222 |
*/
|
|
223 |
void CaQuery::setSort(SortAttribute sortAttribute, Qt::SortOrder sortOrder)
|
|
224 |
{
|
|
225 |
m_d->setSort(sortAttribute, sortOrder);
|
|
226 |
}
|
|
227 |
|
|
228 |
/*!
|
|
229 |
Gets type of sorting.
|
|
230 |
\param[out] sortAttribute enum describing what is taken into account to sort.
|
|
231 |
\param[out] sortOrder sort order (ascending, descending).
|
|
232 |
*/
|
87
|
233 |
void CaQuery::getSort(SortAttribute &sortAttribute,
|
|
234 |
Qt::SortOrder &sortOrder) const
|
85
|
235 |
{
|
|
236 |
m_d->getSort(sortAttribute, sortOrder);
|
|
237 |
}
|
|
238 |
|
|
239 |
/*!
|
|
240 |
Returns no of entries.
|
|
241 |
\retval no of entries.
|
|
242 |
*/
|
|
243 |
unsigned int CaQuery::count() const
|
|
244 |
{
|
|
245 |
return m_d->count();
|
|
246 |
}
|
|
247 |
|
|
248 |
/*!
|
|
249 |
Sets no of entries.
|
|
250 |
\param count no of entries.
|
|
251 |
*/
|
|
252 |
void CaQuery::setCount(unsigned int count)
|
|
253 |
{
|
|
254 |
m_d->setCount(count);
|
|
255 |
}
|
|
256 |
|
|
257 |
/*!
|
88
|
258 |
Returns query attributes.
|
|
259 |
\retval map of attributes indexed by their names.
|
|
260 |
*/
|
|
261 |
QMap<QString, QString> CaQuery::attributes() const
|
|
262 |
{
|
|
263 |
return m_d->attributes();
|
|
264 |
}
|
|
265 |
|
|
266 |
/*!
|
|
267 |
Returns an attribute
|
|
268 |
\param name name of an attribute
|
|
269 |
\retval value of attribute
|
|
270 |
*/
|
|
271 |
QString CaQuery::attribute(const QString &name) const
|
|
272 |
{
|
|
273 |
return m_d->attribute(name);
|
|
274 |
}
|
|
275 |
|
|
276 |
/*!
|
|
277 |
Sets attribute.
|
|
278 |
\param name name of an attribute.
|
|
279 |
\param value value of an attribute.
|
|
280 |
*/
|
|
281 |
void CaQuery::setAttribute(const QString &name, const QString &value)
|
|
282 |
{
|
|
283 |
m_d->setAttribute(name, value);
|
|
284 |
}
|
|
285 |
|
|
286 |
/*!
|
|
287 |
Removes attribute.
|
|
288 |
\param name name of an attribute.
|
|
289 |
*/
|
|
290 |
void CaQuery::removeAttribute(const QString &name)
|
|
291 |
{
|
|
292 |
m_d->removeAttribute(name);
|
|
293 |
}
|
|
294 |
|
|
295 |
/*!
|
85
|
296 |
Clears query (restores the initial state).
|
|
297 |
*/
|
|
298 |
void CaQuery::clear()
|
|
299 |
{
|
|
300 |
m_d->clear();
|
|
301 |
}
|
|
302 |
|
|
303 |
/*!
|
|
304 |
Constructor.
|
|
305 |
\param queryPublic reference to CaQuery.
|
|
306 |
*/
|
|
307 |
CaQueryPrivate::CaQueryPrivate(CaQuery *queryPublic) :
|
|
308 |
m_q(queryPublic), mEntryRoles(ItemEntryRole | GroupEntryRole),
|
99
|
309 |
mParentId(0), mChildId(0), mEntryTypeNames(), mFlagsOn(), mFlagsOff(),
|
85
|
310 |
mSortAttribute(DefaultSortAttribute),
|
88
|
311 |
mSortOrder(Qt::AscendingOrder), mCount(0), mAttributes()
|
85
|
312 |
{
|
|
313 |
}
|
|
314 |
|
|
315 |
/*!
|
|
316 |
Copy assignment operator.
|
|
317 |
\param queryPrivate const reference to CaQueryPrivate.
|
|
318 |
\retval reference to CaQueryPrivate.
|
|
319 |
*/
|
|
320 |
|
|
321 |
CaQueryPrivate &CaQueryPrivate::operator=(
|
|
322 |
const CaQueryPrivate &queryPrivate)
|
|
323 |
{
|
|
324 |
/*m_q is not changed*/
|
|
325 |
mEntryRoles = queryPrivate.mEntryRoles;
|
|
326 |
mParentId = queryPrivate.mParentId;
|
99
|
327 |
mChildId = queryPrivate.mChildId;
|
85
|
328 |
mEntryTypeNames = queryPrivate.mEntryTypeNames;
|
|
329 |
mFlagsOn = queryPrivate.mFlagsOn;
|
|
330 |
mFlagsOff = queryPrivate.mFlagsOff;
|
|
331 |
mSortAttribute = queryPrivate.mSortAttribute;
|
|
332 |
mSortOrder = queryPrivate.mSortOrder;
|
|
333 |
mCount = queryPrivate.mCount;
|
88
|
334 |
mAttributes = queryPrivate.mAttributes;
|
85
|
335 |
|
|
336 |
return *this;
|
|
337 |
}
|
|
338 |
|
|
339 |
/*!
|
|
340 |
Destructor.
|
|
341 |
*/
|
|
342 |
CaQueryPrivate::~CaQueryPrivate()
|
|
343 |
{
|
|
344 |
}
|
|
345 |
|
|
346 |
/*!
|
|
347 |
Returns an entry role.
|
|
348 |
\retval entry role.
|
|
349 |
*/
|
|
350 |
EntryRoles CaQueryPrivate::entryRoles() const
|
|
351 |
{
|
|
352 |
return mEntryRoles;
|
|
353 |
}
|
|
354 |
|
|
355 |
/*!
|
|
356 |
Sets entry roles.
|
|
357 |
\param entryRoles role of the entry.
|
|
358 |
*/
|
|
359 |
void CaQueryPrivate::setEntryRoles(EntryRoles entryRoles)
|
|
360 |
{
|
|
361 |
mEntryRoles = entryRoles;
|
|
362 |
}
|
|
363 |
|
|
364 |
/*!
|
|
365 |
Returns parent id.
|
|
366 |
\retval parent id.
|
|
367 |
*/
|
|
368 |
int CaQueryPrivate::parentId() const
|
|
369 |
{
|
|
370 |
return mParentId;
|
|
371 |
}
|
|
372 |
|
|
373 |
/*!
|
|
374 |
Sets parent id.
|
|
375 |
\param id id of the parent.
|
|
376 |
*/
|
|
377 |
void CaQueryPrivate::setParentId(int id)
|
|
378 |
{
|
|
379 |
mParentId = id;
|
|
380 |
}
|
|
381 |
|
|
382 |
/*!
|
99
|
383 |
Returns child id.
|
|
384 |
\retval child id.
|
|
385 |
*/
|
|
386 |
int CaQueryPrivate::childId() const
|
|
387 |
{
|
|
388 |
return mChildId;
|
|
389 |
}
|
|
390 |
|
|
391 |
/*!
|
|
392 |
Sets child id.
|
|
393 |
\param id id of the child.
|
|
394 |
*/
|
|
395 |
void CaQueryPrivate::setChildId(int id)
|
|
396 |
{
|
|
397 |
mChildId = id;
|
|
398 |
}
|
|
399 |
|
|
400 |
/*!
|
85
|
401 |
Returns a list of entry type names.
|
|
402 |
\retval list of names of entry types.
|
|
403 |
*/
|
|
404 |
QStringList CaQueryPrivate::entryTypeNames() const
|
|
405 |
{
|
|
406 |
return mEntryTypeNames;
|
|
407 |
}
|
|
408 |
|
|
409 |
/*!
|
|
410 |
Sets names of entry types.
|
|
411 |
\param entryTypeNames list of entry type names (strings).
|
|
412 |
*/
|
|
413 |
void CaQueryPrivate::setEntryTypeNames(const QStringList &entryTypeNames)
|
|
414 |
{
|
|
415 |
mEntryTypeNames = entryTypeNames;
|
|
416 |
}
|
|
417 |
|
|
418 |
/*!
|
|
419 |
Adds the next entry type name.
|
|
420 |
\param entryTypeName name of an entry type.
|
|
421 |
*/
|
|
422 |
void CaQueryPrivate::addEntryTypeName(const QString &entryTypeName)
|
|
423 |
{
|
|
424 |
mEntryTypeNames << entryTypeName;
|
|
425 |
}
|
|
426 |
|
|
427 |
/*!
|
|
428 |
Sets flags which should be enabled.
|
|
429 |
\param onFlags flags.
|
|
430 |
*/
|
87
|
431 |
void CaQueryPrivate::setFlagsOn(const EntryFlags &onFlags)
|
85
|
432 |
{
|
|
433 |
mFlagsOn = onFlags;
|
|
434 |
}
|
|
435 |
|
|
436 |
/*!
|
|
437 |
Returns enabled flags.
|
|
438 |
\retval flags which should be enabled.
|
|
439 |
*/
|
|
440 |
EntryFlags CaQueryPrivate::flagsOn() const
|
|
441 |
{
|
|
442 |
return mFlagsOn;
|
|
443 |
}
|
|
444 |
|
|
445 |
/*!
|
|
446 |
Sets flags which should be disabled.
|
|
447 |
\param offFlags flags.
|
|
448 |
*/
|
87
|
449 |
void CaQueryPrivate::setFlagsOff(const EntryFlags &offFlags)
|
85
|
450 |
{
|
|
451 |
mFlagsOff = offFlags;
|
|
452 |
}
|
|
453 |
|
|
454 |
/*!
|
|
455 |
Returns disabled flags.
|
|
456 |
\retval flags which should be disabled.
|
|
457 |
*/
|
|
458 |
EntryFlags CaQueryPrivate::flagsOff() const
|
|
459 |
{
|
|
460 |
return mFlagsOff;
|
|
461 |
}
|
|
462 |
|
|
463 |
/*!
|
|
464 |
Gets type of sorting.
|
|
465 |
\param[out] sortAttribute enum describing what is taken into account to sort.
|
|
466 |
\param[out] sortOrder sort order (ascending, descending).
|
|
467 |
*/
|
|
468 |
void CaQueryPrivate::getSort(SortAttribute &sortAttribute,
|
87
|
469 |
Qt::SortOrder &sortOrder) const
|
85
|
470 |
{
|
|
471 |
sortAttribute = mSortAttribute;
|
|
472 |
sortOrder = mSortOrder;
|
|
473 |
}
|
|
474 |
|
|
475 |
/*!
|
|
476 |
Sets type of sorting.
|
|
477 |
\param sortAttribute enum describing what is taken into account to sort.
|
|
478 |
\param sortOrder sort order (ascending, descending).
|
|
479 |
*/
|
|
480 |
void CaQueryPrivate::setSort(SortAttribute sortAttribute,
|
87
|
481 |
Qt::SortOrder sortOrder)
|
85
|
482 |
{
|
|
483 |
mSortAttribute = sortAttribute;
|
|
484 |
mSortOrder = sortOrder;
|
|
485 |
}
|
|
486 |
|
|
487 |
/*!
|
|
488 |
Returns no of entries.
|
|
489 |
\retval no of entries.
|
|
490 |
*/
|
|
491 |
unsigned int CaQueryPrivate::count() const
|
|
492 |
{
|
|
493 |
return mCount;
|
|
494 |
}
|
|
495 |
|
|
496 |
/*!
|
|
497 |
Sets no of entries.
|
|
498 |
\param count no of entries.
|
|
499 |
*/
|
|
500 |
void CaQueryPrivate::setCount(unsigned int count)
|
|
501 |
{
|
|
502 |
mCount = count;
|
|
503 |
}
|
|
504 |
|
|
505 |
/*!
|
88
|
506 |
\retval map of attributes indexed by their names
|
|
507 |
*/
|
|
508 |
QMap<QString, QString> CaQueryPrivate::attributes() const
|
|
509 |
{
|
|
510 |
return mAttributes;
|
|
511 |
}
|
|
512 |
|
|
513 |
/*!
|
|
514 |
\param name name of an attribute
|
|
515 |
\retval value of attribute
|
|
516 |
*/
|
|
517 |
QString CaQueryPrivate::attribute(const QString &name) const
|
|
518 |
{
|
|
519 |
return mAttributes.value(name);
|
|
520 |
}
|
|
521 |
|
|
522 |
/*!
|
|
523 |
Sets attribute.
|
|
524 |
\param name name of an attribute.
|
|
525 |
\param value value of an attribute.
|
|
526 |
*/
|
|
527 |
void CaQueryPrivate::setAttribute(const QString &name, const QString &value)
|
|
528 |
{
|
|
529 |
mAttributes.insert(name, value);
|
|
530 |
}
|
|
531 |
|
|
532 |
/*!
|
|
533 |
Removes an attribute.
|
|
534 |
\param name name of an attribute.
|
|
535 |
*/
|
|
536 |
void CaQueryPrivate::removeAttribute(const QString &name)
|
|
537 |
{
|
|
538 |
mAttributes.remove(name);
|
|
539 |
}
|
|
540 |
|
|
541 |
/*!
|
85
|
542 |
Clears query (restores the initial state).
|
|
543 |
*/
|
|
544 |
void CaQueryPrivate::clear()
|
|
545 |
{
|
|
546 |
mEntryRoles = ItemEntryRole | GroupEntryRole;
|
|
547 |
mParentId = 0;
|
99
|
548 |
mChildId = 0;
|
85
|
549 |
mEntryTypeNames = QStringList();
|
|
550 |
mFlagsOn = EntryFlags();
|
|
551 |
mFlagsOff = EntryFlags();
|
|
552 |
mSortAttribute = DefaultSortAttribute;
|
|
553 |
mSortOrder = Qt::AscendingOrder;
|
|
554 |
mCount = 0;
|
|
555 |
}
|