mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #923, use CVariant JSON to load/save flight plan
This commit is contained in:
committed by
Mathew Sutcliffe
parent
ff4b37b3fe
commit
e787d50e47
@@ -413,29 +413,34 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString json(CFileUtils::readFileToString(fileName));
|
const QString json(CFileUtils::readFileToString(fileName));
|
||||||
if (json.isEmpty())
|
if (!Json::looksLikeSwiftJson(json))
|
||||||
{
|
{
|
||||||
m = CStatusMessage(this, CStatusMessage::SeverityWarning, "Reading " + fileName + " yields no data", true);
|
m = CStatusMessage(this, CStatusMessage::SeverityWarning, "Reading '%1' yields no data", true) << fileName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFlightPlan fp;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fp.convertFromJson(json);
|
CVariant variant;
|
||||||
|
variant.convertFromJson(Json::jsonObjectFromString(json));
|
||||||
|
if (variant.canConvert<CFlightPlan>())
|
||||||
|
{
|
||||||
|
const CFlightPlan fp = variant.value<CFlightPlan>();
|
||||||
|
this->fillWithFlightPlanData(fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m = CStatusMessage(this, CStatusMessage::SeverityWarning, "Wrong format for flight plan in '%1'") << fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const CJsonException &ex)
|
catch (const CJsonException &ex)
|
||||||
{
|
{
|
||||||
m = ex.toStatusMessage(this, "Parse error in " + fileName);
|
m = ex.toStatusMessage(this, "Parse error in " + fileName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this->fillWithFlightPlanData(fp);
|
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
if (m.isFailure())
|
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||||
{
|
|
||||||
CLogMessage::preformatted(m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFlightPlanComponent::ps_saveToDisk()
|
void CFlightPlanComponent::ps_saveToDisk()
|
||||||
@@ -452,9 +457,10 @@ namespace BlackGui
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CFlightPlan fp;
|
CFlightPlan fp;
|
||||||
this->validateAndInitializeFlightPlan(fp);
|
this->validateAndInitializeFlightPlan(fp); // get data
|
||||||
const QString json(fp.toJsonString());
|
const CVariant variantFp = CVariant::fromValue(fp);
|
||||||
bool ok = CFileUtils::writeStringToFile(json, fileName);
|
const QString json(variantFp.toJsonString());
|
||||||
|
const bool ok = CFileUtils::writeStringToFile(json, fileName);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
m = CStatusMessage(this, CStatusMessage::SeverityInfo, "Written " + fileName, true);
|
m = CStatusMessage(this, CStatusMessage::SeverityInfo, "Written " + fileName, true);
|
||||||
@@ -465,10 +471,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
if (m.isFailure())
|
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||||
{
|
|
||||||
CLogMessage::preformatted(m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFlightPlanComponent::ps_setSelcalInOwnAircraft()
|
void CFlightPlanComponent::ps_setSelcalInOwnAircraft()
|
||||||
@@ -491,8 +494,8 @@ namespace BlackGui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
|
const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
|
||||||
CFlightPlan loadedPlan = sGui->getIContextNetwork()->loadFlightPlanFromNetwork(ownAircraft.getCallsign());
|
const CFlightPlan loadedPlan = sGui->getIContextNetwork()->loadFlightPlanFromNetwork(ownAircraft.getCallsign());
|
||||||
if (loadedPlan.wasSentOrLoaded())
|
if (loadedPlan.wasSentOrLoaded())
|
||||||
{
|
{
|
||||||
this->fillWithFlightPlanData(loadedPlan);
|
this->fillWithFlightPlanData(loadedPlan);
|
||||||
|
|||||||
Reference in New Issue
Block a user