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