1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtContacts module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#include "qcontactfilter.h"
43
#include "qcontactfilter_p.h"
44
#include "qcontactfilters.h"
46
#include "qcontactintersectionfilter.h"
47
#include "qcontactunionfilter.h"
49
#include "qcontactmanager.h"
51
#ifndef QT_NO_DEBUG_STREAM
57
\brief The QContactFilter class is used to select contacts made available
58
through a QContactManager.
62
\ingroup contacts-main
64
This class is used as a parameter to various functions offered by QContactManager, to allow
65
selection of contacts which have certain details or properties.
69
\enum QContactFilter::FilterType
70
Describes the type of the filter
71
\value InvalidFilter An invalid filter which matches nothing
72
\value ContactDetailFilter A filter which matches contacts containing one or more details of a particular definition with a particular value
73
\value ContactDetailRangeFilter A filter which matches contacts containing one or more details of a particular definition whose values are within a particular range
74
\value ChangeLogFilter A filter which matches contacts whose timestamps have been updated since some particular date and time
75
\value ActionFilter A filter which matches contacts for which a particular action is available, or which contain a detail with a particular value for which a particular action is available
76
\value RelationshipFilter A filter which matches contacts which participate in a particular type of relationship, or relationship with a specified contact
77
\value IntersectionFilter A filter which matches all contacts that are matched by all filters it includes
78
\value UnionFilter A filter which matches any contact that is matched by any of the filters it includes
79
\value IdFilter A filter which matches any contact whose local id is contained in a particular list of contact local ids
80
\value DefaultFilter A filter which matches everything
84
\enum QContactFilter::MatchFlag
85
Describes the semantics of matching followed by the filter
86
\value MatchExactly Performs QVariant-based matching , combination of MatchExactly with other flags is not supported
87
\value MatchContains The search term is contained in the item
88
\value MatchStartsWith The search term matches the start of the item
89
\value MatchEndsWith The search term matches the end of the item
90
\value MatchFixedString Performs string-based matching. String-based comparisons are case-insensitive unless the \c MatchCaseSensitive flag is also specified
91
\value MatchCaseSensitive The search is case sensitive
92
\value MatchPhoneNumber The search term is considered to be in the form of a phone number, and special processing (removing dialing prefixes, non significant
93
characters like '-'. ')' etc). may be performed when matching the item.
94
\value MatchKeypadCollation The search term is in the form of text entered by a numeric phone keypad (such as ITU-T E.161 compliant keypads). Each digit in the
95
search term can represent a number of alphanumeric symbols. For example, the search string "43556" would match items "HELLO", "GEKKO", "HELL6" and "43556" among others.
96
Accented characters and other punctuation characters may additionally be matched by the QContactManager in a way consistent with the platform.
100
\fn QContactFilter::operator!=(const QContactFilter& other) const
101
Returns true if this filter is not identical to the \a other filter.
105
#if !defined(Q_CC_MWERKS)
106
template<> QTCONTACTS_PREPEND_NAMESPACE(QContactFilterPrivate) *QSharedDataPointer<QTCONTACTS_PREPEND_NAMESPACE(QContactFilterPrivate)>::clone()
112
QT_BEGIN_NAMESPACE_CONTACTS
114
/*! Constructs an empty filter */
115
QContactFilter::QContactFilter()
120
/*! Constructs a new copy of \a other */
121
QContactFilter::QContactFilter(const QContactFilter& other)
126
/*! Assigns this filter to be \a other
128
QContactFilter& QContactFilter::operator=(const QContactFilter& other)
130
if (this != &other) {
136
/*! Cleans up the memory used by this filter */
137
QContactFilter::~QContactFilter()
141
/*! Returns the type of the filter */
142
QContactFilter::FilterType QContactFilter::type() const
145
return QContactFilter::DefaultFilter;
146
return d_ptr->type();
149
/*! Returns true if the filter has the same type and criteria as \a other
151
bool QContactFilter::operator==(const QContactFilter& other) const
153
/* A default filter is only equal to other default filters */
157
/* Different types can't be equal */
158
if (other.type() != type())
161
/* Otherwise, use the virtual op == */
162
return d_ptr->compare(other.d_ptr);
165
#ifndef QT_NO_DATASTREAM
167
* Writes \a filter to the stream \a out.
169
QDataStream& operator<<(QDataStream& out, const QContactFilter& filter)
171
quint8 formatVersion = 1; // Version of QDataStream format for QContactDetailFilter
172
out << formatVersion << static_cast<quint32>(filter.type());
174
filter.d_ptr->outputToStream(out, formatVersion);
179
* Reads a contact filter from stream \a in into \a filter.
181
QDataStream& operator>>(QDataStream& in, QContactFilter& filter)
183
filter = QContactFilter();
184
quint8 formatVersion;
186
if (formatVersion == 1) {
190
case QContactFilter::InvalidFilter:
191
filter = QContactInvalidFilter();
193
case QContactFilter::ContactDetailFilter:
194
filter = QContactDetailFilter();
196
case QContactFilter::ContactDetailRangeFilter:
197
filter = QContactDetailRangeFilter();
199
case QContactFilter::ChangeLogFilter:
200
filter = QContactChangeLogFilter();
202
case QContactFilter::ActionFilter:
203
filter = QContactActionFilter();
205
case QContactFilter::RelationshipFilter:
206
filter = QContactRelationshipFilter();
208
case QContactFilter::IntersectionFilter:
209
filter = QContactIntersectionFilter();
211
case QContactFilter::UnionFilter:
212
filter = QContactUnionFilter();
214
case QContactFilter::IdFilter:
215
filter = QContactIdFilter();
217
case QContactFilter::DefaultFilter:
218
filter = QContactFilter();
222
filter.d_ptr->inputFromStream(in, formatVersion);
224
in.setStatus(QDataStream::ReadCorruptData);
231
#ifndef QT_NO_DEBUG_STREAM
233
Outputs \a filter to the debug stream \a dbg
235
QDebug operator<<(QDebug dbg, const QContactFilter& filter)
237
dbg.nospace() << "QContactFilter(";
239
filter.d_ptr->debugStreamOut(dbg);
241
dbg.nospace() << "(null)";
242
dbg.nospace() << ")";
243
return dbg.maybeSpace();
249
Constructs a new filter from the given data pointer \a d
251
QContactFilter::QContactFilter(QContactFilterPrivate *d)
258
\relates QContactFilter
259
Returns a filter which is the intersection of the \a left and \a right filters
260
\sa QContactIntersectionFilter
262
const QContactFilter operator&(const QContactFilter& left, const QContactFilter& right)
264
// XXX TODO: empty intersection/union operations are not well defined yet.
265
//if (left.type() == QContactFilter::Intersection) {
266
// QContactIntersectionFilter bf(left);
267
// /* we can just add the right to this one */
272
//if (right.type() == QContactFilter::Intersection) {
273
// QContactIntersectionFilter bf(right);
274
// /* we can prepend the left to this one */
279
/* usual fallback case */
280
QContactIntersectionFilter nif;
281
nif << left << right;
286
\relates QContactFilter
287
Returns a filter which is the union of the \a left and \a right filters
288
\sa QContactUnionFilter
290
const QContactFilter operator|(const QContactFilter& left, const QContactFilter& right)
292
if (left.type() == QContactFilter::UnionFilter) {
293
QContactUnionFilter bf(left);
294
/* we can just add the right to this one */
299
if (right.type() == QContactFilter::UnionFilter) {
300
QContactUnionFilter bf(right);
301
/* we can prepend the left to this one */
306
/* usual fallback case */
307
QContactUnionFilter nif;
308
nif << left << right;
311
QT_END_NAMESPACE_CONTACTS