1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #include "qdeclarativegalleryfilter.h" |
43 | |
44 | #include <qgalleryfilter.h> |
45 | |
46 | QT_BEGIN_NAMESPACE_DOCGALLERY |
47 | |
48 | void QDeclarativeGalleryValueFilter::setValue(const QVariant &value) |
49 | { |
50 | if (value != m_filter.value()) { |
51 | m_filter.setValue(value); |
52 | |
53 | emit valueChanged(); |
54 | emit filterChanged(); |
55 | } |
56 | } |
57 | void QDeclarativeGalleryValueFilter::setPropertyName(const QString &name) |
58 | { |
59 | if (name != m_filter.propertyName()) { |
60 | m_filter.setPropertyName(name); |
61 | |
62 | emit propertyNameChanged(); |
63 | emit filterChanged(); |
64 | } |
65 | } |
66 | |
67 | void QDeclarativeGalleryValueFilter::setNegated(bool negated) |
68 | { |
69 | if (negated != m_filter.isNegated()) { |
70 | m_filter.setNegated(negated); |
71 | |
72 | emit negatedChanged(); |
73 | emit filterChanged(); |
74 | } |
75 | } |
76 | |
77 | QGalleryFilter QDeclarativeGalleryValueFilter::filter() const |
78 | { |
79 | return m_filter; |
80 | } |
81 | |
82 | void QDeclarativeGalleryStringFilter::setPropertyName(const QString &name) |
83 | { |
84 | if (name != m_filter.propertyName()) { |
85 | m_filter.setPropertyName(name); |
86 | |
87 | emit propertyNameChanged(); |
88 | emit filterChanged(); |
89 | } |
90 | } |
91 | |
92 | void QDeclarativeGalleryStringFilter::setValue(const QString &value) |
93 | { |
94 | if (value != m_filter.value()) { |
95 | m_filter.setValue(value); |
96 | |
97 | emit valueChanged(); |
98 | emit filterChanged(); |
99 | } |
100 | } |
101 | |
102 | void QDeclarativeGalleryStringFilter::setNegated(bool negated) |
103 | { |
104 | if (negated != m_filter.isNegated()) { |
105 | m_filter.setNegated(negated); |
106 | |
107 | emit negatedChanged(); |
108 | emit filterChanged(); |
109 | } |
110 | } |
111 | |
112 | QGalleryFilter QDeclarativeGalleryStringFilter::filter() const |
113 | { |
114 | return m_filter; |
115 | } |
116 | |
117 | /*! |
118 | \qmltype GalleryEqualsFilter |
119 | \instantiates QDeclarativeGalleryEqualsFilter |
120 | |
121 | \brief The GalleryEqualsFilter element provides a filter which tests |
122 | if a meta-data property is equal to a value. |
123 | |
124 | \ingroup qml-gallery |
125 | \ingroup qml-gallery-filters |
126 | |
127 | This element is part of the \b {QtMobility.gallery 1.0} module. |
128 | |
129 | \qml |
130 | GalleryEqualsFilter { |
131 | property: "keywords" |
132 | value: "holiday" |
133 | } |
134 | \endqml |
135 | */ |
136 | |
137 | /*! |
138 | \qmlproperty string GalleryEqualsFilter::property |
139 | |
140 | This property holds the name of the property to filter against. |
141 | */ |
142 | |
143 | /*! |
144 | \qmlproperty variant GalleryEqualsFilter::value |
145 | |
146 | This property holds the value to filter using. |
147 | */ |
148 | |
149 | /*! |
150 | \qmlproperty bool GalleryEqualsFilter::negated |
151 | |
152 | This property holds whether the result of a filter should be negated. |
153 | */ |
154 | |
155 | QGalleryFilter QDeclarativeGalleryEqualsFilter::filter() const |
156 | { |
157 | if (m_filter.value().type() == QVariant::RegExp) { |
158 | QGalleryMetaDataFilter filter(m_filter); |
159 | |
160 | filter.setComparator(QGalleryFilter::RegExp); |
161 | |
162 | return filter; |
163 | } else { |
164 | return m_filter; |
165 | } |
166 | } |
167 | |
168 | /*! |
169 | \qmltype GalleryLessThanFilter |
170 | \instantiates QDeclarativeGalleryLessThanFilter |
171 | |
172 | \brief The GalleryLessThanFilter element provides a filter which tests |
173 | if a meta-data property is less than a value. |
174 | |
175 | \ingroup qml-gallery |
176 | \ingroup qml-gallery-filters |
177 | |
178 | This element is part of the \b {QtMobility.gallery 1.0} module. |
179 | |
180 | \qml |
181 | GalleryLessThanFilter { |
182 | property: "lastAccessed" |
183 | value: 2008-01-01T00:00:00 |
184 | } |
185 | \endqml |
186 | */ |
187 | |
188 | /*! |
189 | \qmlproperty string GalleryLessThanFilter::property |
190 | |
191 | This property holds the name of the property to filter against. |
192 | */ |
193 | |
194 | /*! |
195 | \qmlproperty variant GalleryLessThanFilter::value |
196 | |
197 | This property holds the value to filter using. |
198 | */ |
199 | |
200 | /*! |
201 | \qmlproperty bool GalleryLessThanFilter::negated |
202 | |
203 | This property holds whether the result of a filter should be negated. |
204 | */ |
205 | |
206 | |
207 | /*! |
208 | \qmltype GalleryLessThanEqualsFilter |
209 | \instantiates QDeclarativeGalleryLessThanEqualsFilter |
210 | |
211 | \brief The GalleryLessThanEqualsFilter element provides a filter which tests |
212 | if a meta-data property is less than or equal to a value. |
213 | |
214 | \ingroup qml-gallery |
215 | \ingroup qml-gallery-filters |
216 | |
217 | This element is part of the \b {QtMobility.gallery 1.0} module. |
218 | |
219 | \qml |
220 | GalleryLessThanEqualsFilter { |
221 | property: "rating" |
222 | value: 3.5 |
223 | } |
224 | \endqml |
225 | */ |
226 | |
227 | /*! |
228 | \qmlproperty string GalleryLessThanEqualsFilter::property |
229 | |
230 | This property holds the name of the property to filter against. |
231 | */ |
232 | |
233 | /*! |
234 | \qmlproperty variant GalleryLessThanEqualsFilter::value |
235 | |
236 | This property holds the value to filter using. |
237 | */ |
238 | |
239 | /*! |
240 | \qmlproperty bool GalleryLessThanEqualsFilter::negated |
241 | |
242 | This property holds whether the result of a filter should be negated. |
243 | */ |
244 | |
245 | |
246 | /*! |
247 | \qmltype GalleryGreaterThanFilter |
248 | \instantiates QDeclarativeGalleryGreaterThanFilter |
249 | |
250 | \brief The GalleryGreaterThanFilter element provides a filter which tests |
251 | if a meta-data property is greater than a value. |
252 | |
253 | \ingroup qml-gallery |
254 | \ingroup qml-gallery-filters |
255 | |
256 | This element is part of the \b {QtMobility.gallery 1.0} module. |
257 | |
258 | \qml |
259 | GalleryGreaterThanFilter { |
260 | property: "rating" |
261 | value: 3.5 |
262 | } |
263 | \endqml |
264 | */ |
265 | |
266 | /*! |
267 | \qmlproperty string GalleryGreaterThanFilter::property |
268 | |
269 | This property holds the name of the property to filter against. |
270 | */ |
271 | |
272 | /*! |
273 | \qmlproperty variant GalleryGreaterThanFilter::value |
274 | |
275 | This property holds the value to filter using. |
276 | */ |
277 | |
278 | /*! |
279 | \qmlproperty bool GalleryGreaterThanFilter::negated |
280 | |
281 | This property holds whether the result of a filter should be negated. |
282 | */ |
283 | |
284 | /*! |
285 | \qmltype GalleryGreaterThanEqualsFilter |
286 | \instantiates QDeclarativeGalleryGreaterThanEqualsFilter |
287 | |
288 | \brief The GalleryGreaterThanEqualsFilter element provides a filter which |
289 | tests if a meta-data property is greater than or equal to a value. |
290 | |
291 | \ingroup qml-gallery |
292 | \ingroup qml-gallery-filters |
293 | |
294 | This element is part of the \b {QtMobility.gallery 1.0} module. |
295 | |
296 | \qml |
297 | GalleryGreaterThanEqualsFilter { |
298 | property: "lastAccessed" |
299 | value: 2008-01-01T00:00:00 |
300 | } |
301 | \endqml |
302 | */ |
303 | |
304 | /*! |
305 | \qmlproperty string GalleryGreaterThanEqualsFilter::property |
306 | |
307 | This property holds the name of the property to filter against. |
308 | */ |
309 | |
310 | /*! |
311 | \qmlproperty variant GalleryGreaterThanEqualsFilter::value |
312 | |
313 | This property holds the value to filter using. |
314 | */ |
315 | |
316 | /*! |
317 | \qmlproperty bool GalleryGreaterThanEqualsFilter::negated |
318 | |
319 | This property holds whether the result of a filter should be negated. |
320 | */ |
321 | |
322 | /*! |
323 | \qmltype GalleryContainsFilter |
324 | \instantiates QDeclarativeGalleryContainsFilter |
325 | |
326 | \brief The GalleryContainsFilter element provides a filter which tests if |
327 | a meta-data property contains a string. |
328 | |
329 | \ingroup qml-gallery |
330 | \ingroup qml-gallery-filters |
331 | |
332 | This element is part of the \b {QtMobility.gallery 1.0} module. |
333 | |
334 | \qml |
335 | GalleryContainsFilter { |
336 | property: "title" |
337 | value: "excellent" |
338 | } |
339 | \endqml |
340 | */ |
341 | |
342 | /*! |
343 | \qmlproperty string GalleryContainsFilter::property |
344 | |
345 | This property holds the name of the property to filter against. |
346 | */ |
347 | |
348 | /*! |
349 | \qmlproperty variant GalleryContainsFilter::value |
350 | |
351 | This property holds the value to filter using. |
352 | */ |
353 | |
354 | /*! |
355 | \qmlproperty bool GalleryContainsFilter::negated |
356 | |
357 | This property holds whether the result of a filter should be negated. |
358 | */ |
359 | |
360 | /*! |
361 | \qmltype GalleryStartsWithFilter |
362 | \instantiates QDeclarativeGalleryStartsWithFilter |
363 | |
364 | \brief The GalleryStartsWithFilter element provides a filter which tests if |
365 | a meta-data property starts with a string. |
366 | |
367 | \ingroup qml-gallery |
368 | \ingroup qml-gallery-filters |
369 | |
370 | This element is part of the \b {QtMobility.gallery 1.0} module. |
371 | |
372 | \qml |
373 | GalleryStartsWithFilter { |
374 | property: "title" |
375 | value: "the" |
376 | } |
377 | \endqml |
378 | */ |
379 | |
380 | /*! |
381 | \qmlproperty string GalleryStartsWithFilter::property |
382 | |
383 | This property holds the name of the property to filter against. |
384 | */ |
385 | |
386 | /*! |
387 | \qmlproperty variant GalleryStartsWithFilter::value |
388 | |
389 | This property holds the value to filter using. |
390 | */ |
391 | |
392 | /*! |
393 | \qmlproperty bool GalleryStartsWithFilter::negated |
394 | |
395 | This property holds whether the result of a filter should be negated. |
396 | */ |
397 | |
398 | /*! |
399 | \qmltype GalleryEndsWithFilter |
400 | \instantiates QDeclarativeGalleryEndsWithFilter |
401 | |
402 | \brief The GalleryEndsWithFilter element provides a filter which tests if a |
403 | meta-data property ends with a string. |
404 | |
405 | \ingroup qml-gallery |
406 | \ingroup qml-gallery-filters |
407 | |
408 | This element is part of the \b {QtMobility.gallery 1.0} module. |
409 | |
410 | \qml |
411 | GalleryEndsWithFilter { |
412 | property: "title" |
413 | value: ", the" |
414 | } |
415 | \endqml |
416 | */ |
417 | |
418 | /*! |
419 | \qmlproperty string GalleryEndsWithFilter::property |
420 | |
421 | This property holds the name of the property to filter against. |
422 | */ |
423 | |
424 | /*! |
425 | \qmlproperty variant GalleryEndsWithFilter::value |
426 | |
427 | This property holds the value to filter using. |
428 | */ |
429 | |
430 | /*! |
431 | \qmlproperty bool GalleryEndsWithFilter::negated |
432 | |
433 | This property holds whether the result of a filter should be negated. |
434 | */ |
435 | |
436 | /*! |
437 | \qmltype GalleryWildcardFilter |
438 | \instantiates QDeclarativeGalleryWildcardFilter |
439 | |
440 | \brief The GalleryWildcardFilter element provides a filter which tests a |
441 | meta-data property against a value using wildcard matching. |
442 | |
443 | \ingroup qml-gallery |
444 | \ingroup qml-gallery-filters |
445 | |
446 | This element is part of the \b {QtMobility.gallery 1.0} module. |
447 | |
448 | \qml |
449 | GalleryWildcardFilter { |
450 | property: "fileName" |
451 | value: "*.png" |
452 | } |
453 | \endqml |
454 | */ |
455 | |
456 | /*! |
457 | \qmlproperty string GalleryWildcardFilter::property |
458 | |
459 | This property holds the name of the property to filter against. |
460 | */ |
461 | |
462 | /*! |
463 | \qmlproperty variant GalleryWildcardFilter::value |
464 | |
465 | This property holds the value to filter using. |
466 | */ |
467 | |
468 | /*! |
469 | \qmlproperty bool GalleryWildcardFilter::negated |
470 | |
471 | This property holds whether the result of a filter should be negated. |
472 | */ |
473 | |
474 | |
475 | void QDeclarativeGalleryFilterGroup::classBegin() |
476 | { |
477 | } |
478 | |
479 | void QDeclarativeGalleryFilterGroup::componentComplete() |
480 | { |
481 | m_complete = true; |
482 | |
483 | typedef QList<QDeclarativeGalleryFilterBase *>::const_iterator iterator; |
484 | for (iterator it = m_filters.constBegin(), end = m_filters.constEnd(); it != end; ++it) |
485 | connect(sender: *it, SIGNAL(filterChanged()), receiver: this, SIGNAL(filterChanged())); |
486 | } |
487 | |
488 | QQmlListProperty<QDeclarativeGalleryFilterBase> QDeclarativeGalleryFilterGroup::filters() |
489 | { |
490 | return QQmlListProperty<QDeclarativeGalleryFilterBase>( |
491 | this, &m_filters, append, count, at, clear); |
492 | } |
493 | |
494 | void QDeclarativeGalleryFilterGroup::append( |
495 | QQmlListProperty<QDeclarativeGalleryFilterBase> *filters, |
496 | QDeclarativeGalleryFilterBase *filter) |
497 | { |
498 | QDeclarativeGalleryFilterGroup *filterGroup |
499 | = static_cast<QDeclarativeGalleryFilterGroup *>(filters->object); |
500 | |
501 | static_cast<QList<QDeclarativeGalleryFilterBase *>*>(filters->data)->append(t: filter); |
502 | |
503 | if (static_cast<QDeclarativeGalleryFilterGroup *>(filters->object)->m_complete) { |
504 | connect(sender: filter, SIGNAL(filterChanged()), receiver: filterGroup, SIGNAL(filterChanged())); |
505 | |
506 | emit filterGroup->filterChanged(); |
507 | } |
508 | } |
509 | |
510 | int QDeclarativeGalleryFilterGroup::count( |
511 | QQmlListProperty<QDeclarativeGalleryFilterBase> *filters) |
512 | { |
513 | return static_cast<QList<QDeclarativeGalleryFilterBase *>*>(filters->data)->count(); |
514 | } |
515 | |
516 | QDeclarativeGalleryFilterBase *QDeclarativeGalleryFilterGroup::at( |
517 | QQmlListProperty<QDeclarativeGalleryFilterBase> *filters, int index) |
518 | { |
519 | return static_cast<QList<QDeclarativeGalleryFilterBase *>*>(filters->data)->at(i: index); |
520 | } |
521 | |
522 | void QDeclarativeGalleryFilterGroup::clear( |
523 | QQmlListProperty<QDeclarativeGalleryFilterBase> *filters) |
524 | { |
525 | QDeclarativeGalleryFilterGroup *filterGroup |
526 | = static_cast<QDeclarativeGalleryFilterGroup *>(filters->object); |
527 | |
528 | QList<QDeclarativeGalleryFilterBase *> *list |
529 | = static_cast<QList<QDeclarativeGalleryFilterBase *>*>(filters->data); |
530 | |
531 | typedef QList<QDeclarativeGalleryFilterBase *>::const_iterator iterator; |
532 | for (iterator it = list->constBegin(), end = list->constEnd(); it != end; ++it) |
533 | disconnect(sender: *it, SIGNAL(filterChanged()), receiver: filterGroup, SIGNAL(filterChanged())); |
534 | |
535 | list->clear(); |
536 | |
537 | emit filterGroup->filterChanged(); |
538 | } |
539 | |
540 | /*! |
541 | \qmltype GalleryFilterUnion |
542 | \instantiates GalleryFilterUnion |
543 | |
544 | \brief The GalleryFilterUnion elements provides a union of gallery filters. |
545 | |
546 | \ingroup qml-gallery |
547 | \ingroup qml-gallery-filters |
548 | |
549 | This element is part of the \b {QtMobility.gallery 1.0} module. |
550 | */ |
551 | |
552 | /*! |
553 | \qmlproperty filterlist GalleryFilterUnion::filters |
554 | |
555 | This property holds the children of a union filter. |
556 | */ |
557 | |
558 | QGalleryFilter QDeclarativeGalleryFilterUnion::filter() const |
559 | { |
560 | QGalleryUnionFilter unionFilter; |
561 | |
562 | typedef QList<QDeclarativeGalleryFilterBase *>::const_iterator iterator; |
563 | for (iterator it = m_filters.begin(), end = m_filters.end(); it != end; ++it) { |
564 | QGalleryFilter filter = (*it)->filter(); |
565 | switch (filter.type()) { |
566 | case QGalleryFilter::MetaData: |
567 | unionFilter.append(filter: filter.toMetaDataFilter()); |
568 | break; |
569 | case QGalleryFilter::Union: |
570 | unionFilter.append(filter: filter.toUnionFilter()); |
571 | break; |
572 | case QGalleryFilter::Intersection: |
573 | unionFilter.append(filter: filter.toIntersectionFilter()); |
574 | break; |
575 | default: |
576 | break; |
577 | } |
578 | } |
579 | return unionFilter; |
580 | } |
581 | |
582 | /*! |
583 | \qmltype GalleryFilterIntersection |
584 | \instantiates GalleryFilterIntersection |
585 | |
586 | \brief The GalleryFilterIntersection elements provides a intersection of |
587 | gallery filters. |
588 | |
589 | \ingroup qml-gallery |
590 | \ingroup qml-gallery-filters |
591 | |
592 | This element is part of the \b {QtMobility.gallery 1.0} module. |
593 | */ |
594 | |
595 | /*! |
596 | \qmlproperty filterlist GalleryFilterIntersection::filters |
597 | |
598 | This property holds the children of a intersection filter. |
599 | */ |
600 | |
601 | QGalleryFilter QDeclarativeGalleryFilterIntersection::filter() const |
602 | { |
603 | QGalleryIntersectionFilter intersectionFilter; |
604 | |
605 | typedef QList<QDeclarativeGalleryFilterBase *>::const_iterator iterator; |
606 | for (iterator it = m_filters.begin(), end = m_filters.end(); it != end; ++it) { |
607 | QGalleryFilter filter = (*it)->filter(); |
608 | switch (filter.type()) { |
609 | case QGalleryFilter::MetaData: |
610 | intersectionFilter.append(filter: filter.toMetaDataFilter()); |
611 | break; |
612 | case QGalleryFilter::Union: |
613 | intersectionFilter.append(filter: filter.toUnionFilter()); |
614 | break; |
615 | case QGalleryFilter::Intersection: |
616 | intersectionFilter.append(filter: filter.toIntersectionFilter()); |
617 | break; |
618 | default: |
619 | break; |
620 | } |
621 | } |
622 | return intersectionFilter; |
623 | } |
624 | |
625 | #include "moc_qdeclarativegalleryfilter.cpp" |
626 | |
627 | QT_END_NAMESPACE_DOCGALLERY |
628 | |