refs #748 Add operating attribute to CAirport

This commit is contained in:
Michał Garapich
2016-10-11 01:46:10 +02:00
committed by Mathew Sutcliffe
parent cf3e9f1f67
commit 9acfb89e65
3 changed files with 18 additions and 1 deletions

View File

@@ -72,6 +72,8 @@ namespace BlackMisc
Q_ASSERT(json.value("longitude").isDouble()); Q_ASSERT(json.value("longitude").isDouble());
CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0); CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0);
setPosition(pos); setPosition(pos);
setOperating(json.value("operating").toString() == QStringLiteral("Y"));
} }
CAirport CAirport::fromDatabaseJson(const QJsonObject &json, const QString &prefix) CAirport CAirport::fromDatabaseJson(const QJsonObject &json, const QString &prefix)
@@ -81,6 +83,7 @@ namespace BlackMisc
airport.setElevation(CLength(json.value("altitude").toInt(), CLengthUnit::ft())); airport.setElevation(CLength(json.value("altitude").toInt(), CLengthUnit::ft()));
CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0); CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0);
airport.setPosition(pos); airport.setPosition(pos);
airport.setOperating(json.value("operating").toString() == QStringLiteral("Y"));
if (json.value("alpha3").isString() && json.value("country").isString()) if (json.value("alpha3").isString() && json.value("country").isString())
{ {
@@ -106,6 +109,8 @@ namespace BlackMisc
return this->m_position.propertyByIndex(index.copyFrontRemoved()); return this->m_position.propertyByIndex(index.copyFrontRemoved());
case IndexElevation: case IndexElevation:
return this->getElevation().propertyByIndex(index.copyFrontRemoved()); return this->getElevation().propertyByIndex(index.copyFrontRemoved());
case IndexOperating:
return CVariant::from(this->isOperating());
default: default:
return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? return (ICoordinateWithRelativePosition::canHandleIndex(index)) ?
ICoordinateWithRelativePosition::propertyByIndex(index) : ICoordinateWithRelativePosition::propertyByIndex(index) :
@@ -128,6 +133,9 @@ namespace BlackMisc
case IndexPosition: case IndexPosition:
this->m_position.setPropertyByIndex(index.copyFrontRemoved(), variant); this->m_position.setPropertyByIndex(index.copyFrontRemoved(), variant);
break; break;
case IndexOperating:
this->setOperating(variant.toBool());
break;
default: default:
if (ICoordinateWithRelativePosition::canHandleIndex(index)) if (ICoordinateWithRelativePosition::canHandleIndex(index))
{ {

View File

@@ -49,6 +49,7 @@ namespace BlackMisc
IndexPosition, IndexPosition,
IndexCountry, IndexCountry,
IndexElevation, IndexElevation,
IndexOperating,
}; };
//! Default constructor. //! Default constructor.
@@ -98,6 +99,12 @@ namespace BlackMisc
//! \sa setGeodeticHeight //! \sa setGeodeticHeight
void setElevation(const BlackMisc::PhysicalQuantities::CLength &elevation) { return this->m_position.setGeodeticHeight(elevation); } 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 //! \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 //! \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(); } const BlackMisc::PhysicalQuantities::CLength &geodeticHeight() const override { return this->m_position.geodeticHeight(); }
@@ -146,6 +153,7 @@ namespace BlackMisc
QString m_descriptiveName; QString m_descriptiveName;
BlackMisc::Geo::CCoordinateGeodetic m_position; BlackMisc::Geo::CCoordinateGeodetic m_position;
CCountry m_country; CCountry m_country;
bool m_operating;
BLACK_METACLASS( BLACK_METACLASS(
CAirport, CAirport,
@@ -153,6 +161,7 @@ namespace BlackMisc
BLACK_METAMEMBER(descriptiveName), BLACK_METAMEMBER(descriptiveName),
BLACK_METAMEMBER(position), BLACK_METAMEMBER(position),
BLACK_METAMEMBER(country), BLACK_METAMEMBER(country),
BLACK_METAMEMBER(operating),
BLACK_METAMEMBER(relativeDistance), BLACK_METAMEMBER(relativeDistance),
BLACK_METAMEMBER(relativeBearing) BLACK_METAMEMBER(relativeBearing)
); );

View File

@@ -135,10 +135,10 @@ namespace BlackCoreTest
QVERIFY2(this->m_airportReader->getAirports().size() > 0, "No airports"); QVERIFY2(this->m_airportReader->getAirports().size() > 0, "No airports");
auto heathrow = this->m_airportReader->getAirports().findByIcao("EGLL"); auto heathrow = this->m_airportReader->getAirports().findByIcao("EGLL");
QVERIFY2(heathrow.size() == 1, "No Heathrow"); QVERIFY2(heathrow.size() == 1, "No Heathrow");
QVERIFY2(heathrow[0].isOperating(), "Wrong airport data");
auto airports = m_airportReader->getAirports(); auto airports = m_airportReader->getAirports();
airports.sortByRange(CCoordinateGeodetic(CLatitude(51.5085300, CAngleUnit::deg()), CLongitude(-0.1257400, CAngleUnit::deg()), CLength()), true); 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"); QVERIFY2(airports[0].getIcao() == CAirportIcaoCode("EGLW"), "Wrong airport data");
CApplication::processEventsFor(2500); // make sure events are processed CApplication::processEventsFor(2500); // make sure events are processed