mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #650 Implement CAirportDataReader
* Add BlackCore::CAirportDataReader class * Add cache traits for airport list * Add corresponding WebReaderFlag * Add CAirport::convertFromDatabaseJson() * Add CApplication::headerFromNetwork() to handle HTTP HEAD method
This commit is contained in:
@@ -52,6 +52,26 @@ namespace BlackMisc
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "Airport");
|
||||
}
|
||||
|
||||
void CAirport::fromDatabaseJson(const QJsonObject &json)
|
||||
{
|
||||
Q_ASSERT(json.value("icao").isString());
|
||||
setIcao(json.value("icao").toString());
|
||||
|
||||
Q_ASSERT(json.value("country").isString());
|
||||
setCountry(json.value("country").toString());
|
||||
|
||||
Q_ASSERT(json.value("name").isString());
|
||||
setDescriptiveName(json.value("name").toString());
|
||||
|
||||
Q_ASSERT(json.value("altitude").isDouble());
|
||||
setElevation(CLength(json.value("altitude").toInt(), CLengthUnit::ft()));
|
||||
|
||||
Q_ASSERT(json.value("latitude").isDouble());
|
||||
Q_ASSERT(json.value("longitude").isDouble());
|
||||
CCoordinateGeodetic pos(json.value("latitude").toDouble(), json.value("longitude").toDouble(), 0);
|
||||
setPosition(pos);
|
||||
}
|
||||
|
||||
CVariant CAirport::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
|
||||
@@ -42,7 +42,8 @@ namespace BlackMisc
|
||||
IndexIcao = BlackMisc::CPropertyIndex::GlobalIndexCAirport,
|
||||
IndexDescriptiveName,
|
||||
IndexPosition,
|
||||
IndexElevation
|
||||
IndexCountry,
|
||||
IndexElevation,
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
@@ -78,6 +79,12 @@ namespace BlackMisc
|
||||
//! Set position
|
||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
|
||||
|
||||
//! Get the country
|
||||
QString getCountry() const { return m_country; }
|
||||
|
||||
//! Set the country
|
||||
void setCountry(const QString &country) { this->m_country = country; }
|
||||
|
||||
//! Elevation
|
||||
//! \sa geodeticHeight
|
||||
const BlackMisc::PhysicalQuantities::CLength getElevation() const { return this->geodeticHeight(); }
|
||||
@@ -123,16 +130,21 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::convertFromJson
|
||||
void fromDatabaseJson(const QJsonObject &json);
|
||||
|
||||
private:
|
||||
CAirportIcaoCode m_icao;
|
||||
QString m_descriptiveName;
|
||||
BlackMisc::Geo::CCoordinateGeodetic m_position;
|
||||
QString m_country;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CAirport,
|
||||
BLACK_METAMEMBER(icao),
|
||||
BLACK_METAMEMBER(descriptiveName),
|
||||
BLACK_METAMEMBER(position),
|
||||
BLACK_METAMEMBER(country),
|
||||
BLACK_METAMEMBER(relativeDistance),
|
||||
BLACK_METAMEMBER(relativeBearing)
|
||||
);
|
||||
|
||||
@@ -44,5 +44,19 @@ namespace BlackMisc
|
||||
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);
|
||||
}
|
||||
|
||||
CAirportList CAirportList::fromDatabaseJson(const QJsonArray &json)
|
||||
{
|
||||
CAirportList airports;
|
||||
for (const QJsonValue& value: json)
|
||||
{
|
||||
QJsonObject object = value.toObject();
|
||||
CAirport airport;
|
||||
airport.fromDatabaseJson(object);
|
||||
airports.push_back(airport);
|
||||
}
|
||||
|
||||
return airports;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace BlackMisc
|
||||
|
||||
//! Find first station by callsign, if not return given value / default
|
||||
CAirport findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound = CAirport()) const;
|
||||
|
||||
//! Reads the airport list from JSON
|
||||
static CAirportList fromDatabaseJson(const QJsonArray& json);
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace BlackMisc
|
||||
case NoEntity: return "no data";
|
||||
case VatsimDataFile: return "VATSIM data file";
|
||||
case VatsimStatusFile: return "VATSIM status file";
|
||||
case AirportEntity: return "Airport";
|
||||
default:
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags");
|
||||
return "wrong flags";
|
||||
@@ -56,6 +57,7 @@ namespace BlackMisc
|
||||
if (flag.testFlag(NoEntity)) list << "no data";
|
||||
if (flag.testFlag(VatsimDataFile)) list << "VATSIM data file";
|
||||
if (flag.testFlag(VatsimStatusFile)) list << "VATSIM status file";
|
||||
if (flag.testFlag(AirportEntity)) list << "Airport";
|
||||
return list.join(',');
|
||||
}
|
||||
|
||||
|
||||
@@ -44,12 +44,13 @@ namespace BlackMisc
|
||||
MetarEntity = 1 << 8, //!< METAR
|
||||
VatsimDataFile = 1 << 9, //!< the VATSIM data file (multiple data entities)
|
||||
VatsimStatusFile = 1 << 10, //!< the VATSIM status file (URLs for data files etc.)
|
||||
AllEntities = ((1 << 11) - 1), //!< everything
|
||||
AirportEntity = 1 << 11, //!< airports
|
||||
AllEntities = ((1 << 12) - 1), //!< everything
|
||||
AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, //!< all ICAO codes
|
||||
AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, //!< all ICAO codes and countries
|
||||
DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, //!< Combinded
|
||||
AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | InfoObjectEntity, //!< All DB stuff
|
||||
AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel //!< All DB entities, no info objects
|
||||
AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | InfoObjectEntity | AirportEntity, //!< All DB stuff
|
||||
AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel | AirportEntity //!< All DB entities, no info objects
|
||||
};
|
||||
Q_DECLARE_FLAGS(Entity, EntityFlag)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user