From 9acfb89e6516b34ca8905efc2aec9eca814b1a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Garapich?= Date: Tue, 11 Oct 2016 01:46:10 +0200 Subject: [PATCH] refs #748 Add operating attribute to CAirport --- src/blackmisc/aviation/airport.cpp | 8 ++++++++ src/blackmisc/aviation/airport.h | 9 +++++++++ tests/blackcore/testreaders.cpp | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/aviation/airport.cpp b/src/blackmisc/aviation/airport.cpp index 4f8e8ad93..bf15afb5f 100644 --- a/src/blackmisc/aviation/airport.cpp +++ b/src/blackmisc/aviation/airport.cpp @@ -72,6 +72,8 @@ namespace BlackMisc Q_ASSERT(json.value("longitude").isDouble()); CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0); setPosition(pos); + + setOperating(json.value("operating").toString() == QStringLiteral("Y")); } CAirport CAirport::fromDatabaseJson(const QJsonObject &json, const QString &prefix) @@ -81,6 +83,7 @@ namespace BlackMisc airport.setElevation(CLength(json.value("altitude").toInt(), CLengthUnit::ft())); CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0); airport.setPosition(pos); + airport.setOperating(json.value("operating").toString() == QStringLiteral("Y")); if (json.value("alpha3").isString() && json.value("country").isString()) { @@ -106,6 +109,8 @@ namespace BlackMisc return this->m_position.propertyByIndex(index.copyFrontRemoved()); case IndexElevation: return this->getElevation().propertyByIndex(index.copyFrontRemoved()); + case IndexOperating: + return CVariant::from(this->isOperating()); default: return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? ICoordinateWithRelativePosition::propertyByIndex(index) : @@ -128,6 +133,9 @@ namespace BlackMisc case IndexPosition: this->m_position.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexOperating: + this->setOperating(variant.toBool()); + break; default: if (ICoordinateWithRelativePosition::canHandleIndex(index)) { diff --git a/src/blackmisc/aviation/airport.h b/src/blackmisc/aviation/airport.h index caf7bbb0d..99f7d4b37 100644 --- a/src/blackmisc/aviation/airport.h +++ b/src/blackmisc/aviation/airport.h @@ -49,6 +49,7 @@ namespace BlackMisc IndexPosition, IndexCountry, IndexElevation, + IndexOperating, }; //! Default constructor. @@ -98,6 +99,12 @@ namespace BlackMisc //! \sa setGeodeticHeight void setElevation(const BlackMisc::PhysicalQuantities::CLength &elevation) { return this->m_position.setGeodeticHeight(elevation); } + //! Is the airport still active? + bool isOperating() const { return m_operating; } + + //! Sets the value of \sa isOperating(). + void setOperating(bool operating) { m_operating = operating; } + //! \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(); } @@ -146,6 +153,7 @@ namespace BlackMisc QString m_descriptiveName; BlackMisc::Geo::CCoordinateGeodetic m_position; CCountry m_country; + bool m_operating; BLACK_METACLASS( CAirport, @@ -153,6 +161,7 @@ namespace BlackMisc BLACK_METAMEMBER(descriptiveName), BLACK_METAMEMBER(position), BLACK_METAMEMBER(country), + BLACK_METAMEMBER(operating), BLACK_METAMEMBER(relativeDistance), BLACK_METAMEMBER(relativeBearing) ); diff --git a/tests/blackcore/testreaders.cpp b/tests/blackcore/testreaders.cpp index 638f90b2e..44cdb3647 100644 --- a/tests/blackcore/testreaders.cpp +++ b/tests/blackcore/testreaders.cpp @@ -135,10 +135,10 @@ namespace BlackCoreTest QVERIFY2(this->m_airportReader->getAirports().size() > 0, "No airports"); auto heathrow = this->m_airportReader->getAirports().findByIcao("EGLL"); QVERIFY2(heathrow.size() == 1, "No Heathrow"); + QVERIFY2(heathrow[0].isOperating(), "Wrong airport data"); auto airports = m_airportReader->getAirports(); airports.sortByRange(CCoordinateGeodetic(CLatitude(51.5085300, CAngleUnit::deg()), CLongitude(-0.1257400, CAngleUnit::deg()), CLength()), true); - qDebug() << airports[0].getIcao() << airports[1].getIcao(); QVERIFY2(airports[0].getIcao() == CAirportIcaoCode("EGLW"), "Wrong airport data"); CApplication::processEventsFor(2500); // make sure events are processed