Enroute Flight Navigation
A navigation app for VFR pilots
Flightlog::FlightLogExportJSON Class Reference

JSON export format for the flight log. More...

#include <FlightLogExportJSON.h>

Static Public Member Functions

static auto toJSON (const Flight &flight) -> QJsonObject
 Serialize a single flight to JSON.
static auto fromJSON (const QJsonObject &json) -> Flight
 Deserialize a single flight from JSON.
static auto toJSON (const QList< Flight > &flights) -> QByteArray
 Generate JSON content for a list of flights.
static auto fromJSON (const QByteArray &content) -> QList< Flight >
 Parse a list of flights from JSON content.
static auto isValid (const QString &fileName, QString *info=nullptr) -> bool
 Check if a file contains valid flight log JSON data.

Detailed Description

JSON export format for the flight log.

This is a pure export/interchange format — used when the user shares or exports flights as JSON — independent of how the flight log is actually persisted (see FlightLogStorage). Its shape must stay stable regardless of the persistence backend.

Definition at line 39 of file FlightLogExportJSON.h.

Member Function Documentation

◆ fromJSON() [1/2]

auto Flightlog::FlightLogExportJSON::fromJSON ( const QByteArray & content) -> QList< Flight >
staticnodiscard

Parse a list of flights from JSON content.

Parameters
contentJSON content, as produced by toJSON(const QList<Flight>&)
Returns
The parsed flights, or an empty list if content isn't a valid flight log

◆ fromJSON() [2/2]

auto Flightlog::FlightLogExportJSON::fromJSON ( const QJsonObject & json) -> Flight
staticnodiscard

Deserialize a single flight from JSON.

Parameters
jsonA JSON object as produced by toJSON()
Returns
A Flight constructed from the JSON data

◆ isValid()

auto Flightlog::FlightLogExportJSON::isValid ( const QString & fileName,
QString * info = nullptr ) -> bool
staticnodiscard

Check if a file contains valid flight log JSON data.

Reads the file and checks whether it is a JSON document with the {"content": "flightLog", ...} envelope written by toJSON(). Does not check the validity of individual flight entries, only the envelope.

Parameters
fileNameName of a file
infoIf non-null, receives a translated description of why the file was rejected
Returns
True if the file is likely to contain a flight log

◆ toJSON() [1/2]

auto Flightlog::FlightLogExportJSON::toJSON ( const Flight & flight) -> QJsonObject
staticnodiscard

Serialize a single flight to JSON.

Parameters
flightThe flight to serialize
Returns
A JSON object representing the flight

◆ toJSON() [2/2]

auto Flightlog::FlightLogExportJSON::toJSON ( const QList< Flight > & flights) -> QByteArray
staticnodiscard

Generate JSON content for a list of flights.

Parameters
flightsThe flights to include
Returns
JSON content, or empty if flights is empty

The documentation for this class was generated from the following file: