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#ifndef QDECLARATIVECONTACTDETAILRANGEFILTER_H
35#define QDECLARATIVECONTACTDETAILRANGEFILTER_H
36
37#include <QtContacts/qcontactdetailrangefilter.h>
38
39#include "qdeclarativecontact_p.h"
40#include "qdeclarativecontactfilter_p.h"
41
42QTCONTACTS_USE_NAMESPACE
43
44QT_BEGIN_NAMESPACE
45
46class QDeclarativeContactDetailRangeFilter : public QDeclarativeContactFilter
47{
48 Q_OBJECT
49 Q_PROPERTY(QDeclarativeContactDetail::DetailType detail READ detail WRITE setDetail NOTIFY valueChanged)
50 Q_PROPERTY(int field READ field WRITE setField NOTIFY valueChanged)
51 Q_PROPERTY(QVariant min READ minValue WRITE setMinValue NOTIFY valueChanged)
52 Q_PROPERTY(QVariant max READ maxValue WRITE setMaxValue NOTIFY valueChanged)
53 Q_PROPERTY(MatchFlags matchFlags READ matchFlags WRITE setMatchFlags NOTIFY valueChanged)
54 Q_PROPERTY(RangeFlags rangeFlags READ rangeFlags WRITE setRangeFlags NOTIFY valueChanged)
55 Q_FLAGS(RangeFlags)
56public:
57 enum RangeFlag {
58 IncludeLower = QContactDetailRangeFilter::IncludeLower,
59 IncludeUpper = QContactDetailRangeFilter::IncludeUpper,
60 ExcludeLower = QContactDetailRangeFilter::ExcludeLower,
61 ExcludeUpper = QContactDetailRangeFilter::ExcludeUpper
62 };
63 Q_DECLARE_FLAGS(RangeFlags, RangeFlag)
64
65 QDeclarativeContactDetailRangeFilter(QObject* parent = Q_NULLPTR)
66 : QDeclarativeContactFilter(parent)
67 {
68 connect(asender: this, SIGNAL(valueChanged()), SIGNAL(filterChanged()));
69 }
70
71 void setDetail(QDeclarativeContactDetail::DetailType detail)
72 {
73 if (detail != static_cast<QDeclarativeContactDetail::DetailType>(d.detailType())) {
74 d.setDetailType(type: static_cast<QContactDetail::DetailType>(detail), field: d.detailField());
75 emit valueChanged();
76 }
77 }
78
79 QDeclarativeContactDetail::DetailType detail() const
80 {
81 return static_cast<QDeclarativeContactDetail::DetailType>(d.detailType());
82 }
83
84 void setField(int field)
85 {
86 if (field != d.detailField()) {
87 d.setDetailType(type: d.detailType(), field);
88 emit valueChanged();
89 }
90 }
91
92 int field() const
93 {
94 return d.detailField();
95 }
96
97 QDeclarativeContactFilter::MatchFlags matchFlags() const
98 {
99 QDeclarativeContactFilter::MatchFlags flags;
100 flags = ~flags & (int)d.matchFlags();
101 return flags;
102 }
103 void setMatchFlags(QDeclarativeContactFilter::MatchFlags flags)
104 {
105 QContactFilter::MatchFlags newFlags;
106 newFlags = ~newFlags & (int)flags;
107 if (newFlags != d.matchFlags()) {
108 d.setMatchFlags(newFlags);
109 emit valueChanged();
110 }
111 }
112
113 QDeclarativeContactDetailRangeFilter::RangeFlags rangeFlags() const
114 {
115 QDeclarativeContactDetailRangeFilter::RangeFlags flags;
116 flags = ~flags & (int)d.rangeFlags();
117 return flags;
118 }
119 void setRangeFlags(QDeclarativeContactDetailRangeFilter::RangeFlags flags)
120 {
121 QContactDetailRangeFilter::RangeFlags newFlags;
122 newFlags = ~newFlags & (int)flags;
123 if (newFlags != d.rangeFlags()) {
124 d.setRange(min: d.minValue(), max: d.maxValue(), flags: newFlags);
125 emit valueChanged();
126 }
127 }
128
129 QVariant minValue() const
130 {
131 return d.minValue();
132 }
133 void setMinValue(const QVariant& value)
134 {
135 if (value != d.minValue()) {
136 d.setRange(min: value, max: d.maxValue(), flags: d.rangeFlags());
137 emit valueChanged();
138 }
139 }
140
141 QVariant maxValue() const
142 {
143 return d.maxValue();
144 }
145 void setMaxValue(const QVariant& value)
146 {
147 if (value != d.maxValue()) {
148 d.setRange(min: d.minValue(), max: value, flags: d.rangeFlags());
149 emit valueChanged();
150 }
151 }
152
153 QContactFilter filter() const
154 {
155 return d;
156 }
157signals:
158 void valueChanged();
159
160
161private:
162 QContactDetailRangeFilter d;
163};
164
165QT_END_NAMESPACE
166
167QML_DECLARE_TYPE(QDeclarativeContactDetailRangeFilter)
168
169#endif // QDECLARATIVECONTACTDETAILRANGEFILTER_H
170

source code of qtpim/src/imports/contacts/filters/qdeclarativecontactdetailrangefilter_p.h