~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/imports/contacts/qdeclarativecontactfilter.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 QtQml 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 "qdeclarativecontactfilter_p.h"
 
43
 
 
44
QT_BEGIN_NAMESPACE_CONTACTS
 
45
 
 
46
/*!
 
47
   \qmltype Filter
 
48
    \instantiates QDeclarativeContactFilter
 
49
   \brief The Filter element is used as a property of ContactModel, to allow
 
50
   selection of contacts which have certain details or properties.
 
51
 
 
52
   \ingroup qml-contacts-main
 
53
   \inqmlmodule QtContacts 5.0
 
54
 
 
55
   This element is part of the \b{QtContacts} module.
 
56
 
 
57
   \sa QContactFilter
 
58
 */
 
59
 
 
60
 
 
61
/*!
 
62
  \qmlproperty enumeration Filter::type
 
63
 
 
64
  This property holds the type value of this filter. It can be one of:
 
65
 
 
66
  \list
 
67
  \li Filter.DefaultFilter - A filter which matches everything (default).
 
68
  \li Filter.InvalidFilter - An invalid filter which matches nothing.
 
69
  \li Filter.DetailFilter - A filter which matches contacts containing one or more details of a particular definition with a particular value.
 
70
  \li Filter.DetailRangeFilter - A filter which matches contacts containing one or more details of a particular definition whose values are within a particular range.
 
71
  \li Filter.ChangeLogFilter - A filter which matches contacts whose timestamps have been updated since some particular date and time.
 
72
  \li Filter.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.
 
73
  \li Filter.RelationshipFilter - A filter which matches contacts which participate in a particular type of relationship, or relationship with a specified contact.
 
74
  \li Filter.IntersectionFilter - A filter which matches all contacts that are matched by all filters it includes.
 
75
  \li Filter.UnionFilter - A filter which matches any contact that is matched by any of the filters it includes.
 
76
  \li Filter.IdFilter - A filter which matches any contact whose local id is contained in a particular list of contact local ids.
 
77
  \endlist
 
78
  */
 
79
 
 
80
/*!
 
81
   \qmltype ActionFilter
 
82
    \instantiates QDeclarativeContactActionFilter
 
83
   \brief The ActionFilter element provides a filter based around an action availability criterion.
 
84
 
 
85
   \ingroup qml-contacts-filters
 
86
   \inqmlmodule QtContacts 5.0
 
87
 
 
88
   This element is part of the \b{QtContacts} module.
 
89
 
 
90
   \sa QContactActionFilter
 
91
 */
 
92
 
 
93
/*!
 
94
  \qmlproperty string ActionFilter::actionName
 
95
 
 
96
  This property holds the action name criterion of the filter.
 
97
  */
 
98
 
 
99
/*!
 
100
   \qmltype ChangeLogFilter
 
101
    \instantiates QDeclarativeContactChangeLogFilter
 
102
   \brief The ChangeLogFilter element provides a filter based around a contact timestamp criterion.
 
103
 
 
104
   \ingroup qml-contacts-filters
 
105
   \inqmlmodule QtContacts 5.0
 
106
 
 
107
   This element is part of the \b{QtContacts} module.
 
108
 
 
109
   \sa QContactChangeLogFilter
 
110
 */
 
111
 
 
112
/*!
 
113
  \qmlproperty date ChangeLogFilter::since
 
114
 
 
115
  This property holds the date and time lower-bound criterion of the filter.The value can be one of:
 
116
  \list
 
117
  \li ChangeLogFilter.EventAdded
 
118
  \li ChangeLogFilter.EventChanged
 
119
  \li ChangeLogFilter.EventRemoved
 
120
  \endlist
 
121
  */
 
122
 
 
123
/*!
 
124
  \qmlproperty enumeration ChangeLogFilter::eventType
 
125
 
 
126
  This property holds the type of change that this filter will match against.
 
127
  */
 
