summaryrefslogtreecommitdiffstats
path: root/src/imports/organizer/qdeclarativeorganizeritemfilter.cpp
blob: f3470240cf623e95b46a1f29dbdf75ff11e8c13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativeorganizeritemfilter_p.h"

QTORGANIZER_USE_NAMESPACE

QT_BEGIN_NAMESPACE

/*!
    \qmltype Filter
    \instantiates QDeclarativeOrganizerItemFilter
    \brief The Filter element is used to filter items made available through a backend.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-main
    \sa QOrganizerItemFilter
 */

/*!
  \qmlsignal QtOrganizer5::Filter::onFilterChanged()

  This signal is emitted, when any of the Filter's or child element's (like DetailFilter, CollectionFilter etc) properties have been changed.
 */

/*!
    \internal
 */
QDeclarativeOrganizerItemFilter::QDeclarativeOrganizerItemFilter(QObject *parent)
    : QObject(parent)
{
    //for grouped filter: intersect /union filters
    if (parent && qobject_cast<QDeclarativeOrganizerItemFilter *>(parent))
        connect(this, SIGNAL(filterChanged()), parent, SIGNAL(filterChanged()));
}

/*!
    \qmlproperty enumeration Filter::type

    This property holds the type value of this filter. It can be one of:
    \list
    \li Filter.DefaultFilter       A filter which matches everything (default).
    \li Filter.InvalidFilter       An invalid filter which matches nothing.
    \li Filter.IntersectionFilter  A filter which matches all organizer items that are matched by all
                                  filters it includes.
    \li Filter.UnionFilter         A filter which matches any organizer item that is matched by any
                                  of the filters it includes.
    \li Filter.CollectionFilter    A filter which matches any organizer item that is matched by collection.
    \li Filter.DetailFilter        A filter which matches organizer items containing exactly one given detail.
    \li Filter.DetailFieldFilter   A filter which matches organizer items containing one or more details
                                  of a particular type with a particular field having a particular value.
    \li Filter.DetailRangeFilter   A filter which matches organizer items containing one or more details
                                  of a particular type whose values are within a particular range.
    \li Filter.IdFilter            A filter which matches any organizer item whose ID is contained in
                                  a particular list of organizer item IDs.
    \endlist
 */
