Skip to content

Commit

Permalink
Feature/location import export sdlog (#144)
Browse files Browse the repository at this point in the history
* Replace fromLatin1 with QStringLiteral, where applicable

* Initial location export in Sky Dolly logbook format

* Add SDLog location export plugin

* Add initial location export service implementation (WIP)

* Implement basic location export

* Fix typo

* Move location selection logic into actual location export plugin

* Use auto instead of std::int64_t

* Remove QStringLiteral again

- This stems from an outdated "clazy" code recommendation based on Qt 4

* Use auto instead of std::int64_t

* Add location export option to include system locations or not

* Add tooltips
  • Loading branch information
till213 authored May 10, 2024
1 parent 8ffa79c commit e49b3ba
Show file tree
Hide file tree
Showing 38 changed files with 682 additions and 224 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
## 0.18.0

## New Features
- New location export plugin
* Sky Dolly logbook (*.sdlog) export

## Improvements
- A new *Export system locations* option has been added to the location export
* When enabled then also the default locations as provided by Sky Dolly (*Sytem* locations) will be exported
* Otherwise only the *User* and *Import* locations will be exported

## Bug Fixes

Expand Down
15 changes: 7 additions & 8 deletions src/Flight/src/FlightAugmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <memory>
#include <algorithm>
#include <cstdint>
#include <utility>

#include <Kernel/Convert.h>
#include <Kernel/SkyMath.h>
Expand Down Expand Up @@ -60,8 +59,8 @@ namespace {

struct FlightAugmentationPrivate
{
FlightAugmentationPrivate(FlightAugmentation::Procedures theProcedures, FlightAugmentation::Aspects theAspects)
: procedures(theProcedures),
FlightAugmentationPrivate(FlightAugmentation::Procedures procedures, FlightAugmentation::Aspects theAspects)
: procedures(procedures),
aspects(theAspects)
{}

Expand Down Expand Up @@ -124,9 +123,9 @@ void FlightAugmentation::augmentAttitudeAndVelocity(Aircraft &aircraft) noexcept
PositionData &startPositionData = position[i];
const PositionData &endPositionData = position[i + 1];
const SkyMath::Coordinate startPosition(startPositionData.latitude, startPositionData.longitude);
const std::int64_t startTimestamp = startPositionData.timestamp;
const SkyMath::Coordinate endPosition(endPositionData.latitude, endPositionData.longitude);
const std::int64_t endTimestamp = endPositionData.timestamp;
const auto startTimestamp = startPositionData.timestamp;
const SkyMath::Coordinate endPosition {endPositionData.latitude, endPositionData.longitude};
const auto endTimestamp = endPositionData.timestamp;

const auto [distance, speed] = SkyMath::distanceAndSpeed(startPosition, startTimestamp, endPosition, endTimestamp);
// Velocity
Expand Down Expand Up @@ -244,7 +243,7 @@ void FlightAugmentation::augmentProcedures(Aircraft &aircraft) noexcept

void FlightAugmentation::augmentStartProcedure(Aircraft &aircraft) noexcept
{
const std::int64_t lastTimestamp = aircraft.getPosition().getLast().timestamp;
const auto lastTimestamp = aircraft.getPosition().getLast().timestamp;

if (d->aspects.testFlag(Aspect::Engine)) {

Expand Down Expand Up @@ -428,7 +427,7 @@ void FlightAugmentation::augmentStartProcedure(Aircraft &aircraft) noexcept
void FlightAugmentation::augmentLandingProcedure(Aircraft &aircraft) noexcept
{
Position &position = aircraft.getPosition();
const std::int64_t lastTimestamp = position.getLast().timestamp;
const auto lastTimestamp = position.getLast().timestamp;

// Engine
if (d->aspects.testFlag(Aspect::Engine)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/src/SkySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

double SkySearch::normaliseTimestamp(const TimeVariableData &p1, const TimeVariableData &p2, std::int64_t timestamp) noexcept
{
std::int64_t t2 = p2.timestamp - p1.timestamp;
const auto t2 = p2.timestamp - p1.timestamp;
if (t2 != 0) {
std::int64_t t1 = timestamp - p1.timestamp;
const auto t1 = timestamp - p1.timestamp;
return static_cast<double>(t1) / static_cast<double>(t2);
} else {
// p1 and p2 are the same (last sampled) point
Expand Down
13 changes: 12 additions & 1 deletion src/Persistence/include/Persistence/LocationSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@
struct PERSISTENCE_API LocationSelector
{
using TypeSelection = std::unordered_set<std::int64_t>;
TypeSelection typeSelection;
TypeSelection typeSelection {};
std::int64_t categoryId {Const::InvalidId};
std::int64_t countryId {Const::InvalidId};
QString searchKeyword;

LocationSelector(TypeSelection selection)
: typeSelection(std::move(selection))
{}

LocationSelector() = default;
LocationSelector(const LocationSelector &rhs) = delete;
LocationSelector(LocationSelector &&rhs) = default;
LocationSelector &operator=(const LocationSelector &rhs) = delete;
LocationSelector &operator=(LocationSelector &&rhs) = default;
~LocationSelector() = default;

inline bool hasSelectors() const noexcept
{
return typeSelection.size() > 0 ||
Expand Down
1 change: 0 additions & 1 deletion src/Persistence/include/Persistence/PersistenceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define PERSISTENCEMANAGER_H

#include <memory>
#include <utility>

#include <QObject>

Expand Down
13 changes: 13 additions & 0 deletions src/Persistence/include/Persistence/Service/LocationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ class PERSISTENCE_API LocationService final
~LocationService();

bool store(Location &location) noexcept;
bool exportLocation(const Location &location) noexcept;
bool storeAll(std::vector<Location> &locations, Mode mode) noexcept;

/*!
* Exports the \c locations, but does not emit any signal. The \c id of the locations is
* left unchanged (possibly still Const#InvalidId).
*
* \param locations
* the locations that will be exported, typically into another logbook
* \return \c true upon success; \c false else
* \sa storeAll
*/
bool exportAll(const std::vector<Location> &locations) noexcept;

bool update(const Location &location) noexcept;
bool deleteById(std::int64_t id) noexcept;
std::vector<Location> getAll(bool *ok = nullptr) const noexcept;
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/src/Dao/LocationDaoIntf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LocationDaoIntf
virtual ~LocationDaoIntf() = default;

virtual bool add(Location &location) const noexcept = 0;
virtual bool exportLocation(const Location &location) const noexcept = 0;
virtual bool update(const Location &location) const noexcept = 0;

/*!
Expand Down
6 changes: 2 additions & 4 deletions src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,13 @@ inline std::int64_t SQLiteAircraftDao::insertAircraft(std::int64_t flightId, std
}
if (ok) {
aircraftId = query.lastInsertId().toLongLong(&ok);
#ifdef DEBUG
} else {
aircraftId = Const::InvalidId;
#ifdef DEBUG
qDebug() << "SQLiteAircraftDao::insertAircraft: SQL error" << query.lastError().text() << "- error code:" << query.lastError().nativeErrorCode() << "- flight ID" << flightId << "- sequence number" << sequenceNumber;
#endif
}

if (!ok) {
aircraftId = Const::InvalidId;
}
return aircraftId;
}

Expand Down
6 changes: 2 additions & 4 deletions src/Persistence/src/Dao/SQLite/SQLiteFlightDao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,13 @@ inline std::int64_t SQLiteFlightDao::insertFlight(const FlightData &flightData)
bool ok = query.exec();
if (ok) {
flightId = query.lastInsertId().toLongLong(&ok);
#ifdef DEBUG
} else {
flightId = Const::InvalidId;
#ifdef DEBUG
qDebug() << "SQLiteFlightDao::insertFlight: SQL error:" << query.lastError().text() << "- error code:" << query.lastError().nativeErrorCode();
#endif
}

if (!ok) {
flightId = Const::InvalidId;
}
return flightId;
}

Expand Down
Loading

0 comments on commit e49b3ba

Please sign in to comment.