128
 
 
129
/*!
 
130
   \qmltype DetailFilter
 
131
    \instantiates QDeclarativeContactDetailFilter
 
132
   \brief The DetailFilter element provides a filter based around a detail value criterion.
 
133
 
 
134
   \ingroup qml-contacts-filters
 
135
   \inqmlmodule QtContacts 5.0
 
136
 
 
137
   This element is part of the \b{QtContacts} module.
 
138
 
 
139
   \sa QContactDetailFilter
 
140
 */
 
141
 
 
142
/*!
 
143
  \qmlproperty enumeration DetailFilter::detail
 
144
 
 
145
  This property holds the detail type of which details will be matched to.
 
146
 
 
147
  \sa ContactDetail::type
 
148
  */
 
149
 
 
150
/*!
 
151
  \qmlproperty int DetailFilter::field
 
152
 
 
153
  This property holds the detail field type of which detail fields will be matched to.
 
154
  Detail field types are enumeration values defined in each detail elements.
 
155
 
 
156
  \sa Address
 
157
  \sa Anniversary
 
158
  \sa Avatar
 
159
  \sa Birthday
 
160
  \sa DisplayLabel
 
161
  \sa EmailAddress
 
162
  \sa Family
 
163
  \sa Favorite
 
164
  \sa Gender
 
165
  \sa GeoLocation
 
166
  \sa GlobalPresence
 
167
  \sa Guid
 
168
  \sa Name
 
169
  \sa Nickname
 
170
  \sa Note
 
171
  \sa OnlineAccount
 
172
  \sa Organization
 
173
  \sa PhoneNumber
 
174
  \sa Presence
 
175
  \sa Ringtone
 
176
  \sa SyncTarget
 
177
  \sa Tag
 
178
  \sa Timestamp
 
179
  \sa Url
 
180
  \sa Hobby
 
181
  */
 
182
 
 
183
/*!
 
184
  \qmlproperty variant DetailFilter::value
 
185
 
 
186
  This property holds the value criterion of the detail filter.
 
187
  */
 
188
 
 
189
/*!
 
190
  \qmlproperty enumeration DetailFilter::matchFlags
 
191
 
 
192
  This property holds the semantics of the value matching criterion. The valid match flags include:
 
193
  \list
 
194
  \li MatchExactly - Performs QVariant-based matching (default).
 
195
  \li MatchContains - The search term is contained in the item.
 
196
  \li MatchStartsWith - The search term matches the start of the item.
 
197
  \li MatchEndsWith - The search term matches the end of the item.
 
198
  \li MatchFixedString - Performs string-based matching. String-based comparisons are case-insensitive unless the \c MatchCaseSensitive flag is also specified.
 
199
  \li MatchCaseSensitive - The search is case sensitive.
 
200
  \endlist
 
201
  */
 
202
 
 
203
/*!
 
204
   \qmltype DetailRangeFilter
 
205
    \instantiates QDeclarativeContactDetailRangeFilter
 
206
   \brief The DetailRangeFilter element provides a filter based around a detail value range criterion.
 
207
 
 
208
 
 
209
   \ingroup qml-contacts-filters
 
210
   \inqmlmodule QtContacts 5.0
 
211
 
 
212
   This element is part of the \b{QtContacts} module.
 
213
 
 
214
   \sa QContactDetailRangeFilter
 
215
 */
 
216
 
 
217
/*!
 
218
  \qmlproperty enumeration DetailRangeFilter::detail
 
219
 
 
220
  This property holds the detail type of which details will be matched to.
 
221
 
 
222
  \sa ContactDetail::type
 
223
  \sa DetailFilter::detail
 
224
  */
 
225
 
 
226
/*!
 
227
  \qmlproperty int DetailRangeFilter::field
 
228
 
 
229
  This property holds the detail field type of which detail fields will be matched to.
 
230
  Detail field types are enumeration values defined in each detail elements.
 
231
 
 
232
  \sa DetailFilter::field
 
233
  */
 
234
/*!
 
235
  \qmlproperty variant DetailRangeFilter::min
 
236
 
 
237
  This property holds the lower bound of the value range criterion. By default, there is no lower bound.
 
238
  */
 
