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,18 +144,23 @@ 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, [ = ]
{ {
this->prefillWithOwnAircraftData(); if (!sGui || sGui->isShuttingDown() || !myself) { return; }
} if (sGui->getIContextSimulator()->isSimulatorAvailable())
else {
{ this->prefillWithOwnAircraftData();
const CAircraftModel model = m_lastAircraftModel.get(); }
const CServer server = m_lastServer.get(); else
CSimulatedAircraft aircraft(model); {
aircraft.setPilot(server.getUser()); const CAircraftModel model = m_lastAircraftModel.get();
this->prefillWithAircraftData(aircraft); const CServer server = m_lastServer.get();
} CSimulatedAircraft aircraft(model);
aircraft.setPilot(server.getUser());
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

@@ -67,11 +67,11 @@ namespace BlackGui
QScopedPointer<Ui::CFlightPlanComponent> ui; QScopedPointer<Ui::CFlightPlanComponent> ui;
CAltitudeDialog *m_altitudeDialog = nullptr; CAltitudeDialog *m_altitudeDialog = nullptr;
BlackMisc::Aviation::CFlightPlan m_sentFlightPlan; //!< My flight plan BlackMisc::Aviation::CFlightPlan m_sentFlightPlan; //!< My flight plan
BlackMisc::Simulation::CAircraftModel m_model; //!< currently used model BlackMisc::Simulation::CAircraftModel m_model; //!< currently used model
BlackMisc::CIdentifier m_identifier { "FlightPlanComponent", this }; //!< Flightplan identifier BlackMisc::CIdentifier m_identifier { "FlightPlanComponent", this }; //!< Flightplan identifier
BlackMisc::CSetting<BlackMisc::Settings::TDirectorySettings> m_directories { this }; //!< the swift directories BlackMisc::CSetting<BlackMisc::Settings::TDirectorySettings> m_directories { this }; //!< the swift directories
BlackMisc::CDataReadOnly<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model BlackMisc::CDataReadOnly<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
BlackMisc::CDataReadOnly<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other) BlackMisc::CDataReadOnly<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
static constexpr int OverlayMessageMs = 5000; static constexpr int OverlayMessageMs = 5000;
@@ -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;