diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index 602aeb151..fe4674411 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -128,8 +129,12 @@ namespace BlackGui 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_SimBrief, &QPushButton::pressed, this, &CFlightPlanComponent::loadFromSimBrief, 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->pb_SaveTemplate, &QPushButton::released, this, &CFlightPlanComponent::saveTemplateToDisk, Qt::QueuedConnection); + connect(ui->pb_LoadTemplate, &QPushButton::released, this, &CFlightPlanComponent::loadTemplateFromDisk, Qt::QueuedConnection); + connect(ui->pb_ClearTemplate, &QPushButton::released, this, &CFlightPlanComponent::clearTemplate, Qt::QueuedConnection); connect(ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::currentTextChangedToBuildRemarks, Qt::QueuedConnection); connect(ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::syncVoiceComboBoxes, Qt::QueuedConnection); @@ -176,6 +181,8 @@ namespace BlackGui QTimer::singleShot(2500, this, [ = ] { if (!sGui || sGui->isShuttingDown() || !myself) { return; } + + this->loadTemplateFromDisk(); if (sGui->getIContextSimulator()->isSimulatorAvailable()) { this->prefillWithOwnAircraftData(); @@ -581,6 +588,20 @@ namespace BlackGui } } + void CFlightPlanComponent::loadTemplateFromDisk() + { + const QFile f(this->getTemplateName()); + if (!f.exists()) { return; } + + CStatusMessageList msgs; + CFlightPlan fp = CFlightPlan::loadFromMultipleFormats(f.fileName(), &msgs); + if (!fp.hasCallsign()) { fp.setCallsign(ui->le_Callsign->text()); } // set callsign if it wasn't set + if (msgs.isSuccess()) + { + this->fillWithFlightPlanData(fp); + } + } + void CFlightPlanComponent::saveToDisk() { CStatusMessage m; @@ -605,13 +626,7 @@ namespace BlackGui if (ret != QMessageBox::Save) { return; } } - CFlightPlan fp; - this->validateAndInitializeFlightPlan(fp); // get data - - // save as CVariant format - const CVariant variantFp = CVariant::fromValue(fp); - const QString json(variantFp.toJsonString()); - const bool ok = CFileUtils::writeStringToFile(json, fileName); + const bool ok = this->saveFPToDisk(fileName); if (ok) { m = CStatusMessage(this, CStatusMessage::SeverityInfo, u"Written " % fileName, true); @@ -626,6 +641,53 @@ namespace BlackGui if (m.isFailure()) { CLogMessage::preformatted(m); } } + bool CFlightPlanComponent::saveFPToDisk(const QString &fileName) + { + CFlightPlan fp; + const CStatusMessageList msgs = this->validateAndInitializeFlightPlan(fp); // get data + // if (msgs.hasErrorMessages()) { return false; } + Q_UNUSED(msgs) + + // save as CVariant format + const CVariant variantFp = CVariant::fromValue(fp); + const QString json(variantFp.toJsonString()); + const bool ok = CFileUtils::writeStringToFile(json, fileName); + + return ok; + } + + void CFlightPlanComponent::saveTemplateToDisk() + { + const QString fn = this->getTemplateName(); + const bool ok = this->saveFPToDisk(fn); + if (ok) + { + CLogMessage(this).info(u"Saved FP template '%1'") << fn; + } + else + { + CLogMessage(this).warning(u"Saving FP template '%1' failed") << fn; + } + } + + void CFlightPlanComponent::clearTemplate() + { + QFile f(this->getTemplateName()); + if (!f.exists()) { return; } + const bool r = f.remove(); + if (r) { CLogMessage(this).info(u"Deleted FP template '%1'") << f.fileName(); } + } + + QString CFlightPlanComponent::getTemplateName() const + { + const QString fn = + CFileUtils::appendFilePathsAndFixUnc( + CDirectoryUtils::normalizedApplicationDataDirectory(), + QStringLiteral("swiftFlightPlanTemplate.json") + ); + return fn; + } + void CFlightPlanComponent::setSelcalInOwnAircraft() { if (!sGui || !sGui->getIContextOwnAircraft()) { return; } diff --git a/src/blackgui/components/flightplancomponent.h b/src/blackgui/components/flightplancomponent.h index 80446ed76..3c3848dd6 100644 --- a/src/blackgui/components/flightplancomponent.h +++ b/src/blackgui/components/flightplancomponent.h @@ -146,9 +146,24 @@ namespace BlackGui //! Load from disk void loadFromDisk(); + //! Load template from disk + void loadTemplateFromDisk(); + //! Save to disk void saveToDisk(); + //! Save FP to disk + bool saveFPToDisk(const QString &fileName); + + //! Save template to disk + void saveTemplateToDisk(); + + //! Clear template + void clearTemplate(); + + //! Get the template name (full path and file) + QString getTemplateName() const; + //! Set SELCAL in own aircrafr void setSelcalInOwnAircraft(); diff --git a/src/blackgui/components/flightplancomponent.ui b/src/blackgui/components/flightplancomponent.ui index dcf8570ab..49031df2c 100644 --- a/src/blackgui/components/flightplancomponent.ui +++ b/src/blackgui/components/flightplancomponent.ui @@ -42,9 +42,9 @@ 0 - 0 - 371 - 504 + -71 + 368 + 548 @@ -653,34 +653,6 @@ 3 - - - - strict check - - - strict &check - - - - - - - SimBrief - - - - - - - &Reset - - - - :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png - - - @@ -695,6 +667,17 @@ + + + + &Reset + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + @@ -709,17 +692,24 @@ - - + + - Send flight plan to network + strict check - Send + strict &check + + + + + + + &Validate - :/diagona/icons/diagona/icons/network-cloud.png:/diagona/icons/diagona/icons/network-cloud.png + :/diagona/icons/diagona/icons/abacus.png:/diagona/icons/diagona/icons/abacus.png @@ -737,6 +727,27 @@ + + + + SimBrief + + + + + + + Send flight plan to network + + + Send + + + + :/diagona/icons/diagona/icons/network-cloud.png:/diagona/icons/diagona/icons/network-cloud.png + + + @@ -751,14 +762,24 @@ - - + + - &Validate + Save template - - - :/diagona/icons/diagona/icons/abacus.png:/diagona/icons/diagona/icons/abacus.png + + + + + + Clear template + + + + + + + Load template @@ -799,7 +820,7 @@ 0 0 382 - 480 + 477 @@ -1224,21 +1245,16 @@ p, li { white-space: pre-wrap; } sa_FlightPlanTabMain - cb_FlightRule - le_Callsign - tb_SyncWithSimulator - le_AircraftType - le_CruiseTrueAirspeed cb_Heavy cb_Tcas le_PrefixIcaoSuffix le_EquipmentSuffix tb_HelpEquipment + pte_Route le_OriginAirport le_TakeOffTimePlanned lep_CrusingAltitude tb_AltitudeDialog - pte_Route le_DestinationAirport le_EstimatedTimeEnroute le_FuelOnBoard @@ -1251,6 +1267,18 @@ p, li { white-space: pre-wrap; } le_PilotsName le_PilotsHomeBase le_LastSent + pb_Prefill + pb_Reset + pb_ValidateFlightPlan + pb_Send + pb_Download + pb_SimBrief + pb_SaveDisk + pb_LoadDisk + cb_StrictCheck + pb_SaveTemplate + pb_LoadTemplate + pb_ClearTemplate sa_RemarksGenerator le_AirlineOperator le_AircraftRegistration @@ -1263,8 +1291,13 @@ p, li { white-space: pre-wrap; } pte_RemarksGenerated pb_AddRemarks pte_AdditionalRemarks - tbr_EquipmentCodes pb_CopyOver + tbr_EquipmentCodes + le_CruiseTrueAirspeed + tb_SyncWithSimulator + le_Callsign + le_AircraftType + cb_FlightRule