KContacts
addressformatter.cpp
20static constexpr auto AllFields = AddressFormatField::Country | AddressFormatField::Region | AddressFormatField::Locality
21 | AddressFormatField::DependentLocality | AddressFormatField::SortingCode | AddressFormatField::PostalCode | AddressFormatField::StreetAddress
22 | AddressFormatField::Organization | AddressFormatField::Name | AddressFormatField::PostOfficeBox;
24static constexpr auto GeoUriFields = AddressFormatField::StreetAddress | AddressFormatField::PostalCode | AddressFormatField::Locality
25 | AddressFormatField::DependentLocality | AddressFormatField::Region | AddressFormatField::Country;
53AddressFormatter::format(const Address &address, const QString &name, const QString &organization, const AddressFormat &format, AddressFormatStyle style)
72 return address.street().isEmpty() && (address.extended().isEmpty() || style == AddressFormatStyle::GeoUriQuery);
90 return style == AddressFormatStyle::GeoUriQuery ? format.country() : KCountry::fromAlpha2(format.country()).name();
100 const auto precedingSeparator = (it != format.elements().begin() && (*std::prev(it)).isSeparator());
101 if ((*it).isSeparator() && (!line.isEmpty() || (precedingSeparator && styleData.separator == Newline))) {
111 // literals are only added if they not follow an empty field and are not preceding an empty field
112 // to support incomplete addresses we deviate from the libaddressinput algorithm here and also add
113 // the separator if any preceding field in the same line is non-empty, not just the immediate one.
115 bool precedingFieldHasContent = (it == format.elements().begin() || (*std::prev(it)).isSeparator());
125 const auto followingFieldEmpty = (std::next(it) != format.elements().end() && (*std::next(it)).isField() && isFieldEmpty((*std::next(it)).field()));
148 if (!address.street().isEmpty() && !address.extended().isEmpty() && style != AddressFormatStyle::GeoUriQuery) {
183 // append country for formats that need it (international style + not yet present in format.elements())
184 if (styleData.forceCountry && (format.usedFields() & AddressFormatField::Country & styleData.includeFields) == 0 && !address.country().isEmpty()) {
187 // the format of the country for postal addresses depends on the sending country, not the destination
189 const auto sourceFmt = AddressFormatRepository::formatForCountry(sourceCountry.alpha2(), AddressFormatScriptPreference::Local);
static Q_INVOKABLE KContacts::AddressFormat formatForCountry(const QString &countryCode, KContacts::AddressFormatScriptPreference scriptPref, KContacts::AddressFormatPreference formatPref=AddressFormatPreference::Generic)
Look up format data for a country.
Definition addressformat.cpp:111
Information on how addresses are formatted in a specific country/language.
Definition addressformat.h:69
static KCountry fromAlpha2(const char *alpha2Code)
QString name() const
static KCountry fromQLocale(QLocale::Country country)
bool isEmpty() const
PostalAddress address(const QVariant &location)
QString name(StandardAction id)
const QList< QKeySequence > & begin()
Native
bool isEmpty() const const
void push_back(parameter_type value)
void push_front(parameter_type value)
void clear()
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
QString toUpper() const const
QString join(QChar separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.