~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/imports/contacts/filters/qdeclarativecontactdetailrangefilter_p.h

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