mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
refs #533, fix callsign validation and split into functions for ATC/aircraft
This commit is contained in:
@@ -785,7 +785,9 @@ namespace BlackCore
|
||||
void CAirspaceMonitor::icaoOrFsdDataReceived(const CCallsign &callsign, const QString &aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &livery, const QString &modelString, CAircraftModel::ModelType type)
|
||||
{
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "not in main thread");
|
||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "no callsign");
|
||||
BLACK_VERIFY_X(callsign.isValid(), Q_FUNC_INFO, "invalid callsign");
|
||||
if (!callsign.isValid()) { return; }
|
||||
|
||||
if (!this->m_connected) { return; }
|
||||
if (aircraftIcaoDesignator.isEmpty() && airlineIcaoDesignator.isEmpty() && livery.isEmpty()) { return; }
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace BlackGui
|
||||
void CFlightPlanComponent::prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft)
|
||||
{
|
||||
// only override with valid values
|
||||
if (CCallsign::isValidCallsign(ownAircraft.getCallsignAsString()))
|
||||
if (CCallsign::isValidAircraftCallsign(ownAircraft.getCallsignAsString()))
|
||||
{
|
||||
this->ui->le_Callsign->setText(ownAircraft.getCallsign().asString());
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ namespace BlackGui
|
||||
bool validIcaoDesignator = CAircraftIcaoCode::isValidDesignator(values.ownAircraftIcaoTypeDesignator);
|
||||
this->ui->lblp_AircraftIcaoDesignator->setTicked(validIcaoDesignator);
|
||||
|
||||
bool validCallsign = CCallsign::isValidCallsign(values.ownCallsign);
|
||||
bool validCallsign = CCallsign::isValidAircraftCallsign(values.ownCallsign);
|
||||
this->ui->lblp_Callsign->setTicked(validCallsign);
|
||||
|
||||
bool validSimulatorModel = !values.ownAircraftSimulatorModel.isEmpty();
|
||||
@@ -486,7 +486,7 @@ namespace BlackGui
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).validationWarning("Reverse lookup for %1 failed") << model.getModelString();
|
||||
CLogMessage(this).validationInfo("Reverse lookup for %1 failed, set data manually") << model.getModelString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace BlackGui
|
||||
{
|
||||
Q_ASSERT(getIContextSimulator());
|
||||
QString cs = ui->le_Callsign->text().trimmed();
|
||||
if (!CCallsign::isValidCallsign(cs))
|
||||
if (!CCallsign::isValidAircraftCallsign(cs))
|
||||
{
|
||||
CLogMessage(this).validationError("Invalid callsign for mapping");
|
||||
return;
|
||||
|
||||
@@ -187,26 +187,60 @@ namespace BlackMisc
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CCallsign::isValidCallsign(const QString &callsign)
|
||||
bool CCallsign::isValid() const
|
||||
{
|
||||
switch (m_typeHint)
|
||||
{
|
||||
case Atc:
|
||||
return isValidAtcCallsign(*this);
|
||||
case Aircraft:
|
||||
return isValidAircraftCallsign(*this);
|
||||
default:
|
||||
return !this->isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
bool CCallsign::isValidAircraftCallsign(const QString &callsign)
|
||||
{
|
||||
// We allow all number callsigns
|
||||
if (callsign.length() < 2 || callsign.length() > 10) { return false; }
|
||||
|
||||
// We allow all number callsigns
|
||||
static QThreadStorage<QRegularExpression> tsRegex;
|
||||
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z0-9]*$")); }
|
||||
const QRegularExpression ®exp = tsRegex.localData();
|
||||
return (regexp.match(callsign).hasMatch());
|
||||
}
|
||||
|
||||
bool CCallsign::isValidAircraftCallsign(const CCallsign &callsign)
|
||||
{
|
||||
return isValidAircraftCallsign(callsign.asString());
|
||||
}
|
||||
|
||||
bool CCallsign::isValidAtcCallsign(const QString &callsign)
|
||||
{
|
||||
if (callsign.length() < 2 || callsign.length() > 10) { return false; }
|
||||
|
||||
// We allow all number callsigns
|
||||
static QThreadStorage<QRegularExpression> tsRegex;
|
||||
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z0-9_]*$")); }
|
||||
const QRegularExpression ®exp = tsRegex.localData();
|
||||
return (regexp.match(callsign).hasMatch());
|
||||
}
|
||||
|
||||
bool CCallsign::isValidAtcCallsign(const CCallsign &callsign)
|
||||
{
|
||||
return isValidAtcCallsign(callsign.asString());
|
||||
}
|
||||
|
||||
const QStringList &CCallsign::atcCallsignSuffixes()
|
||||
{
|
||||
static const QStringList a( { "APP", "GND", "TWR", "DEL", "CTR" });
|
||||
static const QStringList a({ "APP", "GND", "TWR", "DEL", "CTR" });
|
||||
return a;
|
||||
}
|
||||
|
||||
const QStringList &CCallsign::atcAlikeCallsignSuffixes()
|
||||
{
|
||||
static const QStringList a( { "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS" });
|
||||
static const QStringList a({ "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS" });
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace BlackMisc
|
||||
//! Supervisor?
|
||||
bool isSupervisorCallsign() const;
|
||||
|
||||
//! Get callsign.
|
||||
//! Get callsign (normalized)
|
||||
const QString &asString() const { return this->m_callsign; }
|
||||
|
||||
//! Get callsign.
|
||||
@@ -121,7 +121,19 @@ namespace BlackMisc
|
||||
int comparePropertyByIndex(const CCallsign &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidCallsign(const QString &callsign);
|
||||
bool isValid() const;
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidAircraftCallsign(const QString &callsign);
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidAircraftCallsign(const CCallsign &callsign);
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidAtcCallsign(const QString &callsign);
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidAtcCallsign(const CCallsign &callsign);
|
||||
|
||||
//! List of real ATC suffixes (e.g. TWR);
|
||||
static const QStringList &atcCallsignSuffixes();
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace BlackMisc
|
||||
bool hasAircraftAndAirlineDesignator() const;
|
||||
|
||||
//! Valid callsign?
|
||||
bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidCallsign(this->getCallsign().asString()); }
|
||||
bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidAircraftCallsign(this->getCallsign().asString()); }
|
||||
|
||||
//! Callsign not empty, no further checks
|
||||
bool hasCallsign() const { return !getCallsign().isEmpty(); }
|
||||
|
||||
Reference in New Issue
Block a user