mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T417, flight plan follow ups
* fixed eventfilter, only allow ASCII values, disable in read only mode * set remarks values "from external" * set SELCAL value
This commit is contained in:
committed by
Mat Sutcliffe
parent
35b0836754
commit
be3283305a
@@ -108,21 +108,25 @@ namespace BlackGui
|
||||
ui->le_EquipmentSuffix->setCompleter(completer);
|
||||
|
||||
CUpperCaseEventFilter *ef = new CUpperCaseEventFilter(ui->pte_Route);
|
||||
ef->setOnlyAscii();
|
||||
ui->pte_Route->installEventFilter(ef);
|
||||
ef = new CUpperCaseEventFilter(ui->pte_Remarks);
|
||||
ef->setOnlyAscii();
|
||||
ui->pte_Remarks->installEventFilter(ef);
|
||||
ef = new CUpperCaseEventFilter(ui->pte_AdditionalRemarks);
|
||||
ef->setOnlyAscii();
|
||||
ui->pte_AdditionalRemarks->installEventFilter(ef);
|
||||
ef = new CUpperCaseEventFilter(ui->pte_RemarksGenerated);
|
||||
ui->pte_RemarksGenerated->installEventFilter(ef);
|
||||
// readonly
|
||||
// ef = new CUpperCaseEventFilter(ui->pte_RemarksGenerated);
|
||||
// ui->pte_RemarksGenerated->installEventFilter(ef);
|
||||
|
||||
// connect
|
||||
connect(ui->pb_Send, &QPushButton::pressed, this, &CFlightPlanComponent::sendFlightPlan, Qt::QueuedConnection);
|
||||
connect(ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::loadFlightPlanFromNetwork, Qt::QueuedConnection);
|
||||
connect(ui->pb_Send, &QPushButton::pressed, this, &CFlightPlanComponent::sendFlightPlan, Qt::QueuedConnection);
|
||||
connect(ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::loadFlightPlanFromNetwork, Qt::QueuedConnection);
|
||||
connect(ui->pb_Reset, &QPushButton::pressed, this, &CFlightPlanComponent::resetFlightPlan, Qt::QueuedConnection);
|
||||
connect(ui->pb_ValidateFlightPlan, &QPushButton::pressed, this, &CFlightPlanComponent::validateFlightPlan, Qt::QueuedConnection);
|
||||
connect(ui->tb_SyncWithSimulator, &QPushButton::released, this, &CFlightPlanComponent::syncWithSimulator, Qt::QueuedConnection);
|
||||
connect(ui->pb_Prefill, &QPushButton::pressed, this, &CFlightPlanComponent::anticipateValues, Qt::QueuedConnection);
|
||||
connect(ui->pb_Prefill, &QPushButton::pressed, this, &CFlightPlanComponent::anticipateValues, Qt::QueuedConnection);
|
||||
connect(ui->pb_SimBrief, &QPushButton::pressed, this, &CFlightPlanComponent::loadFromSimBrief, Qt::QueuedConnection);
|
||||
|
||||
connect(ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::currentTextChangedToBuildRemarks, Qt::QueuedConnection);
|
||||
@@ -267,6 +271,10 @@ namespace BlackGui
|
||||
this->showOverlayMessage(m);
|
||||
}
|
||||
|
||||
if (!flightPlan.getRemarks().isEmpty())
|
||||
{
|
||||
this->setRemarksUIValues(flightPlan.getRemarks());
|
||||
}
|
||||
}
|
||||
|
||||
const CLogCategoryList &CFlightPlanComponent::getLogCategories()
|
||||
@@ -931,6 +939,47 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CFlightPlanComponent::setRemarksUIValues(const QString &remarks)
|
||||
{
|
||||
if (remarks.isEmpty()) { return; }
|
||||
const QString r = remarks.toUpper();
|
||||
|
||||
if (remarks.contains("/V"))
|
||||
{
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilitiesFirstPage, "FULL");
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilities, "FULL");
|
||||
}
|
||||
else if (remarks.contains("/T"))
|
||||
{
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilitiesFirstPage, "TEXT ONLY");
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilities, "FULL");
|
||||
}
|
||||
else if (remarks.contains("/R"))
|
||||
{
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilitiesFirstPage, "RECEIVE");
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_VoiceCapabilities, "RECEIVE");
|
||||
}
|
||||
|
||||
if (remarks.contains("NAV/GPSRNAV"))
|
||||
{
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_NavigationEquipment, "GPS OR FMC");
|
||||
}
|
||||
else if (remarks.contains("NAV/VORNDB"))
|
||||
{
|
||||
CGuiUtility::setComboBoxValueByContainingString(ui->cb_NavigationEquipment, "DIRECT VOR");
|
||||
}
|
||||
|
||||
const int selcal = remarks.indexOf("SEL/");
|
||||
if (selcal >= 0 && remarks.length() > selcal + 7)
|
||||
{
|
||||
const QString code = remarks.mid(selcal + 4, 4);
|
||||
if (code.length() == 4)
|
||||
{
|
||||
ui->frp_SelcalCode->setSelcal(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CFlightPlanComponent::loadFromSimBrief()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
@@ -1059,7 +1108,10 @@ namespace BlackGui
|
||||
{
|
||||
ui->cb_VoiceCapabilities->setCurrentText(text);
|
||||
const QString r = CFlightPlanRemarks::replaceVoiceCapabilities(CFlightPlanRemarks::textToVoiceCapabilitiesRemarks(text), ui->pte_Remarks->toPlainText());
|
||||
ui->pte_Remarks->setPlainText(r);
|
||||
if (ui->pte_Remarks->toPlainText() != r)
|
||||
{
|
||||
ui->pte_Remarks->setPlainText(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -224,6 +224,9 @@ namespace BlackGui
|
||||
//! Update the remarks histories
|
||||
void updateRemarksHistories();
|
||||
|
||||
//! Set remark values
|
||||
void setRemarksUIValues(const QString &remarks);
|
||||
|
||||
//! Load from SimBrief
|
||||
void loadFromSimBrief();
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,21 +24,30 @@ namespace BlackGui
|
||||
// processing proceed as it may be a control (e.g. cursor movement)
|
||||
// key. Otherwise convert the text to upper case and insert it at
|
||||
// the current cursor position.
|
||||
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>(object);
|
||||
if (!pte) { return false; }
|
||||
if (pte->isReadOnly()) { return false; }
|
||||
|
||||
if (e->text().length() == 1)
|
||||
{
|
||||
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>(object);
|
||||
if (!pte) { return false; }
|
||||
|
||||
const QChar c = e->text().front();
|
||||
if (!c.isLower()) { return false; }
|
||||
if (!c.isLetter()) { return false; }
|
||||
if (m_illegalChars.contains(c)) { return true; }
|
||||
if (c.isLetter())
|
||||
{
|
||||
const ushort unicode = c.unicode();
|
||||
if (m_onlyAscii && unicode > 127) { return true; }
|
||||
|
||||
pte->insertPlainText(e->text().toUpper());
|
||||
|
||||
// return true to prevent further processing
|
||||
return true;
|
||||
}
|
||||
}
|
||||
pte->insertPlainText(e->text().toUpper());
|
||||
// return true to prevent further processing
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// all codes like backspace etc.
|
||||
return false;
|
||||
}
|
||||
} // length
|
||||
} // key event
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,19 @@ namespace BlackGui
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
//! Not allowed characters
|
||||
void setIllegalCharacters(const QString &illegal) { m_illegalChars = illegal; }
|
||||
|
||||
//! Allow only ASCII
|
||||
void setOnlyAscii() { m_onlyAscii = true; }
|
||||
|
||||
protected:
|
||||
//! Filter
|
||||
bool eventFilter(QObject *object, QEvent *event);
|
||||
|
||||
private:
|
||||
QString m_illegalChars;
|
||||
bool m_onlyAscii = false;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -245,6 +245,36 @@ namespace BlackGui
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CGuiUtility::setComboBoxValueByContainingString(QComboBox *box, const QString &candidate, const QString &unspecified)
|
||||
{
|
||||
if (!box) { return false; }
|
||||
if (!candidate.isEmpty())
|
||||
{
|
||||
for (int i = 0; i < box->count(); i++)
|
||||
{
|
||||
const QString t(box->itemText(i));
|
||||
if (t.contains(candidate, Qt::CaseInsensitive))
|
||||
{
|
||||
box->setCurrentIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found
|
||||
if (unspecified.isEmpty()) { return false; }
|
||||
for (int i = 0; i < box->count(); i++)
|
||||
{
|
||||
const QString t(box->itemText(i));
|
||||
if (t.contains(unspecified, Qt::CaseInsensitive))
|
||||
{
|
||||
box->setCurrentIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CGuiUtility::hasSwiftVariantMimeType(const QMimeData *mime)
|
||||
{
|
||||
return mime && mime->hasFormat(swiftJsonDragAndDropMimeType());
|
||||
|
||||
@@ -100,6 +100,9 @@ namespace BlackGui
|
||||
//! Find best match in comboBox
|
||||
static bool setComboBoxValueByStartingString(QComboBox *box, const QString &candidate, const QString &unspecified = QString());
|
||||
|
||||
//! Find best match in comboBox
|
||||
static bool setComboBoxValueByContainingString(QComboBox *box, const QString &candidate, const QString &unspecified = QString());
|
||||
|
||||
//! Mime data with swift type
|
||||
static bool hasSwiftVariantMimeType(const QMimeData *mime);
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ namespace BlackMisc
|
||||
if (parse) { this->parseFlightPlanRemarks(); }
|
||||
}
|
||||
|
||||
bool CFlightPlanRemarks::setSelcalCode(const QString &selcal)
|
||||
{
|
||||
if (m_selcalCode == selcal || selcal.length() != 4) { return false; }
|
||||
const QString r = CFlightPlanRemarks::replaceRemark(m_remarks, QStringLiteral("SEL/"), QStringLiteral("SEL/%1").arg(selcal));
|
||||
m_remarks = r;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CFlightPlanRemarks::setVoiceCapabilities(const CVoiceCapabilities &capabilities)
|
||||
{
|
||||
m_voiceCapabilities = capabilities;
|
||||
@@ -67,9 +75,9 @@ namespace BlackMisc
|
||||
const QString s =
|
||||
(m_registration.isEmpty() ? QString() : u"reg.: " % m_registration.toQString(i18n))
|
||||
% (!this->hasValidAirlineIcao() ? QString() : u" airline: " % m_airlineIcao.getDesignator())
|
||||
% (m_radioTelephony.isEmpty() ? QString() : u" radio tel.:" % m_radioTelephony)
|
||||
% (m_flightOperator.isEmpty() ? QString() : u" operator: " % m_flightOperator)
|
||||
% (!m_selcalCode.isValid() ? QString() : u" SELCAL: " % m_selcalCode.getCode())
|
||||
% (m_radioTelephony.isEmpty() ? QString() : u" radio tel.:" % m_radioTelephony)
|
||||
% (m_flightOperator.isEmpty() ? QString() : u" operator: " % m_flightOperator)
|
||||
% (!m_selcalCode.isValid() ? QString() : u" SELCAL: " % m_selcalCode.getCode())
|
||||
% u" voice: " % m_voiceCapabilities.toQString(i18n);
|
||||
return s.simplified().trimmed();
|
||||
}
|
||||
@@ -111,13 +119,13 @@ namespace BlackMisc
|
||||
m_isParsed = true;
|
||||
if (m_remarks.isEmpty()) { return; }
|
||||
const QString remarks = m_remarks.toUpper();
|
||||
const QString callsign = CCallsign::unifyCallsign(this->cut(remarks, "REG/")); // registration is a callsign
|
||||
const QString callsign = CCallsign::unifyCallsign(this->getRemark(remarks, "REG/")); // registration is a callsign
|
||||
if (CCallsign::isValidAircraftCallsign(callsign)) { m_registration = CCallsign(callsign, CCallsign::Aircraft); }
|
||||
m_voiceCapabilities = m_voiceCapabilities.isUnknown() ? CVoiceCapabilities(m_remarks) : m_voiceCapabilities;
|
||||
m_flightOperator = this->cut(remarks, "OPR/"); // operator, e.g. British airways, sometimes people use ICAO code here
|
||||
m_selcalCode = CSelcal(this->cut(remarks, "SEL/"));
|
||||
m_radioTelephony = cut(remarks, "CALLSIGN/"); // used similar to radio telephony
|
||||
if (m_radioTelephony.isEmpty()) { m_radioTelephony = cut(remarks, "RT/"); }
|
||||
m_flightOperator = this->getRemark(remarks, "OPR/"); // operator, e.g. British airways, sometimes people use ICAO code here
|
||||
m_selcalCode = CSelcal(this->getRemark(remarks, "SEL/"));
|
||||
m_radioTelephony = getRemark(remarks, "CALLSIGN/"); // used similar to radio telephony
|
||||
if (m_radioTelephony.isEmpty()) { m_radioTelephony = getRemark(remarks, "RT/"); }
|
||||
if (!m_flightOperator.isEmpty() && CAirlineIcaoCode::isValidAirlineDesignator(m_flightOperator))
|
||||
{
|
||||
// if people use ICAO code as flight operator swap with airline ICAO
|
||||
@@ -151,7 +159,7 @@ namespace BlackMisc
|
||||
this->parseFlightPlanRemarks(true);
|
||||
}
|
||||
|
||||
QString CFlightPlanRemarks::cut(const QString &remarks, const QString &marker)
|
||||
QString CFlightPlanRemarks::getRemark(const QString &remarks, const QString &marker)
|
||||
{
|
||||
const int maxIndex = remarks.size() - 1;
|
||||
int f = remarks.indexOf(marker);
|
||||
@@ -168,12 +176,32 @@ namespace BlackMisc
|
||||
int to1 = remarks.indexOf(nextMarker, f + 1); // for case 2,3
|
||||
if (to1 < 0) { to1 = maxIndex + 1; }
|
||||
int to2 = remarks.indexOf('/', f + 1); // for case 1
|
||||
if (to2 < 0) { to2 = maxIndex + 1; } // no more end markes, ends after last character
|
||||
if (to2 < 0) { to2 = maxIndex + 1; } // no more end markers, ends after last character
|
||||
const int to = qMin(to1, to2);
|
||||
const QString cut = remarks.mid(f, to - f).simplified();
|
||||
return cut;
|
||||
}
|
||||
|
||||
QString CFlightPlanRemarks::replaceRemark(const QString &remarks, const QString &marker, const QString &newRemark)
|
||||
{
|
||||
QString r(remarks);
|
||||
const int maxIndex = remarks.size() - 1;
|
||||
int f = remarks.indexOf(marker);
|
||||
if (f >= 0)
|
||||
{
|
||||
f += marker.length();
|
||||
if (maxIndex <= f) { return remarks; }
|
||||
thread_local const QRegularExpression nextMarker("\\s+\\w*/|$");
|
||||
int to1 = remarks.indexOf(nextMarker, f + 1); // for case 2,3
|
||||
if (to1 < 0) { to1 = maxIndex + 1; }
|
||||
int to2 = remarks.indexOf('/', f + 1); // for case 1
|
||||
if (to2 < 0) { to2 = maxIndex + 1; } // no more end markers, ends after last character
|
||||
const int to = qMin(to1, to2);
|
||||
r.remove(f, to - f);
|
||||
}
|
||||
return r.isEmpty() ? newRemark : r % u" " % newRemark;
|
||||
}
|
||||
|
||||
const CLogCategoryList &CFlightPlan::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats { CLogCategory::flightPlan() };
|
||||
@@ -538,11 +566,24 @@ namespace BlackMisc
|
||||
const int b = equipment.indexOf('-');
|
||||
const int e = equipment.indexOf('/');
|
||||
|
||||
CFlightPlanRemarks r = fp.getFlightPlanRemarks();
|
||||
bool remarksChanged = false;
|
||||
if (e > b && e >= 0 && b >= 0 && equipment.size() > e)
|
||||
{
|
||||
CFlightPlanRemarks r = fp.getFlightPlanRemarks();
|
||||
const QString icao = equipment.mid(b + 1, e - b - 1);
|
||||
r.setIcaoEquipmentCodes(icao);
|
||||
remarksChanged = true;
|
||||
}
|
||||
|
||||
const QString selcal = aircraft.firstChildElement("selcal").text();
|
||||
if (selcal.length() == 4)
|
||||
{
|
||||
const bool c = r.setSelcalCode(selcal);
|
||||
remarksChanged = c || remarksChanged;
|
||||
}
|
||||
|
||||
if (remarksChanged)
|
||||
{
|
||||
fp.setFlightPlanRemarks(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace BlackMisc
|
||||
//! SELCAL code
|
||||
const CSelcal &getSelcalCode() const { return m_selcalCode; }
|
||||
|
||||
//! SELCAL code
|
||||
bool setSelcalCode(const QString &selcal);
|
||||
|
||||
//! Get registration (a callsign, but normally not the flight callsign)
|
||||
const CCallsign &getRegistration() const { return m_registration; }
|
||||
|
||||
@@ -141,7 +144,10 @@ namespace BlackMisc
|
||||
);
|
||||
|
||||
//! Cut the remarks part
|
||||
static QString cut(const QString &remarks, const QString &marker);
|
||||
static QString getRemark(const QString &remarks, const QString &marker);
|
||||
|
||||
//! Replace a remark part
|
||||
static QString replaceRemark(const QString &remarks, const QString &marker, const QString &newRemark);
|
||||
};
|
||||
|
||||
//! Value object for a flight plan
|
||||
|
||||
Reference in New Issue
Block a user