refs #801, suppport for missing parts in airports/list

This commit is contained in:
Klaus Basan
2016-11-18 21:46:50 +01:00
parent 26cc77ebab
commit 0bedc9f084
4 changed files with 35 additions and 0 deletions

View File

@@ -38,6 +38,13 @@ namespace BlackMisc
m_icao(icao), m_descriptiveName(descriptiveName), m_position(position)
{ }
void CAirport::updateMissingParts(const CAirport &airport)
{
if (!this->m_country.hasIsoCode() && airport.getCountry().hasIsoCode()) { this->m_country = airport.getCountry(); }
if (this->m_descriptiveName.isEmpty()) { this->m_descriptiveName = airport.getDescriptiveName(); }
if (this->m_descriptiveName.isEmpty()) { this->m_descriptiveName = airport.getDescriptiveName(); }
}
QString CAirport::convertToQString(bool i18n) const
{
QString s = i18n ? QCoreApplication::translate("Aviation", "Airport") : "Airport";

View File

@@ -105,6 +105,9 @@ namespace BlackMisc
//! Sets the value of \sa isOperating().
void setOperating(bool operating) { m_operating = operating; }
//! Update the missing parts in airport
void updateMissingParts(const CAirport &airport);
//! \copydoc Geo::ICoordinateGeodetic::geodeticHeight
//! \remarks this should be used for elevation as depicted here: http://en.wikipedia.org/wiki/Altitude#mediaviewer/File:Vertical_distances.svg
const BlackMisc::PhysicalQuantities::CLength &geodeticHeight() const override { return this->m_position.geodeticHeight(); }

View File

@@ -32,12 +32,31 @@ namespace BlackMisc
return this->findBy(&CAirport::getIcao, icao);
}
bool CAirportList::containsAirportWithIcaoCode(const CAirportIcaoCode &icao) const
{
if (icao.isEmpty()) { return false; }
return this->contains(&CAirport::getIcao, icao);
}
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
{
if (!addedOrReplacedAirport.hasValidIcaoCode()) return; // ignore invalid airport
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
}
void CAirportList::updateMissingParts(const CAirportList &updateFromList)
{
if (updateFromList.isEmpty()) { return; }
for (CAirport &airport : *this)
{
const CAirport fromAirport = updateFromList.findFirstByIcao(airport.getIcao());
if (fromAirport.hasValidIcaoCode())
{
airport.updateMissingParts(fromAirport);
}
}
}
CAirport CAirportList::findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound) const
{
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);

View File

@@ -46,9 +46,15 @@ namespace BlackMisc
//! Find 0..n airports by ICAO code
CAirportList findByIcao(const CAirportIcaoCode &icao) const;
//! Containing an airport with given ICAO code?
bool containsAirportWithIcaoCode(const CAirportIcaoCode &icao) const;
//! Replace or add based on same ICAO code
void replaceOrAddByIcao(const CAirport &addedOrReplacedAirport);
//! Update this list from the other list
void updateMissingParts(const CAirportList &updateFromList);
//! Find first station by callsign, if not return given value / default
CAirport findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound = CAirport()) const;