/* Returns a single formatted string representing the \a address. Lines of the address are delimited by \a newLine. By default lines are delimited by <br/>. The \l {QGeoAddress::countryCode} {countryCode} of the \a address determines the format of the resultant string. */ static QString formattedAddress(const QGeoAddress &address, const QString &newLine = QLatin1String("<br/>")) { const QString Comma(QStringLiteral(", ")); const QString Dash(QStringLiteral("-")); const QString Space(QStringLiteral(" ")); QString text; if (address.countryCode() == QLatin1String("ALB") || address.countryCode() == QLatin1String("MTQ")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("AND") || address.countryCode() == QLatin1String("AUT") || address.countryCode() == QLatin1String("FRA") || address.countryCode() == QLatin1String("GLP") || address.countryCode() == QLatin1String("GUF") || address.countryCode() == QLatin1String("ITA") || address.countryCode() == QLatin1String("LUX") || address.countryCode() == QLatin1String("MCO") || address.countryCode() == QLatin1String("REU") || address.countryCode() == QLatin1String("RUS") || address.countryCode() == QLatin1String("SMR") || address.countryCode() == QLatin1String("VAT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("ARE") || address.countryCode() == QLatin1String("BHS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("AUS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << (address.district().isEmpty() ? address.city() : address.district()) << Space << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BHR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BRA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Dash << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BRN") || address.countryCode() == QLatin1String("JOR") || address.countryCode() == QLatin1String("LBN") || address.countryCode() == QLatin1String("NZL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CAN") || address.countryCode() == QLatin1String("USA") || address.countryCode() == QLatin1String("VIR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Comma << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CHN")) { text += addressLine(QStringList() << address.street() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CHL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CYM")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("GBR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("GIB")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("HKG")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << newLine); text += addressLine(QStringList() << address.city() << newLine); } else if (address.countryCode() == QLatin1String("IND")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Space << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("IDN") || address.countryCode() == QLatin1String("JEY") || address.countryCode() == QLatin1String("LVA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("IRL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("KWT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Comma << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MLT") || address.countryCode() == QLatin1String("SGP") || address.countryCode() == QLatin1String("UKR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MEX")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MYS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("OMN")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.postalCode() << Comma << address.city() << Comma << address.country() << newLine); } else if (address.countryCode() == QLatin1String("PRI")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.state() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("QAT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Comma << address.country() << newLine); } else if (address.countryCode() == QLatin1String("SAU")) { text += addressLine(QStringList() << address.street() << Space << address.district() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("TWN")) { text += addressLine(QStringList() << address.street() << Comma << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("THA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("TUR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("VEN")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("ZAF")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } text.chop(newLine.length()); return text; }
bool QLandmarkFileHandlerLmx::writeAddressInfo(const QLandmark &landmark) { QGeoAddress address = landmark.address(); if (address.street().isEmpty() && address.city().isEmpty() && address.state().isEmpty() && address.country().isEmpty() && address.postcode().isEmpty() && landmark.phoneNumber().isEmpty()) return true; m_writer->writeStartElement(m_ns, "addressInfo"); if (!address.country().isEmpty()) m_writer->writeTextElement(m_ns, "country", address.country()); if (!address.state().isEmpty()) m_writer->writeTextElement(m_ns, "state", address.state()); if (!address.county().isEmpty()) m_writer->writeTextElement(m_ns, "county", address.county()); if (!address.city().isEmpty()) m_writer->writeTextElement(m_ns, "city", address.city()); if (!address.district().isEmpty()) m_writer->writeTextElement(m_ns, "district", address.district()); if (!address.postcode().isEmpty()) m_writer->writeTextElement(m_ns, "postalCode", address.postcode()); QString street; if (!address.street().isEmpty()) street.append(address.street()); if (!street.isEmpty()) m_writer->writeTextElement(m_ns, "street", street); if (!landmark.phoneNumber().isEmpty()) m_writer->writeTextElement(m_ns, "phoneNumber", landmark.phoneNumber()); m_writer->writeEndElement(); return true; }
/*! Returns true if this address is equal to \a other, otherwise returns false. */ bool QGeoAddress::operator==(const QGeoAddress &other) const { #ifdef QGEOADDRESS_DEBUG qDebug() << "country" << (d->sCountry == other.country()); qDebug() << "countryCode" << (d->sCountryCode == other.countryCode()); qDebug() << "state:" << (d->sState == other.state()); qDebug() << "county:" << (d->sCounty == other.county()); qDebug() << "city:" << (d->sCity == other.city()); qDebug() << "district:" << (d->sDistrict == other.district()); qDebug() << "street:" << (d->sStreet == other.street()); qDebug() << "postalCode:" << (d->sPostalCode == other.postalCode()); qDebug() << "text:" << (text() == other.text()); #endif return d->sCountry == other.country() && d->sCountryCode == other.countryCode() && d->sState == other.state() && d->sCounty == other.county() && d->sCity == other.city() && d->sDistrict == other.district() && d->sStreet == other.street() && d->sPostalCode == other.postalCode() && this->text() == other.text(); }
bool QLandmarkFileHandlerLmx::readAddressInfo(QLandmark &landmark) { /* <xsd:complexType name="addressInfoType"> <xsd:all> <xsd:element name="country" type="xsd:string" minOccurs="0" /> <xsd:element name="countryCode" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:token"> <xsd:length value="2"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="state" type="xsd:string" minOccurs="0" /> <xsd:element name="county" type="xsd:string" minOccurs="0" /> <xsd:element name="city" type="xsd:string" minOccurs="0" /> <xsd:element name="district" type="xsd:string" minOccurs="0" /> <xsd:element name="postalCode" type="xsd:string" minOccurs="0" /> <xsd:element name="crossing1" type="xsd:string" minOccurs="0" /> <xsd:element name="crossing2" type="xsd:string" minOccurs="0" /> <xsd:element name="street" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingName" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingZone" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingFloor" type="xsd:string" minOccurs="0" /> <xsd:element name="buildingRoom" type="xsd:string" minOccurs="0" /> <xsd:element name="extension" type="xsd:string" minOccurs="0" /> <xsd:element name="phoneNumber" type="xsd:string" minOccurs="0" /> </xsd:all> </xsd:complexType> */ Q_ASSERT(m_reader->isStartElement() && (m_reader->name() == "addressInfo")); QHash<QString, int> counts; counts["country"] = 0; counts["countryCode"] = 0; counts["state"] = 0; counts["county"] = 0; counts["city"] = 0; counts["district"] = 0; counts["postalCode"] = 0; counts["crossing1"] = 0; counts["crossing2"] = 0; counts["street"] = 0; counts["buildingName"] = 0; counts["buildingZone"] = 0; counts["buildingFloor"] = 0; counts["buildingRoom"] = 0; counts["extension"] = 0; counts["phoneNumber"] = 0; QGeoAddress address; while (m_reader->readNextStartElement()) { QString name = m_reader->name().toString(); if (counts.keys().contains(name)) { if (counts.value(name) == 1) { m_reader->raiseError(QString("The element \"addressInfo\" did not expect more then one occurrence of the child element named \"%1\".").arg(m_reader->name().toString())); return false; } counts[name] = 1; if (name == "county") { address.setCounty(m_reader->readElementText()); } else if (name == "country") { address.setCountry(m_reader->readElementText()); } else if (name == "state") { address.setState(m_reader->readElementText()); } else if (name == "city") { address.setCity(m_reader->readElementText()); } else if (name == "district") { address.setDistrict(m_reader->readElementText()); } else if (name == "postalCode") { address.setPostcode(m_reader->readElementText()); } else if (name == "street") { QString street = m_reader->readElementText(); address.setStreet(street); } else if (name == "phoneNumber") { landmark.setPhoneNumber(m_reader->readElementText()); } else { m_reader->skipCurrentElement(); } } else { m_reader->raiseError(QString("The element \"addressInfo\" did not expect a child element named \"%1\".").arg(m_reader->name().toString())); return false; } } landmark.setAddress(address); return true; }