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
qgeoaddress.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
4#include "qgeoaddress.h"
6
7#include <QtCore/QStringList>
8
9#ifdef QGEOADDRESS_DEBUG
10#include <QDebug>
11#endif
12
14
15QT_IMPL_METATYPE_EXTERN(QGeoAddress)
16
17/*
18 Combines a list of address parts into a single line.
19
20 The parts parameter contains both address elements such as city, state and so on
21 as well as separators such as spaces and commas.
22
23 It is expected that an element is always followed by a separator and the last
24 sepator is usually a new line delimeter.
25
26 For example: Springfield, 8900
27 would have four parts
28 ["Springfield", ", ", "8900", "<br>"]
29
30 The addressLine takes care of putting in separators appropriately or leaving
31 them out depending on whether the adjacent elements are present or not.
32 For example if city were empty in the above scenario the returned string is "8900<br>"
33 If the postal code was empty, returned string is "Springfield<br>"
34 If both city and postal code were empty, the returned string is "".
35*/
36static QString addressLine(const QStringList &parts)
37{
38 QString line;
39 Q_ASSERT(parts.size() % 2 == 0);
40
41 //iterate until just before the last pair
42 QString penultimateSeparator;
43 for (qsizetype i = 0; i < parts.size() - 2; i += 2) {
44 if (!parts.at(i).isEmpty()) {
45 line.append(parts.at(i) + parts.at(i + 1));
46 penultimateSeparator = parts.at(i + 1);
47 }
48 }
49
50 if (parts.at(parts.size() - 2).isEmpty()) {
51 line.chop(penultimateSeparator.size());
52
53 if (!line.isEmpty())
54 line.append(parts.at(parts.size() - 1));
55 } else {
56 line.append(parts.at(parts.size() - 2));
57 line.append(parts.at(parts.size() - 1));
58 }
59
60 return line;
61}
62
63/*
64 Returns a single formatted string representing the \a address. Lines of the address
65 are delimited by \a newLine. By default lines are delimited by <br/>. The \l
66 {QGeoAddress::countryCode} {countryCode} of the \a address determines the format of
67 the resultant string.
68*/
69static QString formattedAddress(const QGeoAddress &address,
70 const QString &newLine = QLatin1String("<br/>"))
71{
72 const QString Comma(QStringLiteral(", "));
73 const QString Dash(QStringLiteral("-"));
74 const QString Space(QStringLiteral(" "));
75
76 QString text;
77
78 // We have 2 main approaches here:
79 // 1. street number goes after street name
80 // 2. street number goes before street name
81 // We need to take it into account while generating the formatted address.
82 // Currently these pages were used to check the formats:
83 // https://en.wikipedia.org/wiki/Address
84 // https://www.grcdi.nl/gsb/world%20address%20formats.html
85 // We do not take into account such address extensions as apartment number,
86 // because this is not what you can usually get from map providers (like
87 // openstreetmap).
88
89 if (address.countryCode() == QLatin1String("ALB")
90 || address.countryCode() == QLatin1String("MTQ")) {
91 text += addressLine(QStringList() << address.street() << Space
92 << address.streetNumber() << newLine);
93 text += addressLine(QStringList() << address.postalCode() << Comma
94 << address.city() << newLine);
95 text += addressLine(QStringList() << address.country() << newLine);
96 } else if (address.countryCode() == QLatin1String("AND")
97 || address.countryCode() == QLatin1String("AUT")
98 || address.countryCode() == QLatin1String("GLP")
99 || address.countryCode() == QLatin1String("ITA")
100 || address.countryCode() == QLatin1String("RUS")
101 || address.countryCode() == QLatin1String("SMR")
102 || address.countryCode() == QLatin1String("VAT")) {
103 text += addressLine(QStringList() << address.street() << Space
104 << address.streetNumber() << newLine);
105 text += addressLine(QStringList() << address.postalCode() << Space
106 << address.city() << newLine);
107 text += addressLine(QStringList() << address.country() << newLine);
108 }else if (address.countryCode() == QLatin1String("FRA")
109 || address.countryCode() == QLatin1String("GUF")
110 || address.countryCode() == QLatin1String("LUX")
111 || address.countryCode() == QLatin1String("MCO")
112 || address.countryCode() == QLatin1String("REU")) {
113 text += addressLine(QStringList() << address.streetNumber() << Space
114 << address.street() << newLine);
115 text += addressLine(QStringList() << address.postalCode() << Space
116 << address.city() << newLine);
117 text += addressLine(QStringList() << address.country() << newLine);
118
119 } else if (address.countryCode() == QLatin1String("ARE")
120 || address.countryCode() == QLatin1String("BHS")) {
121 text += addressLine(QStringList() << address.street() << Space
122 << address.streetNumber() << newLine);
123 text += addressLine(QStringList() << address.district() << Space
124 << address.city() << newLine);
125 text += addressLine(QStringList() << address.country() << newLine);
126 } else if (address.countryCode() == QLatin1String("AUS")) {
127 text += addressLine(QStringList() << address.streetNumber() << Space
128 << address.street() << newLine);
129 text += addressLine(QStringList() << (address.district().isEmpty() ? address.city() : address.district())
130 << Space << address.state() << Space << address.postalCode() << newLine);
131 text += addressLine(QStringList() << address.country() << newLine);
132 } else if (address.countryCode() == QLatin1String("BHR")) {
133 text += addressLine(QStringList() << address.street() << Space
134 << address.streetNumber() << newLine);
135 text += addressLine(QStringList() << address.district() << Comma
136 << address.city() << Comma << address.state() << newLine);
137 text += addressLine(QStringList() << address.country() << newLine);
138 } else if (address.countryCode() == QLatin1String("BRA")) {
139 text += addressLine(QStringList() << address.street() << Space
140 << address.streetNumber() << newLine);
141 text += addressLine(QStringList() << address.district() << Space
142 << address.city() << Dash << address.state() << Space << address.postalCode() << newLine);
143 text += addressLine(QStringList() << address.country() << newLine);
144 } else if (address.countryCode() == QLatin1String("BRN")
145 || address.countryCode() == QLatin1String("JOR")
146 || address.countryCode() == QLatin1String("LBN")
147 || address.countryCode() == QLatin1String("NZL")) {
148 text += addressLine(QStringList() << address.streetNumber() << Space
149 << address.street() << newLine);
150 text += addressLine(QStringList() << address.district() << Space
151 << address.city() << Space << address.postalCode() << newLine);
152 text += addressLine(QStringList() << address.country() << newLine);
153 } else if (address.countryCode() == QLatin1String("CAN")
154 || address.countryCode() == QLatin1String("USA")
155 || address.countryCode() == QLatin1String("VIR")) {
156 text += addressLine(QStringList() << address.streetNumber() << Space
157 << address.street() << newLine);
158 text += addressLine(QStringList() << address.city() << Comma << address.state() << Space
159 << address.postalCode() << newLine);
160 text += addressLine(QStringList() << address.country() << newLine);
161 } else if (address.countryCode() == QLatin1String("CHN")) {
162 text += addressLine(QStringList() << address.street() << Space
163 << address.streetNumber() << Comma
164 << address.city() << newLine);
165 text += addressLine(QStringList() << address.postalCode() << Space << address.state() << newLine);
166 text += addressLine(QStringList() << address.country() << newLine);
167 } else if (address.countryCode() == QLatin1String("CHL")) {
168 text += addressLine(QStringList() << address.street() << Space
169 << address.streetNumber() << newLine);
170 text += addressLine(QStringList() << address.postalCode() << Space
171 << address.district() << Comma << address.city() << Comma
172 << address.state() << newLine);
173 text += addressLine(QStringList() << address.country() << newLine);
174 } else if (address.countryCode() == QLatin1String("CYM")) {
175 text += addressLine(QStringList() << address.streetNumber() << Space
176 << address.street() << newLine);
177 text += addressLine(QStringList() << address.state() << Space
178 << address.postalCode() << newLine);
179 text += addressLine(QStringList() << address.country() << newLine);
180 } else if (address.countryCode() == QLatin1String("GBR")) {
181 text += addressLine(QStringList() << address.streetNumber() << Space
182 << address.street() << newLine);
183 text += addressLine(QStringList() << address.district() << Comma
184 << address.city() << Comma << address.postalCode() << newLine);
185 text += addressLine(QStringList() << address.country() << newLine);
186 } else if (address.countryCode() == QLatin1String("GIB")) {
187 text += addressLine(QStringList() << address.streetNumber() << Space
188 << address.street() << newLine);
189 text += addressLine(QStringList() << address.city() << newLine);
190 text += addressLine(QStringList() << address.country() << newLine);
191 } else if (address.countryCode() == QLatin1String("HKG")) {
192 text += addressLine(QStringList() << address.streetNumber() << Space
193 << address.street() << newLine);
194 text += addressLine(QStringList() << address.district() << newLine);
195 text += addressLine(QStringList() << address.city() << newLine);
196 } else if (address.countryCode() == QLatin1String("IND")) {
197 text += addressLine(QStringList() << address.streetNumber() << Space
198 << address.street() << newLine);
199 text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Space
200 << address.state() << newLine);
201 text += addressLine(QStringList() << address.country() << newLine);
202 } else if (address.countryCode() == QLatin1String("IDN")
203 || address.countryCode() == QLatin1String("JEY")
204 || address.countryCode() == QLatin1String("LVA")) {
205 text += addressLine(QStringList() << address.street() << Space
206 << address.streetNumber() << newLine);
207 text += addressLine(QStringList() << address.city() << Comma << address.postalCode() << newLine);
208 text += addressLine(QStringList() << address.country() << newLine);
209 } else if (address.countryCode() == QLatin1String("IRL")) {
210 text += addressLine(QStringList() << address.streetNumber() << Space
211 << address.street() << newLine);
212 text += addressLine(QStringList() << address.district() << Comma << address.state() << newLine);
213 text += addressLine(QStringList() << address.country() << newLine);
214 } else if (address.countryCode() == QLatin1String("KWT")) {
215 text += addressLine(QStringList() << address.street() << Space
216 << address.streetNumber() << newLine);
217 text += addressLine(QStringList() << address.postalCode() << Comma
218 << address.district() << Comma << address.city() << newLine);
219 text += addressLine(QStringList() << address.country() << newLine);
220 } else if (address.countryCode() == QLatin1String("MLT")
221 || address.countryCode() == QLatin1String("SGP")) {
222 text += addressLine(QStringList() << address.streetNumber() << Space
223 << address.street() << newLine);
224 text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine);
225 text += addressLine(QStringList() << address.country() << newLine);
226 } else if (address.countryCode() == QLatin1String("UKR")) {
227 text += addressLine(QStringList() << address.street() << Space
228 << address.streetNumber() << newLine);
229 text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine);
230 text += addressLine(QStringList() << address.country() << newLine);
231 } else if (address.countryCode() == QLatin1String("MEX")) {
232 text += addressLine(QStringList() << address.street() << Space
233 << address.streetNumber() << newLine);
234 text += addressLine(QStringList() << address.district() << newLine);
235 text += addressLine(QStringList() << address.postalCode() << Space << address.city() << Comma
236 << address.state() << newLine);
237 text += addressLine(QStringList() << address.country() << newLine);
238 } else if (address.countryCode() == QLatin1String("MYS")) {
239 text += addressLine(QStringList() << address.streetNumber() << Space
240 << address.street() << newLine);
241 text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine);
242 text += addressLine(QStringList() << address.state() << newLine);
243 text += addressLine(QStringList() << address.country() << newLine);
244 } else if (address.countryCode() == QLatin1String("OMN")) {
245 text += addressLine(QStringList() << address.streetNumber() << Space
246 << address.street() << newLine);
247 text += addressLine(QStringList() << address.district() << Comma
248 << address.postalCode() << Comma
249 << address.city() << Comma
250 << address.country() << newLine);
251 } else if (address.countryCode() == QLatin1String("PRI")) {
252 text += addressLine(QStringList() << address.street() << Space
253 << address.streetNumber() << newLine);
254 text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma
255 << address.state() << Comma << address.postalCode() << newLine);
256 text += addressLine(QStringList() << address.country() << newLine);
257 } else if (address.countryCode() == QLatin1String("QAT")) {
258 text += addressLine(QStringList() << address.street() << Space
259 << address.streetNumber() << newLine);
260 text += addressLine(QStringList() << address.district() << Space << address.city() << Comma
261 << address.country() << newLine);
262 } else if (address.countryCode() == QLatin1String("SAU")) {
263 text += addressLine(QStringList() << address.streetNumber() << Space
264 << address.street() << Space
265 << address.district() << newLine);
266 text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine);
267 text += addressLine(QStringList() << address.country() << newLine);
268 } else if (address.countryCode() == QLatin1String("TWN")) {
269 text += addressLine(QStringList() << address.street() << Space
270 << address.streetNumber() << Comma
271 << address.district() << Comma
272 << address.city() << newLine);
273 text += addressLine(QStringList() << address.country() << newLine);
274 } else if (address.countryCode() == QLatin1String("THA")) {
275 text += addressLine(QStringList() << address.street() << Space
276 << address.streetNumber() << newLine);
277 text += addressLine(QStringList() << address.district() << Comma << address.city() << Space
278 << address.postalCode() << newLine);
279 text += addressLine(QStringList() << address.country() << newLine);
280 } else if (address.countryCode() == QLatin1String("TUR")) {
281 text += addressLine(QStringList() << address.street() << Space
282 << address.streetNumber() << newLine);
283 text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma
284 << address.city() << newLine);
285 text += addressLine(QStringList() << address.country() << newLine);
286 } else if (address.countryCode() == QLatin1String("VEN")) {
287 text += addressLine(QStringList() << address.street() << Space
288 << address.streetNumber() << newLine);
289 text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Comma
290 << address.state() << newLine);
291 text += addressLine(QStringList() << address.country() << newLine);
292 } else if (address.countryCode() == QLatin1String("ZAF")) {
293 text += addressLine(QStringList() << address.street() << Space
294 << address.streetNumber() << newLine);
295 text += addressLine(QStringList() << address.district() << Comma << address.city() << newLine);
296 text += addressLine(QStringList() << address.country() << newLine);
297 } else {
298 text += addressLine(QStringList() << address.street() << Space
299 << address.streetNumber() << newLine);
300 text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine);
301 text += addressLine(QStringList() << address.country() << newLine);
302 }
303
304 text.chop(newLine.size());
305 return text;
306}
307
308QGeoAddressPrivate::QGeoAddressPrivate()
309 : QSharedData(),
310 m_autoGeneratedText(false)
311{
312}
313
314QGeoAddressPrivate::QGeoAddressPrivate(const QGeoAddressPrivate &other)
315 : QSharedData(other),
316 sCountry(other.sCountry),
317 sCountryCode(other.sCountryCode),
318 sState(other.sState),
319 sCounty(other.sCounty),
320 sCity(other.sCity),
321 sDistrict(other.sDistrict),
322 sStreet(other.sStreet),
323 sStreetNumber(other.sStreetNumber),
324 sPostalCode(other.sPostalCode),
325 sText(other.sText),
326 m_autoGeneratedText(false)
327{
328}
329
330QGeoAddressPrivate::~QGeoAddressPrivate()
331{
332}
333
334/*!
335 \class QGeoAddress
336 \inmodule QtPositioning
337 \ingroup QtPositioning-positioning
338 \ingroup QtLocation-places-data
339 \ingroup QtLocation-places
340 \since 5.2
341
342 \brief The QGeoAddress class represents an address of a \l QGeoLocation.
343
344 The address' attributes are normalized to US feature names and can be mapped
345 to the local feature levels (for example State matches "Bundesland" in Germany).
346
347 The address contains a \l text() for displaying purposes and additional
348 properties to access the components of an address:
349
350 \list
351 \li QGeoAddress::country()
352 \li QGeoAddress::countryCode()
353 \li QGeoAddress::state()
354 \li QGeoAddress::city()
355 \li QGeoAddress::district()
356 \li QGeoAddress::street()
357 \li QGeoAddress::postalCode()
358 \endlist
359*/
360
361/*!
362 Default constructor.
363*/
364QGeoAddress::QGeoAddress()
365 : d(new QGeoAddressPrivate)
366{
367}
368
369/*!
370 Constructs a copy of \a other.
371*/
372QGeoAddress::QGeoAddress(const QGeoAddress &other)
373 : d(other.d)
374{
375}
376
377/*!
378 \fn QGeoAddress::QGeoAddress(QGeoAddress &&other) noexcept
379 \since 6.2
380
381 Constructs a geo address object by moving from \a other.
382
383 \note The moved-from QGeoAddress object can only be destroyed or
384 assigned to. The effect of calling other functions than the destructor
385 or one of the assignment operators is undefined.
386*/
387
388/*!
389 \fn QGeoAddress &QGeoAddress::operator=(QGeoAddress &other)
390 \since 6.2
391
392 Move-assigns the \a other to this address and returns a reference to this
393 address.
394
395 \note The moved-from QGeoAddress object can only be destroyed or
396 assigned to. The effect of calling other functions than the destructor
397 or one of the assignment operators is undefined.
398*/
399
400/*!
401 \fn void QGeoAddress::swap(QGeoAddress &other)
402 \since 6.2
403 \memberswap{address}
404*/
405
406/*!
407 Destroys this address.
408*/
409QGeoAddress::~QGeoAddress()
410{
411}
412
413QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoAddressPrivate)
414
415/*!
416 Assigns the given \a address to this address and
417 returns a reference to this address.
418*/
419QGeoAddress &QGeoAddress::operator=(const QGeoAddress & address)
420{
421 if (this == &address)
422 return *this;
423
424 d = address.d;
425 return *this;
426}
427
428/*!
429 \fn bool QGeoAddress::operator==(const QGeoAddress &lhs, const QGeoAddress &rhs)
430
431 Returns \c true if \a lhs address is equal to \a rhs, otherwise returns
432 \c false.
433*/
434
435/*!
436 \fn bool QGeoAddress::operator!=(const QGeoAddress &lhs, const QGeoAddress &rhs)
437
438 Returns \c true if \a lhs address is not equal to \a rhs, otherwise returns
439 \c false.
440*/
441
442/*!
443 Returns the address as a single formatted string. It is the recommended string
444 to use to display the address to the user. It typically takes the format of
445 an address as found on an envelope, but this is not always necessarily the case.
446
447 The address text is either automatically generated or explicitly assigned.
448 This can be determined by checking \l {QGeoAddress::isTextGenerated()} {isTextGenerated}.
449
450 If an empty string is provided to setText(), then isTextGenerated() will be set
451 to \c true and text() will return a string which is locally formatted according to
452 countryCode() and based on the elements of the address such as street, city and so on.
453 Because the text string is generated from the address elements, a sequence
454 of calls such as text(), setStreet(), text() may return different strings for each
455 invocation of text().
456
457 If a non-empty string is provided to setText(), then isTextGenerated() will be
458 set to \c false and text() will always return the explicitly assigned string.
459 Calls to modify other elements such as setStreet(), setCity() and so on will not
460 affect the resultant string from text().
461*/
462QString QGeoAddress::text() const
463{
464 if (d->sText.isEmpty())
465 return formattedAddress(*this);
466 else
467 return d->sText;
468}
469
470/*!
471 If \a text is not empty, explicitly assigns \a text as the string to be returned by
472 text(). isTextGenerated() will return false.
473
474 If \a text is empty, indicates that text() should be automatically generated
475 from the address elements. isTextGenerated() will return true.
476*/
477void QGeoAddress::setText(const QString &text)
478{
479 d->sText = text;
480}
481
482/*!
483 Returns the country name.
484*/
485QString QGeoAddress::country() const
486{
487 return d->sCountry;
488}
489
490/*!
491 Sets the \a country name.
492*/
493void QGeoAddress::setCountry(const QString &country)
494{
495 d->sCountry = country;
496}
497
498/*!
499 Returns the country code according to ISO 3166-1 alpha-3
500*/
501QString QGeoAddress::countryCode() const
502{
503 return d->sCountryCode;
504}
505
506/*!
507 Sets the \a countryCode according to ISO 3166-1 alpha-3
508*/
509void QGeoAddress::setCountryCode(const QString &countryCode)
510{
511 d->sCountryCode = countryCode;
512}
513
514/*!
515 Returns the state. The state is considered the first subdivision below country.
516*/
517QString QGeoAddress::state() const
518{
519 return d->sState;
520}
521
522/*!
523 Sets the \a state.
524*/
525void QGeoAddress::setState(const QString &state)
526{
527 d->sState = state;
528}
529
530/*!
531 Returns the county. The county is considered the second subdivision below country.
532*/
533QString QGeoAddress::county() const
534{
535 return d->sCounty;
536}
537
538/*!
539 Sets the \a county.
540*/
541void QGeoAddress::setCounty(const QString &county)
542{
543 d->sCounty = county;
544}
545
546/*!
547 Returns the city.
548*/
549QString QGeoAddress::city() const
550{
551 return d->sCity;
552}
553
554/*!
555 Sets the \a city.
556*/
557void QGeoAddress::setCity(const QString &city)
558{
559 d->sCity = city;
560}
561
562/*!
563 Returns the district. The district is considered the subdivison below city.
564*/
565QString QGeoAddress::district() const
566{
567 return d->sDistrict;
568}
569
570/*!
571 Sets the \a district.
572*/
573void QGeoAddress::setDistrict(const QString &district)
574{
575 d->sDistrict = district;
576}
577
578/*!
579 Returns the street name.
580
581 \note Before Qt6 this could also contain things like a unit number,
582 a building name, or anything else that might be used to distinguish
583 one address from another. Use streetNumber() to obtain this data now.
584
585 \sa streetNumber()
586*/
587QString QGeoAddress::street() const
588{
589 return d->sStreet;
590}
591
592/*!
593 Sets the street name to \a street.
594
595 \note Before Qt6 this could also contain things like a unit number,
596 a building name, or anything else that might be used to distinguish
597 one address from another. Use setStreetNumber() to set this data now.
598
599 \sa setStreetNumber()
600*/
601void QGeoAddress::setStreet(const QString &street)
602{
603 d->sStreet = street;
604}
605
606/*!
607 \since 6.2
608 Returns the street number.
609
610 This may also contain things like a unit number, a building name, or
611 anything else that might be used to distinguish one address from another.
612
613 \note Before Qt6 this information was returned by street() method.
614
615 \sa street()
616*/
617QString QGeoAddress::streetNumber() const
618{
619 return d->sStreetNumber;
620}
621
622/*!
623 \since 6.2
624 Sets the street number to \a streetNumber.
625
626 This may also contain things like a unit number, a building name, or
627 anything else that might be used to distinguish one address from another.
628
629 \note Before Qt6 this information was set by setStreet() method.
630
631 \sa setStreet()
632*/
633void QGeoAddress::setStreetNumber(const QString &streetNumber)
634{
635 d->sStreetNumber = streetNumber;
636}
637
638/*!
639 Returns the postal code.
640*/
641QString QGeoAddress::postalCode() const
642{
643 return d->sPostalCode;
644}
645
646/*!
647 Sets the \a postalCode.
648*/
649void QGeoAddress::setPostalCode(const QString &postalCode)
650{
651 d->sPostalCode = postalCode;
652}
653
654/*!
655 Returns whether this address is empty. An address is considered empty
656 if \e all of its fields are empty.
657*/
658bool QGeoAddress::isEmpty() const
659{
660 return d->sCountry.isEmpty() &&
661 d->sCountryCode.isEmpty() &&
662 d->sState.isEmpty() &&
663 d->sCounty.isEmpty() &&
664 d->sCity.isEmpty() &&
665 d->sDistrict.isEmpty() &&
666 d->sStreet.isEmpty() &&
667 d->sStreetNumber.isEmpty() &&
668 d->sPostalCode.isEmpty() &&
669 d->sText.isEmpty();
670
671}
672
673/*!
674 Clears all of the address' data fields.
675*/
676void QGeoAddress::clear()
677{
678 d->sCountry.clear();
679 d->sCountryCode.clear();
680 d->sState.clear();
681 d->sCounty.clear();
682 d->sCity.clear();
683 d->sDistrict.clear();
684 d->sStreet.clear();
685 d->sStreetNumber.clear();
686 d->sPostalCode.clear();
687 d->sText.clear();
688}
689
690/*!
691 Returns true if QGeoAddress::text() is automatically generated from address elements,
692 otherwise returns false if text() has been explicitly assigned.
693
694 \sa text(), setText()
695*/
696bool QGeoAddress::isTextGenerated() const
697{
698 return d->sText.isEmpty();
699}
700
701bool QGeoAddress::equals(const QGeoAddress &lhs, const QGeoAddress &rhs)
702{
703#ifdef QGEOADDRESS_DEBUG
704 qDebug() << "country" << (lhs.d->sCountry == rhs.d->sCountry);
705 qDebug() << "countryCode" << (lhs.d->sCountryCode == rhs.d->sCountryCode);
706 qDebug() << "state:" << (lhs.d->sState == rhs.d->sState);
707 qDebug() << "county:" << (lhs.d->sCounty == rhs.d->sCounty);
708 qDebug() << "city:" << (lhs.d->sCity == rhs.d->sCity);
709 qDebug() << "district:" << (lhs.d->sDistrict == rhs.d->sDistrict);
710 qDebug() << "street:" << (lhs.d->sStreet == rhs.d->sStreet);
711 qDebug() << "street number:" << (lhs.d->sStreetNumber == rhs.d->sStreetNumber);
712 qDebug() << "postalCode:" << (lhs.d->sPostalCode == rhs.d->sPostalCode);
713 qDebug() << "text:" << (lhs.text() == rhs.text());
714#endif
715
716 return lhs.d->sCountry == rhs.d->sCountry &&
717 lhs.d->sCountryCode == rhs.d->sCountryCode &&
718 lhs.d->sState == rhs.d->sState &&
719 lhs.d->sCounty == rhs.d->sCounty &&
720 lhs.d->sCity == rhs.d->sCity &&
721 lhs.d->sDistrict == rhs.d->sDistrict &&
722 lhs.d->sStreet == rhs.d->sStreet &&
723 lhs.d->sStreetNumber == rhs.d->sStreetNumber &&
724 lhs.d->sPostalCode == rhs.d->sPostalCode &&
725 lhs.text() == rhs.text();
726}
727
728/*!
729 \relates QGeoAddress
730
731 Returns the hash value for the \a address, using \a seed for the
732 calculation.
733*/
734size_t qHash(const QGeoAddress &address, size_t seed) noexcept
735{
736 size_t hash = qHashMulti(seed, address.country(), address.countryCode(), address.state(),
737 address.county(), address.city(), address.district(),
738 address.street(), address.streetNumber(), address.postalCode());
739
740 // If the text is generated from all fields, there is no need to use the
741 // resulting string in the hash. However, when the text is specified
742 // explicitly, we need to use it as well.
743 if (!address.isTextGenerated())
744 hash = qHashMulti(seed, hash, address.text());
745 return hash;
746}
747
748QT_END_NAMESPACE
Combined button and popup list for selecting options.
static QString formattedAddress(const QGeoAddress &address, const QString &newLine=QLatin1String("<br/>"))
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:191