Ref T415, allow to manually override FP from simulator

This commit is contained in:
Klaus Basan
2018-11-13 17:21:58 +01:00
parent 42aa521289
commit fe8548a5d4
2 changed files with 42 additions and 19 deletions

View File

@@ -103,6 +103,7 @@ namespace BlackGui
connect(ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::loadFlightPlanFromNetwork); connect(ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::loadFlightPlanFromNetwork);
connect(ui->pb_Reset, &QPushButton::pressed, this, &CFlightPlanComponent::resetFlightPlan); connect(ui->pb_Reset, &QPushButton::pressed, this, &CFlightPlanComponent::resetFlightPlan);
connect(ui->pb_ValidateFlightPlan, &QPushButton::pressed, this, &CFlightPlanComponent::validateFlightPlan); connect(ui->pb_ValidateFlightPlan, &QPushButton::pressed, this, &CFlightPlanComponent::validateFlightPlan);
connect(ui->tb_SyncWithSimulator, &QPushButton::released, this, &CFlightPlanComponent::syncWithSimulator);
connect(ui->pb_Prefill, &QPushButton::pressed, this, &CFlightPlanComponent::anticipateValues); connect(ui->pb_Prefill, &QPushButton::pressed, this, &CFlightPlanComponent::anticipateValues);
connect(ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::currentTextChangedToBuildRemarks); connect(ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::currentTextChangedToBuildRemarks);
@@ -143,7 +144,11 @@ namespace BlackGui
this->buildRemarksString(); this->buildRemarksString();
// prefill some data derived from what was used last // prefill some data derived from what was used last
if (sGui->getIContextSimulator()->isSimulatorSimulating()) const QPointer<CFlightPlanComponent> myself(this);
QTimer::singleShot(2500, this, [ = ]
{
if (!sGui || sGui->isShuttingDown() || !myself) { return; }
if (sGui->getIContextSimulator()->isSimulatorAvailable())
{ {
this->prefillWithOwnAircraftData(); this->prefillWithOwnAircraftData();
} }
@@ -155,6 +160,7 @@ namespace BlackGui
aircraft.setPilot(server.getUser()); aircraft.setPilot(server.getUser());
this->prefillWithAircraftData(aircraft); this->prefillWithAircraftData(aircraft);
} }
});
} }
CFlightPlanComponent::~CFlightPlanComponent() CFlightPlanComponent::~CFlightPlanComponent()
@@ -175,9 +181,9 @@ namespace BlackGui
this->prefillWithAircraftData(ownAircraft); this->prefillWithAircraftData(ownAircraft);
} }
void CFlightPlanComponent::prefillWithAircraftData(const CSimulatedAircraft &aircraft) void CFlightPlanComponent::prefillWithAircraftData(const CSimulatedAircraft &aircraft, bool force)
{ {
if (m_sentFlightPlan.wasSentOrLoaded()) { return; } if (!force && m_sentFlightPlan.wasSentOrLoaded()) { return; }
// only override with valid values // only override with valid values
if (CCallsign::isValidAircraftCallsign(aircraft.getCallsignAsString())) if (CCallsign::isValidAircraftCallsign(aircraft.getCallsignAsString()))
@@ -256,7 +262,7 @@ namespace BlackGui
v = ui->le_Callsign->text().trimmed().toUpper(); v = ui->le_Callsign->text().trimmed().toUpper();
if (v.isEmpty()) if (v.isEmpty())
{ {
messages.push_back(CStatusMessage(this).validationError("Missing '%1'") << ui->lbl_Callsign->text()); // messages.push_back(CStatusMessage(this).validationError("Missing '%1'") << ui->lbl_Callsign->text());
} }
else if (!CCallsign::isValidAircraftCallsign(v)) else if (!CCallsign::isValidAircraftCallsign(v))
{ {
@@ -508,6 +514,8 @@ namespace BlackGui
} }
CFlightPlan fp; CFlightPlan fp;
this->validateAndInitializeFlightPlan(fp); // get data this->validateAndInitializeFlightPlan(fp); // get data
// save as CVariant format
const CVariant variantFp = CVariant::fromValue(fp); const CVariant variantFp = CVariant::fromValue(fp);
const QString json(variantFp.toJsonString()); const QString json(variantFp.toJsonString());
const bool ok = CFileUtils::writeStringToFile(json, fileName); const bool ok = CFileUtils::writeStringToFile(json, fileName);
@@ -635,10 +643,10 @@ namespace BlackGui
{ {
if (ui->cb_Heavy->isChecked()) if (ui->cb_Heavy->isChecked())
{ {
const QPointer<CFlightPlanComponent> guard(this); const QPointer<CFlightPlanComponent> myself(this);
QTimer::singleShot(10, this, [ = ] QTimer::singleShot(10, this, [ = ]
{ {
if (guard.isNull()) { return; } if (!myself) { return; }
ui->cb_Tcas->setChecked(false); ui->cb_Tcas->setChecked(false);
this->buildPrefixIcaoSuffix(); this->buildPrefixIcaoSuffix();
}); });
@@ -666,8 +674,10 @@ namespace BlackGui
{ {
const CAircraftIcaoCode icao = this->getAircraftIcaoCode(); const CAircraftIcaoCode icao = this->getAircraftIcaoCode();
if (!icao.isLoadedFromDb()) { return; } if (!icao.isLoadedFromDb()) { return; }
QPointer<CFlightPlanComponent> myself(this);
QTimer::singleShot(25, this, [ = ] QTimer::singleShot(25, this, [ = ]
{ {
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
const bool heavy = icao.getWtc().startsWith("H"); const bool heavy = icao.getWtc().startsWith("H");
ui->cb_Heavy->setChecked(heavy); ui->cb_Heavy->setChecked(heavy);
if (heavy) { ui->cb_Tcas->setChecked(false); } if (heavy) { ui->cb_Tcas->setChecked(false); }
@@ -675,6 +685,16 @@ namespace BlackGui
}); });
} }
void CFlightPlanComponent::syncWithSimulator()
{
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return; }
const QMessageBox::StandardButton reply = QMessageBox::question(this, QStringLiteral("Override aircraft data"), QStringLiteral("Override aircraft ICAO data from simulator"), QMessageBox::Yes | QMessageBox::No);
if (reply != QMessageBox::Yes) { return; }
const CSimulatedAircraft aircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
this->prefillWithAircraftData(aircraft, true);
}
QString CFlightPlanComponent::getPrefix() const QString CFlightPlanComponent::getPrefix() const
{ {
if (ui->cb_Heavy->isChecked()) { return QStringLiteral("H"); } if (ui->cb_Heavy->isChecked()) { return QStringLiteral("H"); }

View File

@@ -91,7 +91,7 @@ namespace BlackGui
void prefillWithOwnAircraftData(); void prefillWithOwnAircraftData();
//! Prefill with aircraft data //! Prefill with aircraft data
void prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, bool force = false);
//! Prefill with user data //! Prefill with user data
void prefillWithUserData(const BlackMisc::Network::CUser &user); void prefillWithUserData(const BlackMisc::Network::CUser &user);
@@ -153,6 +153,9 @@ namespace BlackGui
//! Aircraft type changed //! Aircraft type changed
void aircraftTypeChanged(); void aircraftTypeChanged();
//! Sync.with simulator
void syncWithSimulator();
//! Get prefix //! Get prefix
QString getPrefix() const; QString getPrefix() const;