1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtContacts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
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 The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qcontactdetailrangefilter.h"
35#include "qcontactdetailrangefilter_p.h"
36
37QT_BEGIN_NAMESPACE_CONTACTS
38
39/*!
40 \class QContactDetailRangeFilter
41 \brief The QContactDetailRangeFilter class provides a filter based around
42 a detail value range criterion.
43
44 \inmodule QtContacts
45
46 \ingroup contacts-filters
47
48 It may be used to select contacts which contain a detail of a particular type
49 with a particular value that lies in a range (either open or closed).
50 */
51
52Q_IMPLEMENT_CONTACTFILTER_PRIVATE(QContactDetailRangeFilter);
53
54/*!
55 * \fn QContactDetailRangeFilter::QContactDetailRangeFilter(const QContactFilter& other)
56 * Constructs a copy of \a other if possible, otherwise constructs a new detail range filter
57 */
58
59/*!
60 * \enum QContactDetailRangeFilter::RangeFlag
61 * Enumerates the semantics of the boundary conditions of the detail range filter
62 * \value IncludeLower The filter will match if the field value is equal to or greater than the minimum value
63 * \value IncludeUpper The filter will match if the field value is equal to or less than the maximum value
64 * \value ExcludeLower The filter will match if the field value is greater than the minimum value (but not equal)
65 * \value ExcludeUpper The filter will match if the field value is less than the maximum value (but not equal)
66 */
67
68/*!
69 * Constructs a new detail range filter
70 */
71QContactDetailRangeFilter::QContactDetailRangeFilter()
72 : QContactFilter(new QContactDetailRangeFilterPrivate)
73{
74}
75
76/*!
77 * Sets the value range criterion of the filter to within \a min and \a max, with boundary conditions specified in the given \a flags.
78 * If \a min or \a max is a null variant, that condition will not be checked. For example, to check for
79 * fields with a value greater than 7, you would specify:
80 * \code
81 * filter.setRange(7, QVariant(), QContactDetailRangeFilter::ExcludeLower);
82 * \endcode
83 * \sa minValue(), maxValue()
84 */
85void QContactDetailRangeFilter::setRange(const QVariant& min, const QVariant& max, RangeFlags flags)
86{
87 Q_D(QContactDetailRangeFilter);
88 d->m_minValue = min;
89 d->m_maxValue = max;
90 d->m_rangeflags = flags;
91}
92
93/*!
94 * Sets the match flags of the filter criterion to \a flags
95 *
96 * Not all flags are supported by a range filter. The supported flags include:
97 *
98 * \list
99 * \li QContactFilter::MatchExactly
100 * \li QContactFilter::MatchFixedString
101 * \li QContactFilter::MatchCaseSensitive
102 * \endlist
103 *
104 * Unsupported flags will be ignored.
105 *
106 * \sa matchFlags()
107 */
108void QContactDetailRangeFilter::setMatchFlags(QContactFilter::MatchFlags flags)
109{
110 Q_D(QContactDetailRangeFilter);
111 flags &= (QContactFilter::MatchExactly | QContactFilter::MatchFixedString | QContactFilter::MatchCaseSensitive);
112 d->m_flags = flags;
113}
114
115/*!
116 * Sets the type of detail which will be matched to \a type, and the field of the detail
117 * which will contain the value criterion to \a field.
118 *
119 * If \a type is QContactDetail::TypeUndefined, the detail filter will match no contacts. If \a field
120 * is not specified, or equal to -1, the detail filter acts like a "detail exists" filter; if any
121 * detail of the specified type is present in a contact, that contact will match the filter, regardless
122 * of what values might be stored in that detail.
123 *
124 * \sa detailType(), detailField()
125 */
126void QContactDetailRangeFilter::setDetailType(QContactDetail::DetailType type, int field)
127{
128 Q_D(QContactDetailRangeFilter);
129 d->m_typeId = type;
130 d->m_fieldId = field;
131}
132
133/*!
134 * Returns the match flags of the criterion, which define semantics such as case sensitivity, and exact matching.
135 * \sa setMatchFlags()
136 */
137QContactFilter::MatchFlags QContactDetailRangeFilter::matchFlags() const
138{
139 Q_D(const QContactDetailRangeFilter);
140 return d->m_flags;
141}
142
143/*!
144 * Returns the type of the details which will be inspected for matching values
145 * \sa setDetailType()
146 */
147QContactDetail::DetailType QContactDetailRangeFilter::detailType() const
148{
149 Q_D(const QContactDetailRangeFilter);
150 return d->m_typeId;
151}
152
153/*!
154 * Returns the detail field containinig the value which will be matched against the value criterion
155 * \sa setDetailType()
156 */
157int QContactDetailRangeFilter::detailField() const
158{
159 Q_D(const QContactDetailRangeFilter);
160 return d->m_fieldId;
161}
162
163/*!
164 * Returns the lower bound of the value range criterion.
165 * If this value is null, there is no lower bound.
166 * If it is valid, the \l rangeFlags() determines whether this value is included in the valid values.
167 * \sa setRange()
168 */
169QVariant QContactDetailRangeFilter::minValue() const
170{
171 Q_D(const QContactDetailRangeFilter);
172 return d->m_minValue;
173}
174
175/*!
176 * Returns the upper bound of the value range criterion
177 * If this value is null, there is no upper bound.
178 * If it is valid, the \l rangeFlags() determines whether this value is included in the valid values.
179 * \sa setRange()
180 */
181QVariant QContactDetailRangeFilter::maxValue() const
182{
183 Q_D(const QContactDetailRangeFilter);
184 return d->m_maxValue;
185}
186
187/*!
188 * Returns a set of flags which defines the boundary condition semantics of the value range criterion
189 * \sa setRange()
190 */
191QContactDetailRangeFilter::RangeFlags QContactDetailRangeFilter::rangeFlags() const
192{
193 Q_D(const QContactDetailRangeFilter);
194 return d->m_rangeflags;
195}
196
197QT_END_NAMESPACE_CONTACTS
198

source code of qtpim/src/contacts/filters/qcontactdetailrangefilter.cpp