239
/*!
 
240
  \qmlproperty variant DetailRangeFilter::max
 
241
 
 
242
  This property holds the upper bound of the value range criterion. By default, there is no upper bound.
 
243
  */
 
244
 
 
245
/*!
 
246
  \qmlproperty enumeration DetailRangeFilter::matchFlags
 
247
 
 
248
  This property holds the match flags of the criterion, which define semantics such as case sensitivity, and exact matching.
 
249
 
 
250
  \sa DetailFilter::matchFlags
 
251
  */
 
252
 
 
253
/*!
 
254
  \qmlproperty enumeration DetailRangeFilter::rangeFlags
 
255
 
 
256
  This property holds a set of flags which defines the boundary condition semantics of the value range criterion.The valid range flags include:
 
257
    \list
 
258
    \li DetailRangeFilter.IncludeLower
 
259
    \li DetailRangeFilter.IncludeUpper
 
260
    \li DetailRangeFilter.ExcludeLower
 
261
    \li DetailRangeFilter.ExcludeUpper
 
262
    \endlist
 
263
  */
 
264
/*!
 
265
   \qmltype IntersectionFilter
 
266
    \instantiates QDeclarativeContactIntersectionFilter
 
267
   \brief The IntersectionFilter element provides a filter which intersects the results of other filters.
 
268
 
 
269
   \ingroup qml-contacts-filters
 
270
   \inqmlmodule QtContacts 5.0
 
271
 
 
272
   This element is part of the \b{QtContacts} module.
 
273
 
 
274
   \sa QContactIntersectionFilter
 
275
 */
 
276
 
 
277
/*!
 
278
  \qmlproperty list<Filter> IntersectionFilter::filters
 
279
 
 
280
  This property holds the list of filters which form the intersection filter.
 
281
  */
 
282
 
 
283
 
 
284
/*!
 
285
   \qmltype UnionFilter
 
286
    \instantiates QDeclarativeContactUnionFilter
 
287
   \brief The UnionFilter element provides a filter which unions the results of other filters.
 
288
 
 
289
   \ingroup qml-contacts-filters
 
290
   \inqmlmodule QtContacts 5.0
 
291
 
 
292
   This element is part of the \b{QtContacts} module.
 
293
 
 
294
   \sa QContactUnionFilter
 
295
 */
 
296
 
 
297
/*!
 
298
  \qmlproperty list<Filter> UnionFilter::filters
 
299
 
 
300
  This property holds the list of filters which form the union filter.
 
301
  */
 
302
 
 
303
/*!
 
304
   \qmltype IdFilter
 
305
    \instantiates QDeclarativeContactIdFilter
 
306
   \brief The IdFilter element provides a filter based around a list of contact ids.
 
307
 
 
308
   \ingroup qml-contacts-filters
 
309
   \inqmlmodule QtContacts 5.0
 
310
 
 
311
   This element is part of the \b{QtContacts} module.
 
312
 
 
313
   \sa QContactIdFilter
 
314
 */
 
315
 
 
316
/*!
 
317
  \qmlproperty list<string> IdFilter::ids
 
318
 
 
319
  This property holds the list of ids of contacts which match this filter.
 
320
  */
 
321
 
 
322
 
 
323
/*!
 
324
   \qmltype RelationshipFilter
 
325
    \instantiates QDeclarativeContactRelationshipFilter
 
326
   \brief The RelationshipFilter element provides a filter based around relationship criteria.
 
327
 
 
328
   \ingroup qml-contacts-filters
 
329
   \inqmlmodule QtContacts 5.0
 
330
 
 
331
 
 
332
   This element is part of the \b{QtContacts} module.
 
333
 
 
334
   \sa Relationship
 
335
   \sa RelationshipModel
 
336
   \sa QContactRelationshipFilter
 
337
   \sa QContactRelationship
 
338
 */
 
339
 
 
340
 
 
341
/*!
 
342
  \qmlproperty variant RelationshipFilter::relationshipType
 
343
 
 
344
  This property holds the type of relationship that a contact must have in order to match the filter.
 
345
 
 
346
  \sa Relationship::type
 
347
 */
 
