mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 08:55:43 +08:00
Ref T26, Ref T27, utility functions in "value object" classes
This commit is contained in:
@@ -252,6 +252,23 @@ namespace BlackMisc
|
|||||||
return combined.join(", ");
|
return combined.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAircraftIcaoCode::matchesAnyDescription(const QString &candidate) const
|
||||||
|
{
|
||||||
|
if (this->hasModelDescription())
|
||||||
|
{
|
||||||
|
if (this->getModelDescription().contains(candidate, Qt::CaseInsensitive)) { return true; }
|
||||||
|
}
|
||||||
|
if (this->hasModelIataDescription())
|
||||||
|
{
|
||||||
|
if (this->getModelIataDescription().contains(candidate, Qt::CaseInsensitive)) { return true; }
|
||||||
|
}
|
||||||
|
if (this->hasModelSwiftDescription())
|
||||||
|
{
|
||||||
|
if (this->getModelSwiftDescription().contains(candidate, Qt::CaseInsensitive)) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CAircraftIcaoCode::matchesCombinedType(const QString &combinedType) const
|
bool CAircraftIcaoCode::matchesCombinedType(const QString &combinedType) const
|
||||||
{
|
{
|
||||||
const QString cc(combinedType.toUpper().trimmed().replace(' ', '*').replace('-', '*'));
|
const QString cc(combinedType.toUpper().trimmed().replace(' ', '*').replace('-', '*'));
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ namespace BlackMisc
|
|||||||
//! Combined description
|
//! Combined description
|
||||||
QString getCombinedModelDescription() const;
|
QString getCombinedModelDescription() const;
|
||||||
|
|
||||||
|
//! Matches any of the (unempty) descriptions
|
||||||
|
bool matchesAnyDescription(const QString &candidate) const;
|
||||||
|
|
||||||
//! Matches given combined code
|
//! Matches given combined code
|
||||||
//! \remark * can be used as wildcard, e.g. L*J, L**
|
//! \remark * can be used as wildcard, e.g. L*J, L**
|
||||||
bool matchesCombinedType(const QString &combinedType) const;
|
bool matchesCombinedType(const QString &combinedType) const;
|
||||||
|
|||||||
@@ -124,6 +124,14 @@ namespace BlackMisc
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftIcaoCodeList CAircraftIcaoCodeList::findMatchingByAnyDescription(const QString &description) const
|
||||||
|
{
|
||||||
|
return this->findBy([&](const CAircraftIcaoCode & code)
|
||||||
|
{
|
||||||
|
return code.matchesAnyDescription(description);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::findWithIataCode(bool removeWhenSameAsDesignator) const
|
CAircraftIcaoCodeList CAircraftIcaoCodeList::findWithIataCode(bool removeWhenSameAsDesignator) const
|
||||||
{
|
{
|
||||||
return this->findBy([&](const CAircraftIcaoCode & code)
|
return this->findBy([&](const CAircraftIcaoCode & code)
|
||||||
@@ -142,6 +150,14 @@ namespace BlackMisc
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftIcaoCodeList CAircraftIcaoCodeList::findByMilitaryFlag(bool military) const
|
||||||
|
{
|
||||||
|
return this->findBy([&](const CAircraftIcaoCode & code)
|
||||||
|
{
|
||||||
|
return (code.isMilitary() == military);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftIcaoCode CAircraftIcaoCodeList::findFirstByDesignatorAndRank(const QString &designator) const
|
CAircraftIcaoCode CAircraftIcaoCodeList::findFirstByDesignatorAndRank(const QString &designator) const
|
||||||
{
|
{
|
||||||
if (!CAircraftIcaoCode::isValidDesignator(designator)) { return CAircraftIcaoCode(); }
|
if (!CAircraftIcaoCode::isValidDesignator(designator)) { return CAircraftIcaoCode(); }
|
||||||
@@ -269,35 +285,40 @@ namespace BlackMisc
|
|||||||
if (icaoPattern.hasValidDbKey())
|
if (icaoPattern.hasValidDbKey())
|
||||||
{
|
{
|
||||||
const int k = icaoPattern.getDbKey();
|
const int k = icaoPattern.getDbKey();
|
||||||
CAircraftIcaoCode c(this->findByKey(k));
|
const CAircraftIcaoCode c(this->findByKey(k));
|
||||||
if (c.hasCompleteData()) { return c; }
|
if (c.hasCompleteData()) { return c; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// get an initial set of data we can choose from
|
// get an initial set of data we can choose from
|
||||||
const QString d(icaoPattern.getDesignator());
|
const QString designator(icaoPattern.getDesignator());
|
||||||
if (d.isEmpty()) { return CAircraftIcaoCode(); }
|
if (designator.isEmpty()) { return CAircraftIcaoCode(); }
|
||||||
CAircraftIcaoCodeList codes;
|
CAircraftIcaoCodeList codes;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
codes = this->findByDesignator(d);
|
codes = this->findByDesignator(designator);
|
||||||
if (!codes.isEmpty()) break;
|
if (!codes.isEmpty()) break;
|
||||||
|
|
||||||
// now we search if the ICAO designator is actually an IATA code
|
// now we search if the ICAO designator is actually an IATA code
|
||||||
codes = this->findByIataCode(d);
|
codes = this->findByIataCode(designator);
|
||||||
if (!codes.isEmpty()) break;
|
if (!codes.isEmpty()) break;
|
||||||
|
|
||||||
if (d.length() > 4)
|
// search by reduced length
|
||||||
|
if (designator.length() >= 4)
|
||||||
{
|
{
|
||||||
codes = this->findByDesignator(d.left(4));
|
codes = this->findByDesignator(designator.left(4));
|
||||||
if (!codes.isEmpty()) break;
|
if (!codes.isEmpty()) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// still empty, try to find by family
|
// still empty, try to find by family
|
||||||
codes = this->findByFamily(d);
|
codes = this->findByFamily(designator);
|
||||||
if (!codes.isEmpty()) break;
|
if (!codes.isEmpty()) break;
|
||||||
|
|
||||||
// now try to find as ending
|
// now try to find as ending
|
||||||
codes = this->findEndingWith(d);
|
codes = this->findEndingWith(designator);
|
||||||
|
if (!codes.isEmpty()) break;
|
||||||
|
|
||||||
|
// by any descriptionS
|
||||||
|
codes = this->findMatchingByAnyDescription(designator);
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
|
|||||||
@@ -76,12 +76,18 @@ namespace BlackMisc
|
|||||||
//! Find by model description
|
//! Find by model description
|
||||||
CAircraftIcaoCodeList findByDescription(const QString &description) const;
|
CAircraftIcaoCodeList findByDescription(const QString &description) const;
|
||||||
|
|
||||||
|
//! Find matching by any model description
|
||||||
|
CAircraftIcaoCodeList findMatchingByAnyDescription(const QString &description) const;
|
||||||
|
|
||||||
//! Those with IATA code
|
//! Those with IATA code
|
||||||
CAircraftIcaoCodeList findWithIataCode(bool removeWhenSameAsDesignator) const;
|
CAircraftIcaoCodeList findWithIataCode(bool removeWhenSameAsDesignator) const;
|
||||||
|
|
||||||
//! Those with family
|
//! Those with family
|
||||||
CAircraftIcaoCodeList findWithFamily(bool removeWhenSameAsDesignator) const;
|
CAircraftIcaoCodeList findWithFamily(bool removeWhenSameAsDesignator) const;
|
||||||
|
|
||||||
|
//! By military flag
|
||||||
|
CAircraftIcaoCodeList findByMilitaryFlag(bool military) const;
|
||||||
|
|
||||||
//! Find by designator, then best match by rank
|
//! Find by designator, then best match by rank
|
||||||
CAircraftIcaoCode findFirstByDesignatorAndRank(const QString &designator) const;
|
CAircraftIcaoCode findFirstByDesignatorAndRank(const QString &designator) const;
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ namespace BlackMisc
|
|||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class OBJ, class CONTAINER>
|
||||||
|
QStringList ICallsignObjectList<OBJ, CONTAINER>::getCallsignStrings() const
|
||||||
|
{
|
||||||
|
return this->getCallsigns().getCallsignStrings();
|
||||||
|
}
|
||||||
|
|
||||||
template <class OBJ, class CONTAINER>
|
template <class OBJ, class CONTAINER>
|
||||||
CONTAINER ICallsignObjectList<OBJ, CONTAINER>::findByCallsign(const CCallsign &callsign) const
|
CONTAINER ICallsignObjectList<OBJ, CONTAINER>::findByCallsign(const CCallsign &callsign) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ namespace BlackMisc
|
|||||||
//! All callsigns
|
//! All callsigns
|
||||||
BlackMisc::Aviation::CCallsignSet getCallsigns() const;
|
BlackMisc::Aviation::CCallsignSet getCallsigns() const;
|
||||||
|
|
||||||
|
//! Get callsign string list
|
||||||
|
QStringList getCallsignStrings() const;
|
||||||
|
|
||||||
//! Find 0..n stations by callsign
|
//! Find 0..n stations by callsign
|
||||||
CONTAINER findByCallsign(const CCallsign &callsign) const;
|
CONTAINER findByCallsign(const CCallsign &callsign) const;
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ namespace BlackMisc
|
|||||||
CCollection<CCallsign>(other)
|
CCollection<CCallsign>(other)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
QStringList CCallsignSet::getCallsignStrings() const
|
||||||
|
{
|
||||||
|
QStringList callsigns;
|
||||||
|
for (const CCallsign &cs : *this)
|
||||||
|
{
|
||||||
|
callsigns.push_back(cs.asString());
|
||||||
|
}
|
||||||
|
return callsigns;
|
||||||
|
}
|
||||||
|
|
||||||
void CCallsignSet::registerMetadata()
|
void CCallsignSet::registerMetadata()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<BlackMisc::CSequence<CCallsign>>();
|
qRegisterMetaType<BlackMisc::CSequence<CCallsign>>();
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ namespace BlackMisc
|
|||||||
//! Construct from a base class object.
|
//! Construct from a base class object.
|
||||||
CCallsignSet(const CCollection<CCallsign> &other);
|
CCallsignSet(const CCollection<CCallsign> &other);
|
||||||
|
|
||||||
|
//! The callsign strings
|
||||||
|
QStringList getCallsignStrings() const;
|
||||||
|
|
||||||
//! Register metadata
|
//! Register metadata
|
||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -219,6 +219,19 @@ namespace BlackMisc
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftModelList CAircraftModelList::findByCombinedTypeWithColorLivery(const QString &combinedType) const
|
||||||
|
{
|
||||||
|
return this->findByCombinedType(combinedType).findColorLiveries();
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftModelList CAircraftModelList::findColorLiveries() const
|
||||||
|
{
|
||||||
|
return this->findBy([ = ](const CAircraftModel & model)
|
||||||
|
{
|
||||||
|
return model.getLivery().isColorLivery();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftModelList CAircraftModelList::findByMilitaryFlag(bool military) const
|
CAircraftModelList CAircraftModelList::findByMilitaryFlag(bool military) const
|
||||||
{
|
{
|
||||||
return this->findBy([ = ](const CAircraftModel & model)
|
return this->findBy([ = ](const CAircraftModel & model)
|
||||||
|
|||||||
@@ -138,6 +138,12 @@ namespace BlackMisc
|
|||||||
//! Find by combined code, wildcards possible e.g. L*P, *2J
|
//! Find by combined code, wildcards possible e.g. L*P, *2J
|
||||||
CAircraftModelList findByCombinedType(const QString &combinedType) const;
|
CAircraftModelList findByCombinedType(const QString &combinedType) const;
|
||||||
|
|
||||||
|
//! Find aircraft with color livery by combined code, wildcards possible e.g. L*P, *2J
|
||||||
|
CAircraftModelList findByCombinedTypeWithColorLivery(const QString &combinedType) const;
|
||||||
|
|
||||||
|
//! Find models with color liveries
|
||||||
|
CAircraftModelList findColorLiveries() const;
|
||||||
|
|
||||||
//! Find by military flag
|
//! Find by military flag
|
||||||
CAircraftModelList findByMilitaryFlag(bool military) const;
|
CAircraftModelList findByMilitaryFlag(bool military) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user