Members of the KDE Community are recommended to subscribe to the kde-community mailing list at to allow them to participate in important discussions and receive other important announcements

Commit e73b3d2b authored by Volker Krause's avatar Volker Krause

Determine airport country also if we have multiple IATA code candidates

As long as they are all in the same country, that is good enough. The
same will also work for timezones.

This is a common scenario with multiple airports in the same city for
example, especially when one is much more relevant than the others and
therefore often resulting in use of simplified/incomplete names.
parent f48519d3
......@@ -27,14 +27,18 @@
#include <KItinerary/Organization>
#include <QDateTime>
#include <QDebug>
#include <QTimeZone>
using namespace KItinerary;
Flight FlightPostProcessor::processFlight(Flight flight) const
Flight FlightPostProcessor::processFlight(Flight flight)
lookupAirportCodes(flight.departureAirport(), m_departureCodes);
lookupAirportCodes(flight.arrivalAirport(), m_arrivalCodes);
flight.setDepartureAirport(processAirport(flight.departureAirport(), m_departureCodes));
flight.setArrivalAirport(processAirport(flight.arrivalAirport(), m_arrivalCodes));
flight.setBoardingTime(processFlightTime(flight.boardingTime(), flight, flight.departureAirport()));
flight.setDepartureTime(processFlightTime(flight.departureTime(), flight, flight.departureAirport()));
......@@ -43,24 +47,20 @@ Flight FlightPostProcessor::processFlight(Flight flight) const
return flight;
Airport FlightPostProcessor::processAirport(Airport airport) const
Airport FlightPostProcessor::processAirport(Airport airport, const std::vector<KnowledgeDb::IataCode> &codes) const
// clean up name
// complete missing IATA codes
auto iataCode = airport.iataCode();
if (iataCode.isEmpty()) {
iataCode = KnowledgeDb::iataCodeFromName(;
if (!iataCode.isEmpty()) {
if (airport.iataCode().isEmpty() && codes.size() == 1) {
// complete missing geo coordinates
auto geo = airport.geo();
if (!geo.isValid()) {
const auto coord = KnowledgeDb::coordinateForAirport(KnowledgeDb::IataCode{iataCode});
if (!geo.isValid() && codes.size() == 1) {
const auto coord = KnowledgeDb::coordinateForAirport(codes[0]);
if (coord.isValid()) {
......@@ -68,11 +68,11 @@ Airport FlightPostProcessor::processAirport(Airport airport) const
// add country
// add country, if all candidates are from the same country
auto addr = airport.address();
if (addr.addressCountry().isEmpty()) {
const auto isoCode = KnowledgeDb::countryForAirport(KnowledgeDb::IataCode{iataCode});
if (isoCode.isValid()) {
if (addr.addressCountry().isEmpty() && codes.size() >= 1) {
const auto isoCode = KnowledgeDb::countryForAirport(codes[0]);
if (isoCode.isValid() && std::all_of(codes.begin(), codes.end(), [isoCode](const auto iataCode) { return KnowledgeDb::countryForAirport(iataCode) == isoCode; })) {
......@@ -120,3 +120,19 @@ QDateTime FlightPostProcessor::processFlightTime(QDateTime dt, const Flight &fli
return dt;
void FlightPostProcessor::lookupAirportCodes(const Airport &airport, std::vector<KnowledgeDb::IataCode>& codes) const
if (!airport.iataCode().isEmpty()) {
// TODO if we don't need this elsewhere, maybe merge those two methods and do this logic internally more efficently?
const auto code = KnowledgeDb::iataCodeFromName(;
if (code.isValid()) {
} else {
codes = KnowledgeDb::iataCodesFromName(;
......@@ -20,6 +20,10 @@
#include "knowledgedb/iatacode.h"
#include <vector>
class QDateTime;
namespace KItinerary {
......@@ -32,12 +36,17 @@ class Flight;
class FlightPostProcessor
Flight processFlight(Flight flight) const;
Flight processFlight(Flight flight);
Airport processAirport(Airport airport) const;
Airport processAirport(Airport airport, const std::vector<KnowledgeDb::IataCode> &codes) const;
Airline processAirline(Airline airline) const;
QDateTime processFlightTime(QDateTime dt, const Flight &flight, const Airport &airport) const;
void lookupAirportCodes(const Airport &airport, std::vector<KnowledgeDb::IataCode> &codes) const;
std::vector<KnowledgeDb::IataCode> m_departureCodes;
std::vector<KnowledgeDb::IataCode> m_arrivalCodes;
Markdown is supported
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