mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T733, allow to save/load a flight plan template
This commit is contained in:
committed by
Mat Sutcliffe
parent
59f8a7f88b
commit
3ffedd16ec
@@ -49,6 +49,7 @@
|
||||
#include <QCompleter>
|
||||
#include <QStringBuilder>
|
||||
#include <QPointer>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <Qt>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>371</width>
|
||||
<height>504</height>
|
||||
<y>-71</y>
|
||||
<width>368</width>
|
||||
<height>548</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -653,34 +653,6 @@
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="cb_StrictCheck">
|
||||
<property name="toolTip">
|
||||
<string>strict check</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>strict &check</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="pb_SimBrief">
|
||||
<property name="text">
|
||||
<string>SimBrief</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pb_Reset">
|
||||
<property name="text">
|
||||
<string>&Reset</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="pb_SaveDisk">
|
||||
<property name="toolTip">
|
||||
@@ -695,6 +667,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pb_Reset">
|
||||
<property name="text">
|
||||
<string>&Reset</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pb_Download">
|
||||
<property name="toolTip">
|
||||
@@ -709,17 +692,24 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pb_Send">
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="cb_StrictCheck">
|
||||
<property name="toolTip">
|
||||
<string>Send flight plan to network</string>
|
||||
<string>strict check</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
<string>strict &check</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pb_ValidateFlightPlan">
|
||||
<property name="text">
|
||||
<string>&Validate</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/network-cloud.png</normaloff>:/diagona/icons/diagona/icons/network-cloud.png</iconset>
|
||||
<normaloff>:/diagona/icons/diagona/icons/abacus.png</normaloff>:/diagona/icons/diagona/icons/abacus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -737,6 +727,27 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="pb_SimBrief">
|
||||
<property name="text">
|
||||
<string>SimBrief</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pb_Send">
|
||||
<property name="toolTip">
|
||||
<string>Send flight plan to network</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/network-cloud.png</normaloff>:/diagona/icons/diagona/icons/network-cloud.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pb_Prefill">
|
||||
<property name="toolTip">
|
||||
@@ -751,14 +762,24 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pb_ValidateFlightPlan">
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="pb_SaveTemplate">
|
||||
<property name="text">
|
||||
<string>&Validate</string>
|
||||
<string>Save template</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/abacus.png</normaloff>:/diagona/icons/diagona/icons/abacus.png</iconset>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="pb_ClearTemplate">
|
||||
<property name="text">
|
||||
<string>Clear template</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="pb_LoadTemplate">
|
||||
<property name="text">
|
||||
<string>Load template</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -799,7 +820,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>382</width>
|
||||
<height>480</height>
|
||||
<height>477</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_RemarksGeneratorScroll">
|
||||
@@ -1224,21 +1245,16 @@ p, li { white-space: pre-wrap; }
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>sa_FlightPlanTabMain</tabstop>
|
||||
<tabstop>cb_FlightRule</tabstop>
|
||||
<tabstop>le_Callsign</tabstop>
|
||||
<tabstop>tb_SyncWithSimulator</tabstop>
|
||||
<tabstop>le_AircraftType</tabstop>
|
||||
<tabstop>le_CruiseTrueAirspeed</tabstop>
|
||||
<tabstop>cb_Heavy</tabstop>
|
||||
<tabstop>cb_Tcas</tabstop>
|
||||
<tabstop>le_PrefixIcaoSuffix</tabstop>
|
||||
<tabstop>le_EquipmentSuffix</tabstop>
|
||||
<tabstop>tb_HelpEquipment</tabstop>
|
||||
<tabstop>pte_Route</tabstop>
|
||||
<tabstop>le_OriginAirport</tabstop>
|
||||
<tabstop>le_TakeOffTimePlanned</tabstop>
|
||||
<tabstop>lep_CrusingAltitude</tabstop>
|
||||
<tabstop>tb_AltitudeDialog</tabstop>
|
||||
<tabstop>pte_Route</tabstop>
|
||||
<tabstop>le_DestinationAirport</tabstop>
|
||||
<tabstop>le_EstimatedTimeEnroute</tabstop>
|
||||
<tabstop>le_FuelOnBoard</tabstop>
|
||||
@@ -1251,6 +1267,18 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstop>le_PilotsName</tabstop>
|
||||
<tabstop>le_PilotsHomeBase</tabstop>
|
||||
<tabstop>le_LastSent</tabstop>
|
||||
<tabstop>pb_Prefill</tabstop>
|
||||
<tabstop>pb_Reset</tabstop>
|
||||
<tabstop>pb_ValidateFlightPlan</tabstop>
|
||||
<tabstop>pb_Send</tabstop>
|
||||
<tabstop>pb_Download</tabstop>
|
||||
<tabstop>pb_SimBrief</tabstop>
|
||||
<tabstop>pb_SaveDisk</tabstop>
|
||||
<tabstop>pb_LoadDisk</tabstop>
|
||||
<tabstop>cb_StrictCheck</tabstop>
|
||||
<tabstop>pb_SaveTemplate</tabstop>
|
||||
<tabstop>pb_LoadTemplate</tabstop>
|
||||
<tabstop>pb_ClearTemplate</tabstop>
|
||||
<tabstop>sa_RemarksGenerator</tabstop>
|
||||
<tabstop>le_AirlineOperator</tabstop>
|
||||
<tabstop>le_AircraftRegistration</tabstop>
|
||||
@@ -1263,8 +1291,13 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstop>pte_RemarksGenerated</tabstop>
|
||||
<tabstop>pb_AddRemarks</tabstop>
|
||||
<tabstop>pte_AdditionalRemarks</tabstop>
|
||||
<tabstop>tbr_EquipmentCodes</tabstop>
|
||||
<tabstop>pb_CopyOver</tabstop>
|
||||
<tabstop>tbr_EquipmentCodes</tabstop>
|
||||
<tabstop>le_CruiseTrueAirspeed</tabstop>
|
||||
<tabstop>tb_SyncWithSimulator</tabstop>
|
||||
<tabstop>le_Callsign</tabstop>
|
||||
<tabstop>le_AircraftType</tabstop>
|
||||
<tabstop>cb_FlightRule</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
|
||||
Reference in New Issue
Block a user