Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdeclarativegeoaddress.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7
8/*!
9 \qmltype Address
10 \inqmlmodule QtPositioning
11 \since 5.2
12
13 \brief The Address QML type represents a specific location as a street address.
14
15 An Address is used as a unit of data for queries such as (Reverse) Geocoding
16 or Places searches -- many of these operations either accept an Address
17 or return one.
18
19 Not all properties of an Address are necessarily available or relevant
20 in all parts of the world and all locales. The \l district, \l state and
21 \l county properties are particularly area-specific for many data sources,
22 and often only one or two of these are available or useful.
23
24 The Address has a \l text property which holds a formatted string. It
25 is the recommended way to display an address to the user and typically
26 takes the format of an address as found on an envelope, but this is not always
27 the case. The \l text may be automatically generated from constituent
28 address properties such as \l street, \l city and and so on, but can also
29 be explicitly assigned. See \l text for details.
30
31 \section2 Example Usage
32
33 The following code snippet shows the declaration of an Address object.
34
35 \code
36 Address {
37 id: address
38 street: "53 Brandl St"
39 city: "Eight Mile Plains"
40 country: "Australia"
41 countryCode: "AUS"
42 }
43 \endcode
44
45 This could then be used, for example, as the value of a geocoding query,
46 to get an exact longitude and latitude for the address.
47
48 \sa {QGeoAddress}
49*/
50
51QDeclarativeGeoAddress::QDeclarativeGeoAddress(QObject *parent) :
52 QObject(parent)
53{
54}
55
56QDeclarativeGeoAddress::QDeclarativeGeoAddress(const QGeoAddress &address, QObject *parent) :
57 QObject(parent), m_address(address)
58{
59}
60
61/*!
62 \qmlproperty QGeoAddress QtPositioning::Address::address
63
64 For details on how to use this property to interface between C++ and QML see
65 "\l {Address - QGeoAddress} {Interfaces between C++ and QML Code}".
66*/
67QGeoAddress QDeclarativeGeoAddress::address() const
68{
69 return m_address;
70}
71
72void QDeclarativeGeoAddress::setAddress(const QGeoAddress &address)
73{
74 // Elaborate but takes care of emiting needed signals
75 setText(address.text());
76 setCountry(address.country());
77 setCountryCode(address.countryCode());
78 setState(address.state());
79 setCounty(address.county());
80 setCity(address.city());
81 setDistrict(address.district());
82 setStreet(address.street());
83 setStreetNumber(address.streetNumber());
84 setPostalCode(address.postalCode());
85 m_address = address;
86}
87
88/*!
89 \qmlproperty string QtPositioning::Address::text
90
91 This property holds the address as a single formatted string. It is the recommended
92 string to use to display the address to the user. It typically takes the format of
93 an address as found on an envelope, but this is not always necessarily the case.
94
95 The address \c text is either automatically generated or explicitly assigned,
96 this can be determined by checking \l isTextGenerated.
97
98 If an empty string is assigned to \c text, then \l isTextGenerated will be set
99 to true and \c text will return a string which is locally formatted according to
100 \l countryCode and based on the properties of the address. Modifying the address
101 properties such as \l street, \l city and so on may cause the contents of \c text to
102 change.
103
104 If a non-empty string is assigned to \c text, then \l isTextGenerated will be
105 set to false and \c text will always return the explicitly assigned string.
106 Modifying address properties will not affect the \c text property.
107*/
108QString QDeclarativeGeoAddress::text() const
109{
110 return m_address.text();
111}
112
113void QDeclarativeGeoAddress::setText(const QString &address)
114{
115 QString oldText = m_address.text();
116 bool oldIsTextGenerated = m_address.isTextGenerated();
117 m_address.setText(address);
118
119 if (oldText != m_address.text())
120 emit textChanged();
121 if (oldIsTextGenerated != m_address.isTextGenerated())
122 emit isTextGeneratedChanged();
123}
124
125/*!
126 \qmlproperty string QtPositioning::Address::country
127
128 This property holds the country of the address as a single formatted string.
129*/
130QString QDeclarativeGeoAddress::country() const
131{
132 return m_address.country();
133}
134
135void QDeclarativeGeoAddress::setCountry(const QString &country)
136{
137 if (m_address.country() == country)
138 return;
139 QString oldText = m_address.text();
140 m_address.setCountry(country);
141 emit countryChanged();
142
143 if (m_address.isTextGenerated() && oldText != m_address.text())
144 emit textChanged();
145}
146
147/*!
148 \qmlproperty string QtPositioning::Address::countryCode
149
150 This property holds the country code of the address as a single formatted string.
151*/
152QString QDeclarativeGeoAddress::countryCode() const
153{
154 return m_address.countryCode();
155}
156
157void QDeclarativeGeoAddress::setCountryCode(const QString &countryCode)
158{
159 if (m_address.countryCode() == countryCode)
160 return;
161 QString oldText = m_address.text();
162 m_address.setCountryCode(countryCode);
163 emit countryCodeChanged();
164
165 if (m_address.isTextGenerated() && oldText != m_address.text())
166 emit textChanged();
167}
168
169/*!
170 \qmlproperty string QtPositioning::Address::state
171
172 This property holds the state of the address as a single formatted string.
173*/
174QString QDeclarativeGeoAddress::state() const
175{
176 return m_address.state();
177}
178
179void QDeclarativeGeoAddress::setState(const QString &state)
180{
181 if (m_address.state() == state)
182 return;
183 QString oldText = m_address.text();
184 m_address.setState(state);
185 emit stateChanged();
186
187 if (m_address.isTextGenerated() && oldText != m_address.text())
188 emit textChanged();
189}
190
191/*!
192 \qmlproperty string QtPositioning::Address::county
193
194 This property holds the county of the address as a single formatted string.
195*/
196QString QDeclarativeGeoAddress::county() const
197{
198 return m_address.county();
199}
200
201void QDeclarativeGeoAddress::setCounty(const QString &county)
202{
203 if (m_address.county() == county)
204 return;
205 QString oldText = m_address.text();
206 m_address.setCounty(county);
207 emit countyChanged();
208
209 if (m_address.isTextGenerated() && oldText != m_address.text())
210 emit textChanged();
211}
212
213/*!
214 \qmlproperty string QtPositioning::Address::city
215
216 This property holds the city of the address as a single formatted string.
217*/
218QString QDeclarativeGeoAddress::city() const
219{
220 return m_address.city();
221}
222
223void QDeclarativeGeoAddress::setCity(const QString &city)
224{
225 if (m_address.city() == city)
226 return;
227 QString oldText = m_address.text();
228 m_address.setCity(city);
229 emit cityChanged();
230
231 if (m_address.isTextGenerated() && oldText != m_address.text())
232 emit textChanged();
233}
234
235/*!
236 \qmlproperty string QtPositioning::Address::district
237
238 This property holds the district of the address as a single formatted string.
239*/
240QString QDeclarativeGeoAddress::district() const
241{
242 return m_address.district();
243}
244
245void QDeclarativeGeoAddress::setDistrict(const QString &district)
246{
247 if (m_address.district() == district)
248 return;
249 QString oldText = m_address.text();
250 m_address.setDistrict(district);
251 emit districtChanged();
252
253 if (m_address.isTextGenerated() && oldText != m_address.text())
254 emit textChanged();
255}
256
257/*!
258 \qmlproperty string QtPositioning::Address::street
259
260 This property holds the street of the address.
261
262 \note Before Qt6 this property could also contain things like a unit number,
263 a building name, or anything else that might be used to distinguish one
264 address from another. Since Qt6 use \l{QtPositioning::Address::}{streetNumber}
265 property for such information.
266*/
267QString QDeclarativeGeoAddress::street() const
268{
269 return m_address.street();
270}
271
272void QDeclarativeGeoAddress::setStreet(const QString &street)
273{
274 if (m_address.street() == street)
275 return;
276 QString oldText = m_address.text();
277 m_address.setStreet(street);
278 emit streetChanged();
279
280 if (m_address.isTextGenerated() && oldText != m_address.text())
281 emit textChanged();
282}
283
284/*!
285 \qmlproperty string QtPositioning::Address::streetNumber
286 \since QtPositioning 6.2
287
288 This property holds the street number of the address like a unit number,
289 a building name, or anything else that might be used to distinguish one
290 address from another.
291*/
292QString QDeclarativeGeoAddress::streetNumber() const
293{
294 return m_address.streetNumber();
295}
296
297void QDeclarativeGeoAddress::setStreetNumber(const QString &streetNumber)
298{
299 if (m_address.streetNumber() == streetNumber)
300 return;
301 QString oldText = m_address.text();
302 m_address.setStreetNumber(streetNumber);
303 emit streetNumberChanged();
304
305 if (m_address.isTextGenerated() && oldText != m_address.text())
306 emit textChanged();
307}
308
309/*!
310 \qmlproperty string QtPositioning::Address::postalCode
311
312 This property holds the postal code of the address as a single formatted string.
313*/
314QString QDeclarativeGeoAddress::postalCode() const
315{
316 return m_address.postalCode();
317}
318
319void QDeclarativeGeoAddress::setPostalCode(const QString &postalCode)
320{
321 if (m_address.postalCode() == postalCode)
322 return;
323 QString oldText = m_address.text();
324 m_address.setPostalCode(postalCode);
325 emit postalCodeChanged();
326
327 if (m_address.isTextGenerated() && oldText != m_address.text())
328 emit textChanged();
329}
330
331/*!
332 \qmlproperty bool QtPositioning::Address::isTextGenerated
333
334 This property holds a boolean that if true, indicates that \l text is automatically
335 generated from address properties. If false, it indicates that the \l text has been
336 explicitly assigned.
337
338*/
339bool QDeclarativeGeoAddress::isTextGenerated() const
340{
341 return m_address.isTextGenerated();
342}
343
344QT_END_NAMESPACE
345
346#include "moc_qdeclarativegeoaddress_p.cpp"
Combined button and popup list for selecting options.