mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T472, category support for ICAO value objects
This commit is contained in:
committed by
Mat Sutcliffe
parent
3be2cd6c5f
commit
c82efe441f
@@ -584,6 +584,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator: return CVariant::fromValue(m_designator);
|
||||
case IndexCategory: return m_category.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIataCode: return CVariant::fromValue(m_iataCode);
|
||||
case IndexFamily: return CVariant::fromValue(m_family);
|
||||
case IndexCombinedAircraftType: return CVariant::fromValue(m_combinedType);
|
||||
@@ -611,6 +612,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator: this->setDesignator(variant.value<QString>()); break;
|
||||
case IndexCategory: m_category.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexIataCode: this->setIataCode(variant.value<QString>()); break;
|
||||
case IndexFamily: this->setFamily(variant.value<QString>()); break;
|
||||
case IndexCombinedAircraftType: this->setCombinedType(variant.value<QString>()); break;
|
||||
@@ -634,6 +636,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator: return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive);
|
||||
case IndexCategory: return m_category.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCategory());
|
||||
case IndexIataCode: return m_iataCode.compare(compareValue.getIataCode(), Qt::CaseInsensitive);
|
||||
case IndexFamily: return m_family.compare(compareValue.getFamily(), Qt::CaseInsensitive);
|
||||
case IndexCombinedAircraftType: return m_combinedType.compare(compareValue.getCombinedType(), Qt::CaseInsensitive);
|
||||
@@ -770,6 +773,8 @@ namespace BlackMisc
|
||||
return CAircraftIcaoCode();
|
||||
}
|
||||
|
||||
const int engineCount(json.value(prefix % u"enginecount").toInt(-1));
|
||||
const int categoryId(json.value(prefix % u"idcategory").toInt(-1));
|
||||
const QString designator(json.value(prefix % u"designator").toString());
|
||||
const QString iata(json.value(prefix % u"iata").toString());
|
||||
const QString family(json.value(prefix % u"family").toString());
|
||||
@@ -779,8 +784,8 @@ namespace BlackMisc
|
||||
const QString modelSwift(json.value(prefix % u"modelswift").toString());
|
||||
const QString type(json.value(prefix % u"type").toString());
|
||||
const QString engine(json.value(prefix % u"engine").toString());
|
||||
const int engineCount(json.value(prefix % u"enginecount").toInt(-1));
|
||||
const QString combined(createdCombinedString(type, engineCount, engine));
|
||||
|
||||
QString wtc(json.value(prefix % u"wtc").toString());
|
||||
if (wtc.length() > 1 && wtc.contains("/"))
|
||||
{
|
||||
@@ -800,6 +805,7 @@ namespace BlackMisc
|
||||
real, legacy, military, rank
|
||||
);
|
||||
code.setKeyVersionTimestampFromDatabaseJson(json, prefix);
|
||||
if (categoryId >=0) { code.setCategoryId(categoryId); }
|
||||
return code;
|
||||
}
|
||||
|
||||
@@ -813,7 +819,7 @@ namespace BlackMisc
|
||||
|
||||
QString CAircraftIcaoCode::createdCombinedString(const QString &type, int engineCount, const QString &engine)
|
||||
{
|
||||
const bool valid = engineCount >= 0 && engineCount < 10;
|
||||
const bool valid = (engineCount >= 0 && engineCount < 10);
|
||||
return createdCombinedString(type, valid ? QString::number(engineCount) : "", engine);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef BLACKMISC_AVIATION_AIRCRAFTICAOCODE_H
|
||||
#define BLACKMISC_AVIATION_AIRCRAFTICAOCODE_H
|
||||
|
||||
#include "aircraftcategory.h"
|
||||
#include "blackmisc/db/datastore.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
@@ -39,7 +40,7 @@ namespace BlackMisc
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexAircraftDesignator = BlackMisc::CPropertyIndex::GlobalIndexCAircraftIcaoCode,
|
||||
IndexAircraftDesignator = CPropertyIndex::GlobalIndexCAircraftIcaoCode,
|
||||
IndexIataCode,
|
||||
IndexFamily,
|
||||
IndexCombinedAircraftType,
|
||||
@@ -54,6 +55,7 @@ namespace BlackMisc
|
||||
IndexIsLegacy,
|
||||
IndexIsVtol,
|
||||
IndexRank,
|
||||
IndexCategory,
|
||||
IndexDesignatorManufacturer //!< designator and manufacturer
|
||||
};
|
||||
|
||||
@@ -254,6 +256,15 @@ namespace BlackMisc
|
||||
//! Combined family descriptive string with key
|
||||
QString getCombinedFamilyStringWithKey() const;
|
||||
|
||||
//! Get category
|
||||
const CAircraftCategory &getCategory() const { return m_category; }
|
||||
|
||||
//! Set category
|
||||
void setCategory(const CAircraftCategory &category) { m_category = category; }
|
||||
|
||||
//! Set category id
|
||||
void setCategoryId(int id) { m_category.setDbKey(id); }
|
||||
|
||||
//! All data set?
|
||||
bool hasCompleteData() const;
|
||||
|
||||
@@ -348,7 +359,8 @@ namespace BlackMisc
|
||||
bool m_realWorld = true; //!< real world aircraft
|
||||
bool m_legacy = false; //!< legacy code
|
||||
bool m_military = false; //!< military aircraft?
|
||||
int m_rank = 10; //!< rank among same codes (0 is best)
|
||||
int m_rank = 10; //!< rank among same codes (0 is best)
|
||||
CAircraftCategory m_category; //!< aircraft category
|
||||
|
||||
//! Create a combined string like L2J
|
||||
static QString createdCombinedString(const QString &type, const QString &engineCount, const QString &engine);
|
||||
@@ -368,6 +380,7 @@ namespace BlackMisc
|
||||
BLACK_METAMEMBER(modelDescription),
|
||||
BLACK_METAMEMBER(modelIataDescription),
|
||||
BLACK_METAMEMBER(modelSwiftDescription),
|
||||
BLACK_METAMEMBER(category),
|
||||
BLACK_METAMEMBER(wtc),
|
||||
BLACK_METAMEMBER(military),
|
||||
BLACK_METAMEMBER(realWorld),
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
||||
#include "aircrafticaocodelist.h"
|
||||
#include "aircraftcategorylist.h"
|
||||
#include "blackmisc/range.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
@@ -314,19 +315,29 @@ namespace BlackMisc
|
||||
{
|
||||
const QMap<QString, int> counts(countManufacturers());
|
||||
if (counts.isEmpty()) return { {}, 0 };
|
||||
const auto pair = *std::max_element(counts.keyValueBegin(), counts.keyValueEnd(), [](const auto &a, const auto &b)
|
||||
const auto pair = *std::max_element(counts.keyValueBegin(), counts.keyValueEnd(), [](const auto & a, const auto & b)
|
||||
{
|
||||
return a.second < b.second;
|
||||
});
|
||||
return { pair.first, pair.second };
|
||||
}
|
||||
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncompleteAndDuplicates, CAircraftIcaoCodeList *inconsistent)
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, const CAircraftCategoryList &categories, bool ignoreIncompleteAndDuplicates, CAircraftIcaoCodeList *inconsistent)
|
||||
{
|
||||
CAircraftIcaoCodeList codes;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
const CAircraftIcaoCode icao(CAircraftIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
CAircraftIcaoCode icao(CAircraftIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
const int catId = icao.getCategory().getDbKey();
|
||||
if (!categories.isEmpty() && catId >= 0)
|
||||
{
|
||||
const CAircraftCategory category = categories.findByKey(catId);
|
||||
if (!category.isNull())
|
||||
{
|
||||
icao.setCategory(category);
|
||||
}
|
||||
}
|
||||
|
||||
if (!icao.hasSpecialDesignator() && !icao.hasCompleteData())
|
||||
{
|
||||
if (ignoreIncompleteAndDuplicates) { continue; }
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
class CAircraftCategoryList;
|
||||
|
||||
//! Value object encapsulating a list of ICAO codes.
|
||||
class BLACKMISC_EXPORT CAircraftIcaoCodeList :
|
||||
public CSequence<CAircraftIcaoCode>,
|
||||
@@ -139,7 +141,7 @@ namespace BlackMisc
|
||||
QPair<QString, int> maxCountManufacturer() const;
|
||||
|
||||
//! From our database JSON format
|
||||
static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncompleteAndDuplicates = true, CAircraftIcaoCodeList *inconsistent = nullptr);
|
||||
static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array, const CAircraftCategoryList &categories, bool ignoreIncompleteAndDuplicates = true, CAircraftIcaoCodeList *inconsistent = nullptr);
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user