348
 
 
349
/*!
 
350
  \qmlproperty int RelationshipFilter::relatedContactId
 
351
 
 
352
  This property holds the id of the contact with whom the tested contact must have a relationship in order for the tested contact to match this filter
 
353
  */
 
354
/*!
 
355
  \qmlproperty enumeration RelationshipFilter::relatedContactRole
 
356
 
 
357
  This property holds the role in the relationship with the tested contact that the related contact must play in order for the tested contact to match this filter.
 
358
  The role can be one of:
 
359
  \list
 
360
  \li Relationship.First - The contact is the first contact in the relationship.
 
361
  \li Relationship.Second - The contact is the second contact in the relationship.
 
362
  \li Relationship.Either - The contact is either the first or second contact in the relationship (default).
 
363
  \endlist
 
364
  */
 
365
 
 
366
/*!
 
367
   \qmltype InvalidFilter
 
368
    \instantiates QDeclarativeContactInvalidFilter
 
369
   \brief the InvalidFilter element provides a filter which will never match any contacts.
 
370
 
 
371
   \ingroup qml-contacts-filters
 
372
   \inqmlmodule QtContacts 5.0
 
373
 
 
374
   This element is part of the \b{QtContacts} module.
 
375
 
 
376
   \sa QContactInvalidFilter
 
377
 */
 
378
 
 
379
QQmlListProperty<QDeclarativeContactFilter> QDeclarativeContactCompoundFilter::filters()
 
380
{
 
381
    return QQmlListProperty<QDeclarativeContactFilter>(this,
 
382
                                                          0, // opaque data parameter
 
383
                                                          filters_append,
 
384
                                                          filters_count,
 
385
                                                          filters_at,
 
386
                                                          filters_clear);
 
387
}
 
388
 
 
389
void QDeclarativeContactCompoundFilter::filters_append(QQmlListProperty<QDeclarativeContactFilter>* prop, QDeclarativeContactFilter* filter)
 
390
{
 
391
    QDeclarativeContactCompoundFilter* compoundFilter = static_cast<QDeclarativeContactCompoundFilter*>(prop->object);
 
392
    compoundFilter->m_filters.append(filter);
 
393
    QObject::connect(filter, SIGNAL(filterChanged()), compoundFilter, SIGNAL(filterChanged()), Qt::UniqueConnection);
 
394
    emit compoundFilter->filterChanged();
 
395
}
 
396
 
 
397
int QDeclarativeContactCompoundFilter::filters_count(QQmlListProperty<QDeclarativeContactFilter>* prop)
 
398
{
 
399
    // The 'prop' is in a sense 'this' for this static function (as given in filters() function)
 
400
    return static_cast<QDeclarativeContactCompoundFilter*>(prop->object)->m_filters.count();
 
401
}
 
402
 
 
403
QDeclarativeContactFilter* QDeclarativeContactCompoundFilter::filters_at(QQmlListProperty<QDeclarativeContactFilter>* prop, int index)
 
404
{
 
405
    return static_cast<QDeclarativeContactCompoundFilter*>(prop->object)->m_filters.at(index);
 
406
}
 
407
 
 
408
void QDeclarativeContactCompoundFilter::filters_clear(QQmlListProperty<QDeclarativeContactFilter>* prop)
 
409
{
 
410
    QDeclarativeContactCompoundFilter* compoundFilter = static_cast<QDeclarativeContactCompoundFilter*>(prop->object);
 
411
    if (!compoundFilter->m_filters.isEmpty()) {
 
412
        foreach (QDeclarativeContactFilter* filter, compoundFilter->m_filters) {
 
413
            QObject::disconnect(filter, SIGNAL(filterChanged()), compoundFilter, SIGNAL(filterChanged()));
 
414
        }
 
415
        compoundFilter->m_filters.clear();
 
416
        emit compoundFilter->filterChanged();
 
417
    }
 
418
}
 
419
 
 
420
#include "moc_qdeclarativecontactfilter_p.cpp"
 
421
 
 
422
QT_END_NAMESPACE_CONTACTS