mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
Ref T111, search for location/name
This commit is contained in:
committed by
Mathew Sutcliffe
parent
58b5dd1278
commit
bb4f0e7a13
@@ -11,11 +11,13 @@
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Geo;
|
||||
|
||||
@@ -38,6 +40,18 @@ namespace BlackMisc
|
||||
m_descriptiveName(descriptiveName), m_icao(icao), m_position(position)
|
||||
{ }
|
||||
|
||||
bool CAirport::matchesLocation(const QString &location) const
|
||||
{
|
||||
if (location.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(location, this->getLocation());
|
||||
}
|
||||
|
||||
bool CAirport::matchesDescriptiveName(const QString &name) const
|
||||
{
|
||||
if (name.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(name, this->getDescriptiveName());
|
||||
}
|
||||
|
||||
void CAirport::updateMissingParts(const CAirport &airport)
|
||||
{
|
||||
if (!this->m_country.hasIsoCode() && airport.getCountry().hasIsoCode()) { this->m_country = airport.getCountry(); }
|
||||
@@ -61,6 +75,7 @@ namespace BlackMisc
|
||||
{
|
||||
CAirport airport(json.value(prefix + "icao").toString());
|
||||
airport.setDescriptiveName(json.value(prefix + "name").toString());
|
||||
airport.setLocation(json.value(prefix + "location").toString());
|
||||
const CCoordinateGeodetic pos(
|
||||
json.value(prefix + "latitude").toDouble(),
|
||||
json.value(prefix + "longitude").toDouble(),
|
||||
@@ -79,11 +94,13 @@ namespace BlackMisc
|
||||
CVariant CAirport::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
return this->m_icao.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexLocation:
|
||||
return CVariant(this->m_location);
|
||||
case IndexDescriptiveName:
|
||||
return CVariant(this->m_descriptiveName);
|
||||
case IndexPosition:
|
||||
@@ -102,12 +119,15 @@ namespace BlackMisc
|
||||
void CAirport::setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAirport>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
this->m_icao.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexLocation:
|
||||
this->setLocation(variant.toQString());
|
||||
break;
|
||||
case IndexDescriptiveName:
|
||||
this->setDescriptiveName(variant.toQString());
|
||||
break;
|
||||
@@ -133,11 +153,13 @@ namespace BlackMisc
|
||||
int CAirport::comparePropertyByIndex(const CPropertyIndex &index, const CAirport &compareValue) const
|
||||
{
|
||||
if (index.isMyself()) { return this->m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao()); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
return this->m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao());
|
||||
case IndexLocation:
|
||||
return this->m_location.compare(compareValue.getLocation(), Qt::CaseInsensitive);
|
||||
case IndexDescriptiveName:
|
||||
return this->m_descriptiveName.compare(compareValue.getDescriptiveName(), Qt::CaseInsensitive);
|
||||
default:
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace BlackMisc
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexIcao = BlackMisc::CPropertyIndex::GlobalIndexCAirport,
|
||||
IndexLocation,
|
||||
IndexDescriptiveName,
|
||||
IndexPosition,
|
||||
IndexCountry,
|
||||
@@ -73,12 +74,24 @@ namespace BlackMisc
|
||||
//! Set ICAO code.
|
||||
void setIcao(const CAirportIcaoCode &icao) { m_icao = icao; }
|
||||
|
||||
//! Get location (e.g. "London")
|
||||
const QString &getLocation() const { return m_location; }
|
||||
|
||||
//! Set location
|
||||
void setLocation(const QString &location) { this->m_location = location; }
|
||||
|
||||
//! Matches location?
|
||||
bool matchesLocation(const QString &location) const;
|
||||
|
||||
//! Get descriptive name
|
||||
QString getDescriptiveName() const { return m_descriptiveName; }
|
||||
const QString &getDescriptiveName() const { return m_descriptiveName; }
|
||||
|
||||
//! Set descriptive name
|
||||
void setDescriptiveName(const QString &name) { this->m_descriptiveName = name; }
|
||||
|
||||
//! Matches name?
|
||||
bool matchesDescriptiveName(const QString &name) const;
|
||||
|
||||
//! Get the position
|
||||
const BlackMisc::Geo::CCoordinateGeodetic &getPosition() const { return m_position; }
|
||||
|
||||
@@ -148,6 +161,7 @@ namespace BlackMisc
|
||||
static CAirport fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
|
||||
|
||||
private:
|
||||
QString m_location;
|
||||
QString m_descriptiveName;
|
||||
bool m_operating = true;
|
||||
CAirportIcaoCode m_icao;
|
||||
@@ -157,6 +171,7 @@ namespace BlackMisc
|
||||
BLACK_METACLASS(
|
||||
CAirport,
|
||||
BLACK_METAMEMBER(icao),
|
||||
BLACK_METAMEMBER(location),
|
||||
BLACK_METAMEMBER(descriptiveName),
|
||||
BLACK_METAMEMBER(position),
|
||||
BLACK_METAMEMBER(country),
|
||||
|
||||
@@ -62,6 +62,23 @@ namespace BlackMisc
|
||||
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);
|
||||
}
|
||||
|
||||
CAirport CAirportList::findFirstByNameOrLocation(const QString &nameOrLocation, const CAirport &ifNotFound) const
|
||||
{
|
||||
if (this->isEmpty() || nameOrLocation.isEmpty()) { return ifNotFound; }
|
||||
CAirportList airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return airport.matchesDescriptiveName(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
|
||||
airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return airport.matchesLocation(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
return ifNotFound;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allIcaoCodes(bool sorted) const
|
||||
{
|
||||
QStringList icaos;
|
||||
|
||||
@@ -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;
|
||||
|
||||
//! Find first by name or location, if not return given value / default
|
||||
CAirport findFirstByNameOrLocation(const QString &nameOrLocation, const CAirport &ifNotFound = CAirport()) const;
|
||||
|
||||
//! Containing an airport with given ICAO code?
|
||||
bool containsAirportWithIcaoCode(const CAirportIcaoCode &icao) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user