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 QDECLARATIVECONTACTADDRESS_H |
35 | #define QDECLARATIVECONTACTADDRESS_H |
36 | |
37 | #include <QtContacts/qcontactaddress.h> |
38 | |
39 | #include "qdeclarativecontactdetail_p.h" |
40 | |
41 | QTCONTACTS_USE_NAMESPACE |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | class QDeclarativeContactAddress : public QDeclarativeContactDetail |
46 | { |
47 | Q_OBJECT |
48 | |
49 | Q_PROPERTY(QString street READ street WRITE setStreet NOTIFY valueChanged) |
50 | Q_PROPERTY(QString locality READ locality WRITE setLocality NOTIFY valueChanged) |
51 | Q_PROPERTY(QString region READ region WRITE setRegion NOTIFY valueChanged) |
52 | Q_PROPERTY(QString postcode READ postcode WRITE setPostcode NOTIFY valueChanged) |
53 | Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY valueChanged) |
54 | Q_PROPERTY(QList<int> subTypes READ subTypes WRITE setSubTypes NOTIFY valueChanged) |
55 | Q_PROPERTY(QString postOfficeBox READ postOfficeBox WRITE setPostOfficeBox NOTIFY valueChanged) |
56 | Q_ENUMS(FieldType) |
57 | Q_ENUMS(AddressSubType) |
58 | public: |
59 | enum FieldType { |
60 | Street = QContactAddress::FieldStreet, |
61 | Locality = QContactAddress::FieldLocality, |
62 | Region = QContactAddress::FieldRegion, |
63 | Postcode = QContactAddress::FieldPostcode, |
64 | Country = QContactAddress::FieldCountry, |
65 | SubTypes = QContactAddress::FieldSubTypes, |
66 | PostOfficeBox = QContactAddress::FieldPostOfficeBox |
67 | }; |
68 | |
69 | enum AddressSubType { |
70 | Parcel = QContactAddress::SubTypeParcel, |
71 | Postal = QContactAddress::SubTypePostal, |
72 | Domestic = QContactAddress::SubTypeDomestic, |
73 | International = QContactAddress::SubTypeInternational |
74 | }; |
75 | |
76 | QDeclarativeContactAddress(QObject* parent = Q_NULLPTR) |
77 | :QDeclarativeContactDetail(parent) |
78 | { |
79 | setDetail(QContactAddress()); |
80 | connect(asender: this, SIGNAL(valueChanged()), SIGNAL(detailChanged())); |
81 | } |
82 | |
83 | DetailType detailType() const |
84 | { |
85 | return QDeclarativeContactDetail::Address; |
86 | } |
87 | |
88 | void setStreet(const QString& v) |
89 | { |
90 | if (!readOnly() && v != street()) { |
91 | detail().setValue(field: QContactAddress::FieldStreet, value: v); |
92 | emit valueChanged(); |
93 | } |
94 | } |
95 | QString street() const {return detail().value(field: QContactAddress::FieldStreet).toString();} |
96 | void setLocality(const QString& v) |
97 | { |
98 | if (!readOnly() && v != locality()) { |
99 | detail().setValue(field: QContactAddress::FieldLocality, value: v); |
100 | emit valueChanged(); |
101 | } |
102 | } |
103 | QString locality() const {return detail().value(field: QContactAddress::FieldLocality).toString();} |
104 | void setRegion(const QString& v) |
105 | { |
106 | if (!readOnly() && v != region()) { |
107 | detail().setValue(field: QContactAddress::FieldRegion, value: v); |
108 | emit valueChanged(); |
109 | } |
110 | } |
111 | QString region() const {return detail().value(field: QContactAddress::FieldRegion).toString();} |
112 | void setPostcode(const QString& v) |
113 | { |
114 | if (!readOnly() && v != postcode()) { |
115 | detail().setValue(field: QContactAddress::FieldPostcode, value: v); |
116 | emit valueChanged(); |
117 | } |
118 | } |
119 | QString postcode() const {return detail().value(field: QContactAddress::FieldPostcode).toString();} |
120 | void setCountry(const QString& v) |
121 | { |
122 | if (!readOnly() && v != country()) { |
123 | detail().setValue(field: QContactAddress::FieldCountry, value: v); |
124 | emit valueChanged(); |
125 | } |
126 | } |
127 | QString country() const {return detail().value(field: QContactAddress::FieldCountry).toString();} |
128 | void setPostOfficeBox(const QString& v) |
129 | { |
130 | if (!readOnly() && v != postOfficeBox()) { |
131 | detail().setValue(field: QContactAddress::FieldPostOfficeBox, value: v); |
132 | emit valueChanged(); |
133 | } |
134 | } |
135 | QString postOfficeBox() const {return detail().value(field: QContactAddress::FieldPostOfficeBox).toString();} |
136 | |
137 | void setSubTypes(const QList<int>& subTypes) |
138 | { |
139 | QList<int> oldList = detail().value< QList<int> >(field: QContactAddress::FieldSubTypes); |
140 | |
141 | if (!readOnly() && subTypes.toSet() != oldList.toSet()) { |
142 | detail().setValue(field: QContactAddress::FieldSubTypes, value: QVariant::fromValue(value: subTypes)); |
143 | emit valueChanged(); |
144 | } |
145 | } |
146 | |
147 | QList<int> subTypes() const |
148 | { |
149 | return detail().value< QList<int> >(field: QContactAddress::FieldSubTypes); |
150 | } |
151 | signals: |
152 | void valueChanged(); |
153 | }; |
154 | |
155 | QT_END_NAMESPACE |
156 | |
157 | QML_DECLARE_TYPE(QDeclarativeContactAddress) |
158 | |
159 | #endif // QDECLARATIVECONTACTADDRESS_H |
160 | |