Commit 7fd6b845 authored by Volker Krause's avatar Volker Krause
Browse files

Prefer coordinate-based country subdivisions if the explicit one is invalid

That means we get a machine readable code here also in cases the region
field is explicitly set, but contains the human readable name.
parent 51516f45
......@@ -37,19 +37,21 @@ QString LocationHelper::regionCode(const QVariant &loc)
const auto addr = LocationUtil::address(loc);
const auto coord = LocationUtil::geo(loc);
if ((addr.addressRegion().isEmpty() || addr.addressCountry().isEmpty()) && coord.isValid()) {
QString code = addr.addressCountry();
if (!code.isEmpty() && !addr.addressRegion().isEmpty()) {
code += QLatin1Char('-') + addr.addressRegion();
if (KCountrySubdivision::fromCode(code).isValid()) {
return code;
// prefer coordinate lookup over explicitly specified values if those don't result in a valid machine-readable code
if (coord.isValid()) {
const auto cs = KCountrySubdivision::fromLocation(coord.latitude(), coord.longitude());
if (cs.isValid()) {
return cs.code();
if (addr.addressCountry().isEmpty()) {
return {};
if (addr.addressRegion().isEmpty()) {
return addr.addressCountry();
return addr.addressCountry() + QLatin1Char('-') + addr.addressRegion();
return code;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment