480 changes: 348 additions & 132 deletions i18n/SkyDolly_de_DE.ts

Large diffs are not rendered by default.

66 changes: 48 additions & 18 deletions src/Kernel/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QCoreApplication>
#include <QStandardPaths>
#include <QSettings>
#include <QString>

#include "SampleRate.h"
#include "Version.h"
Expand All @@ -37,8 +38,8 @@ class SettingsPrivate
QSettings settings;
Version version;

QString libraryPath;
double recordSampleRateValue;
double replaySampleRateValue;
bool windowStayOnTopEnabled;
QString exportPath;
QString defaultExportPath;
Expand All @@ -49,6 +50,7 @@ class SettingsPrivate
int previewInfoDialogCount;

static Settings *instance;
static const QString DefaultDbPath;
static constexpr double DefaultRecordSampleRate = SampleRate::toValue(SampleRate::SampleRate::Auto);
static constexpr bool DefaultWindowStayOnTopEnabled = false;
static constexpr bool DefaultAbsoluteSeek = true;
Expand All @@ -73,8 +75,11 @@ class SettingsPrivate
{}
};

const QString SettingsPrivate::DefaultDbPath = QString();

Settings *SettingsPrivate::instance = nullptr;


// PUBLIC

Settings &Settings::getInstance() noexcept
Expand All @@ -93,6 +98,32 @@ void Settings::destroyInstance() noexcept
}
}

QString Settings::getLibraryPath() const noexcept
{
return d->libraryPath;
}

void Settings::setLibraryPath(const QString &libraryPath) noexcept
{
if (d->libraryPath != libraryPath) {
d->libraryPath = libraryPath;
emit libraryPathChanged(d->libraryPath);
}
}

QString Settings::getExportPath() const noexcept
{
return d->exportPath;
}

void Settings::setExportPath(QString exportPath)
{
if (d->exportPath != exportPath) {
d->exportPath = exportPath;
emit exportPathChanged(d->exportPath);
}
}

SampleRate::SampleRate Settings::getRecordSampleRate() const noexcept
{
return SampleRate::fromValue(d->recordSampleRateValue);
Expand Down Expand Up @@ -125,19 +156,6 @@ void Settings::setWindowStaysOnTopEnabled(bool enable) noexcept
}
}

QString Settings::getExportPath() const noexcept
{
return d->exportPath;
}

void Settings::setExportPath(QString exportPath)
{
if (d->exportPath != exportPath) {
d->exportPath = exportPath;
emit exportPathChanged(d->exportPath);
}
}

bool Settings::isAbsoluteSeekEnabled() const noexcept
{
return d->absoluteSeek;
Expand Down Expand Up @@ -179,7 +197,7 @@ void Settings::setSeekIntervalPercent(double percent) noexcept

int Settings::getPreviewInfoDialogCount() const noexcept
{
return d->previewInfoDialogCount - SettingsPrivate::PreviewInfoDialogBase;
return d->seekIntervalSeconds;
}

void Settings::setPreviewInfoDialogCount(int count) noexcept
Expand All @@ -195,18 +213,23 @@ void Settings::setPreviewInfoDialogCount(int count) noexcept
void Settings::store() noexcept
{
d->settings.setValue("Version", d->version.toString());
d->settings.beginGroup("Library");
{
d->settings.setValue("DbPath", d->libraryPath);
}
d->settings.endGroup();
d->settings.beginGroup("Recording");
{
d->settings.setValue("RecordSampleRate", d->recordSampleRateValue);
}
d->settings.endGroup();
d->settings.endGroup();
d->settings.beginGroup("Replay");
{
d->settings.setValue("AbsoluteSeek", d->absoluteSeek);
d->settings.setValue("SeekIntervalSeconds", d->seekIntervalSeconds);
d->settings.setValue("SeekIntervalPercent", d->seekIntervalPercent);
}
d->settings.endGroup();
d->settings.endGroup();
d->settings.beginGroup("Window");
{
d->settings.setValue("WindowStaysOnTopEnabled", d->windowStayOnTopEnabled);
Expand Down Expand Up @@ -238,6 +261,11 @@ void Settings::restore() noexcept
}

bool ok;
d->settings.beginGroup("Library");
{
d->libraryPath = d->settings.value("DbPath", SettingsPrivate::DefaultDbPath).toString();
}
d->settings.endGroup();
d->settings.beginGroup("Recording");
{
d->recordSampleRateValue = d->settings.value("RecordSampleRate", SettingsPrivate::DefaultRecordSampleRate).toDouble(&ok);
Expand All @@ -246,7 +274,7 @@ void Settings::restore() noexcept
d->recordSampleRateValue = SettingsPrivate::DefaultRecordSampleRate;
}
}
d->settings.endGroup();
d->settings.endGroup();
d->settings.beginGroup("Replay");
{
d->absoluteSeek = d->settings.value("AbsoluteSeek", SettingsPrivate::DefaultAbsoluteSeek).toBool();
Expand Down Expand Up @@ -308,6 +336,8 @@ Settings::Settings() noexcept

void Settings::frenchConnection() noexcept
{
connect(this, &Settings::libraryPathChanged,
this, &Settings::changed);
connect(this, &Settings::recordSampleRateChanged,
this, &Settings::changed);
connect(this, &Settings::exportPathChanged,
Expand Down
10 changes: 10 additions & 0 deletions src/Kernel/src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class KERNEL_API Settings : public QObject
*/
static void destroyInstance() noexcept;

QString getLibraryPath() const noexcept;
void setLibraryPath(const QString &libraryPath) noexcept;

/*!
* Returns the recording sample rate enumeration value.
*
Expand Down Expand Up @@ -195,6 +198,13 @@ public slots:
void restore() noexcept;

signals:
/*!
* Emitted when the library path has changed.
*
* \sa changed()
*/
void libraryPathChanged(const QString &libraryPath);

/*!
* Emitted when the record sample rate has changed.
*
Expand Down
18 changes: 12 additions & 6 deletions src/Kernel/src/SkyMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace SkyMath {
* \return -1 if \c val is a negative value; 0 for \c val
* 0; +1 else
*/
template <typename T> int sgn(T val) noexcept
template <typename T>
int sgn(T val) noexcept
{
return (T(0) < val) - (val < T(0));
}
Expand Down Expand Up @@ -86,7 +87,8 @@ namespace SkyMath {
* or samples values like 165, 175, -175, -165 becomes 165, 175, 185, 195, and
* the normalised values are then suitable for interpolation.
*/
template <typename T> T normalise180(T y0, T y1) noexcept
template <typename T>
T normalise180(T y0, T y1) noexcept
{
T y1n;
T s0 = sgn(y0);
Expand Down Expand Up @@ -126,7 +128,8 @@ namespace SkyMath {
* 0 is even; positive values create a bias towards the first segment;
* negative values create a bias towards the second segment
*/
template <typename T> T interpolateHermite(
template <typename T>
T interpolateHermite(
T y0, T y1, T y2, T y3,
T mu,
T tension = T(0),
Expand Down Expand Up @@ -156,7 +159,8 @@ namespace SkyMath {
*
* Also refer to \c #interpolateHermite().
*/
template <typename T> T interpolateHermite180(
template <typename T>
T interpolateHermite180(
T y0, T y1, T y2, T y3,
T mu,
T tension = T(0),
Expand Down Expand Up @@ -185,7 +189,8 @@ namespace SkyMath {
*
* Also refer to \c #interpolateHermite().
*/
template <typename T> T interpolateHermite360(
template <typename T>
T interpolateHermite360(
T y0, T y1, T y2, T y3,
T mu,
T tension = T(0),
Expand All @@ -204,7 +209,8 @@ namespace SkyMath {
* \param mu
* the interpolation factor in [0.0, 1.0]
*/
template <typename T, typename U> T interpolateLinear(T p1, T p2, U mu) noexcept
template <typename T, typename U>
T interpolateLinear(T p1, T p2, U mu) noexcept
{
if (std::is_integral<T>::value) {
return p1 + qRound(mu * (U(p2) - U(p1)));
Expand Down
20 changes: 10 additions & 10 deletions src/Model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ target_sources(Model
src/World.h
src/Scenario.cpp
src/Scenario.h
src/ScenarioDescription.cpp
src/ScenarioDescription.h
src/FlightCondition.cpp
src/FlightCondition.h
src/Aircraft.cpp
Expand Down Expand Up @@ -43,27 +45,25 @@ target_sources(Model
src/LightData.h
src/AircraftInfo.cpp
src/AircraftInfo.h
src/FlightPlanData.cpp
src/FlightPlanData.h
src/FlightPlan.cpp
src/FlightPlan.h
src/SimVar.cpp
src/SimVar.h
src/SimType.h
src/SkySearch.cpp
src/SkySearch.h
src/CSVConst.cpp
src/CSVConst.h
src/Export/CSVExport.cpp
src/Export/CSVExport.h
src/Import/CSVImport.cpp
src/Import/CSVImport.h
)

set(Model_LIBS
Qt${QT_VERSION_MAJOR}::Core Kernel
set(MODEL_LIBS
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Sql Kernel
)
if (APPLE)
list(APPEND Model_LIBS -lc++)
list(APPEND MODEL_LIBS -lc++)
endif()

target_link_libraries(Model PRIVATE ${Model_LIBS})
target_link_libraries(Model PRIVATE ${MODEL_LIBS})
set_target_properties(Model PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(Model PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})

Expand Down
76 changes: 52 additions & 24 deletions src/Model/src/Aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <memory>

#include <QObject>
#include <QByteArray>
#include <QVector>

#include "../../Kernel/src/SkyMath.h"
Expand All @@ -43,24 +42,28 @@
#include "AircraftHandleData.h"
#include "Light.h"
#include "LightData.h"
#include "FlightPlan.h"
#include "Aircraft.h"

class AircraftPrivate
{
public:
AircraftPrivate() noexcept
: currentTimestamp(TimeVariableData::InvalidTime),
: id(0),
currentTimestamp(TimeVariableData::InvalidTime),
currentAccess(TimeVariableData::Access::Linear),
currentIndex(SkySearch::InvalidIndex),
duration(TimeVariableData::InvalidTime)
{}

qint64 id;
AircraftInfo aircraftInfo;
Engine engine;
PrimaryFlightControl primaryFlightControl;
SecondaryFlightControl secondaryFlightControl;
AircraftHandle aircraftHandle;
Light light;
AircraftInfo aircraftInfo;
FlightPlan flightPlan;

QVector<AircraftData> aircraftData;
qint64 currentTimestamp;
Expand All @@ -83,6 +86,16 @@ Aircraft::~Aircraft() noexcept
{
}

void Aircraft::setId(qint64 id) noexcept
{
d->id = id;
}

qint64 Aircraft::getId() const noexcept
{
return d->id;
}

const Engine &Aircraft::getEngineConst() const noexcept
{
return d->engine;
Expand Down Expand Up @@ -133,40 +146,42 @@ Light &Aircraft::getLight() const noexcept
return d->light;
}

void Aircraft::setAircraftInfo(AircraftInfo aircraftInfo) noexcept
const AircraftInfo &Aircraft::getAircraftInfoConst() const noexcept
{
return d->aircraftInfo;
}

void Aircraft::setAircraftInfo(const AircraftInfo &aircraftInfo) noexcept
{
d->aircraftInfo = aircraftInfo;
emit infoChanged();
}

const AircraftInfo &Aircraft::getAircraftInfo() const noexcept
const FlightPlan &Aircraft::getFlightPlanConst() const noexcept
{
return d->aircraftInfo;
return d->flightPlan;
}

void Aircraft::upsert(AircraftData aircraftData) noexcept
FlightPlan &Aircraft::getFlightPlan() const noexcept
{
if (d->aircraftData.count() > 0) {
return d->flightPlan;
}

void Aircraft::upsert(AircraftData &aircraftData) noexcept
{
if (d->aircraftData.count() > 0) {
if (d->aircraftData.last().timestamp == aircraftData.timestamp) {
// Same timestamp -> replace
d->aircraftData[d->aircraftData.count() - 1] = aircraftData;
#ifdef DEBUG
qDebug("Aircraft::upsertAircraftData: UPDATE sample, timestamp: %llu count: %d", aircraftData.timestamp, d->aircraftData.count());
#endif
} else {
d->aircraftData.append(aircraftData);
#ifdef DEBUG
qDebug("Aircraft::upsertAircraftData: INSERT sample, timestamp: %llu count: %d", aircraftData.timestamp, d->aircraftData.count());
#endif
}
} else {
// The first position sample *must* have a timestamp of 0, as this
// is the timestamp where we setup the initial aircraft position
aircraftData.timestamp = 0;
d->aircraftData.append(aircraftData);
}
d->duration = TimeVariableData::InvalidTime;
emit dataChanged();
}

Expand All @@ -179,7 +194,12 @@ const AircraftData &Aircraft::getLast() const noexcept
}
}

const QVector<AircraftData> &Aircraft::getAll() const noexcept
const QVector<AircraftData> &Aircraft::getAllConst() const noexcept
{
return d->aircraftData;
}

QVector<AircraftData> &Aircraft::getAll() const noexcept
{
return d->aircraftData;
}
Expand Down Expand Up @@ -261,21 +281,23 @@ qint64 Aircraft::getDurationMSec() const noexcept
if (d->aircraftData.count() > 0) {
d->duration = d->aircraftData.last().timestamp;
}
if (d->engine.getAll().count() > 0) {
if (d->engine.getAllConst().count() > 0) {
d->duration = qMax(d->engine.getLast().timestamp, d->duration);
}
if (d->primaryFlightControl.getAll().count() > 0) {
if (d->primaryFlightControl.getAllConst().count() > 0) {
d->duration = qMax(d->primaryFlightControl.getLast().timestamp, d->duration);
}
if (d->secondaryFlightControl.getAll().count() > 0) {
if (d->secondaryFlightControl.getAllConst().count() > 0) {
d->duration = qMax(d->secondaryFlightControl.getLast().timestamp, d->duration);
}
if (d->aircraftHandle.getAll().count() > 0) {
if (d->aircraftHandle.getAllConst().count() > 0) {
d->duration = qMax(d->aircraftHandle.getLast().timestamp, d->duration);
}
if (d->light.getAll().count() > 0) {
if (d->light.getAllConst().count() > 0) {
d->duration = qMax(d->light.getLast().timestamp, d->duration);
}
// Update end time
d->aircraftInfo.endDate = d->aircraftInfo.startDate.addMSecs(d->duration);
}
return d->duration;
}
Expand All @@ -293,11 +315,10 @@ void Aircraft::clear() noexcept
d->secondaryFlightControl.clear();
d->aircraftHandle.clear();
d->light.clear();
d->flightPlan.clear();
d->aircraftInfo.clear();
d->currentTimestamp = TimeVariableData::InvalidTime;
d->currentIndex = SkySearch::InvalidIndex;
d->duration = 0;

emit dataChanged();
}

Expand All @@ -315,12 +336,19 @@ void Aircraft::frenchConnection()
this, &Aircraft::handleDataChanged);
connect(&d->light, &Light::dataChanged,
this, &Aircraft::handleDataChanged);
connect(this, &Aircraft::dataChanged,
this, &Aircraft::invalidateDuration);
}

// PRIVATE SLOTS

void Aircraft::handleDataChanged()
{
d->duration = TimeVariableData::InvalidTime;
emit dataChanged();
}

void Aircraft::invalidateDuration()
{
d->duration = TimeVariableData::InvalidTime;
d->aircraftInfo.endDate = QDateTime();
}
20 changes: 15 additions & 5 deletions src/Model/src/Aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include <memory>

#include <QObject>
#include <QByteArray>
#include <QVector>

class QDateTime;

#include "ModelLib.h"
#include "AircraftInfo.h"
#include "Engine.h"
Expand All @@ -40,6 +41,7 @@ class PrimaryFlightControl;
class SecondaryFlightControl;
class AircraftHandle;
class Light;
class FlightPlan;
class AircraftPrivate;

class MODEL_API Aircraft : public QObject
Expand All @@ -49,6 +51,9 @@ class MODEL_API Aircraft : public QObject
Aircraft(QObject *parent = nullptr) noexcept;
virtual ~Aircraft() noexcept;

void setId(qint64 id) noexcept;
qint64 getId() const noexcept;

const Engine &getEngineConst() const noexcept;
Engine &getEngine() const noexcept;

Expand All @@ -64,12 +69,16 @@ class MODEL_API Aircraft : public QObject
const Light &getLightConst() const noexcept;
Light &getLight() const noexcept;

void setAircraftInfo(AircraftInfo aircraftInfo) noexcept;
const AircraftInfo &getAircraftInfo() const noexcept;
const AircraftInfo &getAircraftInfoConst() const noexcept;
void setAircraftInfo(const AircraftInfo &aircraftInfo) noexcept;

const FlightPlan &getFlightPlanConst() const noexcept;
FlightPlan &getFlightPlan() const noexcept;

void upsert(AircraftData aircraftData) noexcept;
void upsert(AircraftData &aircraftData) noexcept;
const AircraftData &getLast() const noexcept;
const QVector<AircraftData> &getAll() const noexcept;
const QVector<AircraftData> &getAllConst() const noexcept;
QVector<AircraftData> &getAll() const noexcept;
const AircraftData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

qint64 getDurationMSec() const noexcept;
Expand All @@ -89,6 +98,7 @@ class MODEL_API Aircraft : public QObject

private slots:
void handleDataChanged();
void invalidateDuration();
};

#endif // AIRCRAFT_H
15 changes: 7 additions & 8 deletions src/Model/src/AircraftHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,13 @@ AircraftHandle::~AircraftHandle() noexcept
{
}

void AircraftHandle::upsert(AircraftHandleData aircraftHandleData) noexcept
void AircraftHandle::upsert(const AircraftHandleData &aircraftHandleData) noexcept
{
if (d->aircraftHandleData.count() > 0 && d->aircraftHandleData.last().timestamp == aircraftHandleData.timestamp) {
// Same timestamp -> replace
d->aircraftHandleData[d->aircraftHandleData.count() - 1] = aircraftHandleData;
#ifdef DEBUG
qDebug("AircraftHandle::upsertAircraftHandleData: UPDATE sample, timestamp: %llu count: %d", aircraftHandleData.timestamp, d->aircraftHandleData.count());
#endif
} else {
d->aircraftHandleData.append(aircraftHandleData);
#ifdef DEBUG
qDebug("AircraftHandle::upsertAircraftHandleData: INSERT sample, timestamp: %llu count: %d", aircraftHandleData.timestamp, d->aircraftHandleData.count());
#endif
}
emit dataChanged();
}
Expand All @@ -90,7 +84,12 @@ const AircraftHandleData &AircraftHandle::getLast() const noexcept
}
}

const QVector<AircraftHandleData> &AircraftHandle::getAll() const noexcept
QVector<AircraftHandleData> &AircraftHandle::getAll() const noexcept
{
return d->aircraftHandleData;
}

const QVector<AircraftHandleData> &AircraftHandle::getAllConst() const noexcept
{
return d->aircraftHandleData;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/src/AircraftHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MODEL_API AircraftHandle : public QObject
AircraftHandle(QObject *parent = nullptr) noexcept;
virtual ~AircraftHandle() noexcept;

void upsert(AircraftHandleData aircraftHandleData) noexcept;
void upsert(const AircraftHandleData &aircraftHandleData) noexcept;
const AircraftHandleData &getLast() const noexcept;
const QVector<AircraftHandleData> &getAll() const noexcept;
QVector<AircraftHandleData> &getAll() const noexcept;
const QVector<AircraftHandleData> &getAllConst() const noexcept;
const AircraftHandleData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

void clear() noexcept;
Expand Down
21 changes: 8 additions & 13 deletions src/Model/src/AircraftInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,21 @@
// PUBLIC

AircraftInfo::AircraftInfo() noexcept
: startOnGround(false),
aircraftAltitudeAboveGround(0.0f),
initialAirspeed(0),
wingSpan(0),
numberOfEngines(0),
engineType(SimType::EngineType::Unknown)
{
clear();
}

void AircraftInfo::clear()
void AircraftInfo::clear() noexcept
{
name.clear();
atcId.clear();
atcAirline.clear();
atcFlightNumber.clear();
type.clear();
tailNumber.clear();
airline.clear();
flightNumber.clear();
category.clear();
startOnGround = false;
aircraftAltitudeAboveGround = 0.0f;
altitudeAboveGround = 0.0f;
initialAirspeed = 0;
wingSpan = 0;
numberOfEngines = 0;
engineType = SimType::EngineType::Unknown;
numberOfEngines = 0;
}
25 changes: 14 additions & 11 deletions src/Model/src/AircraftInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,38 @@
#ifndef AIRCRAFTINFO_H
#define AIRCRAFTINFO_H

#include <QByteArray>
#include <QString>
#include <QDateTime>

#include "SimType.h"
#include "ModelLib.h"

struct MODEL_API AircraftInfo
{
QByteArray name;
QByteArray atcId;
QByteArray atcAirline;
QByteArray atcFlightNumber;
QByteArray category;
bool startOnGround;
// Feet
float aircraftAltitudeAboveGround;
QDateTime startDate;
QDateTime endDate;
QString type;
QString tailNumber;
QString airline;
QString flightNumber;
QString category;

// Feet
float altitudeAboveGround;
bool startOnGround;
// Knots
int initialAirspeed;
// Feet
int wingSpan;
int numberOfEngines;
SimType::EngineType engineType;
int numberOfEngines;

AircraftInfo() noexcept;
AircraftInfo(AircraftInfo &&) = default;
AircraftInfo(const AircraftInfo &) = default;
AircraftInfo &operator= (const AircraftInfo &) = default;

void clear();
void clear() noexcept;
};

#endif // AIRCRAFTINFO_H
17 changes: 9 additions & 8 deletions src/Model/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,13 @@ Engine::~Engine() noexcept
{
}

void Engine::upsert(EngineData engineData) noexcept
void Engine::upsert(const EngineData &engineData) noexcept
{
if (d->engineData.count() > 0 && d->engineData.last().timestamp == engineData.timestamp) {
// Same timestamp -> replace
d->engineData[d->engineData.count() - 1] = engineData;
#ifdef DEBUG
qDebug("Engine::upsertEngineData: UPDATE sample, timestamp: %llu count: %d", engineData.timestamp, d->engineData.count());
#endif
} else {
d->engineData.append(engineData);
#ifdef DEBUG
qDebug("Engine::upsertEngineData: INSERT sample, timestamp: %llu count: %d", engineData.timestamp, d->engineData.count());
#endif
}
emit dataChanged();
}
Expand All @@ -89,7 +83,12 @@ const EngineData &Engine::getLast() const noexcept
}
}

const QVector<EngineData> &Engine::getAll() const noexcept
QVector<EngineData> &Engine::getAll() const noexcept
{
return d->engineData;
}

const QVector<EngineData> &Engine::getAllConst() const noexcept
{
return d->engineData;
}
Expand Down Expand Up @@ -149,6 +148,7 @@ const EngineData &Engine::interpolate(qint64 timestamp, TimeVariableData::Access
d->currentEngineData.cowlFlapPosition2 = SkyMath::interpolateLinear(p1->cowlFlapPosition2, p2->cowlFlapPosition2, tn);
d->currentEngineData.cowlFlapPosition3 = SkyMath::interpolateLinear(p1->cowlFlapPosition3, p2->cowlFlapPosition3, tn);
d->currentEngineData.cowlFlapPosition4 = SkyMath::interpolateLinear(p1->cowlFlapPosition4, p2->cowlFlapPosition4, tn);

// No interpolation for battery and starter states (boolean)
d->currentEngineData.electricalMasterBattery1 = p1->electricalMasterBattery1;
d->currentEngineData.electricalMasterBattery2 = p1->electricalMasterBattery2;
Expand All @@ -158,6 +158,7 @@ const EngineData &Engine::interpolate(qint64 timestamp, TimeVariableData::Access
d->currentEngineData.generalEngineStarter2 = p1->generalEngineStarter2;
d->currentEngineData.generalEngineStarter3 = p1->generalEngineStarter3;
d->currentEngineData.generalEngineStarter4 = p1->generalEngineStarter4;

d->currentEngineData.timestamp = timestamp;
} else {
// No recorded data, or the timestamp exceeds the timestamp of the last recorded position
Expand Down
5 changes: 3 additions & 2 deletions src/Model/src/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MODEL_API Engine : public QObject
Engine(QObject *parent = nullptr) noexcept;
virtual ~Engine() noexcept;

void upsert(EngineData engineData) noexcept;
void upsert(const EngineData &engineData) noexcept;
const EngineData &getLast() const noexcept;
const QVector<EngineData> &getAll() const noexcept;
QVector<EngineData> &getAll() const noexcept;
const QVector<EngineData> &getAllConst() const noexcept;
const EngineData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

void clear() noexcept;
Expand Down
418 changes: 0 additions & 418 deletions src/Model/src/Export/CSVExport.cpp

This file was deleted.

38 changes: 26 additions & 12 deletions src/Model/src/FlightCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,35 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "SimType.h"
#include "FlightCondition.h"

// PUBLIC

FlightCondition::FlightCondition() noexcept
: groundAltitude(0.0f),
surfaceType(SimType::SurfaceType::Unknown),
ambientTemperature(0.0f),
totalAirTemperature(0.0f),
windVelocity(0.0f),
windDirection(0.0f),
precipitationState(SimType::PrecipitationState::None),
inClouds(false),
visibility(0.0f),
seaLevelPressure(0.0f),
pitotIcingPercent(0),
structuralIcingPercent(0)
{
init();
}

void FlightCondition::clear() noexcept
{
init();
}

// PRIVATE

void FlightCondition::init() noexcept
{
groundAltitude = 0.0;
surfaceType = SimType::SurfaceType::Unknown;
ambientTemperature = 0.0;
totalAirTemperature = 0.0;
windVelocity = 0.0;
windDirection = 0.0;
precipitationState = SimType::PrecipitationState::None;
visibility = 0.0;
seaLevelPressure = 0.0;
pitotIcingPercent = 0.0;
structuralIcingPercent = 0.0;
inClouds = false;
}
13 changes: 11 additions & 2 deletions src/Model/src/FlightCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
#ifndef FLIGHTCONDITION_H
#define FLIGHTCONDITION_H

#include <QtGlobal>
#include <QDateTime>

#include "SimType.h"
#include "ModelLib.h"

struct MODEL_API FlightCondition

{
float groundAltitude;
SimType::SurfaceType surfaceType;
Expand All @@ -38,16 +40,23 @@ struct MODEL_API FlightCondition
float windVelocity;
float windDirection;
SimType::PrecipitationState precipitationState;
bool inClouds;
float visibility;
float seaLevelPressure;
quint8 pitotIcingPercent;
quint8 structuralIcingPercent;
bool inClouds;
QDateTime localTime;
QDateTime zuluTime;

FlightCondition() noexcept;
FlightCondition(FlightCondition &&) = default;
FlightCondition(const FlightCondition &) = default;
FlightCondition &operator= (const FlightCondition &) = default;

void clear() noexcept;

private:
inline void init() noexcept;
};

#endif // FLIGHTCONDITION_H
74 changes: 74 additions & 0 deletions src/Model/src/FlightPlan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <memory>

#include <QObject>
#include <QVector>

#include "FlightPlanData.h"
#include "FlightPlan.h"

class FlightPlanPrivate
{
public:
FlightPlanPrivate() noexcept
{}

QVector<FlightPlanData> flightPlanData;
};

// PUBLIC

FlightPlan::FlightPlan(QObject *parent) noexcept
: QObject(parent),
d(std::make_unique<FlightPlanPrivate>())
{
}

FlightPlan::~FlightPlan() noexcept
{
}

void FlightPlan::add(const FlightPlanData &flightPlanData) noexcept
{
d->flightPlanData.append(flightPlanData);
emit dataChanged();
}

QVector<FlightPlanData> &FlightPlan::getAll() const noexcept
{
return d->flightPlanData;
}

const QVector<FlightPlanData> &FlightPlan::getAllConst() const noexcept
{
return d->flightPlanData;
}

void FlightPlan::clear() noexcept
{
d->flightPlanData.clear();
emit dataChanged();
}
61 changes: 61 additions & 0 deletions src/Model/src/FlightPlan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef FLIGHTPLAN_H
#define FLIGHTPLAN_H


#include <memory>

#include <QObject>
#include <QByteArray>
#include <QVector>

#include "ModelLib.h"

class FlightPlanData;
class FlightPlanPrivate;

class MODEL_API FlightPlan : public QObject
{
Q_OBJECT
public:
FlightPlan(QObject *parent = nullptr) noexcept;
virtual ~FlightPlan() noexcept;

void add(const FlightPlanData &flightPlanData) noexcept;
QVector<FlightPlanData> &getAll() const noexcept;
const QVector<FlightPlanData> &getAllConst() const noexcept;

void clear() noexcept;

signals:
void dataChanged();

private:
Q_DISABLE_COPY(FlightPlan)
std::unique_ptr<FlightPlanPrivate> d;
};

#endif // FLIGHTPLAN_H
19 changes: 7 additions & 12 deletions src/Model/src/Const.h → src/Model/src/FlightPlanData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef CONST_H
#define CONST_H
#include "FlightPlanData.h"

/*!
* General constants.
*/
namespace Const
// PUBLIC

FlightPlanData::FlightPlanData() noexcept
: waypointLatitude(0.0f),
waypointLongitude(0.0f),
waypointAltitude(0.0f)
{
/*! Separator character for CSV import & export */
inline constexpr char Sep = '\t';
/*! Newline character for CSV import & export */
inline constexpr char Ln = '\n';
}

#endif // CONST_H
48 changes: 48 additions & 0 deletions src/Model/src/FlightPlanData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef FLIGHTPLANDATA_H
#define FLIGHTPLANDATA_H

#include <QtGlobal>
#include <QString>

#include "SimType.h"
#include "TimeVariableData.h"
#include "ModelLib.h"

struct MODEL_API FlightPlanData
{
QString waypointIdentifier;
float waypointLatitude;
float waypointLongitude;
float waypointAltitude;

FlightPlanData() noexcept;
FlightPlanData(FlightPlanData &&) = default;
FlightPlanData(const FlightPlanData &) = default;
FlightPlanData &operator= (const FlightPlanData &) = default;
};

#endif // FLIGHTPLANDATA_H
15 changes: 10 additions & 5 deletions src/Model/src/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Light::~Light() noexcept
{
}

void Light::upsert(LightData LightData) noexcept
void Light::upsert(const LightData &lightData) noexcept
{
if (d->lightData.count() > 0 && d->lightData.last().timestamp == LightData.timestamp) {
if (d->lightData.count() > 0 && d->lightData.last().timestamp == lightData.timestamp) {
// Same timestamp -> replace
d->lightData[d->lightData.count() - 1] = LightData;
d->lightData[d->lightData.count() - 1] = lightData;
} else {
d->lightData.append(LightData);
d->lightData.append(lightData);
}
emit dataChanged();
}
Expand All @@ -83,7 +83,12 @@ const LightData &Light::getLast() const noexcept
}
}

const QVector<LightData> &Light::getAll() const noexcept
QVector<LightData> &Light::getAll() const noexcept
{
return d->lightData;
}

const QVector<LightData> &Light::getAllConst() const noexcept
{
return d->lightData;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/src/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MODEL_API Light : public QObject
Light(QObject *parent = nullptr) noexcept;
virtual ~Light() noexcept;

void upsert(LightData LightData) noexcept;
void upsert(const LightData &lightData) noexcept;
const LightData &getLast() const noexcept;
const QVector<LightData> &getAll() const noexcept;
QVector<LightData> &getAll() const noexcept;
const QVector<LightData> &getAllConst() const noexcept;
const LightData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

void clear() noexcept;
Expand Down
15 changes: 7 additions & 8 deletions src/Model/src/PrimaryFlightControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,13 @@ PrimaryFlightControl::~PrimaryFlightControl() noexcept
{
}

void PrimaryFlightControl::upsert(PrimaryFlightControlData primaryFlightControlData) noexcept
void PrimaryFlightControl::upsert(const PrimaryFlightControlData &primaryFlightControlData) noexcept
{
if (d->primaryFlightControlData.count() > 0 && d->primaryFlightControlData.last().timestamp == primaryFlightControlData.timestamp) {
// Same timestamp -> replace
d->primaryFlightControlData[d->primaryFlightControlData.count() - 1] = primaryFlightControlData;
#ifdef DEBUG
qDebug("PrimaryFlightControl::upsertPrimaryFlightControlData: UPDATE sample, timestamp: %llu count: %d", primaryFlightControlData.timestamp, d->primaryFlightControlData.count());
#endif
} else {
d->primaryFlightControlData.append(primaryFlightControlData);
#ifdef DEBUG
qDebug("PrimaryFlightControl::upsertPrimaryFlightControlData: INSERT sample, timestamp: %llu count: %d", primaryFlightControlData.timestamp, d->primaryFlightControlData.count());
#endif
}
emit dataChanged();
}
Expand All @@ -115,7 +109,12 @@ const PrimaryFlightControlData &PrimaryFlightControl::getLast() const noexcept
}
}

const QVector<PrimaryFlightControlData> &PrimaryFlightControl::getAll() const noexcept
QVector<PrimaryFlightControlData> &PrimaryFlightControl::getAll() const noexcept
{
return d->primaryFlightControlData;
}

const QVector<PrimaryFlightControlData> &PrimaryFlightControl::getAllConst() const noexcept
{
return d->primaryFlightControlData;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/src/PrimaryFlightControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MODEL_API PrimaryFlightControl : public QObject
PrimaryFlightControl(QObject *parent = nullptr) noexcept;
virtual ~PrimaryFlightControl() noexcept;

void upsert(PrimaryFlightControlData primaryFlightControlData) noexcept;
void upsert(const PrimaryFlightControlData &primaryFlightControlData) noexcept;
const PrimaryFlightControlData &getLast() const noexcept;
const QVector<PrimaryFlightControlData> &getAll() const noexcept;
QVector<PrimaryFlightControlData> &getAll() const noexcept;
const QVector<PrimaryFlightControlData> &getAllConst() const noexcept;
const PrimaryFlightControlData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

void clear() noexcept;
Expand Down
65 changes: 53 additions & 12 deletions src/Model/src/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <memory>
#include <vector>

#include <QDateTime>
#include <QString>

#include "FlightCondition.h"
#include "Aircraft.h"
#include "Scenario.h"
Expand All @@ -34,14 +37,20 @@ class ScenarioPrivate
public:

ScenarioPrivate() noexcept
{}

~ScenarioPrivate() noexcept
{}
{
clear();
}

qint64 id;
QDateTime creationDate;
QString description;
FlightCondition flightCondition;
std::vector<std::unique_ptr<Aircraft>> aircrafts;

inline void clear() noexcept {
id = 0;
description.clear();
}
};

// PUBLIC
Expand All @@ -62,30 +71,55 @@ Scenario::~Scenario() noexcept
{
}

const Aircraft &Scenario::getUserAircraftConst() const noexcept
void Scenario::setId(qint64 id) noexcept
{
return *(*d->aircrafts.cbegin());
d->id = id;
}

Aircraft &Scenario::getUserAircraft() const noexcept
qint64 Scenario::getId() const noexcept
{
return d->id;
}

const QDateTime &Scenario::getCreationDate() const noexcept
{
return d->creationDate;
}

void Scenario::setCreationDate(const QDateTime &creationDate) noexcept
{
d->creationDate = creationDate;
}

const QString &Scenario::getDescription() const noexcept
{
return d->description;
}

void Scenario::setDescription(const QString &description) noexcept
{
d->description = description;
}

const Aircraft &Scenario::getUserAircraftConst() const noexcept
{
return *(*d->aircrafts.cbegin());
}

void Scenario::setFlightCondition(FlightCondition flightCondition) noexcept
Aircraft &Scenario::getUserAircraft() const noexcept
{
d->flightCondition = flightCondition;
emit flightConditionChanged();
return *(*d->aircrafts.cbegin());
}

const FlightCondition &Scenario::getFlightConditionConst() const noexcept
{
return d->flightCondition;
}

FlightCondition &Scenario::getFlightCondition() const noexcept
void Scenario::setFlightCondition(FlightCondition flightCondition) noexcept
{
return d->flightCondition;
d->flightCondition = flightCondition;
emit flightConditionChanged();
}

qint64 Scenario::getTotalDurationMSec() const noexcept
Expand All @@ -95,6 +129,13 @@ qint64 Scenario::getTotalDurationMSec() const noexcept
return d->aircrafts.at(0)->getDurationMSec();
}

void Scenario::clear() noexcept
{
d->clear();
getUserAircraft().clear();
d->flightCondition.clear();
}

// PRIVATE

void Scenario::frenchConnection() noexcept
Expand Down
19 changes: 17 additions & 2 deletions src/Model/src/Scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include <QObject>

class QDateTime;
class QString;

#include "ModelLib.h"

class FlightCondition;
Expand All @@ -42,15 +45,27 @@ class MODEL_API Scenario : public QObject
Scenario(QObject *parent = nullptr) noexcept;
~Scenario() noexcept;

qint64 getId() const noexcept;
void setId(qint64 id) noexcept;

const QDateTime &getCreationDate() const noexcept;
void setCreationDate(const QDateTime &creationDate) noexcept;

const QString &getDescription() const noexcept;
void setDescription(const QString &description) noexcept;

const Aircraft &getUserAircraftConst() const noexcept;
Aircraft &getUserAircraft() const noexcept;

void setFlightCondition(FlightCondition flightCondition) noexcept;
const FlightCondition &getFlightConditionConst() const noexcept;
FlightCondition &getFlightCondition() const noexcept;
void setFlightCondition(FlightCondition flightCondition) noexcept;

qint64 getTotalDurationMSec() const noexcept;

void clear() noexcept;

static constexpr int InvalidId = -1;

signals:
void aircraftInfoChanged();
void aircraftDataChanged();
Expand Down
33 changes: 33 additions & 0 deletions src/Model/src/ScenarioDescription.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "ScenarioDescription.h"

// PUBLIC

ScenarioDescription::ScenarioDescription()
{}

ScenarioDescription::~ScenarioDescription()
{}
48 changes: 48 additions & 0 deletions src/Model/src/ScenarioDescription.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SCENARIODESCRIPTION_H
#define SCENARIODESCRIPTION_H

#include <QString>
#include <QDateTime>

#include "ModelLib.h"

struct MODEL_API ScenarioDescription
{
ScenarioDescription();
~ScenarioDescription();

qint64 id;
QDateTime creationDate;
QString aircraftType;
QDateTime startDate;
QDateTime endDate;
QString startLocation;
QString endLocation;
QString description;
};

#endif // SCENARIODESCRIPTION_H
15 changes: 7 additions & 8 deletions src/Model/src/SecondaryFlightControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,13 @@ SecondaryFlightControl::~SecondaryFlightControl() noexcept
{
}

void SecondaryFlightControl::upsert(SecondaryFlightControlData secondaryFlightControlData) noexcept
void SecondaryFlightControl::upsert(const SecondaryFlightControlData &secondaryFlightControlData) noexcept
{
if (d->secondaryFlightControlData.count() > 0 && d->secondaryFlightControlData.last().timestamp == secondaryFlightControlData.timestamp) {
// Same timestamp -> replace
d->secondaryFlightControlData[d->secondaryFlightControlData.count() - 1] = secondaryFlightControlData;
#ifdef DEBUG
qDebug("SecondaryFlightControl::upsertSecondaryFlightControlData: UPDATE sample, timestamp: %llu count: %d", secondaryFlightControlData.timestamp, d->secondaryFlightControlData.count());
#endif
} else {
d->secondaryFlightControlData.append(secondaryFlightControlData);
#ifdef DEBUG
qDebug("SecondaryFlightControl::upsertSecondaryFlightControlData: INSERT sample, timestamp: %llu count: %d", secondaryFlightControlData.timestamp, d->secondaryFlightControlData.count());
#endif
}
emit dataChanged();
}
Expand All @@ -89,7 +83,12 @@ const SecondaryFlightControlData &SecondaryFlightControl::getLast() const noexce
}
}

const QVector<SecondaryFlightControlData> &SecondaryFlightControl::getAll() const noexcept
QVector<SecondaryFlightControlData> &SecondaryFlightControl::getAll() const noexcept
{
return d->secondaryFlightControlData;
}

const QVector<SecondaryFlightControlData> &SecondaryFlightControl::getAllConst() const noexcept
{
return d->secondaryFlightControlData;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Model/src/SecondaryFlightControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MODEL_API SecondaryFlightControl : public QObject
SecondaryFlightControl(QObject *parent = nullptr) noexcept;
virtual ~SecondaryFlightControl() noexcept;

void upsert(SecondaryFlightControlData secondaryFlightControlData) noexcept;
void upsert(const SecondaryFlightControlData &secondaryFlightControlData) noexcept;
const SecondaryFlightControlData &getLast() const noexcept;
const QVector<SecondaryFlightControlData> &getAll() const noexcept;
QVector<SecondaryFlightControlData> &getAll() const noexcept;
const QVector<SecondaryFlightControlData> &getAllConst() const noexcept;
const SecondaryFlightControlData &interpolate(qint64 timestamp, TimeVariableData::Access access) const noexcept;

void clear() noexcept;
Expand Down
55 changes: 32 additions & 23 deletions src/Model/src/SimVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,39 @@ const char *SimVar::FoldingWingHandlePosition = "Folding Wing Handle Position";

const char *SimVar::LightStates = "Light States";

const char *SimVar::Title= "Title";
const char *SimVar::ATCId= "ATC Id";
const char *SimVar::ATCAirline= "ATC Airline";
const char *SimVar::ATCFlightNumber= "ATC Flight Number";
const char *SimVar::Category= "Category";
const char *SimVar::Title = "Title";
const char *SimVar::ATCId = "ATC Id";
const char *SimVar::ATCAirline = "ATC Airline";
const char *SimVar::ATCFlightNumber = "ATC Flight Number";
const char *SimVar::Category = "Category";

const char *SimVar::SimOnGround= "Sim On Ground";
const char *SimVar::PlaneAltAboveGround= "Plane Alt Above Ground";
const char *SimVar::AirspeedTrue= "Airspeed True";
const char *SimVar::SurfaceType= "Surface Type";
const char *SimVar::WingSpan= "Wing Span";
const char *SimVar::NumberOfEngines= "Number Of Engines";
const char *SimVar::EngineType= "Engine Type";
const char *SimVar::SimOnGround = "Sim On Ground";
const char *SimVar::PlaneAltAboveGround = "Plane Alt Above Ground";
const char *SimVar::AirspeedTrue = "Airspeed True";
const char *SimVar::SurfaceType = "Surface Type";
const char *SimVar::WingSpan = "Wing Span";
const char *SimVar::NumberOfEngines = "Number Of Engines";
const char *SimVar::EngineType = "Engine Type";

const char *SimVar::GroundAltitude= "Ground Altitude";
const char *SimVar::AmbientTemperature= "Ambient Temperature";
const char *SimVar::TotalAirTemperature= "Total Air Temperature";
const char *SimVar::AmbientWindVelocity= "Ambient Wind Velocity";
const char *SimVar::AmbientWindDirection= "Ambient Wind Direction";
const char *SimVar::AmbientPrecipState= "Ambient Precip State";
const char *SimVar::AmbientInCloud= "Ambient In Cloud";
const char *SimVar::AmbientVisibility= "Ambient Visibility";
const char *SimVar::SeaLevelPressure= "Sea Level Pressure";
const char *SimVar::PitotIcePct= "Pitot Ice Pct";
const char *SimVar::StructuralIcePct= "Structural Ice Pct";
const char *SimVar::GroundAltitude = "Ground Altitude";
const char *SimVar::AmbientTemperature = "Ambient Temperature";
const char *SimVar::TotalAirTemperature = "Total Air Temperature";
const char *SimVar::AmbientWindVelocity = "Ambient Wind Velocity";
const char *SimVar::AmbientWindDirection = "Ambient Wind Direction";
const char *SimVar::AmbientPrecipState = "Ambient Precip State";
const char *SimVar::AmbientInCloud = "Ambient In Cloud";
const char *SimVar::AmbientVisibility = "Ambient Visibility";
const char *SimVar::SeaLevelPressure = "Sea Level Pressure";
const char *SimVar::PitotIcePct = "Pitot Ice Pct";
const char *SimVar::StructuralIcePct = "Structural Ice Pct";

const char *SimVar::GpsWPNextId = "GPS WP Next Id";
const char *SimVar::GpsWPNextLat = "GPS WP Next Lat";
const char *SimVar::GpsWPNextLon = "GPS WP Next Lon";
const char *SimVar::GpsWPNextAlt = "GPS WP Next Alt";
const char *SimVar::GpsWPPrevId = "GPS WP Prev Id";
const char *SimVar::GpsWPPrevLat = "GPS WP Prev Lat";
const char *SimVar::GpsWPPrevLon = "GPS WP Prev Lon";
const char *SimVar::GpsWPPrevAlt = "GPS WP Prev Alt";

const char *SimVar::Timestamp = "Timestamp";
19 changes: 19 additions & 0 deletions src/Model/src/SimVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ namespace SimVar
MODEL_API extern const char *PitotIcePct;
MODEL_API extern const char *StructuralIcePct;

MODEL_API extern const char *GpsWPNextId;
MODEL_API extern const char *GpsWPNextLat;
MODEL_API extern const char *GpsWPNextLon;
MODEL_API extern const char *GpsWPNextAlt;
MODEL_API extern const char *GpsWPPrevId;
MODEL_API extern const char *GpsWPPrevLat;
MODEL_API extern const char *GpsWPPrevLon;
MODEL_API extern const char *GpsWPPrevAlt;

inline constexpr char LocalTime[] = "Local Time";
inline constexpr char LocalYear[] = "Local Year";
inline constexpr char LocalMonthOfYear[] = "Local Month of Year";
inline constexpr char LocalDayOfMonth[] = "Local Day of Month";

inline constexpr char ZuluTime[] = "Zulu Time";
inline constexpr char ZuluYear[] = "Zulu Year";
inline constexpr char ZuluMonthOfYear[] = "Zulu Month of Year";
inline constexpr char ZuluDayOfMonth[] = "Zulu Day of Month";

MODEL_API extern const char *Timestamp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/src/TimeVariableData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

struct MODEL_API TimeVariableData
{
static inline constexpr qint64 InvalidTime = std::numeric_limits<qint64>::min();
static constexpr qint64 InvalidTime = std::numeric_limits<qint64>::min();

enum class Access {
Linear,
Expand Down
84 changes: 84 additions & 0 deletions src/Persistence/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
add_definitions(-DPERSISTENCE_EXPORT)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_library(Persistence SHARED "")
else()
add_library(Persistence SHARED "")
endif()

target_sources(Persistence
PRIVATE
src/PersistenceLib.h
src/ConnectionManager.cpp
src/ConnectionManager.h
src/Metadata.h
src/Dao/DatabaseDaoIntf.h
src/Dao/ScenarioDaoIntf.h
src/Dao/AircraftDaoIntf.h
src/Dao/PositionDaoIntf.h
src/Dao/EngineDaoIntf.h
src/Dao/PrimaryFlightControlDaoIntf.h
src/Dao/SecondaryFlightControlDaoIntf.h
src/Dao/HandleDaoIntf.h
src/Dao/LightDaoIntf.h
src/Dao/FlightPlanDaoIntf.h
src/Dao/DaoFactory.cpp
src/Dao/DaoFactory.h
src/Dao/SQLite/SQLiteDatabaseDao.cpp
src/Dao/SQLite/SQLiteDatabaseDao.h
src/Dao/SQLite/SQLiteScenarioDao.cpp
src/Dao/SQLite/SQLiteScenarioDao.h
src/Dao/SQLite/SQLiteAircraftDao.cpp
src/Dao/SQLite/SQLiteAircraftDao.h
src/Dao/SQLite/SQLitePositionDao.cpp
src/Dao/SQLite/SQLitePositionDao.h
src/Dao/SQLite/SQLiteEngineDao.cpp
src/Dao/SQLite/SQLiteEngineDao.h
src/Dao/SQLite/SQLitePrimaryFlightControlDao.cpp
src/Dao/SQLite/SQLitePrimaryFlightControlDao.h
src/Dao/SQLite/SQLiteSecondaryFlightControlDao.cpp
src/Dao/SQLite/SQLiteSecondaryFlightControlDao.h
src/Dao/SQLite/SQLiteHandleDao.cpp
src/Dao/SQLite/SQLiteHandleDao.h
src/Dao/SQLite/SQLiteLightDao.cpp
src/Dao/SQLite/SQLiteLightDao.h
src/Dao/SQLite/SQLiteFlightPlanDao.cpp
src/Dao/SQLite/SQLiteFlightPlanDao.h
src/Dao/SQLite/SqlMigration.cpp
src/Dao/SQLite/SqlMigration.h
src/Dao/SQLite/SqlMigrationStep.cpp
src/Dao/SQLite/SqlMigrationStep.h
src/Dao/SQLite/Migration/migr-ex-ante.sql
src/Dao/SQLite/Migration/migr-ddl.sql
src/Dao/SQLite/Migration/migr-ex-post.sql
src/Dao/SQLite/Migration/Migration.qrc
src/Service/ScenarioService.cpp
src/Service/ScenarioService.h
src/Service/AircraftService.cpp
src/Service/AircraftService.h
src/Service/DatabaseService.cpp
src/Service/DatabaseService.h
src/Service/CSVService.cpp
src/Service/CSVService.h
src/CSVConst.cpp
src/CSVConst.h
src/Export/CSVExport.cpp
src/Export/CSVExport.h
src/Import/CSVImport.cpp
src/Import/CSVImport.h
)

set(PERSISTENCE_LIBS
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Sql Kernel Model
)
if (APPLE)
list(APPEND PERSISTENCE_LIBS -lc++)
endif()

target_link_libraries(Persistence PRIVATE ${PERSISTENCE_LIBS})
set_target_properties(Persistence PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(Persistence PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})

target_include_directories(Persistence PUBLIC
"${CMAKE_CURRENT_BINARY_DIR}"
)
File renamed without changes.
10 changes: 8 additions & 2 deletions src/Model/src/CSVConst.h → src/Persistence/src/CSVConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#define CSVCONST_H

namespace CSVConst {

/*! Separator character for CSV import & export */
inline constexpr char Sep = '\t';
/*! Newline character for CSV import & export */
inline constexpr char Ln = '\n';

// Format and precision for double
constexpr char Format = 'g';
constexpr int Precision = 9;
inline constexpr char Format = 'g';
inline constexpr int Precision = 9;

enum class DataType : char {
Aircraft = 'a',
Expand Down
132 changes: 132 additions & 0 deletions src/Persistence/src/ConnectionManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <memory>

#include <QString>

#include "../../Kernel/src/Settings.h"
#include "Metadata.h"
#include "Dao/DaoFactory.h"
#include "Dao/DatabaseDaoIntf.h"
#include "ConnectionManager.h"

class ConnectionManagerPrivate
{
public:

std::unique_ptr<DaoFactory> daoFactory;
std::unique_ptr<DatabaseDaoIntf> databaseDao;
QString libraryPath;
bool connected;

static ConnectionManager *instance;

ConnectionManagerPrivate() noexcept
: daoFactory(std::make_unique<DaoFactory>(DaoFactory::DbType::SQLite)),
databaseDao(daoFactory->createDatabaseDao()),
connected(false)
{}
};

ConnectionManager *ConnectionManagerPrivate::instance = nullptr;

// PUBLIC

ConnectionManager &ConnectionManager::getInstance() noexcept
{
if (ConnectionManagerPrivate::instance == nullptr) {
ConnectionManagerPrivate::instance = new ConnectionManager();
}
return *ConnectionManagerPrivate::instance;
}

void ConnectionManager::destroyInstance() noexcept
{
if (ConnectionManagerPrivate::instance != nullptr) {
delete ConnectionManagerPrivate::instance;
ConnectionManagerPrivate::instance = nullptr;
}
}

bool ConnectionManager::connectDb(const QString &libraryPath) noexcept
{
if (d->libraryPath != libraryPath) {
d->connected = d->databaseDao->connectDb(libraryPath);
d->libraryPath = libraryPath;
emit connectionChanged(d->connected);
}
return d->connected;
}

void ConnectionManager::disconnectDb() noexcept
{
d->databaseDao->disconnectDb();
d->connected = false;
emit connectionChanged(d->connected);
}

bool ConnectionManager::isConnected() const noexcept
{
return d->connected;
}

const QString &ConnectionManager::getLibraryPath() const noexcept
{
return d->libraryPath;
}

bool ConnectionManager::migrate() noexcept
{
return d->databaseDao->migrate();
}

bool ConnectionManager::optimise() noexcept
{
emit connectionChanged(d->connected);
return d->databaseDao->optimise();
}

bool ConnectionManager::backup(const QString &backupLibraryPath) noexcept
{
emit connectionChanged(d->connected);
return d->databaseDao->backup(backupLibraryPath);
}

bool ConnectionManager::getMetadata(Metadata &metadata) noexcept
{
return d->databaseDao->getMetadata(metadata);
}

// PROTECTED

ConnectionManager::~ConnectionManager() noexcept
{}

// PRIVATE

ConnectionManager::ConnectionManager() noexcept
: d(std::make_unique<ConnectionManagerPrivate>())
{}

70 changes: 70 additions & 0 deletions src/Persistence/src/ConnectionManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H

#include <memory>

#include <QObject>

class QString;

class Metadata;

#include "PersistenceLib.h"

class ConnectionManagerPrivate;

class ConnectionManager : public QObject
{
Q_OBJECT
public:
static ConnectionManager &getInstance() noexcept;
PERSISTENCE_API static void destroyInstance() noexcept;

bool connectDb(const QString &libraryPath) noexcept;
void disconnectDb() noexcept;
bool isConnected() const noexcept;
const QString &getLibraryPath() const noexcept;

bool migrate() noexcept;
bool optimise() noexcept;
bool backup(const QString &backupLibraryPath) noexcept;
bool getMetadata(Metadata &metadata) noexcept;

signals:
void connectionChanged(bool connected);

protected:
virtual ~ConnectionManager() noexcept;

private:
Q_DISABLE_COPY(ConnectionManager)
std::unique_ptr<ConnectionManagerPrivate> d;

ConnectionManager() noexcept;
};

#endif // CONNECTIONMANAGER_H
54 changes: 54 additions & 0 deletions src/Persistence/src/Dao/AircraftDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef AIRCRAFTDAOINTF_H
#define AIRCRAFTDAOINTF_H

#include <QtGlobal>

class Aircraft;

class AircraftDaoIntf
{
public:
virtual ~AircraftDaoIntf() = default;

/*!
* Persists the \c aircraft. The \c id in \c aircraft is updated.
*
* \param scenarioId
* the scenario the \c aircraft belongs to
* \param sequenceNumber
* the sequence number of the aircraft
* \param aircraft
* the aircraft to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 scenarioId, int sequenceNumber, Aircraft &aircraft) = 0;
virtual bool getById(qint64 id, Aircraft &aircraft) const = 0;
virtual bool getByScenarioId(qint64 scenarioId, int sequenceNumber, Aircraft &aircraft) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // AIRCRAFTDAOINTF_H
185 changes: 185 additions & 0 deletions src/Persistence/src/Dao/DaoFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <memory>

#include "SQLite/SQLiteDatabaseDao.h"
#include "SQLite/SQLiteScenarioDao.h"
#include "SQLite/SQLiteAircraftDao.h"
#include "SQLite/SQLitePositionDao.h"
#include "SQLite/SQLiteEngineDao.h"
#include "SQLite/SQLitePrimaryFlightControlDao.h"
#include "SQLite/SQLiteSecondaryFlightControlDao.h"
#include "SQLite/SQLiteHandleDao.h"
#include "SQLite/SQLiteLightDao.h"
#include "SQLite/SQLiteFlightPlanDao.h"
#include "ScenarioDaoIntf.h"
#include "AircraftDaoIntf.h"
#include "PositionDaoIntf.h"
#include "EngineDaoIntf.h"
#include "PrimaryFlightControlDaoIntf.h"
#include "SecondaryFlightControlDaoIntf.h"
#include "HandleDaoIntf.h"
#include "LightDaoIntf.h"
#include "FlightPlanDaoIntf.h"
#include "DaoFactory.h"

class DaoFactoryPrivate
{
public:
DaoFactoryPrivate(DaoFactory::DbType theDbType)
: dbType(theDbType)
{}

DaoFactory::DbType dbType;
};

// PUBLIC

DaoFactory::DaoFactory(DbType dbType)
: d(std::make_unique<DaoFactoryPrivate>(dbType))
{}

DaoFactory::~DaoFactory()
{}

std::unique_ptr<DatabaseDaoIntf> DaoFactory::createDatabaseDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteDatabaseDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<ScenarioDaoIntf> DaoFactory::createScenarioDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteScenarioDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<AircraftDaoIntf> DaoFactory::createAircraftDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteAircraftDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<PositionDaoIntf> DaoFactory::createPositionDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLitePositionDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<EngineDaoIntf> DaoFactory::createEngineDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteEngineDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<PrimaryFlightControlDaoIntf> DaoFactory::createPrimaryFlightControlDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLitePrimaryFlightControlDao>();
break;
default:
return nullptr;
break;
}
};

std::unique_ptr<SecondaryFlightControlDaoIntf> DaoFactory::createSecondaryFlightControlDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteSecondaryFlightControlDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<HandleDaoIntf> DaoFactory::createHandleDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteHandleDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<LightDaoIntf> DaoFactory::createLightDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteLightDao>();
break;
default:
return nullptr;
break;
}
}

std::unique_ptr<FlightPlanDaoIntf> DaoFactory::createFlightPlanDao() noexcept
{
switch (d->dbType) {
case DbType::SQLite:
return std::make_unique<SQLiteFlightPlanDao>();
break;
default:
return nullptr;
break;
}
}
70 changes: 70 additions & 0 deletions src/Persistence/src/Dao/DaoFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef DAOFACTORY_H
#define DAOFACTORY_H

#include <memory>

#include "ScenarioDaoIntf.h"
#include "AircraftDaoIntf.h"
#include "PositionDaoIntf.h"
#include "EngineDaoIntf.h"
#include "PrimaryFlightControlDaoIntf.h"
#include "SecondaryFlightControlDaoIntf.h"
#include "HandleDaoIntf.h"
#include "LightDaoIntf.h"
#include "FlightPlanDaoIntf.h"
#include "DatabaseDaoIntf.h"

class DaoFactoryPrivate;

class DaoFactory
{
public:

enum class DbType
{
SQLite = 0
};

DaoFactory(DbType dbType);
~DaoFactory();

std::unique_ptr<DatabaseDaoIntf> createDatabaseDao() noexcept;
std::unique_ptr<ScenarioDaoIntf> createScenarioDao() noexcept;
std::unique_ptr<AircraftDaoIntf> createAircraftDao() noexcept;
std::unique_ptr<PositionDaoIntf> createPositionDao() noexcept;
std::unique_ptr<EngineDaoIntf> createEngineDao() noexcept;
std::unique_ptr<PrimaryFlightControlDaoIntf> createPrimaryFlightControlDao() noexcept;
std::unique_ptr<SecondaryFlightControlDaoIntf> createSecondaryFlightControlDao() noexcept;
std::unique_ptr<HandleDaoIntf> createHandleDao() noexcept;
std::unique_ptr<LightDaoIntf> createLightDao() noexcept;
std::unique_ptr<FlightPlanDaoIntf> createFlightPlanDao() noexcept;

private:
std::unique_ptr<DaoFactoryPrivate> d;
};

#endif // DAOFACTORY_H
47 changes: 47 additions & 0 deletions src/Persistence/src/Dao/DatabaseDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef DATABASEDAOINTF_H
#define DATABASEDAOINTF_H

class QString;

#include "../Metadata.h"

class DatabaseDaoIntf
{
public:
virtual ~DatabaseDaoIntf() = default;

virtual bool connectDb(const QString &libraryPath) = 0;
virtual void disconnectDb() = 0;

virtual bool migrate() = 0;
virtual bool optimise() = 0;
virtual bool backup(const QString &backupPath) = 0;

virtual bool getMetadata(Metadata &metadata) const = 0;
};

#endif // DATABASEDAOINTF_H
52 changes: 52 additions & 0 deletions src/Persistence/src/Dao/EngineDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef ENGINEDAOINTF_H
#define ENGINEDAOINTF_H

#include <QVector>

class EngineData;

class EngineDaoIntf
{
public:
virtual ~EngineDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the EngineData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const EngineData &data) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<EngineData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};


#endif // ENGINEDAOINTF_H
49 changes: 49 additions & 0 deletions src/Persistence/src/Dao/FlightPlanDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef FLIGHTPLANDAOINTF_H
#define FLIGHTPLANDAOINTF_H

class FlightPlanData;

class FlightPlanDaoIntf
{
public:
virtual ~FlightPlanDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the FlightPlanData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const QVector<FlightPlanData> &data) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<FlightPlanData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // FLIGHTPLANDAOINTF_H
51 changes: 51 additions & 0 deletions src/Persistence/src/Dao/HandleDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef HANDLEDAOINTF_H
#define HANDLEDAOINTF_H

#include <QVector>

class AircraftHandleData;

class HandleDaoIntf
{
public:
virtual ~HandleDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the AircraftHandleData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const AircraftHandleData &data) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<AircraftHandleData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // HANDLEDAOINTF_H
49 changes: 49 additions & 0 deletions src/Persistence/src/Dao/LightDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef LIGHTDAOINTF_H
#define LIGHTDAOINTF_H

class LightData;

class LightDaoIntf
{
public:
virtual ~LightDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the LightData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const LightData &lightData) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<LightData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // LIGHTDAOINTF_H
51 changes: 51 additions & 0 deletions src/Persistence/src/Dao/PositionDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef POSITIONDAOINTF_H
#define POSITIONDAOINTF_H

#include <QVector>

class AircraftData;

class PositionDaoIntf
{
public:
virtual ~PositionDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the AircraftData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const AircraftData &data) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<AircraftData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // POSITIONDAOINTF_H
51 changes: 51 additions & 0 deletions src/Persistence/src/Dao/PrimaryFlightControlDaoIntf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef PRIMARYFLIGHTCONTROLDAOINTF_H
#define PRIMARYFLIGHTCONTROLDAOINTF_H

#include <QVector>

class PrimaryFlightControlData;

class PrimaryFlightControlDaoIntf
{
public:
virtual ~PrimaryFlightControlDaoIntf() = default;

/*!
* Persists the \c data.
*
* \param aircraftId
* the aircraft the \c data belongs to
* \param data
* the SecondaryFlightControlData to be persisted
* \return \c true on success; \c false else
*/
virtual bool add(qint64 aircraftId, const PrimaryFlightControlData &primaryFlightControlData) = 0;
virtual bool getByAircraftId(qint64 aircraftId, QVector<PrimaryFlightControlData> &data) const = 0;
virtual bool deleteByScenarioId(qint64 scenarioId) = 0;
};

#endif // PRIMARYFLIGHTCONTROLDAOINTF_H
88 changes: 88 additions & 0 deletions src/Persistence/src/Dao/SQLite/DbMigration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <QFile>
#include <QTextStream>
#include <QRegularExpression>

#include "DbMigration.h"

class DbMigrationPrivate
{
public:
DbMigrationPrivate()
{}
};

// PUBLIC

DbMigration::DbMigration()
: d(std::make_unique<DbMigrationPrivate>())
{
}

DbMigration::~DbMigration()
{}

bool DbMigration::migrateExAnte() noexcept
{
return true;
}

bool DbMigration::migrateDdl() noexcept
{

Q_INIT_RESOURCE(Migration);

QFile migr(":/dao/sqlite/migr/migr-ddl.sql");
migr.open(QFile::OpenModeFlag::ReadOnly | QFile::OpenModeFlag::Text);

QTextStream textStream(&migr);
QStringList lines;
while (!textStream.atEnd()) {
lines += textStream.readLine();
}

for (const QString &line : std::as_const(lines)) {
if (line.trimmed().startsWith("@migr")) {
// https://regex101.com/
const QRegularExpression regexp("@migr\\(([\\w=\"\\-,.\\s]+)\\)");
QRegularExpressionMatch match = regexp.match(line);
if (match.hasMatch()) {
QString migrTag = match.captured();
qDebug("migration: %s", qPrintable(migrTag));
}
}
}

migr.close();

return true;
}

bool DbMigration::migrateExPost() noexcept
{
return true;
}

48 changes: 48 additions & 0 deletions src/Persistence/src/Dao/SQLite/DbMigration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Sky Dolly - The black sheep for your flight recordings
*
* Copyright (c) Oliver Knoll
* All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef DBMIGRATION_H
#define DBMIGRATION_H

#include <memory>

#include <QString>

class DbMigrationPrivate;

class DbMigration
{
public:
DbMigration();
~DbMigration();

bool migrateExAnte() noexcept;
bool migrateDdl() noexcept;
bool migrateExPost() noexcept;

private:
std::unique_ptr<DbMigrationPrivate> d;
};

#endif // DBMIGRATION_H
7 changes: 7 additions & 0 deletions src/Persistence/src/Dao/SQLite/Migration/Migration.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/dao/sqlite/migr">
<file>migr-ddl.sql</file>
<file>migr-ex-ante.sql</file>
<file>migr-ex-post.sql</file>
</qresource>
</RCC>
162 changes: 162 additions & 0 deletions src/Persistence/src/Dao/SQLite/Migration/migr-ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
@migr(id = "4a66fae6-d70a-4230-ad1e-0db27c9b1466", descn = "Create meta info table", step_cnt = 2)
create table meta (
creation_date datetime,
last_optim_date datetime,
last_backup_date datetime
);

@migr(id = "da30cf74-c698-4a73-bad1-c1cf3f380f32", descn = "Create scenario table", step_cnt = 1)
create table scenario (
id integer primary key,
creation_date datetime default current_timestamp,
description text,
surface_type integer,
ground_altitude real,
ambient_temperature real,
total_air_temperature real,
wind_velocity real,
wind_direction real,
visibility real,
sea_level_pressure real,
pitot_icing real,
structural_icing real,
precipitation_state integer,
in_clouds integer,
local_sim_time datetime,
zulu_sim_time datetime
);

@migr(id = "1fb17949-6c94-4bbf-98a2-ff54fe3a749f", descn = "Create aircraft table", step_cnt = 1)
create table aircraft (
id integer primary key,
scenario_id integer not null,
seq_nr integer not null,
start_date datetime,
end_date datetime,
type text,
tail_number text,
airline text,
flight_number text,
category integer,
initial_airspeed integer,
wing_span integer,
engine_type integer,
nof_engines integer,
altitude_above_ground real,
start_on_ground integer,
foreign key(scenario_id) references scenario(id)
);
create unique index aircraft_idx1 on aircraft (scenario_id, seq_nr);

@migr(id = "9b831594-f6c2-489c-906d-2de31bb9788b", descn = "Create position table", step_cnt = 1)
create table position (
aircraft_id integer not null,
timestamp integer not null,
latitude real,
longitude real,
altitude real,
pitch real,
bank real,
heading real,
velocity_x real,
velocity_y real,
velocity_z real,
rotation_velocity_x real,
rotation_velocity_y real,
rotation_velocity_z real,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "0f5e5cc3-8977-4de0-be15-104f3ab045aa", descn = "Create engine table", step_cnt = 1)
create table engine (
aircraft_id integer not null,
timestamp integer not null,
throttle_lever_position1 real,
throttle_lever_position2 real,
throttle_lever_position3 real,
throttle_lever_position4 real,
propeller_lever_position1 real,
propeller_lever_position2 real,
propeller_lever_position3 real,
propeller_lever_position4 real,
mixture_lever_position1 real,
mixture_lever_position2 real,
mixture_lever_position3 real,
mixture_lever_position4 real,
cowl_flap_position1 real,
cowl_flap_position2 real,
cowl_flap_position3 real,
cowl_flap_position4 real,
electrical_master_battery1 real,
electrical_master_battery2 real,
electrical_master_battery3 real,
electrical_master_battery4 real,
general_engine_starter1 real,
general_engine_starter2 real,
general_engine_starter3 real,
general_engine_starter4 real,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "148779f2-44c5-4d8c-9c0a-06d6d8158655", descn = "Create primary flight controls table", step_cnt = 1)
create table primary_flight_control (
aircraft_id integer not null,
timestamp integer not null,
rudder_position integer,
elevator_position integer,
aileron_position integer,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "73f7c48a-53f4-42a7-ab1d-011266c8ead3", descn = "Create secondary flight controls table", step_cnt = 1)
create table secondary_flight_control (
aircraft_id integer not null,
timestamp integer not null,
leading_edge_flaps_left_percent integer,
leading_edge_flaps_right_percent integer,
trailing_edge_flaps_left_percent integer,
trailing_edge_flaps_right_percent integer,
spoilers_handle_position integer,
flaps_handle_index integer,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "b9a56065-d6ac-4572-bba0-39f7ba8a3169", descn = "Create handles and levers table", step_cnt = 1)
create table handle (
aircraft_id integer not null,
timestamp integer not null,
brake_left_position integer,
brake_right_position integer,
water_rudder_handle_position integer,
tail_hook_position integer,
canopy_open integer,
gear_handle_position integer,
folding_wing_handle_position integer,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "ae5cb680-41fa-40e8-8ea9-0777c3574bd4", descn = "Create lights table", step_cnt = 1)
create table light (
aircraft_id integer not null,
timestamp integer not null,
light_states integer,
primary key(aircraft_id, timestamp),
foreign key(aircraft_id) references aircraft(id)
);

@migr(id = "fb2a21ad-5b8d-4be0-ae94-33e63be2ef3a", descn = "Create flight plan table", step_cnt = 1)
create table flight_plan (
aircraft_id integer not null,
seq_nr integer,
ident text,
latitude real,
longitude real,
altitude real,
primary key(aircraft_id, seq_nr),
foreign key(aircraft_id) references aircraft(id)
);
Empty file.
3 changes: 3 additions & 0 deletions src/Persistence/src/Dao/SQLite/Migration/migr-ex-post.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@migr(id = "4a66fae6-d70a-4230-ad1e-0db27c9b1466", descn = "Create meta info table", step = 2)
insert into meta (creation_date)
values (datetime('now'));
Loading