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 QtQml 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#ifndef QDECLARATIVECONTACTFILTER_P_H
35#define QDECLARATIVECONTACTFILTER_P_H
36
37#include <QtQml/qqml.h>
38
39#include <QtContacts/qcontactfilter.h>
40
41QTCONTACTS_USE_NAMESPACE
42
43QT_BEGIN_NAMESPACE
44
45class QDeclarativeContactFilter : public QObject
46{
47 Q_OBJECT
48 Q_PROPERTY(FilterType type READ type NOTIFY filterChanged)
49 Q_ENUMS(FilterType)
50 Q_FLAGS(MatchFlags)
51public:
52 QDeclarativeContactFilter(QObject *parent=0)
53 :QObject(parent)
54 {
55 //for grouped filter: intersect /union filters
56 if (parent && qobject_cast<QDeclarativeContactFilter*>(object: parent)) {
57 connect(sender: this, SIGNAL(filterChanged()), receiver: parent, SIGNAL(filterChanged()));
58 }
59 }
60
61 enum FilterType {
62 InvalidFilter = QContactFilter::InvalidFilter,
63 DetailFilter = QContactFilter::ContactDetailFilter,
64 DetailRangeFilter = QContactFilter::ContactDetailRangeFilter,
65 ChangeLogFilter = QContactFilter::ChangeLogFilter,
66 ActionFilter = QContactFilter::ActionFilter,
67 RelationshipFilter = QContactFilter::RelationshipFilter,
68 IntersectionFilter = QContactFilter::IntersectionFilter,
69 UnionFilter = QContactFilter::UnionFilter,
70 IdFilter = QContactFilter::IdFilter,
71 DefaultFilter = QContactFilter::DefaultFilter
72 };
73
74 FilterType type() const {
75 return static_cast<FilterType>(filter().type());
76 }
77
78 enum MatchFlag {
79 MatchExactly = QContactFilter::MatchExactly,
80 MatchContains = QContactFilter::MatchContains,
81 MatchStartsWith = QContactFilter::MatchStartsWith,
82 MatchEndsWith = QContactFilter::MatchEndsWith,
83 MatchFixedString = QContactFilter::MatchFixedString,
84 MatchCaseSensitive = QContactFilter::MatchCaseSensitive,
85 MatchPhoneNumber = QContactFilter::MatchPhoneNumber,
86 MatchKeypadCollation = QContactFilter::MatchKeypadCollation
87 };
88 Q_DECLARE_FLAGS(MatchFlags, MatchFlag)
89
90 virtual QContactFilter filter() const
91 {
92 return QContactFilter();
93 }
94
95signals:
96 void filterChanged();
97};
98
99class QDeclarativeContactCompoundFilter : public QDeclarativeContactFilter
100{
101 Q_OBJECT
102 Q_PROPERTY(QQmlListProperty<QDeclarativeContactFilter> filters READ filters)
103 Q_CLASSINFO("DefaultProperty", "filters")
104
105public:
106 explicit QDeclarativeContactCompoundFilter(QObject* parent = Q_NULLPTR) : QDeclarativeContactFilter(parent){}
107 virtual ~QDeclarativeContactCompoundFilter() {}
108 // 'READ' accessor for the filters, basically this is also a 'WRITE' accessor
109 // as per QQmlListProperty's design.
110 QQmlListProperty<QDeclarativeContactFilter> filters();
111
112 static void filters_append(QQmlListProperty<QDeclarativeContactFilter>* prop, QDeclarativeContactFilter* filter);
113 static int filters_count(QQmlListProperty<QDeclarativeContactFilter>* prop);
114 static QDeclarativeContactFilter* filters_at(QQmlListProperty<QDeclarativeContactFilter>* prop, int index);
115 static void filters_clear(QQmlListProperty<QDeclarativeContactFilter>* prop);
116
117protected:
118 QList<QDeclarativeContactFilter*> m_filters;
119};
120
121QT_END_NAMESPACE
122
123QML_DECLARE_TYPE(QDeclarativeContactFilter)
124QML_DECLARE_TYPE(QDeclarativeContactCompoundFilter)
125
126#endif // QDECLARATIVECONTACTFILTER_P_H
127

source code of qtpim/src/imports/contacts/qdeclarativecontactfilter_p.h