QDeclarativeOrganizerItemFilter::FilterType QDeclarativeOrganizerItemFilter::type() const
{
    return static_cast<QDeclarativeOrganizerItemFilter::FilterType>(filter().type());
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemFilter::filter() const
{
    return QOrganizerItemFilter();
}


/*!
    \qmltype InvalidFilter
    \instantiates QDeclarativeOrganizerItemInvalidFilter
    \brief the InvalidFilter element provides a filter which will never match any organizer items.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa QOrganizerItemInvalidFilter
 */

/*!
  \qmlsignal InvalidFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemInvalidFilter::QDeclarativeOrganizerItemInvalidFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemInvalidFilter::filter() const
{
    return QOrganizerItemInvalidFilter();
}


/*!
    \internal
 */
QDeclarativeOrganizerItemCompoundFilter::QDeclarativeOrganizerItemCompoundFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \internal
 */
QDeclarativeOrganizerItemCompoundFilter::~QDeclarativeOrganizerItemCompoundFilter()
{
}

/*!
    \internal
 */
QQmlListProperty<QDeclarativeOrganizerItemFilter> QDeclarativeOrganizerItemCompoundFilter::filters()
{
    return { this, nullptr, filters_append, filters_count, filters_at, filters_clear };
}

/*!
    \internal
 */
void QDeclarativeOrganizerItemCompoundFilter::filters_append(QQmlListProperty<QDeclarativeOrganizerItemFilter> *prop,
                                                             QDeclarativeOrganizerItemFilter *filter)
{
    QDeclarativeOrganizerItemCompoundFilter *compoundFilter = static_cast<QDeclarativeOrganizerItemCompoundFilter *>(prop->object);
    compoundFilter->m_filters.append(filter);
    QObject::connect(filter, SIGNAL(filterChanged()), compoundFilter, SIGNAL(valueChanged()));
    emit compoundFilter->valueChanged();
}

/*!
    \internal
 */
qsizetype QDeclarativeOrganizerItemCompoundFilter::filters_count(QQmlListProperty<QDeclarativeOrganizerItemFilter> *prop)
{
    return static_cast<QDeclarativeOrganizerItemCompoundFilter *>(prop->object)->m_filters.count();
}

/*!
    \internal
 */
QDeclarativeOrganizerItemFilter *QDeclarativeOrganizerItemCompoundFilter::filters_at(QQmlListProperty<QDeclarativeOrganizerItemFilter> *prop, qsizetype index)
{
    return static_cast<QDeclarativeOrganizerItemCompoundFilter *>(prop->object)->m_filters.at(index);
}

/*!
    \internal
 */
void QDeclarativeOrganizerItemCompoundFilter::filters_clear(QQmlListProperty<QDeclarativeOrganizerItemFilter> *prop)
{
    QDeclarativeOrganizerItemCompoundFilter *filter = static_cast<QDeclarativeOrganizerItemCompoundFilter *>(prop->object);
    if (!filter->m_filters.isEmpty()) {
        filter->m_filters.clear();
        emit filter->valueChanged();
    }
}


/*!
    \qmltype IntersectionFilter
    \instantiates QDeclarativeOrganizerItemIntersectionFilter
    \brief The IntersectionFilter element provides a filter which intersects the results of other filters.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa QOrganizerItemIntersectionFilter
 */

/*!
  \qmlsignal InvalidFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemIntersectionFilter::QDeclarativeOrganizerItemIntersectionFilter(QObject *parent)
    : QDeclarativeOrganizerItemCompoundFilter(parent)
{
}

/*!
    \qmlproperty list<filter> IntersectionFilter::filters

    This property holds the list of filters which form the intersection filter.
 */

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemIntersectionFilter::filter() const
{
    QList<QOrganizerItemFilter> filters;
    foreach (const QDeclarativeOrganizerItemFilter *filter, m_filters)
        filters << filter->filter();
    QOrganizerItemIntersectionFilter f;
    f.setFilters(filters);
    return f;
}


/*!
    \qmltype UnionFilter
    \instantiates QDeclarativeOrganizerItemUnionFilter
    \brief The UnionFilter element provides a filter which unions the results of other filters.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa QOrganizerItemUnionFilter
 */

/*!
  \qmlsignal UnionFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemUnionFilter::QDeclarativeOrganizerItemUnionFilter(QObject *parent)
    : QDeclarativeOrganizerItemCompoundFilter(parent)
{
}

/*!
    \qmlproperty list<filter> UnionFilter::filters

    This property holds the list of filters which form the union filter.
 */

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemUnionFilter::filter() const
{
    QList<QOrganizerItemFilter> filters;
    foreach (const QDeclarativeOrganizerItemFilter *filter, m_filters)
        filters << filter->filter();
    QOrganizerItemUnionFilter f;
    f.setFilters(filters);
    return f;
}


/*!
    \qmltype CollectionFilter
    \instantiates QDeclarativeOrganizerItemCollectionFilter
    \brief The CollectionFilter element provides a filter based around the collection one organizer
           item belongs to.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa Collection
 */

/*!
  \qmlsignal CollectionFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemCollectionFilter::QDeclarativeOrganizerItemCollectionFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \qmlproperty list<string> CollectionFilter::ids

    This property holds the list of IDs of organizer collections which the items should belong to.
 */
QStringList QDeclarativeOrganizerItemCollectionFilter::ids() const
{
    return m_ids;
}

void QDeclarativeOrganizerItemCollectionFilter::setIds(const QStringList &ids)
{
    foreach (const QString &id, ids) {
        if (!m_ids.contains(id)) {
            m_ids = ids;
            emit valueChanged();
            return;
        }
    }

    foreach (const QString &id, m_ids) {
        if (!ids.contains(id)) {
            m_ids = ids;
            emit valueChanged();
            return;
        }
    }
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemCollectionFilter::filter() const
{
    QOrganizerItemCollectionFilter f;
    QSet<QOrganizerCollectionId> ids;

    foreach (const QVariant &id, m_ids) {
        QOrganizerCollectionId cId = QOrganizerCollectionId::fromString(id.toString());
        if (!cId.isNull())
            ids << cId;
    }

    f.setCollectionIds(ids);
    return f;
}



/*!
    \qmltype DetailFilter
    \instantiates QDeclarativeOrganizerItemDetailFilter
    \brief The DetailFilter element provides a filter based around a detail value criterion.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters

    Simple example how to utilize DetailFilter element together with OrganizerModel and ListView elements:
    \code
    Rectangle {
        height: 400; width: 400;

        OrganizerModel{
            id: organizer
            startPeriod: "2009-01-01"
            endPeriod: "2012-12-31"
            filter: todoFilter
        }

        Type {
            id: typeDetailToMatch
            type: Type.Todo
        }

        DetailFilter {
            id: todoFilter
            detail: typeDetailToMatch
        }

        ListView {
            width: parent.width; height: parent.height;
            model: organizer.items
            delegate: Text {text: displayLabel}
        }
    }
    \endcode

    \sa QOrganizerItemDetailFilter
 */

/*!
  \qmlsignal DetailFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemDetailFilter::QDeclarativeOrganizerItemDetailFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
    , m_detail(0)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \qmlproperty Detail DetailFilter::detail

    This property holds the detail instance used by this filter for matching.
  */
QDeclarativeOrganizerItemDetail *QDeclarativeOrganizerItemDetailFilter::detail() const
{
    return m_detail;
}

void QDeclarativeOrganizerItemDetailFilter::setDetail(QDeclarativeOrganizerItemDetail *detail)
{
    if (m_detail != detail) {
        m_detail = detail;
        if (m_detail && m_detail->detail() != d.detail()) {
            d.setDetail(m_detail->detail());
            emit valueChanged();
        }
    }
}


/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemDetailFilter::filter() const
{
    return d;
}


/*!
    \qmltype DetailFieldFilter
    \instantiates QDeclarativeOrganizerItemDetailFieldFilter
    \brief The DetailFieldFilter element provides a filter based around a detail value criterion.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters

    Simple example how to utilize DetailFieldFilter element together with OrganizerModel and ListView elements:
    \code
    Rectangle {
        height: 400; width: 400;

        OrganizerModel{
            id: organizer
            startPeriod: "2009-01-01"
            endPeriod: "2012-12-31"
            filter: todoFilter
        }

        DetailFieldFilter {
            id: todoFilter
            detail: Detail.Type
            field: Type.FieldType
            value: Type.Todo
        }

        ListView {
            width: parent.width; height: parent.height;
            model: organizer.items
            delegate: Text {text: displayLabel}
        }
    }
    \endcode

    \sa QOrganizerItemDetailFieldFilter
 */

/*!
  \qmlsignal DetailFieldFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemDetailFieldFilter::QDeclarativeOrganizerItemDetailFieldFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \qmlproperty enum DetailFieldFilter::detail

    This property holds the detail type of which the detail filter will be matched to. The value
    shuold be the enumeration value of Detail::type.
  */
QDeclarativeOrganizerItemDetail::DetailType QDeclarativeOrganizerItemDetailFieldFilter::detail() const
{
    return static_cast<QDeclarativeOrganizerItemDetail::DetailType>(d.detailType());
}

void QDeclarativeOrganizerItemDetailFieldFilter::setDetail(QDeclarativeOrganizerItemDetail::DetailType detail)
{
    if (detail != static_cast<QDeclarativeOrganizerItemDetail::DetailType>(d.detailType())) {
        d.setDetail(static_cast<QOrganizerItemDetail::DetailType>(detail), d.detailField());
        emit valueChanged();
    }
}

/*!
    \qmlproperty enum DetailFieldFilter::field

    This property holds the detail field type of which the detail field filter will be matched to. The
    value should be the filld enumeration value defined in each detail element.

    \sa EventTime, JournalTime, TodoTime, TodoProgress, Reminder, AudibleReminder, VisualReminder,
        EmailReminder, Comment, Description, DisplayLabel, Guid, Location, Parent, Priority, Recurrence,
        Timestamp, ItemType, Tag
  */
int QDeclarativeOrganizerItemDetailFieldFilter::field() const
{
    return d.detailField();
}

void QDeclarativeOrganizerItemDetailFieldFilter::setField(int field)
{
    if (field != d.detailField()) {
        d.setDetail(d.detailType(), field);
        emit valueChanged();
    }
}

/*!
  \qmlproperty variant DetailFieldFilter::value

  This property holds the value criterion of the detail field filter.
  */
QVariant QDeclarativeOrganizerItemDetailFieldFilter::value() const
{
    return d.value();
}

void QDeclarativeOrganizerItemDetailFieldFilter::setValue(const QVariant &newValue)
{
    if (newValue != value()) {
        if (newValue.metaType().id() == QMetaType::QDateTime) {
            // handling dates and datetimes internally as UTC
            d.setValue(newValue.toDateTime().toUTC());
        } else {
            d.setValue(newValue);
        }
        emit valueChanged();
    }
}

/*!
  \qmlproperty enumeration DetailFieldFilter::matchFlags

  This property holds the semantics of the value matching criterion. The valid match flags include:
  \list
  \li MatchExactly - Performs QVariant-based matching (default).
  \li MatchContains - The search term is contained in the item.
  \li MatchStartsWith - The search term matches the start of the item.
  \li MatchEndsWith - The search term matches the end of the item.
  \li MatchFixedString - Performs string-based matching. String-based comparisons are case-insensitive unless the \c MatchCaseSensitive flag is also specified.
  \li MatchCaseSensitive - The search is case sensitive.
  \endlist
 */
QDeclarativeOrganizerItemFilter::MatchFlags QDeclarativeOrganizerItemDetailFieldFilter::matchFlags() const
{
    QDeclarativeOrganizerItemFilter::MatchFlags newFlags;
    newFlags = ~newFlags & (int)d.matchFlags();
    return newFlags;
}

void QDeclarativeOrganizerItemDetailFieldFilter::setMatchFlags(QDeclarativeOrganizerItemFilter::MatchFlags flags)
{
    QOrganizerItemFilter::MatchFlags newFlags;
    newFlags = ~newFlags & (int)flags;
    if (newFlags != d.matchFlags()) {
        d.setMatchFlags(newFlags);
        emit valueChanged();
    }
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemDetailFieldFilter::filter() const
{
    return d;
}


/*!
    \qmltype DetailRangeFilter
    \instantiates QDeclarativeOrganizerItemDetailRangeFilter
    \brief The DetailRangeFilter element provides a filter based around a detail value range criterion.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa QOrganizerItemDetailRangeFilter
 */

/*!
  \qmlsignal DetailRangeFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemDetailRangeFilter::QDeclarativeOrganizerItemDetailRangeFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \qmlproperty enum DetailRangeFilter::detail

    This property holds the detail type of which the detail filter will be matched to. The value
    shuold be the enumeration value of Detail::type.
  */
QDeclarativeOrganizerItemDetail::DetailType QDeclarativeOrganizerItemDetailRangeFilter::detail() const
{
    return static_cast<QDeclarativeOrganizerItemDetail::DetailType>(d.detailType());
}

void QDeclarativeOrganizerItemDetailRangeFilter::setDetail(QDeclarativeOrganizerItemDetail::DetailType detail)
{
    if (detail != static_cast<QDeclarativeOrganizerItemDetail::DetailType>(d.detailType())) {
        d.setDetail(static_cast<QOrganizerItemDetail::DetailType>(detail), d.detailField());
        emit valueChanged();
    }
}

/*!
    \qmlproperty enum DetailRangeFilter::field

    This property holds the detail field type of which the detail filter will be matched to. The
    value should be the filld enumeration value defined in each detail element.

    \sa EventTime, JournalTime, TodoTime, TodoProgress, Reminder, AudibleReminder, VisualReminder,
        EmailReminder, Comment, Description, DisplayLabel, Guid, Location, Parent, Priority, Recurrence,
        Timestamp, ItemType, Tag
  */
int QDeclarativeOrganizerItemDetailRangeFilter::field() const
{
    return d.detailField();
}

void QDeclarativeOrganizerItemDetailRangeFilter::setField(int field)
{
    if (field != d.detailField()) {
        d.setDetail(d.detailType(), field);
        emit valueChanged();
    }
}


/*!
  \qmlproperty variant DetailRangeFilter::min

  This property holds the lower bound of the value range criterion. By default, there is no lower bound.
  */
void QDeclarativeOrganizerItemDetailRangeFilter::setMinValue(const QVariant &value)
{
    if (value != d.minValue()) {
        d.setRange(value, d.maxValue(), d.rangeFlags());
        emit valueChanged();
    }
}

QVariant QDeclarativeOrganizerItemDetailRangeFilter::minValue() const
{
    return d.minValue();
}

/*!
  \qmlproperty variant DetailRangeFilter::max

  This property holds the upper bound of the value range criterion. By default, there is no upper bound.
  */
void QDeclarativeOrganizerItemDetailRangeFilter::setMaxValue(const QVariant &value)
{
    if (value != d.maxValue()) {
        d.setRange(d.minValue(), value, d.rangeFlags());
        emit valueChanged();
    }
}

QVariant QDeclarativeOrganizerItemDetailRangeFilter::maxValue() const
{
    return d.maxValue();
}

/*!
  \qmlproperty enumeration DetailRangeFilter::matchFlags

  This property holds the match flags of the criterion, which define semantics such as case sensitivity, and exact matching.
  \sa DetailFieldFilter::matchFlags
  */
void QDeclarativeOrganizerItemDetailRangeFilter::setMatchFlags(QDeclarativeOrganizerItemFilter::MatchFlags flags)
{
    QOrganizerItemFilter::MatchFlags newFlags;
    newFlags = ~newFlags & (int)flags;
    if (newFlags != d.matchFlags()) {
        d.setMatchFlags(newFlags);
        emit valueChanged();
    }
}

QDeclarativeOrganizerItemFilter::MatchFlags QDeclarativeOrganizerItemDetailRangeFilter::matchFlags() const
{
    QDeclarativeOrganizerItemFilter::MatchFlags newFlags;
    newFlags = ~newFlags & (int)d.matchFlags();
    return newFlags;
}

/*!
  \qmlproperty enumeration DetailRangeFilter::rangeFlags

  This property holds a set of flags which defines the boundary condition semantics of the value range criterion. The valid range flags include:
    \list
    \li DetailRangeFilter.IncludeLower
    \li DetailRangeFilter.IncludeUpper
    \li DetailRangeFilter.ExcludeLower
    \li DetailRangeFilter.ExcludeUpper
    \endlist
  */
void QDeclarativeOrganizerItemDetailRangeFilter::setRangeFlags(RangeFlags flags)
{
    QOrganizerItemDetailRangeFilter::RangeFlags newFlags;
    newFlags = ~newFlags & (int)flags;
    if (newFlags != d.rangeFlags()) {
        d.setRange(d.minValue(), d.maxValue(), newFlags);
        emit valueChanged();
    }
}
QDeclarativeOrganizerItemDetailRangeFilter::RangeFlags QDeclarativeOrganizerItemDetailRangeFilter::rangeFlags() const
{
    QDeclarativeOrganizerItemDetailRangeFilter::RangeFlags newFlags;
    newFlags = ~newFlags & (int)d.rangeFlags();
    return newFlags;
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemDetailRangeFilter::filter() const
{
    return d;
}


/*!
    \qmltype IdFilter
    \instantiates QDeclarativeOrganizerItemIdFilter
    \brief The IdFilter element provides a filter based around a list of organizer item IDs.
    \inqmlmodule QtOrganizer
    \ingroup qml-organizer-filters
    \sa {QOrganizerItemIdFilter}
 */

/*!
  \qmlsignal IdFilter::onFilterChanged()

  \sa QtOrganizer5::Filter::onFilterChanged
*/

/*!
    \internal
 */
QDeclarativeOrganizerItemIdFilter::QDeclarativeOrganizerItemIdFilter(QObject *parent)
    : QDeclarativeOrganizerItemFilter(parent)
{
    connect(this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
}

/*!
    \qmlproperty list<string> IdFilter::ids

    This property holds the list of IDs of organizer items which match this filter.
 */
QStringList QDeclarativeOrganizerItemIdFilter::ids() const
{
    return m_ids;
}

void QDeclarativeOrganizerItemIdFilter::setIds(const QStringList &ids)
{
    foreach (const QString& id, ids) {
        if (!m_ids.contains(id)) {
            m_ids = ids;
            emit valueChanged();
            return;
        }
    }

    foreach (const QString& id, m_ids) {
        if (!ids.contains(id)) {
            m_ids = ids;
            emit valueChanged();
        }
    }
}

/*!
    \internal
 */
QOrganizerItemFilter QDeclarativeOrganizerItemIdFilter::filter() const
{
    QOrganizerItemIdFilter f;
    QList<QOrganizerItemId> ids;
    foreach (const QString& id, m_ids) {
        QOrganizerItemId itemId = QOrganizerItemId::fromString(id);
        if (!itemId.isNull())
            ids << itemId;
    }

    f.setIds(ids);
    return f;
}

QT_END_NAMESPACE

#include "moc_qdeclarativeorganizeritemfilter_p.cpp"