From 1b85305803f8bd107201c7de66bc5b1af73f76ab Mon Sep 17 00:00:00 2001 From: Oliver Knoll Date: Sat, 8 Oct 2022 18:31:14 +0200 Subject: [PATCH] Feature perform (#55) * Reduce code analysis warnings * Remove NullData constants - Pass simulation records by value * Use struct instead of class for private data * Use qDebug() << "" instead of qDebug("") * Pre-allocate vector capacity - Return std::vector by value * Return vectors by value - Revert arguments back to "const &" - Also refer to: https://raw.githubusercontent.com/CppCon/CppCon2014/ master/Presentations/Back%20to%20the%20Basics! %20Essentials%20of%20Modern%20C%2B%2B%20Style/Back%20to%20the%20Basics! %20Essentials%20of%20Modern%20C%2B%2B%20Style%20-%20Herb%20Sutter%20- %20CppCon%202014.pdf - -> Slide 24 * Move data will invalidate data ("null" data) * Return aircraft vector by value * Return by value (copy ellision) * Return data by value (WIP) - Won't compile * Use const pimpl - Refer to "Lifetime Safety... By Default: Making Code Leak-Free by Construction", Herb Sutter, CppCon 2016 - WIP (won't compile) * Refactoring (WIP) * C++-14-ify type traits * Use return value optimisation (RVO) * Fix mutual shared pointer dependencies (graph edges) - In the (academic) case when the module graph should have cycles - Which would be possible if two (or seval) modules defined "after" dependencies for each other (which would be a "configuration bug") * Remove const from values returned by value * Value-based aircraft list - Drop QObject inheritance - WIP: Refactor signals (won't compile) * Move waypoint / aircraft info signals - Compiles again - TODO: Explictly emit signals (from services) * Move ctor: initialise private data * Thread-safe acccess to singletons - Not that we have multiple threads just yet... - ... but you never know :) * Rename LogbookManager to PersistenceManager - To avoid confusion with Logbook (the model) * Replace "other" with "rhs" * Refactoring (won't compile) * FIX: Update Flight information dialog when loading flight * Restore method names * Bump version to 0.13 * Rule of zero / five #1 * Rule of zero / five #2 * Rule of zero / five #3 * Rule of zero / five #4 * Update * Constant strings * Fix compilation (Windows) --- CHANGELOG.md | 11 + CMakeLists.txt | 2 +- i18n/SkyDolly_de_DE.ts | 674 +++++++++--------- src/Flight/include/Flight/Analytics.h | 15 +- .../include/Flight/FlightAugmentation.h | 8 +- src/Flight/src/Analytics.cpp | 35 +- src/Flight/src/FlightAugmentation.cpp | 18 +- src/Kernel/CMakeLists.txt | 2 +- src/Kernel/include/Kernel/Const.h | 24 +- src/Kernel/include/Kernel/Convert.h | 14 +- src/Kernel/include/Kernel/Enum.h | 2 +- src/Kernel/include/Kernel/FlightSimulator.h | 5 +- src/Kernel/include/Kernel/PositionParser.h | 2 +- src/Kernel/include/Kernel/Settings.h | 13 +- src/Kernel/include/Kernel/Sort.h | 43 +- src/Kernel/include/Kernel/Unit.h | 6 +- src/Kernel/include/Kernel/Version.h | 22 +- src/Kernel/src/Convert.cpp | 7 +- src/Kernel/src/FlightSimulator.cpp | 32 - src/Kernel/src/PositionParser.cpp | 2 +- src/Kernel/src/Settings.cpp | 92 +-- src/Kernel/src/SettingsConverter.cpp | 6 +- src/Kernel/src/SettingsConverter.h | 2 +- src/Kernel/src/Unit.cpp | 16 +- src/Kernel/src/Version.cpp | 34 +- src/KernelTest/src/PositionParserTest.cpp | 2 +- src/KernelTest/src/PositionParserTest.h | 2 +- src/KernelTest/src/SortTest.cpp | 4 +- src/Model/CMakeLists.txt | 14 +- src/Model/include/Model/AbstractComponent.h | 79 +- src/Model/include/Model/Aircraft.h | 43 +- src/Model/include/Model/AircraftHandle.h | 10 +- src/Model/include/Model/AircraftHandleData.h | 29 +- src/Model/include/Model/AircraftInfo.h | 20 +- src/Model/include/Model/AircraftType.h | 19 +- src/Model/include/Model/Data.h | 11 +- src/Model/include/Model/Engine.h | 12 +- src/Model/include/Model/EngineData.h | 66 +- src/Model/include/Model/Enumeration.h | 16 +- src/Model/include/Model/Flight.h | 71 +- src/Model/include/Model/FlightCondition.h | 33 +- src/Model/include/Model/FlightDate.h | 8 +- src/Model/include/Model/FlightPlan.h | 26 +- src/Model/include/Model/FlightSummary.h | 15 +- src/Model/include/Model/InitialPosition.h | 24 +- src/Model/include/Model/Light.h | 12 +- src/Model/include/Model/LightData.h | 13 +- src/Model/include/Model/Location.h | 14 +- src/Model/include/Model/Logbook.h | 16 +- src/Model/include/Model/Position.h | 12 +- src/Model/include/Model/PositionData.h | 35 +- .../include/Model/PrimaryFlightControl.h | 12 +- .../include/Model/PrimaryFlightControlData.h | 18 +- .../include/Model/SecondaryFlightControl.h | 10 +- .../Model/SecondaryFlightControlData.h | 22 +- src/Model/include/Model/SimVar.h | 230 +++--- src/Model/include/Model/SkySearch.h | 18 +- src/Model/include/Model/TimeVariableData.h | 36 +- src/Model/include/Model/Waypoint.h | 22 +- src/Model/src/Aircraft.cpp | 72 +- src/Model/src/AircraftHandle.cpp | 53 +- src/Model/src/AircraftHandleData.cpp | 43 -- src/Model/src/AircraftInfo.cpp | 35 +- src/Model/src/AircraftType.cpp | 28 +- src/Model/src/Data.cpp | 24 - src/Model/src/Engine.cpp | 85 +-- src/Model/src/EngineData.cpp | 28 +- src/Model/src/Enumeration.cpp | 27 +- src/Model/src/Flight.cpp | 78 +- src/Model/src/FlightCondition.cpp | 60 -- src/Model/src/FlightPlan.cpp | 24 +- src/Model/src/FlightSummary.cpp | 68 -- src/Model/src/InitialPosition.cpp | 9 +- src/Model/src/Light.cpp | 31 +- src/Model/src/LightData.cpp | 34 - src/Model/src/Logbook.cpp | 36 +- src/Model/src/Position.cpp | 52 +- src/Model/src/PositionData.cpp | 13 +- src/Model/src/PrimaryFlightControl.cpp | 37 +- src/Model/src/PrimaryFlightControlData.cpp | 36 - src/Model/src/SecondaryFlightControl.cpp | 52 +- src/Model/src/SecondaryFlightControlData.cpp | 39 - src/Model/src/TimeVariableData.cpp | 34 - src/Model/src/Waypoint.cpp | 27 - src/Persistence/CMakeLists.txt | 6 +- .../include/Persistence/FlightSelector.h | 12 +- .../include/Persistence/LocationSelector.h | 1 - .../Persistence/PersistedEnumerationItem.h | 7 +- ...{LogbookManager.h => PersistenceManager.h} | 39 +- .../Persistence/Service/AircraftService.h | 10 +- .../Persistence/Service/AircraftTypeService.h | 16 +- .../Persistence/Service/DatabaseService.h | 9 +- .../Persistence/Service/EnumerationService.h | 18 +- .../Persistence/Service/FlightService.h | 8 +- .../Persistence/Service/LocationService.h | 14 +- .../Persistence/Service/LogbookService.h | 8 +- src/Persistence/src/Dao/AircraftDaoIntf.h | 12 +- src/Persistence/src/Dao/AircraftTypeDaoIntf.h | 12 +- src/Persistence/src/Dao/DaoFactory.cpp | 8 +- src/Persistence/src/Dao/DaoFactory.h | 9 +- src/Persistence/src/Dao/DatabaseDaoIntf.h | 17 +- src/Persistence/src/Dao/EngineDaoIntf.h | 10 +- src/Persistence/src/Dao/EnumerationDaoIntf.h | 15 +- src/Persistence/src/Dao/FlightDaoIntf.h | 5 + src/Persistence/src/Dao/HandleDaoIntf.h | 8 +- src/Persistence/src/Dao/LightDaoIntf.h | 8 +- src/Persistence/src/Dao/LocationDaoIntf.h | 10 +- src/Persistence/src/Dao/LogbookDaoIntf.h | 7 +- src/Persistence/src/Dao/PositionDaoIntf.h | 8 +- .../src/Dao/PrimaryFlightControlDaoIntf.h | 8 +- .../src/Dao/SQLite/SQLiteAircraftDao.cpp | 113 +-- .../src/Dao/SQLite/SQLiteAircraftDao.h | 18 +- .../src/Dao/SQLite/SQLiteAircraftTypeDao.cpp | 75 +- .../src/Dao/SQLite/SQLiteAircraftTypeDao.h | 13 +- .../src/Dao/SQLite/SQLiteDatabaseDao.cpp | 51 +- .../src/Dao/SQLite/SQLiteDatabaseDao.h | 21 +- .../src/Dao/SQLite/SQLiteEngineDao.cpp | 47 +- .../src/Dao/SQLite/SQLiteEngineDao.h | 14 +- .../src/Dao/SQLite/SQLiteEnumerationDao.cpp | 24 +- .../src/Dao/SQLite/SQLiteEnumerationDao.h | 15 +- .../src/Dao/SQLite/SQLiteFlightDao.cpp | 27 +- .../src/Dao/SQLite/SQLiteFlightDao.h | 6 +- .../src/Dao/SQLite/SQLiteHandleDao.cpp | 47 +- .../src/Dao/SQLite/SQLiteHandleDao.h | 15 +- .../src/Dao/SQLite/SQLiteLightDao.cpp | 48 +- .../src/Dao/SQLite/SQLiteLightDao.h | 14 +- .../src/Dao/SQLite/SQLiteLocationDao.cpp | 46 +- .../src/Dao/SQLite/SQLiteLocationDao.h | 12 +- .../src/Dao/SQLite/SQLiteLogbookDao.cpp | 47 +- .../src/Dao/SQLite/SQLiteLogbookDao.h | 15 +- .../src/Dao/SQLite/SQLitePositionDao.cpp | 49 +- .../src/Dao/SQLite/SQLitePositionDao.h | 14 +- .../SQLite/SQLitePrimaryFlightControlDao.cpp | 49 +- .../SQLite/SQLitePrimaryFlightControlDao.h | 14 +- .../SQLiteSecondaryFlightControlDao.cpp | 48 +- .../SQLite/SQLiteSecondaryFlightControlDao.h | 14 +- .../src/Dao/SQLite/SQLiteWaypointDao.cpp | 19 +- .../src/Dao/SQLite/SQLiteWaypointDao.h | 8 +- .../src/Dao/SQLite/SqlMigration.cpp | 33 +- src/Persistence/src/Dao/SQLite/SqlMigration.h | 8 +- .../src/Dao/SQLite/SqlMigrationStep.cpp | 28 +- .../src/Dao/SQLite/SqlMigrationStep.h | 8 +- .../src/Dao/SQLite/migr/LogbookMigration.sql | 4 + .../src/Dao/SecondaryFlightControlDaoIntf.h | 8 +- src/Persistence/src/Dao/WaypointDaoIntf.h | 5 + src/Persistence/src/FlightSelector.cpp | 35 - src/Persistence/src/LocationSelector.cpp | 30 - .../src/PersistedEnumerationItem.cpp | 28 +- ...bookManager.cpp => PersistenceManager.cpp} | 130 ++-- .../src/Service/AircraftService.cpp | 36 +- .../src/Service/AircraftTypeService.cpp | 46 +- .../src/Service/DatabaseService.cpp | 41 +- .../src/Service/EnumerationService.cpp | 29 +- src/Persistence/src/Service/FlightService.cpp | 22 +- .../src/Service/LocationService.cpp | 51 +- .../src/Service/LogbookService.cpp | 21 +- .../include/PluginManager/AbstractModule.h | 8 +- .../PluginManager/AbstractSkyConnect.h | 19 +- .../include/PluginManager/BasicExportDialog.h | 12 +- .../include/PluginManager/BasicImportDialog.h | 16 +- .../include/PluginManager/CsvConst.h | 2 +- .../include/PluginManager/Export.h | 3 +- .../include/PluginManager/ExportPluginBase.h | 16 +- .../PluginManager/ExportPluginBaseSettings.h | 10 +- .../include/PluginManager/ImportPluginBase.h | 10 +- .../PluginManager/ImportPluginBaseSettings.h | 10 +- .../include/PluginManager/ModuleIntf.h | 5 + .../include/PluginManager/ModuleManager.h | 8 +- .../include/PluginManager/PluginBase.h | 18 +- .../include/PluginManager/PluginIntf.h | 5 + .../include/PluginManager/PluginManager.h | 17 +- .../include/PluginManager/SettingsIntf.h | 8 +- .../include/PluginManager/SkyConnectIntf.h | 23 +- .../include/PluginManager/SkyConnectManager.h | 24 +- src/PluginManager/src/AbstractModule.cpp | 3 +- src/PluginManager/src/AbstractSkyConnect.cpp | 16 +- src/PluginManager/src/BasicExportDialog.cpp | 21 +- src/PluginManager/src/BasicImportDialog.cpp | 17 +- src/PluginManager/src/Export.cpp | 9 +- src/PluginManager/src/ExportPluginBase.cpp | 24 +- .../src/ExportPluginBaseSettings.cpp | 24 +- src/PluginManager/src/ImportPluginBase.cpp | 21 +- .../src/ImportPluginBaseSettings.cpp | 21 +- src/PluginManager/src/ModuleManager.cpp | 24 +- src/PluginManager/src/PluginBase.cpp | 6 +- src/PluginManager/src/PluginManager.cpp | 50 +- src/PluginManager/src/SkyConnectManager.cpp | 39 +- .../src/MSFSSimConnectPlugin.cpp | 47 +- .../MSFSSimConnectPlugin/src/SimConnectAi.cpp | 3 +- .../src/SimConnectAircraftInfo.h | 3 +- .../PathCreator/src/PathCreatorPlugin.cpp | 14 +- .../PathCreator/src/PathCreatorPlugin.h | 6 +- .../CsvExport/src/CsvExportOptionWidget.cpp | 10 +- .../CsvExport/src/CsvExportOptionWidget.h | 4 +- .../Export/CsvExport/src/CsvExportPlugin.cpp | 13 +- .../Export/CsvExport/src/CsvExportPlugin.h | 4 +- .../CsvExport/src/CsvExportSettings.cpp | 14 +- .../Export/CsvExport/src/CsvExportSettings.h | 4 +- .../CsvExport/src/FlightRadar24CsvWriter.cpp | 16 +- .../CsvExport/src/FlightRadar24CsvWriter.h | 4 +- .../src/PositionAndAttitudeCsvWriter.cpp | 9 +- .../src/PositionAndAttitudeCsvWriter.h | 4 +- .../CsvExport/src/SkyDollyCsvWriter.cpp | 10 +- .../Export/CsvExport/src/SkyDollyCsvWriter.h | 8 +- .../GpxExport/src/GpxExportOptionWidget.cpp | 10 +- .../GpxExport/src/GpxExportOptionWidget.h | 6 +- .../Export/GpxExport/src/GpxExportPlugin.cpp | 18 +- .../Export/GpxExport/src/GpxExportPlugin.h | 20 +- .../GpxExport/src/GpxExportSettings.cpp | 12 +- .../Export/GpxExport/src/GpxExportSettings.h | 14 +- .../IgcExport/src/IgcExportOptionWidget.cpp | 10 +- .../IgcExport/src/IgcExportOptionWidget.h | 6 +- .../Export/IgcExport/src/IgcExportPlugin.cpp | 14 +- .../Export/IgcExport/src/IgcExportPlugin.h | 20 +- .../IgcExport/src/IgcExportSettings.cpp | 10 +- .../Export/IgcExport/src/IgcExportSettings.h | 14 +- .../JsonExport/src/JsonExportPlugin.cpp | 20 +- .../Export/JsonExport/src/JsonExportPlugin.h | 20 +- .../JsonExport/src/JsonExportSettings.cpp | 11 +- .../JsonExport/src/JsonExportSettings.h | 14 +- .../KmlExport/src/KmlExportOptionWidget.cpp | 16 +- .../KmlExport/src/KmlExportOptionWidget.h | 6 +- .../Export/KmlExport/src/KmlExportPlugin.cpp | 25 +- .../Export/KmlExport/src/KmlExportPlugin.h | 20 +- .../KmlExport/src/KmlExportSettings.cpp | 12 +- .../Export/KmlExport/src/KmlExportSettings.h | 14 +- .../Export/KmlExport/src/KmlStyleExport.cpp | 27 +- .../Export/KmlExport/src/KmlStyleExport.h | 4 +- .../CsvImport/src/CsvImportOptionWidget.cpp | 10 +- .../CsvImport/src/CsvImportOptionWidget.h | 6 +- .../Import/CsvImport/src/CsvImportPlugin.cpp | 12 +- .../Import/CsvImport/src/CsvImportPlugin.h | 4 +- .../CsvImport/src/CsvImportSettings.cpp | 12 +- .../Import/CsvImport/src/CsvImportSettings.h | 14 +- .../CsvImport/src/FlightRadar24CsvParser.cpp | 9 +- .../CsvImport/src/FlightRecorderCsvParser.cpp | 94 ++- .../CsvImport/src/FlightRecorderCsvParser.h | 6 +- .../CsvImport/src/SkyDollyCsvParser.cpp | 18 +- .../GpxImport/src/GpxImportOptionWidget.cpp | 10 +- .../GpxImport/src/GpxImportOptionWidget.h | 6 +- .../Import/GpxImport/src/GpxImportPlugin.cpp | 9 +- .../Import/GpxImport/src/GpxImportPlugin.h | 30 +- .../GpxImport/src/GpxImportSettings.cpp | 12 +- .../Import/GpxImport/src/GpxImportSettings.h | 14 +- .../Import/GpxImport/src/GpxParser.cpp | 22 +- src/Plugins/Import/GpxImport/src/GpxParser.h | 4 +- .../IgcImport/src/IgcImportOptionWidget.cpp | 10 +- .../IgcImport/src/IgcImportOptionWidget.h | 4 +- .../Import/IgcImport/src/IgcImportPlugin.cpp | 16 +- .../Import/IgcImport/src/IgcImportPlugin.h | 30 +- .../IgcImport/src/IgcImportSettings.cpp | 12 +- .../Import/IgcImport/src/IgcImportSettings.h | 12 +- .../Import/IgcImport/src/IgcParser.cpp | 56 +- src/Plugins/Import/IgcImport/src/IgcParser.h | 2 +- .../KmlImport/src/AbstractKmlParser.cpp | 16 +- .../Import/KmlImport/src/AbstractKmlParser.h | 8 +- .../KmlImport/src/AbstractKmlTrackParser.cpp | 14 +- .../KmlImport/src/AbstractKmlTrackParser.h | 10 +- .../KmlImport/src/FlightAwareKmlParser.cpp | 16 +- .../KmlImport/src/FlightAwareKmlParser.h | 10 +- .../KmlImport/src/FlightRadar24KmlParser.cpp | 30 +- .../KmlImport/src/FlightRadar24KmlParser.h | 14 +- .../Import/KmlImport/src/GenericKmlParser.cpp | 12 +- .../Import/KmlImport/src/GenericKmlParser.h | 10 +- .../KmlImport/src/KmlImportOptionWidget.cpp | 10 +- .../KmlImport/src/KmlImportOptionWidget.h | 6 +- .../Import/KmlImport/src/KmlImportPlugin.cpp | 14 +- .../Import/KmlImport/src/KmlImportPlugin.h | 30 +- .../KmlImport/src/KmlImportSettings.cpp | 12 +- .../Import/KmlImport/src/KmlImportSettings.h | 14 +- .../Module/Formation/src/Formation.cpp | 2 +- .../Module/Formation/src/FormationPlugin.cpp | 8 +- .../Module/Formation/src/FormationPlugin.h | 2 +- .../Module/Formation/src/FormationWidget.cpp | 16 +- .../Module/Formation/src/FormationWidget.h | 2 +- .../Location/src/EnumerationItemDelegate.cpp | 4 +- .../Location/src/EnumerationItemDelegate.h | 2 +- .../Module/Location/src/LocationPlugin.cpp | 4 +- .../Module/Location/src/LocationPlugin.h | 2 +- .../Module/Location/src/LocationWidget.cpp | 37 +- .../Module/Location/src/LocationWidget.h | 2 +- .../Module/Logbook/src/LogbookPlugin.cpp | 4 +- .../Module/Logbook/src/LogbookPlugin.h | 2 +- .../Module/Logbook/src/LogbookWidget.cpp | 26 +- .../Module/Logbook/src/LogbookWidget.h | 3 +- .../Module/Template/src/TemplatePlugin.cpp | 4 +- .../Module/Template/src/TemplatePlugin.h | 2 +- .../Module/Template/src/TemplateWidget.cpp | 7 +- .../Module/Template/src/TemplateWidget.h | 5 +- .../include/UserInterface/MainWindow.h | 5 +- src/UserInterface/src/Dialog/AboutDialog.cpp | 3 +- src/UserInterface/src/Dialog/AboutDialog.h | 5 +- src/UserInterface/src/Dialog/FlightDialog.cpp | 3 +- src/UserInterface/src/Dialog/FlightDialog.h | 11 +- .../src/Dialog/LogbookBackupDialog.cpp | 22 +- .../src/Dialog/LogbookBackupDialog.h | 13 +- .../src/Dialog/LogbookSettingsDialog.cpp | 22 +- .../src/Dialog/LogbookSettingsDialog.h | 5 +- .../src/Dialog/SimulationVariablesDialog.cpp | 58 +- .../src/Dialog/SimulationVariablesDialog.h | 11 +- .../src/Dialog/StatisticsDialog.cpp | 26 +- .../src/Dialog/StatisticsDialog.h | 7 +- src/UserInterface/src/MainWindow.cpp | 27 +- .../Widget/AbstractSimulationVariableWidget.h | 3 - .../src/Widget/AircraftHandleWidget.cpp | 17 +- .../src/Widget/AircraftHandleWidget.h | 11 +- .../src/Widget/AircraftInfoWidget.cpp | 23 +- .../src/Widget/AircraftInfoWidget.h | 5 +- .../src/Widget/AircraftWidget.cpp | 17 +- src/UserInterface/src/Widget/AircraftWidget.h | 10 +- src/UserInterface/src/Widget/EngineWidget.cpp | 19 +- src/UserInterface/src/Widget/EngineWidget.h | 10 +- .../src/Widget/FlightConditionWidget.cpp | 17 +- .../src/Widget/FlightConditionWidget.h | 7 +- .../src/Widget/FlightDescriptionWidget.cpp | 14 +- .../src/Widget/FlightDescriptionWidget.h | 5 +- .../src/Widget/FlightPlanWidget.cpp | 32 +- .../src/Widget/FlightPlanWidget.h | 9 +- src/UserInterface/src/Widget/LightWidget.cpp | 18 +- src/UserInterface/src/Widget/LightWidget.h | 10 +- .../src/Widget/PrimaryFlightControlWidget.cpp | 18 +- .../src/Widget/PrimaryFlightControlWidget.h | 10 +- .../Widget/SecondaryFlightControlWidget.cpp | 18 +- .../src/Widget/SecondaryFlightControlWidget.h | 10 +- .../src/Widget/WaypointWidget.cpp | 12 +- src/UserInterface/src/Widget/WaypointWidget.h | 9 +- src/Widget/include/Widget/ActionButton.h | 3 +- src/Widget/include/Widget/ActionCheckBox.h | 7 +- src/Widget/include/Widget/ActionRadioButton.h | 7 +- src/Widget/include/Widget/ActiveButton.h | 6 +- .../Widget/AircraftSelectionComboBox.h | 6 +- .../include/Widget/BackupPeriodComboBox.h | 6 +- .../include/Widget/EnumerationComboBox.h | 2 +- src/Widget/include/Widget/TableDateItem.h | 8 +- src/Widget/include/Widget/TableTimeItem.h | 8 +- src/Widget/src/ActionCheckBox.cpp | 3 +- src/Widget/src/ActionRadioButton.cpp | 3 +- src/Widget/src/ActiveButton.cpp | 3 +- src/Widget/src/AircraftSelectionComboBox.cpp | 13 +- src/Widget/src/BackupPeriodComboBox.cpp | 3 +- src/Widget/src/EnumerationComboBox.cpp | 6 +- src/Widget/src/EnumerationWidgetItem.cpp | 2 + src/Widget/src/TableDateItem.cpp | 3 +- src/Widget/src/TableTimeItem.cpp | 3 +- src/main.cpp | 4 +- 345 files changed, 3336 insertions(+), 3898 deletions(-) delete mode 100644 src/Kernel/src/FlightSimulator.cpp delete mode 100644 src/Model/src/AircraftHandleData.cpp delete mode 100644 src/Model/src/Data.cpp delete mode 100644 src/Model/src/FlightSummary.cpp delete mode 100644 src/Model/src/LightData.cpp delete mode 100644 src/Model/src/PrimaryFlightControlData.cpp delete mode 100644 src/Model/src/SecondaryFlightControlData.cpp delete mode 100644 src/Model/src/TimeVariableData.cpp rename src/Persistence/include/Persistence/{LogbookManager.h => PersistenceManager.h} (72%) delete mode 100644 src/Persistence/src/FlightSelector.cpp delete mode 100644 src/Persistence/src/LocationSelector.cpp rename src/Persistence/src/{LogbookManager.cpp => PersistenceManager.cpp} (72%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd418bde..1b52fae1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.13.0 + +### Bug Fixes +- The various tabs in the Flight information dialog (Description, Aircraft, Conditions and Flight Plan) are now properly updated when importing a flight or loading a flight from the logbook + +### Under The Hood +- Rule of Zero, copy-and-swap [[Back to Basics: RAII and the Rule of Zero - Arthur O'Dwyer - CppCon 2019](https://www.youtube.com/watch?v=7Qgd9B1KuMQ)] +- Thread-safe access to singletons [[Back to Basics: Concurrency - Arthur O'Dwyer - CppCon 2020](https://www.youtube.com/watch?v=F6Ipn7gCOsY)] +- Value-based aircraft list (CPU cache optimisation) +- Small performance optimisations (e.g. return value optimisation) + ## 0.12.0 ### New Features diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc8848ff..07d282f76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(APP_NAME "SkyDolly") project( ${APP_NAME} - VERSION 0.12.0 + VERSION 0.13.0 DESCRIPTION "Sky Dolly - The Black Sheep for Your Flight Recordings" HOMEPAGE_URL "https://github.com/till213/SkyDolly" LANGUAGES CXX diff --git a/i18n/SkyDolly_de_DE.ts b/i18n/SkyDolly_de_DE.ts index 9cd0e0a21..00cca34de 100644 --- a/i18n/SkyDolly_de_DE.ts +++ b/i18n/SkyDolly_de_DE.ts @@ -29,12 +29,12 @@ - + Copied to clipboard - + %1 The Black Sheep for Your Flight Recordings @@ -102,22 +102,22 @@ MIT License - + Down - + Up - + On - + Off @@ -271,33 +271,33 @@ MIT License BackupPeriodComboBox - + Never - + Once a month, when exiting Sky Dolly - + Once a week, when exiting Sky Dolly - + Daily, when exiting Sky Dolly - + Always, when exiting Sky Dolly - - + + Next time, when exiting Sky Dolly @@ -345,47 +345,47 @@ MIT License - + &Export - + User aircraft only - + All aircraft (single file) - + All aircraft (separate files) - + smaller file size, less accuracy - + good accuracy - + Original data (no resampling) - + The current user aircraft will be exported. - + %Ln aircraft will be exported. @@ -393,7 +393,7 @@ MIT License - + The position data will be resampled every %1 milliseconds, resulting in %Ln exported positions. @@ -401,7 +401,7 @@ MIT License - + The original recorded data will be exported, resulting in total %Ln exported positions. @@ -409,22 +409,22 @@ MIT License - + Only the currently selected user aircraft is exported. - + All aircraft are exported, into a single file (if supported by the format; otherwise separate files). - + All aircraft are exported, into separate files. - + Export File @@ -472,37 +472,37 @@ MIT License - + &Import - + Add all aircraft to same new flight - + When checked then all aircraft are added to the same newly created flight. Otherwise a new flight is created for each imported file. - + Add aircraft to current flight - + When checked then the imported aircraft is added to the currently loaded flight. Otherwise a new flight is created. - + Import Directory - + Import File @@ -531,22 +531,22 @@ MIT License DatabaseService - + Open Logbook - + New Logbook - + Database exists - + The logbook %1 already exists. Please choose another path. @@ -638,41 +638,41 @@ MIT License ExportPluginBase - - + + &Replace - - + + Replace - - + + A file named "%1" already exists. Do you want to replace it? - - + + The file already exists in "%1". Replacing it will overwrite its contents. - + Export error - + An error occured during export into file %1. - + Replace &All @@ -786,27 +786,27 @@ MIT License - + &Description - + &Aircraft - + &Conditions - + &Flight Plan - + F Window|Flight... @@ -866,13 +866,13 @@ MIT License - - The vertical distance, calculated in multiples of the wingspan of the current user aircraft. + + Vertical: - - Vertical: + + The vertical distance, calculated in multiples of the wingspan of the current user aircraft. @@ -885,6 +885,18 @@ MIT License Set relative position + + + Replay + + + + + + + Time Offset + + Decrease the time offset by 1 second. @@ -915,6 +927,11 @@ MIT License Reset the time offsets of all formation aircraft. + + + &Reset All + + @@ -928,13 +945,13 @@ MIT License - - Permanently deletes the currently selected aircraft from the formation. + + &Set User Aircraft - - &Set User Aircraft + + Permanently deletes the currently selected aircraft from the formation. @@ -943,23 +960,6 @@ MIT License &Delete - - - - - Time Offset - - - - - &Reset All - - - - - Replay - - @@ -1205,22 +1205,22 @@ or choose another reference aircraft (marked in green) in the formation. - + Simulation time - + Recording (real world) time - + Timestamps are based on the time set in the flight simulator. - + Timestamps are based on the (real world) recording time. This may be useful for GPS-tagging screenshots taken during flight recording. @@ -1268,40 +1268,40 @@ or choose another reference aircraft (marked in green) in the formation. - - + + Waypoint (<wpt>) - - + + Route (<rte>) - - + + Track (<trk>) - + feet - + knots - + Converts imported height above WGS84 ellipsoid to height above the EGM2008 geoid. - + No earth gravity model (EGM) is available. @@ -1352,22 +1352,22 @@ or choose another reference aircraft (marked in green) in the formation. - + GNSS altitude - + Pressure altitude - + Converts imported height above WGS84 ellipsoid to height above the EGM2008 geoid. - + No earth gravity model (EGM) is available. @@ -1375,48 +1375,48 @@ or choose another reference aircraft (marked in green) in the formation. ImportPluginBase - - + + Import error - + The file %1 could not be imported. - + The selected aircraft '%1' is not a known aircraft in the logbook. Check for spelling errors or record a flight with this aircraft first. - + &Proceed - + &Ignore All Failures - + Import Failure - + The file %1 could not be imported. Do you want to proceed with the remaining files in directory %2? - + Aborting will keep the already successfully imported flights and aircraft. - + Aircraft imported on %1 from file: %2 @@ -1463,22 +1463,22 @@ or choose another reference aircraft (marked in green) in the formation. - + One color - + One color per engine type - + Color ramp - + Color ramp per engine type @@ -1491,7 +1491,7 @@ or choose another reference aircraft (marked in green) in the formation. - + Generic KML with track data @@ -1585,23 +1585,23 @@ or choose another reference aircraft (marked in green) in the formation. - - True heading: + + Description: - - Default Values + + Pitch: - - Altitude: + + Bank: - - feet + + True heading: @@ -1611,29 +1611,29 @@ or choose another reference aircraft (marked in green) in the formation. - - - knots + + Default Values - - On ground + + Altitude: - - Description: + + feet - - Pitch: + + + knots - - Bank: + + On ground @@ -1673,7 +1673,7 @@ or choose another reference aircraft (marked in green) in the formation. - + &Delete @@ -1684,81 +1684,81 @@ or choose another reference aircraft (marked in green) in the formation. - - - Position + + + Title - - - Altitude + + + Description - - - Pitch + + + Type - - - Bank + + + Category - - - Description + + + Country - - - Indicated Airspeed + + + Identifer - - - On Ground + + + Position - - - Title + + + Altitude - - - Type + + + Pitch - - - Category + + + Bank - - - Identifer + + + True Heading - - - Country + + + Indicated Airspeed - - - True Heading + + + On Ground @@ -1768,68 +1768,68 @@ or choose another reference aircraft (marked in green) in the formation. - + Double-click to teleport to location. - + Double-click to edit title. - + Double-click to edit description. - - + + Double-click to edit category. - + Double-click to edit identifier. - + Double-click to edit position. - + Double-click to edit altitude. - + Click to toggle on ground. - + Do not ask again. - + Delete Aircraft - + The location with ID %1 is about to be deleted. Do you want to delete the location? - + Deletion cannot be undone. - + &Keep @@ -1882,39 +1882,6 @@ or choose another reference aircraft (marked in green) in the formation. - - LogbookManager - - - Newer Version - - - - - The logbook %1 has been created with a newer version %2. Do you want to create a new logbook? - - - - - Logbooks created with newer %1 versions cannot be opened. - - - - - Create &New Logbook - - - - - &Open Another Logbook - - - - - &Cancel - - - LogbookPlugin @@ -2177,11 +2144,6 @@ or choose another reference aircraft (marked in green) in the formation. - - - Logbook - - REC @@ -2213,6 +2175,11 @@ or choose another reference aircraft (marked in green) in the formation.Simulation duration. + + + Logbook + + Logbook error @@ -2509,7 +2476,7 @@ or choose another reference aircraft (marked in green) in the formation. - + Optimise Logbook @@ -2560,8 +2527,8 @@ or choose another reference aircraft (marked in green) in the formation. - - + + Logbook error @@ -2571,126 +2538,159 @@ or choose another reference aircraft (marked in green) in the formation. - + Factor [f] - + Percent [%] - + No valid connection plugin found - + No valid connection plugin has been found in the plugin directory! Sky Dolly will launch with reduced functionality. - + Custom replay speed factor in [%L1, %L2]. - + Custom replay speed % in [%L1%, %L2%]. - + Recording - + %1 ms (%2) - + Record [@%1 Hz]. - + Record [auto sample rate]. - + Fast forward [%1 sec]. - + Rewind [%1 sec]. - + Fast forward [%1 %]. - + Rewind [%1 %]. - + Hide modules. - + Show modules. - + The logbook %1 could not be created. - + &Optimise - + Logbook optimisation will regain unused space. The current %1 size is %2. Do you want to optimise the logbook? - + The optimisation operation may take a while, depending on the logbook file size. - + Success - + The logbook %1 optimisation was successful. - + The new file size is: %1 (previous size: %2). - + The logbook could not be optimised. + + PersistenceManager + + + Newer Version + + + + + The logbook %1 has been created with a newer version %2. Do you want to create a new logbook? + + + + + Logbooks created with newer %1 versions cannot be opened. + + + + + Create &New Logbook + + + + + &Open Another Logbook + + + + + &Cancel + + + PrimaryFlightControlWidget @@ -2722,214 +2722,214 @@ or choose another reference aircraft (marked in green) in the formation. QObject - - + + Comma-separated values (*.%1) - + GPS exchange format (*.%1) - - + + Creation date - - + + Start (local time) - - + + End (local time) - - + + Ambient temperature - - + + Total air temperature - - + + Precipitation - - + + Wind direction - - + + Wind speed - - + + Visibility - - + + In clouds - - + + Category - - + + Engine type - - + + Number of engines - - + + Wingspan - - + + Initial altitude above ground - - + + Initial airspeed - - + + Airline - - + + Flight number - - + + Tail number - - + + International gliding commission (*.%1) - + JavaScript object notation (*.%1) - - + + Keyhole markup language (*.%1) - + Description - + Arrival time (local) - + Arrival time (zulu) - + Altitude - + Sky Dolly CSV import - + Flightradar24 CSV import - + Flight Recorder CSV import - + GPX exchange format (*.%1) - + GPX import - + Glider type: - + Pilot: - + Co-Pilot: - + Flight date: - + KML import @@ -3420,73 +3420,73 @@ or choose another reference aircraft (marked in green) in the formation.SimulationVariablesDialog - + Simulation Variables - + &Aircraft - + &Engine - + &Primary Controls - + &Secondary Controls - + &Handles && Brakes - + &Lights - + V Window|Simulation Variables... - + DISCONNECTED - + CONNECTED - + RECORDING - + RECORDING PAUSED - + PLAYBACK - + PLAYPACK PAUSED @@ -3529,13 +3529,13 @@ or choose another reference aircraft (marked in green) in the formation. - + S Window|Statistics... - + Auto @@ -3564,52 +3564,52 @@ or choose another reference aircraft (marked in green) in the formation. Unit - + N - + S - + E - + W - + Fog (< 3,300 ft) - + Mist (< 1.2 mi) - + Haze (< 3.1 mi) - + Clear (>= 3.1 mi) - + Yes - + No diff --git a/src/Flight/include/Flight/Analytics.h b/src/Flight/include/Flight/Analytics.h index 4bd355e59..cf8e9af25 100644 --- a/src/Flight/include/Flight/Analytics.h +++ b/src/Flight/include/Flight/Analytics.h @@ -1,4 +1,4 @@ -/** + /** * Sky Dolly - The Black Sheep for Your Flight Recordings * * Copyright (c) Oliver Knoll @@ -36,7 +36,7 @@ class Aircraft; struct PositionData; -class AnalyticsPrivate; +struct AnalyticsPrivate; /*! * Provides basic flight path & events analytics. @@ -46,6 +46,10 @@ class FLIGHT_API Analytics public: Analytics(const Aircraft &aircraft); + Analytics(const Analytics &rhs) = delete; + Analytics(Analytics &&rhs); + Analytics &operator=(const Analytics &rhs) = delete; + Analytics &operator=(Analytics &&rhs); ~Analytics(); /*! @@ -54,12 +58,11 @@ class FLIGHT_API Analytics * still on the ground). The movement is purely calculated based on the distance * between the positions. * - * \return the heading of the first aircraft movement; PositionData::NullData if - * no positions exist + * \return the heading of the first aircraft movement */ - const std::pair firstMovementHeading() const noexcept; + std::pair firstMovementHeading() const noexcept; - const PositionData &closestPosition(double latitude, double longitude) const noexcept; + PositionData closestPosition(double latitude, double longitude) const noexcept; private: std::unique_ptr d; diff --git a/src/Flight/include/Flight/FlightAugmentation.h b/src/Flight/include/Flight/FlightAugmentation.h index 8660e1ea1..429199801 100644 --- a/src/Flight/include/Flight/FlightAugmentation.h +++ b/src/Flight/include/Flight/FlightAugmentation.h @@ -33,7 +33,7 @@ #include "FlightLib.h" class Aircraft; -class FlightAugmentationPrivate; +struct FlightAugmentationPrivate; /*! * Augments flight data with attitude and velocity, for instance. @@ -69,7 +69,11 @@ class FLIGHT_API FlightAugmentation Q_DECLARE_FLAGS(Aspects, Aspect) FlightAugmentation(Procedures procedures = Procedure::All, Aspects aspects = Aspect::All) noexcept; - ~FlightAugmentation() noexcept; + FlightAugmentation(const FlightAugmentation &rhs) = delete; + FlightAugmentation(FlightAugmentation &&rhs); + FlightAugmentation &operator=(const FlightAugmentation &rhs) = delete; + FlightAugmentation &operator=(FlightAugmentation &&rhs); + ~FlightAugmentation(); void setProcedures(Procedures procedures) noexcept; Procedures getProcedures() const noexcept; diff --git a/src/Flight/src/Analytics.cpp b/src/Flight/src/Analytics.cpp index f79fa3a77..3eb9474cd 100644 --- a/src/Flight/src/Analytics.cpp +++ b/src/Flight/src/Analytics.cpp @@ -27,6 +27,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -50,9 +53,8 @@ namespace { }; } -class AnalyticsPrivate +struct AnalyticsPrivate { -public: AnalyticsPrivate(const Aircraft &theAircraft) : aircraft(theAircraft) {} @@ -64,20 +66,13 @@ class AnalyticsPrivate Analytics::Analytics(const Aircraft &aircraft) : d(std::make_unique(aircraft)) -{ -#ifdef DEBUG - qDebug("Analytics::~Analytics: CREATED"); -#endif -} +{} -Analytics::~Analytics() -{ -#ifdef DEBUG - qDebug("Analytics::~Analytics: DELETED"); -#endif -} +Analytics::Analytics(Analytics &&rhs) = default; +Analytics &Analytics::operator=(Analytics &&rhs) = default; +Analytics::~Analytics() = default; -const std::pair Analytics::firstMovementHeading() const noexcept +std::pair Analytics::firstMovementHeading() const noexcept { std::pair result; Position &position = d->aircraft.getPosition(); @@ -101,23 +96,19 @@ const std::pair Analytics::firstMovementHeading() const no return result; } -const PositionData &Analytics::closestPosition(double latitude, double longitude) const noexcept +PositionData Analytics::closestPosition(double latitude, double longitude) const noexcept { + PositionData positionData; double minimumDistance = std::numeric_limits::max(); - const PositionData *closestPositionData {nullptr}; Position &position = d->aircraft.getPosition(); for (const PositionData &pos : position) { const double distance = SkyMath::geodesicDistance(SkyMath::Coordinate(latitude, longitude), SkyMath::Coordinate(pos.latitude, pos.longitude)); if (minimumDistance > distance) { - closestPositionData = &pos; + positionData = pos; minimumDistance = distance; } } - if (closestPositionData != nullptr) { - return *closestPositionData; - } else { - return PositionData::NullData; - } + return positionData; } diff --git a/src/Flight/src/FlightAugmentation.cpp b/src/Flight/src/FlightAugmentation.cpp index 621d78c5b..bd3914205 100644 --- a/src/Flight/src/FlightAugmentation.cpp +++ b/src/Flight/src/FlightAugmentation.cpp @@ -58,9 +58,8 @@ namespace { constexpr double MaxBankAngle = 25; } -class FlightAugmentationPrivate +struct FlightAugmentationPrivate { -public: FlightAugmentationPrivate(FlightAugmentation::Procedures theProcedures, FlightAugmentation::Aspects theAspects) : procedures(theProcedures), aspects(theAspects) @@ -74,18 +73,11 @@ class FlightAugmentationPrivate FlightAugmentation::FlightAugmentation(Procedures procedures, Aspects aspects) noexcept : d(std::make_unique(procedures, aspects)) -{ -#ifdef DEBUG - qDebug("FlightAugmentation::~FlightAugmentation: CREATED"); -#endif -} +{} -FlightAugmentation::~FlightAugmentation() noexcept -{ -#ifdef DEBUG - qDebug("FlightAugmentation::~FlightAugmentation: DELETED"); -#endif -} +FlightAugmentation::FlightAugmentation(FlightAugmentation &&rhs) = default; +FlightAugmentation &FlightAugmentation::operator=(FlightAugmentation &&rhs) = default; +FlightAugmentation::~FlightAugmentation() = default; void FlightAugmentation::setProcedures(Procedures procedures) noexcept { diff --git a/src/Kernel/CMakeLists.txt b/src/Kernel/CMakeLists.txt index ad458a903..760751431 100644 --- a/src/Kernel/CMakeLists.txt +++ b/src/Kernel/CMakeLists.txt @@ -21,7 +21,7 @@ target_sources(${LIBRARY_NAME} include/Kernel/Convert.h src/Convert.cpp include/Kernel/Enum.h include/Kernel/File.h src/File.cpp - include/Kernel/FlightSimulator.h src/FlightSimulator.cpp + include/Kernel/FlightSimulator.h include/Kernel/Name.h include/Kernel/PositionParser.h src/PositionParser.cpp include/Kernel/Replay.h diff --git a/src/Kernel/include/Kernel/Const.h b/src/Kernel/include/Kernel/Const.h index f68c069e6..7f807299a 100644 --- a/src/Kernel/include/Kernel/Const.h +++ b/src/Kernel/include/Kernel/Const.h @@ -1,15 +1,23 @@ #ifndef CONST_H #define CONST_H +#include + namespace Const { - constexpr char LogbookExtension[] = ".sdlog"; - - constexpr char BackupNeverSymId[] = "NEVER"; - constexpr char BackupNowSymId[] = "NOW"; - constexpr char BackupMonthlySymId[] = "MONTH"; - constexpr char BackupWeeklySymId[] = "WEEK"; - constexpr char BackupDailySymId[] = "DAY"; - constexpr char BackupAlwaysSymId[] = "ALWAYS"; + + /*! + * An invalid ID indicates that the object has not yet been (successfully) persisted. + */ + constexpr std::int64_t InvalidId {-1}; + + constexpr const char *LogbookExtension {".sdlog"}; + + constexpr const char *BackupNeverSymId = "NEVER"; + constexpr const char *BackupNowSymId = "NOW"; + constexpr const char *BackupMonthlySymId = "MONTH"; + constexpr const char *BackupWeeklySymId = "WEEK"; + constexpr const char *BackupDailySymId = "DAY"; + constexpr const char *BackupAlwaysSymId = "ALWAYS"; } #endif // CONST_H diff --git a/src/Kernel/include/Kernel/Convert.h b/src/Kernel/include/Kernel/Convert.h index f851b929b..6b72566ee 100644 --- a/src/Kernel/include/Kernel/Convert.h +++ b/src/Kernel/include/Kernel/Convert.h @@ -28,6 +28,10 @@ #include #include +#ifdef DEBUG +#include +#endif + #include #include "KernelLib.h" @@ -45,7 +49,11 @@ class KERNEL_API Convert final public: Convert() noexcept; - ~Convert() noexcept; + Convert(const Convert &rhs) = delete; + Convert(Convert &&rhs); + Convert &operator=(const Convert &rhs) = delete; + Convert &operator=(Convert &&rhs); + ~Convert(); /*! * Converts the \c height height above WGS84 reference ellipsoid to height above the earth @@ -79,7 +87,7 @@ class KERNEL_API Convert final catch (const std::exception &ex) { heightAboveGeoid = height; #ifdef DEBUG - qDebug("Convert::wgs84ToEgmGeoid: caught exception: %s", ex.what()); + qDebug() << "Convert::wgs84ToEgmGeoid: caught exception: %s", ex.what(); #endif } } else { @@ -120,7 +128,7 @@ class KERNEL_API Convert final catch (const std::exception &ex) { heightAboveEllipsoid = height; #ifdef DEBUG - qDebug("Convert::egmToWgs84Ellipsoid: caught exception: %s", ex.what()); + qDebug() << "Convert::egmToWgs84Ellipsoid: caught exception:" << ex.what(); #endif } } else { diff --git a/src/Kernel/include/Kernel/Enum.h b/src/Kernel/include/Kernel/Enum.h index eccae2785..e05810918 100644 --- a/src/Kernel/include/Kernel/Enum.h +++ b/src/Kernel/include/Kernel/Enum.h @@ -38,7 +38,7 @@ namespace Enum template constexpr auto toUnderlyingType(E e) noexcept { - return static_cast::type>(e); + return static_cast>(e); } } diff --git a/src/Kernel/include/Kernel/FlightSimulator.h b/src/Kernel/include/Kernel/FlightSimulator.h index c203500c8..e51a742e9 100644 --- a/src/Kernel/include/Kernel/FlightSimulator.h +++ b/src/Kernel/include/Kernel/FlightSimulator.h @@ -33,7 +33,6 @@ class KERNEL_API FlightSimulator final { public: - FlightSimulator() noexcept; enum struct Id { None, @@ -49,15 +48,13 @@ class KERNEL_API FlightSimulator final static inline const QString FlightSimulatorNamePrepar3Dv5 {QStringLiteral("Prepar3Dv5")}; static inline Id nameToId(QStringView name) noexcept { - Id id; + Id id {Id::None}; if (name == FlightSimulatorNameAll) { id = Id::All; } else if (name == FlightSimulatorNameMSFS) { id = Id::FS2020; } else if (name == FlightSimulatorNamePrepar3Dv5) { id = Id::Prepar3Dv5; - } else { - id = Id::None; } return id; } diff --git a/src/Kernel/include/Kernel/PositionParser.h b/src/Kernel/include/Kernel/PositionParser.h index 8cd377c3a..84a8e03e2 100644 --- a/src/Kernel/include/Kernel/PositionParser.h +++ b/src/Kernel/include/Kernel/PositionParser.h @@ -1,5 +1,5 @@ /** - * Sky Dolly - The Black Sheep for your Flight Recordings + * Sky Dolly - The Black Sheep for Your Flight Recordings * * Copyright (c) Oliver Knoll * All rights reserved. diff --git a/src/Kernel/include/Kernel/Settings.h b/src/Kernel/include/Kernel/Settings.h index 6ebbabc92..ce84b80b7 100644 --- a/src/Kernel/include/Kernel/Settings.h +++ b/src/Kernel/include/Kernel/Settings.h @@ -42,8 +42,8 @@ #include "SampleRate.h" #include "KernelLib.h" -class SettingsPrivate; class Version; +struct SettingsPrivate; /*! * The application settings. These settings are persisted to user configuration @@ -54,6 +54,11 @@ class KERNEL_API Settings final : public QObject Q_OBJECT public: + Settings(const Settings &rhs) = delete; + Settings(Settings &&rhs) = delete; + Settings &operator=(const Settings &rhs) = delete; + Settings &operator=(Settings &&rhs) = delete; + /*! * Returns the singleton Settings instance. * @@ -798,13 +803,11 @@ public slots: */ void changed(); -protected: - ~Settings() noexcept override; - private: - std::unique_ptr d; + const std::unique_ptr d; Settings() noexcept; + ~Settings() final; void frenchConnection() noexcept; diff --git a/src/Kernel/include/Kernel/Sort.h b/src/Kernel/include/Kernel/Sort.h index b46d4d8a6..c26b133eb 100644 --- a/src/Kernel/include/Kernel/Sort.h +++ b/src/Kernel/include/Kernel/Sort.h @@ -55,19 +55,26 @@ template > class Sort struct Vertex { - explicit Vertex() - : id(T()) + explicit Vertex(T theId) noexcept + : id(theId) {}; - explicit Vertex(T theId) - : id(theId) + Vertex() noexcept + : id(T()) {}; + Vertex(const Vertex &rhs) = delete; + Vertex(Vertex &&rhs) = default; + Vertex &operator=(const Vertex &rhs) = delete; + Vertex &operator=(Vertex &&rhs) = default; + ~Vertex() = default; + T id; + /*! - * The edges are defined by this and their end vertices given in the \c edges list. + * The edges are defined by the non-owning \c edges list. */ - std::vector> edges; + std::vector edges; State state {State::NotVisited}; }; @@ -87,16 +94,16 @@ template > class Sort * \return the nodes sorted in topological order, with the first node at beginning of the deque; * an empty deque if the \c graph is either empty or not a directed acyclic graph (DAG) */ - static std::deque> topologicalSort(Graph &graph, Sorting sorting = Sorting::Normal) noexcept + static std::deque topologicalSort(Graph &graph, Sorting sorting = Sorting::Normal) noexcept { - std::deque> sorted; + std::deque sorted; for (auto &it : graph) { it.second->state = State::NotVisited; } bool ok {true}; for (auto &it : graph) { if (it.second->state != State::Done) { - ok = visit(it.second, sorting, sorted); + ok = visit(*(it.second), sorting, sorted); if (!ok) { // Not a DAG -> clear sorted vertices sorted.clear(); @@ -113,29 +120,29 @@ template > class Sort // vertices have completely been recursively visited. // Returns true if the visit was successful or false in case a cycle was detected (in which case the 'sorted' result // is left as is, without cycle) - static bool visit(std::shared_ptr vertex, Sorting sorting, std::deque> &sorted) noexcept + static bool visit(Vertex &vertex, Sorting sorting, std::deque &sorted) noexcept { - if (vertex->state == State::Done) { + if (vertex.state == State::Done) { // Already visited return true; - } else if (vertex->state == State::Visiting) { + } else if (vertex.state == State::Visiting) { // Not a DAG (cycle detected) return false; } - vertex->state = State::Visiting; + vertex.state = State::Visiting; bool ok {true}; - for (std::shared_ptr n : vertex->edges) { - ok = visit(n, sorting, sorted); + for (Vertex *v : vertex.edges) { + ok = visit(*v, sorting, sorted); if (!ok) { break; } } - vertex->state = State::Done; + vertex.state = State::Done; if (sorting == Sorting::Normal) { - sorted.push_front(vertex); + sorted.push_front(&vertex); } else { - sorted.push_back(vertex); + sorted.push_back(&vertex); } return ok; } diff --git a/src/Kernel/include/Kernel/Unit.h b/src/Kernel/include/Kernel/Unit.h index 1d4504a53..54561ad78 100644 --- a/src/Kernel/include/Kernel/Unit.h +++ b/src/Kernel/include/Kernel/Unit.h @@ -37,7 +37,7 @@ class QTime; #include "KernelLib.h" -class UnitPrivate; +struct UnitPrivate; class KERNEL_API Unit final { @@ -51,6 +51,10 @@ class KERNEL_API Unit final }; Unit(); + Unit(const Unit &rhs) = delete; + Unit(Unit &&rhs); + Unit &operator=(const Unit &rhs) = delete; + Unit &operator=(Unit &&rhs); ~Unit(); /*! diff --git a/src/Kernel/include/Kernel/Version.h b/src/Kernel/include/Kernel/Version.h index 72949bdec..cc900cfe2 100644 --- a/src/Kernel/include/Kernel/Version.h +++ b/src/Kernel/include/Kernel/Version.h @@ -45,10 +45,6 @@ struct VersionPrivate; class KERNEL_API Version final { public: - /*! - * Creates this Version with the current values of the application version. - */ - Version() noexcept; /*! * Creates this Version with \p majorNo, \p minorNo and \p patchNo values. This @@ -72,9 +68,13 @@ class KERNEL_API Version final * \sa #operator<() */ Version(QStringView version) noexcept; - Version(const Version &other) noexcept; - Version(Version &&other) noexcept; - ~Version() noexcept; + + Version() noexcept; + Version(const Version &rhs) = delete; + Version(Version &&rhs); + Version &operator=(const Version &rhs) = delete; + Version &operator=(Version &&rhs); + ~Version(); void fromString(QStringView version) noexcept; @@ -115,14 +115,6 @@ class KERNEL_API Version final */ bool isNull() const noexcept; - /*! - * Assignmnent operator. - * - * \param rhs - * the other Version to assign from - */ - void operator=(const Version &rhs) noexcept; - /*! * Compares this Version against \c rhs for equality. * diff --git a/src/Kernel/src/Convert.cpp b/src/Kernel/src/Convert.cpp index 280cbf388..bf8b99c82 100644 --- a/src/Kernel/src/Convert.cpp +++ b/src/Kernel/src/Convert.cpp @@ -39,7 +39,7 @@ // PUBLIC Convert::Convert() noexcept -{ +{ const QFileInfo earthGravityModelFileInfo = Settings::getInstance().getEarthGravityModelFileInfo(); if (earthGravityModelFileInfo.exists()) { try { @@ -57,5 +57,6 @@ Convert::Convert() noexcept } } -Convert::~Convert() noexcept -{} +Convert::Convert(Convert &&rhs) = default; +Convert &Convert::operator=(Convert &&rhs) = default; +Convert::~Convert() = default; diff --git a/src/Kernel/src/FlightSimulator.cpp b/src/Kernel/src/FlightSimulator.cpp deleted file mode 100644 index 1f81bee6e..000000000 --- a/src/Kernel/src/FlightSimulator.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 - -#include "FlightSimulator.h" - -// PUBLIC - -FlightSimulator::FlightSimulator() noexcept -{} diff --git a/src/Kernel/src/PositionParser.cpp b/src/Kernel/src/PositionParser.cpp index 63fdaf5fc..3b7e4a401 100644 --- a/src/Kernel/src/PositionParser.cpp +++ b/src/Kernel/src/PositionParser.cpp @@ -1,5 +1,5 @@ /** - * Sky Dolly - The Black Sheep for your Flight Recordings + * Sky Dolly - The Black Sheep for Your Flight Recordings * * Copyright (c) Oliver Knoll * All rights reserved. diff --git a/src/Kernel/src/Settings.cpp b/src/Kernel/src/Settings.cpp index 645184e14..658a8e488 100644 --- a/src/Kernel/src/Settings.cpp +++ b/src/Kernel/src/Settings.cpp @@ -22,10 +22,13 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#include + #include #include #include #include +#include #include #include #include @@ -45,18 +48,33 @@ namespace { - constexpr bool DefaultBackupBeforeMigration {true}; - - constexpr char ResourceDirectoryName[] = "Resources"; + constexpr const char *ResourceDirectoryName {"Resources"}; // This happens to be the same directory name as when unzipping the downloaded EGM data // from https://geographiclib.sourceforge.io/html/geoid.html#geoidinst - constexpr char EgmDirectoryName[] = "geoids"; - constexpr char DefaultEgmFileName[] = "egm2008-5.pgm"; + constexpr const char *EgmDirectoryName {"geoids"}; + constexpr const char *DefaultEgmFileName {"egm2008-5.pgm"}; } -class SettingsPrivate +struct SettingsPrivate { -public: + SettingsPrivate() noexcept + : version(QCoreApplication::instance()->applicationVersion()), + backupBeforeMigration(DefaultBackupBeforeMigration), + recordingSampleRateValue(DefaultRecordingSampleRate), + windowStayOnTop(DefaultWindowStayOnTop), + minimalUi(DefaultMinimalUi), + moduleSelectorVisible(DefaultModuleSelectorVisible), + replaySpeedVisible(DefaultReplaySpeedVisible) + { + QStringList standardLocations = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::DocumentsLocation); + if (standardLocations.count() > 0) { + defaultExportPath = standardLocations.first(); + defaultLogbookPath = standardLocations.first() % "/" % Version::getApplicationName() % "/" % Version::getApplicationName() % Const::LogbookExtension; + } else { + defaultExportPath = "."; + } + } + QSettings settings; Version version; @@ -101,15 +119,17 @@ class SettingsPrivate int previewInfoDialogCount; - static Settings *instance; + static inline std::once_flag onceFlag; + static inline Settings *instance {nullptr}; static constexpr QUuid DefaultSkyConnectPluginUuid {}; + static constexpr bool DefaultBackupBeforeMigration {true}; static constexpr double DefaultRecordingSampleRate {SampleRate::toValue(SampleRate::SampleRate::Auto)}; static constexpr bool DefaultWindowStayOnTop {false}; static constexpr bool DefaultMinimalUi {false}; - static constexpr bool DefaultModuleSelectorVisible {true}; - static constexpr bool DefaultReplaySpeedVisible {true}; - static constexpr bool DefaultAbsoluteSeek {true}; + static constexpr bool DefaultModuleSelectorVisible {true}; + static constexpr bool DefaultReplaySpeedVisible {true}; + static constexpr bool DefaultAbsoluteSeek {true}; static constexpr double DefaultSeekIntervalSeconds {1.0}; static constexpr double DefaultSeekIntervalPercent {0.5}; static constexpr bool DefaultReplayLoop {false}; @@ -117,12 +137,12 @@ class SettingsPrivate static constexpr double DefaultRepeatFlapsHandleIndex {false}; // For now the default value is true, as no known aircraft exists where the canopy values would not // have to be repeated - static constexpr bool DefaultRepeatCanopyOpen {true}; + static constexpr bool DefaultRepeatCanopyOpen {true}; static constexpr bool DefaultRelativePositionPlacement {true}; - static constexpr bool DefaultDeleteFlightConfirmation {true}; - static constexpr bool DefaultDeleteAircraftConfirmation {true}; - static constexpr bool DefaultDeleteLocationConfirmation {true}; - static constexpr bool DefaultResetTimeOffsetConfirmation {true}; + static constexpr bool DefaultDeleteFlightConfirmation {true}; + static constexpr bool DefaultDeleteAircraftConfirmation {true}; + static constexpr bool DefaultDeleteLocationConfirmation {true}; + static constexpr bool DefaultResetTimeOffsetConfirmation {true}; static constexpr bool DefaultMinimalUiButtonTextVisible {false}; static constexpr bool DefaultMinimalUiNonEssentialButtonVisible {false}; @@ -132,32 +152,16 @@ class SettingsPrivate static constexpr int DefaultPreviewInfoDialogCount {3}; static constexpr int PreviewInfoDialogBase {100}; - - SettingsPrivate() noexcept - : version(QCoreApplication::instance()->applicationVersion()) - { - QStringList standardLocations = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::DocumentsLocation); - if (standardLocations.count() > 0) { - defaultExportPath = standardLocations.first(); - defaultLogbookPath = standardLocations.first() + "/" + Version::getApplicationName() + "/" + Version::getApplicationName() + Const::LogbookExtension; - } else { - defaultExportPath = "."; - } - } - - ~SettingsPrivate() noexcept - {} }; -Settings *SettingsPrivate::instance = nullptr; // PUBLIC Settings &Settings::getInstance() noexcept { - if (SettingsPrivate::instance == nullptr) { + std::call_once(SettingsPrivate::onceFlag, []() { SettingsPrivate::instance = new Settings(); - } + }); return *SettingsPrivate::instance; } @@ -712,7 +716,7 @@ void Settings::restore() noexcept d->settings.beginGroup("Logbook"); { d->logbookPath = d->settings.value("Path", d->defaultLogbookPath).toString(); - d->backupBeforeMigration = d->settings.value("BackupBeforeMigration", ::DefaultBackupBeforeMigration).toBool(); + d->backupBeforeMigration = d->settings.value("BackupBeforeMigration", SettingsPrivate::DefaultBackupBeforeMigration).toBool(); } d->settings.endGroup(); d->settings.beginGroup("Plugins"); @@ -824,16 +828,6 @@ void Settings::restore() noexcept d->settings.endGroup(); } -// PROTECTED - -Settings::~Settings() noexcept -{ -#ifdef DEBUG - qDebug() << "Settings::~Settings: DELETED"; -#endif - store(); -} - // PRIVATE Settings::Settings() noexcept @@ -847,6 +841,14 @@ Settings::Settings() noexcept updateEgmFilePath(); } +Settings::~Settings() +{ +#ifdef DEBUG + qDebug() << "Settings::~Settings: DELETED"; +#endif + store(); +} + void Settings::frenchConnection() noexcept { connect(this, &Settings::logbookPathChanged, diff --git a/src/Kernel/src/SettingsConverter.cpp b/src/Kernel/src/SettingsConverter.cpp index ba48ae87d..07af70db2 100644 --- a/src/Kernel/src/SettingsConverter.cpp +++ b/src/Kernel/src/SettingsConverter.cpp @@ -30,7 +30,7 @@ namespace { - void convertToV12(Version settingsVersion, QSettings &settings) + void convertToV13(const Version &settingsVersion, QSettings &settings) noexcept { // Nothing to convert yet } @@ -38,10 +38,10 @@ namespace // PUBLIC -void SettingsConverter::convertToCurrent(Version settingsVersion, QSettings &settings) +void SettingsConverter::convertToCurrent(const Version &settingsVersion, QSettings &settings) noexcept { const Version currentVersion; if (settingsVersion < currentVersion) { - ::convertToV12(settingsVersion, settings); + ::convertToV13(settingsVersion, settings); } } diff --git a/src/Kernel/src/SettingsConverter.h b/src/Kernel/src/SettingsConverter.h index b15e520cb..cd13e78c5 100644 --- a/src/Kernel/src/SettingsConverter.h +++ b/src/Kernel/src/SettingsConverter.h @@ -31,7 +31,7 @@ namespace SettingsConverter { - void convertToCurrent(Version settingsVersion, QSettings &settings); + void convertToCurrent(const Version &settingsVersion, QSettings &settings) noexcept; }; #endif // SETTINGSCONVERTER_H diff --git a/src/Kernel/src/Unit.cpp b/src/Kernel/src/Unit.cpp index a4aec3688..81825031d 100644 --- a/src/Kernel/src/Unit.cpp +++ b/src/Kernel/src/Unit.cpp @@ -39,7 +39,6 @@ #include #include -#include "Convert.h" #include "Unit.h" namespace { @@ -59,14 +58,14 @@ namespace { constexpr int CoordinatePrecision = 6; } -class UnitPrivate { +struct UnitPrivate { public: UnitPrivate() {} QLocale locale; - static inline QLatin1Char NumberPadding {QLatin1Char('0')}; + static constexpr QLatin1Char NumberPadding {'0'}; }; // PUBLIC @@ -75,8 +74,9 @@ Unit::Unit() : d(std::make_unique()) {} -Unit::~Unit() -{} +Unit::Unit(Unit &&rhs) = default; +Unit &Unit::operator=(Unit &&rhs) = default; +Unit::~Unit() = default; QString Unit::formatLatitudeDMS(double latitude) const noexcept { @@ -261,13 +261,13 @@ QString Unit::formatElapsedTime(std::int64_t milliSeconds) const noexcept if (qAbs(milliSeconds) < ::MillisecondsPerSecond) { elapsedTime = QCoreApplication::translate("Unit", "%1 milliseconds", nullptr, static_cast(milliSeconds)).arg(milliSeconds); } else if (qAbs(milliSeconds) < ::MillisecondsPerSecond * ::SecondsPerMinute) { - const double seconds = static_cast(milliSeconds) / ::MillisecondsPerSecond; + const double seconds = static_cast(milliSeconds) / static_cast(::MillisecondsPerSecond); elapsedTime = QCoreApplication::translate("Unit", "%1 seconds", nullptr, static_cast(seconds)).arg(QString::number(seconds, 'f', 1)); } else if (qAbs(milliSeconds) < ::MillisecondsPerSecond * ::SecondsPerMinute * ::MinutesPerHour) { - const double minutes = static_cast(milliSeconds) / (::MillisecondsPerSecond * ::SecondsPerMinute); + const double minutes = static_cast(milliSeconds) / static_cast(::MillisecondsPerSecond * ::SecondsPerMinute); elapsedTime = QCoreApplication::translate("Unit", "%1 minutes", nullptr, static_cast(minutes)).arg(QString::number(minutes, 'f', 1)); } else { - const double hours = static_cast(milliSeconds) / (::MillisecondsPerSecond * ::SecondsPerMinute * ::MinutesPerHour); + const double hours = static_cast(milliSeconds) / static_cast(::MillisecondsPerSecond * ::SecondsPerMinute * ::MinutesPerHour); elapsedTime = QCoreApplication::translate("Unit", "%1 hours", nullptr, static_cast(hours)).arg(QString::number(hours, 'f', 1)); } diff --git a/src/Kernel/src/Version.cpp b/src/Kernel/src/Version.cpp index 6edf6e368..7eb7fa218 100644 --- a/src/Kernel/src/Version.cpp +++ b/src/Kernel/src/Version.cpp @@ -38,23 +38,23 @@ struct VersionPrivate { - VersionPrivate() noexcept - {} - VersionPrivate(int theMajor, int theMinor, int thePatch) noexcept : major(theMajor), minor(theMinor), patch(thePatch) {} - VersionPrivate(const VersionPrivate &other) - : major(other.major), minor(other.minor), patch(other.patch) - {} + VersionPrivate() = default; + ~VersionPrivate() = default; + VersionPrivate(const VersionPrivate &rhs) = default; + VersionPrivate(VersionPrivate &&rhs) = default; + VersionPrivate &operator=(const VersionPrivate &rhs) = default; + VersionPrivate &operator=(VersionPrivate &&rhs) = default; int major {VersionConfig::Major}; int minor {VersionConfig::Minor}; int patch {VersionConfig::Patch}; - // https://grammar.yourdictionary.com/parts-of-speech/adjectives/adjectives-that-start-with-c.html - static inline const QString CodeName {QStringLiteral("Celestial Cessna")}; + // https://grammar.yourdictionary.com/parts-of-speech/adjectives/adjectives-that-start-with-d.html + static inline const QString CodeName {QStringLiteral("Dapper Daher")}; }; // PUBLIC @@ -73,13 +73,9 @@ Version::Version(QStringView version) noexcept fromString(version); } -Version::Version(const Version &other) noexcept - : d(std::make_unique(other.d->major, other.d->minor, other.d->patch)) -{} - -Version::Version(Version &&other) noexcept - : d(std::move(other.d)) -{} +Version::Version(Version &&rhs) = default; +Version &Version::operator=(Version &&rhs) = default; +Version::~Version() = default; void Version::fromString(QStringView version) noexcept { @@ -92,9 +88,6 @@ void Version::fromString(QStringView version) noexcept } } -Version::~Version() noexcept -{} - int Version::getMajor() const noexcept { return d->major; @@ -120,11 +113,6 @@ bool Version::isNull() const noexcept return d->major == 0 && d->minor == 0 && d->patch == 0; } -void Version::operator=(const Version &rhs) noexcept -{ - d = std::make_unique(rhs.d->major, rhs.d->minor, rhs.d->patch); -} - bool Version::operator==(const Version &rhs) const noexcept { bool result; diff --git a/src/KernelTest/src/PositionParserTest.cpp b/src/KernelTest/src/PositionParserTest.cpp index f7cf41cf4..cdc280537 100644 --- a/src/KernelTest/src/PositionParserTest.cpp +++ b/src/KernelTest/src/PositionParserTest.cpp @@ -1,5 +1,5 @@ /** - * Sky Dolly - The Black Sheep for your Flight Recordings + * Sky Dolly - The Black Sheep for Your Flight Recordings * * Copyright (c) Oliver Knoll * All rights reserved. diff --git a/src/KernelTest/src/PositionParserTest.h b/src/KernelTest/src/PositionParserTest.h index 21debafc8..eabda8575 100644 --- a/src/KernelTest/src/PositionParserTest.h +++ b/src/KernelTest/src/PositionParserTest.h @@ -1,5 +1,5 @@ /** - * Sky Dolly - The Black Sheep for your Flight Recordings + * Sky Dolly - The Black Sheep for Your Flight Recordings * * Copyright (c) Oliver Knoll * All rights reserved. diff --git a/src/KernelTest/src/SortTest.cpp b/src/KernelTest/src/SortTest.cpp index 2f875418d..4901a5885 100644 --- a/src/KernelTest/src/SortTest.cpp +++ b/src/KernelTest/src/SortTest.cpp @@ -122,12 +122,12 @@ void SortTest::topologicalSort() std::shared_ptr sourceVertex = graph.at(nodeId); sourceVertex->edges.reserve(edgeList.size()); for (const int id : edgeList) { - sourceVertex->edges.push_back(graph.at(id)); + sourceVertex->edges.push_back(graph.at(id).get()); } } // Exercise - std::deque> sorted = Sort::topologicalSort(graph, sorting); + std::deque sorted = Sort::topologicalSort(graph, sorting); // Verify int i {0}; diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 56e009565..e0f3efdcc 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -14,28 +14,28 @@ target_compile_definitions(${LIBRARY_NAME} target_sources(${LIBRARY_NAME} PRIVATE include/Model/ModelLib.h - include/Model/Data.h src/Data.cpp + include/Model/Data.h include/Model/Logbook.h src/Logbook.cpp include/Model/AbstractComponent.h include/Model/Flight.h src/Flight.cpp - include/Model/FlightSummary.h src/FlightSummary.cpp + include/Model/FlightSummary.h include/Model/FlightDate.h src/FlightDate.cpp include/Model/FlightCondition.h src/FlightCondition.cpp include/Model/Aircraft.h src/Aircraft.cpp - include/Model/TimeVariableData.h src/TimeVariableData.cpp + include/Model/TimeVariableData.h include/Model/Position.h src/Position.cpp include/Model/PositionData.h src/PositionData.cpp include/Model/InitialPosition.h src/InitialPosition.cpp include/Model/Engine.h src/Engine.cpp include/Model/EngineData.h src/EngineData.cpp include/Model/PrimaryFlightControl.h src/PrimaryFlightControl.cpp - include/Model/PrimaryFlightControlData.h src/PrimaryFlightControlData.cpp + include/Model/PrimaryFlightControlData.h include/Model/SecondaryFlightControl.h src/SecondaryFlightControl.cpp - include/Model/SecondaryFlightControlData.h src/SecondaryFlightControlData.cpp + include/Model/SecondaryFlightControlData.h include/Model/AircraftHandle.h src/AircraftHandle.cpp - include/Model/AircraftHandleData.h src/AircraftHandleData.cpp + include/Model/AircraftHandleData.h include/Model/Light.h src/Light.cpp - include/Model/LightData.h src/LightData.cpp + include/Model/LightData.h include/Model/AircraftType.h src/AircraftType.cpp include/Model/AircraftInfo.h src/AircraftInfo.cpp include/Model/Waypoint.h src/Waypoint.cpp diff --git a/src/Model/include/Model/AbstractComponent.h b/src/Model/include/Model/AbstractComponent.h index f4b8eb1f9..7f9136a61 100644 --- a/src/Model/include/Model/AbstractComponent.h +++ b/src/Model/include/Model/AbstractComponent.h @@ -44,43 +44,25 @@ class MODEL_API AbstractComponent using Data = typename std::vector; using Iterator = typename Data::iterator; using ConstIterator = typename Data::const_iterator; - using BackInsertIterator = typename std::back_insert_iterator; explicit AbstractComponent(const AircraftInfo &aircraftInfo) noexcept : m_aircraftInfo(aircraftInfo) {} + AbstractComponent() noexcept; + AbstractComponent(const AbstractComponent &rhs) = default; + AbstractComponent(AbstractComponent &&rhs) = default; + AbstractComponent &operator=(const AbstractComponent &rhs) = default; + AbstractComponent &operator=(AbstractComponent &&rhs) = default; virtual ~AbstractComponent() = default; - AbstractComponent(const AbstractComponent &) = default; - AbstractComponent(AbstractComponent &&other) - : m_data (std::move(other.m_data)), - m_aircraftInfo(std::move(other.m_aircraftInfo)), - m_currentTimestamp(other.m_currentTimestamp), - m_currentIndex(other.m_currentIndex), - m_currentAccess(other.m_currentAccess) - {} - AbstractComponent &operator=(const AbstractComponent &rhs) + void setData(const Data &data) noexcept { - if (this != &rhs) { - // Don't copy the reference member - m_data = rhs.m_data; - m_currentTimestamp = rhs.m_currentTimestamp; - m_currentIndex = rhs.m_currentIndex; - m_currentAccess = rhs.m_currentAccess; - } - return *this; + m_data = data; } - AbstractComponent &operator=(AbstractComponent &&rhs) + void setData(Data &&data) noexcept { - if (this != &rhs) { - // Don't copy the reference member - m_data = std::move(rhs.m_data); - m_currentTimestamp = rhs.m_currentTimestamp; - m_currentIndex = rhs.m_currentIndex; - m_currentAccess = rhs.m_currentAccess; - } - return *this; + m_data = std::move(data); } /*! @@ -94,11 +76,11 @@ class MODEL_API AbstractComponent * the data to be upserted * \sa upsert */ - void upsertLast(const T data) noexcept + void upsertLast(const T &data) noexcept { if (m_data.size() > 0 && m_data.back() == data) { // Same timestamp -> replace - m_data[m_data.size() - 1] = std::move(data); + m_data.back() = data; } else { m_data.push_back(std::move(data)); } @@ -115,7 +97,7 @@ class MODEL_API AbstractComponent * the data to be upserted * \sa upsertLast */ - void upsert(const T data) noexcept + void upsert(const T &data) noexcept { auto result = std::find_if(m_data.begin(), m_data.end(), [&data] (const TimeVariableData &d) { return d.timestamp == data.timestamp; }); @@ -127,22 +109,26 @@ class MODEL_API AbstractComponent } } + /*! + * Returns the first data element. The collection must have at least one element, + * otherwise the behaviour is undefined. + * + * \return the first element T of the collection + */ const T &getFirst() const noexcept { - if (!m_data.empty()) { - return m_data.front(); - } else { - return T::NullData; - } + return m_data.front(); } + /*! + * Returns the last data element. The collection must have at least one element, + * otherwise the behaviour is undefined. + * + * \return the last element T of the collection + */ const T &getLast() const noexcept { - if (!m_data.empty()) { - return m_data.back(); - } else { - return T::NullData; - } + return m_data.back(); } [[nodiscard]] @@ -178,11 +164,6 @@ class MODEL_API AbstractComponent return m_data.cend(); } - BackInsertIterator backInsertIterator() noexcept - { - return std::back_inserter(m_data); - } - T &operator[](std::size_t index) noexcept { return m_data[index]; @@ -193,7 +174,7 @@ class MODEL_API AbstractComponent return m_data[index]; } - virtual const T &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept = 0; + virtual T interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept = 0; protected: [[nodiscard]] @@ -209,7 +190,7 @@ class MODEL_API AbstractComponent } [[nodiscard]] - inline const std::int64_t getCurrentTimestamp() const noexcept + inline std::int64_t getCurrentTimestamp() const noexcept { return m_currentTimestamp; } @@ -219,7 +200,7 @@ class MODEL_API AbstractComponent } [[nodiscard]] - inline const int getCurrentIndex() const noexcept + inline int getCurrentIndex() const noexcept { return m_currentIndex; } @@ -229,7 +210,7 @@ class MODEL_API AbstractComponent } [[nodiscard]] - inline const TimeVariableData::Access getCurrentAccess() const noexcept + inline TimeVariableData::Access getCurrentAccess() const noexcept { return m_currentAccess; } diff --git a/src/Model/include/Model/Aircraft.h b/src/Model/include/Model/Aircraft.h index ade0a40a1..39875c667 100644 --- a/src/Model/include/Model/Aircraft.h +++ b/src/Model/include/Model/Aircraft.h @@ -28,8 +28,6 @@ #include #include -#include - class QDateTime; #include "ModelLib.h" @@ -42,14 +40,18 @@ class SecondaryFlightControl; class AircraftHandle; class Light; class FlightPlan; -class AircraftPrivate; +struct AircraftPrivate; -class MODEL_API Aircraft : public QObject +class MODEL_API Aircraft final { - Q_OBJECT public: - explicit Aircraft(QObject *parent = nullptr) noexcept; - ~Aircraft() noexcept override; + + Aircraft() noexcept; + Aircraft(const Aircraft &rhs) = delete; + Aircraft(Aircraft &&rhs); + Aircraft &operator=(const Aircraft &rhs) = delete; + Aircraft &operator=(Aircraft &&rhs); + ~Aircraft(); std::int64_t getId() const noexcept; void setId(std::int64_t id) noexcept; @@ -88,9 +90,6 @@ class MODEL_API Aircraft : public QObject bool operator==(const Aircraft &rhs) const noexcept; bool operator!=(const Aircraft &rhs) const noexcept; - static constexpr std::int64_t InvalidId {-1}; - -public slots: /*! * Invalidates the duration, such that it gets updated the next time * #getDurationMSec is called. @@ -102,32 +101,8 @@ public slots: */ void invalidateDuration() noexcept; -signals: - /*! - * Emitted whenever the aircraft info has changed. - */ - void infoChanged(const Aircraft &aircraft); - - /*! - * Emitted whenever the tail number has changed. - * - * \param aircraft - * the aircraft whose tail number has changed - */ - void tailNumberChanged(const Aircraft &aircraft); - - /*! - * Emitted whenever the aircraft's time offset has changed. - * - * \param aircraft - * the aircraft whose time offset has changed - */ - void timeOffsetChanged(const Aircraft &aircraft); - private: std::unique_ptr d; - - void frenchConnection(); }; #endif // AIRCRAFT_H diff --git a/src/Model/include/Model/AircraftHandle.h b/src/Model/include/Model/AircraftHandle.h index b010baec0..22b4aeedd 100644 --- a/src/Model/include/Model/AircraftHandle.h +++ b/src/Model/include/Model/AircraftHandle.h @@ -34,20 +34,14 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API AircraftHandle : public AbstractComponent +class MODEL_API AircraftHandle final : public AbstractComponent { public: explicit AircraftHandle(const AircraftInfo &aircraftInfo) noexcept; - AircraftHandle(AircraftHandle &other) = default; - AircraftHandle(AircraftHandle &&other) = default; - ~AircraftHandle() noexcept override; - AircraftHandle &operator=(const AircraftHandle &rhs) = default; - AircraftHandle &operator=(AircraftHandle &&rhs) = default; - const AircraftHandleData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + AircraftHandleData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - AircraftHandleData m_currentAircraftHandleData; AircraftHandleData m_previousAircraftHandleData; }; diff --git a/src/Model/include/Model/AircraftHandleData.h b/src/Model/include/Model/AircraftHandleData.h index f02f8d577..a894e6ee0 100644 --- a/src/Model/include/Model/AircraftHandleData.h +++ b/src/Model/include/Model/AircraftHandleData.h @@ -32,28 +32,19 @@ #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API AircraftHandleData : public TimeVariableData +struct MODEL_API AircraftHandleData final : public TimeVariableData { - std::int16_t brakeLeftPosition; - std::int16_t brakeRightPosition; + std::int16_t brakeLeftPosition {0}; + std::int16_t brakeRightPosition {0}; // Implementation note: the water rudder can also have negative (-100.0) values, // hence hence the type std::int16_t (position) which also supports negative values - std::int16_t waterRudderHandlePosition; - std::uint8_t tailhookPosition; - std::uint8_t canopyOpen; - std::uint8_t leftWingFolding; - std::uint8_t rightWingFolding; - bool gearHandlePosition; - bool smokeEnabled; - - AircraftHandleData() noexcept; - AircraftHandleData(const AircraftHandleData &other) = default; - AircraftHandleData(AircraftHandleData &&other) = default; - ~AircraftHandleData() override = default; - AircraftHandleData &operator=(const AircraftHandleData &rhs) = default; - AircraftHandleData &operator=(AircraftHandleData &&rhs) = default; - - static const AircraftHandleData NullData; + std::int16_t waterRudderHandlePosition {0}; + std::uint8_t tailhookPosition {0}; + std::uint8_t canopyOpen {0}; + std::uint8_t leftWingFolding {0}; + std::uint8_t rightWingFolding {0}; + bool gearHandlePosition {false}; + bool smokeEnabled {false}; }; #endif // AIRCRAFTHANDLEDATA_H diff --git a/src/Model/include/Model/AircraftInfo.h b/src/Model/include/Model/AircraftInfo.h index 6482721ce..82534ee66 100644 --- a/src/Model/include/Model/AircraftInfo.h +++ b/src/Model/include/Model/AircraftInfo.h @@ -32,27 +32,29 @@ #include "AircraftType.h" #include "ModelLib.h" -struct MODEL_API AircraftInfo +struct MODEL_API AircraftInfo final { - std::int64_t aircraftId; + std::int64_t aircraftId {0}; AircraftType aircraftType; // Milliseconds - std::int64_t timeOffset; + std::int64_t timeOffset {0}; QString tailNumber; QString airline; QString flightNumber; // Feet - float altitudeAboveGround; - bool startOnGround; + float altitudeAboveGround {0.0f}; + bool startOnGround {false}; // Knots (TAS) - int initialAirspeed; + int initialAirspeed {0}; AircraftInfo(std::int64_t aircraftId) noexcept; - AircraftInfo(const AircraftInfo &other) = default; - AircraftInfo(AircraftInfo &&other) noexcept; + AircraftInfo() noexcept; + AircraftInfo(const AircraftInfo &rhs) = default; + AircraftInfo(AircraftInfo &&rhs) = default; AircraftInfo &operator=(const AircraftInfo &rhs) = default; - AircraftInfo &operator=(AircraftInfo &&rhs) noexcept; + AircraftInfo &operator=(AircraftInfo &&rhs) = default; + ~AircraftInfo() = default; void clear() noexcept; }; diff --git a/src/Model/include/Model/AircraftType.h b/src/Model/include/Model/AircraftType.h index 2e8f21c9f..b63cd243b 100644 --- a/src/Model/include/Model/AircraftType.h +++ b/src/Model/include/Model/AircraftType.h @@ -31,7 +31,7 @@ #include "SimType.h" #include "ModelLib.h" -struct MODEL_API AircraftType +struct MODEL_API AircraftType final { /*! * The aircraft type, e.g. "Pitts Special". This is really the SimConnect "container title" @@ -49,16 +49,17 @@ struct MODEL_API AircraftType */ QString category; // Feet - int wingSpan; - SimType::EngineType engineType; - int numberOfEngines; + int wingSpan {0}; + SimType::EngineType engineType {SimType::EngineType::Unknown}; + int numberOfEngines {0}; - AircraftType() noexcept; - ~AircraftType() = default; - AircraftType(const AircraftType &other) = default; - AircraftType(AircraftType &&other) noexcept; + AircraftType(QString type, QString category, int wingSpan, SimType::EngineType engineType, int numberOfEngines) noexcept; + AircraftType() = default; + AircraftType(const AircraftType &rhs) = default; + AircraftType(AircraftType &&rhs) = default; AircraftType &operator=(const AircraftType &rhs) = default; - AircraftType &operator=(AircraftType &&rhs) noexcept; + AircraftType &operator=(AircraftType &&rhs) = default; + ~AircraftType() = default; void clear() noexcept; }; diff --git a/src/Model/include/Model/Data.h b/src/Model/include/Model/Data.h index 52644f10c..68ea0a9e4 100644 --- a/src/Model/include/Model/Data.h +++ b/src/Model/include/Model/Data.h @@ -27,6 +27,7 @@ #include +#include /*! * The base data object for all non-time variant data objects which are persisted, * identified by their \c id. @@ -35,14 +36,16 @@ */ struct Data { - explicit Data(std::int64_t id = InvalidId) + explicit Data(std::int64_t id = Const::InvalidId) : id(id) {} + Data(const Data &rhs) = default; + Data(Data &&rhs) = default; + Data &operator=(const Data &rhs) = default; + Data &operator=(Data &&rhs) = default; virtual ~Data() = default; - std::int64_t id {InvalidId}; - - static constexpr std::int64_t InvalidId {-1}; + std::int64_t id {Const::InvalidId}; }; #endif // DATA_H diff --git a/src/Model/include/Model/Engine.h b/src/Model/include/Model/Engine.h index d35e409ec..e204f7350 100644 --- a/src/Model/include/Model/Engine.h +++ b/src/Model/include/Model/Engine.h @@ -30,20 +30,12 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API Engine : public AbstractComponent +class MODEL_API Engine final : public AbstractComponent { public: explicit Engine(const AircraftInfo &aircraftInfo) noexcept; - Engine(Engine &other) = default; - Engine(Engine &&other) = default; - ~Engine() noexcept override; - Engine &operator=(const Engine &rhs) = default; - Engine &operator=(Engine &&rhs) = default; - const EngineData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; - -private: - EngineData m_currentEngineData; + EngineData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; }; #endif // ENGINE_H diff --git a/src/Model/include/Model/EngineData.h b/src/Model/include/Model/EngineData.h index 43f7a5763..667bd98d6 100644 --- a/src/Model/include/Model/EngineData.h +++ b/src/Model/include/Model/EngineData.h @@ -30,50 +30,44 @@ #include #include -#include "SimType.h" #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API EngineData : public TimeVariableData +struct MODEL_API EngineData final : public TimeVariableData { // Implementation note: the throttle and propeller levers can also yield // negative thrust, hence the type std::int16_t (position) which also supports negative values - std::int16_t throttleLeverPosition1; - std::int16_t throttleLeverPosition2; - std::int16_t throttleLeverPosition3; - std::int16_t throttleLeverPosition4; - std::int16_t propellerLeverPosition1; - std::int16_t propellerLeverPosition2; - std::int16_t propellerLeverPosition3; - std::int16_t propellerLeverPosition4; - std::uint8_t mixtureLeverPosition1; - std::uint8_t mixtureLeverPosition2; - std::uint8_t mixtureLeverPosition3; - std::uint8_t mixtureLeverPosition4; - std::uint8_t cowlFlapPosition1; - std::uint8_t cowlFlapPosition2; - std::uint8_t cowlFlapPosition3; - std::uint8_t cowlFlapPosition4; + std::int16_t throttleLeverPosition1 {0}; + std::int16_t throttleLeverPosition2 {0}; + std::int16_t throttleLeverPosition3 {0}; + std::int16_t throttleLeverPosition4 {0}; + std::int16_t propellerLeverPosition1 {0}; + std::int16_t propellerLeverPosition2 {0}; + std::int16_t propellerLeverPosition3 {0}; + std::int16_t propellerLeverPosition4 {0}; + std::uint8_t mixtureLeverPosition1 {0}; + std::uint8_t mixtureLeverPosition2 {0}; + std::uint8_t mixtureLeverPosition3 {0}; + std::uint8_t mixtureLeverPosition4 {0}; + std::uint8_t cowlFlapPosition1 {0}; + std::uint8_t cowlFlapPosition2 {0}; + std::uint8_t cowlFlapPosition3 {0}; + std::uint8_t cowlFlapPosition4 {0}; - bool electricalMasterBattery1; - bool electricalMasterBattery2; - bool electricalMasterBattery3; - bool electricalMasterBattery4; - bool generalEngineStarter1; - bool generalEngineStarter2; - bool generalEngineStarter3; - bool generalEngineStarter4; - bool generalEngineCombustion1; - bool generalEngineCombustion2; - bool generalEngineCombustion3; - bool generalEngineCombustion4; + bool electricalMasterBattery1 {false}; + bool electricalMasterBattery2 {false}; + bool electricalMasterBattery3 {false}; + bool electricalMasterBattery4 {false}; + bool generalEngineStarter1 {false}; + bool generalEngineStarter2 {false}; + bool generalEngineStarter3 {false}; + bool generalEngineStarter4 {false}; + bool generalEngineCombustion1 {false}; + bool generalEngineCombustion2 {false}; + bool generalEngineCombustion3 {false}; + bool generalEngineCombustion4 {false}; explicit EngineData(std::int16_t throttleLeverPosition1 = 0, std::int16_t propellerLeverPosition1 = 0, std::uint8_t mixtureLeverPosition1 = 0, std::uint8_t cowlFlapPosition1 = 0) noexcept; - EngineData(const EngineData &other) = default; - EngineData(EngineData &&other) = default; - ~EngineData() override = default; - EngineData &operator=(const EngineData &rhs) = default; - EngineData &operator=(EngineData &&rhs) = default; inline bool hasEngineStarterEnabled() const noexcept { @@ -84,8 +78,6 @@ struct MODEL_API EngineData : public TimeVariableData { return (generalEngineCombustion1 || generalEngineCombustion2 || generalEngineCombustion3 || generalEngineCombustion4); } - - static const EngineData NullData; }; #endif // ENGINEDATA_H diff --git a/src/Model/include/Model/Enumeration.h b/src/Model/include/Model/Enumeration.h index da2cd2c7b..56c3efd36 100644 --- a/src/Model/include/Model/Enumeration.h +++ b/src/Model/include/Model/Enumeration.h @@ -27,11 +27,9 @@ #include #include -#include #include -#include "InitialPosition.h" #include "Data.h" #include "ModelLib.h" @@ -44,14 +42,16 @@ struct EnumerationPrivate; * * \sa Enum#toUnderlyingType */ -class MODEL_API Enumeration +class MODEL_API Enumeration final { public: - - Enumeration(QString name) noexcept; - Enumeration(Enumeration &&other) noexcept = default; - ~Enumeration() noexcept; - Enumeration &operator=(Enumeration &&rhs) noexcept = default; + Enumeration(const QString &name) noexcept; + Enumeration() noexcept; + Enumeration(const Enumeration &rhs) = delete; + Enumeration(Enumeration &&rhs); + Enumeration &operator=(const Enumeration &rhs) = delete; + Enumeration &operator=(Enumeration &&rhs); + ~Enumeration(); using Item = struct Item_ : public Data { diff --git a/src/Model/include/Model/Flight.h b/src/Model/include/Model/Flight.h index c7a35e9cd..44b557d63 100644 --- a/src/Model/include/Model/Flight.h +++ b/src/Model/include/Model/Flight.h @@ -40,14 +40,19 @@ class QString; #include "FlightCondition.h" #include "ModelLib.h" +struct Waypoint; struct FlightPrivate; -class MODEL_API Flight : public QObject +class MODEL_API Flight final : public QObject { Q_OBJECT public: explicit Flight(QObject *parent = nullptr) noexcept; - ~Flight() noexcept override; + Flight(const Flight &rhs) = delete; + Flight(Flight &&rhs) = delete; + Flight &operator=(const Flight &rhs) = delete; + Flight &operator=(Flight &&rhs) = delete; + ~Flight() override; std::int64_t getId() const noexcept; void setId(std::int64_t id) noexcept; @@ -61,7 +66,7 @@ class MODEL_API Flight : public QObject const QString &getDescription() const noexcept; void setDescription(const QString &description) noexcept; - void setAircraft(std::vector> aircraft) noexcept; + void setAircraft(std::vector &&aircraft) noexcept; Aircraft &addUserAircraft() noexcept; Aircraft &getUserAircraft() const noexcept; @@ -116,6 +121,33 @@ class MODEL_API Flight : public QObject std::int64_t deleteAircraftByIndex(int index) noexcept; std::size_t count() const noexcept; + /*! + * Adds the \c waypoint to the flight plan of the user aircraft. + * + * \param waypoint + * the waypoint to be added to the flight plan of the user aircraft + * \sa waypointAdded + */ + void addWaypoint(const Waypoint &waypoint) noexcept; + + /*! + * Updates the waypoint at \c index with the given \c waypoint. + * + * \param index + * the index of the waypoint to be updated + * \param waypoint + * the waypoint data to update with + * \sa waypointUpdated + */ + void updateWaypoint(int index, const Waypoint &waypoint) noexcept; + + /*! + * Clears all waypoints of the flight plan of the user aircraft. + * + * \sa waypointsCleared + */ + void clearWaypoints() noexcept; + const FlightCondition &getFlightCondition() const noexcept; void setFlightCondition(FlightCondition flightCondition) noexcept; @@ -145,7 +177,7 @@ class MODEL_API Flight : public QObject void clear(bool withOneAircraft) noexcept; - using Iterator = std::vector>::iterator; + using Iterator = std::vector::iterator; Iterator begin() noexcept; Iterator end() noexcept; @@ -155,11 +187,6 @@ class MODEL_API Flight : public QObject Aircraft &operator[](std::size_t index) noexcept; const Aircraft &operator[](std::size_t index) const noexcept; - /*! - * The initial ID for every newly created flight. An invalid ID indicates that this - * flight has not yet been (successfully) persisted. - */ - static constexpr std::int64_t InvalidId {-1}; static constexpr int InvalidAircraftIndex {-1}; signals: @@ -172,6 +199,30 @@ class MODEL_API Flight : public QObject void aircraftAdded(const Aircraft &newAircraft); void aircraftRemoved(std::int64_t removedAircraftId); + void infoChanged(const Aircraft &aircraft); + + /*! + * Emitted whenever a new \c waypoint has been added to the user aircraft. + * + * \param waypoint + * the newly added waypoint + */ + void waypointAdded(const Waypoint &waypoint); + + /*! + * Emitted whenever the \c waypoint of the user aircraft at \c index has been udpated. + * + * \param index + * the index of the updated waypoint + * \param waypoint + * the updated waypoint + */ + void waypointUpdated(int index, const Waypoint &waypoint); + + /*! + * Emitted whenever all waypoints of the user aircraft have been cleared. + */ + void waypointsCleared(); /*! * Emitted whenever the user aircraft index is changed to \c newUserAircraftIndex. In case a previous user aircraft @@ -209,8 +260,6 @@ class MODEL_API Flight : public QObject private: std::unique_ptr d; - inline void connectWithAircraftSignals(Aircraft &aircraft); - /* * Re-assigns the user aircraft \c index, but without emitting the \c userAircraftChanged signal. * This is useful in case an aircraft with an index lower (<) than the current user aircraft diff --git a/src/Model/include/Model/FlightCondition.h b/src/Model/include/Model/FlightCondition.h index 4149647c3..2f37b5eb9 100644 --- a/src/Model/include/Model/FlightCondition.h +++ b/src/Model/include/Model/FlightCondition.h @@ -33,32 +33,25 @@ #include "SimType.h" #include "ModelLib.h" -struct MODEL_API FlightCondition +struct MODEL_API FlightCondition final { - float groundAltitude; - SimType::SurfaceType surfaceType; - float ambientTemperature; - float totalAirTemperature; - float windSpeed; - float windDirection; - SimType::PrecipitationState precipitationState; - float visibility; - float seaLevelPressure; - std::uint8_t pitotIcingPercent; - std::uint8_t structuralIcingPercent; - bool inClouds; + float groundAltitude {0.0f}; + SimType::SurfaceType surfaceType {SimType::SurfaceType::Unknown}; + float ambientTemperature {0.0f}; + float totalAirTemperature {0.0f}; + float windSpeed {0.0f}; + float windDirection {0.0f}; + SimType::PrecipitationState precipitationState {SimType::PrecipitationState::None}; + float visibility {0.0f}; + float seaLevelPressure {0.0f}; + std::uint8_t pitotIcingPercent {0}; + std::uint8_t structuralIcingPercent {0}; + bool inClouds {false}; QDateTime startLocalTime; QDateTime startZuluTime; QDateTime endLocalTime; QDateTime endZuluTime; - FlightCondition() noexcept; - FlightCondition(const FlightCondition &other) = default; - FlightCondition(FlightCondition &&other) noexcept; - ~FlightCondition() = default; - FlightCondition &operator=(const FlightCondition &rhs) = default; - FlightCondition &operator=(FlightCondition &&rhs) noexcept; - void clear() noexcept; }; diff --git a/src/Model/include/Model/FlightDate.h b/src/Model/include/Model/FlightDate.h index 0939f2476..124279daa 100644 --- a/src/Model/include/Model/FlightDate.h +++ b/src/Model/include/Model/FlightDate.h @@ -9,15 +9,9 @@ * Represents a date on which flights have been recorded, including * the number of recorded flights on that date. */ -struct MODEL_API FlightDate +struct MODEL_API FlightDate final { - FlightDate() noexcept = default; FlightDate(int year, int month, int dayOfMonth, int nofFlights) noexcept; - FlightDate(const FlightDate &other) = default; - FlightDate(FlightDate &&other) = default; - ~FlightDate() = default; - FlightDate &operator=(const FlightDate &rhs) = default; - FlightDate &operator=(FlightDate &&rhs) = default; /*! * The year of the flight: [1 - 9999] diff --git a/src/Model/include/Model/FlightPlan.h b/src/Model/include/Model/FlightPlan.h index 468f22bb1..8447919b6 100644 --- a/src/Model/include/Model/FlightPlan.h +++ b/src/Model/include/Model/FlightPlan.h @@ -30,21 +30,21 @@ #include #include -#include -#include - #include "Waypoint.h" #include "ModelLib.h" -class Waypoint; -class FlightPlanPrivate; +struct Waypoint; +struct FlightPlanPrivate; -class MODEL_API FlightPlan : public QObject +class MODEL_API FlightPlan final { - Q_OBJECT public: - explicit FlightPlan(QObject *parent = nullptr) noexcept; - ~FlightPlan() noexcept override; + FlightPlan() noexcept; + FlightPlan(const FlightPlan &rhs) = delete; + FlightPlan(FlightPlan &&rhs); + FlightPlan &operator=(const FlightPlan &rhs) = delete; + FlightPlan &operator=(FlightPlan &&rhs); + ~FlightPlan(); void add(const Waypoint &waypoint) noexcept; void update(int index, const Waypoint &waypoint) noexcept; @@ -52,24 +52,16 @@ class MODEL_API FlightPlan : public QObject void clear() noexcept; using Iterator = std::vector::iterator; - using BackInsertIterator = std::back_insert_iterator>; Iterator begin() noexcept; Iterator end() noexcept; const Iterator begin() const noexcept; const Iterator end() const noexcept; - BackInsertIterator backInsertIterator() noexcept; Waypoint &operator[](std::size_t index) noexcept; const Waypoint &operator[](std::size_t index) const noexcept; -signals: - void waypointAdded(const Waypoint &waypoint); - void waypointUpdated(int index, const Waypoint &waypoint); - void waypointsCleared(); - private: - Q_DISABLE_COPY(FlightPlan) std::unique_ptr d; }; diff --git a/src/Model/include/Model/FlightSummary.h b/src/Model/include/Model/FlightSummary.h index b3ef29dc9..933bb1607 100644 --- a/src/Model/include/Model/FlightSummary.h +++ b/src/Model/include/Model/FlightSummary.h @@ -25,26 +25,21 @@ #ifndef FLIGHTSUMMARY_H #define FLIGHTSUMMARY_H +#include "Kernel/Const.h" #include #include #include +#include #include "ModelLib.h" -struct MODEL_API FlightSummary +struct MODEL_API FlightSummary final { - FlightSummary() noexcept; - FlightSummary(const FlightSummary &other) = default; - FlightSummary(FlightSummary &&other) noexcept; - ~FlightSummary() noexcept; - FlightSummary &operator=(const FlightSummary &rhs) = default; - FlightSummary &operator=(FlightSummary &&rhs) noexcept; - - std::int64_t flightId; + std::int64_t flightId {Const::InvalidId}; QDateTime creationDate; QString aircraftType; - int aircraftCount; + std::size_t aircraftCount {0}; QDateTime startSimulationLocalTime; QDateTime startSimulationZuluTime; QDateTime endSimulationLocalTime; diff --git a/src/Model/include/Model/InitialPosition.h b/src/Model/include/Model/InitialPosition.h index aa6b44da5..790a5ab8f 100644 --- a/src/Model/include/Model/InitialPosition.h +++ b/src/Model/include/Model/InitialPosition.h @@ -37,25 +37,20 @@ struct AircraftInfo; -struct MODEL_API InitialPosition +struct MODEL_API InitialPosition final { - double latitude; - double longitude; - double altitude; - double pitch; - double bank; - double trueHeading; + double latitude {0.0}; + double longitude {0.0}; + double altitude {0.0}; + double pitch {0.0}; + double bank {0.0}; + double trueHeading {0.0}; // Indicated airspeed [knots] - int indicatedAirspeed; - bool onGround; + int indicatedAirspeed {InvalidIndicatedAirspeed}; + bool onGround {false}; explicit InitialPosition(double latitude = 0.0, double longitude = 0.0, double altitude = 0.0) noexcept; InitialPosition(const PositionData &positionData, const AircraftInfo &aircraftInfo) noexcept; - InitialPosition(const InitialPosition &other) = default; - InitialPosition(InitialPosition &&other) = default; - ~InitialPosition() = default; - InitialPosition &operator=(const InitialPosition &rhs) = default; - InitialPosition &operator=(InitialPosition &&rhs) = default; inline bool isNull() const noexcept { return (indicatedAirspeed == InvalidIndicatedAirspeed); @@ -73,7 +68,6 @@ struct MODEL_API InitialPosition onGround = false; } - static const InitialPosition NullData; static constexpr int InvalidIndicatedAirspeed = std::numeric_limits::min(); }; diff --git a/src/Model/include/Model/Light.h b/src/Model/include/Model/Light.h index 2ba28ee2c..161f4e0aa 100644 --- a/src/Model/include/Model/Light.h +++ b/src/Model/include/Model/Light.h @@ -30,20 +30,12 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API Light : public AbstractComponent +class MODEL_API Light final : public AbstractComponent { public: explicit Light(const AircraftInfo &aircraftInfo) noexcept; - Light(Light &other) = default; - Light(Light &&other) = default; - ~Light() noexcept override; - Light &operator=(const Light &rhs) = default; - Light &operator=(Light &&rhs) = default; - const LightData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; - -private: - LightData m_currentLightData; + LightData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; }; #endif // LIGHT_H diff --git a/src/Model/include/Model/LightData.h b/src/Model/include/Model/LightData.h index 5e49bc265..ae4472c2d 100644 --- a/src/Model/include/Model/LightData.h +++ b/src/Model/include/Model/LightData.h @@ -32,18 +32,9 @@ #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API LightData : public TimeVariableData +struct MODEL_API LightData final : public TimeVariableData { - SimType::LightStates lightStates; - - explicit LightData(SimType::LightStates lightStates = SimType::LightState::None) noexcept; - LightData(const LightData &other) = default; - LightData(LightData &&other) = default; - ~LightData() override = default; - LightData &operator=(const LightData &rhs) = default; - LightData &operator=(LightData &&rhs) = default; - - static const LightData NullData; + SimType::LightStates lightStates {SimType::LightState::None}; }; #endif // LIGHTDATA_H diff --git a/src/Model/include/Model/Location.h b/src/Model/include/Model/Location.h index 9dfc3017b..ba747632f 100644 --- a/src/Model/include/Model/Location.h +++ b/src/Model/include/Model/Location.h @@ -27,17 +27,18 @@ #include +#include #include "InitialPosition.h" #include "Data.h" #include "ModelLib.h" -struct MODEL_API Location : public Data +struct MODEL_API Location final : public Data { QString title; QString description; - std::int64_t typeId {InvalidId}; - std::int64_t categoryId {InvalidId}; - std::int64_t countryId {InvalidId}; + std::int64_t typeId {Const::InvalidId}; + std::int64_t categoryId {Const::InvalidId}; + std::int64_t countryId {Const::InvalidId}; /// \todo Use QFlags std::int64_t attributes {0}; QString identifier; @@ -52,11 +53,6 @@ struct MODEL_API Location : public Data explicit Location(double latitude = 0.0, double longitude = 0.0, double altitude = 0.0) noexcept; explicit Location(const InitialPosition &initialPosition) noexcept; - Location(Location &other) = default; - Location(Location &&other) = default; - ~Location() noexcept override = default; - Location &operator=(const Location &rhs) = default; - Location &operator=(Location &&rhs) = default; inline InitialPosition toInitialPosition() const noexcept { InitialPosition initialPosition {latitude, longitude, altitude}; diff --git a/src/Model/include/Model/Logbook.h b/src/Model/include/Model/Logbook.h index 1d1d19ca5..433737654 100644 --- a/src/Model/include/Model/Logbook.h +++ b/src/Model/include/Model/Logbook.h @@ -32,12 +32,17 @@ #include "Flight.h" #include "ModelLib.h" -class LogbookPrivate; +struct LogbookPrivate; -class MODEL_API Logbook : public QObject +class MODEL_API Logbook final : public QObject { Q_OBJECT public: + Logbook(const Logbook &rhs) = delete; + Logbook(Logbook &&rhs) = delete; + Logbook &operator=(const Logbook &rhs) = delete; + Logbook &operator=(Logbook &&rhs) = delete; + static Logbook &getInstance() noexcept; static void destroyInstance() noexcept; Flight &getCurrentFlight() const noexcept; @@ -45,14 +50,11 @@ class MODEL_API Logbook : public QObject signals: void flightTitleOrDescriptionChanged(std::int64_t id); -protected: - ~Logbook() noexcept override; - private: - Q_DISABLE_COPY(Logbook) - std::unique_ptr d; + const std::unique_ptr d; Logbook() noexcept; + ~Logbook() override; }; #endif // LOGBOOK_H diff --git a/src/Model/include/Model/Position.h b/src/Model/include/Model/Position.h index d56d0ed05..e500616a9 100644 --- a/src/Model/include/Model/Position.h +++ b/src/Model/include/Model/Position.h @@ -30,20 +30,12 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API Position : public AbstractComponent +class MODEL_API Position final : public AbstractComponent { public: explicit Position(const AircraftInfo &aircraftInfo) noexcept; - Position(Position &other) = default; - Position(Position &&other) = default; - ~Position() noexcept override; - Position &operator=(const Position &rhs) = default; - Position &operator=(Position &&rhs) = default; - const PositionData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; - -private: - PositionData m_currentPositionData; + PositionData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; }; #endif // POSITION_H diff --git a/src/Model/include/Model/PositionData.h b/src/Model/include/Model/PositionData.h index e57fb084b..95e357c04 100644 --- a/src/Model/include/Model/PositionData.h +++ b/src/Model/include/Model/PositionData.h @@ -31,35 +31,28 @@ #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API PositionData : public TimeVariableData +struct MODEL_API PositionData final : public TimeVariableData { // Position - double latitude; - double longitude; + double latitude {0.0}; + double longitude {0.0}; // GPS altitude - double altitude; + double altitude {0.0}; // Indicated pressure altitude (analytical purposes only) - double indicatedAltitude; - double pitch; - double bank; - double trueHeading; + double indicatedAltitude {0.0}; + double pitch {0.0}; + double bank {0.0}; + double trueHeading {0.0}; // Velocity - double velocityBodyX; - double velocityBodyY; - double velocityBodyZ; - double rotationVelocityBodyX; - double rotationVelocityBodyY; - double rotationVelocityBodyZ; + double velocityBodyX {0.0}; + double velocityBodyY {0.0}; + double velocityBodyZ {0.0}; + double rotationVelocityBodyX {0.0}; + double rotationVelocityBodyY {0.0}; + double rotationVelocityBodyZ {0.0}; explicit PositionData(double latitude = 0.0, double longitude = 0.0, double altitude = 0.0) noexcept; - PositionData(const PositionData &other) = default; - PositionData(PositionData &&other) = default; - ~PositionData() override = default; - PositionData &operator=(const PositionData &rhs) = default; - PositionData &operator=(PositionData &&rhs) = default; - - static const PositionData NullData; }; #endif // POSITIONDATA_H diff --git a/src/Model/include/Model/PrimaryFlightControl.h b/src/Model/include/Model/PrimaryFlightControl.h index 5a06e7d7b..5afbac972 100644 --- a/src/Model/include/Model/PrimaryFlightControl.h +++ b/src/Model/include/Model/PrimaryFlightControl.h @@ -30,20 +30,12 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API PrimaryFlightControl : public AbstractComponent +class MODEL_API PrimaryFlightControl final : public AbstractComponent { public: explicit PrimaryFlightControl(const AircraftInfo &aircraftInfo) noexcept; - PrimaryFlightControl(PrimaryFlightControl &other) = default; - PrimaryFlightControl(PrimaryFlightControl &&other) = default; - ~PrimaryFlightControl() noexcept override; - PrimaryFlightControl &operator=(const PrimaryFlightControl &rhs) = default; - PrimaryFlightControl &operator=(PrimaryFlightControl &&rhs) = default; - const PrimaryFlightControlData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; - -private: - PrimaryFlightControlData m_currentPrimaryFlightControlData; + PrimaryFlightControlData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; }; #endif // PRIMARYFLIGHTCONTROL_H diff --git a/src/Model/include/Model/PrimaryFlightControlData.h b/src/Model/include/Model/PrimaryFlightControlData.h index 669fdbabe..68759d5c9 100644 --- a/src/Model/include/Model/PrimaryFlightControlData.h +++ b/src/Model/include/Model/PrimaryFlightControlData.h @@ -30,24 +30,14 @@ #include #include -#include "SimType.h" #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API PrimaryFlightControlData : public TimeVariableData +struct MODEL_API PrimaryFlightControlData final : public TimeVariableData { - std::int16_t rudderPosition; - std::int16_t elevatorPosition; - std::int16_t aileronPosition; - - PrimaryFlightControlData() noexcept; - PrimaryFlightControlData(const PrimaryFlightControlData &other) = default; - PrimaryFlightControlData(PrimaryFlightControlData &&other) = default; - ~PrimaryFlightControlData() override = default; - PrimaryFlightControlData &operator=(const PrimaryFlightControlData &rhs) = default; - PrimaryFlightControlData &operator=(PrimaryFlightControlData &&rhs) = default; - - static const PrimaryFlightControlData NullData; + std::int16_t rudderPosition {0}; + std::int16_t elevatorPosition {0}; + std::int16_t aileronPosition {0}; }; #endif // PRIMARYFLIGHTCONTROLDATA_H diff --git a/src/Model/include/Model/SecondaryFlightControl.h b/src/Model/include/Model/SecondaryFlightControl.h index f2a5cd303..708893c8f 100644 --- a/src/Model/include/Model/SecondaryFlightControl.h +++ b/src/Model/include/Model/SecondaryFlightControl.h @@ -30,20 +30,14 @@ #include "AbstractComponent.h" #include "ModelLib.h" -class MODEL_API SecondaryFlightControl : public AbstractComponent +class MODEL_API SecondaryFlightControl final : public AbstractComponent { public: explicit SecondaryFlightControl(const AircraftInfo &aircraftInfo) noexcept; - SecondaryFlightControl(SecondaryFlightControl &other) = default; - SecondaryFlightControl(SecondaryFlightControl &&other) = default; - ~SecondaryFlightControl() noexcept override; - SecondaryFlightControl &operator=(const SecondaryFlightControl &rhs) = default; - SecondaryFlightControl &operator=(SecondaryFlightControl &&rhs) = default; - const SecondaryFlightControlData &interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + SecondaryFlightControlData interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - SecondaryFlightControlData m_currentSecondaryFlightControlData; SecondaryFlightControlData m_previousSecondaryFlightControlData; }; diff --git a/src/Model/include/Model/SecondaryFlightControlData.h b/src/Model/include/Model/SecondaryFlightControlData.h index 042716be8..4e2b663af 100644 --- a/src/Model/include/Model/SecondaryFlightControlData.h +++ b/src/Model/include/Model/SecondaryFlightControlData.h @@ -30,26 +30,18 @@ #include #include -#include "SimType.h" #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API SecondaryFlightControlData : public TimeVariableData +struct MODEL_API SecondaryFlightControlData final : public TimeVariableData { // Flaps & speed brakes - std::int16_t leadingEdgeFlapsLeftPosition; - std::int16_t leadingEdgeFlapsRightPosition; - std::int16_t trailingEdgeFlapsLeftPosition; - std::int16_t trailingEdgeFlapsRightPosition; - std::int16_t spoilersHandlePosition; - std::int8_t flapsHandleIndex; - - SecondaryFlightControlData() noexcept; - SecondaryFlightControlData(const SecondaryFlightControlData &other) = default; - SecondaryFlightControlData(SecondaryFlightControlData &&other) = default; - SecondaryFlightControlData &operator=(const SecondaryFlightControlData &) = default; - - static const SecondaryFlightControlData NullData; + std::int16_t leadingEdgeFlapsLeftPosition {0}; + std::int16_t leadingEdgeFlapsRightPosition {0}; + std::int16_t trailingEdgeFlapsLeftPosition {0}; + std::int16_t trailingEdgeFlapsRightPosition {0}; + std::int16_t spoilersHandlePosition {0}; + std::int8_t flapsHandleIndex {0}; }; #endif // SECONDARYFLIGHTCONTROLDATA_H diff --git a/src/Model/include/Model/SimVar.h b/src/Model/include/Model/SimVar.h index 320fceeae..decea7ef4 100644 --- a/src/Model/include/Model/SimVar.h +++ b/src/Model/include/Model/SimVar.h @@ -25,128 +25,126 @@ #ifndef SIMVAR_H #define SIMVAR_H -#include "ModelLib.h" - /*! * Constants related to simulation variable names. */ namespace SimVar { // Simulation variables (SimConnect) - constexpr char Latitude[] = "Plane Latitude"; - constexpr char Longitude[] = "Plane Longitude"; - constexpr char Altitude[] = "Plane Altitude"; - constexpr char IndicatedAltitude[] = "Indicated Altitude"; - constexpr char Pitch[] = "Plane Pitch Degrees"; - constexpr char Bank[] = "Plane Bank Degrees"; - constexpr char TrueHeading[] = "Plane Heading Degrees True"; - - constexpr char VelocityBodyX[] = "Velocity Body X"; - constexpr char VelocityBodyY[] = "Velocity Body Y"; - constexpr char VelocityBodyZ[] = "Velocity Body Z"; - constexpr char RotationVelocityBodyX[] = "Rotation Velocity Body X"; - constexpr char RotationVelocityBodyY[] = "Rotation Velocity Body Y"; - constexpr char RotationVelocityBodyZ[] = "Rotation Velocity Body Z"; - - constexpr char RudderPosition[] = "Rudder Position"; - constexpr char ElevatorPosition[] = "Elevator Position"; - constexpr char AileronPosition[] = "Aileron Position"; - - constexpr char ThrottleLeverPosition1[] = "General Eng Throttle Lever Position:1"; - constexpr char ThrottleLeverPosition2[] = "General Eng Throttle Lever Position:2"; - constexpr char ThrottleLeverPosition3[] = "General Eng Throttle Lever Position:3"; - constexpr char ThrottleLeverPosition4[] = "General Eng Throttle Lever Position:4"; - constexpr char PropellerLeverPosition1[] = "General Eng Propeller Lever Position:1"; - constexpr char PropellerLeverPosition2[] = "General Eng Propeller Lever Position:2"; - constexpr char PropellerLeverPosition3[] = "General Eng Propeller Lever Position:3"; - constexpr char PropellerLeverPosition4[] = "General Eng Propeller Lever Position:4"; - constexpr char MixtureLeverPosition1[] = "General Eng Mixture Lever Position:1"; - constexpr char MixtureLeverPosition2[] = "General Eng Mixture Lever Position:2"; - constexpr char MixtureLeverPosition3[] = "General Eng Mixture Lever Position:3"; - constexpr char MixtureLeverPosition4[] = "General Eng Mixture Lever Position:4"; - constexpr char RecipEngineCowlFlapPosition1[] = "Recip Eng Cowl Flap Position:1"; - constexpr char RecipEngineCowlFlapPosition2[] = "Recip Eng Cowl Flap Position:2"; - constexpr char RecipEngineCowlFlapPosition3[] = "Recip Eng Cowl Flap Position:3"; - constexpr char RecipEngineCowlFlapPosition4[] = "Recip Eng Cowl Flap Position:4"; - constexpr char ElectricalMasterBattery1[] = "Electrical Master Battery:1"; - constexpr char ElectricalMasterBattery2[] = "Electrical Master Battery:2"; - constexpr char ElectricalMasterBattery3[] = "Electrical Master Battery:3"; - constexpr char ElectricalMasterBattery4[] = "Electrical Master Battery:4"; - constexpr char GeneralEngineStarter1[] = "General Eng Starter:1"; - constexpr char GeneralEngineStarter2[] = "General Eng Starter:2"; - constexpr char GeneralEngineStarter3[] = "General Eng Starter:3"; - constexpr char GeneralEngineStarter4[] = "General Eng Starter:4"; - constexpr char GeneralEngineCombustion1[] = "General Eng Combustion:1"; - constexpr char GeneralEngineCombustion2[] = "General Eng Combustion:2"; - constexpr char GeneralEngineCombustion3[] = "General Eng Combustion:3"; - constexpr char GeneralEngineCombustion4[] = "General Eng Combustion:4"; - - constexpr char LeadingEdgeFlapsLeftPercent[] = "Leading Edge Flaps Left Percent"; - constexpr char LeadingEdgeFlapsRightPercent[] = "Leading Edge Flaps Right Percent"; - constexpr char TrailingEdgeFlapsLeftPercent[] = "Trailing Edge Flaps Left Percent"; - constexpr char TrailingEdgeFlapsRightPercent[] = "Trailing Edge Flaps Right Percent"; - constexpr char SpoilersHandlePosition[] = "Spoilers Handle Position"; - constexpr char FlapsHandleIndex[] = "Flaps Handle Index"; - - constexpr char BrakeLeftPosition[] = "Brake Left Position"; - constexpr char BrakeRightPosition[] = "Brake Right Position"; - constexpr char WaterRudderHandlePosition[] = "Water Rudder Handle Position"; - constexpr char TailhookPosition[] = "Tailhook Position"; - constexpr char CanopyOpen[] = "Canopy Open"; - constexpr char GearHandlePosition[] = "Gear Handle Position"; - constexpr char SmokeEnable[] = "Smoke Enable"; - constexpr char FoldingWingLeftPercent[] = "Folding Wing Left Percent"; - constexpr char FoldingWingRightPercent[] = "Folding Wing Right Percent"; - - constexpr char LightStates[] = "Light States"; - - constexpr char Title[] = "Title"; - constexpr char ATCId[] = "ATC Id"; - constexpr char ATCAirline[] = "ATC Airline"; - constexpr char ATCFlightNumber[] = "ATC Flight Number"; - constexpr char Category[] = "Category"; - - constexpr char SimOnGround[] = "Sim On Ground"; - constexpr char PlaneAltAboveGround[] = "Plane Alt Above Ground"; - constexpr char AirspeedTrue[] = "Airspeed True"; - constexpr char AirspeedIndicated[] = "Airspeed Indicated"; - constexpr char SurfaceType[] = "Surface Type"; - constexpr char WingSpan[] = "Wing Span"; - constexpr char NumberOfEngines[] = "Number Of Engines"; - constexpr char EngineType[] = "Engine Type"; - - constexpr char GroundAltitude[] = "Ground Altitude"; - constexpr char AmbientTemperature[] = "Ambient Temperature"; - constexpr char TotalAirTemperature[] = "Total Air Temperature"; - constexpr char AmbientWindVelocity[] = "Ambient Wind Velocity"; - constexpr char AmbientWindDirection[] = "Ambient Wind Direction"; - constexpr char AmbientPrecipState[] = "Ambient Precip State"; - constexpr char AmbientInCloud[] = "Ambient In Cloud"; - constexpr char AmbientVisibility[] = "Ambient Visibility"; - constexpr char SeaLevelPressure[] = "Sea Level Pressure"; - constexpr char PitotIcePct[] = "Pitot Ice Pct"; - constexpr char StructuralIcePct[] = "Structural Ice Pct"; - - constexpr char GpsWPNextId[] = "GPS WP Next Id"; - constexpr char GpsWPNextLat[] = "GPS WP Next Lat"; - constexpr char GpsWPNextLon[] = "GPS WP Next Lon"; - constexpr char GpsWPNextAlt[] = "GPS WP Next Alt"; - constexpr char GpsWPPrevId[] = "GPS WP Prev Id"; - constexpr char GpsWPPrevLat[] = "GPS WP Prev Lat"; - constexpr char GpsWPPrevLon[] = "GPS WP Prev Lon"; - constexpr char GpsWPPrevAlt[] = "GPS WP Prev Alt"; - - constexpr char LocalTime[] = "Local Time"; - constexpr char LocalYear[] = "Local Year"; - constexpr char LocalMonthOfYear[] = "Local Month of Year"; - constexpr char LocalDayOfMonth[] = "Local Day of Month"; - - constexpr char ZuluTime[] = "Zulu Time"; - constexpr char ZuluYear[] = "Zulu Year"; - constexpr char ZuluMonthOfYear[] = "Zulu Month of Year"; - constexpr char ZuluDayOfMonth[] = "Zulu Day of Month"; - - constexpr char Timestamp[] = "Timestamp"; + constexpr const char *Latitude = "Plane Latitude"; + constexpr const char *Longitude = "Plane Longitude"; + constexpr const char *Altitude = "Plane Altitude"; + constexpr const char *IndicatedAltitude = "Indicated Altitude"; + constexpr const char *Pitch = "Plane Pitch Degrees"; + constexpr const char *Bank = "Plane Bank Degrees"; + constexpr const char *TrueHeading = "Plane Heading Degrees True"; + + constexpr const char *VelocityBodyX = "Velocity Body X"; + constexpr const char *VelocityBodyY = "Velocity Body Y"; + constexpr const char *VelocityBodyZ = "Velocity Body Z"; + constexpr const char *RotationVelocityBodyX = "Rotation Velocity Body X"; + constexpr const char *RotationVelocityBodyY = "Rotation Velocity Body Y"; + constexpr const char *RotationVelocityBodyZ = "Rotation Velocity Body Z"; + + constexpr const char *RudderPosition = "Rudder Position"; + constexpr const char *ElevatorPosition = "Elevator Position"; + constexpr const char *AileronPosition = "Aileron Position"; + + constexpr const char *ThrottleLeverPosition1 = "General Eng Throttle Lever Position:1"; + constexpr const char *ThrottleLeverPosition2 = "General Eng Throttle Lever Position:2"; + constexpr const char *ThrottleLeverPosition3 = "General Eng Throttle Lever Position:3"; + constexpr const char *ThrottleLeverPosition4 = "General Eng Throttle Lever Position:4"; + constexpr const char *PropellerLeverPosition1 = "General Eng Propeller Lever Position:1"; + constexpr const char *PropellerLeverPosition2 = "General Eng Propeller Lever Position:2"; + constexpr const char *PropellerLeverPosition3 = "General Eng Propeller Lever Position:3"; + constexpr const char *PropellerLeverPosition4 = "General Eng Propeller Lever Position:4"; + constexpr const char *MixtureLeverPosition1 = "General Eng Mixture Lever Position:1"; + constexpr const char *MixtureLeverPosition2 = "General Eng Mixture Lever Position:2"; + constexpr const char *MixtureLeverPosition3 = "General Eng Mixture Lever Position:3"; + constexpr const char *MixtureLeverPosition4 = "General Eng Mixture Lever Position:4"; + constexpr const char *RecipEngineCowlFlapPosition1 = "Recip Eng Cowl Flap Position:1"; + constexpr const char *RecipEngineCowlFlapPosition2 = "Recip Eng Cowl Flap Position:2"; + constexpr const char *RecipEngineCowlFlapPosition3 = "Recip Eng Cowl Flap Position:3"; + constexpr const char *RecipEngineCowlFlapPosition4 = "Recip Eng Cowl Flap Position:4"; + constexpr const char *ElectricalMasterBattery1 = "Electrical Master Battery:1"; + constexpr const char *ElectricalMasterBattery2 = "Electrical Master Battery:2"; + constexpr const char *ElectricalMasterBattery3 = "Electrical Master Battery:3"; + constexpr const char *ElectricalMasterBattery4 = "Electrical Master Battery:4"; + constexpr const char *GeneralEngineStarter1 = "General Eng Starter:1"; + constexpr const char *GeneralEngineStarter2 = "General Eng Starter:2"; + constexpr const char *GeneralEngineStarter3 = "General Eng Starter:3"; + constexpr const char *GeneralEngineStarter4 = "General Eng Starter:4"; + constexpr const char *GeneralEngineCombustion1 = "General Eng Combustion:1"; + constexpr const char *GeneralEngineCombustion2 = "General Eng Combustion:2"; + constexpr const char *GeneralEngineCombustion3 = "General Eng Combustion:3"; + constexpr const char *GeneralEngineCombustion4 = "General Eng Combustion:4"; + + constexpr const char *LeadingEdgeFlapsLeftPercent = "Leading Edge Flaps Left Percent"; + constexpr const char *LeadingEdgeFlapsRightPercent = "Leading Edge Flaps Right Percent"; + constexpr const char *TrailingEdgeFlapsLeftPercent = "Trailing Edge Flaps Left Percent"; + constexpr const char *TrailingEdgeFlapsRightPercent = "Trailing Edge Flaps Right Percent"; + constexpr const char *SpoilersHandlePosition = "Spoilers Handle Position"; + constexpr const char *FlapsHandleIndex = "Flaps Handle Index"; + + constexpr const char *BrakeLeftPosition = "Brake Left Position"; + constexpr const char *BrakeRightPosition = "Brake Right Position"; + constexpr const char *WaterRudderHandlePosition = "Water Rudder Handle Position"; + constexpr const char *TailhookPosition = "Tailhook Position"; + constexpr const char *CanopyOpen = "Canopy Open"; + constexpr const char *GearHandlePosition = "Gear Handle Position"; + constexpr const char *SmokeEnable = "Smoke Enable"; + constexpr const char *FoldingWingLeftPercent = "Folding Wing Left Percent"; + constexpr const char *FoldingWingRightPercent = "Folding Wing Right Percent"; + + constexpr const char *LightStates = "Light States"; + + constexpr const char *Title = "Title"; + constexpr const char *ATCId = "ATC Id"; + constexpr const char *ATCAirline = "ATC Airline"; + constexpr const char *ATCFlightNumber = "ATC Flight Number"; + constexpr const char *Category = "Category"; + + constexpr const char *SimOnGround = "Sim On Ground"; + constexpr const char *PlaneAltAboveGround = "Plane Alt Above Ground"; + constexpr const char *AirspeedTrue = "Airspeed True"; + constexpr const char *AirspeedIndicated = "Airspeed Indicated"; + constexpr const char *SurfaceType = "Surface Type"; + constexpr const char *WingSpan = "Wing Span"; + constexpr const char *NumberOfEngines = "Number Of Engines"; + constexpr const char *EngineType = "Engine Type"; + + constexpr const char *GroundAltitude = "Ground Altitude"; + constexpr const char *AmbientTemperature = "Ambient Temperature"; + constexpr const char *TotalAirTemperature = "Total Air Temperature"; + constexpr const char *AmbientWindVelocity = "Ambient Wind Velocity"; + constexpr const char *AmbientWindDirection = "Ambient Wind Direction"; + constexpr const char *AmbientPrecipState = "Ambient Precip State"; + constexpr const char *AmbientInCloud = "Ambient In Cloud"; + constexpr const char *AmbientVisibility = "Ambient Visibility"; + constexpr const char *SeaLevelPressure = "Sea Level Pressure"; + constexpr const char *PitotIcePct = "Pitot Ice Pct"; + constexpr const char *StructuralIcePct = "Structural Ice Pct"; + + constexpr const char *GpsWPNextId = "GPS WP Next Id"; + constexpr const char *GpsWPNextLat = "GPS WP Next Lat"; + constexpr const char *GpsWPNextLon = "GPS WP Next Lon"; + constexpr const char *GpsWPNextAlt = "GPS WP Next Alt"; + constexpr const char *GpsWPPrevId = "GPS WP Prev Id"; + constexpr const char *GpsWPPrevLat = "GPS WP Prev Lat"; + constexpr const char *GpsWPPrevLon = "GPS WP Prev Lon"; + constexpr const char *GpsWPPrevAlt = "GPS WP Prev Alt"; + + constexpr const char *LocalTime = "Local Time"; + constexpr const char *LocalYear = "Local Year"; + constexpr const char *LocalMonthOfYear = "Local Month of Year"; + constexpr const char *LocalDayOfMonth = "Local Day of Month"; + + constexpr const char *ZuluTime = "Zulu Time"; + constexpr const char *ZuluYear = "Zulu Year"; + constexpr const char *ZuluMonthOfYear = "Zulu Month of Year"; + constexpr const char *ZuluDayOfMonth = "Zulu Day of Month"; + + constexpr const char *Timestamp = "Timestamp"; } #endif // SIMVAR_H diff --git a/src/Model/include/Model/SkySearch.h b/src/Model/include/Model/SkySearch.h index 7a08ebc1b..0c84d03f0 100644 --- a/src/Model/include/Model/SkySearch.h +++ b/src/Model/include/Model/SkySearch.h @@ -31,7 +31,6 @@ #include #include "TimeVariableData.h" -#include "PositionData.h" namespace SkySearch { @@ -81,7 +80,7 @@ namespace SkySearch { template int binaryIntervalSearch(const std::vector &data, std::int64_t timestamp, int lowIndex, int highIndex) noexcept { - int index; + int index {InvalidIndex}; if (data.size() == 0) { index = InvalidIndex; } else if (data.at(lowIndex).timestamp > timestamp) { @@ -93,8 +92,6 @@ namespace SkySearch { } else if (data.back().timestamp == timestamp) { index = data.size() - 1; } else { - - index = InvalidIndex; int low = lowIndex; int high = highIndex; while (low <= high) @@ -126,7 +123,7 @@ namespace SkySearch { template int linearIntervalSearch(const std::vector &data, std::int64_t timestamp, int startIndex) noexcept { - int index; + int index {startIndex}; if (data.size() == 0) { index = InvalidIndex; } else if (data.at(startIndex).timestamp > timestamp) { @@ -134,7 +131,6 @@ namespace SkySearch { } else if (data.back().timestamp < timestamp) { index = InvalidIndex; } else { - index = startIndex; int size = data.size(); // Linear search: increment the current index, until we find a position having a // timestamp > the given timestamp @@ -163,7 +159,7 @@ namespace SkySearch { template int updateStartIndex(const std::vector &data, int startIndex, std::int64_t timestamp) noexcept { - int index = startIndex; + int index {startIndex}; int size = data.size(); if (size > 0) { if (timestamp < data.back().timestamp) { @@ -201,8 +197,8 @@ namespace SkySearch { } else { // The given timestamp lies "in the past" and could really be anywwhere // -> binary search in the past - int low; - int high; + auto low {0}; + auto high {data.size() - 1}; if (startIndex != InvalidIndex) { if (timestamp < data.at(startIndex).timestamp) { // Search in "the past" @@ -213,10 +209,6 @@ namespace SkySearch { low = startIndex; high = data.size() - 1; } - } else { - // index not yet initialised -> search entire timeline - low = 0; - high = data.size() - 1; } index = binaryIntervalSearch(data, timestamp, low, high); } diff --git a/src/Model/include/Model/TimeVariableData.h b/src/Model/include/Model/TimeVariableData.h index 4de46d8b0..6e04da8a7 100644 --- a/src/Model/include/Model/TimeVariableData.h +++ b/src/Model/include/Model/TimeVariableData.h @@ -28,12 +28,16 @@ #include #include -#include "SimType.h" #include "ModelLib.h" struct MODEL_API TimeVariableData { - static constexpr std::int64_t InvalidTime = std::numeric_limits::min(); + TimeVariableData() = default; + TimeVariableData(const TimeVariableData &rhs) = default; + TimeVariableData(TimeVariableData &&rhs) = default; + TimeVariableData &operator=(const TimeVariableData &rhs) = default; + TimeVariableData &operator=(TimeVariableData &&rhs) = default; + virtual ~TimeVariableData() = default; /*! * Defines the way (use case) the sampled data is accessed. @@ -48,19 +52,28 @@ struct MODEL_API TimeVariableData }; // In milliseconds since the start of recording - std::int64_t timestamp; - - TimeVariableData() noexcept; - TimeVariableData(const TimeVariableData &other) = default; - TimeVariableData(TimeVariableData &&other) = default; - virtual ~TimeVariableData() noexcept; - TimeVariableData &operator=(const TimeVariableData &rhs) = default; - TimeVariableData &operator=(TimeVariableData &&rhs) = default; + std::int64_t timestamp {InvalidTime}; + /*! + * Returns whether this data is considered \enull data. + * + * \return \c true if this data is \enull (invalid) data; \c false else + * \sa reset + */ inline bool isNull() const noexcept { return (timestamp == InvalidTime); } + /*! + * Resets this data such that it is considered \e null data afterwards. + * + * \sa isNull + */ + inline void reset() noexcept + { + timestamp = InvalidTime; + } + friend inline bool operator==(const TimeVariableData &lhs, const TimeVariableData &rhs) noexcept { return lhs.timestamp == rhs.timestamp; @@ -75,6 +88,9 @@ struct MODEL_API TimeVariableData { return !(lhs >= rhs); } + + static constexpr std::int64_t InvalidTime = std::numeric_limits::min(); + }; #endif // TIMEVARIABLEDATA_H diff --git a/src/Model/include/Model/Waypoint.h b/src/Model/include/Model/Waypoint.h index e7ccc598c..7f7e2f48a 100644 --- a/src/Model/include/Model/Waypoint.h +++ b/src/Model/include/Model/Waypoint.h @@ -29,25 +29,19 @@ #include #include -#include "SimType.h" #include "TimeVariableData.h" #include "ModelLib.h" -struct MODEL_API Waypoint : public TimeVariableData +struct MODEL_API Waypoint final : public TimeVariableData { QString identifier; - float latitude; - float longitude; - float altitude; QDateTime localTime; QDateTime zuluTime; + float latitude {0.0}; + float longitude {0.0}; + float altitude {0.0}; explicit Waypoint(float latitude = 0.0f, float longitude = 0.0f, float altitude = 0.0f) noexcept; - Waypoint(const Waypoint &other) = default; - Waypoint(Waypoint &&other) noexcept; - ~Waypoint() override = default; - Waypoint &operator=(const Waypoint &rhs) = default; - Waypoint &operator=(Waypoint &&rhs) noexcept; /*! * Returns whether this waypoint is valid or not. @@ -56,11 +50,11 @@ struct MODEL_API Waypoint : public TimeVariableData */ bool isValid() const noexcept; - // Note: declaring the constants as "inline" (with initialisation in the header) - // apparently won't make them accessible from outside this library (DLL) + // Note: declaring the constant as "inline" (with initialisation in the header) + // apparently won't make the Waypoint accessible from outside this library (DLL) static const Waypoint NullWaypoint; - static const char CustomDepartureIdentifier[]; - static const char CustomArrivalIdentifier[]; + static constexpr const char *CustomDepartureIdentifier {"CUSTD"}; + static constexpr const char *CustomArrivalIdentifier {"CUSTA"}; }; #endif // WAYPOINT_H diff --git a/src/Model/src/Aircraft.cpp b/src/Model/src/Aircraft.cpp index f3c8c9d13..b33f09831 100644 --- a/src/Model/src/Aircraft.cpp +++ b/src/Model/src/Aircraft.cpp @@ -27,13 +27,8 @@ #include #include -#include -#ifdef DEBUG -#include -#endif - +#include #include "TimeVariableData.h" -#include "SkySearch.h" #include "AircraftInfo.h" #include "Position.h" #include "PositionData.h" @@ -50,17 +45,11 @@ #include "FlightPlan.h" #include "Aircraft.h" -class AircraftPrivate +struct AircraftPrivate { public: - AircraftPrivate() noexcept - : id(Aircraft::InvalidId), - aircraftInfo(id), - duration(TimeVariableData::InvalidTime) - {} - - std::int64_t id; - AircraftInfo aircraftInfo; + std::int64_t id {Const::InvalidId}; + AircraftInfo aircraftInfo {id}; Position position{aircraftInfo}; Engine engine{aircraftInfo}; PrimaryFlightControl primaryFlightControl{aircraftInfo}; @@ -69,27 +58,18 @@ class AircraftPrivate Light light{aircraftInfo}; FlightPlan flightPlan; - mutable std::int64_t duration; + mutable std::int64_t duration {TimeVariableData::InvalidTime}; }; // PUBLIC -Aircraft::Aircraft(QObject *parent) noexcept - : QObject(parent), - d(std::make_unique()) -{ - frenchConnection(); -#ifdef DEBUG - qDebug() << "Aircraft::Aircraft: CREATED, ID:" << d->id; -#endif -} +Aircraft::Aircraft() noexcept + : d(std::make_unique()) +{} -Aircraft::~Aircraft() noexcept -{ -#ifdef DEBUG - qDebug() << "Aircraft::~Aircraft: DELETED, ID:" << d->id; -#endif -} +Aircraft::Aircraft(Aircraft &&rhs) = default; +Aircraft &Aircraft::operator=(Aircraft &&rhs) = default; +Aircraft::~Aircraft() = default; std::int64_t Aircraft::getId() const noexcept { @@ -144,17 +124,11 @@ const AircraftInfo &Aircraft::getAircraftInfo() const noexcept void Aircraft::setAircraftInfo(const AircraftInfo &aircraftInfo) noexcept { - if (d->aircraftInfo != aircraftInfo) { - d->aircraftInfo = aircraftInfo; - emit infoChanged(*this); - } + d->aircraftInfo = aircraftInfo; } void Aircraft::setTailNumber(const QString &tailNumber) noexcept { - if (d->aircraftInfo.tailNumber != tailNumber) { - d->aircraftInfo.tailNumber = tailNumber; - emit tailNumberChanged(*this); - } + d->aircraftInfo.tailNumber = tailNumber; } std::int64_t Aircraft::getTimeOffset() const noexcept @@ -163,10 +137,8 @@ std::int64_t Aircraft::getTimeOffset() const noexcept } void Aircraft::setTimeOffset(std::int64_t timeOffset) noexcept { - if (d->aircraftInfo.timeOffset != timeOffset) { - d->aircraftInfo.timeOffset = timeOffset; - emit timeOffsetChanged(*this); - } + d->aircraftInfo.timeOffset = timeOffset; + invalidateDuration(); } std::int64_t Aircraft::getDurationMSec() const noexcept @@ -233,17 +205,3 @@ void Aircraft::invalidateDuration() noexcept { d->duration = TimeVariableData::InvalidTime; } - -// PRIVATE - -void Aircraft::frenchConnection() -{ - // Tail number - connect(this, &Aircraft::tailNumberChanged, - this, &Aircraft::infoChanged); - // Timestamp offset - connect(this, &Aircraft::timeOffsetChanged, - this, &Aircraft::invalidateDuration); - connect(this, &Aircraft::timeOffsetChanged, - this, &Aircraft::infoChanged); -} diff --git a/src/Model/src/AircraftHandle.cpp b/src/Model/src/AircraftHandle.cpp index db3ee0b2e..0680c627d 100644 --- a/src/Model/src/AircraftHandle.cpp +++ b/src/Model/src/AircraftHandle.cpp @@ -25,10 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif - #include #include #include "TimeVariableData.h" @@ -41,21 +37,11 @@ AircraftHandle::AircraftHandle(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "AircraftHandle::AircraftHandle: CREATED"; -#endif -} - -AircraftHandle::~AircraftHandle() noexcept -{ -#ifdef DEBUG - qDebug() << "AircraftHandle::AircraftHandle: DELETED"; -#endif -} +{} -const AircraftHandleData &AircraftHandle::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +AircraftHandleData AircraftHandle::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + AircraftHandleData aircraftHandleData; const AircraftHandleData *p1 {nullptr}, *p2 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -87,39 +73,36 @@ const AircraftHandleData &AircraftHandle::interpolate(std::int64_t timestamp, Ti } if (p1 != nullptr) { - m_currentAircraftHandleData.brakeLeftPosition = SkyMath::interpolateLinear(p1->brakeLeftPosition, p2->brakeLeftPosition, tn); - m_currentAircraftHandleData.brakeRightPosition = SkyMath::interpolateLinear(p1->brakeRightPosition, p2->brakeRightPosition, tn); - m_currentAircraftHandleData.waterRudderHandlePosition = SkyMath::interpolateLinear(p1->waterRudderHandlePosition, p2->waterRudderHandlePosition, tn); - m_currentAircraftHandleData.tailhookPosition = SkyMath::interpolateLinear(p1->tailhookPosition, p2->tailhookPosition, tn); - m_currentAircraftHandleData.canopyOpen = SkyMath::interpolateLinear(p1->canopyOpen, p2->canopyOpen, tn); - m_currentAircraftHandleData.leftWingFolding = SkyMath::interpolateLinear(p1->leftWingFolding, p2->leftWingFolding, tn); - m_currentAircraftHandleData.rightWingFolding = SkyMath::interpolateLinear(p1->rightWingFolding, p2->rightWingFolding, tn); - m_currentAircraftHandleData.gearHandlePosition = p1->gearHandlePosition; - m_currentAircraftHandleData.smokeEnabled = p1->smokeEnabled; - m_currentAircraftHandleData.timestamp = adjustedTimestamp; + aircraftHandleData.brakeLeftPosition = SkyMath::interpolateLinear(p1->brakeLeftPosition, p2->brakeLeftPosition, tn); + aircraftHandleData.brakeRightPosition = SkyMath::interpolateLinear(p1->brakeRightPosition, p2->brakeRightPosition, tn); + aircraftHandleData.waterRudderHandlePosition = SkyMath::interpolateLinear(p1->waterRudderHandlePosition, p2->waterRudderHandlePosition, tn); + aircraftHandleData.tailhookPosition = SkyMath::interpolateLinear(p1->tailhookPosition, p2->tailhookPosition, tn); + aircraftHandleData.canopyOpen = SkyMath::interpolateLinear(p1->canopyOpen, p2->canopyOpen, tn); + aircraftHandleData.leftWingFolding = SkyMath::interpolateLinear(p1->leftWingFolding, p2->leftWingFolding, tn); + aircraftHandleData.rightWingFolding = SkyMath::interpolateLinear(p1->rightWingFolding, p2->rightWingFolding, tn); + aircraftHandleData.gearHandlePosition = p1->gearHandlePosition; + aircraftHandleData.smokeEnabled = p1->smokeEnabled; + aircraftHandleData.timestamp = adjustedTimestamp; // Certain aircraft override the CANOPY OPEN, so values need to be repeatedly set if (Settings::getInstance().isRepeatCanopyOpenEnabled()) { // We do that my storing the previous values (when the canopy is "open")... - m_previousAircraftHandleData = m_currentAircraftHandleData; + m_previousAircraftHandleData = aircraftHandleData; } else { // "Repeat values" setting disabled - m_previousAircraftHandleData = AircraftHandleData::NullData; + m_previousAircraftHandleData = AircraftHandleData(); } } else if (!m_previousAircraftHandleData.isNull()) { // ... and send the previous values again - m_currentAircraftHandleData = m_previousAircraftHandleData; - m_currentAircraftHandleData.timestamp = adjustedTimestamp; - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentAircraftHandleData = AircraftHandleData::NullData; + aircraftHandleData = m_previousAircraftHandleData; + aircraftHandleData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentAircraftHandleData; + return aircraftHandleData; } template class AbstractComponent; diff --git a/src/Model/src/AircraftHandleData.cpp b/src/Model/src/AircraftHandleData.cpp deleted file mode 100644 index 2a2d51e34..000000000 --- a/src/Model/src/AircraftHandleData.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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 "TimeVariableData.h" -#include "AircraftHandleData.h" - -// PUBLIC - -AircraftHandleData::AircraftHandleData() noexcept - : TimeVariableData(), - brakeLeftPosition(0), - brakeRightPosition(0), - waterRudderHandlePosition(0), - tailhookPosition(0), - canopyOpen(0), - leftWingFolding(0), - rightWingFolding(0), - gearHandlePosition(false), - smokeEnabled(false) -{} - -const AircraftHandleData AircraftHandleData::NullData = AircraftHandleData(); diff --git a/src/Model/src/AircraftInfo.cpp b/src/Model/src/AircraftInfo.cpp index 4ad77c922..99eb2f9b0 100644 --- a/src/Model/src/AircraftInfo.cpp +++ b/src/Model/src/AircraftInfo.cpp @@ -27,47 +27,14 @@ #include -#include "AircraftType.h" #include "AircraftInfo.h" // PUBLIC AircraftInfo::AircraftInfo(std::int64_t theAircraftId) noexcept - : aircraftId(theAircraftId), - timeOffset(0), - altitudeAboveGround(0.0f), - startOnGround(false), - initialAirspeed(0) + : aircraftId(theAircraftId) {} -AircraftInfo::AircraftInfo(AircraftInfo &&other) noexcept - : aircraftId(other.aircraftId), - aircraftType(std::move(other.aircraftType)), - timeOffset(other.timeOffset), - tailNumber(std::move(other.tailNumber)), - airline(std::move(other.airline)), - flightNumber(std::move(other.flightNumber)), - altitudeAboveGround(other.altitudeAboveGround), - startOnGround(other.startOnGround), - initialAirspeed(other.initialAirspeed) -{} - -AircraftInfo &AircraftInfo::operator=(AircraftInfo &&rhs) noexcept -{ - if (this != &rhs) { - aircraftId = rhs.aircraftId; - aircraftType = std::move(rhs.aircraftType), - timeOffset = rhs.timeOffset, - tailNumber = std::move(rhs.tailNumber), - airline = std::move(rhs.airline), - flightNumber = std::move(rhs.flightNumber), - altitudeAboveGround = rhs.altitudeAboveGround, - startOnGround = rhs.startOnGround, - initialAirspeed = rhs.initialAirspeed; - } - return *this; -} - void AircraftInfo::clear() noexcept { *this = AircraftInfo(aircraftId); diff --git a/src/Model/src/AircraftType.cpp b/src/Model/src/AircraftType.cpp index e77c1ff28..69ba8fd7d 100644 --- a/src/Model/src/AircraftType.cpp +++ b/src/Model/src/AircraftType.cpp @@ -28,31 +28,9 @@ // PUBLIC -AircraftType::AircraftType() noexcept - : wingSpan(0), - engineType(SimType::EngineType::Unknown), - numberOfEngines(0) -{} - -AircraftType::AircraftType(AircraftType &&other) noexcept - : type(std::move(other.type)), - category(std::move(other.category)), - wingSpan(other.wingSpan), - engineType(other.engineType), - numberOfEngines(other.numberOfEngines) -{} - -AircraftType &AircraftType::operator=(AircraftType &&rhs) noexcept -{ - if (this != &rhs) { - type = std::move(rhs.type); - category = std::move(rhs.category); - wingSpan = rhs.wingSpan; - engineType = rhs.engineType; - numberOfEngines = rhs.numberOfEngines; - } - return *this; -} +AircraftType::AircraftType(QString type, QString category, int wingSpan, SimType::EngineType engineType, int numberOfEngines) noexcept + : type(type), category(category), wingSpan(wingSpan), engineType(engineType), numberOfEngines(numberOfEngines) +{}; void AircraftType::clear() noexcept { diff --git a/src/Model/src/Data.cpp b/src/Model/src/Data.cpp deleted file mode 100644 index 439728104..000000000 --- a/src/Model/src/Data.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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. - */ diff --git a/src/Model/src/Engine.cpp b/src/Model/src/Engine.cpp index d24296baa..c95224c82 100644 --- a/src/Model/src/Engine.cpp +++ b/src/Model/src/Engine.cpp @@ -25,10 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif - #include #include "TimeVariableData.h" #include "SkySearch.h" @@ -40,21 +36,11 @@ Engine::Engine(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "Engine::Engine: CREATED"; -#endif -} - -Engine::~Engine() noexcept -{ -#ifdef DEBUG - qDebug() << "Engine::Engine: DELETED"; -#endif -} +{} -const EngineData &Engine::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +EngineData Engine::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + EngineData engineData; const EngineData *p1 {nullptr}, *p2 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -86,48 +72,45 @@ const EngineData &Engine::interpolate(std::int64_t timestamp, TimeVariableData:: } if (p1 != nullptr) { - m_currentEngineData.throttleLeverPosition1 = SkyMath::interpolateLinear(p1->throttleLeverPosition1, p2->throttleLeverPosition1, tn); - m_currentEngineData.throttleLeverPosition2 = SkyMath::interpolateLinear(p1->throttleLeverPosition2, p2->throttleLeverPosition2, tn); - m_currentEngineData.throttleLeverPosition3 = SkyMath::interpolateLinear(p1->throttleLeverPosition3, p2->throttleLeverPosition3, tn); - m_currentEngineData.throttleLeverPosition4 = SkyMath::interpolateLinear(p1->throttleLeverPosition4, p2->throttleLeverPosition4, tn); - m_currentEngineData.propellerLeverPosition1 = SkyMath::interpolateLinear(p1->propellerLeverPosition1, p2->propellerLeverPosition1, tn); - m_currentEngineData.propellerLeverPosition2 = SkyMath::interpolateLinear(p1->propellerLeverPosition2, p2->propellerLeverPosition2, tn); - m_currentEngineData.propellerLeverPosition3 = SkyMath::interpolateLinear(p1->propellerLeverPosition3, p2->propellerLeverPosition3, tn); - m_currentEngineData.propellerLeverPosition4 = SkyMath::interpolateLinear(p1->propellerLeverPosition4, p2->propellerLeverPosition4, tn); - m_currentEngineData.mixtureLeverPosition1 = SkyMath::interpolateLinear(p1->mixtureLeverPosition1, p2->mixtureLeverPosition1, tn); - m_currentEngineData.mixtureLeverPosition2 = SkyMath::interpolateLinear(p1->mixtureLeverPosition2, p2->mixtureLeverPosition2, tn); - m_currentEngineData.mixtureLeverPosition3 = SkyMath::interpolateLinear(p1->mixtureLeverPosition3, p2->mixtureLeverPosition3, tn); - m_currentEngineData.mixtureLeverPosition4 = SkyMath::interpolateLinear(p1->mixtureLeverPosition4, p2->mixtureLeverPosition4, tn); - m_currentEngineData.cowlFlapPosition1 = SkyMath::interpolateLinear(p1->cowlFlapPosition1, p2->cowlFlapPosition1, tn); - m_currentEngineData.cowlFlapPosition2 = SkyMath::interpolateLinear(p1->cowlFlapPosition2, p2->cowlFlapPosition2, tn); - m_currentEngineData.cowlFlapPosition3 = SkyMath::interpolateLinear(p1->cowlFlapPosition3, p2->cowlFlapPosition3, tn); - m_currentEngineData.cowlFlapPosition4 = SkyMath::interpolateLinear(p1->cowlFlapPosition4, p2->cowlFlapPosition4, tn); + engineData.throttleLeverPosition1 = SkyMath::interpolateLinear(p1->throttleLeverPosition1, p2->throttleLeverPosition1, tn); + engineData.throttleLeverPosition2 = SkyMath::interpolateLinear(p1->throttleLeverPosition2, p2->throttleLeverPosition2, tn); + engineData.throttleLeverPosition3 = SkyMath::interpolateLinear(p1->throttleLeverPosition3, p2->throttleLeverPosition3, tn); + engineData.throttleLeverPosition4 = SkyMath::interpolateLinear(p1->throttleLeverPosition4, p2->throttleLeverPosition4, tn); + engineData.propellerLeverPosition1 = SkyMath::interpolateLinear(p1->propellerLeverPosition1, p2->propellerLeverPosition1, tn); + engineData.propellerLeverPosition2 = SkyMath::interpolateLinear(p1->propellerLeverPosition2, p2->propellerLeverPosition2, tn); + engineData.propellerLeverPosition3 = SkyMath::interpolateLinear(p1->propellerLeverPosition3, p2->propellerLeverPosition3, tn); + engineData.propellerLeverPosition4 = SkyMath::interpolateLinear(p1->propellerLeverPosition4, p2->propellerLeverPosition4, tn); + engineData.mixtureLeverPosition1 = SkyMath::interpolateLinear(p1->mixtureLeverPosition1, p2->mixtureLeverPosition1, tn); + engineData.mixtureLeverPosition2 = SkyMath::interpolateLinear(p1->mixtureLeverPosition2, p2->mixtureLeverPosition2, tn); + engineData.mixtureLeverPosition3 = SkyMath::interpolateLinear(p1->mixtureLeverPosition3, p2->mixtureLeverPosition3, tn); + engineData.mixtureLeverPosition4 = SkyMath::interpolateLinear(p1->mixtureLeverPosition4, p2->mixtureLeverPosition4, tn); + engineData.cowlFlapPosition1 = SkyMath::interpolateLinear(p1->cowlFlapPosition1, p2->cowlFlapPosition1, tn); + engineData.cowlFlapPosition2 = SkyMath::interpolateLinear(p1->cowlFlapPosition2, p2->cowlFlapPosition2, tn); + engineData.cowlFlapPosition3 = SkyMath::interpolateLinear(p1->cowlFlapPosition3, p2->cowlFlapPosition3, tn); + engineData.cowlFlapPosition4 = SkyMath::interpolateLinear(p1->cowlFlapPosition4, p2->cowlFlapPosition4, tn); // No interpolation for battery and starter/combustion states (boolean) - m_currentEngineData.electricalMasterBattery1 = p1->electricalMasterBattery1; - m_currentEngineData.electricalMasterBattery2 = p1->electricalMasterBattery2; - m_currentEngineData.electricalMasterBattery3 = p1->electricalMasterBattery3; - m_currentEngineData.electricalMasterBattery4 = p1->electricalMasterBattery4; - m_currentEngineData.generalEngineStarter1 = p1->generalEngineStarter1; - m_currentEngineData.generalEngineStarter2 = p1->generalEngineStarter2; - m_currentEngineData.generalEngineStarter3 = p1->generalEngineStarter3; - m_currentEngineData.generalEngineStarter4 = p1->generalEngineStarter4; - m_currentEngineData.generalEngineCombustion1 = p1->generalEngineCombustion1; - m_currentEngineData.generalEngineCombustion2 = p1->generalEngineCombustion2; - m_currentEngineData.generalEngineCombustion3 = p1->generalEngineCombustion3; - m_currentEngineData.generalEngineCombustion4 = p1->generalEngineCombustion4; + engineData.electricalMasterBattery1 = p1->electricalMasterBattery1; + engineData.electricalMasterBattery2 = p1->electricalMasterBattery2; + engineData.electricalMasterBattery3 = p1->electricalMasterBattery3; + engineData.electricalMasterBattery4 = p1->electricalMasterBattery4; + engineData.generalEngineStarter1 = p1->generalEngineStarter1; + engineData.generalEngineStarter2 = p1->generalEngineStarter2; + engineData.generalEngineStarter3 = p1->generalEngineStarter3; + engineData.generalEngineStarter4 = p1->generalEngineStarter4; + engineData.generalEngineCombustion1 = p1->generalEngineCombustion1; + engineData.generalEngineCombustion2 = p1->generalEngineCombustion2; + engineData.generalEngineCombustion3 = p1->generalEngineCombustion3; + engineData.generalEngineCombustion4 = p1->generalEngineCombustion4; - m_currentEngineData.timestamp = adjustedTimestamp; - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentEngineData = EngineData::NullData; + engineData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentEngineData; + return engineData; } -template class AbstractComponent; \ No newline at end of file +template class AbstractComponent; diff --git a/src/Model/src/EngineData.cpp b/src/Model/src/EngineData.cpp index a494e9c8a..98a5ba2a1 100644 --- a/src/Model/src/EngineData.cpp +++ b/src/Model/src/EngineData.cpp @@ -32,33 +32,7 @@ EngineData::EngineData(std::int16_t theThrottleLeverPosition1, std::int16_t thePropellerLeverPosition1, std::uint8_t theMixtureLeverPosition1, std::uint8_t theCowlFlapPosition1) noexcept : TimeVariableData(), throttleLeverPosition1(theThrottleLeverPosition1), - throttleLeverPosition2(0), - throttleLeverPosition3(0), - throttleLeverPosition4(0), propellerLeverPosition1(thePropellerLeverPosition1), - propellerLeverPosition2(0), - propellerLeverPosition3(0), - propellerLeverPosition4(0), mixtureLeverPosition1(theMixtureLeverPosition1), - mixtureLeverPosition2(0), - mixtureLeverPosition3(0), - mixtureLeverPosition4(0), - cowlFlapPosition1(theCowlFlapPosition1), - cowlFlapPosition2(0), - cowlFlapPosition3(0), - cowlFlapPosition4(0), - electricalMasterBattery1(false), - electricalMasterBattery2(false), - electricalMasterBattery3(false), - electricalMasterBattery4(false), - generalEngineStarter1(false), - generalEngineStarter2(false), - generalEngineStarter3(false), - generalEngineStarter4(false), - generalEngineCombustion1(false), - generalEngineCombustion2(false), - generalEngineCombustion3(false), - generalEngineCombustion4(false) + cowlFlapPosition1(theCowlFlapPosition1) {} - -const EngineData EngineData::NullData = EngineData(); diff --git a/src/Model/src/Enumeration.cpp b/src/Model/src/Enumeration.cpp index d88066ea7..e662e164f 100644 --- a/src/Model/src/Enumeration.cpp +++ b/src/Model/src/Enumeration.cpp @@ -27,15 +27,13 @@ #include #include -#ifdef DEBUG -#include -#endif +#include #include "Enumeration.h" struct EnumerationPrivate { - EnumerationPrivate(QString theName) noexcept + EnumerationPrivate(const QString &theName) noexcept : name(theName) {} @@ -49,20 +47,17 @@ struct EnumerationPrivate // PUBLIC -Enumeration::Enumeration(QString name) noexcept +Enumeration::Enumeration() noexcept + : d(std::make_unique(QString())) +{} + +Enumeration::Enumeration(const QString &name) noexcept : d(std::make_unique(name)) -{ -#ifdef DEBUG - qDebug() << "Enumeration::Enumeration: CREATED, name:" << d->name; -#endif -} +{} -Enumeration::~Enumeration() noexcept -{ -#ifdef DEBUG - qDebug() << "Enumeration::Enumeration: DELETED, name:" << d->name; -#endif -} +Enumeration::Enumeration(Enumeration &&rhs) = default; +Enumeration &Enumeration::operator=(Enumeration &&rhs) = default; +Enumeration::~Enumeration() = default; QString Enumeration::getName() const noexcept { diff --git a/src/Model/src/Flight.cpp b/src/Model/src/Flight.cpp index 16002fba9..12a676558 100644 --- a/src/Model/src/Flight.cpp +++ b/src/Model/src/Flight.cpp @@ -35,6 +35,7 @@ #include #endif +#include #include "FlightCondition.h" #include "Aircraft.h" #include "FlightPlan.h" @@ -49,16 +50,16 @@ struct FlightPrivate clear(true); } - std::int64_t id {Flight::InvalidId}; + std::int64_t id {Const::InvalidId}; QDateTime creationTime {QDateTime::currentDateTime()}; QString title; QString description; FlightCondition flightCondition; - std::vector> aircraft; + std::vector aircraft; int userAircraftIndex {Flight::InvalidAircraftIndex}; inline void clear(bool withOneAircraft) noexcept { - id = Flight::InvalidId; + id = Const::InvalidId; title.clear(); description.clear(); flightCondition.clear(); @@ -71,7 +72,7 @@ struct FlightPrivate // it is newly allocated (the aircraft is only added in the constructor body) // or cleared just before loading a flight if (aircraft.size() > 0) { - aircraft.at(0)->clear(); + aircraft.at(0).clear(); } } }; @@ -84,17 +85,9 @@ Flight::Flight(QObject *parent) noexcept { // A flight always has at least one (user) aircraft addUserAircraft(); -#ifdef DEBUG - qDebug() << "Flight::Flight: CREATED, ID:" << d->id; -#endif } -Flight::~Flight() noexcept -{ -#ifdef DEBUG - qDebug() << "Flight::~Flight: DELETED, ID:" << d->id; -#endif -} +Flight::~Flight() = default; void Flight::setId(std::int64_t id) noexcept { @@ -142,36 +135,32 @@ void Flight::setDescription(const QString &description) noexcept } } -void Flight::setAircraft(std::vector> aircraft) noexcept +void Flight::setAircraft(std::vector &&aircraft) noexcept { d->aircraft = std::move(aircraft); for (auto &aircraft : d->aircraft) { - emit aircraftAdded(*aircraft.get()); - connectWithAircraftSignals(*aircraft.get()); + emit aircraftAdded(aircraft); } } Aircraft &Flight::addUserAircraft() noexcept { - std::unique_ptr aircraft = std::make_unique(); - connectWithAircraftSignals(*aircraft.get()); - - d->aircraft.push_back(std::move(aircraft)); + d->aircraft.push_back(Aircraft()); switchUserAircraftIndex(static_cast(d->aircraft.size()) - 1); - emit aircraftAdded(*d->aircraft.back().get()); - return *d->aircraft.back().get(); + emit aircraftAdded(d->aircraft.back()); + return d->aircraft.back(); } Aircraft &Flight::getUserAircraft() const noexcept { - return *d->aircraft.at(d->userAircraftIndex); + return d->aircraft.at(d->userAircraftIndex); } int Flight::getAircraftIndex(const Aircraft &aircraft) const noexcept { - std::int64_t index {InvalidAircraftIndex}; + int index {InvalidAircraftIndex}; const auto it = std::find_if(d->aircraft.cbegin(), d->aircraft.cend(), - [&aircraft](const std::unique_ptr &a) { return a->getId() == aircraft.getId(); }); + [&aircraft](const Aircraft &a) { return a.getId() == aircraft.getId(); }); if (it != d->aircraft.cend()) { index = static_cast(std::distance(d->aircraft.cbegin(), it)); } @@ -202,10 +191,10 @@ void Flight::switchUserAircraftIndex(int index) noexcept std::int64_t Flight::deleteAircraftByIndex(int index) noexcept { - std::int64_t aircraftId {Aircraft::InvalidId}; + std::int64_t aircraftId {Const::InvalidId}; // A flight has at least one aircraft if (d->aircraft.size() > 1) { - aircraftId = d->aircraft.at(index)->getId(); + aircraftId = d->aircraft.at(index).getId(); if (index < d->userAircraftIndex) { // An aircraft with a lower index or the user aircraft index itself // is to be removed -> re-assign the user aircraft index accordingly @@ -226,6 +215,24 @@ std::size_t Flight::count() const noexcept return d->aircraft.size(); } +void Flight::addWaypoint(const Waypoint &waypoint) noexcept +{ + getUserAircraft().getFlightPlan().add(waypoint); + emit waypointAdded(waypoint); +} + +void Flight::updateWaypoint(int index, const Waypoint &waypoint) noexcept +{ + getUserAircraft().getFlightPlan().update(index, waypoint); + emit waypointUpdated(index, waypoint); +} + +void Flight::clearWaypoints() noexcept +{ + getUserAircraft().getFlightPlan().clear(); + emit waypointsCleared(); +} + const FlightCondition &Flight::getFlightCondition() const noexcept { return d->flightCondition; @@ -271,7 +278,7 @@ std::int64_t Flight::getTotalDurationMSec(bool ofUserAircraft) const noexcept totalDuractionMSec = getUserAircraft().getDurationMSec(); } else { for (const auto &aircraft : d->aircraft) { - totalDuractionMSec = std::max(aircraft->getDurationMSec(), totalDuractionMSec); + totalDuractionMSec = std::max(aircraft.getDurationMSec(), totalDuractionMSec); } } return totalDuractionMSec; @@ -300,6 +307,7 @@ void Flight::clear(bool withOneAircraft) noexcept // Only emit the signals if the flight has at least one aircraft // (but e.g. not shortly before loading a new flight from the logbook) emit cleared(); + emit waypointsCleared(); emit descriptionOrTitleChanged(); } } @@ -328,26 +336,16 @@ const Flight::Iterator Flight::end() const noexcept Aircraft &Flight::operator[](std::size_t index) noexcept { - return *d->aircraft[index]; + return d->aircraft[index]; } const Aircraft &Flight::operator[](std::size_t index) const noexcept { - return *d->aircraft[index]; + return d->aircraft[index]; } // PRIVATE -inline void Flight::connectWithAircraftSignals(Aircraft &aircraft) -{ - connect(&aircraft, &Aircraft::infoChanged, - this, &Flight::aircraftInfoChanged); - connect(&aircraft, &Aircraft::tailNumberChanged, - this, &Flight::tailNumberChanged); - connect(&aircraft, &Aircraft::timeOffsetChanged, - this, &Flight::timeOffsetChanged); -} - void Flight::reassignUserAircraftIndex(std::int64_t index) noexcept { d->userAircraftIndex = index; diff --git a/src/Model/src/FlightCondition.cpp b/src/Model/src/FlightCondition.cpp index 97176f9e2..3d603cd53 100644 --- a/src/Model/src/FlightCondition.cpp +++ b/src/Model/src/FlightCondition.cpp @@ -22,70 +22,10 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#include - -#include "SimType.h" #include "FlightCondition.h" // PUBLIC -FlightCondition::FlightCondition() noexcept - : groundAltitude{0.0f}, - surfaceType{SimType::SurfaceType::Unknown}, - ambientTemperature{0.0f}, - totalAirTemperature{0.0f}, - windSpeed{0.0f}, - windDirection{0.0f}, - precipitationState{SimType::PrecipitationState::None}, - visibility{0.0f}, - seaLevelPressure{0.0f}, - pitotIcingPercent{0}, - structuralIcingPercent{0}, - inClouds{false} -{} - -FlightCondition::FlightCondition(FlightCondition &&other) noexcept - : groundAltitude(other.groundAltitude), - surfaceType(other.surfaceType), - ambientTemperature(other.ambientTemperature), - totalAirTemperature(other.totalAirTemperature), - windSpeed(other.windSpeed), - windDirection(other.windDirection), - precipitationState(other.precipitationState), - visibility(other.visibility), - seaLevelPressure(other.seaLevelPressure), - pitotIcingPercent(other.pitotIcingPercent), - structuralIcingPercent(other.structuralIcingPercent), - inClouds(other.inClouds), - startLocalTime(std::move(other.startLocalTime)), - startZuluTime(std::move(other.startZuluTime)), - endLocalTime(std::move(other.endLocalTime)), - endZuluTime(std::move(other.endZuluTime)) -{} - -FlightCondition &FlightCondition::operator=(FlightCondition &&rhs) noexcept -{ - if (this != &rhs) { - groundAltitude = rhs.groundAltitude; - surfaceType = rhs.surfaceType; - ambientTemperature = rhs.ambientTemperature; - totalAirTemperature = rhs.totalAirTemperature; - windSpeed = rhs.windSpeed; - windDirection = rhs.windDirection; - precipitationState = rhs.precipitationState; - visibility = rhs.visibility; - seaLevelPressure = rhs.seaLevelPressure; - pitotIcingPercent = rhs.pitotIcingPercent; - structuralIcingPercent = rhs.structuralIcingPercent; - inClouds = rhs.inClouds; - startLocalTime = std::move(rhs.startLocalTime); - startZuluTime = std::move(rhs.startZuluTime); - endLocalTime = std::move(rhs.endLocalTime); - endZuluTime = std::move(rhs.endZuluTime); - } - return *this; -} - void FlightCondition::clear() noexcept { *this = FlightCondition(); diff --git a/src/Model/src/FlightPlan.cpp b/src/Model/src/FlightPlan.cpp index 11a2c4715..46013b1d8 100644 --- a/src/Model/src/FlightPlan.cpp +++ b/src/Model/src/FlightPlan.cpp @@ -32,29 +32,24 @@ #include "Waypoint.h" #include "FlightPlan.h" -class FlightPlanPrivate +struct FlightPlanPrivate { -public: - FlightPlanPrivate() noexcept - {} - std::vector waypoints; }; // PUBLIC -FlightPlan::FlightPlan(QObject *parent) noexcept - : QObject(parent), - d(std::make_unique()) +FlightPlan::FlightPlan() noexcept + : d(std::make_unique()) {} -FlightPlan::~FlightPlan() noexcept -{} +FlightPlan::FlightPlan(FlightPlan &&rhs) = default; +FlightPlan &FlightPlan::operator=(FlightPlan &&rhs) = default; +FlightPlan::~FlightPlan() = default; void FlightPlan::add(const Waypoint &waypoint) noexcept { d->waypoints.push_back(waypoint); - emit waypointAdded(waypoint); } void FlightPlan::update(int index, const Waypoint &waypoint) noexcept @@ -89,7 +84,6 @@ void FlightPlan::update(int index, const Waypoint &waypoint) noexcept } if (changed) { d->waypoints[index] = currentWaypoint; - emit waypointUpdated(index, currentWaypoint); } } @@ -101,7 +95,6 @@ std::size_t FlightPlan::count() const noexcept void FlightPlan::clear() noexcept { d->waypoints.clear(); - emit waypointsCleared(); } FlightPlan::Iterator FlightPlan::begin() noexcept @@ -124,11 +117,6 @@ const FlightPlan::Iterator FlightPlan::end() const noexcept return Iterator(d->waypoints.end()); } -FlightPlan::BackInsertIterator FlightPlan::backInsertIterator() noexcept -{ - return std::back_inserter(d->waypoints); -} - // OPERATORS Waypoint &FlightPlan::operator[](std::size_t index) noexcept diff --git a/src/Model/src/FlightSummary.cpp b/src/Model/src/FlightSummary.cpp deleted file mode 100644 index e471296b4..000000000 --- a/src/Model/src/FlightSummary.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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 "Flight.h" -#include "FlightSummary.h" - -// PUBLIC - -FlightSummary::FlightSummary() noexcept - : flightId(Flight::InvalidId), - aircraftCount(0) -{} - -FlightSummary::~FlightSummary() noexcept -{} - -FlightSummary::FlightSummary(FlightSummary &&other) noexcept - : flightId(other.flightId), - creationDate(std::move(other.creationDate)), - aircraftType(std::move(other.aircraftType)), - aircraftCount(other.aircraftCount), - startSimulationLocalTime(std::move(other.startSimulationLocalTime)), - startSimulationZuluTime(std::move(other.startSimulationZuluTime)), - endSimulationLocalTime(std::move(other.endSimulationLocalTime)), - endSimulationZuluTime(std::move(other.endSimulationZuluTime)), - startLocation(std::move(other.startLocation)), - endLocation(std::move(other.endLocation)), - title(std::move(other.title)) -{} - -FlightSummary &FlightSummary::operator=(FlightSummary &&rhs) noexcept -{ - if (this != &rhs) { - flightId = rhs.flightId; - creationDate = std::move(rhs.creationDate); - aircraftType = std::move(rhs.aircraftType); - aircraftCount = rhs.aircraftCount; - startSimulationLocalTime = std::move(rhs.startSimulationLocalTime); - startSimulationZuluTime = std::move(rhs.startSimulationZuluTime); - endSimulationLocalTime = std::move(rhs.endSimulationLocalTime); - endSimulationZuluTime = std::move(rhs.endSimulationZuluTime); - startLocation = std::move(rhs.startLocation); - endLocation = std::move(rhs.endLocation); - title = std::move(rhs.title); - } - return *this; -} diff --git a/src/Model/src/InitialPosition.cpp b/src/Model/src/InitialPosition.cpp index b67e9832d..ca2cb6bfb 100644 --- a/src/Model/src/InitialPosition.cpp +++ b/src/Model/src/InitialPosition.cpp @@ -31,12 +31,7 @@ InitialPosition::InitialPosition(double theLatitude, double theLongitude, double theAltitude) noexcept : latitude(theLatitude), longitude(theLongitude), - altitude(theAltitude), - pitch(0.0), - bank(0.0), - trueHeading(0.0), - indicatedAirspeed(InvalidIndicatedAirspeed), - onGround(false) + altitude(theAltitude) {} InitialPosition::InitialPosition(const PositionData &positionData, const AircraftInfo &aircraftInfo) noexcept @@ -44,5 +39,3 @@ InitialPosition::InitialPosition(const PositionData &positionData, const Aircraf fromPositionData(positionData); onGround = aircraftInfo.startOnGround; } - -const InitialPosition InitialPosition::NullData = InitialPosition(0.0, 0.0, 0.0); diff --git a/src/Model/src/Light.cpp b/src/Model/src/Light.cpp index ecf67b7c1..d7016a6ef 100644 --- a/src/Model/src/Light.cpp +++ b/src/Model/src/Light.cpp @@ -25,10 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif - #include #include "TimeVariableData.h" #include "SkySearch.h" @@ -41,21 +37,11 @@ Light::Light(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "Light::Light: CREATED"; -#endif -} - -Light::~Light() noexcept -{ -#ifdef DEBUG - qDebug() << "Light::Light: DELETED"; -#endif -} +{} -const LightData &Light::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +LightData Light::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + LightData lightData; const LightData *p1 {nullptr}, *p2 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -84,18 +70,15 @@ const LightData &Light::interpolate(std::int64_t timestamp, TimeVariableData::Ac if (p1 != nullptr) { // No interpolation for light states - m_currentLightData.lightStates = p1->lightStates; - m_currentLightData.timestamp = adjustedTimestamp; - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentLightData = LightData::NullData; + lightData.lightStates = p1->lightStates; + lightData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentLightData; + return lightData; } -template class AbstractComponent; \ No newline at end of file +template class AbstractComponent; diff --git a/src/Model/src/LightData.cpp b/src/Model/src/LightData.cpp deleted file mode 100644 index 50041f2d3..000000000 --- a/src/Model/src/LightData.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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 "LightData.h" - -// PUBLIC - -LightData::LightData(SimType::LightStates theLightStates) noexcept - : TimeVariableData(), - lightStates(theLightStates) -{} - -const LightData LightData::NullData = LightData(); diff --git a/src/Model/src/Logbook.cpp b/src/Model/src/Logbook.cpp index 17a67a8e4..8a4f0aaa0 100644 --- a/src/Model/src/Logbook.cpp +++ b/src/Model/src/Logbook.cpp @@ -24,14 +24,17 @@ */ #include #include +#include #include +#ifdef DEBUG +#include +#endif #include "Logbook.h" -class LogbookPrivate +struct LogbookPrivate { -public: LogbookPrivate() noexcept {} @@ -40,18 +43,18 @@ class LogbookPrivate std::vector> flights; - static Logbook *instance; + static inline std::once_flag onceFlag; + static inline Logbook *instance; }; -Logbook *LogbookPrivate::instance = nullptr; // PUBLIC Logbook &Logbook::getInstance() noexcept { - if (LogbookPrivate::instance == nullptr) { + std::call_once(LogbookPrivate::onceFlag, []() { LogbookPrivate::instance = new Logbook(); - } + }); return *LogbookPrivate::instance; } @@ -68,15 +71,6 @@ Flight &Logbook::getCurrentFlight() const noexcept return *(*d->flights.cbegin()); } -// PROTECTED - -Logbook::~Logbook() noexcept -{ -#ifdef DEBUG - qDebug("Logbook::~Logbook: DELETED"); -#endif -} - // PRIVATE Logbook::Logbook() noexcept @@ -84,10 +78,16 @@ Logbook::Logbook() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("Logbook::Logbook: CREATED"); + qDebug() << "Logbook::Logbook: CREATED"; #endif // Logbook may support several flights, but for now there will be always // exactly one - std::unique_ptr defaultFlight = std::make_unique(); - d->flights.push_back(std::move(defaultFlight)); + d->flights.push_back(std::make_unique()); +} + +Logbook::~Logbook() +{ +#ifdef DEBUG + qDebug() << "Logbook::~Logbook: DELETED"; +#endif } diff --git a/src/Model/src/Position.cpp b/src/Model/src/Position.cpp index a9353c20d..95024d1f2 100644 --- a/src/Model/src/Position.cpp +++ b/src/Model/src/Position.cpp @@ -45,21 +45,11 @@ namespace Position::Position(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "Position::Position: CREATED"; -#endif -} +{} -Position::~Position() noexcept -{ -#ifdef DEBUG - qDebug() << "Position::Position: DELETED"; -#endif -} - -const PositionData &Position::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +PositionData Position::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + PositionData positionData; const PositionData *p0 {nullptr}, *p1 {nullptr}, *p2 {nullptr}, *p3 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -87,41 +77,37 @@ const PositionData &Position::interpolate(std::int64_t timestamp, TimeVariableDa // Aircraft position & attitude // Latitude: [-90, 90] - no discontinuity at +/- 90 - m_currentPositionData.latitude = SkyMath::interpolateHermite(p0->latitude, p1->latitude, p2->latitude, p3->latitude, tn); + positionData.latitude = SkyMath::interpolateHermite(p0->latitude, p1->latitude, p2->latitude, p3->latitude, tn); // Longitude: [-180, 180] - discontinuity at the +/- 180 meridian - m_currentPositionData.longitude = SkyMath::interpolateHermite180(p0->longitude, p1->longitude, p2->longitude, p3->longitude, tn); + positionData.longitude = SkyMath::interpolateHermite180(p0->longitude, p1->longitude, p2->longitude, p3->longitude, tn); // Altitude [open range] - m_currentPositionData.altitude = SkyMath::interpolateHermite(p0->altitude, p1->altitude, p2->altitude, p3->altitude, tn); + positionData.altitude = SkyMath::interpolateHermite(p0->altitude, p1->altitude, p2->altitude, p3->altitude, tn); // The indicated altitude is not used for replay - only for display and analytical purposes, // so linear interpolation is sufficient - m_currentPositionData.indicatedAltitude = SkyMath::interpolateLinear(p1->indicatedAltitude, p2->indicatedAltitude, tn); + positionData.indicatedAltitude = SkyMath::interpolateLinear(p1->indicatedAltitude, p2->indicatedAltitude, tn); // Pitch: [-90, 90] - no discontinuity at +/- 90 - m_currentPositionData.pitch = SkyMath::interpolateHermite(p0->pitch, p1->pitch, p2->pitch, p3->pitch, tn, ::Tension); + positionData.pitch = SkyMath::interpolateHermite(p0->pitch, p1->pitch, p2->pitch, p3->pitch, tn, ::Tension); // Bank: [-180, 180] - discontinuity at +/- 180 - m_currentPositionData.bank = SkyMath::interpolateHermite180(p0->bank, p1->bank, p2->bank, p3->bank, tn, ::Tension); + positionData.bank = SkyMath::interpolateHermite180(p0->bank, p1->bank, p2->bank, p3->bank, tn, ::Tension); // Heading: [0, 360] - discontinuity at 0/360 - m_currentPositionData.trueHeading = SkyMath::interpolateHermite360(p0->trueHeading, p1->trueHeading, p2->trueHeading, p3->trueHeading, tn, ::Tension); + positionData.trueHeading = SkyMath::interpolateHermite360(p0->trueHeading, p1->trueHeading, p2->trueHeading, p3->trueHeading, tn, ::Tension); // Velocity - m_currentPositionData.velocityBodyX = SkyMath::interpolateLinear(p1->velocityBodyX, p2->velocityBodyX, tn); - m_currentPositionData.velocityBodyY = SkyMath::interpolateLinear(p1->velocityBodyY, p2->velocityBodyY, tn); - m_currentPositionData.velocityBodyZ = SkyMath::interpolateLinear(p1->velocityBodyZ, p2->velocityBodyZ, tn); - m_currentPositionData.rotationVelocityBodyX = SkyMath::interpolateLinear(p1->rotationVelocityBodyX, p2->rotationVelocityBodyX, tn); - m_currentPositionData.rotationVelocityBodyY = SkyMath::interpolateLinear(p1->rotationVelocityBodyY, p2->rotationVelocityBodyY, tn); - m_currentPositionData.rotationVelocityBodyZ = SkyMath::interpolateLinear(p1->rotationVelocityBodyZ, p2->rotationVelocityBodyZ, tn); - - m_currentPositionData.timestamp = adjustedTimestamp; - - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentPositionData = PositionData::NullData; + positionData.velocityBodyX = SkyMath::interpolateLinear(p1->velocityBodyX, p2->velocityBodyX, tn); + positionData.velocityBodyY = SkyMath::interpolateLinear(p1->velocityBodyY, p2->velocityBodyY, tn); + positionData.velocityBodyZ = SkyMath::interpolateLinear(p1->velocityBodyZ, p2->velocityBodyZ, tn); + positionData.rotationVelocityBodyX = SkyMath::interpolateLinear(p1->rotationVelocityBodyX, p2->rotationVelocityBodyX, tn); + positionData.rotationVelocityBodyY = SkyMath::interpolateLinear(p1->rotationVelocityBodyY, p2->rotationVelocityBodyY, tn); + positionData.rotationVelocityBodyZ = SkyMath::interpolateLinear(p1->rotationVelocityBodyZ, p2->rotationVelocityBodyZ, tn); + + positionData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentPositionData; + return positionData; } template class AbstractComponent; diff --git a/src/Model/src/PositionData.cpp b/src/Model/src/PositionData.cpp index 6a4582d8e..b38ec001b 100644 --- a/src/Model/src/PositionData.cpp +++ b/src/Model/src/PositionData.cpp @@ -34,16 +34,5 @@ PositionData::PositionData(double theLatitude, double theLongitude, double theAl latitude(theLatitude), longitude(theLongitude), altitude(theAltitdue), - indicatedAltitude(theAltitdue), - pitch(0.0), - bank(0.0), - trueHeading(0.0), - velocityBodyX(0.0), - velocityBodyY(0.0), - velocityBodyZ(0.0), - rotationVelocityBodyX(0.0), - rotationVelocityBodyY(0.0), - rotationVelocityBodyZ(0.0) + indicatedAltitude(theAltitdue) {} - -const PositionData PositionData::NullData = PositionData(0.0, 0.0, 0.0); diff --git a/src/Model/src/PrimaryFlightControl.cpp b/src/Model/src/PrimaryFlightControl.cpp index 8e22311e4..66d4e48a5 100644 --- a/src/Model/src/PrimaryFlightControl.cpp +++ b/src/Model/src/PrimaryFlightControl.cpp @@ -25,10 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif - #include #include "TimeVariableData.h" #include "SkySearch.h" @@ -36,30 +32,16 @@ #include "PrimaryFlightControlData.h" #include "PrimaryFlightControl.h" -namespace -{ - constexpr double Tension = 0.0; -} // PUBLIC PrimaryFlightControl::PrimaryFlightControl(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "PrimaryFlightControl::PrimaryFlightControl: CREATED"; -#endif -} - -PrimaryFlightControl::~PrimaryFlightControl() noexcept -{ -#ifdef DEBUG - qDebug() << "PrimaryFlightControl::PrimaryFlightControl: DELETED"; -#endif -} +{} -const PrimaryFlightControlData &PrimaryFlightControl::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +PrimaryFlightControlData PrimaryFlightControl::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + PrimaryFlightControlData primaryFlightControlData; const PrimaryFlightControlData *p1 {nullptr}, *p2 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -91,20 +73,17 @@ const PrimaryFlightControlData &PrimaryFlightControl::interpolate(std::int64_t t } if (p1 != nullptr) { - m_currentPrimaryFlightControlData.rudderPosition = SkyMath::interpolateLinear(p1->rudderPosition, p2->rudderPosition, tn); - m_currentPrimaryFlightControlData.elevatorPosition = SkyMath::interpolateLinear(p1->elevatorPosition, p2->elevatorPosition, tn); - m_currentPrimaryFlightControlData.aileronPosition = SkyMath::interpolateLinear(p1->aileronPosition, p2->aileronPosition, tn); - m_currentPrimaryFlightControlData.timestamp = adjustedTimestamp; - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentPrimaryFlightControlData = PrimaryFlightControlData::NullData; + primaryFlightControlData.rudderPosition = SkyMath::interpolateLinear(p1->rudderPosition, p2->rudderPosition, tn); + primaryFlightControlData.elevatorPosition = SkyMath::interpolateLinear(p1->elevatorPosition, p2->elevatorPosition, tn); + primaryFlightControlData.aileronPosition = SkyMath::interpolateLinear(p1->aileronPosition, p2->aileronPosition, tn); + primaryFlightControlData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentPrimaryFlightControlData; + return primaryFlightControlData; } template class AbstractComponent; diff --git a/src/Model/src/PrimaryFlightControlData.cpp b/src/Model/src/PrimaryFlightControlData.cpp deleted file mode 100644 index 3197aad87..000000000 --- a/src/Model/src/PrimaryFlightControlData.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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 "PrimaryFlightControlData.h" - -// PUBLIC - -PrimaryFlightControlData::PrimaryFlightControlData() noexcept - : TimeVariableData(), - rudderPosition(0), - elevatorPosition(0), - aileronPosition(0) -{} - -const PrimaryFlightControlData PrimaryFlightControlData::NullData = PrimaryFlightControlData(); diff --git a/src/Model/src/SecondaryFlightControl.cpp b/src/Model/src/SecondaryFlightControl.cpp index d8f328708..c5e1193df 100644 --- a/src/Model/src/SecondaryFlightControl.cpp +++ b/src/Model/src/SecondaryFlightControl.cpp @@ -25,10 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif - #include #include #include "TimeVariableData.h" @@ -37,30 +33,15 @@ #include "SecondaryFlightControlData.h" #include "SecondaryFlightControl.h" -namespace -{ - constexpr double Tension = 0.0; -} - // PUBLIC SecondaryFlightControl::SecondaryFlightControl(const AircraftInfo &aircraftInfo) noexcept : AbstractComponent(aircraftInfo) -{ -#ifdef DEBUG - qDebug() << "SecondaryFlightControl::SecondaryFlightControl: CREATED"; -#endif -} - -SecondaryFlightControl::~SecondaryFlightControl() noexcept -{ -#ifdef DEBUG - qDebug() << "SecondaryFlightControl::SecondaryFlightControl: DELETED"; -#endif -} +{} -const SecondaryFlightControlData &SecondaryFlightControl::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept +SecondaryFlightControlData SecondaryFlightControl::interpolate(std::int64_t timestamp, TimeVariableData::Access access) noexcept { + SecondaryFlightControlData secondaryFlightControlData; const SecondaryFlightControlData *p1 {nullptr}, *p2 {nullptr}; const std::int64_t timeOffset = access != TimeVariableData::Access::Export ? getAircraftInfo().timeOffset : 0; const std::int64_t adjustedTimestamp = std::max(timestamp + timeOffset, std::int64_t(0)); @@ -92,38 +73,35 @@ const SecondaryFlightControlData &SecondaryFlightControl::interpolate(std::int64 } if (p1 != nullptr) { - m_currentSecondaryFlightControlData.leadingEdgeFlapsLeftPosition = SkyMath::interpolateLinear(p1->leadingEdgeFlapsLeftPosition, p2->leadingEdgeFlapsLeftPosition, tn); - m_currentSecondaryFlightControlData.leadingEdgeFlapsRightPosition = SkyMath::interpolateLinear(p1->leadingEdgeFlapsRightPosition, p2->leadingEdgeFlapsRightPosition, tn); - m_currentSecondaryFlightControlData.trailingEdgeFlapsLeftPosition = SkyMath::interpolateLinear(p1->trailingEdgeFlapsLeftPosition, p2->trailingEdgeFlapsLeftPosition, tn); - m_currentSecondaryFlightControlData.trailingEdgeFlapsRightPosition = SkyMath::interpolateLinear(p1->trailingEdgeFlapsRightPosition, p2->trailingEdgeFlapsRightPosition, tn); - m_currentSecondaryFlightControlData.spoilersHandlePosition = SkyMath::interpolateLinear(p1->spoilersHandlePosition, p2->spoilersHandlePosition, tn); + secondaryFlightControlData.leadingEdgeFlapsLeftPosition = SkyMath::interpolateLinear(p1->leadingEdgeFlapsLeftPosition, p2->leadingEdgeFlapsLeftPosition, tn); + secondaryFlightControlData.leadingEdgeFlapsRightPosition = SkyMath::interpolateLinear(p1->leadingEdgeFlapsRightPosition, p2->leadingEdgeFlapsRightPosition, tn); + secondaryFlightControlData.trailingEdgeFlapsLeftPosition = SkyMath::interpolateLinear(p1->trailingEdgeFlapsLeftPosition, p2->trailingEdgeFlapsLeftPosition, tn); + secondaryFlightControlData.trailingEdgeFlapsRightPosition = SkyMath::interpolateLinear(p1->trailingEdgeFlapsRightPosition, p2->trailingEdgeFlapsRightPosition, tn); + secondaryFlightControlData.spoilersHandlePosition = SkyMath::interpolateLinear(p1->spoilersHandlePosition, p2->spoilersHandlePosition, tn); // No interpolation for flaps handle position - m_currentSecondaryFlightControlData.flapsHandleIndex = p1->flapsHandleIndex; + secondaryFlightControlData.flapsHandleIndex = p1->flapsHandleIndex; // Certain aircraft automatically override the FLAPS HANDLE INDEX, so values need to be repeatedly set if (Settings::getInstance().isRepeatFlapsHandleIndexEnabled()) { // We do that my storing the previous values (when the flaps are set)... - m_previousSecondaryFlightControlData = m_currentSecondaryFlightControlData; + m_previousSecondaryFlightControlData = secondaryFlightControlData; } else { // "Repeat values" setting disabled - m_previousSecondaryFlightControlData = SecondaryFlightControlData::NullData; + m_previousSecondaryFlightControlData = SecondaryFlightControlData(); } - m_currentSecondaryFlightControlData.timestamp = adjustedTimestamp; + secondaryFlightControlData.timestamp = adjustedTimestamp; } else if (!m_previousSecondaryFlightControlData.isNull()) { // ... and send the previous values again (for as long as the flaps are extracted) - m_currentSecondaryFlightControlData = m_previousSecondaryFlightControlData; - m_currentSecondaryFlightControlData.timestamp = adjustedTimestamp; - } else { - // No recorded data, or the timestamp exceeds the timestamp of the last recorded position - m_currentSecondaryFlightControlData = SecondaryFlightControlData::NullData; + secondaryFlightControlData = m_previousSecondaryFlightControlData; + secondaryFlightControlData.timestamp = adjustedTimestamp; } setCurrentIndex(currentIndex); setCurrentTimestamp(adjustedTimestamp); setCurrentAccess(access); } - return m_currentSecondaryFlightControlData; + return secondaryFlightControlData; } template class AbstractComponent; diff --git a/src/Model/src/SecondaryFlightControlData.cpp b/src/Model/src/SecondaryFlightControlData.cpp deleted file mode 100644 index 9440a8e83..000000000 --- a/src/Model/src/SecondaryFlightControlData.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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 "SecondaryFlightControlData.h" - -// PUBLIC - -SecondaryFlightControlData::SecondaryFlightControlData() noexcept - : TimeVariableData(), - leadingEdgeFlapsLeftPosition(0), - leadingEdgeFlapsRightPosition(0), - trailingEdgeFlapsLeftPosition(0), - trailingEdgeFlapsRightPosition(0), - spoilersHandlePosition(0), - flapsHandleIndex(0) -{} - -const SecondaryFlightControlData SecondaryFlightControlData::NullData = SecondaryFlightControlData(); diff --git a/src/Model/src/TimeVariableData.cpp b/src/Model/src/TimeVariableData.cpp deleted file mode 100644 index 3500beb4e..000000000 --- a/src/Model/src/TimeVariableData.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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 "TimeVariableData.h" - -// PUBLIC - -TimeVariableData::TimeVariableData() noexcept - : timestamp(InvalidTime) -{} - -TimeVariableData::~TimeVariableData() noexcept -{} diff --git a/src/Model/src/Waypoint.cpp b/src/Model/src/Waypoint.cpp index 04f16a84f..0b270a4a6 100644 --- a/src/Model/src/Waypoint.cpp +++ b/src/Model/src/Waypoint.cpp @@ -24,7 +24,6 @@ */ #include -#include "LightData.h" #include "Waypoint.h" // PUBLIC @@ -36,35 +35,9 @@ Waypoint::Waypoint(float theLatitude, float theLongitude, float theAltitude) noe altitude(theAltitude) {} -Waypoint::Waypoint(Waypoint &&other) noexcept - : TimeVariableData(std::move(other)), - identifier(std::move(other.identifier)), - latitude(other.latitude), - longitude(other.longitude), - altitude(other.altitude), - localTime(std::move(other.localTime)), - zuluTime(std::move(other.zuluTime)) -{} - -Waypoint &Waypoint::operator=(Waypoint &&rhs) noexcept -{ - if (this != &rhs) { - TimeVariableData::operator=(rhs); - identifier = std::move(rhs.identifier); - latitude = rhs.latitude; - longitude = rhs.longitude; - altitude = rhs.altitude; - localTime = std::move(rhs.localTime); - zuluTime = std::move(rhs.zuluTime); - } - return *this; -} - bool Waypoint::isValid() const noexcept { return !identifier.isEmpty(); } const Waypoint Waypoint::NullWaypoint = Waypoint(); -const char Waypoint::CustomDepartureIdentifier[] = "CUSTD"; -const char Waypoint::CustomArrivalIdentifier[] = "CUSTA"; diff --git a/src/Persistence/CMakeLists.txt b/src/Persistence/CMakeLists.txt index f766a5e6a..12e4852f2 100644 --- a/src/Persistence/CMakeLists.txt +++ b/src/Persistence/CMakeLists.txt @@ -14,9 +14,9 @@ target_compile_definitions(${LIBRARY_NAME} target_sources(${LIBRARY_NAME} PRIVATE include/Persistence/PersistenceLib.h - include/Persistence/LogbookManager.h src/LogbookManager.cpp - include/Persistence/FlightSelector.h src/FlightSelector.cpp - include/Persistence/LocationSelector.h src/LocationSelector.cpp + include/Persistence/PersistenceManager.h src/PersistenceManager.cpp + include/Persistence/FlightSelector.h + include/Persistence/LocationSelector.h include/Persistence/Metadata.h include/Persistence/PersistedEnumerationItem.h src/PersistedEnumerationItem.cpp src/Dao/DatabaseDaoIntf.h diff --git a/src/Persistence/include/Persistence/FlightSelector.h b/src/Persistence/include/Persistence/FlightSelector.h index c95cccc6b..38fe0b93c 100644 --- a/src/Persistence/include/Persistence/FlightSelector.h +++ b/src/Persistence/include/Persistence/FlightSelector.h @@ -34,14 +34,12 @@ struct PERSISTENCE_API FlightSelector { public: - FlightSelector(); - - QDate fromDate; - QDate toDate; + QDate fromDate {MinDate}; + QDate toDate {MaxDate}; QString searchKeyword; - bool hasFormation; - SimType::EngineType engineType; - int mininumDurationMinutes; + bool hasFormation {false}; + SimType::EngineType engineType {SimType::EngineType::All}; + int mininumDurationMinutes {0}; // The release date of MSFS ;) static inline const QDate MinDate {2020, 8, 18}; diff --git a/src/Persistence/include/Persistence/LocationSelector.h b/src/Persistence/include/Persistence/LocationSelector.h index 6653a91d3..6c47f0de5 100644 --- a/src/Persistence/include/Persistence/LocationSelector.h +++ b/src/Persistence/include/Persistence/LocationSelector.h @@ -35,7 +35,6 @@ struct PERSISTENCE_API LocationSelector { public: - LocationSelector(); }; #endif // LOCATIONSELECTOR_H diff --git a/src/Persistence/include/Persistence/PersistedEnumerationItem.h b/src/Persistence/include/Persistence/PersistedEnumerationItem.h index 55032e75c..5c9071c1c 100644 --- a/src/Persistence/include/Persistence/PersistedEnumerationItem.h +++ b/src/Persistence/include/Persistence/PersistedEnumerationItem.h @@ -39,7 +39,12 @@ class PERSISTENCE_API PersistedEnumerationItem { public: PersistedEnumerationItem(QString enumerationName, QString symbolicId) noexcept; - ~PersistedEnumerationItem() noexcept; + PersistedEnumerationItem() = default; + PersistedEnumerationItem(const PersistedEnumerationItem &rhs) = delete; + PersistedEnumerationItem(PersistedEnumerationItem &&rhs); + PersistedEnumerationItem &operator=(const PersistedEnumerationItem &rhs) = delete; + PersistedEnumerationItem &operator=(PersistedEnumerationItem &&rhs); + ~PersistedEnumerationItem(); std::int64_t id() const noexcept; diff --git a/src/Persistence/include/Persistence/LogbookManager.h b/src/Persistence/include/Persistence/PersistenceManager.h similarity index 72% rename from src/Persistence/include/Persistence/LogbookManager.h rename to src/Persistence/include/Persistence/PersistenceManager.h index 8e08a8ade..39181fe32 100644 --- a/src/Persistence/include/Persistence/LogbookManager.h +++ b/src/Persistence/include/Persistence/PersistenceManager.h @@ -22,10 +22,11 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#ifndef LOGBOOKMANAGER_H -#define LOGBOOKMANAGER_H +#ifndef PERSISTENCEMANAGER_H +#define PERSISTENCEMANAGER_H #include +#include #include @@ -39,13 +40,18 @@ class Version; class Metadata; class Version; -class LogbookManagerPrivate; +struct PersistenceManagerPrivate; -class PERSISTENCE_API LogbookManager : public QObject +class PERSISTENCE_API PersistenceManager final : public QObject { Q_OBJECT public: - static LogbookManager &getInstance() noexcept; + PersistenceManager(const PersistenceManager &rhs) = delete; + PersistenceManager(PersistenceManager &&rhs) = delete; + PersistenceManager &operator=(const PersistenceManager &rhs) = delete; + PersistenceManager &operator=(PersistenceManager &&rhs) = delete; + + static PersistenceManager &getInstance() noexcept; static void destroyInstance() noexcept; /*! @@ -57,12 +63,12 @@ class PERSISTENCE_API LogbookManager : public QObject * paths (or to quit the application altogether). * * The actual logbook path (which is usually the given \c logbookPath) - * is stored in the Settings. + * is stored in the PersistenceManager. * * \param logbookPath * the path of the logbook (database) file to connect with * \return \c true if the connection succeeded; \c false else - * \sa Settings#setLogbookPath + * \sa PersistenceManager#setLogbookPath * \sa connectionChanged */ bool connectWithLogbook(const QString &logbookPath, QWidget *parent) noexcept; @@ -75,9 +81,9 @@ class PERSISTENCE_API LogbookManager : public QObject bool optimise() noexcept; bool backup(const QString &backupLogbookPath) noexcept; - bool getMetadata(Metadata &metadata) const noexcept; - bool getDatabaseVersion(Version &databaseVersion) const noexcept; - bool getBackupDirectoryPath(QString &backupDirectoryPath) const noexcept; + Metadata getMetadata(bool *ok = nullptr) const noexcept; + Version getDatabaseVersion(bool *ok = nullptr) const noexcept; + QString getBackupDirectoryPath(bool *ok = nullptr) const noexcept; QString getBackupFileName(const QString &backupDirectoryPath) const noexcept; static QString createBackupPathIfNotExists(const QString &relativeOrAbsoluteBackupDirectoryPath) noexcept; @@ -85,17 +91,14 @@ class PERSISTENCE_API LogbookManager : public QObject signals: void connectionChanged(bool connected); -protected: - ~LogbookManager() noexcept override; - private: - Q_DISABLE_COPY(LogbookManager) - std::unique_ptr d; + const std::unique_ptr d; - LogbookManager() noexcept; + PersistenceManager() noexcept; + ~PersistenceManager() override; bool connectDb(const QString &logbookPath) noexcept; - bool checkDatabaseVersion(Version &databaseVersion) const noexcept; + std::pair checkDatabaseVersion() const noexcept; }; -#endif // LOGBOOKMANAGER_H +#endif // PERSISTENCEMANAGER_H diff --git a/src/Persistence/include/Persistence/Service/AircraftService.h b/src/Persistence/include/Persistence/Service/AircraftService.h index 5e9b6243e..2f823de14 100644 --- a/src/Persistence/include/Persistence/Service/AircraftService.h +++ b/src/Persistence/include/Persistence/Service/AircraftService.h @@ -34,17 +34,21 @@ #include #include "../PersistenceLib.h" -class AircraftServicePrivate; +struct AircraftServicePrivate; class PERSISTENCE_API AircraftService { public: AircraftService() noexcept; - ~AircraftService() noexcept; + AircraftService(const AircraftService &rhs) = delete; + AircraftService(AircraftService &&rhs); + AircraftService &operator=(const AircraftService &rhs) = delete; + AircraftService &operator=(AircraftService &&rhs); + ~AircraftService(); bool store(std::int64_t flightId, std::size_t sequenceNumber, Aircraft &aircraft) noexcept; bool deleteByIndex(int index) noexcept; - bool getAircraftInfos(std::int64_t flightId, std::vector &aircraftInfos) const noexcept; + std::vector getAircraftInfos(std::int64_t flightId, bool *ok = nullptr) const noexcept; bool changeTimeOffset(Aircraft &aircraft, std::int64_t newOffset) noexcept; bool changeTailNumber(Aircraft &aircraft, const QString &tailNumber) noexcept; diff --git a/src/Persistence/include/Persistence/Service/AircraftTypeService.h b/src/Persistence/include/Persistence/Service/AircraftTypeService.h index 0e67b0391..687d0332b 100644 --- a/src/Persistence/include/Persistence/Service/AircraftTypeService.h +++ b/src/Persistence/include/Persistence/Service/AircraftTypeService.h @@ -28,24 +28,26 @@ #include #include -#include - class QString; #include #include #include "../PersistenceLib.h" -class AircraftTypeServicePrivate; +struct AircraftTypeServicePrivate; class PERSISTENCE_API AircraftTypeService { public: AircraftTypeService() noexcept; - ~AircraftTypeService() noexcept; - - bool getByType(const QString &type, AircraftType &aircraftType) const noexcept; - bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept; + AircraftTypeService(const AircraftTypeService &rhs) = delete; + AircraftTypeService(AircraftTypeService &&rhs); + AircraftTypeService &operator=(const AircraftTypeService &rhs) = delete; + AircraftTypeService &operator=(AircraftTypeService &&rhs); + ~AircraftTypeService(); + + AircraftType getByType(const QString &type, bool *ok = nullptr) const noexcept; + std::vector getAll(bool *ok = nullptr) const noexcept; bool exists(const QString &type) const noexcept; private: diff --git a/src/Persistence/include/Persistence/Service/DatabaseService.h b/src/Persistence/include/Persistence/Service/DatabaseService.h index 82b171d8e..85c490505 100644 --- a/src/Persistence/include/Persistence/Service/DatabaseService.h +++ b/src/Persistence/include/Persistence/Service/DatabaseService.h @@ -33,17 +33,20 @@ class QString; class QWidget; class QDateTime; -#include "../Metadata.h" #include "../PersistenceLib.h" class Version; -class DatabaseServicePrivate; +struct DatabaseServicePrivate; class PERSISTENCE_API DatabaseService { public: DatabaseService() noexcept; - ~DatabaseService() noexcept; + DatabaseService(const DatabaseService &rhs) = delete; + DatabaseService(DatabaseService &&rhs); + DatabaseService &operator=(const DatabaseService &rhs) = delete; + DatabaseService &operator=(DatabaseService &&rhs); + ~DatabaseService(); bool backup() noexcept; diff --git a/src/Persistence/include/Persistence/Service/EnumerationService.h b/src/Persistence/include/Persistence/Service/EnumerationService.h index a23888ee5..a24943bc3 100644 --- a/src/Persistence/include/Persistence/Service/EnumerationService.h +++ b/src/Persistence/include/Persistence/Service/EnumerationService.h @@ -38,16 +38,22 @@ class PERSISTENCE_API EnumerationService { public: EnumerationService() noexcept; - ~EnumerationService() noexcept; + EnumerationService(const EnumerationService &rhs) = delete; + EnumerationService(EnumerationService &&rhs); + EnumerationService &operator=(const EnumerationService &rhs) = delete; + EnumerationService &operator=(EnumerationService &&rhs); + ~EnumerationService(); /*! - * Gets the persisted Enumeration by its \c enumeration.name. + * Gets the persisted Enumeration by its enumeration \c name. * - * \param enumeration - * the persisted Enumeration to get, identified by its \c name member - * \return \c true if successful; \c false else (unknown Enumeration name, no database connection) + * \param name + * the name of the enumeration + * \param ok + * if set, \c true if successful; \c false else (unknown Enumeration name, no database connection) + * \return the persisted Enumeration to get, identified by the \c name */ - bool getEnumerationByName(Enumeration &enumeration); + Enumeration getEnumerationByName(const QString &name, bool *ok = nullptr); // Implementation note: // Well-known database enumerations: TitleCase name must match with corresponding diff --git a/src/Persistence/include/Persistence/Service/FlightService.h b/src/Persistence/include/Persistence/Service/FlightService.h index 505283a6b..597d8a346 100644 --- a/src/Persistence/include/Persistence/Service/FlightService.h +++ b/src/Persistence/include/Persistence/Service/FlightService.h @@ -35,13 +35,17 @@ #include "../PersistenceLib.h" class SkyConnectIntf; -class FlightServicePrivate; +struct FlightServicePrivate; class PERSISTENCE_API FlightService { public: FlightService() noexcept; - ~FlightService() noexcept; + FlightService(const FlightService &rhs) = delete; + FlightService(FlightService &&rhs); + FlightService &operator=(const FlightService &rhs) = delete; + FlightService &operator=(FlightService &&rhs); + ~FlightService(); bool store(Flight &flight) noexcept; bool restore(std::int64_t id, Flight &flight) noexcept; diff --git a/src/Persistence/include/Persistence/Service/LocationService.h b/src/Persistence/include/Persistence/Service/LocationService.h index 86963777b..4c9e251ac 100644 --- a/src/Persistence/include/Persistence/Service/LocationService.h +++ b/src/Persistence/include/Persistence/Service/LocationService.h @@ -26,7 +26,7 @@ #define LOCATIONSERVICE_H #include -#include +#include #include #include @@ -34,19 +34,23 @@ #include "../PersistenceLib.h" struct LocationSelector; -class LocationServicePrivate; +struct LocationServicePrivate; class PERSISTENCE_API LocationService { public: LocationService() noexcept; - ~LocationService() noexcept; + LocationService(const LocationService &rhs) = delete; + LocationService(LocationService &&rhs); + LocationService &operator=(const LocationService &rhs) = delete; + LocationService &operator=(LocationService &&rhs); + ~LocationService(); bool store(Location &location) noexcept; bool update(const Location &location) noexcept; bool deleteById(std::int64_t id) noexcept; - bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept; - bool getSelectedLocations(const LocationSelector &locationSelector, std::back_insert_iterator> backInsertIterator) const noexcept; + std::vector getAll(bool *ok = nullptr) const noexcept; + std::vector getSelectedLocations(const LocationSelector &locationSelector, bool *ok = nullptr) const noexcept; private: std::unique_ptr d; diff --git a/src/Persistence/include/Persistence/Service/LogbookService.h b/src/Persistence/include/Persistence/Service/LogbookService.h index 08c3e9719..5ca81f407 100644 --- a/src/Persistence/include/Persistence/Service/LogbookService.h +++ b/src/Persistence/include/Persistence/Service/LogbookService.h @@ -35,13 +35,17 @@ #include "../PersistenceLib.h" class FlightSelector; -class LogbookServicePrivate; +struct LogbookServicePrivate; class PERSISTENCE_API LogbookService { public: LogbookService() noexcept; - ~LogbookService() noexcept; + LogbookService(const LogbookService &rhs) = delete; + LogbookService(LogbookService &&rhs); + LogbookService &operator=(const LogbookService &rhs) = delete; + LogbookService &operator=(LogbookService &&rhs); + ~LogbookService(); bool getFlightDates(std::front_insert_iterator> frontInsertIterator) const noexcept; std::vector getFlightSummaries(const FlightSelector &flightSelector) const noexcept; diff --git a/src/Persistence/src/Dao/AircraftDaoIntf.h b/src/Persistence/src/Dao/AircraftDaoIntf.h index 7710e1420..cd7c4660f 100644 --- a/src/Persistence/src/Dao/AircraftDaoIntf.h +++ b/src/Persistence/src/Dao/AircraftDaoIntf.h @@ -27,18 +27,22 @@ #include #include -#include #include #include class QString; class Aircraft; -class AircraftInfo; +struct AircraftInfo; class AircraftDaoIntf { public: + AircraftDaoIntf() = default; + AircraftDaoIntf(const AircraftDaoIntf &rhs) = delete; + AircraftDaoIntf(AircraftDaoIntf &&rhs) = default; + AircraftDaoIntf &operator=(const AircraftDaoIntf &rhs) = delete; + AircraftDaoIntf &operator=(AircraftDaoIntf &&rhs) = default; virtual ~AircraftDaoIntf() = default; /*! @@ -53,11 +57,11 @@ class AircraftDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t flightId, std::size_t sequenceNumber, Aircraft &aircraft) noexcept = 0; - virtual bool getByFlightId(std::int64_t flightId, std::back_insert_iterator>> backInsertIterator) const noexcept = 0; + virtual std::vector getByFlightId(std::int64_t flightId, bool *ok = nullptr) const noexcept = 0; virtual bool adjustAircraftSequenceNumbersByFlightId(std::int64_t id, std::size_t sequenceNumber) noexcept = 0; virtual bool deleteAllByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteById(std::int64_t id) noexcept = 0; - virtual bool getAircraftInfosByFlightId(std::int64_t flightId, std::vector &aircraftInfos) const noexcept = 0; + virtual std::vector getAircraftInfosByFlightId(std::int64_t flightId, bool *ok = nullptr) const noexcept = 0; virtual bool updateTimeOffset(std::int64_t id, std::int64_t timeOffset) noexcept = 0; virtual bool updateTailNumber(std::int64_t id, const QString &tailNumber) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/AircraftTypeDaoIntf.h b/src/Persistence/src/Dao/AircraftTypeDaoIntf.h index fe9c0ad02..4efa9cccb 100644 --- a/src/Persistence/src/Dao/AircraftTypeDaoIntf.h +++ b/src/Persistence/src/Dao/AircraftTypeDaoIntf.h @@ -27,9 +27,6 @@ #include #include -#include - -#include class QString; @@ -38,11 +35,16 @@ struct AircraftType; class AircraftTypeDaoIntf { public: + AircraftTypeDaoIntf() = default; + AircraftTypeDaoIntf(const AircraftTypeDaoIntf &rhs) = delete; + AircraftTypeDaoIntf(AircraftTypeDaoIntf &&rhs) = default; + AircraftTypeDaoIntf &operator=(const AircraftTypeDaoIntf &rhs) = delete; + AircraftTypeDaoIntf &operator=(AircraftTypeDaoIntf &&rhs) = default; virtual ~AircraftTypeDaoIntf() = default; virtual bool upsert(const AircraftType &aircraftType) noexcept = 0; - virtual bool getByType(const QString &type, AircraftType &aircraftType) const noexcept = 0; - virtual bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual AircraftType getByType(const QString &type, bool *ok = nullptr) const noexcept = 0; + virtual std::vector getAll(bool *ok = nullptr) const noexcept = 0; virtual bool exists(const QString &type) const noexcept = 0; }; diff --git a/src/Persistence/src/Dao/DaoFactory.cpp b/src/Persistence/src/Dao/DaoFactory.cpp index 053bccc99..e93df6986 100644 --- a/src/Persistence/src/Dao/DaoFactory.cpp +++ b/src/Persistence/src/Dao/DaoFactory.cpp @@ -52,9 +52,8 @@ #include "EnumerationDaoIntf.h" #include "DaoFactory.h" -class DaoFactoryPrivate +struct DaoFactoryPrivate { -public: DaoFactoryPrivate(DaoFactory::DbType theDbType) : dbType(theDbType) {} @@ -68,8 +67,9 @@ DaoFactory::DaoFactory(DbType dbType) : d(std::make_unique(dbType)) {} -DaoFactory::~DaoFactory() -{} +DaoFactory::DaoFactory(DaoFactory &&rhs) = default; +DaoFactory &DaoFactory::operator=(DaoFactory &&rhs) = default; +DaoFactory::~DaoFactory() = default; std::unique_ptr DaoFactory::createDatabaseDao() noexcept { diff --git a/src/Persistence/src/Dao/DaoFactory.h b/src/Persistence/src/Dao/DaoFactory.h index 6ddd25196..33f07f0de 100644 --- a/src/Persistence/src/Dao/DaoFactory.h +++ b/src/Persistence/src/Dao/DaoFactory.h @@ -42,7 +42,7 @@ class DatabaseDaoIntf; class LocationDaoIntf; class EnumerationDaoIntf; -class DaoFactoryPrivate; +struct DaoFactoryPrivate; class DaoFactory { @@ -54,7 +54,12 @@ class DaoFactory }; DaoFactory(DbType dbType); - ~DaoFactory(); + DaoFactory() = default; + DaoFactory(const DaoFactory &rhs) = delete; + DaoFactory(DaoFactory &&rhs); + DaoFactory &operator=(const DaoFactory &rhs) = delete; + DaoFactory &operator=(DaoFactory &&rhs); + virtual ~DaoFactory(); std::unique_ptr createDatabaseDao() noexcept; std::unique_ptr createLogbookDao() noexcept; diff --git a/src/Persistence/src/Dao/DatabaseDaoIntf.h b/src/Persistence/src/Dao/DatabaseDaoIntf.h index adcadcabb..3d5f4ed8e 100644 --- a/src/Persistence/src/Dao/DatabaseDaoIntf.h +++ b/src/Persistence/src/Dao/DatabaseDaoIntf.h @@ -25,14 +25,21 @@ #ifndef DATABASEDAOINTF_H #define DATABASEDAOINTF_H -class QString; +#include + class QDateTime; -#include +#include +#include "Metadata.h" class DatabaseDaoIntf { public: + DatabaseDaoIntf() = default; + DatabaseDaoIntf(const DatabaseDaoIntf &rhs) = delete; + DatabaseDaoIntf(DatabaseDaoIntf &&rhs) = default; + DatabaseDaoIntf &operator=(const DatabaseDaoIntf &rhs) = delete; + DatabaseDaoIntf &operator=(DatabaseDaoIntf &&rhs) = default; virtual ~DatabaseDaoIntf() = default; virtual bool connectDb(const QString &logbookPath) noexcept = 0; @@ -45,9 +52,9 @@ class DatabaseDaoIntf virtual bool updateNextBackupDate(const QDateTime &date) noexcept = 0; virtual bool updateBackupDirectoryPath(const QString &backupDirectoryPath) noexcept = 0; - virtual bool getMetadata(Metadata &metadata) const noexcept = 0; - virtual bool getDatabaseVersion(Version &databaseVersion) const noexcept = 0; - virtual bool getBackupDirectoryPath(QString &backupDirectoryPath) const noexcept = 0; + virtual Metadata getMetadata(bool *ok = nullptr) const noexcept = 0; + virtual Version getDatabaseVersion(bool *ok = nullptr) const noexcept = 0; + virtual QString getBackupDirectoryPath(bool *ok = nullptr) const noexcept = 0; }; #endif // DATABASEDAOINTF_H diff --git a/src/Persistence/src/Dao/EngineDaoIntf.h b/src/Persistence/src/Dao/EngineDaoIntf.h index 02675dce4..b5421cbe7 100644 --- a/src/Persistence/src/Dao/EngineDaoIntf.h +++ b/src/Persistence/src/Dao/EngineDaoIntf.h @@ -26,16 +26,18 @@ #define ENGINEDAOINTF_H #include -#include #include -#include - struct EngineData; class EngineDaoIntf { public: + EngineDaoIntf() = default; + EngineDaoIntf(const EngineDaoIntf &rhs) = delete; + EngineDaoIntf(EngineDaoIntf &&rhs) = default; + EngineDaoIntf &operator=(const EngineDaoIntf &rhs) = delete; + EngineDaoIntf &operator=(EngineDaoIntf &&rhs) = default; virtual ~EngineDaoIntf() = default; /*! @@ -48,7 +50,7 @@ class EngineDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const EngineData &data) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/EnumerationDaoIntf.h b/src/Persistence/src/Dao/EnumerationDaoIntf.h index ef85cf480..c1f6d2f89 100644 --- a/src/Persistence/src/Dao/EnumerationDaoIntf.h +++ b/src/Persistence/src/Dao/EnumerationDaoIntf.h @@ -35,6 +35,11 @@ class Enumeration; class EnumerationDaoIntf { public: + EnumerationDaoIntf() = default; + EnumerationDaoIntf(const EnumerationDaoIntf &rhs) = delete; + EnumerationDaoIntf(EnumerationDaoIntf &&rhs) = default; + EnumerationDaoIntf &operator=(const EnumerationDaoIntf &rhs) = delete; + EnumerationDaoIntf &operator=(EnumerationDaoIntf &&rhs) = default; virtual ~EnumerationDaoIntf() = default; /*! @@ -48,11 +53,13 @@ class EnumerationDaoIntf * | BackupPeriod | enum_backup_period | * | LocationCategory | enum_location_category | * - * \param enumeration - * the Enumeration as defined on the database, with an already assigned name (camelCase) - * \return \c true if successful; \c false else (enumeration does not exist; no DB connection) + * \param name + * the name of the enumeration; in camelCase + * \param ok + * if provided, set to \c true if successful; \c false else (enumeration does not exist; no DB connection) + * \return the Enumeration as defined on the database */ - virtual bool get(Enumeration &enumeration) const noexcept = 0; + virtual Enumeration get(const QString &name, bool *ok = nullptr) const noexcept = 0; }; #endif // ENUMERATIONDAOINTF_H diff --git a/src/Persistence/src/Dao/FlightDaoIntf.h b/src/Persistence/src/Dao/FlightDaoIntf.h index 9e4b5e6a3..18cea304f 100644 --- a/src/Persistence/src/Dao/FlightDaoIntf.h +++ b/src/Persistence/src/Dao/FlightDaoIntf.h @@ -35,6 +35,11 @@ class FlightSummary; class FlightDaoIntf { public: + FlightDaoIntf() = default; + FlightDaoIntf(const FlightDaoIntf &rhs) = delete; + FlightDaoIntf(FlightDaoIntf &&rhs) = default; + FlightDaoIntf &operator=(const FlightDaoIntf &rhs) = delete; + FlightDaoIntf &operator=(FlightDaoIntf &&rhs) = default; virtual ~FlightDaoIntf() = default; /*! diff --git a/src/Persistence/src/Dao/HandleDaoIntf.h b/src/Persistence/src/Dao/HandleDaoIntf.h index 441afc5b1..fa708209a 100644 --- a/src/Persistence/src/Dao/HandleDaoIntf.h +++ b/src/Persistence/src/Dao/HandleDaoIntf.h @@ -26,7 +26,6 @@ #define HANDLEDAOINTF_H #include -#include #include struct AircraftHandleData; @@ -34,6 +33,11 @@ struct AircraftHandleData; class HandleDaoIntf { public: + HandleDaoIntf() = default; + HandleDaoIntf(const HandleDaoIntf &rhs) = delete; + HandleDaoIntf(HandleDaoIntf &&rhs) = default; + HandleDaoIntf &operator=(const HandleDaoIntf &rhs) = delete; + HandleDaoIntf &operator=(HandleDaoIntf &&rhs) = default; virtual ~HandleDaoIntf() = default; /*! @@ -46,7 +50,7 @@ class HandleDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const AircraftHandleData &data) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/LightDaoIntf.h b/src/Persistence/src/Dao/LightDaoIntf.h index 46a68b460..15ec2d86f 100644 --- a/src/Persistence/src/Dao/LightDaoIntf.h +++ b/src/Persistence/src/Dao/LightDaoIntf.h @@ -26,7 +26,6 @@ #define LIGHTDAOINTF_H #include -#include #include struct LightData; @@ -34,6 +33,11 @@ struct LightData; class LightDaoIntf { public: + LightDaoIntf() = default; + LightDaoIntf(const LightDaoIntf &rhs) = delete; + LightDaoIntf(LightDaoIntf &&rhs) = default; + LightDaoIntf &operator=(const LightDaoIntf &rhs) = delete; + LightDaoIntf &operator=(LightDaoIntf &&rhs) = default; virtual ~LightDaoIntf() = default; /*! @@ -46,7 +50,7 @@ class LightDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const LightData &lightData) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/LocationDaoIntf.h b/src/Persistence/src/Dao/LocationDaoIntf.h index d1056845b..3d6ecb1bc 100644 --- a/src/Persistence/src/Dao/LocationDaoIntf.h +++ b/src/Persistence/src/Dao/LocationDaoIntf.h @@ -26,7 +26,6 @@ #define LOCATIONDAOINTF_H #include -#include #include struct LocationSelector; @@ -35,13 +34,18 @@ struct Location; class LocationDaoIntf { public: + LocationDaoIntf() = default; + LocationDaoIntf(const LocationDaoIntf &rhs) = delete; + LocationDaoIntf(LocationDaoIntf &&rhs) = default; + LocationDaoIntf &operator=(const LocationDaoIntf &rhs) = delete; + LocationDaoIntf &operator=(LocationDaoIntf &&rhs) = default; virtual ~LocationDaoIntf() = default; virtual bool add(Location &location) noexcept = 0; virtual bool update(const Location &location) noexcept = 0; virtual bool deleteById(std::int64_t id) noexcept = 0; - virtual bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept = 0; - virtual bool getSelectedLocations(const LocationSelector &selector, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getAll(bool *ok = nullptr) const noexcept = 0; + virtual std::vector getSelectedLocations(const LocationSelector &selector, bool *ok = nullptr) const noexcept = 0; }; #endif // LOCATIONDAOINTF_H diff --git a/src/Persistence/src/Dao/LogbookDaoIntf.h b/src/Persistence/src/Dao/LogbookDaoIntf.h index cc702771e..65f0d4cb1 100644 --- a/src/Persistence/src/Dao/LogbookDaoIntf.h +++ b/src/Persistence/src/Dao/LogbookDaoIntf.h @@ -41,10 +41,15 @@ class FlightSummary; class LogbookDaoIntf { public: + LogbookDaoIntf() = default; + LogbookDaoIntf(const LogbookDaoIntf &rhs) = delete; + LogbookDaoIntf(LogbookDaoIntf &&rhs) = default; + LogbookDaoIntf &operator=(const LogbookDaoIntf &rhs) = delete; + LogbookDaoIntf &operator=(LogbookDaoIntf &&rhs) = default; virtual ~LogbookDaoIntf() = default; virtual bool getFlightDates(std::front_insert_iterator> frontInsertIterator) const noexcept = 0; - virtual std::vector getFlightSummaries(const FlightSelector &flightSelector) const noexcept = 0; + virtual std::vector getFlightSummaries(const FlightSelector &flightSelector, bool *ok = nullptr) const noexcept = 0; }; #endif // LOGBOOKDAO_H diff --git a/src/Persistence/src/Dao/PositionDaoIntf.h b/src/Persistence/src/Dao/PositionDaoIntf.h index 522533f12..9a49d1f4d 100644 --- a/src/Persistence/src/Dao/PositionDaoIntf.h +++ b/src/Persistence/src/Dao/PositionDaoIntf.h @@ -26,7 +26,6 @@ #define POSITIONDAOINTF_H #include -#include #include struct PositionData; @@ -34,6 +33,11 @@ struct PositionData; class PositionDaoIntf { public: + PositionDaoIntf() = default; + PositionDaoIntf(const PositionDaoIntf &rhs) = delete; + PositionDaoIntf(PositionDaoIntf &&rhs) = default; + PositionDaoIntf &operator=(const PositionDaoIntf &rhs) = delete; + PositionDaoIntf &operator=(PositionDaoIntf &&rhs) = default; virtual ~PositionDaoIntf() = default; /*! @@ -46,7 +50,7 @@ class PositionDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const PositionData &data) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/PrimaryFlightControlDaoIntf.h b/src/Persistence/src/Dao/PrimaryFlightControlDaoIntf.h index 6aba8fbf4..df2a3b3c7 100644 --- a/src/Persistence/src/Dao/PrimaryFlightControlDaoIntf.h +++ b/src/Persistence/src/Dao/PrimaryFlightControlDaoIntf.h @@ -26,7 +26,6 @@ #define PRIMARYFLIGHTCONTROLDAOINTF_H #include -#include #include struct PrimaryFlightControlData; @@ -34,6 +33,11 @@ struct PrimaryFlightControlData; class PrimaryFlightControlDaoIntf { public: + PrimaryFlightControlDaoIntf() = default; + PrimaryFlightControlDaoIntf(const PrimaryFlightControlDaoIntf &rhs) = delete; + PrimaryFlightControlDaoIntf(PrimaryFlightControlDaoIntf &&rhs) = default; + PrimaryFlightControlDaoIntf &operator=(const PrimaryFlightControlDaoIntf &rhs) = delete; + PrimaryFlightControlDaoIntf &operator=(PrimaryFlightControlDaoIntf &&rhs) = default; virtual ~PrimaryFlightControlDaoIntf() = default; /*! @@ -46,7 +50,7 @@ class PrimaryFlightControlDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const PrimaryFlightControlData &primaryFlightControlData) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.cpp index 667501861..3d08bab2c 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.cpp @@ -32,10 +32,10 @@ #include #include #include +#include #ifdef DEBUG #include #endif -#include #include #include @@ -54,9 +54,7 @@ #include #include #include -#include "../../Dao/FlightDaoIntf.h" #include "../../Dao/AircraftTypeDaoIntf.h" -#include "../../Dao/AircraftDaoIntf.h" #include "../../Dao/PositionDaoIntf.h" #include "../../Dao/EngineDaoIntf.h" #include "../../Dao/PrimaryFlightControlDaoIntf.h" @@ -67,9 +65,8 @@ #include "../../Dao/DaoFactory.h" #include "SQLiteAircraftDao.h" -class SQLiteAircraftDaoPrivate +struct SQLiteAircraftDaoPrivate { -public: SQLiteAircraftDaoPrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), aircraftTypeDao(daoFactory->createAircraftTypeDao()), @@ -93,14 +90,23 @@ class SQLiteAircraftDaoPrivate std::unique_ptr waypointDao; }; +namespace +{ + // The initial capacity of the position vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + // Most flighs have only one aircraft + constexpr int DefaultCapacity = 1; +} + // PUBLIC SQLiteAircraftDao::SQLiteAircraftDao() noexcept : d(std::make_unique()) {} -SQLiteAircraftDao::~SQLiteAircraftDao() noexcept -{} +SQLiteAircraftDao::SQLiteAircraftDao(SQLiteAircraftDao &&rhs) = default; +SQLiteAircraftDao &SQLiteAircraftDao::operator=(SQLiteAircraftDao &&rhs) = default; +SQLiteAircraftDao::~SQLiteAircraftDao() = default; bool SQLiteAircraftDao::add(std::int64_t flightId, std::size_t sequenceNumber, Aircraft &aircraft) noexcept { @@ -152,7 +158,7 @@ bool SQLiteAircraftDao::add(std::int64_t flightId, std::size_t sequenceNumber, A aircraft.setId(id); #ifdef DEBUG } else { - qDebug("SQLiteAircraftDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } if (ok) { @@ -209,41 +215,46 @@ bool SQLiteAircraftDao::add(std::int64_t flightId, std::size_t sequenceNumber, A return ok; } -bool SQLiteAircraftDao::getByFlightId(std::int64_t flightId, std::back_insert_iterator>> backInsertIterator) const noexcept +std::vector SQLiteAircraftDao::getByFlightId(std::int64_t flightId, bool *ok) const noexcept { - std::vector aircraftInfos; - bool ok = getAircraftInfosByFlightId(flightId, aircraftInfos); - if (ok) { + std::vector aircraftList; + bool success {true}; + std::vector aircraftInfos = getAircraftInfosByFlightId(flightId, &success); + if (success) { + aircraftList.reserve(aircraftInfos.size()); for (const AircraftInfo &info: aircraftInfos) { - std::unique_ptr aircraft = std::make_unique(); - aircraft->setId(info.aircraftId); - aircraft->setAircraftInfo(info); - ok = d->positionDao->getByAircraftId(aircraft->getId(), aircraft->getPosition().backInsertIterator()); - if (ok) { - ok = d->engineDao->getByAircraftId(aircraft->getId(), aircraft->getEngine().backInsertIterator()); + Aircraft aircraft; + aircraft.setId(info.aircraftId); + aircraft.setAircraftInfo(info); + aircraft.getPosition().setData(d->positionDao->getByAircraftId(aircraft.getId(), &success)); + if (success) { + aircraft.getEngine().setData(d->engineDao->getByAircraftId(aircraft.getId(), &success)); } - if (ok) { - ok = d->primaryFlightControlDao->getByAircraftId(aircraft->getId(), aircraft->getPrimaryFlightControl().backInsertIterator()); + if (success) { + aircraft.getPrimaryFlightControl().setData(d->primaryFlightControlDao->getByAircraftId(aircraft.getId(), &success)); } - if (ok) { - ok = d->secondaryFlightControlDao->getByAircraftId(aircraft->getId(), aircraft->getSecondaryFlightControl().backInsertIterator()); + if (success) { + aircraft.getSecondaryFlightControl().setData(d->secondaryFlightControlDao->getByAircraftId(aircraft.getId(), &success)); } - if (ok) { - ok = d->handleDao->getByAircraftId(aircraft->getId(), aircraft->getAircraftHandle().backInsertIterator()); + if (success) { + aircraft.getAircraftHandle().setData(d->handleDao->getByAircraftId(aircraft.getId(), &success)); } - if (ok) { - ok = d->lightDao->getByAircraftId(aircraft->getId(), aircraft->getLight().backInsertIterator()); + if (success) { + aircraft.getLight().setData(d->lightDao->getByAircraftId(aircraft.getId(), &success)); } - if (ok) { - ok = d->waypointDao->getByAircraftId(aircraft->getId(), aircraft->getFlightPlan()); + if (success) { + success = d->waypointDao->getByAircraftId(aircraft.getId(), aircraft.getFlightPlan()); } - if (ok) { - backInsertIterator = std::move(aircraft); + if (success) { + aircraftList.push_back(std::move(aircraft)); } } } - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftList; } bool SQLiteAircraftDao::adjustAircraftSequenceNumbersByFlightId(std::int64_t flightId, std::size_t sequenceNumber) noexcept @@ -261,7 +272,7 @@ bool SQLiteAircraftDao::adjustAircraftSequenceNumbersByFlightId(std::int64_t fli const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftDao::adjustAircraftSequenceNumbersByIndex: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::adjustAircraftSequenceNumbersByIndex: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -300,7 +311,7 @@ bool SQLiteAircraftDao::deleteAllByFlightId(std::int64_t flightId) noexcept ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif } @@ -342,7 +353,7 @@ bool SQLiteAircraftDao::deleteById(std::int64_t id) noexcept ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftDao::deleteById: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::deleteById: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif } @@ -350,8 +361,9 @@ bool SQLiteAircraftDao::deleteById(std::int64_t id) noexcept return ok; } -bool SQLiteAircraftDao::getAircraftInfosByFlightId(std::int64_t flightId, std::vector &aircraftInfos) const noexcept +std::vector SQLiteAircraftDao::getAircraftInfosByFlightId(std::int64_t flightId, bool *ok) const noexcept { + std::vector aircraftInfos; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -362,9 +374,14 @@ bool SQLiteAircraftDao::getAircraftInfosByFlightId(std::int64_t flightId, std::v ); query.bindValue(":flight_id", QVariant::fromValue(flightId)); - bool ok = query.exec(); - if (ok) { - aircraftInfos.clear(); + bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + aircraftInfos.reserve(query.size()); + } else { + aircraftInfos.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int idIdx = record.indexOf("id"); const int typeIdx = record.indexOf("type"); @@ -375,10 +392,6 @@ bool SQLiteAircraftDao::getAircraftInfosByFlightId(std::int64_t flightId, std::v const int initialAirspeedIdx = record.indexOf("initial_airspeed"); const int airCraftAltitudeAboveGroundIdx = record.indexOf("altitude_above_ground"); const int startOnGroundIdx = record.indexOf("start_on_ground"); - const int size = query.size(); - if (size > 0) { - aircraftInfos.reserve(size); - } while (ok && query.next()) { AircraftInfo info(query.value(idIdx).toLongLong()); const QString &type = query.value(typeIdx).toString(); @@ -390,20 +403,22 @@ bool SQLiteAircraftDao::getAircraftInfosByFlightId(std::int64_t flightId, std::v info.altitudeAboveGround = query.value(airCraftAltitudeAboveGroundIdx).toFloat(); info.startOnGround = query.value(startOnGroundIdx).toBool(); - AircraftType aircraftType; - ok = d->aircraftTypeDao->getByType(type, aircraftType); + AircraftType aircraftType = d->aircraftTypeDao->getByType(type, &success); if (ok) { info.aircraftType = std::move(aircraftType); - aircraftInfos.push_back(info); + aircraftInfos.push_back(std::move(info)); }; } } #ifdef DEBUG else { - qDebug("SQLiteAircraftDao::getAircraftInfosByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::getAircraftInfosByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftInfos; } bool SQLiteAircraftDao::updateTimeOffset(std::int64_t id, std::int64_t timeOffset) noexcept @@ -420,7 +435,7 @@ bool SQLiteAircraftDao::updateTimeOffset(std::int64_t id, std::int64_t timeOffse const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftDao::updateTimeOffset: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::updateTimeOffset: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -440,7 +455,7 @@ bool SQLiteAircraftDao::updateTailNumber(std::int64_t id, const QString &tailNum const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftDao::updateTailNumber: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftDao::updateTailNumber: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.h b/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.h index 5091f0833..bee244c31 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteAircraftDao.h @@ -28,28 +28,30 @@ #include #include #include -#include #include -#include - -#include #include "../AircraftDaoIntf.h" -class SQLiteAircraftDaoPrivate; +class Aircraft; +struct AircraftInfo; +struct SQLiteAircraftDaoPrivate; class SQLiteAircraftDao : public AircraftDaoIntf { public: SQLiteAircraftDao() noexcept; - ~SQLiteAircraftDao() noexcept override; + SQLiteAircraftDao(const SQLiteAircraftDao &rhs) = delete; + SQLiteAircraftDao(SQLiteAircraftDao &&rhs); + SQLiteAircraftDao &operator=(const SQLiteAircraftDao &rhs) = delete; + SQLiteAircraftDao &operator=(SQLiteAircraftDao &&rhs); + ~SQLiteAircraftDao() override; bool add(std::int64_t flightId, std::size_t sequenceNumber, Aircraft &aircraft) noexcept override; - bool getByFlightId(std::int64_t flightId, std::back_insert_iterator>> backInsertIterator) const noexcept override; + std::vector getByFlightId(std::int64_t flightId, bool *ok = nullptr) const noexcept override; bool adjustAircraftSequenceNumbersByFlightId(std::int64_t flightId, std::size_t sequenceNumber) noexcept override; bool deleteAllByFlightId(std::int64_t flightId) noexcept override; bool deleteById(std::int64_t id) noexcept override; - bool getAircraftInfosByFlightId(std::int64_t flightId, std::vector &aircraftInfos) const noexcept override; + std::vector getAircraftInfosByFlightId(std::int64_t flightId, bool *ok = nullptr) const noexcept override; bool updateTimeOffset(std::int64_t id, std::int64_t timeOffset) noexcept override; bool updateTailNumber(std::int64_t id, const QString &tailNumber) noexcept override; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.cpp index 969a2d569..465322ca2 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.cpp @@ -30,18 +30,27 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include #include "SQLiteAircraftTypeDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the aircraft type vector; happens to be the number of default + // aircraft types (as per Sky Dolly v0.12), also refer to LogbookMigration.sql + constexpr int DefaultCapacity = 206; +} -SQLiteAircraftTypeDao::SQLiteAircraftTypeDao() noexcept -{} +// PUBLIC -SQLiteAircraftTypeDao::~SQLiteAircraftTypeDao() noexcept -{} +SQLiteAircraftTypeDao::SQLiteAircraftTypeDao(SQLiteAircraftTypeDao &&rhs) = default; +SQLiteAircraftTypeDao &SQLiteAircraftTypeDao::operator=(SQLiteAircraftTypeDao &&rhs) = default; +SQLiteAircraftTypeDao::~SQLiteAircraftTypeDao() = default; bool SQLiteAircraftTypeDao::upsert(const AircraftType &aircraftType) noexcept { @@ -66,14 +75,15 @@ bool SQLiteAircraftTypeDao::upsert(const AircraftType &aircraftType) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteAircraftTypeDao::upsert: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftTypeDao::upsert: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLiteAircraftTypeDao::getByType(const QString &type, AircraftType &aircraftType) const noexcept +AircraftType SQLiteAircraftTypeDao::getByType(const QString &type, bool *ok) const noexcept { + AircraftType aircraftType; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -84,11 +94,11 @@ bool SQLiteAircraftTypeDao::getByType(const QString &type, AircraftType &aircraf query.bindValue(":type", type); aircraftType.type = type; - bool ok = query.exec(); - if (ok) { + bool success = query.exec(); + if (success) { const QSqlRecord record = query.record(); - ok = query.next(); - if (ok) { + success = query.next(); + if (success) { const int categoryIdx = record.indexOf("category"); const int wingSpanIdx = record.indexOf("wing_span"); const int engineTypeIdx = record.indexOf("engine_type"); @@ -101,14 +111,18 @@ bool SQLiteAircraftTypeDao::getByType(const QString &type, AircraftType &aircraf } #ifdef DEBUG else { - qDebug("SQLiteAircraftTypeDao::getByType: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteAircraftTypeDao::getByType: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftType; } -bool SQLiteAircraftTypeDao::getAll(std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteAircraftTypeDao::getAll(bool *ok) const noexcept { + std::vector aircraftTypes; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -116,9 +130,15 @@ bool SQLiteAircraftTypeDao::getAll(std::back_insert_iteratorhasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + aircraftTypes.reserve(query.size()); + } else { + aircraftTypes.reserve(::DefaultCapacity); + } - const bool ok = query.exec(); - if (ok) { QSqlRecord record = query.record(); const int typeIdx = record.indexOf("type"); const int categoryIdx = record.indexOf("category"); @@ -126,22 +146,23 @@ bool SQLiteAircraftTypeDao::getAll(std::back_insert_iterator(query.value(engineTypeIdx).toInt()); - aircraftType.numberOfEngines = query.value(nofEnginesIdx).toInt(); - - backInsertIterator = std::move(aircraftType); + const QString type = query.value(typeIdx).toString(); + const QString category = query.value(categoryIdx).toString(); + const int wingSpan = query.value(wingSpanIdx).toInt(); + const SimType::EngineType engineType = static_cast(query.value(engineTypeIdx).toInt()); + const int numberOfEngines = query.value(nofEnginesIdx).toInt(); + aircraftTypes.emplace_back(type, category, wingSpan, engineType, numberOfEngines); } #ifdef DEBUG } else { - qDebug("SQLitePositionDao::getAll: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::getAll: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftTypes; } bool SQLiteAircraftTypeDao::exists(const QString &type) const noexcept @@ -164,7 +185,7 @@ bool SQLiteAircraftTypeDao::exists(const QString &type) const noexcept } else { exists = false; #ifdef DEBUG - qDebug("SQLitePositionDao::exists: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::exists: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } diff --git a/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.h b/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.h index 409fb1448..70b618f71 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteAircraftTypeDao.h @@ -27,7 +27,6 @@ #include #include -#include class QString; @@ -38,12 +37,16 @@ struct AircraftType; class SQLiteAircraftTypeDao : public AircraftTypeDaoIntf { public: - SQLiteAircraftTypeDao() noexcept; - ~SQLiteAircraftTypeDao() noexcept override; + SQLiteAircraftTypeDao() = default; + SQLiteAircraftTypeDao(const SQLiteAircraftTypeDao &rhs) = delete; + SQLiteAircraftTypeDao(SQLiteAircraftTypeDao &&rhs); + SQLiteAircraftTypeDao &operator=(const SQLiteAircraftTypeDao &rhs) = delete; + SQLiteAircraftTypeDao &operator=(SQLiteAircraftTypeDao &&rhs); + ~SQLiteAircraftTypeDao() override; bool upsert(const AircraftType &aircraftType) noexcept override; - bool getByType(const QString &type, AircraftType &aircraftType) const noexcept override; - bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept override; + AircraftType getByType(const QString &type, bool *ok = nullptr) const noexcept override; + std::vector getAll(bool *ok = nullptr) const noexcept override; bool exists(const QString &type) const noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.cpp index 083827169..6e524d7cf 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.cpp @@ -31,6 +31,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -38,11 +41,10 @@ #include "SqlMigration.h" #include "SQLiteDatabaseDao.h" -constexpr char DbName[] = "QSQLITE"; +constexpr const char *DbName {"QSQLITE"}; -class DatabaseDaoPrivate +struct DatabaseDaoPrivate { -public: DatabaseDaoPrivate() {} @@ -55,6 +57,9 @@ SQLiteDatabaseDao::SQLiteDatabaseDao() noexcept : d(std::make_unique()) {} +SQLiteDatabaseDao::SQLiteDatabaseDao(SQLiteDatabaseDao &&rhs) = default; +SQLiteDatabaseDao &SQLiteDatabaseDao::operator=(SQLiteDatabaseDao &&rhs) = default; + SQLiteDatabaseDao::~SQLiteDatabaseDao() noexcept { disconnectSQLite(); @@ -90,7 +95,7 @@ bool SQLiteDatabaseDao::optimise() noexcept ok = query.exec("update metadata set last_optim_date = datetime('now') where rowid = 1;"); #ifdef DEBUG } else { - qDebug("SQLiteDatabaseDao::optimise(: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteDatabaseDao::optimise(: SQL error:" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } return ok; @@ -104,7 +109,7 @@ bool SQLiteDatabaseDao::backup(const QString &backupPath) noexcept ok = query.exec("update metadata set last_backup_date = datetime('now') where rowid = 1;"); #ifdef DEBUG } else { - qDebug("SQLiteDatabaseDao::backup(: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteDatabaseDao::backup(: SQL error:" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } return ok; @@ -149,12 +154,13 @@ bool SQLiteDatabaseDao::updateBackupDirectoryPath(const QString &backupDirectory return query.exec(); } -bool SQLiteDatabaseDao::getMetadata(Metadata &metadata) const noexcept +Metadata SQLiteDatabaseDao::getMetadata(bool *ok) const noexcept { + Metadata metadata; QSqlQuery query; query.setForwardOnly(true); - const bool ok = query.exec( + const bool success = query.exec( "select m.creation_date," " m.app_version," " m.last_optim_date," @@ -166,7 +172,7 @@ bool SQLiteDatabaseDao::getMetadata(Metadata &metadata) const noexcept "join enum_backup_period ebp " "on m.backup_period_id = ebp.id;" ); - if (ok && query.next()) { + if (success && query.next()) { QDateTime dateTime = query.value(0).toDateTime(); dateTime.setTimeZone(QTimeZone::utc()); metadata.creationDate = dateTime.toLocalTime(); @@ -189,28 +195,39 @@ bool SQLiteDatabaseDao::getMetadata(Metadata &metadata) const noexcept metadata.backupDirectoryPath = query.value(5).toString(); metadata.backupPeriodSymId = query.value(6).toString(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return metadata; }; -bool SQLiteDatabaseDao::getDatabaseVersion(Version &databaseVersion) const noexcept +Version SQLiteDatabaseDao::getDatabaseVersion(bool *ok) const noexcept { + Version version; QSqlQuery query; - const bool ok = query.exec("select m.app_version from metadata m;"); - if (ok && query.next()) { + const bool success = query.exec("select m.app_version from metadata m;"); + if (success && query.next()) { QString appVersion = query.value(0).toString(); - databaseVersion.fromString(appVersion); + version.fromString(appVersion); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return version; }; -bool SQLiteDatabaseDao::getBackupDirectoryPath(QString &backupDirectoryPath) const noexcept +QString SQLiteDatabaseDao::getBackupDirectoryPath(bool *ok) const noexcept { + QString backupDirectoryPath; QSqlQuery query; - const bool ok = query.exec("select m.backup_directory_path from metadata m;"); + const bool success = query.exec("select m.backup_directory_path from metadata m;"); if (ok && query.next()) { backupDirectoryPath = query.value(0).toString(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return backupDirectoryPath; }; // PRIVATE diff --git a/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.h b/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.h index b2e7e951e..5d8187e84 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteDatabaseDao.h @@ -27,21 +27,25 @@ #include -#include +#include -class QString; class QDateTime; -#include +#include #include "../DatabaseDaoIntf.h" +#include "Metadata.h" -class DatabaseDaoPrivate; +struct DatabaseDaoPrivate; class SQLiteDatabaseDao : public DatabaseDaoIntf { public: SQLiteDatabaseDao() noexcept; - ~SQLiteDatabaseDao() noexcept override; + SQLiteDatabaseDao(const SQLiteDatabaseDao &rhs) = delete; + SQLiteDatabaseDao(SQLiteDatabaseDao &&rhs); + SQLiteDatabaseDao &operator=(const SQLiteDatabaseDao &rhs) = delete; + SQLiteDatabaseDao &operator=(SQLiteDatabaseDao &&rhs); + ~SQLiteDatabaseDao() override; bool connectDb(const QString &logbookPath) noexcept override; void disconnectDb() noexcept override; @@ -53,12 +57,11 @@ class SQLiteDatabaseDao : public DatabaseDaoIntf bool updateNextBackupDate(const QDateTime &date) noexcept override; bool updateBackupDirectoryPath(const QString &backupDirectoryPath) noexcept override; - bool getMetadata(Metadata &metadata) const noexcept override; - bool getDatabaseVersion(Version &databaseVersion) const noexcept override; - bool getBackupDirectoryPath(QString &backupDirectoryPath) const noexcept override; + Metadata getMetadata(bool *ok = nullptr) const noexcept override; + Version getDatabaseVersion(bool *ok = nullptr) const noexcept override; + QString getBackupDirectoryPath(bool *ok = nullptr) const noexcept override; private: - Q_DISABLE_COPY(SQLiteDatabaseDao) std::unique_ptr d; void disconnectSQLite() noexcept; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.cpp index 6047107ac..fdb81956e 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.cpp @@ -32,17 +32,26 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include "SQLiteEngineDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the engine vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + constexpr int DefaultCapacity = 10; +} -SQLiteEngineDao::SQLiteEngineDao() noexcept -{} +// PUBLIC -SQLiteEngineDao::~SQLiteEngineDao() noexcept -{} +SQLiteEngineDao::SQLiteEngineDao(SQLiteEngineDao &&rhs) = default; +SQLiteEngineDao &SQLiteEngineDao::operator=(SQLiteEngineDao &&rhs) = default; +SQLiteEngineDao::~SQLiteEngineDao() = default; bool SQLiteEngineDao::add(std::int64_t aircraftId, const EngineData &data) noexcept { @@ -147,14 +156,15 @@ bool SQLiteEngineDao::add(std::int64_t aircraftId, const EngineData &data) noex const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteEngineDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteEngineDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLiteEngineDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteEngineDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector engineData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -165,8 +175,14 @@ bool SQLiteEngineDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_ ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + engineData.reserve(query.size()); + } else { + engineData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int throttleLeverPosition1Idx = record.indexOf("throttle_lever_position1"); @@ -232,14 +248,17 @@ bool SQLiteEngineDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_ data.generalEngineCombustion3 = query.value(generalEngineCombustion3Idx).toBool(); data.generalEngineCombustion4 = query.value(generalEngineCombustion4Idx).toBool(); - backInsertIterator = std::move(data); + engineData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLiteEngineDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteEngineDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return engineData; } bool SQLiteEngineDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -258,7 +277,7 @@ bool SQLiteEngineDao::deleteByFlightId(std::int64_t flightId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteEngineDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteEngineDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -277,7 +296,7 @@ bool SQLiteEngineDao::deleteByAircraftId(std::int64_t aircraftId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteEngineDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteEngineDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.h b/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.h index a4dc0413b..3ed8c5c0d 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteEngineDao.h @@ -27,20 +27,24 @@ #include #include -#include #include -#include #include "../EngineDaoIntf.h" +struct EngineData; + class SQLiteEngineDao : public EngineDaoIntf { public: - SQLiteEngineDao() noexcept; - ~SQLiteEngineDao() noexcept override; + SQLiteEngineDao() = default; + SQLiteEngineDao(const SQLiteEngineDao &rhs) = delete; + SQLiteEngineDao(SQLiteEngineDao &&rhs); + SQLiteEngineDao &operator=(const SQLiteEngineDao &rhs) = delete; + SQLiteEngineDao &operator=(SQLiteEngineDao &&rhs); + ~SQLiteEngineDao() override; bool add(std::int64_t aircraftId, const EngineData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.cpp index 95cb945d0..ef0ac0539 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.cpp @@ -38,14 +38,13 @@ // PUBIC -SQLiteEnumerationDao::SQLiteEnumerationDao() noexcept -{} +SQLiteEnumerationDao::SQLiteEnumerationDao(SQLiteEnumerationDao &&rhs) = default; +SQLiteEnumerationDao &SQLiteEnumerationDao::operator=(SQLiteEnumerationDao &&rhs) = default; +SQLiteEnumerationDao::~SQLiteEnumerationDao() = default; -SQLiteEnumerationDao::~SQLiteEnumerationDao() noexcept -{} - -bool SQLiteEnumerationDao::get(Enumeration &enumeration) const noexcept +Enumeration SQLiteEnumerationDao::get(const QString &name, bool *ok) const noexcept { + Enumeration enumeration {name}; const QString enumerationTableName = QStringLiteral("enum_") % Name::fromCamelCase(enumeration.getName()); QSqlQuery query; @@ -56,8 +55,8 @@ bool SQLiteEnumerationDao::get(Enumeration &enumeration) const noexcept "order by e.id asc;" ); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { QSqlRecord record = query.record(); const int idIdx = record.indexOf("id"); const int symbolicIdIdx = record.indexOf("sym_id"); @@ -65,8 +64,8 @@ bool SQLiteEnumerationDao::get(Enumeration &enumeration) const noexcept while (query.next()) { const std::int64_t id = query.value(idIdx).toLongLong(); const QString symbolicId = query.value(symbolicIdIdx).toString(); - const QString name = query.value(nameIdx).toString(); - enumeration.addItem({id, symbolicId, name}); + const QString itemName = query.value(nameIdx).toString(); + enumeration.addItem({id, symbolicId, itemName}); } #ifdef DEBUG } else { @@ -74,5 +73,8 @@ bool SQLiteEnumerationDao::get(Enumeration &enumeration) const noexcept #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return enumeration; } diff --git a/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.h b/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.h index 39b09b598..8d58c27da 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteEnumerationDao.h @@ -25,19 +25,22 @@ #ifndef SQLITEENUMERATIONDAO_H #define SQLITEENUMERATIONDAO_H -#include +class QString; +#include #include "../EnumerationDaoIntf.h" -class Enumeration; - class SQLiteEnumerationDao : public EnumerationDaoIntf { public: - SQLiteEnumerationDao() noexcept; - ~SQLiteEnumerationDao() noexcept override; + SQLiteEnumerationDao() = default; + SQLiteEnumerationDao(const SQLiteEnumerationDao &rhs) = delete; + SQLiteEnumerationDao(SQLiteEnumerationDao &&rhs); + SQLiteEnumerationDao &operator=(const SQLiteEnumerationDao &rhs) = delete; + SQLiteEnumerationDao &operator=(SQLiteEnumerationDao &&rhs); + ~SQLiteEnumerationDao() override; - bool get(Enumeration &enumeration) const noexcept override; + Enumeration get(const QString &name, bool *ok = nullptr) const noexcept override; }; #endif // SQLITEENUMERATIONDAO_H diff --git a/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.cpp index 4e6b24bea..acf3e4c43 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.cpp @@ -34,6 +34,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -62,8 +65,9 @@ SQLiteFlightDao::SQLiteFlightDao() noexcept : d(std::make_unique()) {} -SQLiteFlightDao::~SQLiteFlightDao() noexcept -{} +SQLiteFlightDao::SQLiteFlightDao(SQLiteFlightDao &&rhs) = default; +SQLiteFlightDao &SQLiteFlightDao::operator=(SQLiteFlightDao &&rhs) = default; +SQLiteFlightDao::~SQLiteFlightDao() = default; bool SQLiteFlightDao::add(Flight &flight) noexcept { @@ -146,14 +150,14 @@ bool SQLiteFlightDao::add(Flight &flight) noexcept flight.setId(id); #ifdef DEBUG } else { - qDebug("SQLiteFlightDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::add: SQL error:" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } if (ok) { // Starts at 1 std::size_t sequenceNumber = 1; - for (auto &it : flight) { - ok = d->aircraftDao->add(flight.getId(), sequenceNumber, *it.get()); + for (auto &aircaft : flight) { + ok = d->aircraftDao->add(flight.getId(), sequenceNumber, aircaft); if (ok) { ++sequenceNumber; } else { @@ -230,8 +234,7 @@ bool SQLiteFlightDao::get(std::int64_t id, Flight &flight) const noexcept flight.setFlightCondition(flightCondition); } - std::vector> aircraft; - ok = d->aircraftDao->getByFlightId(id, std::back_inserter(aircraft)); + std::vector aircraft = d->aircraftDao->getByFlightId(id, &ok); flight.setAircraft(std::move(aircraft)); if (ok) { // Index starts at 0 @@ -240,7 +243,7 @@ bool SQLiteFlightDao::get(std::int64_t id, Flight &flight) const noexcept } #ifdef DEBUG } else { - qDebug("SQLiteFlightDao::get: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::get: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } return ok; @@ -261,7 +264,7 @@ bool SQLiteFlightDao::deleteById(std::int64_t id) noexcept ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteFlightDao::deleteById: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::deleteById: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif } @@ -282,7 +285,7 @@ bool SQLiteFlightDao::updateTitle(std::int64_t id, const QString &title) noexcep const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteFlightDao::updateTitleQuery: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::updateTitleQuery: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -304,7 +307,7 @@ bool SQLiteFlightDao::updateTitleAndDescription(std::int64_t id, const QString & bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteFlightDao::updateTitleAndDescription: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::updateTitleAndDescription: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -325,7 +328,7 @@ bool SQLiteFlightDao::updateUserAircraftIndex(std::int64_t id, int index) noexce const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteFlightDao::updateUserAircraftIndex: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteFlightDao::updateUserAircraftIndex: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.h b/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.h index 574c8bbed..423cf7d0f 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteFlightDao.h @@ -39,7 +39,11 @@ class SQLiteFlightDao : public FlightDaoIntf { public: SQLiteFlightDao() noexcept; - ~SQLiteFlightDao() noexcept override; + SQLiteFlightDao(const SQLiteFlightDao &rhs) = delete; + SQLiteFlightDao(SQLiteFlightDao &&rhs); + SQLiteFlightDao &operator=(const SQLiteFlightDao &rhs) = delete; + SQLiteFlightDao &operator=(SQLiteFlightDao &&rhs); + ~SQLiteFlightDao() override; bool add(Flight &flight) noexcept override; bool get(std::int64_t id, Flight &flight) const noexcept override; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.cpp index 7042cfaee..2855d993c 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.cpp @@ -24,7 +24,6 @@ */ #include #include -#include #include #include @@ -32,17 +31,26 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include "SQLiteHandleDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the aircraft handles vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + constexpr int DefaultCapacity = 4; +} -SQLiteHandleDao::SQLiteHandleDao() noexcept -{} +// PUBLIC -SQLiteHandleDao::~SQLiteHandleDao() noexcept -{} +SQLiteHandleDao::SQLiteHandleDao(SQLiteHandleDao &&rhs) = default; +SQLiteHandleDao &SQLiteHandleDao::operator=(SQLiteHandleDao &&rhs) = default; +SQLiteHandleDao::~SQLiteHandleDao() = default; bool SQLiteHandleDao::add(std::int64_t aircraftId, const AircraftHandleData &aircraftHandleData) noexcept { @@ -90,14 +98,15 @@ bool SQLiteHandleDao::add(std::int64_t aircraftId, const AircraftHandleData &air const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteHandleDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteHandleDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLiteHandleDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteHandleDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector aircraftHandleData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -108,8 +117,14 @@ bool SQLiteHandleDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_ ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); + const bool success = query.exec(); if (ok) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + aircraftHandleData.reserve(query.size()); + } else { + aircraftHandleData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int brakeLeftPositionIdx = record.indexOf("brake_left_position"); @@ -136,15 +151,17 @@ bool SQLiteHandleDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_ data.gearHandlePosition = query.value(gearHandlePositionIdx).toBool(); data.smokeEnabled = query.value(smokeEnablePositionIdx).toBool(); - backInsertIterator = std::move(data); + aircraftHandleData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLiteHandleDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteHandleDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftHandleData; } bool SQLiteHandleDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -163,7 +180,7 @@ bool SQLiteHandleDao::deleteByFlightId(std::int64_t flightId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteHandleDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteHandleDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -182,7 +199,7 @@ bool SQLiteHandleDao::deleteByAircraftId(std::int64_t aircraftId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteHandleDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteHandleDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.h b/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.h index 9ad7e9ab8..86679c25d 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteHandleDao.h @@ -27,23 +27,26 @@ #include #include -#include #include -#include #include "../HandleDaoIntf.h" +struct AircraftHandleData; + class SQLiteHandleDao : public HandleDaoIntf { public: - SQLiteHandleDao() noexcept; - ~SQLiteHandleDao() noexcept override; + SQLiteHandleDao() = default; + SQLiteHandleDao(const SQLiteHandleDao &rhs) = delete; + SQLiteHandleDao(SQLiteHandleDao &&rhs); + SQLiteHandleDao &operator=(const SQLiteHandleDao &rhs) = delete; + SQLiteHandleDao &operator=(SQLiteHandleDao &&rhs); + ~SQLiteHandleDao() override; bool add(std::int64_t aircraftId, const AircraftHandleData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; - #endif // SQLITEHANDLEDAO_H diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLightDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteLightDao.cpp index 70b54f2fe..af60c2446 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLightDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteLightDao.cpp @@ -24,7 +24,6 @@ */ #include #include -#include #include #include @@ -32,17 +31,26 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include "SQLiteLightDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the light vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + constexpr int DefaultCapacity = 1; +} -SQLiteLightDao::SQLiteLightDao() noexcept -{} +// PUBLIC -SQLiteLightDao::~SQLiteLightDao() noexcept -{} +SQLiteLightDao::SQLiteLightDao(SQLiteLightDao &&rhs) = default; +SQLiteLightDao &SQLiteLightDao::operator=(SQLiteLightDao &&rhs) = default; +SQLiteLightDao::~SQLiteLightDao() = default; bool SQLiteLightDao::add(std::int64_t aircraftId, const LightData &lightData) noexcept { @@ -65,14 +73,15 @@ bool SQLiteLightDao::add(std::int64_t aircraftId, const LightData &lightData) n const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteLightDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLightDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLiteLightDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteLightDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector lightData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -83,8 +92,14 @@ bool SQLiteLightDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_i ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + lightData.reserve(query.size()); + } else { + lightData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int lightStatesIdx = record.indexOf("light_states"); @@ -94,15 +109,18 @@ bool SQLiteLightDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_i data.timestamp = query.value(timestampIdx).toLongLong(); data.lightStates = static_cast(query.value(lightStatesIdx).toInt()); - backInsertIterator = std::move(data); + lightData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLiteLightDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLightDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return lightData; } bool SQLiteLightDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -120,7 +138,7 @@ bool SQLiteLightDao::deleteByFlightId(std::int64_t flightId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteLightDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLightDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -138,7 +156,7 @@ bool SQLiteLightDao::deleteByAircraftId(std::int64_t aircraftId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteLightDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLightDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLightDao.h b/src/Persistence/src/Dao/SQLite/SQLiteLightDao.h index 75c049cd6..2cbdc1903 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLightDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteLightDao.h @@ -27,20 +27,24 @@ #include #include -#include #include -#include #include "../LightDaoIntf.h" +struct LightData; + class SQLiteLightDao : public LightDaoIntf { public: - SQLiteLightDao() noexcept; - ~SQLiteLightDao() noexcept override; + SQLiteLightDao() = default; + SQLiteLightDao(const SQLiteLightDao &rhs) = delete; + SQLiteLightDao(SQLiteLightDao &&rhs); + SQLiteLightDao &operator=(const SQLiteLightDao &rhs) = delete; + SQLiteLightDao &operator=(SQLiteLightDao &&rhs); + ~SQLiteLightDao() override; bool add(std::int64_t aircraftId, const LightData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.cpp index 5dddf5954..80b4815f9 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef DEBUG #include #endif @@ -37,13 +38,18 @@ #include #include "SQLiteLocationDao.h" -// PUBIC +namespace +{ + // The initial capacity of the location vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + constexpr int DefaultCapacity = 25; +} -SQLiteLocationDao::SQLiteLocationDao() noexcept -{} +// PUBIC -SQLiteLocationDao::~SQLiteLocationDao() noexcept -{} +SQLiteLocationDao::SQLiteLocationDao(SQLiteLocationDao &&rhs) = default; +SQLiteLocationDao &SQLiteLocationDao::operator=(SQLiteLocationDao &&rhs) = default; +SQLiteLocationDao::~SQLiteLocationDao() = default; bool SQLiteLocationDao::add(Location &location) noexcept { @@ -180,8 +186,9 @@ bool SQLiteLocationDao::deleteById(std::int64_t id) noexcept return ok; } -bool SQLiteLocationDao::getAll(std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteLocationDao::getAll(bool *ok) const noexcept { + std::vector locations; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -190,8 +197,14 @@ bool SQLiteLocationDao::getAll(std::back_insert_iterator> "order by l.id;" ); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + locations.reserve(query.size()); + } else { + locations.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int idIdx = record.indexOf("id"); const int titleIdx = record.indexOf("title"); @@ -229,19 +242,26 @@ bool SQLiteLocationDao::getAll(std::back_insert_iterator> location.onGround = query.value(onGroundIdx).toBool(); location.attributes = query.value(attributesIdx).toLongLong(); - backInsertIterator = std::move(location); + locations.push_back(std::move(location)); } } #ifdef DEBUG else { - qDebug("SQLiteLocationDao::getAll: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code:" + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLocationDao::getAll: SQL error:" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif - return ok; + if (ok != nullptr) { + *ok = success; + } + return locations; } /// \todo IMPLEMENT ME -bool SQLiteLocationDao::getSelectedLocations(const LocationSelector &selector, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteLocationDao::getSelectedLocations(const LocationSelector &selector, bool *ok) const noexcept { - return true; + std::vector locations; + if (ok != nullptr) { + *ok = true; + } + return locations; } diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.h b/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.h index 1bc42d964..df956d431 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteLocationDao.h @@ -34,14 +34,18 @@ struct Location; class SQLiteLocationDao : public LocationDaoIntf { public: - SQLiteLocationDao() noexcept; - ~SQLiteLocationDao() noexcept override; + SQLiteLocationDao() = default; + SQLiteLocationDao(const SQLiteLocationDao &rhs) = delete; + SQLiteLocationDao(SQLiteLocationDao &&rhs); + SQLiteLocationDao &operator=(const SQLiteLocationDao &rhs) = delete; + SQLiteLocationDao &operator=(SQLiteLocationDao &&rhs); + ~SQLiteLocationDao() override; bool add(Location &location) noexcept override; bool update(const Location &location) noexcept override; bool deleteById(std::int64_t id) noexcept override; - bool getAll(std::back_insert_iterator> backInsertIterator) const noexcept override; - bool getSelectedLocations(const LocationSelector &selector, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getAll(bool *ok = nullptr) const noexcept override; + std::vector getSelectedLocations(const LocationSelector &selector, bool *ok = nullptr) const noexcept override; }; #endif // SQLITELOCATIONDAO_H diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.cpp index 2e67c47d9..83016b59c 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.cpp @@ -33,8 +33,12 @@ #include #include #include +#include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -44,13 +48,19 @@ #include #include "SQLiteLogbookDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the logbook summaries vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + // Assume 50 entries per logbook + constexpr int DefaultSummaryCapacity = 50; +} -SQLiteLogbookDao::SQLiteLogbookDao() noexcept -{} +// PUBLIC -SQLiteLogbookDao::~SQLiteLogbookDao() noexcept -{} +SQLiteLogbookDao::SQLiteLogbookDao(SQLiteLogbookDao &&rhs) = default; +SQLiteLogbookDao &SQLiteLogbookDao::operator=(SQLiteLogbookDao &&rhs) = default; +SQLiteLogbookDao::~SQLiteLogbookDao() = default; bool SQLiteLogbookDao::getFlightDates(std::front_insert_iterator> frontInsertIterator) const noexcept { @@ -74,24 +84,24 @@ bool SQLiteLogbookDao::getFlightDates(std::front_insert_iterator SQLiteLogbookDao::getFlightSummaries(const FlightSelector &flightSelector) const noexcept +std::vector SQLiteLogbookDao::getFlightSummaries(const FlightSelector &flightSelector, bool *ok) const noexcept { - const QString LikeOperatorPlaceholder("%"); - std::vector summaries; + QString searchKeyword; if (!flightSelector.searchKeyword.isEmpty()) { + const QString LikeOperatorPlaceholder {"%"}; // Add like operator placeholders searchKeyword = LikeOperatorPlaceholder % flightSelector.searchKeyword % LikeOperatorPlaceholder; } @@ -135,8 +145,14 @@ std::vector SQLiteLogbookDao::getFlightSummaries(const FlightSele const QVariant engineTypeVariant = flightSelector.engineType != SimType::EngineType::All ? Enum::toUnderlyingType(flightSelector.engineType) : QVariant(); query.bindValue(":engine_type", engineTypeVariant); query.bindValue(":duration", flightSelector.mininumDurationMinutes); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + summaries.reserve(query.size()); + } else { + summaries.reserve(::DefaultSummaryCapacity); + } QSqlRecord record = query.record(); const int idIdx = record.indexOf("id"); const int creationTimeIdx = record.indexOf("creation_time"); @@ -169,13 +185,16 @@ std::vector SQLiteLogbookDao::getFlightSummaries(const FlightSele summary.endLocation = query.value(endWaypointIdx).toString(); summary.title = query.value(titleIdx).toString(); - summaries.push_back(summary); + summaries.push_back(std::move(summary)); } #ifdef DEBUG } else { - qDebug("SQLiteLogbookDao::getFlightSummaries: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteLogbookDao::getFlightSummaries: SQL error:" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } + if (ok != nullptr) { + *ok = success; + } return summaries; } diff --git a/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.h b/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.h index e9ae0bde2..0c4adb60c 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteLogbookDao.h @@ -28,24 +28,25 @@ #include #include #include -#include -#include - -#include #include "../LogbookDaoIntf.h" +struct FlightSelector; struct FlightDate; struct FlightSummary; class SQLiteLogbookDao : public LogbookDaoIntf { public: - SQLiteLogbookDao() noexcept; - ~SQLiteLogbookDao() noexcept override; + SQLiteLogbookDao() = default; + SQLiteLogbookDao(const SQLiteLogbookDao &rhs) = delete; + SQLiteLogbookDao(SQLiteLogbookDao &&rhs); + SQLiteLogbookDao &operator=(const SQLiteLogbookDao &rhs) = delete; + SQLiteLogbookDao &operator=(SQLiteLogbookDao &&rhs); + ~SQLiteLogbookDao() override; bool getFlightDates(std::front_insert_iterator> frontInsertIterator) const noexcept override; - std::vector getFlightSummaries(const FlightSelector &flightSelector) const noexcept override; + std::vector getFlightSummaries(const FlightSelector &flightSelector, bool *ok) const noexcept override; }; #endif // SQLITELOGBOOKDAO_H diff --git a/src/Persistence/src/Dao/SQLite/SQLitePositionDao.cpp b/src/Persistence/src/Dao/SQLite/SQLitePositionDao.cpp index d9c98d86f..f3b195f95 100644 --- a/src/Persistence/src/Dao/SQLite/SQLitePositionDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLitePositionDao.cpp @@ -32,18 +32,28 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include #include "SQLitePositionDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the position vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + // Samples at 30 Hz for an assumed flight duration of 2 * 60 seconds = 2 minutes + constexpr int DefaultCapacity = 30 * 2 * 60; +} -SQLitePositionDao::SQLitePositionDao() noexcept -{} +// PUBLIC -SQLitePositionDao::~SQLitePositionDao() noexcept -{} +SQLitePositionDao::SQLitePositionDao(SQLitePositionDao &&rhs) = default; +SQLitePositionDao &SQLitePositionDao::operator=(SQLitePositionDao &&rhs) = default; +SQLitePositionDao::~SQLitePositionDao() = default; bool SQLitePositionDao::add(std::int64_t aircraftId, const PositionData &position) noexcept { @@ -103,14 +113,15 @@ bool SQLitePositionDao::add(std::int64_t aircraftId, const PositionData &positio #ifdef DEBUG if (!ok) { - qDebug("SQLitePositionDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLitePositionDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLitePositionDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector positionData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -121,8 +132,14 @@ bool SQLitePositionDao::getByAircraftId(std::int64_t aircraftId, std::back_inser ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + positionData.reserve(query.size()); + } else { + positionData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int latitudeIdx = record.indexOf("latitude"); @@ -141,7 +158,6 @@ bool SQLitePositionDao::getByAircraftId(std::int64_t aircraftId, std::back_inser while (query.next()) { PositionData data; - data.timestamp = query.value(timestampIdx).toLongLong(); data.latitude = query.value(latitudeIdx).toDouble(); data.longitude = query.value(longitudeIdx).toDouble(); @@ -157,15 +173,18 @@ bool SQLitePositionDao::getByAircraftId(std::int64_t aircraftId, std::back_inser data.rotationVelocityBodyY = query.value(rotationVelocityYIdx).toDouble(); data.rotationVelocityBodyZ = query.value(rotationVelocityZIdx).toDouble(); - backInsertIterator = std::move(data); + positionData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLitePositionDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return positionData; } bool SQLitePositionDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -184,7 +203,7 @@ bool SQLitePositionDao::deleteByFlightId(std::int64_t flightId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLitePositionDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -203,7 +222,7 @@ bool SQLitePositionDao::deleteByAircraftId(std::int64_t aircraftId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLitePositionDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePositionDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLitePositionDao.h b/src/Persistence/src/Dao/SQLite/SQLitePositionDao.h index ec3186bf6..943e482c7 100644 --- a/src/Persistence/src/Dao/SQLite/SQLitePositionDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLitePositionDao.h @@ -27,20 +27,24 @@ #include #include -#include #include -#include #include "../PositionDaoIntf.h" +struct PositionData; + class SQLitePositionDao : public PositionDaoIntf { public: - SQLitePositionDao() noexcept; - ~SQLitePositionDao() noexcept override; + SQLitePositionDao() = default; + SQLitePositionDao(const SQLitePositionDao &rhs) = delete; + SQLitePositionDao(SQLitePositionDao &&rhs); + SQLitePositionDao &operator=(const SQLitePositionDao &rhs) = delete; + SQLitePositionDao &operator=(SQLitePositionDao &&rhs); + ~SQLitePositionDao() override; bool add(std::int64_t aircraftId, const PositionData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.cpp b/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.cpp index 11d561806..ad07f5470 100644 --- a/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.cpp @@ -24,7 +24,6 @@ */ #include #include -#include #include #include @@ -32,18 +31,28 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include #include "SQLitePrimaryFlightControlDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the primary flight control vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + // Samples at 30 Hz for an assumed flight duration of 2 * 60 seconds = 2 minutes + constexpr int DefaultCapacity = 30 * 2 * 60; +} -SQLitePrimaryFlightControlDao::SQLitePrimaryFlightControlDao() noexcept -{} +// PUBLIC -SQLitePrimaryFlightControlDao::~SQLitePrimaryFlightControlDao() noexcept -{} +SQLitePrimaryFlightControlDao::SQLitePrimaryFlightControlDao(SQLitePrimaryFlightControlDao &&rhs) = default; +SQLitePrimaryFlightControlDao &SQLitePrimaryFlightControlDao::operator=(SQLitePrimaryFlightControlDao &&rhs) = default; +SQLitePrimaryFlightControlDao::~SQLitePrimaryFlightControlDao() = default; bool SQLitePrimaryFlightControlDao::add(std::int64_t aircraftId, const PrimaryFlightControlData &primaryFlightControlData) noexcept { @@ -73,14 +82,15 @@ bool SQLitePrimaryFlightControlDao::add(std::int64_t aircraftId, const PrimaryFl const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLitePrimaryFlightControlDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePrimaryFlightControlDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLitePrimaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLitePrimaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector primaryFlightControlData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -91,8 +101,14 @@ bool SQLitePrimaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, std ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + primaryFlightControlData.reserve(query.size()); + } else { + primaryFlightControlData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int rudderPositionIdx = record.indexOf("rudder_position"); @@ -107,15 +123,18 @@ bool SQLitePrimaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, std data.elevatorPosition = query.value(elevatorPositionIdx).toDouble(); data.aileronPosition = query.value(aileronPositionIdx).toDouble(); - backInsertIterator = std::move(data); + primaryFlightControlData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLitePrimaryFlightControlDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePrimaryFlightControlDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return primaryFlightControlData; } bool SQLitePrimaryFlightControlDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -134,7 +153,7 @@ bool SQLitePrimaryFlightControlDao::deleteByFlightId(std::int64_t flightId) noex const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLitePrimaryFlightControlDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePrimaryFlightControlDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -153,7 +172,7 @@ bool SQLitePrimaryFlightControlDao::deleteByAircraftId(std::int64_t aircraftId) const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLitePrimaryFlightControlDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLitePrimaryFlightControlDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.h b/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.h index f578a132c..399753cbe 100644 --- a/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLitePrimaryFlightControlDao.h @@ -27,20 +27,24 @@ #include #include -#include #include -#include #include "../PrimaryFlightControlDaoIntf.h" +struct PrimaryFlightControlData; + class SQLitePrimaryFlightControlDao : public PrimaryFlightControlDaoIntf { public: - SQLitePrimaryFlightControlDao() noexcept; - ~SQLitePrimaryFlightControlDao() noexcept override; + SQLitePrimaryFlightControlDao() = default; + SQLitePrimaryFlightControlDao(const SQLitePrimaryFlightControlDao &rhs) = delete; + SQLitePrimaryFlightControlDao(SQLitePrimaryFlightControlDao &&rhs); + SQLitePrimaryFlightControlDao &operator=(const SQLitePrimaryFlightControlDao &rhs) = delete; + SQLitePrimaryFlightControlDao &operator=(SQLitePrimaryFlightControlDao &&rhs); + ~SQLitePrimaryFlightControlDao() override; bool add(std::int64_t aircraftId, const PrimaryFlightControlData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.cpp index 1b2db8593..73bff4433 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.cpp @@ -32,18 +32,28 @@ #include #include #include +#include +#ifdef DEBUG +#include +#endif #include #include #include "SQLiteSecondaryFlightControlDao.h" -// PUBLIC +namespace +{ + // The initial capacity of the secondary flight control vector (e.g. SQLite does not support returning + // the result count for the given SELECT query) + // Samples at 30 Hz for an assumed flight duration of 2 * 60 seconds = 2 minutes + constexpr int DefaultCapacity = 30 * 2 * 60; +} -SQLiteSecondaryFlightControlDao::SQLiteSecondaryFlightControlDao() noexcept -{} +// PUBLIC -SQLiteSecondaryFlightControlDao::~SQLiteSecondaryFlightControlDao() noexcept -{} +SQLiteSecondaryFlightControlDao::SQLiteSecondaryFlightControlDao(SQLiteSecondaryFlightControlDao &&rhs) = default; +SQLiteSecondaryFlightControlDao &SQLiteSecondaryFlightControlDao::operator=(SQLiteSecondaryFlightControlDao &&rhs) = default; +SQLiteSecondaryFlightControlDao::~SQLiteSecondaryFlightControlDao() = default; bool SQLiteSecondaryFlightControlDao::add(std::int64_t aircraftId, const SecondaryFlightControlData &secondaryFlightControlData) noexcept { @@ -82,14 +92,15 @@ bool SQLiteSecondaryFlightControlDao::add(std::int64_t aircraftId, const Seconda const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteSecondaryFlightControlDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteSecondaryFlightControlDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; } -bool SQLiteSecondaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector SQLiteSecondaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, bool *ok) const noexcept { + std::vector secondaryFlightControlData; QSqlQuery query; query.setForwardOnly(true); query.prepare( @@ -100,8 +111,14 @@ bool SQLiteSecondaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, s ); query.bindValue(":aircraft_id", QVariant::fromValue(aircraftId)); - const bool ok = query.exec(); - if (ok) { + const bool success = query.exec(); + if (success) { + const bool querySizeFeature = QSqlDatabase::database().driver()->hasFeature(QSqlDriver::QuerySize); + if (querySizeFeature) { + secondaryFlightControlData.reserve(query.size()); + } else { + secondaryFlightControlData.reserve(::DefaultCapacity); + } QSqlRecord record = query.record(); const int timestampIdx = record.indexOf("timestamp"); const int leadingEdgeFlapsLeftPercentIdx = record.indexOf("leading_edge_flaps_left_percent"); @@ -120,15 +137,18 @@ bool SQLiteSecondaryFlightControlDao::getByAircraftId(std::int64_t aircraftId, s data.spoilersHandlePosition = query.value(spoilersHandlePositionIdx).toInt(); data.flapsHandleIndex = query.value(flapsHandleIndexIdx).toInt(); - backInsertIterator = std::move(data); + secondaryFlightControlData.push_back(std::move(data)); } #ifdef DEBUG } else { - qDebug("SQLiteSecondaryFlightControlDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteSecondaryFlightControlDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } - return ok; + if (ok != nullptr) { + *ok = success; + } + return secondaryFlightControlData; } bool SQLiteSecondaryFlightControlDao::deleteByFlightId(std::int64_t flightId) noexcept @@ -147,7 +167,7 @@ bool SQLiteSecondaryFlightControlDao::deleteByFlightId(std::int64_t flightId) no const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteSecondaryFlightControlDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteSecondaryFlightControlDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -166,7 +186,7 @@ bool SQLiteSecondaryFlightControlDao::deleteByAircraftId(std::int64_t aircraftId const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteSecondaryFlightControlDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteSecondaryFlightControlDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.h b/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.h index 6030785f2..6565a0663 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteSecondaryFlightControlDao.h @@ -27,20 +27,24 @@ #include #include -#include #include -#include #include "../SecondaryFlightControlDaoIntf.h" +struct SecondaryFlightControlData; + class SQLiteSecondaryFlightControlDao : public SecondaryFlightControlDaoIntf { public: - SQLiteSecondaryFlightControlDao() noexcept; - ~SQLiteSecondaryFlightControlDao() noexcept override; + SQLiteSecondaryFlightControlDao() = default; + SQLiteSecondaryFlightControlDao(const SQLiteSecondaryFlightControlDao &rhs) = delete; + SQLiteSecondaryFlightControlDao(SQLiteSecondaryFlightControlDao &&rhs); + SQLiteSecondaryFlightControlDao &operator=(const SQLiteSecondaryFlightControlDao &rhs) = delete; + SQLiteSecondaryFlightControlDao &operator=(SQLiteSecondaryFlightControlDao &&rhs); + ~SQLiteSecondaryFlightControlDao() override; bool add(std::int64_t aircraftId, const SecondaryFlightControlData &data) noexcept override; - bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept override; + std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept override; bool deleteByFlightId(std::int64_t flightId) noexcept override; bool deleteByAircraftId(std::int64_t aircraftId) noexcept override; }; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.cpp b/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.cpp index e6fb40ee0..90792d7f4 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.cpp +++ b/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.cpp @@ -32,6 +32,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -39,11 +42,9 @@ // PUBLIC -SQLiteWaypointDao::SQLiteWaypointDao() noexcept -{} - -SQLiteWaypointDao::~SQLiteWaypointDao() noexcept -{} +SQLiteWaypointDao::SQLiteWaypointDao(SQLiteWaypointDao &&rhs) = default; +SQLiteWaypointDao &SQLiteWaypointDao::operator=(SQLiteWaypointDao &&rhs) = default; +SQLiteWaypointDao::~SQLiteWaypointDao() = default; bool SQLiteWaypointDao::add(std::int64_t aircraftId, const FlightPlan &flightPlan) noexcept { @@ -86,7 +87,7 @@ bool SQLiteWaypointDao::add(std::int64_t aircraftId, const FlightPlan &flightPla ok = query.exec(); if (!ok) { #ifdef DEBUG - qDebug("SQLiteWaypointDao::add: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteWaypointDao::add: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif break; } @@ -130,7 +131,7 @@ bool SQLiteWaypointDao::getByAircraftId(std::int64_t aircraftId, FlightPlan &fli } #ifdef DEBUG } else { - qDebug("SQLiteWaypointDao::getByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteWaypointDao::getByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); #endif } @@ -153,7 +154,7 @@ bool SQLiteWaypointDao::deleteByFlightId(std::int64_t flightId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteWaypointDao::deleteByFlightId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteWaypointDao::deleteByFlightId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return ok; @@ -172,7 +173,7 @@ bool SQLiteWaypointDao::deleteByAircraftId(std::int64_t aircraftId) noexcept const bool ok = query.exec(); #ifdef DEBUG if (!ok) { - qDebug("SQLiteWaypointDao::deleteByAircraftId: SQL error: %s", qPrintable(query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode())); + qDebug() << "SQLiteWaypointDao::deleteByAircraftId: SQL error" << query.lastError().databaseText() << "- error code:" << query.lastError().nativeErrorCode(); } #endif return true; diff --git a/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.h b/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.h index 41d33c434..0adb76fe8 100644 --- a/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.h +++ b/src/Persistence/src/Dao/SQLite/SQLiteWaypointDao.h @@ -36,8 +36,12 @@ class FlightPlan; class SQLiteWaypointDao : public WaypointDaoIntf { public: - SQLiteWaypointDao() noexcept; - ~SQLiteWaypointDao() noexcept override; + SQLiteWaypointDao() = default; + SQLiteWaypointDao(const SQLiteWaypointDao &rhs) = delete; + SQLiteWaypointDao(SQLiteWaypointDao &&rhs); + SQLiteWaypointDao &operator=(const SQLiteWaypointDao &rhs) = delete; + SQLiteWaypointDao &operator=(SQLiteWaypointDao &&rhs); + ~SQLiteWaypointDao() override; bool add(std::int64_t aircraftId, const FlightPlan &flightPlan) noexcept override; bool getByAircraftId(std::int64_t aircraftId, FlightPlan &flightPlan) const noexcept override; diff --git a/src/Persistence/src/Dao/SQLite/SqlMigration.cpp b/src/Persistence/src/Dao/SQLite/SqlMigration.cpp index 2dcd83483..4d263c15d 100644 --- a/src/Persistence/src/Dao/SQLite/SqlMigration.cpp +++ b/src/Persistence/src/Dao/SQLite/SqlMigration.cpp @@ -30,9 +30,6 @@ #include #include #include -#ifdef DEBUG -#include -#endif #include #include @@ -43,8 +40,6 @@ namespace { - constexpr char MigrationDirectory[] = "Resources/migr"; - // Also refer to Locations.csv constexpr int TitleIndex = 1; constexpr int DescriptionIndex = 2; @@ -62,9 +57,8 @@ namespace constexpr int AttributesIndex = 14; } -class SqlMigrationPrivate +struct SqlMigrationPrivate { -public: SqlMigrationPrivate() {} @@ -74,21 +68,15 @@ class SqlMigrationPrivate // PUBLIC -SqlMigration::SqlMigration() +SqlMigration::SqlMigration() noexcept : d(std::make_unique()) { Q_INIT_RESOURCE(Migration); -#ifdef DEBUG - qDebug() << "SqlMigration::SqlMigration: CREATED"; -#endif } -SqlMigration::~SqlMigration() -{ -#ifdef DEBUG - qDebug() << "SqlMigration::~SqlMigration: DELETED"; -#endif -} +SqlMigration::SqlMigration(SqlMigration &&rhs) = default; +SqlMigration &SqlMigration::operator=(SqlMigration &&rhs) = default; +SqlMigration::~SqlMigration() = default; bool SqlMigration::migrate() noexcept { @@ -137,7 +125,7 @@ bool SqlMigration::migrateSql(const QString &migrationFilePath) noexcept const QRegularExpressionMatch tagMatch = it.next(); QString tag = tagMatch.captured(1); #ifdef DEBUG - qDebug("SqlMigration::migrate: %s", qPrintable(tag)); + qDebug() << "SqlMigration::migrate:" << tag; #endif SqlMigrationStep step; ok = step.parseTag(tagMatch); @@ -222,19 +210,16 @@ bool SqlMigration::migrateLocation(const QRegularExpressionMatch &locationMatch) Location location; location.title = locationMatch.captured(::TitleIndex); location.description = locationMatch.captured(::DescriptionIndex).replace("\\n", "\n"); - Enumeration locationType(EnumerationService::LocationType); - ok = d->enumerationService.getEnumerationByName(locationType); + Enumeration locationType = d->enumerationService.getEnumerationByName(EnumerationService::LocationType, &ok); if (ok) { location.typeId = locationType.getItemBySymbolicId(EnumerationService::LocationTypeSystemSymbolicId).id; } - Enumeration locationCategory(EnumerationService::LocationCategory); - ok = d->enumerationService.getEnumerationByName(locationCategory); + Enumeration locationCategory = d->enumerationService.getEnumerationByName(EnumerationService::LocationCategory, &ok); if (ok) { const QString categorySymbolicId = locationMatch.captured(::CategoryIndex); location.categoryId = locationCategory.getItemBySymbolicId(categorySymbolicId).id; } - Enumeration country(EnumerationService::Country); - ok = d->enumerationService.getEnumerationByName(country); + Enumeration country = d->enumerationService.getEnumerationByName(EnumerationService::Country, &ok); if (ok) { const QString countrySymbolicId = locationMatch.captured(::CountryIndex); location.countryId = country.getItemBySymbolicId(countrySymbolicId).id; diff --git a/src/Persistence/src/Dao/SQLite/SqlMigration.h b/src/Persistence/src/Dao/SQLite/SqlMigration.h index 6270af4fb..7b5b4fb9c 100644 --- a/src/Persistence/src/Dao/SQLite/SqlMigration.h +++ b/src/Persistence/src/Dao/SQLite/SqlMigration.h @@ -31,12 +31,16 @@ class QRegularExpressionMatch; -class SqlMigrationPrivate; +struct SqlMigrationPrivate; class SqlMigration { public: - SqlMigration(); + SqlMigration() noexcept; + SqlMigration(const SqlMigration &rhs) = delete; + SqlMigration(SqlMigration &&rhs); + SqlMigration &operator=(const SqlMigration &rhs) = delete; + SqlMigration &operator=(SqlMigration &&rhs); ~SqlMigration(); bool migrate() noexcept; diff --git a/src/Persistence/src/Dao/SQLite/SqlMigrationStep.cpp b/src/Persistence/src/Dao/SQLite/SqlMigrationStep.cpp index 3dc086267..9a8cf0ffb 100644 --- a/src/Persistence/src/Dao/SQLite/SqlMigrationStep.cpp +++ b/src/Persistence/src/Dao/SQLite/SqlMigrationStep.cpp @@ -32,12 +32,14 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include "SqlMigrationStep.h" -class SqlMigrationStepPrivate +struct SqlMigrationStepPrivate { -public: SqlMigrationStepPrivate() {} @@ -51,12 +53,13 @@ class SqlMigrationStepPrivate // PUBLIC -SqlMigrationStep::SqlMigrationStep() +SqlMigrationStep::SqlMigrationStep() noexcept : d(std::make_unique()) {} -SqlMigrationStep::~SqlMigrationStep() -{} +SqlMigrationStep::SqlMigrationStep(SqlMigrationStep &&rhs) = default; +SqlMigrationStep &SqlMigrationStep::operator=(SqlMigrationStep &&rhs) = default; +SqlMigrationStep::~SqlMigrationStep() = default; bool SqlMigrationStep::isValid() const noexcept { @@ -65,7 +68,7 @@ bool SqlMigrationStep::isValid() const noexcept bool SqlMigrationStep::parseTag(const QRegularExpressionMatch &tagMatch) noexcept { - bool ok; + const QString tag = tagMatch.captured(1); // Match the tag's content, e.g. id = 42, descn = "The description", step = 1 @@ -73,7 +76,7 @@ bool SqlMigrationStep::parseTag(const QRegularExpressionMatch &tagMatch) noexcep static const QRegularExpression tagRegExp(R"(([\w]+)\s*=\s*["]*([\w\s\-]+)["]*)"); QRegularExpressionMatchIterator it = tagRegExp.globalMatch(tag); - ok = true; + bool ok {true}; while (ok && it.hasNext()) { QRegularExpressionMatch match = it.next(); @@ -129,8 +132,7 @@ bool SqlMigrationStep::execute(QStringView sql) noexcept QRegularExpressionMatch match = it.next(); #ifdef DEBUG - qDebug("SqlMigrationStep::execute: SQL: %s\n", qPrintable(match.captured(1).toUtf8())); - qDebug("\n"); + qDebug() << "SqlMigrationStep::execute: SQL:" << match.captured(1) << "\n\n"; #endif QSqlQuery query; ok = query.exec(match.captured(1).trimmed() % ";"); @@ -138,7 +140,7 @@ bool SqlMigrationStep::execute(QStringView sql) noexcept errorMessage = query.lastError().databaseText() + " - error code: " + query.lastError().nativeErrorCode(); QSqlDatabase::database().rollback(); #ifdef DEBUG - qDebug("SqlMigrationStep::execute: FAILED:\n%s\n", qPrintable(errorMessage)); + qDebug() << "SqlMigrationStep::execute: FAILED:\n" << errorMessage; #endif } } @@ -166,7 +168,7 @@ void SqlMigrationStep::registerMigration(bool success, QString errorMessage) noe ok = QSqlDatabase::database().commit(); } else { #ifdef DEBUG - qDebug("SqlMigrationStep::registerMigration: update MIGR table FAILED:\n%s\n", qPrintable(migrQuery.lastError().databaseText() + " - error code: " + migrQuery.lastError().nativeErrorCode())); + qDebug() << "SqlMigrationStep::registerMigration: update MIGR table FAILED:\n" << migrQuery.lastError().databaseText() << "- error code:" << migrQuery.lastError().nativeErrorCode(); #endif QSqlDatabase::database().rollback(); } @@ -193,14 +195,14 @@ void SqlMigrationStep::registerMigration(bool success, QString errorMessage) noe QSqlDatabase::database().commit(); } else { #ifdef DEBUG - qDebug("SqlMigrationStep::registerMigration: update MIGR table FAILED:\n%s\n", qPrintable(migrQuery.lastError().databaseText() + " - error code: " + migrQuery.lastError().nativeErrorCode())); + qDebug() << "SqlMigrationStep::registerMigration: update MIGR table FAILED:\n" << migrQuery.lastError().databaseText() << "- error code:" << migrQuery.lastError().nativeErrorCode(); #endif QSqlDatabase::database().rollback(); } } #ifdef DEBUG else { - qDebug("SqlMigrationStep::registerMigration: FAILED to create transaction."); + qDebug() << "SqlMigrationStep::registerMigration: FAILED to create transaction."; } #endif } diff --git a/src/Persistence/src/Dao/SQLite/SqlMigrationStep.h b/src/Persistence/src/Dao/SQLite/SqlMigrationStep.h index 3582da331..f51bfa761 100644 --- a/src/Persistence/src/Dao/SQLite/SqlMigrationStep.h +++ b/src/Persistence/src/Dao/SQLite/SqlMigrationStep.h @@ -34,12 +34,16 @@ class QRegularExpressionMatch; class QStringRef; -class SqlMigrationStepPrivate; +struct SqlMigrationStepPrivate; class SqlMigrationStep { public: - SqlMigrationStep(); + SqlMigrationStep() noexcept; + SqlMigrationStep(const SqlMigrationStep &rhs) = delete; + SqlMigrationStep(SqlMigrationStep &&rhs); + SqlMigrationStep &operator=(const SqlMigrationStep &rhs) = delete; + SqlMigrationStep &operator=(SqlMigrationStep &&rhs); ~SqlMigrationStep(); bool isValid() const noexcept; diff --git a/src/Persistence/src/Dao/SQLite/migr/LogbookMigration.sql b/src/Persistence/src/Dao/SQLite/migr/LogbookMigration.sql index d59ed7bb9..2083467c5 100644 --- a/src/Persistence/src/Dao/SQLite/migr/LogbookMigration.sql +++ b/src/Persistence/src/Dao/SQLite/migr/LogbookMigration.sql @@ -675,3 +675,7 @@ alter table position rename heading to true_heading; @migr(id = "c94c121e-3d93-44e4-a747-6db2b5e3b45b", descn = "Update application version to 0.12", step = 1) update metadata set app_version = '0.12.0'; + +@migr(id = "d7f115b0-8bd1-40f7-9098-5481878f5f6d", descn = "Update application version to 0.13", step = 1) +update metadata +set app_version = '0.13.0'; diff --git a/src/Persistence/src/Dao/SecondaryFlightControlDaoIntf.h b/src/Persistence/src/Dao/SecondaryFlightControlDaoIntf.h index de71524bb..7301d3c46 100644 --- a/src/Persistence/src/Dao/SecondaryFlightControlDaoIntf.h +++ b/src/Persistence/src/Dao/SecondaryFlightControlDaoIntf.h @@ -26,7 +26,6 @@ #define SECONDARYFLIGHTCONTROLDAOINTF_H #include -#include #include struct SecondaryFlightControlData; @@ -34,6 +33,11 @@ struct SecondaryFlightControlData; class SecondaryFlightControlDaoIntf { public: + SecondaryFlightControlDaoIntf() = default; + SecondaryFlightControlDaoIntf(const SecondaryFlightControlDaoIntf &rhs) = delete; + SecondaryFlightControlDaoIntf(SecondaryFlightControlDaoIntf &&rhs) = default; + SecondaryFlightControlDaoIntf &operator=(const SecondaryFlightControlDaoIntf &rhs) = delete; + SecondaryFlightControlDaoIntf &operator=(SecondaryFlightControlDaoIntf &&rhs) = default; virtual ~SecondaryFlightControlDaoIntf() = default; /*! @@ -46,7 +50,7 @@ class SecondaryFlightControlDaoIntf * \return \c true on success; \c false else */ virtual bool add(std::int64_t aircraftId, const SecondaryFlightControlData &data) noexcept = 0; - virtual bool getByAircraftId(std::int64_t aircraftId, std::back_insert_iterator> backInsertIterator) const noexcept = 0; + virtual std::vector getByAircraftId(std::int64_t aircraftId, bool *ok = nullptr) const noexcept = 0; virtual bool deleteByFlightId(std::int64_t flightId) noexcept = 0; virtual bool deleteByAircraftId(std::int64_t aircraftId) noexcept = 0; }; diff --git a/src/Persistence/src/Dao/WaypointDaoIntf.h b/src/Persistence/src/Dao/WaypointDaoIntf.h index 1fa4f6336..8204130f4 100644 --- a/src/Persistence/src/Dao/WaypointDaoIntf.h +++ b/src/Persistence/src/Dao/WaypointDaoIntf.h @@ -33,6 +33,11 @@ class Waypoint; class WaypointDaoIntf { public: + WaypointDaoIntf() = default; + WaypointDaoIntf(const WaypointDaoIntf &rhs) = delete; + WaypointDaoIntf(WaypointDaoIntf &&rhs) = default; + WaypointDaoIntf &operator=(const WaypointDaoIntf &rhs) = delete; + WaypointDaoIntf &operator=(WaypointDaoIntf &&rhs) = default; virtual ~WaypointDaoIntf() = default; /*! diff --git a/src/Persistence/src/FlightSelector.cpp b/src/Persistence/src/FlightSelector.cpp deleted file mode 100644 index 8296d5b37..000000000 --- a/src/Persistence/src/FlightSelector.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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 "FlightSelector.h" - -// PUBLIC - -FlightSelector::FlightSelector() - : fromDate(MinDate), - toDate(MaxDate), - hasFormation(false), - engineType(SimType::EngineType::All), - mininumDurationMinutes(0) -{} diff --git a/src/Persistence/src/LocationSelector.cpp b/src/Persistence/src/LocationSelector.cpp deleted file mode 100644 index 2233816ff..000000000 --- a/src/Persistence/src/LocationSelector.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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 "LocationSelector.h" - -// PUBLIC - -LocationSelector::LocationSelector() -{} diff --git a/src/Persistence/src/PersistedEnumerationItem.cpp b/src/Persistence/src/PersistedEnumerationItem.cpp index ced9ca44c..49b263762 100644 --- a/src/Persistence/src/PersistedEnumerationItem.cpp +++ b/src/Persistence/src/PersistedEnumerationItem.cpp @@ -26,10 +26,8 @@ #include #include -#ifdef DEBUG -#include -#endif +#include #include #include #include "Service/EnumerationService.h" @@ -38,34 +36,28 @@ struct PersistedEnumerationItemPrivate { PersistedEnumerationItemPrivate(QString enumerationName, QString symbolicId) - : enumeration(enumerationName) { - if (enumerationService.getEnumerationByName(enumeration)) { + bool ok {false}; + enumeration = enumerationService.getEnumerationByName(enumerationName, &ok); + if (ok) { id = enumeration.getItemBySymbolicId(symbolicId).id; } } Enumeration enumeration; - std::int64_t id {Data::InvalidId}; + std::int64_t id {Const::InvalidId}; EnumerationService enumerationService; }; // PUBLIC +PersistedEnumerationItem::PersistedEnumerationItem(PersistedEnumerationItem &&rhs) = default; +PersistedEnumerationItem &PersistedEnumerationItem::operator=(PersistedEnumerationItem &&rhs) = default; +PersistedEnumerationItem::~PersistedEnumerationItem() = default; + PersistedEnumerationItem::PersistedEnumerationItem(QString enumerationName, QString symbolicId) noexcept : d(std::make_unique(enumerationName, symbolicId)) -{ -#ifdef DEBUG - qDebug() << "PersistedEnumerationItem::PersistedEnumerationItem: CREATED, name:" << enumerationName << "ID:" << d->id; -#endif -} - -PersistedEnumerationItem::~PersistedEnumerationItem() noexcept -{ -#ifdef DEBUG - qDebug() << "PersistedEnumerationItem::~PersistedEnumerationItem: DELETED, name:" << d->enumeration.getName() << "ID:" << d->id; -#endif -} +{} std::int64_t PersistedEnumerationItem::id() const noexcept { diff --git a/src/Persistence/src/LogbookManager.cpp b/src/Persistence/src/PersistenceManager.cpp similarity index 72% rename from src/Persistence/src/LogbookManager.cpp rename to src/Persistence/src/PersistenceManager.cpp index e78a50d98..7e63d1417 100644 --- a/src/Persistence/src/LogbookManager.cpp +++ b/src/Persistence/src/PersistenceManager.cpp @@ -23,8 +23,11 @@ * DEALINGS IN THE SOFTWARE. */ #include +#include +#include #include +#include #include #include #include @@ -44,16 +47,15 @@ #include "Dao/DaoFactory.h" #include "Dao/DatabaseDaoIntf.h" #include "Service/DatabaseService.h" -#include "LogbookManager.h" +#include "PersistenceManager.h" namespace { constexpr int MaxBackupIndex = 1024; } -class LogbookManagerPrivate +struct PersistenceManagerPrivate { -public: - LogbookManagerPrivate() noexcept + PersistenceManagerPrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), databaseDao(daoFactory->createDatabaseDao()), connected(false) @@ -64,33 +66,33 @@ class LogbookManagerPrivate QString logbookPath; bool connected; - static LogbookManager *instance; + static inline std::once_flag onceFlag; + static inline PersistenceManager *instance; }; -LogbookManager *LogbookManagerPrivate::instance = nullptr; // PUBLIC -LogbookManager &LogbookManager::getInstance() noexcept +PersistenceManager &PersistenceManager::getInstance() noexcept { - if (LogbookManagerPrivate::instance == nullptr) { - LogbookManagerPrivate::instance = new LogbookManager(); - } - return *LogbookManagerPrivate::instance; + std::call_once(PersistenceManagerPrivate::onceFlag, []() { + PersistenceManagerPrivate::instance = new PersistenceManager(); + }); + return *PersistenceManagerPrivate::instance; } -void LogbookManager::destroyInstance() noexcept +void PersistenceManager::destroyInstance() noexcept { - if (LogbookManagerPrivate::instance != nullptr) { - delete LogbookManagerPrivate::instance; - LogbookManagerPrivate::instance = nullptr; + if (PersistenceManagerPrivate::instance != nullptr) { + delete PersistenceManagerPrivate::instance; + PersistenceManagerPrivate::instance = nullptr; } } -bool LogbookManager::connectWithLogbook(const QString &logbookPath, QWidget *parent) noexcept +bool PersistenceManager::connectWithLogbook(const QString &logbookPath, QWidget *parent) noexcept { QString currentLogbookPath = logbookPath; - bool ok = true; + bool ok {true}; bool retry = true; while (retry && ok) { const QString logbookDirectoryPath = QFileInfo(currentLogbookPath).absolutePath(); @@ -106,8 +108,8 @@ bool LogbookManager::connectWithLogbook(const QString &logbookPath, QWidget *par } ok = connectDb(currentLogbookPath); if (ok) { - Version databaseVersion; - ok = checkDatabaseVersion(databaseVersion); + const auto & [success, databaseVersion] = checkDatabaseVersion(); + ok = success; if (ok) { Settings &settings = Settings::getInstance(); Flight &flight = Logbook::getInstance().getCurrentFlight(); @@ -115,8 +117,7 @@ bool LogbookManager::connectWithLogbook(const QString &logbookPath, QWidget *par // Create a backup before migration of existing logbooks Version appVersion; if (!databaseVersion.isNull() && settings.isBackupBeforeMigrationEnabled() && databaseVersion < appVersion) { - QString backupDirectoryPath; - ok = d->databaseDao->getBackupDirectoryPath(backupDirectoryPath); + QString backupDirectoryPath = d->databaseDao->getBackupDirectoryPath(&ok); if (ok) { if (backupDirectoryPath.isNull()) { // Default backup location, relative to logbook path @@ -187,7 +188,7 @@ bool LogbookManager::connectWithLogbook(const QString &logbookPath, QWidget *par return ok; } -void LogbookManager::disconnectFromLogbook() noexcept +void PersistenceManager::disconnectFromLogbook() noexcept { d->databaseDao->disconnectDb(); d->logbookPath.clear(); @@ -195,62 +196,66 @@ void LogbookManager::disconnectFromLogbook() noexcept emit connectionChanged(d->connected); } -bool LogbookManager::isConnected() const noexcept +bool PersistenceManager::isConnected() const noexcept { return d->connected; } -const QString &LogbookManager::getLogbookPath() const noexcept +const QString &PersistenceManager::getLogbookPath() const noexcept { return d->logbookPath; } -bool LogbookManager::migrate() noexcept +bool PersistenceManager::migrate() noexcept { return d->databaseDao->migrate(); } -bool LogbookManager::optimise() noexcept +bool PersistenceManager::optimise() noexcept { return d->databaseDao->optimise(); } -bool LogbookManager::backup(const QString &backupLogbookPath) noexcept +bool PersistenceManager::backup(const QString &backupLogbookPath) noexcept { return d->databaseDao->backup(backupLogbookPath); } -bool LogbookManager::getMetadata(Metadata &metadata) const noexcept +Metadata PersistenceManager::getMetadata(bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->databaseDao->getMetadata(metadata); + Metadata metadata; + bool success = QSqlDatabase::database().transaction(); + if (success) { + metadata = d->databaseDao->getMetadata(&success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return metadata; } -bool LogbookManager::getDatabaseVersion(Version &databaseVersion) const noexcept +Version PersistenceManager::getDatabaseVersion(bool *ok) const noexcept { - return d->databaseDao->getDatabaseVersion(databaseVersion); + return d->databaseDao->getDatabaseVersion(ok); } -bool LogbookManager::getBackupDirectoryPath(QString &backupDirectoryPath) const noexcept +QString PersistenceManager::getBackupDirectoryPath(bool *ok) const noexcept { - return d->databaseDao->getBackupDirectoryPath(backupDirectoryPath); + return d->databaseDao->getBackupDirectoryPath(ok); } -QString LogbookManager::getBackupFileName(const QString &backupDirectoryPath) const noexcept +QString PersistenceManager::getBackupFileName(const QString &backupDirectoryPath) const noexcept { QDir backupDir(backupDirectoryPath); const QString &logbookPath = getLogbookPath(); const QFileInfo logbookInfo = QFileInfo(logbookPath); const QString baseName = logbookInfo.completeBaseName(); const QString baseBackupLogbookName = baseName + "-" + QDateTime::currentDateTime().toString("yyyy-MM-dd hhmm"); - QString backupLogbookName = baseBackupLogbookName + Const::LogbookExtension; + QString backupLogbookName = baseBackupLogbookName % Const::LogbookExtension; int index = 1; while (backupDir.exists(backupLogbookName) && index <= MaxBackupIndex) { - backupLogbookName = baseBackupLogbookName + QString("-%1").arg(index) + Const::LogbookExtension; + backupLogbookName = baseBackupLogbookName % QString("-%1").arg(index) % Const::LogbookExtension; ++index; } if (index <= MaxBackupIndex) { @@ -260,12 +265,12 @@ QString LogbookManager::getBackupFileName(const QString &backupDirectoryPath) co } } -QString LogbookManager::createBackupPathIfNotExists(const QString &relativeOrAbsoluteBackupDirectoryPath) noexcept +QString PersistenceManager::createBackupPathIfNotExists(const QString &relativeOrAbsoluteBackupDirectoryPath) noexcept { QString existingBackupPath; if (QDir::isRelativePath(relativeOrAbsoluteBackupDirectoryPath)) { - const LogbookManager &LogbookManager = LogbookManager::getInstance(); - const QString &logbookDirectoryPath = QFileInfo(LogbookManager.getLogbookPath()).absolutePath(); + const PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + const QString &logbookDirectoryPath = QFileInfo(persistenceManager.getLogbookPath()).absolutePath(); existingBackupPath = logbookDirectoryPath + "/" + QFileInfo(relativeOrAbsoluteBackupDirectoryPath).fileName(); } else { existingBackupPath = relativeOrAbsoluteBackupDirectoryPath; @@ -281,49 +286,46 @@ QString LogbookManager::createBackupPathIfNotExists(const QString &relativeOrAbs return existingBackupPath; } -// PROTECTED +// PRIVATE -LogbookManager::~LogbookManager() noexcept +PersistenceManager::PersistenceManager() noexcept + : QObject(), + d(std::make_unique()) { - disconnectFromLogbook(); #ifdef DEBUG - qDebug() << "LogbookManager::~LogbookManager: DELETED"; + qDebug() << "PersistenceManager::PersistenceManager: CREATED"; #endif } -// PRIVATE - -LogbookManager::LogbookManager() noexcept - : QObject(), - d(std::make_unique()) +PersistenceManager::~PersistenceManager() { + disconnectFromLogbook(); #ifdef DEBUG - qDebug() << "LogbookManager::LogbookManager: CREATED"; + qDebug() << "PersistenceManager::~PersistenceManager: DELETED"; #endif } -bool LogbookManager::connectDb(const QString &logbookPath) noexcept +bool PersistenceManager::connectDb(const QString &logbookPath) noexcept { - bool ok; + bool ok {true}; if (d->logbookPath != logbookPath) { ok = d->databaseDao->connectDb(logbookPath); d->logbookPath = logbookPath; - } else { - ok = false; } return ok; } -bool LogbookManager::checkDatabaseVersion(Version &databaseVersion) const noexcept +std::pair PersistenceManager::checkDatabaseVersion() const noexcept { - Version currentAppVersion; - bool ok = getDatabaseVersion(databaseVersion); - if (ok) { - ok = currentAppVersion >= databaseVersion; + std::pair result; + result.second = getDatabaseVersion(&result.first); + if (result.first) { + Version currentAppVersion; + result.first = currentAppVersion >= result.second; } else { // New database - no metadata exists yet - ok = true; - databaseVersion = Version(0, 0, 0); + result.first = true; + result.second = Version(0, 0, 0); } - return ok; + return result; } diff --git a/src/Persistence/src/Service/AircraftService.cpp b/src/Persistence/src/Service/AircraftService.cpp index 5e118f96c..b15f4302f 100644 --- a/src/Persistence/src/Service/AircraftService.cpp +++ b/src/Persistence/src/Service/AircraftService.cpp @@ -29,6 +29,7 @@ #include +#include #include #include #include "../Dao/FlightDaoIntf.h" @@ -36,7 +37,7 @@ #include "../Dao/AircraftDaoIntf.h" #include -class AircraftServicePrivate +struct AircraftServicePrivate { public: AircraftServicePrivate() noexcept @@ -54,18 +55,11 @@ class AircraftServicePrivate AircraftService::AircraftService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("AircraftService::AircraftService: CREATED."); -#endif -} +{} -AircraftService::~AircraftService() noexcept -{ -#ifdef DEBUG - qDebug("AircraftService::~AircraftService: DELETED."); -#endif -} +AircraftService::AircraftService(AircraftService &&rhs) = default; +AircraftService &AircraftService::operator=(AircraftService &&rhs) = default; +AircraftService::~AircraftService() = default; bool AircraftService::store(std::int64_t flightId, std::size_t sequenceNumber, Aircraft &aircraft) noexcept { @@ -93,7 +87,7 @@ bool AircraftService::deleteByIndex(int index) noexcept Flight &flight = Logbook::getInstance().getCurrentFlight(); const std::int64_t aircraftId = flight.deleteAircraftByIndex(index); bool ok {true}; - if (aircraftId != Aircraft::InvalidId) { + if (aircraftId != Const::InvalidId) { ok = QSqlDatabase::database().transaction(); if (ok) { ok = d->aircraftDao->deleteById(aircraftId); @@ -102,7 +96,7 @@ bool AircraftService::deleteByIndex(int index) noexcept } if (ok) { // Sequence numbers start at 1 - ok = d->aircraftDao->adjustAircraftSequenceNumbersByFlightId(flight.getId(), index + 1); + ok = d->aircraftDao->adjustAircraftSequenceNumbersByFlightId(flight.getId(), static_cast(index) + 1); } if (ok) { ok = QSqlDatabase::database().commit(); @@ -114,14 +108,18 @@ bool AircraftService::deleteByIndex(int index) noexcept return ok; } -bool AircraftService::getAircraftInfos(std::int64_t flightId, std::vector &aircraftInfos) const noexcept +std::vector AircraftService::getAircraftInfos(std::int64_t flightId, bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->aircraftDao->getAircraftInfosByFlightId(flightId, aircraftInfos); + std::vector aircraftInfos; + bool success = QSqlDatabase::database().transaction(); + if (success) { + aircraftInfos = d->aircraftDao->getAircraftInfosByFlightId(flightId, &success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftInfos; } bool AircraftService::changeTimeOffset(Aircraft &aircraft, std::int64_t newOffset) noexcept diff --git a/src/Persistence/src/Service/AircraftTypeService.cpp b/src/Persistence/src/Service/AircraftTypeService.cpp index d09253b2f..7a89f8e41 100644 --- a/src/Persistence/src/Service/AircraftTypeService.cpp +++ b/src/Persistence/src/Service/AircraftTypeService.cpp @@ -34,9 +34,8 @@ #include "../Dao/AircraftTypeDaoIntf.h" #include -class AircraftTypeServicePrivate +struct AircraftTypeServicePrivate { -public: AircraftTypeServicePrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), aircraftTypeDao(daoFactory->createAircraftTypeDao()) @@ -50,37 +49,38 @@ class AircraftTypeServicePrivate AircraftTypeService::AircraftTypeService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("AircraftTypeService::AircraftTypeService: CREATED."); -#endif -} +{} -AircraftTypeService::~AircraftTypeService() noexcept -{ -#ifdef DEBUG - qDebug("AircraftTypeService::~AircraftTypeService: DELETED."); -#endif -} +AircraftTypeService::AircraftTypeService(AircraftTypeService &&rhs) = default; +AircraftTypeService &AircraftTypeService::operator=(AircraftTypeService &&rhs) = default; +AircraftTypeService::~AircraftTypeService() = default; -bool AircraftTypeService::getByType(const QString &type, AircraftType &aircraftType) const noexcept +AircraftType AircraftTypeService::getByType(const QString &type, bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->aircraftTypeDao->getByType(type, aircraftType); + AircraftType aircraftType; + bool success = QSqlDatabase::database().transaction(); + if (success) { + aircraftType = d->aircraftTypeDao->getByType(type, &success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftType; } -bool AircraftTypeService::getAll(std::back_insert_iterator> backInsertIterator) const noexcept +std::vector AircraftTypeService::getAll(bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->aircraftTypeDao->getAll(backInsertIterator); + std::vector aircraftTypes; + bool success = QSqlDatabase::database().transaction(); + if (success) { + aircraftTypes = d->aircraftTypeDao->getAll(&success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return aircraftTypes; } bool AircraftTypeService::exists(const QString &type) const noexcept diff --git a/src/Persistence/src/Service/DatabaseService.cpp b/src/Persistence/src/Service/DatabaseService.cpp index 3792afe79..184a55760 100644 --- a/src/Persistence/src/Service/DatabaseService.cpp +++ b/src/Persistence/src/Service/DatabaseService.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include #include @@ -38,7 +40,7 @@ #include #include #include -#include +#include #include "../Dao/DaoFactory.h" #include "../Dao/DatabaseDaoIntf.h" #include @@ -51,7 +53,7 @@ namespace constexpr int BackupPeriodOneDay = 1; } -class DatabaseServicePrivate +struct DatabaseServicePrivate { public: DatabaseServicePrivate() noexcept @@ -67,35 +69,28 @@ class DatabaseServicePrivate DatabaseService::DatabaseService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("DatabaseService::DatabaseService: CREATED."); -#endif -} +{} -DatabaseService::~DatabaseService() noexcept -{ -#ifdef DEBUG - qDebug("DatabaseService::~DatabaseService: DELETED."); -#endif -} +DatabaseService::DatabaseService(DatabaseService &&rhs) = default; +DatabaseService &DatabaseService::operator=(DatabaseService &&rhs) = default; +DatabaseService::~DatabaseService() = default; bool DatabaseService::backup() noexcept { QString backupDirectoryPath; - LogbookManager &logbookManager = LogbookManager::getInstance(); - Metadata metaData; - bool ok = logbookManager.getMetadata(metaData); + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + bool ok {true}; + const Metadata metaData = persistenceManager.getMetadata(&ok); if (ok) { - backupDirectoryPath = LogbookManager::createBackupPathIfNotExists(metaData.backupDirectoryPath); + backupDirectoryPath = PersistenceManager::createBackupPathIfNotExists(metaData.backupDirectoryPath); } ok = !backupDirectoryPath.isNull(); if (ok) { - const QString backupFileName = logbookManager.getBackupFileName(backupDirectoryPath); + const QString backupFileName = persistenceManager.getBackupFileName(backupDirectoryPath); if (!backupFileName.isNull()) { const QString backupFilePath = backupDirectoryPath + "/" + backupFileName; - ok = logbookManager.backup(backupFilePath); + ok = persistenceManager.backup(backupFilePath); if (ok) { ok = d->databaseDao->updateBackupDirectoryPath(backupDirectoryPath); } @@ -140,8 +135,8 @@ bool DatabaseService::setNextBackupDate(const QDateTime &date) noexcept bool DatabaseService::updateBackupDate() noexcept { - Metadata metaData; - bool ok = LogbookManager::getInstance().getMetadata(metaData); + bool ok {true}; + const Metadata metaData = PersistenceManager::getInstance().getMetadata(&ok); if (ok) { const QDateTime today = QDateTime::currentDateTime(); QDateTime nextBackupDate = metaData.lastBackupDate.isNull() ? today : metaData.lastBackupDate; @@ -180,7 +175,7 @@ QString DatabaseService::getExistingLogbookPath(QWidget *parent) noexcept { Settings &settings = Settings::getInstance(); QString existingLogbookPath = QFileInfo(settings.getLogbookPath()).absolutePath(); - QString logbookPath = QFileDialog::getOpenFileName(parent, QCoreApplication::translate("DatabaseService", "Open Logbook"), existingLogbookPath, QString("*") + Const::LogbookExtension); + QString logbookPath = QFileDialog::getOpenFileName(parent, QCoreApplication::translate("DatabaseService", "Open Logbook"), existingLogbookPath, QString("*") % Const::LogbookExtension); return logbookPath; } @@ -201,7 +196,7 @@ QString DatabaseService::getNewLogbookPath(QWidget *parent) noexcept if (!logbookDirectoryPath.isEmpty()) { QFileInfo info = QFileInfo(logbookDirectoryPath); if (!info.exists()) { - newLogbookPath = logbookDirectoryPath + "/" + info.fileName() + Const::LogbookExtension; + newLogbookPath = logbookDirectoryPath + "/" % info.fileName() % Const::LogbookExtension; retry = false; } else { QMessageBox::information(parent, QCoreApplication::translate("DatabaseService", "Database exists"), diff --git a/src/Persistence/src/Service/EnumerationService.cpp b/src/Persistence/src/Service/EnumerationService.cpp index b295c9224..b36c3387a 100644 --- a/src/Persistence/src/Service/EnumerationService.cpp +++ b/src/Persistence/src/Service/EnumerationService.cpp @@ -25,9 +25,6 @@ #include #include -#ifdef DEBUG -#include -#endif #include #include "../Dao/DaoFactory.h" @@ -49,25 +46,19 @@ struct EnumerationServicePrivate EnumerationService::EnumerationService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug() << "EnumerationService::EnumerationService: CREATED."; -#endif -} +{} -EnumerationService::~EnumerationService() noexcept -{ -#ifdef DEBUG - qDebug() << "EnumerationService::~EnumerationService: DELETED."; -#endif -} +EnumerationService::EnumerationService(EnumerationService &&rhs) = default; +EnumerationService &EnumerationService::operator=(EnumerationService &&rhs) = default; +EnumerationService::~EnumerationService() = default; -bool EnumerationService::getEnumerationByName(Enumeration &enumeration) +Enumeration EnumerationService::getEnumerationByName(const QString &name, bool *ok) { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->enumerationDao->get(enumeration); + Enumeration enumeration; + bool success = QSqlDatabase::database().transaction(); + if (success) { + enumeration = d->enumerationDao->get(name, &success); } QSqlDatabase::database().rollback(); - return ok; + return enumeration; } diff --git a/src/Persistence/src/Service/FlightService.cpp b/src/Persistence/src/Service/FlightService.cpp index bff9a7008..ff14d9b33 100644 --- a/src/Persistence/src/Service/FlightService.cpp +++ b/src/Persistence/src/Service/FlightService.cpp @@ -28,21 +28,16 @@ #include #include -#ifdef DEBUG -#include -#endif #include #include #include #include "../Dao/DaoFactory.h" #include "../Dao/FlightDaoIntf.h" -#include "../Dao/AircraftDaoIntf.h" #include -class FlightServicePrivate +struct FlightServicePrivate { -public: FlightServicePrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), flightDao(daoFactory->createFlightDao()) @@ -56,18 +51,11 @@ class FlightServicePrivate FlightService::FlightService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug() << "FlightService::FlightService: CREATED."; -#endif -} +{} -FlightService::~FlightService() noexcept -{ -#ifdef DEBUG - qDebug() << "FlightService::~FlightService: DELETED."; -#endif -} +FlightService::FlightService(FlightService &&rhs) = default; +FlightService &FlightService::operator=(FlightService &&rhs) = default; +FlightService::~FlightService() = default; bool FlightService::store(Flight &flight) noexcept { diff --git a/src/Persistence/src/Service/LocationService.cpp b/src/Persistence/src/Service/LocationService.cpp index 654a76d5f..89d96d3d7 100644 --- a/src/Persistence/src/Service/LocationService.cpp +++ b/src/Persistence/src/Service/LocationService.cpp @@ -24,12 +24,9 @@ */ #include #include -#include +#include #include -#ifdef DEBUG -#include -#endif #include #include "../Dao/DaoFactory.h" @@ -37,9 +34,8 @@ #include #include -class LocationServicePrivate +struct LocationServicePrivate { -public: LocationServicePrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), locationDao(daoFactory->createLocationDao()) @@ -53,18 +49,11 @@ class LocationServicePrivate LocationService::LocationService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug() << "LocationService::LocationService: CREATED."; -#endif -} +{} -LocationService::~LocationService() noexcept -{ -#ifdef DEBUG - qDebug() << "LocationService::~LocationService: DELETED."; -#endif -} +LocationService::LocationService(LocationService &&rhs) = default; +LocationService &LocationService::operator=(LocationService &&rhs) = default; +LocationService::~LocationService() = default; bool LocationService::store(Location &location) noexcept { @@ -108,22 +97,30 @@ bool LocationService::deleteById(std::int64_t id) noexcept return ok; } -bool LocationService::getAll(std::back_insert_iterator> backInsertIterator) const noexcept +std::vector LocationService::getAll(bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->locationDao->getAll(backInsertIterator); + std::vector locations; + bool success = QSqlDatabase::database().transaction(); + if (success) { + locations = d->locationDao->getAll(&success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return locations; } -bool LocationService::getSelectedLocations(const LocationSelector &locationSelector, std::back_insert_iterator> backInsertIterator) const noexcept +std::vector LocationService::getSelectedLocations(const LocationSelector &locationSelector, bool *ok) const noexcept { - bool ok = QSqlDatabase::database().transaction(); - if (ok) { - ok = d->locationDao->getSelectedLocations(locationSelector, backInsertIterator); + std::vector locations; + bool success = QSqlDatabase::database().transaction(); + if (success) { + locations = d->locationDao->getSelectedLocations(locationSelector, &success); QSqlDatabase::database().rollback(); } - return ok; + if (ok != nullptr) { + *ok = success; + } + return locations; } diff --git a/src/Persistence/src/Service/LogbookService.cpp b/src/Persistence/src/Service/LogbookService.cpp index 750583dc7..b40ff32fc 100644 --- a/src/Persistence/src/Service/LogbookService.cpp +++ b/src/Persistence/src/Service/LogbookService.cpp @@ -27,9 +27,6 @@ #include #include -#ifdef DEBUG -#include -#endif #include #include @@ -38,9 +35,8 @@ #include #include -class LogbookServicePrivate +struct LogbookServicePrivate { -public: LogbookServicePrivate() noexcept : daoFactory(std::make_unique(DaoFactory::DbType::SQLite)), logbookDao(daoFactory->createLogbookDao()) @@ -54,18 +50,11 @@ class LogbookServicePrivate LogbookService::LogbookService() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug() << "LogbookService::LogbookService: CREATED."; -#endif -} +{} -LogbookService::~LogbookService() noexcept -{ -#ifdef DEBUG - qDebug() << "LogbookService::~LogbookService: DELETED."; -#endif -} +LogbookService::LogbookService(LogbookService &&rhs) = default; +LogbookService &LogbookService::operator=(LogbookService &&rhs) = default; +LogbookService::~LogbookService() = default; bool LogbookService::getFlightDates(std::front_insert_iterator> frontInsertIterator) const noexcept { diff --git a/src/PluginManager/include/PluginManager/AbstractModule.h b/src/PluginManager/include/PluginManager/AbstractModule.h index 97fd8f902..172cda980 100644 --- a/src/PluginManager/include/PluginManager/AbstractModule.h +++ b/src/PluginManager/include/PluginManager/AbstractModule.h @@ -43,7 +43,11 @@ class PLUGINMANAGER_API AbstractModule : public QObject, public ModuleIntf Q_INTERFACES(ModuleIntf) public: explicit AbstractModule(QObject *parent = nullptr) noexcept; - ~AbstractModule() noexcept override; + AbstractModule(const AbstractModule &rhs) = delete; + AbstractModule(AbstractModule &&rhs) = delete; + AbstractModule &operator=(const AbstractModule &rhs) = delete; + AbstractModule &operator=(AbstractModule &&rhs) = delete; + ~AbstractModule() override; ModuleIntf::RecordIconId getRecordIconId() const noexcept override; void setRecording(bool enable) noexcept override; @@ -61,7 +65,7 @@ protected slots: void onRecordingStopped() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; }; diff --git a/src/PluginManager/include/PluginManager/AbstractSkyConnect.h b/src/PluginManager/include/PluginManager/AbstractSkyConnect.h index 8fbfa2a7a..f6d030cac 100644 --- a/src/PluginManager/include/PluginManager/AbstractSkyConnect.h +++ b/src/PluginManager/include/PluginManager/AbstractSkyConnect.h @@ -38,7 +38,7 @@ class Flight; class Aircraft; -class AbstractSkyConnectPrivate; +struct AbstractSkyConnectPrivate; class PLUGINMANAGER_API AbstractSkyConnect : public SkyConnectIntf { @@ -51,7 +51,11 @@ class PLUGINMANAGER_API AbstractSkyConnect : public SkyConnectIntf }; AbstractSkyConnect(QObject *parent = nullptr) noexcept; - ~AbstractSkyConnect() noexcept override; + AbstractSkyConnect(const AbstractSkyConnect &rhs) = delete; + AbstractSkyConnect(AbstractSkyConnect &&rhs) = delete; + AbstractSkyConnect &operator=(const AbstractSkyConnect &rhs) = delete; + AbstractSkyConnect &operator=(AbstractSkyConnect &&rhs) = delete; + ~AbstractSkyConnect() override; bool setUserAircraftInitialPosition(const InitialPosition &initialPosition) noexcept override; bool freezeUserAircraft(bool enable) noexcept override; @@ -59,12 +63,12 @@ class PLUGINMANAGER_API AbstractSkyConnect : public SkyConnectIntf ReplayMode getReplayMode() const noexcept override; void setReplayMode(ReplayMode replayMode) noexcept override; - void startRecording(RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition::NullData) noexcept override; + void startRecording(RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition()) noexcept override; void stopRecording() noexcept override; bool isRecording() const noexcept override; bool isInRecordingState() const noexcept override; - void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition::NullData) noexcept override; + void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition()) noexcept override; void stopReplay() noexcept override; bool isReplaying() const noexcept override; bool isInReplayState() const noexcept override; @@ -146,8 +150,7 @@ protected slots: virtual void recordData() noexcept = 0; private: - Q_DISABLE_COPY(AbstractSkyConnect) - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; bool hasRecordingStarted() const noexcept; @@ -155,8 +158,8 @@ protected slots: inline bool retryWithReconnect(std::function func); - bool setupInitialRecordingPosition(const InitialPosition &initialPosition) noexcept; - bool setupInitialReplayPosition(const InitialPosition &flyWithFormationPosition) noexcept; + bool setupInitialRecordingPosition(InitialPosition initialPosition) noexcept; + bool setupInitialReplayPosition(InitialPosition flyWithFormationPosition) noexcept; bool updateUserAircraftFreeze() noexcept; private slots: diff --git a/src/PluginManager/include/PluginManager/BasicExportDialog.h b/src/PluginManager/include/PluginManager/BasicExportDialog.h index 5de4c94b2..74aaa1742 100644 --- a/src/PluginManager/include/PluginManager/BasicExportDialog.h +++ b/src/PluginManager/include/PluginManager/BasicExportDialog.h @@ -35,7 +35,7 @@ class Flight; class ExportPluginBaseSettings; -class BasicExportDialogPrivate; +struct BasicExportDialogPrivate; namespace Ui { class BasicExportDialog; @@ -47,7 +47,11 @@ class PLUGINMANAGER_API BasicExportDialog : public QDialog public: explicit BasicExportDialog(const Flight &flight, const QString &fileSuffix, const QString &fileFilter, ExportPluginBaseSettings &pluginSettings, QWidget *parent = nullptr) noexcept; - virtual ~BasicExportDialog() noexcept; + BasicExportDialog(const BasicExportDialog &rhs) = delete; + BasicExportDialog(BasicExportDialog &&rhs) = delete; + BasicExportDialog &operator=(const BasicExportDialog &rhs) = delete; + BasicExportDialog &operator=(BasicExportDialog &&rhs) = delete; + ~BasicExportDialog() override; QString getSelectedFilePath() const noexcept; void setSelectedFilePath(const QString &filePath) noexcept; @@ -55,8 +59,8 @@ class PLUGINMANAGER_API BasicExportDialog : public QDialog void setOptionWidget(QWidget *widget) noexcept; private: - std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; void initBasicUi() noexcept; diff --git a/src/PluginManager/include/PluginManager/BasicImportDialog.h b/src/PluginManager/include/PluginManager/BasicImportDialog.h index 05e277cfe..36449e482 100644 --- a/src/PluginManager/include/PluginManager/BasicImportDialog.h +++ b/src/PluginManager/include/PluginManager/BasicImportDialog.h @@ -32,12 +32,12 @@ class QWidget; +#include #include "PluginManagerLib.h" class Flight; -struct AircraftType; class ImportPluginBaseSettings; -class BasicImportDialogPrivate; +struct BasicImportDialogPrivate; namespace Ui { class BasicImportDialog; @@ -48,9 +48,13 @@ class PLUGINMANAGER_API BasicImportDialog : public QDialog Q_OBJECT public: explicit BasicImportDialog(const Flight &flight, const QString &fileExtension, ImportPluginBaseSettings &pluginSettings, QWidget *parent = nullptr) noexcept; - virtual ~BasicImportDialog() noexcept; + BasicImportDialog(const BasicImportDialog &rhs) = delete; + BasicImportDialog(BasicImportDialog &&rhs) = delete; + BasicImportDialog &operator=(const BasicImportDialog &rhs) = delete; + BasicImportDialog &operator=(BasicImportDialog &&rhs) = delete; + ~BasicImportDialog() override; - bool getSelectedAircraftType(AircraftType &aircraftType) const noexcept; + AircraftType getSelectedAircraftType(bool *ok = nullptr) const noexcept; QString getSelectedPath() const noexcept; QString getFileFilter() const noexcept; @@ -59,8 +63,8 @@ class PLUGINMANAGER_API BasicImportDialog : public QDialog void setOptionWidget(QWidget *widget) noexcept; private: - std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; void initBasicUi() noexcept; diff --git a/src/PluginManager/include/PluginManager/CsvConst.h b/src/PluginManager/include/PluginManager/CsvConst.h index b2ce7aee2..88ca951a6 100644 --- a/src/PluginManager/include/PluginManager/CsvConst.h +++ b/src/PluginManager/include/PluginManager/CsvConst.h @@ -49,7 +49,7 @@ namespace CsvConst { Light = 'l' }; - constexpr char TypeColumnName[] = "Type"; + constexpr const char *TypeColumnName {"Type"}; } #endif // CSVCONST_H diff --git a/src/PluginManager/include/PluginManager/Export.h b/src/PluginManager/include/PluginManager/Export.h index c12dabe3d..1dae349db 100644 --- a/src/PluginManager/include/PluginManager/Export.h +++ b/src/PluginManager/include/PluginManager/Export.h @@ -26,7 +26,6 @@ #define EXPORT_H #include -#include #include #include @@ -68,7 +67,7 @@ class PLUGINMANAGER_API Export */ static QString formatNumber(double number) noexcept; - static void resamplePositionDataForExport(const Aircraft &aircraft, const SampleRate::ResamplingPeriod resamplingPeriod, std::back_insert_iterator> backInsertIterator) noexcept; + static std::vector resamplePositionDataForExport(const Aircraft &aircraft, const SampleRate::ResamplingPeriod resamplingPeriod) noexcept; }; #endif // EXPORT_H diff --git a/src/PluginManager/include/PluginManager/ExportPluginBase.h b/src/PluginManager/include/PluginManager/ExportPluginBase.h index 1826c52aa..eca012bf8 100644 --- a/src/PluginManager/include/PluginManager/ExportPluginBase.h +++ b/src/PluginManager/include/PluginManager/ExportPluginBase.h @@ -45,7 +45,7 @@ struct PositionData; class FLight; class Aircraft; class ExportPluginBaseSettings; -class ExportPluginBasePrivate; +struct ExportPluginBasePrivate; class PLUGINMANAGER_API ExportPluginBase : public PluginBase, public ExportIntf { @@ -53,7 +53,11 @@ class PLUGINMANAGER_API ExportPluginBase : public PluginBase, public ExportIntf Q_INTERFACES(ExportIntf) public: ExportPluginBase() noexcept; - ~ExportPluginBase() noexcept override; + ExportPluginBase(const ExportPluginBase &rhs) = delete; + ExportPluginBase(ExportPluginBase &&rhs) = delete; + ExportPluginBase &operator=(const ExportPluginBase &rhs) = delete; + ExportPluginBase &operator=(ExportPluginBase &&rhs) = delete; + ~ExportPluginBase() override; QWidget *getParentWidget() const noexcept final { @@ -95,15 +99,15 @@ class PLUGINMANAGER_API ExportPluginBase : public PluginBase, public ExportIntf virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept = 0; private: - std::unique_ptr d; + const std::unique_ptr d; bool exportFlight(const Flight &flight, const QString &filePath) noexcept; // Exports all aircraft into separate files, given the 'baseFilePath' bool exportAllAircraft(const Flight &flight, const QString &baseFilePath) noexcept; - virtual void addSettings(Settings::KeyValues &keyValues) const noexcept final; - virtual void addKeysWithDefaults(Settings::KeysWithDefaults &keysWithDefaults) const noexcept final; - virtual void restoreSettings(Settings::ValuesByKey valuesByKey) noexcept final; + void addSettings(Settings::KeyValues &keyValues) const noexcept final; + void addKeysWithDefaults(Settings::KeysWithDefaults &keysWithDefaults) const noexcept final; + void restoreSettings(Settings::ValuesByKey valuesByKey) noexcept final; }; #endif // EXPORTPLUGINBASE_H diff --git a/src/PluginManager/include/PluginManager/ExportPluginBaseSettings.h b/src/PluginManager/include/PluginManager/ExportPluginBaseSettings.h index d75bd2ee7..b2d9e2150 100644 --- a/src/PluginManager/include/PluginManager/ExportPluginBaseSettings.h +++ b/src/PluginManager/include/PluginManager/ExportPluginBaseSettings.h @@ -34,7 +34,7 @@ #include #include "PluginManagerLib.h" -class ExportPluginBaseSettingsPrivate; +struct ExportPluginBaseSettingsPrivate; class PLUGINMANAGER_API ExportPluginBaseSettings : public QObject { @@ -54,7 +54,11 @@ class PLUGINMANAGER_API ExportPluginBaseSettings : public QObject }; ExportPluginBaseSettings() noexcept; - virtual ~ExportPluginBaseSettings() noexcept; + ExportPluginBaseSettings(const ExportPluginBaseSettings &rhs) = delete; + ExportPluginBaseSettings(ExportPluginBaseSettings &&rhs) = delete; + ExportPluginBaseSettings &operator=(const ExportPluginBaseSettings &rhs) = delete; + ExportPluginBaseSettings &operator=(ExportPluginBaseSettings &&rhs) = delete; + ~ExportPluginBaseSettings() override; SampleRate::ResamplingPeriod getResamplingPeriod() const noexcept; void setResamplingPeriod(SampleRate::ResamplingPeriod resamplingPeriod) noexcept; @@ -97,7 +101,7 @@ class PLUGINMANAGER_API ExportPluginBaseSettings : public QObject virtual void restoreDefaultsExtn() noexcept = 0; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // EXPORTPLUGINBASESETTINGS_H diff --git a/src/PluginManager/include/PluginManager/ImportPluginBase.h b/src/PluginManager/include/PluginManager/ImportPluginBase.h index 7709c66ec..47095a479 100644 --- a/src/PluginManager/include/PluginManager/ImportPluginBase.h +++ b/src/PluginManager/include/PluginManager/ImportPluginBase.h @@ -46,7 +46,7 @@ struct AircraftType; struct AircraftInfo; struct FlightCondition; class ImportPluginBaseSettings; -class ImportPluginBasePrivate; +struct ImportPluginBasePrivate; class PLUGINMANAGER_API ImportPluginBase : public PluginBase, public ImportIntf { @@ -54,7 +54,11 @@ class PLUGINMANAGER_API ImportPluginBase : public PluginBase, public ImportIntf Q_INTERFACES(ImportIntf) public: ImportPluginBase() noexcept; - ~ImportPluginBase() noexcept override; + ImportPluginBase(const ImportPluginBase &rhs) = delete; + ImportPluginBase(ImportPluginBase &&rhs) = delete; + ImportPluginBase &operator=(const ImportPluginBase &rhs) = delete; + ImportPluginBase &operator=(ImportPluginBase &&rhs) = delete; + ~ImportPluginBase() override; QWidget *getParentWidget() const noexcept final { @@ -97,7 +101,7 @@ class PLUGINMANAGER_API ImportPluginBase : public PluginBase, public ImportIntf virtual void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept = 0; private: - std::unique_ptr d; + const std::unique_ptr d; virtual void addSettings(Settings::KeyValues &keyValues) const noexcept final; virtual void addKeysWithDefaults(Settings::KeysWithDefaults &keysWithDefaults) const noexcept final; diff --git a/src/PluginManager/include/PluginManager/ImportPluginBaseSettings.h b/src/PluginManager/include/PluginManager/ImportPluginBaseSettings.h index 968ff48cc..ec677ca19 100644 --- a/src/PluginManager/include/PluginManager/ImportPluginBaseSettings.h +++ b/src/PluginManager/include/PluginManager/ImportPluginBaseSettings.h @@ -34,14 +34,18 @@ #include #include "PluginManagerLib.h" -class ImportPluginBaseSettingsPrivate; +struct ImportPluginBaseSettingsPrivate; class PLUGINMANAGER_API ImportPluginBaseSettings : public QObject { Q_OBJECT public: ImportPluginBaseSettings() noexcept; - virtual ~ImportPluginBaseSettings() noexcept; + ImportPluginBaseSettings(const ImportPluginBaseSettings &rhs) = delete; + ImportPluginBaseSettings(ImportPluginBaseSettings &&rhs) = delete; + ImportPluginBaseSettings &operator=(const ImportPluginBaseSettings &rhs) = delete; + ImportPluginBaseSettings &operator=(ImportPluginBaseSettings &&rhs) = delete; + ~ImportPluginBaseSettings() override; bool isImportDirectoryEnabled() const noexcept; void setImportDirectoryEnabled(bool enabled) noexcept; @@ -67,7 +71,7 @@ class PLUGINMANAGER_API ImportPluginBaseSettings : public QObject virtual void restoreDefaultsExtn() noexcept = 0; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // IMPORTPLUGINBASESETTINGS_H diff --git a/src/PluginManager/include/PluginManager/ModuleIntf.h b/src/PluginManager/include/PluginManager/ModuleIntf.h index 32d156219..709985ba0 100644 --- a/src/PluginManager/include/PluginManager/ModuleIntf.h +++ b/src/PluginManager/include/PluginManager/ModuleIntf.h @@ -39,6 +39,11 @@ class ModuleIntf Add }; + ModuleIntf() = default; + ModuleIntf(const ModuleIntf &rhs) = delete; + ModuleIntf(ModuleIntf &&rhs) = default; + ModuleIntf &operator=(const ModuleIntf &rhs) = delete; + ModuleIntf &operator=(ModuleIntf &&rhs) = default; virtual ~ModuleIntf() = default; virtual QString getModuleName() const noexcept = 0; diff --git a/src/PluginManager/include/PluginManager/ModuleManager.h b/src/PluginManager/include/PluginManager/ModuleManager.h index 91c612265..f7782ca84 100644 --- a/src/PluginManager/include/PluginManager/ModuleManager.h +++ b/src/PluginManager/include/PluginManager/ModuleManager.h @@ -53,7 +53,11 @@ class PLUGINMANAGER_API ModuleManager : public QObject Q_OBJECT public: explicit ModuleManager(QLayout &layout, QObject *parent = nullptr) noexcept; - ~ModuleManager() noexcept override; + ModuleManager(const ModuleManager &rhs) = delete; + ModuleManager(ModuleManager &&rhs) = delete; + ModuleManager &operator=(const ModuleManager &rhs) = delete; + ModuleManager &operator=(ModuleManager &&rhs) = delete; + ~ModuleManager() override; using ActionRegistry = tsl::ordered_map; const ActionRegistry &getActionRegistry() const noexcept; @@ -87,7 +91,7 @@ class PLUGINMANAGER_API ModuleManager : public QObject // First: module name - second: path using ModuleInfo = std::pair; - std::unique_ptr d; + const std::unique_ptr d; void initModules() noexcept; void frenchConnection() noexcept; diff --git a/src/PluginManager/include/PluginManager/PluginBase.h b/src/PluginManager/include/PluginManager/PluginBase.h index 91fab2377..543c67771 100644 --- a/src/PluginManager/include/PluginManager/PluginBase.h +++ b/src/PluginManager/include/PluginManager/PluginBase.h @@ -34,20 +34,24 @@ #include "PluginIntf.h" #include "PluginManagerLib.h" -class PluginBasePrivate; +struct PluginBasePrivate; class PLUGINMANAGER_API PluginBase : public QObject, public PluginIntf { Q_OBJECT public: PluginBase(); - virtual ~PluginBase(); + PluginBase(const PluginBase &rhs) = delete; + PluginBase(PluginBase &&rhs) = delete; + PluginBase &operator=(const PluginBase &rhs) = delete; + PluginBase &operator=(PluginBase &&rhs) = delete; + ~PluginBase() override; - virtual QWidget *getParentWidget() const noexcept override; - virtual void setParentWidget(QWidget *parent) noexcept override; + QWidget *getParentWidget() const noexcept override; + void setParentWidget(QWidget *parent) noexcept override; - virtual void storeSettings(const QUuid &pluginUuid) const noexcept override; - virtual void restoreSettings(const QUuid &pluginUuid) noexcept override; + void storeSettings(const QUuid &pluginUuid) const noexcept override; + void restoreSettings(const QUuid &pluginUuid) noexcept override; protected: /*! @@ -75,7 +79,7 @@ class PLUGINMANAGER_API PluginBase : public QObject, public PluginIntf virtual void restoreSettings(Settings::ValuesByKey valuesByKey) noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // PLUGINBASE_H diff --git a/src/PluginManager/include/PluginManager/PluginIntf.h b/src/PluginManager/include/PluginManager/PluginIntf.h index aaa61633c..5c8c37062 100644 --- a/src/PluginManager/include/PluginManager/PluginIntf.h +++ b/src/PluginManager/include/PluginManager/PluginIntf.h @@ -31,6 +31,11 @@ class QUuid; class PluginIntf { public: + PluginIntf() = default; + PluginIntf(const PluginIntf &rhs) = delete; + PluginIntf(PluginIntf &&rhs) = default; + PluginIntf &operator=(const PluginIntf &rhs) = delete; + PluginIntf &operator=(PluginIntf &&rhs) = default; virtual ~PluginIntf() = default; virtual QWidget *getParentWidget() const noexcept = 0; diff --git a/src/PluginManager/include/PluginManager/PluginManager.h b/src/PluginManager/include/PluginManager/PluginManager.h index ae188139a..bcfd7dc99 100644 --- a/src/PluginManager/include/PluginManager/PluginManager.h +++ b/src/PluginManager/include/PluginManager/PluginManager.h @@ -36,18 +36,22 @@ class QUuid; class QWidget; class QString; -#include "ExportIntf.h" #include "PluginManagerLib.h" class SkyConnectIntf; class Flight; class FlightService; -class PluginManagerPrivate; +struct PluginManagerPrivate; -class PLUGINMANAGER_API PluginManager : public QObject +class PLUGINMANAGER_API PluginManager final : public QObject { Q_OBJECT public: + PluginManager(const PluginManager &rhs) = delete; + PluginManager(PluginManager &&rhs) = delete; + PluginManager &operator=(const PluginManager &rhs) = delete; + PluginManager &operator=(PluginManager &&rhs) = delete; + static PluginManager &getInstance() noexcept; static void destroyInstance() noexcept; @@ -63,14 +67,11 @@ class PLUGINMANAGER_API PluginManager : public QObject bool importFlight(const QUuid &pluginUuid, FlightService &flightService, Flight &flight) const noexcept; bool exportFlight(const Flight &flight, const QUuid &pluginUuid) const noexcept; -protected: - virtual ~PluginManager() noexcept; - private: - Q_DISABLE_COPY(PluginManager) - std::unique_ptr d; + const std::unique_ptr d; PluginManager() noexcept; + ~PluginManager() override; std::vector enumeratePlugins(const QString &pluginDirectoryName, QMap &plugins) noexcept; }; diff --git a/src/PluginManager/include/PluginManager/SettingsIntf.h b/src/PluginManager/include/PluginManager/SettingsIntf.h index 8dcdb3fac..599a41902 100644 --- a/src/PluginManager/include/PluginManager/SettingsIntf.h +++ b/src/PluginManager/include/PluginManager/SettingsIntf.h @@ -34,8 +34,12 @@ class PLUGINMANAGER_API SettingsIntf : public QObject { Q_OBJECT public: - virtual ~SettingsIntf() - {} + SettingsIntf() = default; + SettingsIntf(const SettingsIntf &rhs) = delete; + SettingsIntf(SettingsIntf &&rhs) = delete; + SettingsIntf &operator=(const SettingsIntf &rhs) = delete; + SettingsIntf &operator=(SettingsIntf &&rhs) = delete; + ~SettingsIntf() override = default; virtual Settings::KeyValues getSettings() const noexcept = 0; virtual Settings::KeysWithDefaults getKeysWithDefault() const noexcept = 0; diff --git a/src/PluginManager/include/PluginManager/SkyConnectIntf.h b/src/PluginManager/include/PluginManager/SkyConnectIntf.h index b969b8736..42822ca7f 100644 --- a/src/PluginManager/include/PluginManager/SkyConnectIntf.h +++ b/src/PluginManager/include/PluginManager/SkyConnectIntf.h @@ -65,10 +65,18 @@ class PLUGINMANAGER_API SkyConnectIntf : public QObject FlyWithFormation }; + SkyConnectIntf(QObject *parent = nullptr) noexcept + : QObject(parent) + {} + + SkyConnectIntf(const SkyConnectIntf &rhs) = delete; + SkyConnectIntf(SkyConnectIntf &&rhs) = delete; + SkyConnectIntf &operator=(const SkyConnectIntf &rhs) = delete; + SkyConnectIntf &operator=(SkyConnectIntf &&rhs) = delete; ~SkyConnectIntf() override = default; virtual bool setUserAircraftInitialPosition(const InitialPosition &initialPosition) noexcept = 0; - virtual bool setUserAircraftPosition(const PositionData & positionData) noexcept = 0; + virtual bool setUserAircraftPosition(const PositionData &positionData) noexcept = 0; virtual bool freezeUserAircraft(bool enable) noexcept = 0; /*! @@ -99,7 +107,7 @@ class PLUGINMANAGER_API SkyConnectIntf : public QObject * the optional initial position where the current user aircraft is placed before recording; * set to a \e null position if the user aircraft should keep its current initial position */ - virtual void startRecording(RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition::NullData) noexcept = 0; + virtual void startRecording(RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition()) noexcept = 0; virtual void stopRecording() noexcept = 0; /*! @@ -125,7 +133,7 @@ class PLUGINMANAGER_API SkyConnectIntf : public QObject */ virtual bool isInRecordingState() const noexcept = 0; - virtual void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition::NullData) noexcept = 0; + virtual void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition()) noexcept = 0; virtual void stopReplay() noexcept = 0; /*! @@ -210,10 +218,6 @@ public slots: virtual void onTailNumberChanged(const Aircraft &aircraft) noexcept = 0; protected: - SkyConnectIntf(QObject *parent = nullptr) noexcept - : QObject(parent) - {} - /*! * Sets the new connection \c state. This method will also emit the * signal #recordingStarted and #recordingStopped when the state changes @@ -246,7 +250,7 @@ public slots: * \param replayMode * the current replay mode */ - void replayModeChanged(ReplayMode replayMode); + void replayModeChanged(SkyConnectIntf::ReplayMode replayMode); /*! * Emitted whenever recording has been started, that is when the @@ -279,9 +283,6 @@ public slots: * the received Location */ void locationReceived(Location location); - -private: - Q_DISABLE_COPY(SkyConnectIntf) }; #define SKYCONNECT_INTERFACE_IID "com.github.till213.SkyDolly.SkyConnectInterface/1.0" diff --git a/src/PluginManager/include/PluginManager/SkyConnectManager.h b/src/PluginManager/include/PluginManager/SkyConnectManager.h index 5d400b0cb..9c3c07c1f 100644 --- a/src/PluginManager/include/PluginManager/SkyConnectManager.h +++ b/src/PluginManager/include/PluginManager/SkyConnectManager.h @@ -43,13 +43,18 @@ class QUuid; #include "SkyConnectIntf.h" #include "PluginManagerLib.h" -class skyConnectManagerPrivate; +struct skyConnectManagerPrivate; /// \todo Gradually implement all methods from the SkyConnectIntf and then finally inherit from it -class PLUGINMANAGER_API SkyConnectManager : public QObject +class PLUGINMANAGER_API SkyConnectManager final : public QObject { Q_OBJECT public: + SkyConnectManager(const SkyConnectManager &rhs) = delete; + SkyConnectManager(SkyConnectManager &&rhs) = delete; + SkyConnectManager &operator=(const SkyConnectManager &rhs) = delete; + SkyConnectManager &operator=(SkyConnectManager &&rhs) = delete; + static SkyConnectManager &getInstance() noexcept; static void destroyInstance() noexcept; @@ -79,21 +84,21 @@ class PLUGINMANAGER_API SkyConnectManager : public QObject SkyConnectIntf::ReplayMode getReplayMode() const noexcept; void setReplayMode(SkyConnectIntf::ReplayMode replayMode) noexcept; - void startRecording(SkyConnectIntf::RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition::NullData) noexcept; + void startRecording(SkyConnectIntf::RecordingMode recordingMode, const InitialPosition &initialPosition = InitialPosition()) noexcept; void stopRecording() noexcept; bool isRecording() const noexcept; bool isInRecordingState() const noexcept; - void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition::NullData) noexcept; + void startReplay(bool fromStart, const InitialPosition &flyWithFormationPosition = InitialPosition()) noexcept; void stopReplay() noexcept; bool isReplaying() const noexcept; bool isInReplayState() const noexcept; /*! - * Returns \c true in case the SkyConnect connection is \em active, that is either + * Returns \c true in case the SkyConnect connection is \eactive, that is either * a replay or recording (including paused states) is taking place. * - * \return \c true if the SkyConnect connection is \em active; \c false else + * \return \c true if the SkyConnect connection is \eactive; \c false else * \sa isInRecordingState * \sa isInReplayState */ @@ -168,14 +173,11 @@ public slots: */ void locationReceived(Location location); -protected: - ~SkyConnectManager() noexcept override; - private: - Q_DISABLE_COPY(SkyConnectManager) - std::unique_ptr d; + const std::unique_ptr d; SkyConnectManager() noexcept; + ~SkyConnectManager() override; void frenchConnection() noexcept; void initialisePlugins(const QString &pluginDirectoryName) noexcept; diff --git a/src/PluginManager/src/AbstractModule.cpp b/src/PluginManager/src/AbstractModule.cpp index c45940201..f0f6db85c 100644 --- a/src/PluginManager/src/AbstractModule.cpp +++ b/src/PluginManager/src/AbstractModule.cpp @@ -50,8 +50,7 @@ AbstractModule::AbstractModule(QObject *parent) noexcept frenchConnection(); } -AbstractModule::~AbstractModule() noexcept -{} +AbstractModule::~AbstractModule() = default; ModuleIntf::RecordIconId AbstractModule::getRecordIconId() const noexcept { diff --git a/src/PluginManager/src/AbstractSkyConnect.cpp b/src/PluginManager/src/AbstractSkyConnect.cpp index b8f1bab18..2b09d5ef3 100644 --- a/src/PluginManager/src/AbstractSkyConnect.cpp +++ b/src/PluginManager/src/AbstractSkyConnect.cpp @@ -33,6 +33,7 @@ #include #endif +#include #include #include #include @@ -101,8 +102,7 @@ AbstractSkyConnect::AbstractSkyConnect(QObject *parent) noexcept frenchConnection(); } -AbstractSkyConnect::~AbstractSkyConnect() noexcept -{} +AbstractSkyConnect::~AbstractSkyConnect() = default; bool AbstractSkyConnect::setUserAircraftInitialPosition(const InitialPosition &initialPosition) noexcept { @@ -541,7 +541,7 @@ void AbstractSkyConnect::updateUserAircraft(int newUserAircraftIndex, int previo // by an invalid ID (= it has never been persisted). In such a case it does not // have an associated AI object either const Aircraft &userAircraft = d->currentFlight[newUserAircraftIndex]; - if (userAircraft.getId() != Aircraft::InvalidId) { + if (userAircraft.getId() != Const::InvalidId) { removeAiObject(userAircraft.getId()); } if (previousUserAircraftIndex != Flight::InvalidAircraftIndex) { @@ -621,8 +621,8 @@ void AbstractSkyConnect::createAiObjects() noexcept const bool includingUserAircraft = getReplayMode() == ReplayMode::FlyWithFormation; const std::int64_t userAircraftId = d->currentFlight.getUserAircraft().getId(); for (const auto &aircraft : d->currentFlight) { - if (aircraft->getId() != userAircraftId || includingUserAircraft) { - onAddAiObject(*aircraft); + if (aircraft.getId() != userAircraftId || includingUserAircraft) { + onAddAiObject(aircraft); } } } @@ -687,7 +687,7 @@ bool AbstractSkyConnect::retryWithReconnect(std::function func) --nofAttempts; if (!ok && nofAttempts > 0) { #ifdef DEBUG - qDebug("AbstractSkyConnect::retryWithReconnect: previous connection is stale, RETRY with reconnect %d more time(s)...", nofAttempts); + qDebug() << "AbstractSkyConnect::retryWithReconnect: previous connection is stale, RETRY with reconnect" << nofAttempts << "more time(s)..."; #endif // Automatically reconnect in case the server crashed // previously (without sending a "quit" message) @@ -701,7 +701,7 @@ bool AbstractSkyConnect::retryWithReconnect(std::function func) return ok; } -bool AbstractSkyConnect::setupInitialRecordingPosition(const InitialPosition &initialPosition) noexcept +bool AbstractSkyConnect::setupInitialRecordingPosition(InitialPosition initialPosition) noexcept { bool ok {true}; if (!initialPosition.isNull()) { @@ -711,7 +711,7 @@ bool AbstractSkyConnect::setupInitialRecordingPosition(const InitialPosition &in return ok; } -bool AbstractSkyConnect::setupInitialReplayPosition(const InitialPosition &flyWithFormationPosition) noexcept +bool AbstractSkyConnect::setupInitialReplayPosition(InitialPosition flyWithFormationPosition) noexcept { bool ok {true}; switch (d->replayMode) { diff --git a/src/PluginManager/src/BasicExportDialog.cpp b/src/PluginManager/src/BasicExportDialog.cpp index 0dc744ab3..e704dbc96 100644 --- a/src/PluginManager/src/BasicExportDialog.cpp +++ b/src/PluginManager/src/BasicExportDialog.cpp @@ -50,9 +50,8 @@ #include "BasicExportDialog.h" #include "ui_BasicExportDialog.h" -class BasicExportDialogPrivate +struct BasicExportDialogPrivate { -public: BasicExportDialogPrivate(const Flight &theFlight, const QString &theFileSuffix, const QString &theFileFilter, ExportPluginBaseSettings &thePluginSettings) noexcept : flight(theFlight), fileSuffix(theFileSuffix), @@ -82,17 +81,9 @@ BasicExportDialog::BasicExportDialog(const Flight &flight, const QString &fileSu initUi(); updateUi(); frenchConnection(); -#ifdef DEBUG - qDebug("BasicExportDialog::BasicExportDialog: CREATED"); -#endif } -BasicExportDialog::~BasicExportDialog() noexcept -{ -#ifdef DEBUG - qDebug("BasicExportDialog::~BasicExportDialog: DELETED"); -#endif -} +BasicExportDialog::~BasicExportDialog() = default; QString BasicExportDialog::getSelectedFilePath() const noexcept { @@ -206,11 +197,11 @@ std::int64_t BasicExportDialog::estimateNofSamplePoints() const noexcept if (period != 0) { if (isExportUserAircraftOnly()) { std::int64_t duration = d->flight.getUserAircraft().getDurationMSec(); - nofSamplePoints += static_cast(std::round(static_cast(duration) / static_cast(period))) + 1; + nofSamplePoints += static_cast(std::round(static_cast(duration) / static_cast(period))) + 1; } else { for (const auto &aircraft : d->flight) { - std::int64_t duration = aircraft->getDurationMSec(); - nofSamplePoints += static_cast(std::round(static_cast(duration) / static_cast(period))) + 1; + std::int64_t duration = aircraft.getDurationMSec(); + nofSamplePoints += static_cast(std::round(static_cast(duration) / static_cast(period))) + 1; } } } else { @@ -219,7 +210,7 @@ std::int64_t BasicExportDialog::estimateNofSamplePoints() const noexcept nofSamplePoints += d->flight.getUserAircraft().getPosition().count(); } else { for (const auto &aircraft : d->flight) { - nofSamplePoints += aircraft->getPosition().count(); + nofSamplePoints += aircraft.getPosition().count(); } } } diff --git a/src/PluginManager/src/BasicImportDialog.cpp b/src/PluginManager/src/BasicImportDialog.cpp index 5ef76e950..03fd2c633 100644 --- a/src/PluginManager/src/BasicImportDialog.cpp +++ b/src/PluginManager/src/BasicImportDialog.cpp @@ -42,9 +42,8 @@ #include "BasicImportDialog.h" #include "ui_BasicImportDialog.h" -class BasicImportDialogPrivate +struct BasicImportDialogPrivate { -public: BasicImportDialogPrivate(const Flight &theFlight, const QString &theFileFilter, ImportPluginBaseSettings &pluginSettings) noexcept : flight(theFlight), aircraftTypeService(std::make_unique()), @@ -73,26 +72,18 @@ BasicImportDialog::BasicImportDialog(const Flight &flight, const QString &fileSu initUi(); updateUi(); frenchConnection(); -#ifdef DEBUG - qDebug("BasicImportDialog::BasicImportDialog: CREATED"); -#endif } -BasicImportDialog::~BasicImportDialog() noexcept -{ -#ifdef DEBUG - qDebug("BasicImportDialog::~BasicImportDialog: DELETED"); -#endif -} +BasicImportDialog::~BasicImportDialog() = default; QString BasicImportDialog::getSelectedPath() const noexcept { return ui->pathLineEdit->text(); } -bool BasicImportDialog::getSelectedAircraftType(AircraftType &aircraftType) const noexcept +AircraftType BasicImportDialog::getSelectedAircraftType(bool *ok) const noexcept { - return d->aircraftTypeService->getByType(ui->aircraftSelectionComboBox->currentText(), aircraftType); + return d->aircraftTypeService->getByType(ui->aircraftSelectionComboBox->currentText(), ok); } QString BasicImportDialog::getFileFilter() const noexcept diff --git a/src/PluginManager/src/Export.cpp b/src/PluginManager/src/Export.cpp index 141eef73e..243a7ff1f 100644 --- a/src/PluginManager/src/Export.cpp +++ b/src/PluginManager/src/Export.cpp @@ -74,8 +74,9 @@ QString Export::formatNumber(double number) noexcept return QString::number(number, 'f', ::NumberPrecision); } -void Export::resamplePositionDataForExport(const Aircraft &aircraft, const SampleRate::ResamplingPeriod resamplingPeriod, std::back_insert_iterator> backInsertIterator) noexcept +std::vector Export::resamplePositionDataForExport(const Aircraft &aircraft, const SampleRate::ResamplingPeriod resamplingPeriod) noexcept { + std::vector interpolatedPositionData; // Position data Position &position = aircraft.getPosition(); if (resamplingPeriod != SampleRate::ResamplingPeriod::Original) { @@ -85,12 +86,14 @@ void Export::resamplePositionDataForExport(const Aircraft &aircraft, const Sampl while (timestamp <= duration) { const PositionData &positionData = position.interpolate(timestamp, TimeVariableData::Access::Export); if (!positionData.isNull()) { - backInsertIterator = positionData; + interpolatedPositionData.push_back(positionData); } timestamp += deltaTime; } } else { // Original data requested - std::copy(position.begin(), position.end(), backInsertIterator); + interpolatedPositionData.reserve(position.count()); + std::copy(position.begin(), position.end(), std::back_inserter(interpolatedPositionData)); } + return interpolatedPositionData; } diff --git a/src/PluginManager/src/ExportPluginBase.cpp b/src/PluginManager/src/ExportPluginBase.cpp index a4f964eb2..58c010510 100644 --- a/src/PluginManager/src/ExportPluginBase.cpp +++ b/src/PluginManager/src/ExportPluginBase.cpp @@ -46,9 +46,8 @@ #include "ExportPluginBaseSettings.h" #include "ExportPluginBase.h" -class ExportPluginBasePrivate +struct ExportPluginBasePrivate { -public: ExportPluginBasePrivate() {} @@ -59,18 +58,9 @@ class ExportPluginBasePrivate ExportPluginBase::ExportPluginBase() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("ExportPluginBase::ExportPluginBase: CREATED"); -#endif -} +{} -ExportPluginBase::~ExportPluginBase() noexcept -{ -#ifdef DEBUG - qDebug("ExportPluginBase::~ExportPluginBase: DELETED"); -#endif -} +ExportPluginBase::~ExportPluginBase() = default; bool ExportPluginBase::exportFlight(const Flight &flight) noexcept { @@ -160,7 +150,7 @@ bool ExportPluginBase::exportFlight(const Flight &flight, const QString &filePat } QGuiApplication::restoreOverrideCursor(); #ifdef DEBUG - qDebug("%s export %s in %lld ms", qPrintable(QFileInfo(filePath).fileName()), (ok ? qPrintable("SUCCESS") : qPrintable("FAIL")), timer.elapsed()); + qDebug() << QFileInfo(filePath).fileName() << "export" << (ok ? "SUCCESS" : "FAIL") << "in" << timer.elapsed() << "ms"; #endif if (ok) { @@ -181,7 +171,7 @@ bool ExportPluginBase::exportAllAircraft(const Flight &flight, const QString &fi { bool ok {true}; bool replaceAll {false}; - int i = 1; + int i {1}; for (const auto &aircraft : flight) { // Don't append sequence numbers if flight has only one aircraft const QString sequencedFilePath = flight.count() > 1 ? File::getSequenceFilePath(filePath, i) : filePath; @@ -209,10 +199,10 @@ bool ExportPluginBase::exportAllAircraft(const Flight &flight, const QString &fi QGuiApplication::processEvents(); } - QFile file(sequencedFilePath); + QFile file {sequencedFilePath}; ok = file.open(QIODevice::WriteOnly); if (ok) { - ok = exportAircraft(flight, *aircraft, file); + ok = exportAircraft(flight, aircraft, file); d->exportedFilePaths.push_back(sequencedFilePath); } file.close(); diff --git a/src/PluginManager/src/ExportPluginBaseSettings.cpp b/src/PluginManager/src/ExportPluginBaseSettings.cpp index 44d90d321..1fab8d2ac 100644 --- a/src/PluginManager/src/ExportPluginBaseSettings.cpp +++ b/src/PluginManager/src/ExportPluginBaseSettings.cpp @@ -32,9 +32,9 @@ namespace { // Keys - constexpr char ResamplingPeriodKey[] = "ResamplingPeriod"; - constexpr char FormationExportKey[] = "FormationExport"; - constexpr char OpenExportedFilesEnabledKey[] = "OpenExportedFilesEnabled"; + constexpr const char *ResamplingPeriodKey {"ResamplingPeriod"}; + constexpr const char *FormationExportKey {"FormationExport"}; + constexpr const char *OpenExportedFilesEnabledKey {"OpenExportedFilesEnabled"}; // Defaults constexpr SampleRate::ResamplingPeriod DefaultResamplingPeriod = SampleRate::ResamplingPeriod::OneHz; @@ -42,9 +42,8 @@ namespace constexpr bool DefaultOpenExportedFilesEnabled = false; } -class ExportPluginBaseSettingsPrivate +struct ExportPluginBaseSettingsPrivate { -public: ExportPluginBaseSettingsPrivate() : resamplingPeriod(::DefaultResamplingPeriod), formationExport(::DefaultFormationExport), @@ -62,18 +61,9 @@ class ExportPluginBaseSettingsPrivate ExportPluginBaseSettings::ExportPluginBaseSettings() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("ExportPluginBaseSettings::ExportPluginBaseSettings: CREATED"); -#endif -} +{} -ExportPluginBaseSettings::~ExportPluginBaseSettings() noexcept -{ -#ifdef DEBUG - qDebug("ExportPluginBaseSettings::~ExportPluginBaseSettings: DELETED"); -#endif -} +ExportPluginBaseSettings::~ExportPluginBaseSettings() = default; SampleRate::ResamplingPeriod ExportPluginBaseSettings::getResamplingPeriod() const noexcept { @@ -164,7 +154,7 @@ void ExportPluginBaseSettings::addKeysWithDefaults(Settings::KeysWithDefaults &k void ExportPluginBaseSettings::restoreSettings(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; int enumeration = valuesByKey.at(::ResamplingPeriodKey).toInt(&ok); if (ok) { d->resamplingPeriod = static_cast(enumeration); diff --git a/src/PluginManager/src/ImportPluginBase.cpp b/src/PluginManager/src/ImportPluginBase.cpp index 7a1b129e2..bf472feea 100644 --- a/src/PluginManager/src/ImportPluginBase.cpp +++ b/src/PluginManager/src/ImportPluginBase.cpp @@ -57,9 +57,8 @@ #include "ImportPluginBaseSettings.h" #include "ImportPluginBase.h" -class ImportPluginBasePrivate +struct ImportPluginBasePrivate { -public: ImportPluginBasePrivate() : flight(nullptr), aircraftService(std::make_unique()), @@ -79,18 +78,9 @@ class ImportPluginBasePrivate ImportPluginBase::ImportPluginBase() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("ImportPluginBase::ImportPluginBase: CREATED"); -#endif -} +{} -ImportPluginBase::~ImportPluginBase() noexcept -{ -#ifdef DEBUG - qDebug("ImportPluginBase::~ImportPluginBase: DELETED"); -#endif -} +ImportPluginBase::~ImportPluginBase() = default; bool ImportPluginBase::importFlight(FlightService &flightService, Flight &flight) noexcept { @@ -114,7 +104,7 @@ bool ImportPluginBase::importFlight(FlightService &flightService, Flight &flight Settings::getInstance().setExportPath(directoryPath); selectedFilePaths.append(selectedPath); } - ok = importDialog->getSelectedAircraftType(d->aircraftType); + d->aircraftType = importDialog->getSelectedAircraftType(&ok); if (ok) { #ifdef DEBUG QElapsedTimer timer; @@ -125,7 +115,7 @@ bool ImportPluginBase::importFlight(FlightService &flightService, Flight &flight ok = importFlights(selectedFilePaths, flightService, flight); QGuiApplication::restoreOverrideCursor(); #ifdef DEBUG - qDebug("%s import %s in %lld ms", qPrintable(QFileInfo(selectedPath).fileName()), (ok ? qPrintable("SUCCESS") : qPrintable("FAIL")), timer.elapsed()); + qDebug() << QFileInfo(selectedPath).fileName() << "import" << (ok ? "SUCCESS" : "FAIL") << "in" << timer.elapsed() << "ms"; #endif if (!ok && !baseSettings.isImportDirectoryEnabled()) { QMessageBox::warning(PluginBase::getParentWidget(), tr("Import error"), tr("The file %1 could not be imported.").arg(selectedPath)); @@ -265,7 +255,6 @@ void ImportPluginBase::updateAircraftInfo() noexcept FlightPlan &flightPlan = aircraft.getFlightPlan(); int waypointCount = flightPlan.count(); if (waypointCount == 0) { - Waypoint departure; departure.identifier = Waypoint::CustomDepartureIdentifier; departure.latitude = static_cast(firstPositionData.latitude); diff --git a/src/PluginManager/src/ImportPluginBaseSettings.cpp b/src/PluginManager/src/ImportPluginBaseSettings.cpp index a153487c1..a46bef917 100644 --- a/src/PluginManager/src/ImportPluginBaseSettings.cpp +++ b/src/PluginManager/src/ImportPluginBaseSettings.cpp @@ -23,6 +23,7 @@ * DEALINGS IN THE SOFTWARE. */ #include +#include #include #include "ImportPluginBaseSettings.h" @@ -30,17 +31,16 @@ namespace { // Keys - constexpr char ImportDirectoryEnabledKey[] = "ImportDirectoryEnabled"; - constexpr char AddToFlightEnabledKey[] = "AddToFlightEnabled"; + constexpr const char *ImportDirectoryEnabledKey {"ImportDirectoryEnabled"}; + constexpr const char *AddToFlightEnabledKey {"AddToFlightEnabled"}; // Defaults constexpr bool DefaultImportDirectoryEnabled = false; constexpr bool DefaultAddToFlightEnabled = false; } -class ImportPluginBaseSettingsPrivate +struct ImportPluginBaseSettingsPrivate { -public: ImportPluginBaseSettingsPrivate() : importDirectoryEnabled(::DefaultImportDirectoryEnabled), addToFlightEnabled(::DefaultAddToFlightEnabled) @@ -54,18 +54,9 @@ class ImportPluginBaseSettingsPrivate ImportPluginBaseSettings::ImportPluginBaseSettings() noexcept : d(std::make_unique()) -{ -#ifdef DEBUG - qDebug("ImportPluginBaseSettings::ImportPluginBaseSettings: CREATED"); -#endif -} +{} -ImportPluginBaseSettings::~ImportPluginBaseSettings() noexcept -{ -#ifdef DEBUG - qDebug("ImportPluginBaseSettings::~ImportPluginBaseSettings: DELETED"); -#endif -} +ImportPluginBaseSettings::~ImportPluginBaseSettings() = default; bool ImportPluginBaseSettings::isImportDirectoryEnabled() const noexcept { diff --git a/src/PluginManager/src/ModuleManager.cpp b/src/PluginManager/src/ModuleManager.cpp index b2aa26b84..9e8b9b0a8 100644 --- a/src/PluginManager/src/ModuleManager.cpp +++ b/src/PluginManager/src/ModuleManager.cpp @@ -53,15 +53,15 @@ namespace { - constexpr char ModuleDirectoryName[] = "Module"; + constexpr const char *ModuleDirectoryName {"Module"}; #if defined(Q_OS_MAC) - constexpr char PluginDirectoryName[] = "PlugIns"; + constexpr const char *PluginDirectoryName {"PlugIns"}; #else - constexpr char PluginDirectoryName[] = "Plugins"; + constexpr const char *PluginDirectoryName {"Plugins"}; #endif - constexpr char PluginUuidKey[] = "uuid"; - constexpr char PluginNameKey[] = "name"; - constexpr char PluginAfter[] = "after"; + constexpr const char *PluginUuidKey {"uuid"}; + constexpr const char *PluginNameKey {"name"}; + constexpr const char *PluginAfter {"after"}; } struct ModuleManagerPrivate @@ -125,17 +125,11 @@ ModuleManager::ModuleManager(QLayout &layout, QObject *parent) noexcept activateModule(d->moduleRegistry.begin()->first); } frenchConnection(); -#ifdef DEBUG - qDebug() << "ModuleManager::ModuleManager: CREATED."; -#endif } -ModuleManager::~ModuleManager() noexcept +ModuleManager::~ModuleManager() { d->pluginLoader->unload(); -#ifdef DEBUG - qDebug() << "ModuleManager::~ModuleManager: DELETED."; -#endif } const ModuleManager::ActionRegistry &ModuleManager::getActionRegistry() const noexcept @@ -282,14 +276,14 @@ void ModuleManager::initModule(const QString fileName, std::unordered_mapsecond; } - vertex->edges.push_back(afterVertex); + vertex->edges.push_back(afterVertex.get()); } } } void ModuleManager::initModuleActions(const std::unordered_map &moduleInfos, Graph &graph) noexcept { - std::deque> sortedModules; + std::deque sortedModules; // Reverse sorting, because the "after" edge (directed from A to B: A --- after ---> B) really means that // "first B, then A" (= reversed topological sorting) sortedModules = UuidSort::topologicalSort(graph, UuidSort::Sorting::Reverse); diff --git a/src/PluginManager/src/PluginBase.cpp b/src/PluginManager/src/PluginBase.cpp index 4270a1c84..1dfa0d0cc 100644 --- a/src/PluginManager/src/PluginBase.cpp +++ b/src/PluginManager/src/PluginBase.cpp @@ -28,9 +28,8 @@ #include #include "PluginBase.h" -class PluginBasePrivate +struct PluginBasePrivate { -public: PluginBasePrivate() : parent(nullptr) {} @@ -44,8 +43,7 @@ PluginBase::PluginBase() : d(std::make_unique()) {} -PluginBase::~PluginBase() -{} +PluginBase::~PluginBase() = default; QWidget *PluginBase::getParentWidget() const noexcept { diff --git a/src/PluginManager/src/PluginManager.cpp b/src/PluginManager/src/PluginManager.cpp index 3e2d34ae3..6c6ae69b3 100644 --- a/src/PluginManager/src/PluginManager.cpp +++ b/src/PluginManager/src/PluginManager.cpp @@ -23,6 +23,7 @@ * DEALINGS IN THE SOFTWARE. */ #include +#include #include #include @@ -44,20 +45,19 @@ namespace { - constexpr char ExportDirectoryName[] = "Export"; - constexpr char ImportDirectoryName[] = "Import"; + constexpr const char *ExportDirectoryName {"Export"}; + constexpr const char *ImportDirectoryName {"Import"}; #if defined(Q_OS_MAC) - constexpr char PluginDirectoryName[] = "PlugIns"; + constexpr const char *PluginDirectoryName {"PlugIns"}; #else - constexpr char PluginDirectoryName[] = "Plugins"; + constexpr const char *PluginDirectoryName {"Plugins"}; #endif - constexpr char PluginUuidKey[] = "uuid"; - constexpr char PluginNameKey[] = "name"; + constexpr const char *PluginUuidKey {"uuid"}; + constexpr const char *PluginNameKey {"name"}; } -class PluginManagerPrivate +struct PluginManagerPrivate { -public: PluginManagerPrivate() noexcept : parentWidget(nullptr) { @@ -71,26 +71,26 @@ class PluginManagerPrivate pluginsDirectory.cd(PluginDirectoryName); } - ~PluginManagerPrivate() noexcept - {} + ~PluginManagerPrivate() = default; QWidget *parentWidget; QDir pluginsDirectory; // Plugin UUID / plugin path QMap exportPluginRegistry; QMap importPluginRegistry; - static PluginManager *instance; + + static inline std::once_flag onceFlag; + static inline PluginManager *instance; }; -PluginManager *PluginManagerPrivate::instance = nullptr; // PUBLIC PluginManager &PluginManager::getInstance() noexcept { - if (PluginManagerPrivate::instance == nullptr) { + std::call_once(PluginManagerPrivate::onceFlag, []() { PluginManagerPrivate::instance = new PluginManager(); - } + }); return *PluginManagerPrivate::instance; } @@ -119,7 +119,7 @@ std::vector PluginManager::initialiseImportPlugins() noex bool PluginManager::importFlight(const QUuid &pluginUuid, FlightService &flightService, Flight &flight) const noexcept { - bool ok; + bool ok {false}; if (d->importPluginRegistry.contains(pluginUuid)) { const QString pluginPath = d->importPluginRegistry.value(pluginUuid); QPluginLoader loader(pluginPath); @@ -134,15 +134,13 @@ bool PluginManager::importFlight(const QUuid &pluginUuid, FlightService &flightS ok = false; } loader.unload(); - } else { - ok = false; } return ok; } bool PluginManager::exportFlight(const Flight &flight, const QUuid &pluginUuid) const noexcept { - bool ok; + bool ok {false}; if (d->exportPluginRegistry.contains(pluginUuid)) { const QString pluginPath = d->exportPluginRegistry.value(pluginUuid); QPluginLoader loader(pluginPath); @@ -157,28 +155,24 @@ bool PluginManager::exportFlight(const Flight &flight, const QUuid &pluginUuid) ok = false; } loader.unload(); - } else { - ok = false; } return ok; } -// PROTECTED +// PRIVATE -PluginManager::~PluginManager() noexcept +PluginManager::PluginManager() noexcept + : d(std::make_unique()) { #ifdef DEBUG - qDebug() << "PluginManager::~PluginManager: DELETED"; + qDebug() << "PluginManager::PluginManager: CREATED"; #endif } -// PRIVATE - -PluginManager::PluginManager() noexcept - : d(std::make_unique()) +PluginManager::~PluginManager() { #ifdef DEBUG - qDebug() << "PluginManager::PluginManager: CREATED"; + qDebug() << "PluginManager::~PluginManager: DELETED"; #endif } diff --git a/src/PluginManager/src/SkyConnectManager.cpp b/src/PluginManager/src/SkyConnectManager.cpp index 491f31eca..b0d226519 100644 --- a/src/PluginManager/src/SkyConnectManager.cpp +++ b/src/PluginManager/src/SkyConnectManager.cpp @@ -24,6 +24,7 @@ */ #include #include +#include #include #include @@ -45,15 +46,15 @@ namespace { - constexpr char ConnectPluginDirectoryName[] = "Connect"; + constexpr const char *ConnectPluginDirectoryName {"Connect"}; #if defined(Q_OS_MAC) - constexpr char PluginDirectoryName[] = "PlugIns"; + constexpr const char *PluginDirectoryName {"PlugIns"}; #else - constexpr char PluginDirectoryName[] = "Plugins"; + constexpr const char *PluginDirectoryName {"Plugins"}; #endif - constexpr char PluginUuidKey[] = "uuid"; - constexpr char PluginNameKey[] = "name"; - constexpr char PluginFlightSimulatorNameKey[] = "flightSimulator"; + constexpr const char *PluginUuidKey {"uuid"}; + constexpr const char *PluginNameKey {"name"}; + constexpr const char *PluginFlightSimulatorNameKey {"flightSimulator"}; } struct skyConnectManagerPrivate @@ -83,18 +84,17 @@ struct skyConnectManagerPrivate QPluginLoader *pluginLoader; QUuid currentPluginUuid; - static SkyConnectManager *instance; + static inline std::once_flag onceFlag; + static inline SkyConnectManager *instance; }; -SkyConnectManager *skyConnectManagerPrivate::instance = nullptr; - // PUBLIC SkyConnectManager &SkyConnectManager::getInstance() noexcept { - if (skyConnectManagerPrivate::instance == nullptr) { + std::call_once(skyConnectManagerPrivate::onceFlag, []() { skyConnectManagerPrivate::instance = new SkyConnectManager(); - } + }); return *skyConnectManagerPrivate::instance; } @@ -405,15 +405,6 @@ bool SkyConnectManager::tryAndSetCurrentSkyConnect(const QUuid &uuid) noexcept return ok; } -// PROTECTED - -SkyConnectManager::~SkyConnectManager() noexcept -{ -#ifdef DEBUG - qDebug() << "SkyConnectManager::~SkyConnectManager: DELETED"; -#endif -} - // PRIVATE SkyConnectManager::SkyConnectManager() noexcept @@ -425,6 +416,14 @@ SkyConnectManager::SkyConnectManager() noexcept #endif } +SkyConnectManager::~SkyConnectManager() +{ +#ifdef DEBUG + qDebug() << "SkyConnectManager::~SkyConnectManager: DELETED"; +#endif +} + + void SkyConnectManager::frenchConnection() noexcept { // Settings diff --git a/src/Plugins/Connect/MSFSSimConnectPlugin/src/MSFSSimConnectPlugin.cpp b/src/Plugins/Connect/MSFSSimConnectPlugin/src/MSFSSimConnectPlugin.cpp index 290fcc9e1..56f1f9fb8 100644 --- a/src/Plugins/Connect/MSFSSimConnectPlugin/src/MSFSSimConnectPlugin.cpp +++ b/src/Plugins/Connect/MSFSSimConnectPlugin/src/MSFSSimConnectPlugin.cpp @@ -40,6 +40,7 @@ #include +#include #include #include #include @@ -227,7 +228,7 @@ void MSFSSimConnectPlugin::onStopRecording() noexcept const Aircraft &userAircraft = flight.getUserAircraft(); FlightPlan &flightPlan = userAircraft.getFlightPlan(); for (const auto &it : d->flightPlan) { - flightPlan.add(it.second); + flight.addWaypoint(it.second); } // Update timestamp and simulation time of last waypoint @@ -237,7 +238,7 @@ void MSFSSimConnectPlugin::onStopRecording() noexcept waypoint.localTime = d->currentLocalDateTime; waypoint.zuluTime = d->currentZuluDateTime; waypoint.timestamp = getCurrentTimestamp(); - flightPlan.update(waypointCount - 1, waypoint); + flight.updateWaypoint(waypointCount - 1, waypoint); } else if (waypointCount == 0 && userAircraft.getPosition().count() > 0) { Waypoint departureWaypoint; PositionData position = userAircraft.getPosition().getFirst(); @@ -248,7 +249,7 @@ void MSFSSimConnectPlugin::onStopRecording() noexcept departureWaypoint.localTime = flight.getFlightCondition().startLocalTime; departureWaypoint.zuluTime = flight.getFlightCondition().startZuluTime; departureWaypoint.timestamp = 0; - flightPlan.add(departureWaypoint); + flight.addWaypoint(departureWaypoint); Waypoint arrivalWaypoint; position = userAircraft.getPosition().getLast(); @@ -259,7 +260,7 @@ void MSFSSimConnectPlugin::onStopRecording() noexcept arrivalWaypoint.localTime = d->currentLocalDateTime; arrivalWaypoint.zuluTime = d->currentZuluDateTime; arrivalWaypoint.timestamp = std::max(getCurrentTimestamp(), departureWaypoint.timestamp + 1); - flightPlan.add(arrivalWaypoint); + flight.addWaypoint(arrivalWaypoint); } // Update end simulation time of flight conditions @@ -308,12 +309,12 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // In case of "fly with formation" always send all formation aircraft (as AI aircraft): we simply do this // by setting the userAircraftId to an invalid ID, so no aircraft in the Flight is considered the "user aircraft" // (which is really being controlled by the user as an "additional aircraft", next to the formation) - const std::int64_t userAircraftId = getReplayMode() != ReplayMode::FlyWithFormation ? flight.getUserAircraft().getId() : Aircraft::InvalidId; - bool ok = true; + const std::int64_t userAircraftId = getReplayMode() != ReplayMode::FlyWithFormation ? flight.getUserAircraft().getId() : Const::InvalidId; + bool ok {true}; for (auto &aircraft : flight) { // Replay AI aircraft - if any - during recording (if all aircraft are selected for replay) - const bool isUserAircraft = aircraft->getId() == userAircraftId; + const bool isUserAircraft = aircraft.getId() == userAircraftId; if (isUserAircraft && getReplayMode() == ReplayMode::UserAircraftManualControl) { // The user aircraft (of the formation) is manually flown continue; @@ -327,11 +328,11 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // When recording (a formation flight) we send the already recorded aircraft, except the // user aircraft (which is currently being recorded) if (isConnectedWithSim() && getState() != Connect::State::Recording || !isUserAircraft) { - const std::int64_t objectId = isUserAircraft ? ::SIMCONNECT_OBJECT_ID_USER : d->simConnectAi->getSimulatedObjectByAircraftId(aircraft->getId()); + const std::int64_t objectId = isUserAircraft ? ::SIMCONNECT_OBJECT_ID_USER : d->simConnectAi->getSimulatedObjectByAircraftId(aircraft.getId()); if (objectId != SimConnectAi::InvalidObjectId) { ok = true; - const PositionData &positionData = aircraft->getPosition().interpolate(currentTimestamp, access); + const PositionData &positionData = aircraft.getPosition().interpolate(currentTimestamp, access); if (!positionData.isNull()) { SimConnectPositionRequest simConnnectPositionRequest; simConnnectPositionRequest.fromPositionData(positionData); @@ -343,7 +344,7 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // Engine if (ok) { - const EngineData &engineData = aircraft->getEngine().interpolate(currentTimestamp, access); + const EngineData &engineData = aircraft.getEngine().interpolate(currentTimestamp, access); if (!engineData.isNull()) { SimConnectEngineRequest simConnectEngineRequest; simConnectEngineRequest.fromEngineData(engineData); @@ -359,7 +360,7 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // Primary flight controls if (ok) { - const PrimaryFlightControlData &primaryFlightControlData = aircraft->getPrimaryFlightControl().interpolate(currentTimestamp, access); + const PrimaryFlightControlData &primaryFlightControlData = aircraft.getPrimaryFlightControl().interpolate(currentTimestamp, access); if (!primaryFlightControlData.isNull()) { SimConnectPrimaryFlightControl simConnectPrimaryFlightControl; simConnectPrimaryFlightControl.fromPrimaryFlightControlData(primaryFlightControlData); @@ -372,7 +373,7 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // Secondary flight controls if (ok) { - const SecondaryFlightControlData &secondaryFlightControlData = aircraft->getSecondaryFlightControl().interpolate(currentTimestamp, access); + const SecondaryFlightControlData &secondaryFlightControlData = aircraft.getSecondaryFlightControl().interpolate(currentTimestamp, access); if (!secondaryFlightControlData.isNull()) { SimConnectSecondaryFlightControl simConnectSecondaryFlightControl; simConnectSecondaryFlightControl.fromSecondaryFlightControlData(secondaryFlightControlData); @@ -385,7 +386,7 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // Aircraft handles & brakes if (ok) { - const AircraftHandleData aircraftHandleData = aircraft->getAircraftHandle().interpolate(currentTimestamp, access); + const AircraftHandleData aircraftHandleData = aircraft.getAircraftHandle().interpolate(currentTimestamp, access); if (!aircraftHandleData.isNull()) { SimConnectAircraftHandle simConnectAircraftHandle; simConnectAircraftHandle.fromAircraftHandleData(aircraftHandleData); @@ -398,7 +399,7 @@ bool MSFSSimConnectPlugin::sendAircraftData(std::int64_t currentTimestamp, TimeV // Lights if (ok) { - const LightData &lightData = aircraft->getLight().interpolate(currentTimestamp, access); + const LightData &lightData = aircraft.getLight().interpolate(currentTimestamp, access); if (!lightData.isNull()) { SimConnectLight simConnectLight; simConnectLight.fromLightData(lightData); @@ -536,37 +537,31 @@ void MSFSSimConnectPlugin::recordData() noexcept userAircraft.getPosition().upsertLast(std::move(d->currentPositionData)); // Processed dataStored = true; - d->currentPositionData = PositionData::NullData; } if (!d->currentEngineData.isNull()) { userAircraft.getEngine().upsertLast(std::move(d->currentEngineData)); // Processed dataStored = true; - d->currentEngineData = EngineData::NullData; } if (!d->currentPrimaryFlightControlData.isNull()) { userAircraft.getPrimaryFlightControl().upsertLast(std::move(d->currentPrimaryFlightControlData)); // Processed dataStored = true; - d->currentPrimaryFlightControlData = PrimaryFlightControlData::NullData; } if (!d->currentSecondaryFlightControlData.isNull()) { userAircraft.getSecondaryFlightControl().upsertLast(std::move(d->currentSecondaryFlightControlData)); // Processed dataStored = true; - d->currentSecondaryFlightControlData = SecondaryFlightControlData::NullData; } if (!d->currentAircraftHandleData.isNull()) { userAircraft.getAircraftHandle().upsertLast(std::move(d->currentAircraftHandleData)); // Processed dataStored = true; - d->currentAircraftHandleData = AircraftHandleData::NullData; } if (!d->currentLightData.isNull()) { userAircraft.getLight().upsertLast(std::move(d->currentLightData)); // Processed dataStored = true; - d->currentLightData = LightData::NullData; } if (dataStored) { if (!isElapsedTimerRunning()) { @@ -587,12 +582,12 @@ void MSFSSimConnectPlugin::frenchConnection() noexcept void MSFSSimConnectPlugin::resetCurrentSampleData() noexcept { - d->currentPositionData = PositionData::NullData; - d->currentEngineData = EngineData::NullData; - d->currentPrimaryFlightControlData = PrimaryFlightControlData::NullData; - d->currentSecondaryFlightControlData = SecondaryFlightControlData::NullData; - d->currentAircraftHandleData = AircraftHandleData::NullData; - d->currentLightData = LightData::NullData; + d->currentPositionData.reset(); + d->currentEngineData.reset(); + d->currentPrimaryFlightControlData.reset(); + d->currentSecondaryFlightControlData.reset(); + d->currentAircraftHandleData.reset(); + d->currentLightData.reset(); } bool MSFSSimConnectPlugin::reconnectWithSim() noexcept diff --git a/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAi.cpp b/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAi.cpp index bd50e61cc..e51d6bf39 100644 --- a/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAi.cpp +++ b/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAi.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -82,7 +83,7 @@ void SimConnectAi::addObject(const Aircraft &aircraft, std::int64_t timestamp) n { // Check if the newly added aircraft has any recording yet // (otherwise it is the new user aircraft being added for a new recording) - if (aircraft.getId() != Aircraft::InvalidId) { + if (aircraft.getId() != Const::InvalidId) { const AircraftInfo aircraftInfo = aircraft.getAircraftInfo(); Position &position = aircraft.getPosition(); const PositionData positioNData = position.interpolate(timestamp, TimeVariableData::Access::Seek); diff --git a/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAircraftInfo.h b/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAircraftInfo.h index ec0f3303f..377d52aaf 100644 --- a/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAircraftInfo.h +++ b/src/Plugins/Connect/MSFSSimConnectPlugin/src/SimConnectAircraftInfo.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -122,7 +123,7 @@ struct SimConnectAircraftInfo inline AircraftInfo toAircraftInfo() const noexcept { - AircraftInfo aircraftInfo(Aircraft::InvalidId); + AircraftInfo aircraftInfo(Const::InvalidId); // Length check if (SUCCEEDED(StringCbLengthA(&title[0], sizeof(title), nullptr))) { diff --git a/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.cpp b/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.cpp index 2484af79f..2a51232fa 100644 --- a/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.cpp +++ b/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.cpp @@ -69,9 +69,8 @@ namespace { const int ReplayPeriod = static_cast(std::round(1000.0 / ReplayRate)); } -class PathCreatorPluginPrivate +struct PathCreatorPluginPrivate { -public: PathCreatorPluginPrivate() noexcept : randomGenerator(QRandomGenerator::global()) { @@ -145,13 +144,14 @@ void PathCreatorPlugin::onStopRecording() noexcept flightCondition.endZuluTime = QDateTime::currentDateTimeUtc(); flight.setFlightCondition(flightCondition); - FlightPlan &flightPlan = flight.getUserAircraft().getFlightPlan(); + Aircraft &aircraft = flight.getUserAircraft(); + FlightPlan &flightPlan = aircraft.getFlightPlan(); int waypointCount = flightPlan.count(); if (waypointCount > 1) { Waypoint waypoint = flightPlan[waypointCount - 1]; waypoint.localTime = QDateTime::currentDateTime(); waypoint.zuluTime = QDateTime::currentDateTimeUtc(); - flightPlan.update(waypointCount - 1, waypoint); + flight.updateWaypoint(waypointCount - 1, waypoint); } } @@ -206,7 +206,7 @@ bool PathCreatorPlugin::connectWithSim() noexcept return true; } -void PathCreatorPlugin::onAddAiObject(const Aircraft &aircraft) noexcept +void PathCreatorPlugin::onAddAiObject([[maybe_unused]] const Aircraft &aircraft) noexcept { #ifdef DEBUG qDebug() << "PathCreatorPlugin::onAddAiObject: CALLED"; @@ -402,8 +402,8 @@ void PathCreatorPlugin::recordWaypoint() noexcept waypoint.zuluTime = QDateTime::currentDateTimeUtc(); waypoint.timestamp = getCurrentTimestamp(); - Aircraft &aircraft = getCurrentFlight().getUserAircraft(); - aircraft.getFlightPlan().add(waypoint); + Flight &flight = getCurrentFlight(); + flight.addWaypoint(waypoint); } } diff --git a/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.h b/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.h index 4dcefb836..130229a4c 100644 --- a/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.h +++ b/src/Plugins/Connect/PathCreator/src/PathCreatorPlugin.h @@ -37,8 +37,8 @@ class Flight; class Aircraft; struct PositionData; -class InitialPosition; -class PathCreatorPluginPrivate; +struct InitialPosition; +struct PathCreatorPluginPrivate; class PathCreatorPlugin : public AbstractSkyConnect { @@ -82,7 +82,7 @@ protected slots: void recordData() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void recordPositionData(std::int64_t timestamp) noexcept; diff --git a/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.cpp b/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.cpp index 070713e9e..dc774f71d 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.cpp +++ b/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.cpp @@ -24,15 +24,17 @@ */ #include #include +#ifdef DEBUG +#include +#endif #include #include "CsvExportOptionWidget.h" #include "CsvExportSettings.h" #include "ui_CsvExportOptionWidget.h" -class CsvExportOptionWidgetPrivate +struct CsvExportOptionWidgetPrivate { -public: CsvExportOptionWidgetPrivate(CsvExportSettings &theSettings) noexcept : settings(theSettings) {} @@ -52,14 +54,14 @@ CsvExportOptionWidget::CsvExportOptionWidget(CsvExportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("CsvExportOptionWidget::CsvExportOptionWidget: CREATED"); + qDebug() << "CsvExportOptionWidget::CsvExportOptionWidget: CREATED"; #endif } CsvExportOptionWidget::~CsvExportOptionWidget() noexcept { #ifdef DEBUG - qDebug("CsvExportOptionWidget::~CsvExportOptionWidget: DELETED"); + qDebug() << "CsvExportOptionWidget::~CsvExportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.h b/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.h index 876f77ca3..04369a913 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.h +++ b/src/Plugins/Export/CsvExport/src/CsvExportOptionWidget.h @@ -34,7 +34,7 @@ namespace Ui { } class CsvExportSettings; -class CsvExportOptionWidgetPrivate; +struct CsvExportOptionWidgetPrivate; class CsvExportOptionWidget : public QWidget { @@ -45,7 +45,7 @@ class CsvExportOptionWidget : public QWidget private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Export/CsvExport/src/CsvExportPlugin.cpp b/src/Plugins/Export/CsvExport/src/CsvExportPlugin.cpp index 6f5bca143..dc5c96d32 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportPlugin.cpp +++ b/src/Plugins/Export/CsvExport/src/CsvExportPlugin.cpp @@ -27,6 +27,9 @@ // Implements the % operator for string concatenation #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -38,7 +41,7 @@ #include "PositionAndAttitudeCsvWriter.h" #include "CsvExportPlugin.h" -class CsvExportPluginPrivate +struct CsvExportPluginPrivate { public: CsvExportPluginPrivate() noexcept @@ -55,14 +58,14 @@ CsvExportPlugin::CsvExportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("CsvExportPlugin::CsvExportPlugin: PLUGIN LOADED"); + qDebug() << "CsvExportPlugin::CsvExportPlugin: PLUGIN LOADED"; #endif } CsvExportPlugin::~CsvExportPlugin() noexcept { #ifdef DEBUG - qDebug("CsvExportPlugin::~CsvExportPlugin: PLUGIN UNLOADED"); + qDebug() << "CsvExportPlugin::~CsvExportPlugin: PLUGIN UNLOADED"; #endif } @@ -101,7 +104,6 @@ bool CsvExportPlugin::exportFlight([[maybe_unused]] const Flight &flight, [[mayb bool CsvExportPlugin::exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept { - bool ok; std::unique_ptr writer; switch (d->pluginSettings.getFormat()) { case CsvExportSettings::Format::SkyDolly: @@ -115,10 +117,9 @@ bool CsvExportPlugin::exportAircraft(const Flight &flight, const Aircraft &aircr break; } + bool ok {false}; if (writer != nullptr) { ok = writer->write(flight, aircraft, io); - } else { - ok = false; } return ok; diff --git a/src/Plugins/Export/CsvExport/src/CsvExportPlugin.h b/src/Plugins/Export/CsvExport/src/CsvExportPlugin.h index 2e85f5a4d..77d450eb4 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportPlugin.h +++ b/src/Plugins/Export/CsvExport/src/CsvExportPlugin.h @@ -41,7 +41,7 @@ class QDateTime; class Aircraft; -class CsvExportPluginPrivate; +struct CsvExportPluginPrivate; class CsvExportPlugin : public ExportPluginBase { @@ -62,7 +62,7 @@ class CsvExportPlugin : public ExportPluginBase virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // CSVEXPORTPLUGIN_H diff --git a/src/Plugins/Export/CsvExport/src/CsvExportSettings.cpp b/src/Plugins/Export/CsvExport/src/CsvExportSettings.cpp index a86b9b44d..9dc28b9e8 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportSettings.cpp +++ b/src/Plugins/Export/CsvExport/src/CsvExportSettings.cpp @@ -26,6 +26,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -35,15 +38,14 @@ namespace { // Keys - constexpr char FormatKey[] = "Format"; + constexpr const char *FormatKey {"Format"}; // Defaults constexpr CsvExportSettings::Format DefaultFormat = CsvExportSettings::Format::SkyDolly; } -class CsvExportSettingsPrivate +struct CsvExportSettingsPrivate { -public: CsvExportSettingsPrivate() {} @@ -57,14 +59,14 @@ CsvExportSettings::CsvExportSettings() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("CsvExportSettings::CsvExportSettings: CREATED"); + qDebug() << "CsvExportSettings::CsvExportSettings: CREATED"; #endif } CsvExportSettings::~CsvExportSettings() noexcept { #ifdef DEBUG - qDebug("CsvExportSettings::~CsvExportSettings: DELETED"); + qDebug() << "CsvExportSettings::~CsvExportSettings: DELETED"; #endif } @@ -103,7 +105,7 @@ void CsvExportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void CsvExportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::FormatKey).toInt(&ok); if (ok) { d->format = static_cast(enumeration); diff --git a/src/Plugins/Export/CsvExport/src/CsvExportSettings.h b/src/Plugins/Export/CsvExport/src/CsvExportSettings.h index 721e30f06..baa42b4c5 100644 --- a/src/Plugins/Export/CsvExport/src/CsvExportSettings.h +++ b/src/Plugins/Export/CsvExport/src/CsvExportSettings.h @@ -32,7 +32,7 @@ #include #include -class CsvExportSettingsPrivate; +struct CsvExportSettingsPrivate; class CsvExportSettings : public ExportPluginBaseSettings { @@ -66,7 +66,7 @@ class CsvExportSettings : public ExportPluginBaseSettings virtual void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // CSVEXPORTSETTINGS_H diff --git a/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.cpp b/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.cpp index 62fdbfebf..301eb4c1e 100644 --- a/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.cpp +++ b/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.cpp @@ -23,6 +23,7 @@ * DEALINGS IN THE SOFTWARE. */ #include +#include #include #include @@ -30,6 +31,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -54,9 +58,8 @@ namespace inline const QString DirectionColumn = QStringLiteral("Direction"); } -class FlightRadar24CsvWriterPrivate +struct FlightRadar24CsvWriterPrivate { -public: FlightRadar24CsvWriterPrivate(const CsvExportSettings &thePluginSettings) noexcept : pluginSettings(thePluginSettings) {} @@ -72,14 +75,14 @@ FlightRadar24CsvWriter::FlightRadar24CsvWriter(const CsvExportSettings &pluginSe : d(std::make_unique(pluginSettings)) { #ifdef DEBUG - qDebug("FlightRadar24CsvWriter::FlightRadar24CsvWriter: CREATED"); + qDebug() << "FlightRadar24CsvWriter::FlightRadar24CsvWriter: CREATED"; #endif } FlightRadar24CsvWriter::~FlightRadar24CsvWriter() noexcept { #ifdef DEBUG - qDebug("FlightRadar24CsvWriter::~FlightRadar24CsvWriter: DELETED"); + qDebug() << "FlightRadar24CsvWriter::~FlightRadar24CsvWriter: DELETED"; #endif } @@ -99,9 +102,8 @@ bool FlightRadar24CsvWriter::write(const Flight &flight, const Aircraft &aircraf if (ok) { const QDateTime startDateTimeUtc = flight.getAircraftStartZuluTime(aircraft); const QString callSign = aircraft.getAircraftInfo().flightNumber; - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - for (PositionData &positionData : interpolatedPositionData) { + const std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + for (const PositionData &positionData : interpolatedPositionData) { if (!positionData.isNull()) { const QDateTime dateTimeUtc = startDateTimeUtc.addMSecs(positionData.timestamp); const std::int64_t secsSinceEpoch = dateTimeUtc.toSecsSinceEpoch(); diff --git a/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.h b/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.h index c94a85f1b..6d1b4b5bc 100644 --- a/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.h +++ b/src/Plugins/Export/CsvExport/src/FlightRadar24CsvWriter.h @@ -33,7 +33,7 @@ class Flight; class Aircraft; class CsvExportSettings; class PositionData; -class FlightRadar24CsvWriterPrivate; +struct FlightRadar24CsvWriterPrivate; class FlightRadar24CsvWriter : public CsvWriterIntf { @@ -44,7 +44,7 @@ class FlightRadar24CsvWriter : public CsvWriterIntf virtual bool write(const Flight &flight, const Aircraft &aircraft, QIODevice &ioDevice) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; static inline QString formatPosition(const PositionData &positionData) noexcept; }; diff --git a/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.cpp b/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.cpp index e0a2c3fe0..1efaffd4f 100644 --- a/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.cpp +++ b/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -60,9 +61,8 @@ namespace inline const QString HeadingColumn = QStringLiteral("Heading"); } -class PositionAndAttitudeCsvWriterPrivate +struct PositionAndAttitudeCsvWriterPrivate { -public: PositionAndAttitudeCsvWriterPrivate(const CsvExportSettings &thePluginSettings) noexcept : pluginSettings(thePluginSettings) {} @@ -106,9 +106,8 @@ bool PositionAndAttitudeCsvWriter::write(const Flight &flight, const Aircraft &a bool ok = io.write(csv.toUtf8()); if (ok) { const QDateTime startDateTimeUtc = flight.getAircraftStartZuluTime(aircraft); - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - for (PositionData &positionData : interpolatedPositionData) { + const std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + for (const PositionData &positionData : interpolatedPositionData) { if (!positionData.isNull()) { const QDateTime dateTimeUtc = startDateTimeUtc.addMSecs(positionData.timestamp); const QString csv = QString::number(positionData.timestamp) % CsvConst::CommaSep % diff --git a/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.h b/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.h index 0b2e232dd..278c72092 100644 --- a/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.h +++ b/src/Plugins/Export/CsvExport/src/PositionAndAttitudeCsvWriter.h @@ -33,7 +33,7 @@ class Flight; class Aircraft; class CsvExportSettings; class PositionData; -class PositionAndAttitudeCsvWriterPrivate; +struct PositionAndAttitudeCsvWriterPrivate; class PositionAndAttitudeCsvWriter : public CsvWriterIntf { @@ -44,7 +44,7 @@ class PositionAndAttitudeCsvWriter : public CsvWriterIntf virtual bool write(const Flight &flight, const Aircraft &aircraft, QIODevice &ioDevice) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // POSITIONANDATTITUDECSVWRITER_H diff --git a/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.cpp b/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.cpp index f826f4b76..bd966417f 100644 --- a/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.cpp +++ b/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.cpp @@ -28,6 +28,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -49,9 +52,8 @@ #include "CsvExportSettings.h" #include "SkyDollyCsvWriter.h" -class SkyDollyCsvWriterPrivate +struct SkyDollyCsvWriterPrivate { -public: SkyDollyCsvWriterPrivate(const CsvExportSettings &thePluginSettings) noexcept : pluginSettings(thePluginSettings) {} @@ -67,14 +69,14 @@ SkyDollyCsvWriter::SkyDollyCsvWriter(const CsvExportSettings &pluginSettings) no : d(std::make_unique(pluginSettings)) { #ifdef DEBUG - qDebug("SkyDollyCsvWriter::SkyDollyCsvWriter: CREATED"); + qDebug() << "SkyDollyCsvWriter::SkyDollyCsvWriter: CREATED"; #endif } SkyDollyCsvWriter::~SkyDollyCsvWriter() noexcept { #ifdef DEBUG - qDebug("SkyDollyCsvWriter::~SkyDollyCsvWriter: DELETED"); + qDebug() << "SkyDollyCsvWriter::~SkyDollyCsvWriter: DELETED"; #endif } diff --git a/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.h b/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.h index 34955f467..78128cdbb 100644 --- a/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.h +++ b/src/Plugins/Export/CsvExport/src/SkyDollyCsvWriter.h @@ -43,18 +43,18 @@ struct SecondaryFlightControlData; struct AircraftHandleData; struct LightData; class CsvExportSettings; -class SkyDollyCsvWriterPrivate; +struct SkyDollyCsvWriterPrivate; class SkyDollyCsvWriter : public CsvWriterIntf { public: SkyDollyCsvWriter(const CsvExportSettings &pluginSettings) noexcept; - virtual ~SkyDollyCsvWriter() noexcept; + ~SkyDollyCsvWriter() noexcept override; - virtual bool write(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; + bool write(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; static QString getPositionHeader() noexcept; static QString getPositionData(const PositionData &data) noexcept; diff --git a/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.cpp b/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.cpp index 61d253bda..eba196184 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.cpp +++ b/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.cpp @@ -24,15 +24,17 @@ */ #include #include +#ifdef DEBUG +#include +#endif #include #include "GpxExportOptionWidget.h" #include "GpxExportSettings.h" #include "ui_GpxExportOptionWidget.h" -class GpxExportOptionWidgetPrivate +struct GpxExportOptionWidgetPrivate { -public: GpxExportOptionWidgetPrivate(GpxExportSettings &theSettings) noexcept : settings(theSettings) {} @@ -52,14 +54,14 @@ GpxExportOptionWidget::GpxExportOptionWidget(GpxExportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("GpxExportOptionWidget::GpxExportOptionWidget: CREATED"); + qDebug() << "GpxExportOptionWidget::GpxExportOptionWidget: CREATED"; #endif } GpxExportOptionWidget::~GpxExportOptionWidget() noexcept { #ifdef DEBUG - qDebug("GpxExportOptionWidget::~GpxExportOptionWidget: DELETED"); + qDebug() << "GpxExportOptionWidget::~GpxExportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.h b/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.h index ffd095734..925b6652f 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.h +++ b/src/Plugins/Export/GpxExport/src/GpxExportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class GpxExportSettings; -class GpxExportOptionWidgetPrivate; +struct GpxExportOptionWidgetPrivate; class GpxExportOptionWidget : public QWidget { Q_OBJECT public: explicit GpxExportOptionWidget(GpxExportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~GpxExportOptionWidget() noexcept; + ~GpxExportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Export/GpxExport/src/GpxExportPlugin.cpp b/src/Plugins/Export/GpxExport/src/GpxExportPlugin.cpp index 5f9f6c689..2feed16f8 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportPlugin.cpp +++ b/src/Plugins/Export/GpxExport/src/GpxExportPlugin.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -76,14 +75,14 @@ GpxExportPlugin::GpxExportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("GpxExportPlugin::GpxExportPlugin: PLUGIN LOADED"); + qDebug() << "GpxExportPlugin::GpxExportPlugin: PLUGIN LOADED"; #endif } GpxExportPlugin::~GpxExportPlugin() noexcept { #ifdef DEBUG - qDebug("GpxExportPlugin::~GpxExportPlugin: PLUGIN UNLOADED"); + qDebug() << "GpxExportPlugin::~GpxExportPlugin: PLUGIN UNLOADED"; #endif } @@ -182,9 +181,9 @@ bool GpxExportPlugin::exportFlightInfo(QIODevice &io) const noexcept bool GpxExportPlugin::exportAllAircraft(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; for (const auto &aircraft : *d->flight) { - ok = exportAircraft(*aircraft, io); + ok = exportAircraft(aircraft, io); if (!ok) { break; } @@ -203,9 +202,8 @@ bool GpxExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) co break; } - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - bool ok = true; + const std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + bool ok {true}; if (interpolatedPositionData.size() > 0) { const AircraftInfo &aircraftInfo = aircraft.getAircraftInfo(); @@ -218,7 +216,7 @@ bool GpxExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) co ok = io.write(trackBegin.toUtf8()); if (ok) { - for (PositionData &positionData : interpolatedPositionData) { + for (const PositionData &positionData : interpolatedPositionData) { ok = exportTrackPoint(positionData, io); if (!ok) { break; @@ -239,7 +237,7 @@ bool GpxExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) co bool GpxExportPlugin::exportWaypoints(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; const FlightPlan &flightPlan = d->flight->getUserAircraft().getFlightPlan(); for (const Waypoint &waypoint : flightPlan) { ok = exportWaypoint(waypoint, io); diff --git a/src/Plugins/Export/GpxExport/src/GpxExportPlugin.h b/src/Plugins/Export/GpxExport/src/GpxExportPlugin.h index 1b709d6c8..184f03fc0 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportPlugin.h +++ b/src/Plugins/Export/GpxExport/src/GpxExportPlugin.h @@ -42,7 +42,7 @@ class Flight; class Aircraft; struct PositionData; struct Waypoint; -class GpxExportPluginPrivate; +struct GpxExportPluginPrivate; class GpxExportPlugin : public ExportPluginBase { @@ -51,19 +51,19 @@ class GpxExportPlugin : public ExportPluginBase Q_INTERFACES(ExportIntf) public: GpxExportPlugin() noexcept; - virtual ~GpxExportPlugin() noexcept; + ~GpxExportPlugin() noexcept override; protected: - virtual ExportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool hasMultiAircraftSupport() const noexcept override; - virtual bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; - virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; + ExportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool hasMultiAircraftSupport() const noexcept override; + bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; + bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; bool exportHeader(QIODevice &io) const noexcept; bool exportFlightInfo(QIODevice &io) const noexcept; diff --git a/src/Plugins/Export/GpxExport/src/GpxExportSettings.cpp b/src/Plugins/Export/GpxExport/src/GpxExportSettings.cpp index a2bdb1c51..1dacf099f 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportSettings.cpp +++ b/src/Plugins/Export/GpxExport/src/GpxExportSettings.cpp @@ -26,6 +26,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -41,9 +44,8 @@ namespace constexpr GpxExportSettings::TimestampMode DefaultTimestampMode {GpxExportSettings::TimestampMode::Simulation}; } -class GpxExportSettingsPrivate +struct GpxExportSettingsPrivate { -public: GpxExportSettingsPrivate() : timestampMode(::DefaultTimestampMode) {} @@ -58,14 +60,14 @@ GpxExportSettings::GpxExportSettings() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("GpxExportSettings::GpxExportSettings: CREATED"); + qDebug() << "GpxExportSettings::GpxExportSettings: CREATED"; #endif } GpxExportSettings::~GpxExportSettings() noexcept { #ifdef DEBUG - qDebug("GpxExportSettings::~GpxExportSettings: DELETED"); + qDebug() << "GpxExportSettings::~GpxExportSettings: DELETED"; #endif } @@ -104,7 +106,7 @@ void GpxExportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void GpxExportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::TimestampModeKey).toInt(&ok); if (ok) { d->timestampMode = static_cast(enumeration); diff --git a/src/Plugins/Export/GpxExport/src/GpxExportSettings.h b/src/Plugins/Export/GpxExport/src/GpxExportSettings.h index 63c7258f9..044694f81 100644 --- a/src/Plugins/Export/GpxExport/src/GpxExportSettings.h +++ b/src/Plugins/Export/GpxExport/src/GpxExportSettings.h @@ -32,7 +32,7 @@ #include #include -class GpxExportSettingsPrivate; +struct GpxExportSettingsPrivate; class GpxExportSettings : public ExportPluginBaseSettings { @@ -44,7 +44,7 @@ class GpxExportSettings : public ExportPluginBaseSettings }; GpxExportSettings() noexcept; - virtual ~GpxExportSettings() noexcept; + ~GpxExportSettings() noexcept override; TimestampMode getTimestampMode() const noexcept; void setTimestampMode(TimestampMode timestampMode) noexcept; @@ -56,13 +56,13 @@ class GpxExportSettings : public ExportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // GPXEXPORTSETTINGS_H diff --git a/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.cpp b/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.cpp index 18f0fcc4b..114860d40 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.cpp +++ b/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.cpp @@ -24,14 +24,16 @@ */ #include #include +#ifdef DEBUG +#include +#endif #include "IgcExportOptionWidget.h" #include "IgcExportSettings.h" #include "ui_IgcExportOptionWidget.h" -class IgcExportOptionWidgetPrivate +struct IgcExportOptionWidgetPrivate { -public: IgcExportOptionWidgetPrivate(IgcExportSettings &theSettings) noexcept : settings(theSettings) {} @@ -51,14 +53,14 @@ IgcExportOptionWidget::IgcExportOptionWidget(IgcExportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("IgcExportOptionWidget::IgcExportOptionWidget: CREATED"); + qDebug() << "IgcExportOptionWidget::IgcExportOptionWidget: CREATED"; #endif } IgcExportOptionWidget::~IgcExportOptionWidget() noexcept { #ifdef DEBUG - qDebug("IgcExportOptionWidget::~IgcExportOptionWidget: DELETED"); + qDebug() << "IgcExportOptionWidget::~IgcExportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.h b/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.h index f5e3ca00c..321dfe39b 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.h +++ b/src/Plugins/Export/IgcExport/src/IgcExportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class IgcExportSettings; -class IgcExportOptionWidgetPrivate; +struct IgcExportOptionWidgetPrivate; class IgcExportOptionWidget : public QWidget { Q_OBJECT public: explicit IgcExportOptionWidget(IgcExportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~IgcExportOptionWidget() noexcept; + ~IgcExportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Export/IgcExport/src/IgcExportPlugin.cpp b/src/Plugins/Export/IgcExport/src/IgcExportPlugin.cpp index 95a63c54c..b09ea779d 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportPlugin.cpp +++ b/src/Plugins/Export/IgcExport/src/IgcExportPlugin.cpp @@ -108,9 +108,8 @@ namespace constexpr int KRecordIntervalSec {20}; } -class IgcExportPluginPrivate +struct IgcExportPluginPrivate { -public: IgcExportPluginPrivate() noexcept : flight(nullptr) {} @@ -138,14 +137,14 @@ IgcExportPlugin::IgcExportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("IgcExportPlugin::IgcExportPlugin: PLUGIN LOADED"); + qDebug() << "IgcExportPlugin::IgcExportPlugin: PLUGIN LOADED"; #endif } IgcExportPlugin::~IgcExportPlugin() noexcept { #ifdef DEBUG - qDebug("IgcExportPlugin::~IgcExportPlugin: PLUGIN UNLOADED"); + qDebug() << "IgcExportPlugin::~IgcExportPlugin: PLUGIN UNLOADED"; #endif } @@ -295,10 +294,9 @@ inline bool IgcExportPlugin::exportFixes(const Aircraft &aircraft, QIODevice &io Convert convert; Engine &engine = aircraft.getEngine(); - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - bool ok = true; - for (PositionData &positionData : interpolatedPositionData) { + const std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + bool ok {true}; + for (const PositionData &positionData : interpolatedPositionData) { if (!positionData.isNull()) { // Convert height above EGM geoid to height above WGS84 ellipsoid (HAE) [meters] diff --git a/src/Plugins/Export/IgcExport/src/IgcExportPlugin.h b/src/Plugins/Export/IgcExport/src/IgcExportPlugin.h index 32beeddc0..1372b41ee 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportPlugin.h +++ b/src/Plugins/Export/IgcExport/src/IgcExportPlugin.h @@ -44,7 +44,7 @@ class Flight; class Aircraft; struct EngineData; struct Waypoint; -class IgcExportPluginPrivate; +struct IgcExportPluginPrivate; class IgcExportPlugin : public ExportPluginBase { @@ -53,19 +53,19 @@ class IgcExportPlugin : public ExportPluginBase Q_INTERFACES(ExportIntf) public: IgcExportPlugin() noexcept; - virtual ~IgcExportPlugin() noexcept; + ~IgcExportPlugin() noexcept override; protected: - virtual ExportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool hasMultiAircraftSupport() const noexcept override; - virtual bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; - virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; + ExportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool hasMultiAircraftSupport() const noexcept override; + bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; + bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; inline bool exportARecord(QIODevice &io) const noexcept; inline bool exportHRecord(const Aircraft &aircraft, QIODevice &io) const noexcept; diff --git a/src/Plugins/Export/IgcExport/src/IgcExportSettings.cpp b/src/Plugins/Export/IgcExport/src/IgcExportSettings.cpp index 1217818ba..a730bc881 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportSettings.cpp +++ b/src/Plugins/Export/IgcExport/src/IgcExportSettings.cpp @@ -26,6 +26,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -39,9 +42,8 @@ namespace constexpr char CoPilotNameKey[] {"CoPilotName"}; } -class IgcExportSettingsPrivate +struct IgcExportSettingsPrivate { -public: IgcExportSettingsPrivate() : pilotName(DefaultPilotName), coPilotName(DefaultCoPilotName) @@ -61,14 +63,14 @@ IgcExportSettings::IgcExportSettings() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("IgcExportSettings::IgcExportSettings: CREATED"); + qDebug() << "IgcExportSettings::IgcExportSettings: CREATED"; #endif } IgcExportSettings::~IgcExportSettings() noexcept { #ifdef DEBUG - qDebug("IgcExportSettings::~IgcExportSettings: DELETED"); + qDebug() << "IgcExportSettings::~IgcExportSettings: DELETED"; #endif } diff --git a/src/Plugins/Export/IgcExport/src/IgcExportSettings.h b/src/Plugins/Export/IgcExport/src/IgcExportSettings.h index a1be9587e..d6a262b71 100644 --- a/src/Plugins/Export/IgcExport/src/IgcExportSettings.h +++ b/src/Plugins/Export/IgcExport/src/IgcExportSettings.h @@ -33,14 +33,14 @@ #include #include -class IgcExportSettingsPrivate; +struct IgcExportSettingsPrivate; class IgcExportSettings : public ExportPluginBaseSettings { Q_OBJECT public: IgcExportSettings() noexcept; - virtual ~IgcExportSettings() noexcept; + ~IgcExportSettings() noexcept override; QString getPilotName() const noexcept; void setPilotName(const QString &pilotName) noexcept; @@ -58,13 +58,13 @@ class IgcExportSettings : public ExportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // IGCEXPORTSETTINGS_H diff --git a/src/Plugins/Export/JsonExport/src/JsonExportPlugin.cpp b/src/Plugins/Export/JsonExport/src/JsonExportPlugin.cpp index 2742a867e..6b79b7693 100644 --- a/src/Plugins/Export/JsonExport/src/JsonExportPlugin.cpp +++ b/src/Plugins/Export/JsonExport/src/JsonExportPlugin.cpp @@ -55,9 +55,8 @@ #include "JsonExportSettings.h" #include "JsonExportPlugin.h" -class JsonExportPluginPrivate +struct JsonExportPluginPrivate { -public: JsonExportPluginPrivate() noexcept : flight(nullptr) {} @@ -75,14 +74,14 @@ JsonExportPlugin::JsonExportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("JsonExportPlugin::JsonExportPlugin: PLUGIN LOADED"); + qDebug() << "JsonExportPlugin::JsonExportPlugin: PLUGIN LOADED"; #endif } JsonExportPlugin::~JsonExportPlugin() noexcept { #ifdef DEBUG - qDebug("JsonExportPlugin::~JsonExportPlugin: PLUGIN UNLOADED"); + qDebug() << "JsonExportPlugin::~JsonExportPlugin: PLUGIN UNLOADED"; #endif } @@ -169,10 +168,10 @@ bool JsonExportPlugin::exportHeader(QIODevice &io) const noexcept bool JsonExportPlugin::exportAllAircraft(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; std::size_t i = 0; for (const auto &aircraft : *d->flight) { - ok = exportAircraft(*aircraft, io); + ok = exportAircraft(aircraft, io); if (ok) { if (i < d->flight->count() - 1) { ok = io.write(",\n"); @@ -189,9 +188,8 @@ bool JsonExportPlugin::exportAllAircraft(QIODevice &io) const noexcept bool JsonExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) const noexcept { - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - bool ok = true; + const std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + bool ok {true}; const AircraftInfo &info = aircraft.getAircraftInfo(); const AircraftType &type = info.aircraftType; @@ -204,7 +202,7 @@ bool JsonExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) c ok = io.write(trackBegin.toUtf8()); if (ok) { std::size_t i = 0; - for (PositionData &positionData : interpolatedPositionData) { + for (const PositionData &positionData : interpolatedPositionData) { ok = exportTrackPoint(positionData, io); if (ok) { if (i < interpolatedPositionData.size() - 1) { @@ -246,7 +244,7 @@ bool JsonExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) c bool JsonExportPlugin::exportWaypoints(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; const FlightPlan &flightPlan = d->flight->getUserAircraft().getFlightPlan(); for (const Waypoint &waypoint : flightPlan) { ok = exportWaypoint(waypoint, io); diff --git a/src/Plugins/Export/JsonExport/src/JsonExportPlugin.h b/src/Plugins/Export/JsonExport/src/JsonExportPlugin.h index 19bd569ca..ec905b2a3 100644 --- a/src/Plugins/Export/JsonExport/src/JsonExportPlugin.h +++ b/src/Plugins/Export/JsonExport/src/JsonExportPlugin.h @@ -42,7 +42,7 @@ class Flight; class Aircraft; struct PositionData; struct Waypoint; -class JsonExportPluginPrivate; +struct JsonExportPluginPrivate; class JsonExportPlugin : public ExportPluginBase { @@ -51,19 +51,19 @@ class JsonExportPlugin : public ExportPluginBase Q_INTERFACES(ExportIntf) public: JsonExportPlugin() noexcept; - virtual ~JsonExportPlugin() noexcept; + ~JsonExportPlugin() noexcept override; protected: - virtual ExportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool hasMultiAircraftSupport() const noexcept override; - virtual bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; - virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; + ExportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool hasMultiAircraftSupport() const noexcept override; + bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; + bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; bool exportHeader(QIODevice &io) const noexcept; bool exportAllAircraft(QIODevice &io) const noexcept; diff --git a/src/Plugins/Export/JsonExport/src/JsonExportSettings.cpp b/src/Plugins/Export/JsonExport/src/JsonExportSettings.cpp index 03986cebc..531c647e9 100644 --- a/src/Plugins/Export/JsonExport/src/JsonExportSettings.cpp +++ b/src/Plugins/Export/JsonExport/src/JsonExportSettings.cpp @@ -26,18 +26,19 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include #include #include "JsonExportSettings.h" -class JsonExportSettingsPrivate +struct JsonExportSettingsPrivate { -public: JsonExportSettingsPrivate() {} - }; // PUBLIC @@ -47,14 +48,14 @@ JsonExportSettings::JsonExportSettings() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("JsonExportSettings::JsonExportSettings: CREATED"); + qDebug() << "JsonExportSettings::JsonExportSettings: CREATED"; #endif } JsonExportSettings::~JsonExportSettings() noexcept { #ifdef DEBUG - qDebug("JsonExportSettings::~JsonExportSettings: DELETED"); + qDebug() << "JsonExportSettings::~JsonExportSettings: DELETED"; #endif } diff --git a/src/Plugins/Export/JsonExport/src/JsonExportSettings.h b/src/Plugins/Export/JsonExport/src/JsonExportSettings.h index 4acb5e1a1..1399dcb67 100644 --- a/src/Plugins/Export/JsonExport/src/JsonExportSettings.h +++ b/src/Plugins/Export/JsonExport/src/JsonExportSettings.h @@ -32,14 +32,14 @@ #include #include -class JsonExportSettingsPrivate; +struct JsonExportSettingsPrivate; class JsonExportSettings : public ExportPluginBaseSettings { Q_OBJECT public: JsonExportSettings() noexcept; - virtual ~JsonExportSettings() noexcept; + ~JsonExportSettings() noexcept override; signals: /*! @@ -48,13 +48,13 @@ class JsonExportSettings : public ExportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // JSONEXPORTSETTINGS_H diff --git a/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.cpp b/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.cpp index b9dcfa437..ed02a543f 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.cpp +++ b/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.cpp @@ -27,6 +27,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include "KmlExportOptionWidget.h" @@ -46,15 +49,14 @@ namespace AllEndColor }; - constexpr char DisabledColor[] = "#aaa"; + constexpr const char *DisabledColor {"#aaa"}; } -class KmlExportOptionWidgetPrivate +struct KmlExportOptionWidgetPrivate { -public: KmlExportOptionWidgetPrivate(KmlExportSettings &theSettings) noexcept - : settings(theSettings), - colorButtonGroup(std::make_unique()) + : colorButtonGroup(std::make_unique()), + settings(theSettings) {} std::unique_ptr colorButtonGroup; @@ -73,14 +75,14 @@ KmlExportOptionWidget::KmlExportOptionWidget(KmlExportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("KmlExportOptionWidget::KmlExportOptionWidget: CREATED"); + qDebug() << "KmlExportOptionWidget::KmlExportOptionWidget: CREATED"; #endif } KmlExportOptionWidget::~KmlExportOptionWidget() noexcept { #ifdef DEBUG - qDebug("KmlExportOptionWidget::~KmlExportOptionWidget: DELETED"); + qDebug() << "KmlExportOptionWidget::~KmlExportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.h b/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.h index e1572e8c0..8944108bf 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.h +++ b/src/Plugins/Export/KmlExport/src/KmlExportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class KmlExportSettings; -class KmlExportOptionWidgetPrivate; +struct KmlExportOptionWidgetPrivate; class KmlExportOptionWidget : public QWidget { Q_OBJECT public: explicit KmlExportOptionWidget(KmlExportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~KmlExportOptionWidget() noexcept; + ~KmlExportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Export/KmlExport/src/KmlExportPlugin.cpp b/src/Plugins/Export/KmlExport/src/KmlExportPlugin.cpp index 3e321ff8a..5ac9bddcd 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportPlugin.cpp +++ b/src/Plugins/Export/KmlExport/src/KmlExportPlugin.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -59,14 +58,13 @@ namespace constexpr int MaxLineSegments = 16384; // Placemark "look at" direction - constexpr char LookAtTilt[] = "50"; - constexpr char LookAtRange[] = "4000"; + constexpr const char *LookAtTilt {"50"}; + constexpr const char *LookAtRange {"4000"}; constexpr int HeadingNorth = 0; } -class KmlExportPluginPrivate +struct KmlExportPluginPrivate { -public: KmlExportPluginPrivate() noexcept : flight(nullptr), styleExport(std::make_unique(pluginSettings)) @@ -87,14 +85,14 @@ KmlExportPlugin::KmlExportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("KmlExportPlugin::KmlExportPlugin: PLUGIN LOADED"); + qDebug() << "KmlExportPlugin::KmlExportPlugin: PLUGIN LOADED"; #endif } KmlExportPlugin::~KmlExportPlugin() noexcept { #ifdef DEBUG - qDebug("KmlExportPlugin::~KmlExportPlugin: PLUGIN UNLOADED"); + qDebug() << "KmlExportPlugin::~KmlExportPlugin: PLUGIN UNLOADED"; #endif } @@ -213,10 +211,10 @@ bool KmlExportPlugin::exportFlightInfo(QIODevice &io) const noexcept bool KmlExportPlugin::exportAllAircraft(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; for (const auto &aircraft : *d->flight) { - d->aircraftTypeCount[aircraft->getAircraftInfo().aircraftType.type] += 1; - ok = exportAircraft(*aircraft, io); + d->aircraftTypeCount[aircraft.getAircraftInfo().aircraftType.type] += 1; + ok = exportAircraft(aircraft, io); if (!ok) { break; } @@ -237,9 +235,8 @@ bool KmlExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) co " \n" " \n"); - std::vector interpolatedPositionData; - Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod(), std::back_inserter(interpolatedPositionData)); - bool ok = true; + std::vector interpolatedPositionData = Export::resamplePositionDataForExport(aircraft, d->pluginSettings.getResamplingPeriod()); + bool ok {true}; if (interpolatedPositionData.size() > 0) { const int aircraftTypeCount = d->aircraftTypeCount[aircraft.getAircraftInfo().aircraftType.type]; @@ -310,7 +307,7 @@ bool KmlExportPlugin::exportAircraft(const Aircraft &aircraft, QIODevice &io) co bool KmlExportPlugin::exportWaypoints(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; const FlightPlan &flightPlan = d->flight->getUserAircraft().getFlightPlan(); for (const Waypoint &waypoint : flightPlan) { diff --git a/src/Plugins/Export/KmlExport/src/KmlExportPlugin.h b/src/Plugins/Export/KmlExport/src/KmlExportPlugin.h index 4229d42b0..f4b5531cf 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportPlugin.h +++ b/src/Plugins/Export/KmlExport/src/KmlExportPlugin.h @@ -43,7 +43,7 @@ class Flight; class Aircraft; struct PositionData; struct Waypoint; -class KmlExportPluginPrivate; +struct KmlExportPluginPrivate; class KmlExportPlugin : public ExportPluginBase { @@ -52,19 +52,19 @@ class KmlExportPlugin : public ExportPluginBase Q_INTERFACES(ExportIntf) public: KmlExportPlugin() noexcept; - virtual ~KmlExportPlugin() noexcept; + ~KmlExportPlugin() noexcept override; protected: - virtual ExportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool hasMultiAircraftSupport() const noexcept override; - virtual bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; - virtual bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; + ExportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool hasMultiAircraftSupport() const noexcept override; + bool exportFlight(const Flight &flight, QIODevice &io) noexcept override; + bool exportAircraft(const Flight &flight, const Aircraft &aircraft, QIODevice &io) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; bool exportHeader(QIODevice &io) const noexcept; bool exportFlightInfo(QIODevice &io) const noexcept; diff --git a/src/Plugins/Export/KmlExport/src/KmlExportSettings.cpp b/src/Plugins/Export/KmlExport/src/KmlExportSettings.cpp index 9b4ee70fa..9b7f1fbd3 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportSettings.cpp +++ b/src/Plugins/Export/KmlExport/src/KmlExportSettings.cpp @@ -26,6 +26,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -71,9 +74,8 @@ namespace } -class KmlExportSettingsPrivate +struct KmlExportSettingsPrivate { -public: KmlExportSettingsPrivate() : colorStyle(::DefaultColorStyle), nofColorsPerRamp(::DefaultNofColorsPerRamp), @@ -108,14 +110,14 @@ KmlExportSettings::KmlExportSettings() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("KmlExportSettings::KmlExportSettings: CREATED"); + qDebug() << "KmlExportSettings::KmlExportSettings: CREATED"; #endif } KmlExportSettings::~KmlExportSettings() noexcept { #ifdef DEBUG - qDebug("KmlExportSettings::~KmlExportSettings: DELETED"); + qDebug() << "KmlExportSettings::~KmlExportSettings: DELETED"; #endif } @@ -369,7 +371,7 @@ void KmlExportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void KmlExportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::ColorStyleKey).toInt(&ok); if (ok) { d->colorStyle = static_cast(enumeration); diff --git a/src/Plugins/Export/KmlExport/src/KmlExportSettings.h b/src/Plugins/Export/KmlExport/src/KmlExportSettings.h index 8bd772267..2a3ebba6b 100644 --- a/src/Plugins/Export/KmlExport/src/KmlExportSettings.h +++ b/src/Plugins/Export/KmlExport/src/KmlExportSettings.h @@ -33,7 +33,7 @@ #include #include -class KmlExportSettingsPrivate; +struct KmlExportSettingsPrivate; class KmlExportSettings : public ExportPluginBaseSettings { @@ -47,7 +47,7 @@ class KmlExportSettings : public ExportPluginBaseSettings }; KmlExportSettings() noexcept; - virtual ~KmlExportSettings() noexcept; + ~KmlExportSettings() noexcept override; ColorStyle getColorStyle() const noexcept; void setColorStyle(ColorStyle colorStyle) noexcept; @@ -85,13 +85,13 @@ class KmlExportSettings : public ExportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // KMLEXPORTSETTINGS_H diff --git a/src/Plugins/Export/KmlExport/src/KmlStyleExport.cpp b/src/Plugins/Export/KmlExport/src/KmlStyleExport.cpp index a09b8021f..0d915d1f2 100644 --- a/src/Plugins/Export/KmlExport/src/KmlStyleExport.cpp +++ b/src/Plugins/Export/KmlExport/src/KmlStyleExport.cpp @@ -41,20 +41,19 @@ namespace constexpr QRgb PolygonHighlightColor = 0xcc7ed5c9; constexpr QRgb PolygonColor = 0x337ed5c9; - constexpr char JetStyleId[] = "s_jet_style"; - constexpr char TurbopropStyleId[] = "s_turbo_prop_style"; - constexpr char PistonStyleId[] = "s_piston_style"; - constexpr char AllStyleId[] = "s_all_style"; - - constexpr char JetStyleMapId[] = "sm_jet_style"; - constexpr char TurbopropStyleMapId[] = "sm_turbo_prop_style"; - constexpr char PistonStyleMapId[] = "sm_piston_style"; - constexpr char AllStyleMapId[] = "sm_all_style"; + constexpr const char *JetStyleId {"s_jet_style"}; + constexpr const char *TurbopropStyleId {"s_turbo_prop_style"}; + constexpr const char *PistonStyleId {"s_piston_style"}; + constexpr const char *AllStyleId {"s_all_style"}; + + constexpr const char *JetStyleMapId {"sm_jet_style"}; + constexpr const char *TurbopropStyleMapId {"sm_turbo_prop_style"}; + constexpr const char *PistonStyleMapId {"sm_piston_style"}; + constexpr const char *AllStyleMapId {"sm_all_style"}; } -class KmlStyleExportPrivate +struct KmlStyleExportPrivate { -public: KmlStyleExportPrivate(const KmlExportSettings &theExportSettings) noexcept : settings(theExportSettings), jetColorRampIndex(0), @@ -222,7 +221,7 @@ bool KmlStyleExport::exportHighlightLineStyle(QIODevice &io) const noexcept bool KmlStyleExport::exportNormalLineStyles(QIODevice &io) const noexcept { const float lineWidth = d->settings.getLineWidth(); - bool ok = true; + bool ok {true}; if (d->settings.getColorStyle() == KmlExportSettings::ColorStyle::OneColorPerEngineType || d->settings.getColorStyle() == KmlExportSettings::ColorStyle::ColorRampPerEngineType) { // Per engine type (one color or ramp) ok = exportNormalLineStylesPerEngineType(SimType::EngineType::Jet, d->jetColorRamp, lineWidth, io); @@ -241,7 +240,7 @@ bool KmlStyleExport::exportNormalLineStyles(QIODevice &io) const noexcept bool KmlStyleExport::exportLineStyleMaps(QIODevice &io) const noexcept { - bool ok = true; + bool ok {true}; // Jet style map if (d->settings.getColorStyle() == KmlExportSettings::ColorStyle::OneColorPerEngineType || d->settings.getColorStyle() == KmlExportSettings::ColorStyle::ColorRampPerEngineType) { @@ -397,7 +396,7 @@ bool KmlStyleExport::exportNormalLineStylesPerEngineType(SimType::EngineType eng break; } - bool ok = true; + bool ok {true}; int index = 0; const QRgb polygonColorKml = Color::convertRgbToKml(PolygonColor); diff --git a/src/Plugins/Export/KmlExport/src/KmlStyleExport.h b/src/Plugins/Export/KmlExport/src/KmlStyleExport.h index c85426b1e..b5da5cb50 100644 --- a/src/Plugins/Export/KmlExport/src/KmlStyleExport.h +++ b/src/Plugins/Export/KmlExport/src/KmlStyleExport.h @@ -34,7 +34,7 @@ class QIODevice; #include #include "KmlExportSettings.h" -class KmlStyleExportPrivate; +struct KmlStyleExportPrivate; class KmlStyleExport { @@ -53,7 +53,7 @@ class KmlStyleExport static QString getStyleUrl(Icon icon) noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; void initialiseColorRamps() noexcept; bool exportHighlightLineStyle(QIODevice &io) const noexcept; diff --git a/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.cpp b/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.cpp index 4dc7eda7c..3422ed96f 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.cpp +++ b/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.cpp @@ -23,6 +23,9 @@ * DEALINGS IN THE SOFTWARE. */ #include +#ifdef DEBUG +#include +#endif #include #include @@ -30,9 +33,8 @@ #include "CsvImportSettings.h" #include "ui_CsvImportOptionWidget.h" -class CsvImportOptionWidgetPrivate +struct CsvImportOptionWidgetPrivate { -public: CsvImportOptionWidgetPrivate(CsvImportSettings &theImportSettings) noexcept : settings(theImportSettings) {} @@ -52,14 +54,14 @@ CsvImportOptionWidget::CsvImportOptionWidget(CsvImportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("CsvImportOptionWidget::CsvImportOptionWidget: CREATED"); + qDebug() << "CsvImportOptionWidget::CsvImportOptionWidget: CREATED"; #endif } CsvImportOptionWidget::~CsvImportOptionWidget() noexcept { #ifdef DEBUG - qDebug("CsvImportOptionWidget::~CsvImportOptionWidget: DELETED"); + qDebug() << "CsvImportOptionWidget::~CsvImportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.h b/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.h index c95dc9f09..0805fca3d 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.h +++ b/src/Plugins/Import/CsvImport/src/CsvImportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class CsvImportSettings; -class CsvImportOptionWidgetPrivate; +struct CsvImportOptionWidgetPrivate; class CsvImportOptionWidget : public QWidget { Q_OBJECT public: explicit CsvImportOptionWidget(CsvImportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~CsvImportOptionWidget() noexcept; + ~CsvImportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Import/CsvImport/src/CsvImportPlugin.cpp b/src/Plugins/Import/CsvImport/src/CsvImportPlugin.cpp index e1027155c..8d11abe16 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportPlugin.cpp +++ b/src/Plugins/Import/CsvImport/src/CsvImportPlugin.cpp @@ -40,9 +40,8 @@ #include "CsvImportOptionWidget.h" #include "CsvImportPlugin.h" -class CsvImportPluginPrivate +struct CsvImportPluginPrivate { -public: CsvImportPluginPrivate() {} @@ -59,14 +58,14 @@ CsvImportPlugin::CsvImportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("CsvImportPlugin::CsvImportPlugin: PLUGIN LOADED"); + qDebug() << "CsvImportPlugin::CsvImportPlugin: PLUGIN LOADED"; #endif } CsvImportPlugin::~CsvImportPlugin() noexcept { #ifdef DEBUG - qDebug("CsvImportPlugin::~CsvImportPlugin: PLUGIN UNLOADED"); + qDebug() << "CsvImportPlugin::~CsvImportPlugin: PLUGIN UNLOADED"; #endif } @@ -94,8 +93,6 @@ std::unique_ptr CsvImportPlugin::createOptionWidget() const noexcept bool CsvImportPlugin::importFlight(QFile &file, Flight &flight) noexcept { - bool ok; - std::unique_ptr parser; switch (d->pluginSettings.getFormat()) { case CsvImportSettings::Format::SkyDolly: @@ -108,10 +105,9 @@ bool CsvImportPlugin::importFlight(QFile &file, Flight &flight) noexcept parser = std::make_unique(); break; } + bool ok {false}; if (parser != nullptr) { ok = parser->parse(file, d->firstDateTimeUtc, d->flightNumber, flight); - } else { - ok = false; } return ok; } diff --git a/src/Plugins/Import/CsvImport/src/CsvImportPlugin.h b/src/Plugins/Import/CsvImport/src/CsvImportPlugin.h index f9af3c798..0190936cb 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportPlugin.h +++ b/src/Plugins/Import/CsvImport/src/CsvImportPlugin.h @@ -42,7 +42,7 @@ class Flight; struct AircraftInfo; struct FlightCondition; class ImportPluginBaseSettings; -class CsvImportPluginPrivate; +struct CsvImportPluginPrivate; class CsvImportPlugin : public ImportPluginBase { @@ -69,7 +69,7 @@ class CsvImportPlugin : public ImportPluginBase void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // CSVIMPORTPLUGIN_H diff --git a/src/Plugins/Import/CsvImport/src/CsvImportSettings.cpp b/src/Plugins/Import/CsvImport/src/CsvImportSettings.cpp index 0636fe13d..3cda8a513 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportSettings.cpp +++ b/src/Plugins/Import/CsvImport/src/CsvImportSettings.cpp @@ -22,6 +22,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#ifdef DEBUG +#include +#endif #include #include @@ -37,9 +40,8 @@ namespace constexpr CsvImportSettings::Format DefaultFormat {CsvImportSettings::Format::SkyDolly}; } -class CsvImportSettingsPrivate +struct CsvImportSettingsPrivate { -public: CsvImportSettingsPrivate() : format(::DefaultFormat) {} @@ -53,14 +55,14 @@ CsvImportSettings::CsvImportSettings() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("CsvImportSettings::CsvImportSettings: CREATED"); + qDebug() << "CsvImportSettings::CsvImportSettings: CREATED"; #endif } CsvImportSettings::~CsvImportSettings() noexcept { #ifdef DEBUG - qDebug("CsvImportSettings::~CsvImportSettings: DELETED"); + qDebug() << "CsvImportSettings::~CsvImportSettings: DELETED"; #endif } @@ -99,7 +101,7 @@ void CsvImportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void CsvImportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::FormatKey).toInt(&ok); if (ok) { d->format = static_cast(enumeration); diff --git a/src/Plugins/Import/CsvImport/src/CsvImportSettings.h b/src/Plugins/Import/CsvImport/src/CsvImportSettings.h index 06a5a182b..914c059a7 100644 --- a/src/Plugins/Import/CsvImport/src/CsvImportSettings.h +++ b/src/Plugins/Import/CsvImport/src/CsvImportSettings.h @@ -33,7 +33,7 @@ #include #include -class CsvImportSettingsPrivate; +struct CsvImportSettingsPrivate; class CsvImportSettings : public ImportPluginBaseSettings { @@ -49,7 +49,7 @@ class CsvImportSettings : public ImportPluginBaseSettings }; CsvImportSettings() noexcept; - virtual ~CsvImportSettings() noexcept; + ~CsvImportSettings() noexcept override; Format getFormat() const noexcept; void setFormat(Format format) noexcept; @@ -61,13 +61,13 @@ class CsvImportSettings : public ImportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // CSVIMPORTSETTINGS_H diff --git a/src/Plugins/Import/CsvImport/src/FlightRadar24CsvParser.cpp b/src/Plugins/Import/CsvImport/src/FlightRadar24CsvParser.cpp index 0f10dd1d0..e80770ef3 100644 --- a/src/Plugins/Import/CsvImport/src/FlightRadar24CsvParser.cpp +++ b/src/Plugins/Import/CsvImport/src/FlightRadar24CsvParser.cpp @@ -42,7 +42,7 @@ namespace { - constexpr char FlightRadar24CSVPattern[] = R"(^(\d*),(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z),([\w]*|[\d]*),\"([-]?\d{1,2}.\d+),([-]?\d{1,3}.\d+)\",(\d+),(\d+),(\d+))"; + constexpr const char *FlightRadar24CSVPattern {R"(^(\d*),(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z),([\w]*|[\d]*),\"([-]?\d{1,2}.\d+),([-]?\d{1,3}.\d+)\",(\d+),(\d+),(\d+))"}; constexpr int UnixTimestampIndex = 1; constexpr int CallsignIndex = 2; constexpr int LatitudeIndex = 3; @@ -57,26 +57,25 @@ namespace FlightRadar24CsvParser::FlightRadar24CsvParser() noexcept { #ifdef DEBUG - qDebug("FlightRadar24CsvParser::~FlightRadar24CsvParser: CREATED"); + qDebug() << "FlightRadar24CsvParser::~FlightRadar24CsvParser: CREATED"; #endif } FlightRadar24CsvParser::~FlightRadar24CsvParser() noexcept { #ifdef DEBUG - qDebug("FlightRadar24CsvParser::~FlightRadar24CsvParser: DELETED"); + qDebug() << "FlightRadar24CsvParser::~FlightRadar24CsvParser: DELETED"; #endif } bool FlightRadar24CsvParser::parse(QFile &file, QDateTime &firstDateTimeUtc, QString &flightNumber, Flight &flight) noexcept { - bool ok; Aircraft &aircraft = flight.getUserAircraft(); static const QRegularExpression regexp(::FlightRadar24CSVPattern); // Headers const QByteArray header = file.readLine(); - ok = !header.isNull(); + bool ok = !header.isNull(); firstDateTimeUtc.setTimeZone(QTimeZone::utc()); QDateTime currentDateTimeUtc; diff --git a/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.cpp b/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.cpp index be7050910..d6cb98ebd 100644 --- a/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.cpp +++ b/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.cpp @@ -62,62 +62,61 @@ namespace // Column names // Position - constexpr char Milliseconds[] = "Milliseconds"; - constexpr char Latitude[] = "Latitude"; - constexpr char Longitude[] = "Longitude"; - constexpr char Altitude[] = "Altitude"; - constexpr char Pitch[] = "Pitch"; - constexpr char Bank[] = "Bank"; - constexpr char TrueHeading[] = "TrueHeading"; - constexpr char VelocityBodyX[] = "VelocityBodyX"; - constexpr char VelocityBodyY[] = "VelocityBodyY"; - constexpr char VelocityBodyZ[] = "VelocityBodyZ"; - constexpr char RotationVelocityBodyX[] = "RotationVelocityBodyX"; - constexpr char RotationVelocityBodyY[] = "RotationVelocityBodyY"; - constexpr char RotationVelocityBodyZ[] = "RotationVelocityBodyZ"; + constexpr const char *Milliseconds {"Milliseconds"}; + constexpr const char *Latitude {"Latitude"}; + constexpr const char *Longitude {"Longitude"}; + constexpr const char *Altitude {"Altitude"}; + constexpr const char *Pitch {"Pitch"}; + constexpr const char *Bank {"Bank"}; + constexpr const char *TrueHeading {"TrueHeading"}; + constexpr const char *VelocityBodyX {"VelocityBodyX"}; + constexpr const char *VelocityBodyY {"VelocityBodyY"}; + constexpr const char *VelocityBodyZ {"VelocityBodyZ"}; + constexpr const char *RotationVelocityBodyX {"RotationVelocityBodyX"}; + constexpr const char *RotationVelocityBodyY {"RotationVelocityBodyY"}; + constexpr const char *RotationVelocityBodyZ {"RotationVelocityBodyZ"}; // Engine - constexpr char ThrottleLeverPosition1[] = "ThrottleLeverPosition1"; - constexpr char ThrottleLeverPosition2[] = "ThrottleLeverPosition2"; - constexpr char ThrottleLeverPosition3[] = "ThrottleLeverPosition3"; - constexpr char ThrottleLeverPosition4[] = "ThrottleLeverPosition4"; + constexpr const char *ThrottleLeverPosition1 {"ThrottleLeverPosition1"}; + constexpr const char *ThrottleLeverPosition2 {"ThrottleLeverPosition2"}; + constexpr const char *ThrottleLeverPosition3 {"ThrottleLeverPosition3"}; + constexpr const char *ThrottleLeverPosition4 {"ThrottleLeverPosition4"}; // Primary flight controls - constexpr char RudderPosition[] = "RudderPosition"; - constexpr char ElevatorPosition[] = "ElevatorPosition"; - constexpr char AileronPosition[] = "AileronPosition"; + constexpr const char *RudderPosition {"RudderPosition"}; + constexpr const char *ElevatorPosition {"ElevatorPosition"}; + constexpr const char *AileronPosition {"AileronPosition"}; // Secondary flight controls - constexpr char LeadingEdgeFlapsLeftPercent[] = "LeadingEdgeFlapsLeftPercent"; - constexpr char LeadingEdgeFlapsRightPercent[] = "LeadingEdgeFlapsRightPercent"; - constexpr char TrailingEdgeFlapsLeftPercent[] = "TrailingEdgeFlapsLeftPercent"; - constexpr char TrailingEdgeFlapsRightPercent[] = "TrailingEdgeFlapsRightPercent"; - constexpr char SpoilerHandlePosition[] = "SpoilerHandlePosition"; - constexpr char FlapsHandleIndex[] = "FlapsHandleIndex"; + constexpr const char *LeadingEdgeFlapsLeftPercent {"LeadingEdgeFlapsLeftPercent"}; + constexpr const char *LeadingEdgeFlapsRightPercent {"LeadingEdgeFlapsRightPercent"}; + constexpr const char *TrailingEdgeFlapsLeftPercent {"TrailingEdgeFlapsLeftPercent"}; + constexpr const char *TrailingEdgeFlapsRightPercent {"TrailingEdgeFlapsRightPercent"}; + constexpr const char *SpoilerHandlePosition {"SpoilerHandlePosition"}; + constexpr const char *FlapsHandleIndex {"FlapsHandleIndex"}; // Aircraft handles - constexpr char BrakeLeftPosition[] = "BrakeLeftPosition"; - constexpr char BrakeRightPosition[] = "BrakeRightPosition"; - constexpr char WaterRudderHandlePosition[] = "WaterRudderHandlePosition"; - constexpr char GearHandlePosition[] = "GearHandlePosition"; + constexpr const char *BrakeLeftPosition {"BrakeLeftPosition"}; + constexpr const char *BrakeRightPosition {"BrakeRightPosition"}; + constexpr const char *WaterRudderHandlePosition {"WaterRudderHandlePosition"}; + constexpr const char *GearHandlePosition {"GearHandlePosition"}; // Lights - constexpr char LightTaxi[] = "LightTaxi"; - constexpr char LightLanding[] = "LightLanding"; - constexpr char LightStrobe[] = "LightStrobe"; - constexpr char LightBeacon[] = "LightBeacon"; - constexpr char LightNav[] = "LightNav"; - constexpr char LightWing[] = "LightWing"; - constexpr char LightLogo[] = "LightLogo"; - constexpr char LightRecognition[] = "LightRecognition"; - constexpr char LightCabin[] = "LightCabin"; + constexpr const char *LightTaxi {"LightTaxi"}; + constexpr const char *LightLanding {"LightLanding"}; + constexpr const char *LightStrobe {"LightStrobe"}; + constexpr const char *LightBeacon {"LightBeacon"}; + constexpr const char *LightNav {"LightNav"}; + constexpr const char *LightWing {"LightWing"}; + constexpr const char *LightLogo {"LightLogo"}; + constexpr const char *LightRecognition {"LightRecognition"}; + constexpr const char *LightCabin {"LightCabin"}; constexpr int InvalidIdx = std::numeric_limits::max(); } -class FlightRecorderCsvParserPrivate +struct FlightRecorderCsvParserPrivate { -public: FlightRecorderCsvParserPrivate() : flight(nullptr) { @@ -134,18 +133,18 @@ FlightRecorderCsvParser::FlightRecorderCsvParser() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("FlightRecorderCsvParser::~FlightRecorderCsvParser: CREATED"); + qDebug() << "FlightRecorderCsvParser::~FlightRecorderCsvParser: CREATED"; #endif } FlightRecorderCsvParser::~FlightRecorderCsvParser() noexcept { #ifdef DEBUG - qDebug("FlightRecorderCsvParser::~FlightRecorderCsvParser: DELETED"); + qDebug() << "FlightRecorderCsvParser::~FlightRecorderCsvParser: DELETED"; #endif } -bool FlightRecorderCsvParser::parse(QFile &file, QDateTime &firstDateTimeUtc, QString &flightNumber, Flight &flight) noexcept +bool FlightRecorderCsvParser::parse(QFile &file, QDateTime &firstDateTimeUtc, [[maybe_unused]] QString &flightNumber, Flight &flight) noexcept { d->flight = &flight; firstDateTimeUtc = QFileInfo(file).birthTime().toUTC(); @@ -205,7 +204,6 @@ bool FlightRecorderCsvParser::parseData(QFile &file) noexcept lightNavIdx {InvalidIdx}, lightWingIdx {InvalidIdx}, lightLogoIdx {InvalidIdx}, lightRecognitionIdx {InvalidIdx}, lightCabinIdx {InvalidIdx}; - bool ok; Aircraft &aircraft = d->flight->getUserAircraft(); Position &position = aircraft.getPosition(); Engine &engine = aircraft.getEngine(); @@ -216,7 +214,7 @@ bool FlightRecorderCsvParser::parseData(QFile &file) noexcept QByteArray data = file.readLine(); // At least one data row expected - ok = !data.isNull(); + bool ok = !data.isNull(); bool firstRow {true}; std::int64_t timestampDelta {0}; while (ok && !data.isNull()) { @@ -387,7 +385,7 @@ bool FlightRecorderCsvParser::parseData(QFile &file) noexcept inline bool FlightRecorderCsvParser::importTimestamp(const QList &values, bool firstRow, std::int64_t ×tamp, std::int64_t ×tampDelta) noexcept { static int timestampIdx = ::InvalidIdx; - bool ok = true; + bool ok {true}; if (timestampIdx == ::InvalidIdx) { auto it = d->columnIndexes.find(::Milliseconds); if (it != d->columnIndexes.end()) { @@ -417,7 +415,7 @@ inline bool FlightRecorderCsvParser::importTimestamp(const QList &va template inline bool FlightRecorderCsvParser::importValue(const QList &values, const char *name, int &idx, T &value) noexcept { - bool ok = true; + bool ok {true}; if (idx == ::InvalidIdx) { auto it = d->columnIndexes.find(name); if (it != d->columnIndexes.end()) { diff --git a/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.h b/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.h index 644b2a7c3..3756668cd 100644 --- a/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.h +++ b/src/Plugins/Import/CsvImport/src/FlightRecorderCsvParser.h @@ -39,15 +39,15 @@ class QString; class Flight; struct EngineData; struct AircraftHandleData; -class FlightRecorderCsvParserPrivate; +struct FlightRecorderCsvParserPrivate; class FlightRecorderCsvParser : public CsvParserIntf { public: FlightRecorderCsvParser() noexcept; - virtual ~FlightRecorderCsvParser() noexcept; + ~FlightRecorderCsvParser() noexcept override; - virtual bool parse(QFile &file, QDateTime &firstDateTimeUtc, QString &flightNumber, Flight &flight) noexcept override; + bool parse(QFile &file, QDateTime &firstDateTimeUtc, QString &flightNumber, Flight &flight) noexcept override; private: std::unique_ptr d; diff --git a/src/Plugins/Import/CsvImport/src/SkyDollyCsvParser.cpp b/src/Plugins/Import/CsvImport/src/SkyDollyCsvParser.cpp index 757734c03..436aa6c1c 100644 --- a/src/Plugins/Import/CsvImport/src/SkyDollyCsvParser.cpp +++ b/src/Plugins/Import/CsvImport/src/SkyDollyCsvParser.cpp @@ -55,14 +55,14 @@ SkyDollyCsvParser::SkyDollyCsvParser() noexcept { #ifdef DEBUG - qDebug("SkyDollyCsvParser::~SkyDollyCsvParser: CREATED"); + qDebug() << "SkyDollyCsvParser::~SkyDollyCsvParser: CREATED"; #endif } SkyDollyCsvParser::~SkyDollyCsvParser() noexcept { #ifdef DEBUG - qDebug("SkyDollyCsvParser::~SkyDollyCsvParser: DELETED"); + qDebug() << "SkyDollyCsvParser::~SkyDollyCsvParser: DELETED"; #endif } @@ -151,7 +151,7 @@ inline bool SkyDollyCsvParser::importPositionData(const QList &heade PositionData data; int columnIndex = 0; std::int64_t timestampDelta = 0; - bool ok = false; + bool ok {false}; for (const QByteArray &header : headers) { if (columnIndex >= values.count()) { @@ -255,7 +255,7 @@ inline bool SkyDollyCsvParser::importEngineData(const QList &headers EngineData data; int columnIndex = 0; std::int64_t timestampDelta = 0; - bool ok = false; + bool ok {false}; for (const QByteArray &header : headers) { if (columnIndex >= values.count()) { @@ -432,7 +432,7 @@ inline bool SkyDollyCsvParser::importPrimaryFlightControlData(const QList= values.count()) { @@ -484,7 +484,7 @@ inline bool SkyDollyCsvParser::importSecondaryFlightControlData(const QList= values.count()) { @@ -551,7 +551,7 @@ inline bool SkyDollyCsvParser::importAircraftHandleData(const QList AircraftHandleData data; int columnIndex = 0; std::int64_t timestampDelta = 0; - bool ok = false; + bool ok {false}; for (const QByteArray &header : headers) { if (columnIndex >= values.count()) { @@ -633,7 +633,7 @@ inline bool SkyDollyCsvParser::importLightData(const QList &headers, LightData data; int columnIndex = 0; std::int64_t timestampDelta = 0; - bool ok = false; + bool ok {false}; for (const QByteArray &header : headers) { if (columnIndex >= values.count()) { @@ -672,7 +672,7 @@ inline bool SkyDollyCsvParser::importLightData(const QList &headers, inline bool SkyDollyCsvParser::importTimestamp(const QList &values, int columnIndex, bool firstRow, std::int64_t ×tamp, std::int64_t ×tampDelta) noexcept { - bool ok; + bool ok {true}; timestamp = values.at(columnIndex).toLongLong(&ok); if (ok) { if (!firstRow) { diff --git a/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.cpp b/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.cpp index 0147cc083..73385774c 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.cpp +++ b/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.cpp @@ -24,6 +24,9 @@ */ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -38,9 +41,8 @@ namespace constexpr int MaximumSpeed = 999; } -class GpxImportOptionWidgetPrivate +struct GpxImportOptionWidgetPrivate { -public: GpxImportOptionWidgetPrivate(GpxImportSettings &theImportSettings) noexcept : settings(theImportSettings) {} @@ -60,14 +62,14 @@ GpxImportOptionWidget::GpxImportOptionWidget(GpxImportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("GpxImportOptionWidget::GpxImportOptionWidget: CREATED"); + qDebug() << "GpxImportOptionWidget::GpxImportOptionWidget: CREATED"; #endif } GpxImportOptionWidget::~GpxImportOptionWidget() noexcept { #ifdef DEBUG - qDebug("GpxImportOptionWidget::~GpxImportOptionWidget: DELETED"); + qDebug() << "GpxImportOptionWidget::~GpxImportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.h b/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.h index c3faed965..41a359492 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.h +++ b/src/Plugins/Import/GpxImport/src/GpxImportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class GpxImportSettings; -class GpxImportOptionWidgetPrivate; +struct GpxImportOptionWidgetPrivate; class GpxImportOptionWidget : public QWidget { Q_OBJECT public: explicit GpxImportOptionWidget(GpxImportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~GpxImportOptionWidget() noexcept; + ~GpxImportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Import/GpxImport/src/GpxImportPlugin.cpp b/src/Plugins/Import/GpxImport/src/GpxImportPlugin.cpp index 3214fd084..073bd172b 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportPlugin.cpp +++ b/src/Plugins/Import/GpxImport/src/GpxImportPlugin.cpp @@ -52,9 +52,8 @@ #include "GpxParser.h" #include "GpxImportPlugin.h" -class GpxImportPluginPrivate +struct GpxImportPluginPrivate { -public: GpxImportPluginPrivate() : flight(nullptr) {} @@ -73,14 +72,14 @@ GpxImportPlugin::GpxImportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("GpxImportPlugin::GpxImportPlugin: PLUGIN LOADED"); + qDebug() << "GpxImportPlugin::GpxImportPlugin: PLUGIN LOADED"; #endif } GpxImportPlugin::~GpxImportPlugin() noexcept { #ifdef DEBUG - qDebug("GpxImportPlugin::~GpxImportPlugin: PLUGIN UNLOADED"); + qDebug() << "GpxImportPlugin::~GpxImportPlugin: PLUGIN UNLOADED"; #endif } @@ -115,7 +114,7 @@ bool GpxImportPlugin::importFlight(QFile &file, Flight &flight) noexcept bool ok = !d->xml.hasError(); #ifdef DEBUG if (!ok) { - qDebug("GpxImportPlugin::import: XML error: %s", qPrintable(d->xml.errorString())); + qDebug() << "GpxImportPlugin::import: XML error" << d->xml.errorString(); } #endif // We are done with the import diff --git a/src/Plugins/Import/GpxImport/src/GpxImportPlugin.h b/src/Plugins/Import/GpxImport/src/GpxImportPlugin.h index 5410ce055..5780321f4 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportPlugin.h +++ b/src/Plugins/Import/GpxImport/src/GpxImportPlugin.h @@ -42,7 +42,7 @@ class Flight; struct AircraftInfo; struct FlightCondition; class ImportPluginBaseSettings; -class GpxImportPluginPrivate; +struct GpxImportPluginPrivate; class GpxImportPlugin : public ImportPluginBase { @@ -51,25 +51,25 @@ class GpxImportPlugin : public ImportPluginBase Q_INTERFACES(ImportIntf) public: GpxImportPlugin() noexcept; - virtual ~GpxImportPlugin() noexcept; + ~GpxImportPlugin() noexcept override; protected: - virtual ImportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool importFlight(QFile &file, Flight &flight) noexcept override; + ImportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool importFlight(QFile &file, Flight &flight) noexcept override; - virtual FlightAugmentation::Procedures getProcedures() const noexcept override; - virtual FlightAugmentation::Aspects getAspects() const noexcept override; - virtual QDateTime getStartDateTimeUtc() noexcept override; - virtual QString getTitle() const noexcept override; - virtual void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; - virtual void updateExtendedFlightInfo(Flight &flight) noexcept override; - virtual void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; + FlightAugmentation::Procedures getProcedures() const noexcept override; + FlightAugmentation::Aspects getAspects() const noexcept override; + QDateTime getStartDateTimeUtc() noexcept override; + QString getTitle() const noexcept override; + void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; + void updateExtendedFlightInfo(Flight &flight) noexcept override; + void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void parseGPX() noexcept; void updateWaypoints() noexcept; diff --git a/src/Plugins/Import/GpxImport/src/GpxImportSettings.cpp b/src/Plugins/Import/GpxImport/src/GpxImportSettings.cpp index 4154427b2..81da9c54a 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportSettings.cpp +++ b/src/Plugins/Import/GpxImport/src/GpxImportSettings.cpp @@ -22,6 +22,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#ifdef DEBUG +#include +#endif #include #include @@ -47,9 +50,8 @@ namespace constexpr bool DefaultConvertAltitude {true}; } -class GpxImportSettingsPrivate +struct GpxImportSettingsPrivate { -public: GpxImportSettingsPrivate() : waypointSelection(::DefaultWaypointSelection), positionSelection(::DefaultPositionSelection), @@ -71,14 +73,14 @@ GpxImportSettings::GpxImportSettings() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("GpxImportSettings::GpxImportSettings: CREATED"); + qDebug() << "GpxImportSettings::GpxImportSettings: CREATED"; #endif } GpxImportSettings::~GpxImportSettings() noexcept { #ifdef DEBUG - qDebug("GpxImportSettings::~GpxImportSettings: DELETED"); + qDebug() << "GpxImportSettings::~GpxImportSettings: DELETED"; #endif } @@ -201,7 +203,7 @@ void GpxImportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void GpxImportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; int enumeration = valuesByKey.at(::WaypointSelectionKey).toInt(&ok); if (ok) { d->waypointSelection = static_cast(enumeration); diff --git a/src/Plugins/Import/GpxImport/src/GpxImportSettings.h b/src/Plugins/Import/GpxImport/src/GpxImportSettings.h index 62841b93b..4c3bbbeb4 100644 --- a/src/Plugins/Import/GpxImport/src/GpxImportSettings.h +++ b/src/Plugins/Import/GpxImport/src/GpxImportSettings.h @@ -33,7 +33,7 @@ #include #include -class GpxImportSettingsPrivate; +struct GpxImportSettingsPrivate; class GpxImportSettings : public ImportPluginBaseSettings { @@ -46,7 +46,7 @@ class GpxImportSettings : public ImportPluginBaseSettings }; GpxImportSettings() noexcept; - virtual ~GpxImportSettings() noexcept; + ~GpxImportSettings() noexcept override; GPXElement getWaypointSelection() const noexcept; void setWaypointSelection(GPXElement selection) noexcept; @@ -70,13 +70,13 @@ class GpxImportSettings : public ImportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // GPXIMPORTSETTINGS_H diff --git a/src/Plugins/Import/GpxImport/src/GpxParser.cpp b/src/Plugins/Import/GpxImport/src/GpxParser.cpp index f928dbbc6..4e65fb75c 100644 --- a/src/Plugins/Import/GpxImport/src/GpxParser.cpp +++ b/src/Plugins/Import/GpxImport/src/GpxParser.cpp @@ -46,9 +46,8 @@ * - if the timestamp is greater than the last timestamp -> continue the existing track (keep adding to current Positions) * - else start a new track (add a new Position list entry) -> new aircraft */ -class GpxParserPrivate +struct GpxParserPrivate { -public: GpxParserPrivate(Flight &theFlight, QXmlStreamReader &xmlStreamReader, const GpxImportSettings &thePluginSettings) noexcept : flight(theFlight), xml(xmlStreamReader), @@ -72,14 +71,14 @@ GpxParser::GpxParser(Flight &flight, QXmlStreamReader &xmlStreamReader, const Gp : d(std::make_unique(flight, xmlStreamReader, thePluginSettings)) { #ifdef DEBUG - qDebug("GpxParser::~GpxParser: CREATED"); + qDebug() << "GpxParser::~GpxParser: CREATED"; #endif } GpxParser::~GpxParser() noexcept { #ifdef DEBUG - qDebug("GpxParser::~GpxParser: DELETED"); + qDebug() << "GpxParser::~GpxParser: DELETED"; #endif } @@ -87,7 +86,7 @@ void GpxParser::parse() noexcept { if (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parse: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parse: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::gpx) { parseGPX(); @@ -118,7 +117,7 @@ void GpxParser::parseGPX() noexcept { while (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parseGPX: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parseGPX: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::metadata) { parseMetadata(); @@ -138,7 +137,7 @@ void GpxParser::parseMetadata() noexcept { while (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parseMetadata: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parseMetadata: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::name) { d->documentName = d->xml.readElementText(); @@ -204,7 +203,7 @@ void GpxParser::parseRoute() noexcept { while (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parseRoute: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parseRoute: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::name) { // The route name takes precedence over the name given in the metadata @@ -274,7 +273,7 @@ void GpxParser::parseTrack() noexcept { while (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parseTrack: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parseTrack: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::trkseg) { parseTrackSegment(); @@ -288,7 +287,7 @@ void GpxParser::parseTrackSegment() noexcept { while (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("GpxParser::parseTrackSegment: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "GpxParser::parseTrackSegment: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == Gpx::trkpt) { parseTrackPoint(); @@ -354,8 +353,7 @@ inline void GpxParser::parseTrackPoint() noexcept bool GpxParser::parseWaypointType(double &latitude, double &longitude, double &altitude, QString &identifier, QDateTime &dateTime) noexcept { - bool ok; - + bool ok {true}; const QXmlStreamAttributes attributes = d->xml.attributes(); latitude = attributes.value(Gpx::lat).toDouble(&ok); if (ok) { diff --git a/src/Plugins/Import/GpxImport/src/GpxParser.h b/src/Plugins/Import/GpxImport/src/GpxParser.h index bbf575a58..7101c12b8 100644 --- a/src/Plugins/Import/GpxImport/src/GpxParser.h +++ b/src/Plugins/Import/GpxImport/src/GpxParser.h @@ -35,7 +35,7 @@ class QDateTime; class Flight; class GpxImportSettings; -class GpxParserPrivate; +struct GpxParserPrivate; class GpxParser { @@ -49,7 +49,7 @@ class GpxParser QString getDescription() const noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; void parseGPX() noexcept; void parseMetadata() noexcept; diff --git a/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.cpp b/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.cpp index 44088c361..b3abbfaf8 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.cpp +++ b/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.cpp @@ -25,6 +25,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -32,9 +35,8 @@ #include "IgcImportSettings.h" #include "ui_IgcImportOptionWidget.h" -class IgcImportOptionWidgetPrivate +struct IgcImportOptionWidgetPrivate { -public: IgcImportOptionWidgetPrivate(IgcImportSettings &theImportSettings) noexcept : settings(theImportSettings) {} @@ -54,14 +56,14 @@ IgcImportOptionWidget::IgcImportOptionWidget(IgcImportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("IgcImportOptionWidget::IgcImportOptionWidget: CREATED"); + qDebug() << "IgcImportOptionWidget::IgcImportOptionWidget: CREATED"; #endif } IgcImportOptionWidget::~IgcImportOptionWidget() noexcept { #ifdef DEBUG - qDebug("IgcImportOptionWidget::~IgcImportOptionWidget: DELETED"); + qDebug() << "IgcImportOptionWidget::~IgcImportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.h b/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.h index d0ca19c8c..446a50af0 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.h +++ b/src/Plugins/Import/IgcImport/src/IgcImportOptionWidget.h @@ -34,7 +34,7 @@ namespace Ui { } class IgcImportSettings; -class IgcImportOptionWidgetPrivate; +struct IgcImportOptionWidgetPrivate; class IgcImportOptionWidget : public QWidget { @@ -45,7 +45,7 @@ class IgcImportOptionWidget : public QWidget private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Import/IgcImport/src/IgcImportPlugin.cpp b/src/Plugins/Import/IgcImport/src/IgcImportPlugin.cpp index 2ea2b6997..2f8d17eec 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportPlugin.cpp +++ b/src/Plugins/Import/IgcImport/src/IgcImportPlugin.cpp @@ -36,6 +36,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include @@ -67,9 +70,8 @@ namespace constexpr double SameWaypointDistanceThreshold {500}; } -class IgcImportPluginPrivate +struct IgcImportPluginPrivate { -public: IgcImportPluginPrivate() : flight(nullptr), throttleResponseCurve(QEasingCurve::OutExpo) @@ -96,14 +98,14 @@ IgcImportPlugin::IgcImportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("IgcImportPlugin::IgcImportPlugin: PLUGIN LOADED"); + qDebug() << "IgcImportPlugin::IgcImportPlugin: PLUGIN LOADED"; #endif } IgcImportPlugin::~IgcImportPlugin() noexcept { #ifdef DEBUG - qDebug("IgcImportPlugin::~IgcImportPlugin: PLUGIN UNLOADED"); + qDebug() << "IgcImportPlugin::~IgcImportPlugin: PLUGIN UNLOADED"; #endif } @@ -198,7 +200,7 @@ bool IgcImportPlugin::importFlight(QFile &file, Flight &flight) noexcept engine.upsertLast(engineData); engineState = loudNoise ? IgcImportPluginPrivate::EngineState::Running : IgcImportPluginPrivate::EngineState::Shutdown; #ifdef DEBUG - qDebug("IgcImportPlugin::readFile: engine INITIALISED, current ENL: %f threshold %f, engine RUNNING: %d", enl, enlThresholdNorm, loudNoise); + qDebug() << "IgcImportPlugin::readFile: engine INITIALISED, current ENL:" << enl << " threshold:" << enlThresholdNorm << "engine RUNNING:" << loudNoise; #endif break; @@ -220,7 +222,7 @@ bool IgcImportPlugin::importFlight(QFile &file, Flight &flight) noexcept engine.upsertLast(engineData); engineState = IgcImportPluginPrivate::EngineState::Shutdown; #ifdef DEBUG - qDebug("IgcImportPlugin::readFile: engine now SHUTDOWN, current ENL: %f < %f", enl, enlThresholdNorm); + qDebug() << "IgcImportPlugin::readFile: engine now SHUTDOWN, current ENL:" << enl << " threshold:" << enlThresholdNorm; #endif } break; @@ -243,7 +245,7 @@ bool IgcImportPlugin::importFlight(QFile &file, Flight &flight) noexcept engine.upsertLast(engineData); engineState = IgcImportPluginPrivate::EngineState::Running; #ifdef DEBUG - qDebug("IgcImportPlugin::readFile: engine now RUNNING, current ENL: %f > %f", enl, enlThresholdNorm); + qDebug() << "IgcImportPlugin::readFile: engine now RUNNING, current ENL:" << enl << " threshold:" << enlThresholdNorm; #endif } break; diff --git a/src/Plugins/Import/IgcImport/src/IgcImportPlugin.h b/src/Plugins/Import/IgcImport/src/IgcImportPlugin.h index 94ea9c37d..ef09212da 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportPlugin.h +++ b/src/Plugins/Import/IgcImport/src/IgcImportPlugin.h @@ -42,7 +42,7 @@ class Flight; struct AircraftInfo; struct FlightCondition; class ImportPluginBaseSettings; -class IgcImportPluginPrivate; +struct IgcImportPluginPrivate; class IgcImportPlugin : public ImportPluginBase { @@ -51,25 +51,25 @@ class IgcImportPlugin : public ImportPluginBase Q_INTERFACES(ImportIntf) public: IgcImportPlugin() noexcept; - virtual ~IgcImportPlugin() noexcept; + ~IgcImportPlugin() noexcept override; protected: - virtual ImportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool importFlight(QFile &file, Flight &flight) noexcept override; + ImportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool importFlight(QFile &file, Flight &flight) noexcept override; - virtual FlightAugmentation::Procedures getProcedures() const noexcept override; - virtual FlightAugmentation::Aspects getAspects() const noexcept override; - virtual QDateTime getStartDateTimeUtc() noexcept override; - virtual QString getTitle() const noexcept override; - virtual void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; - virtual void updateExtendedFlightInfo(Flight &flight) noexcept override; - virtual void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; + FlightAugmentation::Procedures getProcedures() const noexcept override; + FlightAugmentation::Aspects getAspects() const noexcept override; + QDateTime getStartDateTimeUtc() noexcept override; + QString getTitle() const noexcept override; + void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; + void updateExtendedFlightInfo(Flight &flight) noexcept override; + void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void updateWaypoints() noexcept; diff --git a/src/Plugins/Import/IgcImport/src/IgcImportSettings.cpp b/src/Plugins/Import/IgcImport/src/IgcImportSettings.cpp index c335273ff..c848f804b 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportSettings.cpp +++ b/src/Plugins/Import/IgcImport/src/IgcImportSettings.cpp @@ -22,6 +22,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#ifdef DEBUG +#include +#endif #include #include @@ -41,9 +44,8 @@ namespace constexpr bool DefaultConvertAltitude {true}; } -class IgcImportSettingsPrivate +struct IgcImportSettingsPrivate { -public: IgcImportSettingsPrivate() : altitudeMode(::DefaultAltitudeMode), enlThresholdPercent(::DefaultEnlThresholdPercent), @@ -61,14 +63,14 @@ IgcImportSettings::IgcImportSettings() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("IgcImportSettings::IgcImportSettings: CREATED"); + qDebug() << "IgcImportSettings::IgcImportSettings: CREATED"; #endif } IgcImportSettings::~IgcImportSettings() noexcept { #ifdef DEBUG - qDebug("IgcImportSettings::~IgcImportSettings: DELETED"); + qDebug() << "IgcImportSettings::~IgcImportSettings: DELETED"; #endif } @@ -149,7 +151,7 @@ void IgcImportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void IgcImportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::AltitudeKey).toInt(&ok); if (ok) { d->altitudeMode = static_cast(enumeration); diff --git a/src/Plugins/Import/IgcImport/src/IgcImportSettings.h b/src/Plugins/Import/IgcImport/src/IgcImportSettings.h index 72a81cdee..d7bc44069 100644 --- a/src/Plugins/Import/IgcImport/src/IgcImportSettings.h +++ b/src/Plugins/Import/IgcImport/src/IgcImportSettings.h @@ -33,7 +33,7 @@ #include #include -class IgcImportSettingsPrivate; +struct IgcImportSettingsPrivate; class IgcImportSettings : public ImportPluginBaseSettings { @@ -45,7 +45,7 @@ class IgcImportSettings : public ImportPluginBaseSettings }; IgcImportSettings() noexcept; - virtual ~IgcImportSettings() noexcept; + ~IgcImportSettings() noexcept override; AltitudeMode getAltitudeMode() const noexcept; void setAltitudeMode(AltitudeMode altitudeMode) noexcept; @@ -63,10 +63,10 @@ class IgcImportSettings : public ImportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: std::unique_ptr d; diff --git a/src/Plugins/Import/IgcImport/src/IgcParser.cpp b/src/Plugins/Import/IgcImport/src/IgcParser.cpp index 68da32367..dd1103f0d 100644 --- a/src/Plugins/Import/IgcImport/src/IgcParser.cpp +++ b/src/Plugins/Import/IgcImport/src/IgcParser.cpp @@ -58,24 +58,24 @@ namespace constexpr char BRecord = 'B'; // Three letter codes (TLC) - constexpr char TLCDate[] = "DTE"; - constexpr char TLCPilot[] = "PLT"; - constexpr char TLCCoPilot[] = "CM2"; - constexpr char TLCGliderType[] = "GTY"; - constexpr char TLCGliderId[] = "GID"; + constexpr const char *TLCDate {"DTE"}; + constexpr const char *TLCPilot {"PLT"}; + constexpr const char *TLCCoPilot {"CM2"}; + constexpr const char *TLCGliderType {"GTY"}; + constexpr const char *TLCGliderId {"GID"}; // Offsets constexpr int InvalidOffset = -1; // Formats - constexpr char DateFormat[] = "HHmmss"; + constexpr const char *DateFormat {"HHmmss"}; // H (header) record - constexpr char HRecordDatePattern[] = R"(^HFDTE(?:DATE:)?(\d{2})(\d{2})(\d{2})(?:,?(\d{2}))?)"; - constexpr char HRecordPilotPattern[] = R"(^H(\w)PLT(?:.{0,}?:(.*)|(.*))$)"; - constexpr char HRecordCoPilotPattern[] = R"(^H(\w)CM2(?:.{0,}?:(.*)|(.*))$)"; - constexpr char HRecordGliderTypePattern[] = R"(^H(\w)GTY(?:.{0,}?:(.*)|(.*))$)"; - constexpr char HRecordGliderIdPattern[] = R"(^H(\w)GID(?:.{0,}?:(.*)|(.*))$)"; + constexpr const char *HRecordDatePattern {R"(^HFDTE(?:DATE:)?(\d{2})(\d{2})(\d{2})(?:,?(\d{2}))?)"}; + constexpr const char *HRecordPilotPattern {R"(^H(\w)PLT(?:.{0,}?:(.*)|(.*))$)"}; + constexpr const char *HRecordCoPilotPattern {R"(^H(\w)CM2(?:.{0,}?:(.*)|(.*))$)"}; + constexpr const char *HRecordGliderTypePattern {R"(^H(\w)GTY(?:.{0,}?:(.*)|(.*))$)"}; + constexpr const char *HRecordGliderIdPattern {R"(^H(\w)GID(?:.{0,}?:(.*)|(.*))$)"}; constexpr int HRecordDayIndex = 1; constexpr int HRecordMonthIndex = 2; @@ -83,15 +83,15 @@ namespace constexpr int HRecordFlightNumberIndex = 4; // I (addition definition) record - constexpr char IRecordPattern[] = R"(^[I](\d{2})((?:\d{4}[A-Z]{3})+))"; + constexpr const char *IRecordPattern {R"(^[I](\d{2})((?:\d{4}[A-Z]{3})+))"}; constexpr int IRecordNofAdditionsIndex = 1; constexpr int IRecordAdditionsDefinitionsIndex = 2; // Length of addition definition [bytes] constexpr int IRecordAdditionDefinitionLength = 7; // C (task) record - constexpr char CRecordTaskDefinitionPattern[] = R"(^C(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{4})([-\d]{2})(.*))"; - constexpr char CRecordTaskPattern[] = R"(^C(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])(.*))"; + constexpr const char *CRecordTaskDefinitionPattern {R"(^C(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{4})([-\d]{2})(.*))"}; + constexpr const char *CRecordTaskPattern {R"(^C(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])(.*))"}; constexpr int CRecordLatitudeDegreesIndex = 1; // MMmmm - minutes (MM) with fractional (mmm) part: by dividing by 1000 we get the proper float value @@ -108,7 +108,7 @@ namespace constexpr int CRecordTaskIndex = 7; // B (fix) record - constexpr char BRecordPattern[] = R"(^B(\d{6})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(-\d{4}|\d{5})(-\d{4}|\d{5}))"; + constexpr const char *BRecordPattern {R"(^B(\d{6})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(-\d{4}|\d{5})(-\d{4}|\d{5}))"}; // HHMMSS constexpr int BRecordDateIndex = 1; @@ -130,9 +130,7 @@ namespace constexpr int BRecordGNSSAltitudeIndex = 10; // Values - constexpr char DirectionTypeNorth = 'N'; constexpr char DirectionTypeSouth = 'S'; - constexpr char DirectionTypeEast = 'E'; constexpr char DirectionTypeWest = 'W'; } @@ -246,7 +244,7 @@ bool IgcParser::readManufacturer() noexcept bool IgcParser::readRecords() noexcept { - bool ok = true; + bool ok {true}; QByteArray line = d->file->readLine(); while (ok && !line.isEmpty()) { switch (line.at(0)) { @@ -277,7 +275,7 @@ bool IgcParser::readRecords() noexcept bool IgcParser::parseHeader(const QByteArray &line) noexcept { - bool ok = true; + bool ok {true}; const QByteArray type = line.mid(2, 3); if (type == ::TLCDate) { @@ -296,7 +294,7 @@ bool IgcParser::parseHeader(const QByteArray &line) noexcept bool IgcParser::parseHeaderDate(const QByteArray &line) noexcept { - bool ok = true; + bool ok {true}; QRegularExpressionMatch match = d->hRecordDateRegExp.match(line); if (match.hasMatch()) { int year; @@ -333,7 +331,7 @@ bool IgcParser::parseHeaderDate(const QByteArray &line) noexcept bool IgcParser::parseHeaderText(const QByteArray &line, const QRegularExpression ®Exp, QString &text) noexcept { - bool ok = true; + bool ok {true}; QRegularExpressionMatch match = regExp.match(line); if (match.hasMatch()) { // Ignore the data source for now (F: flight recorder, O: observer, P: pilot) @@ -368,7 +366,7 @@ bool IgcParser::parseHeaderGliderId(const QByteArray &line) noexcept bool IgcParser::parseFixAdditions(const QByteArray &line) noexcept { - bool ok; + bool ok {false}; QRegularExpressionMatch match = d->iRecordRegExp.match(line); if (match.hasMatch()) { const int nofAdditions = match.capturedView(::IRecordNofAdditionsIndex).toInt(); @@ -390,20 +388,15 @@ bool IgcParser::parseFixAdditions(const QByteArray &line) noexcept } else { ok = false; } - } else { - // No pattern match - ok = false; } return ok; } bool IgcParser::parseTask(const QByteArray &line) noexcept { - bool ok; + bool ok {true}; QRegularExpressionMatch match = d->cRecordTaskDefinitionRegExp.match(line); - if (match.hasMatch()) { - ok = true; - } else { + if (!match.hasMatch()) { match = d->cRecordTaskRegExp.match(line); if (match.hasMatch()) { // Latitude @@ -434,7 +427,7 @@ bool IgcParser::parseTask(const QByteArray &line) noexcept bool IgcParser::parseFix(const QByteArray &line) noexcept { - bool ok; + bool ok {false}; QRegularExpressionMatch match = d->bRecordRegExp.match(line); if (match.hasMatch()) { @@ -501,9 +494,6 @@ bool IgcParser::parseFix(const QByteArray &line) noexcept // Invalid timestamp ok = false; } - } else { - // No pattern match - ok = false; } return ok; } diff --git a/src/Plugins/Import/IgcImport/src/IgcParser.h b/src/Plugins/Import/IgcImport/src/IgcParser.h index fa3dee123..c0117b746 100644 --- a/src/Plugins/Import/IgcImport/src/IgcParser.h +++ b/src/Plugins/Import/IgcImport/src/IgcParser.h @@ -121,7 +121,7 @@ class IgcParser bool hasEnvironmentalNoiseLevel() const noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; void init() noexcept; diff --git a/src/Plugins/Import/KmlImport/src/AbstractKmlParser.cpp b/src/Plugins/Import/KmlImport/src/AbstractKmlParser.cpp index 144c30ed8..c2904a645 100644 --- a/src/Plugins/Import/KmlImport/src/AbstractKmlParser.cpp +++ b/src/Plugins/Import/KmlImport/src/AbstractKmlParser.cpp @@ -30,6 +30,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -39,9 +42,8 @@ #include "Kml.h" #include "AbstractKmlParser.h" -class AbstractKmlParserPrivate +struct AbstractKmlParserPrivate { -public: AbstractKmlParserPrivate() noexcept : flight(nullptr), xml(nullptr) @@ -61,14 +63,14 @@ AbstractKmlParser::AbstractKmlParser() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("AbstractKmlParser::AbstractKmlParser: CREATED"); + qDebug() << "AbstractKmlParser::AbstractKmlParser: CREATED"; #endif } AbstractKmlParser::~AbstractKmlParser() noexcept { #ifdef DEBUG - qDebug("AbstractKmlParser::~AbstractKmlParser: DELETED"); + qDebug() << "AbstractKmlParser::~AbstractKmlParser: DELETED"; #endif } @@ -116,7 +118,7 @@ void AbstractKmlParser::parseDocument() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("AbstractKmlParser::parseDocument: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "AbstractKmlParser::parseDocument: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::name) { parseDocumentName(); @@ -135,7 +137,7 @@ void AbstractKmlParser::parseFolder() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("AbstractKmlParser::parseFolder: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "AbstractKmlParser::parseFolder: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::Placemark) { parsePlacemark(); @@ -152,7 +154,7 @@ void AbstractKmlParser::parsePlacemark() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("AbstractKmlParser::parsePlacemark: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "AbstractKmlParser::parsePlacemark: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::Track) { parseTrack(); diff --git a/src/Plugins/Import/KmlImport/src/AbstractKmlParser.h b/src/Plugins/Import/KmlImport/src/AbstractKmlParser.h index c563cb4fd..b5a2b385d 100644 --- a/src/Plugins/Import/KmlImport/src/AbstractKmlParser.h +++ b/src/Plugins/Import/KmlImport/src/AbstractKmlParser.h @@ -33,15 +33,15 @@ class QXmlStreamReader; #include "KmlParserIntf.h" -class AbstractKmlParserPrivate; +struct AbstractKmlParserPrivate; class AbstractKmlParser : public KmlParserIntf { public: AbstractKmlParser() noexcept; - virtual ~AbstractKmlParser() noexcept; + ~AbstractKmlParser() noexcept override; - virtual QString getDocumentName() const noexcept override; + QString getDocumentName() const noexcept override; protected: void initialise(Flight *flight, QXmlStreamReader *xml) noexcept; @@ -57,7 +57,7 @@ class AbstractKmlParser : public KmlParserIntf virtual void parseTrack() noexcept = 0; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // ABSTRACTKMLPARSER_H diff --git a/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.cpp b/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.cpp index 5f44ad9f3..7f738afb9 100644 --- a/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.cpp +++ b/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.cpp @@ -31,6 +31,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -41,9 +44,8 @@ #include "AbstractKmlParser.h" #include "AbstractKmlTrackParser.h" -class AbstractKmlTrackParserPrivate +struct AbstractKmlTrackParserPrivate { -public: AbstractKmlTrackParserPrivate() noexcept { firstDateTimeUtc.setTimeZone(QTimeZone::utc()); @@ -59,14 +61,14 @@ AbstractKmlTrackParser::AbstractKmlTrackParser() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("AbstractKmlTrackParser::AbstractKmlTrackParser: CREATED"); + qDebug() << "AbstractKmlTrackParser::AbstractKmlTrackParser: CREATED"; #endif } AbstractKmlTrackParser::~AbstractKmlTrackParser() noexcept { #ifdef DEBUG - qDebug("AbstractKmlTrackParser::~AbstractKmlTrackParser: DELETED"); + qDebug() << "AbstractKmlTrackParser::~AbstractKmlTrackParser: DELETED"; #endif } @@ -94,12 +96,12 @@ void AbstractKmlTrackParser::parseTrack() noexcept QDateTime currentDateTimeUtc; currentDateTimeUtc.setTimeZone(QTimeZone::utc()); - bool ok = true; + bool ok {true}; int currentTrackDataIndex = 0; while (xml->readNextStartElement()) { const QStringRef xmlName = xml->name(); #ifdef DEBUG - qDebug("AbstractKmlTrackParser::parseTrack: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "AbstractKmlTrackParser::parseTrack: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::when) { const QString dateTimeText = xml->readElementText(); diff --git a/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.h b/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.h index 4280b5060..33d84a65b 100644 --- a/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.h +++ b/src/Plugins/Import/KmlImport/src/AbstractKmlTrackParser.h @@ -33,21 +33,21 @@ class QXmlStreamReader; #include "AbstractKmlParser.h" -class AbstractKmlTrackParserPrivate; +struct AbstractKmlTrackParserPrivate; class AbstractKmlTrackParser : public AbstractKmlParser { public: AbstractKmlTrackParser() noexcept; - virtual ~AbstractKmlTrackParser() noexcept; + ~AbstractKmlTrackParser() noexcept override; - virtual QDateTime getFirstDateTimeUtc() const noexcept override; + QDateTime getFirstDateTimeUtc() const noexcept override; protected: - virtual void parseTrack() noexcept override; + void parseTrack() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // ABSTRACTKMLTRACKPARSER_H diff --git a/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.cpp b/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.cpp index a786f8df8..12fe72203 100644 --- a/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.cpp +++ b/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.cpp @@ -28,6 +28,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -39,9 +42,8 @@ #include "AbstractKmlTrackParser.h" #include "FlightAwareKmlParser.h" -class FlightAwareKmlParserPrivate +struct FlightAwareKmlParserPrivate { -public: FlightAwareKmlParserPrivate() noexcept {} @@ -55,14 +57,14 @@ FlightAwareKmlParser::FlightAwareKmlParser() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("FlightAwareKmlParser::FlightAwareKmlParser: CREATED"); + qDebug() << "FlightAwareKmlParser::FlightAwareKmlParser: CREATED"; #endif } FlightAwareKmlParser::~FlightAwareKmlParser() noexcept { #ifdef DEBUG - qDebug("FlightAwareKmlParser::~FlightAwareKmlParser: DELETED"); + qDebug() << "FlightAwareKmlParser::~FlightAwareKmlParser: DELETED"; #endif } @@ -91,7 +93,7 @@ void FlightAwareKmlParser::parsePlacemark() noexcept while (xml->readNextStartElement()) { const QStringRef xmlName = xml->name(); #ifdef DEBUG - qDebug("FlightAwareKmlParser::parsePlacemark: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightAwareKmlParser::parsePlacemark: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::name) { placemarkName = xml->readElementText(); @@ -115,11 +117,11 @@ void FlightAwareKmlParser::parseWaypoint(const QString &icaoOrName) noexcept { Flight *flight = getFlight(); QXmlStreamReader *xml = getXmlStreamReader(); - bool ok; + bool ok {true}; while (xml->readNextStartElement()) { const QStringRef xmlName = xml->name(); #ifdef DEBUG - qDebug("FlightAwareKmlParser::parseWaypoint: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightAwareKmlParser::parseWaypoint: XML start element:" << xmlName.toString(); #endif if (xmlName == QStringLiteral("coordinates")) { const QString coordinatesText = xml->readElementText(); diff --git a/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.h b/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.h index 10874719a..fce9e1f69 100644 --- a/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.h +++ b/src/Plugins/Import/KmlImport/src/FlightAwareKmlParser.h @@ -35,19 +35,19 @@ class QXmlStreamReader; #include "AbstractKmlTrackParser.h" class Flight; -class FlightAwareKmlParserPrivate; +struct FlightAwareKmlParserPrivate; class FlightAwareKmlParser : public AbstractKmlTrackParser { public: FlightAwareKmlParser() noexcept; - virtual ~FlightAwareKmlParser() noexcept; + ~FlightAwareKmlParser() noexcept override; - virtual void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; - virtual QString getFlightNumber() const noexcept override; + void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; + QString getFlightNumber() const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void parsePlacemark() noexcept override; void parseWaypoint(const QString &name) noexcept; diff --git a/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.cpp b/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.cpp index ec2012966..ba53a1948 100644 --- a/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.cpp +++ b/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.cpp @@ -31,6 +31,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -41,9 +44,8 @@ #include "Kml.h" #include "FlightRadar24KmlParser.h" -class FlightRadar24KmlParserPrivate +struct FlightRadar24KmlParserPrivate { -public: using TrackItem = struct { std::int64_t timestamp; double latitude; @@ -85,14 +87,14 @@ FlightRadar24KmlParser::FlightRadar24KmlParser() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("FlightRadar24KmlParser::FlightRadar24KmlParser: CREATED"); + qDebug() << "FlightRadar24KmlParser::FlightRadar24KmlParser: CREATED"; #endif } FlightRadar24KmlParser::~FlightRadar24KmlParser() noexcept { #ifdef DEBUG - qDebug("FlightRadar24KmlParser::~FlightRadar24KmlParser: DELETED"); + qDebug() << "FlightRadar24KmlParser::~FlightRadar24KmlParser: DELETED"; #endif } @@ -108,7 +110,7 @@ void FlightRadar24KmlParser::parse(QXmlStreamReader &xmlStreamReader, Flight &fl if (d->xml->readNextStartElement()) { #ifdef DEBUG - qDebug("FlightRadar24KmlParser::readKML: XML start element: %s", qPrintable(d->xml->name().toString())); + qDebug() << "FlightRadar24KmlParser::readKML: XML start element:" << d->xml->name().toString(); #endif if (d->xml->name() == Kml::Document) { parseName(); @@ -153,7 +155,7 @@ void FlightRadar24KmlParser::parseName() noexcept { if (d->xml->readNextStartElement()) { #ifdef DEBUG - qDebug("FlightAwareKmlParser::readDocument: XML start element: %s", qPrintable(d->xml->name().toString())); + qDebug() << "FlightAwareKmlParser::readDocument: XML start element:" << d->xml->name().toString(); #endif if (d->xml->name() == Kml::name) { d->documentName = d->xml->readElementText(); @@ -182,7 +184,7 @@ void FlightRadar24KmlParser::parseFolder() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("FlightRadar24KmlParser::readDocument: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightRadar24KmlParser::readDocument: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::name) { name = d->xml->readElementText(); @@ -203,7 +205,7 @@ void FlightRadar24KmlParser::parsePlacemark() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("FlightRadar24KmlParser::readDocument: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightRadar24KmlParser::readDocument: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::description) { if (!parseDescription()) { @@ -221,10 +223,10 @@ void FlightRadar24KmlParser::parsePlacemark() noexcept bool FlightRadar24KmlParser::parseDescription() noexcept { - bool ok; + bool ok {false}; const QString description = d->xml->readElementText(); #ifdef DEBUG - qDebug("FlightRadar24KmlParser::parseDescription: description %s", qPrintable(description)); + qDebug() << "FlightRadar24KmlParser::parseDescription: description:" << description; #endif QRegularExpressionMatch match = d->speedRegExp.match(description); if (match.hasMatch()) { @@ -239,8 +241,6 @@ bool FlightRadar24KmlParser::parseDescription() noexcept } else { ok = false; } - } else { - ok = false; } return ok; @@ -254,7 +254,7 @@ void FlightRadar24KmlParser::parseTimestamp() noexcept while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("FlightRadar24KmlParser::parseTimestamp: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightRadar24KmlParser::parseTimestamp: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::when) { const QString dateTimeText = d->xml->readElementText(); @@ -277,11 +277,11 @@ void FlightRadar24KmlParser::parseTimestamp() noexcept void FlightRadar24KmlParser::parsePoint() noexcept { - bool ok = true; + bool ok {true}; while (d->xml->readNextStartElement()) { const QStringRef xmlName = d->xml->name(); #ifdef DEBUG - qDebug("FlightRadar24KmlParser::parsePoint: XML start element: %s", qPrintable(xmlName.toString())); + qDebug() << "FlightRadar24KmlParser::parsePoint: XML start element:" << xmlName.toString(); #endif if (xmlName == Kml::coordinates) { const QString coordinatesText = d->xml->readElementText(); diff --git a/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.h b/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.h index 425e3cbfa..6e69a53e6 100644 --- a/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.h +++ b/src/Plugins/Import/KmlImport/src/FlightRadar24KmlParser.h @@ -35,21 +35,21 @@ class QXmlStreamReader; #include "KmlParserIntf.h" class Flight; -class FlightRadar24KmlParserPrivate; +struct FlightRadar24KmlParserPrivate; class FlightRadar24KmlParser : public KmlParserIntf { public: FlightRadar24KmlParser() noexcept; - virtual ~FlightRadar24KmlParser() noexcept; + ~FlightRadar24KmlParser() noexcept override; - virtual void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; - virtual QString getDocumentName() const noexcept override; - virtual QString getFlightNumber() const noexcept override; - virtual QDateTime getFirstDateTimeUtc() const noexcept override; + void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; + QString getDocumentName() const noexcept override; + QString getFlightNumber() const noexcept override; + QDateTime getFirstDateTimeUtc() const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void parseName() noexcept; void parseDocument() noexcept; diff --git a/src/Plugins/Import/KmlImport/src/GenericKmlParser.cpp b/src/Plugins/Import/KmlImport/src/GenericKmlParser.cpp index 96981ee42..3db8ee396 100644 --- a/src/Plugins/Import/KmlImport/src/GenericKmlParser.cpp +++ b/src/Plugins/Import/KmlImport/src/GenericKmlParser.cpp @@ -26,17 +26,17 @@ #include #include +#ifdef DEBUG +#include +#endif -#include "Kml.h" #include "AbstractKmlTrackParser.h" #include "GenericKmlParser.h" -class GenericKmlParserPrivate +struct GenericKmlParserPrivate { -public: GenericKmlParserPrivate() noexcept {} - }; // PUBLIC @@ -46,14 +46,14 @@ GenericKmlParser::GenericKmlParser() noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug("GenericKmlParser::GenericKmlParser: CREATED"); + qDebug() << "GenericKmlParser::GenericKmlParser: CREATED"; #endif } GenericKmlParser::~GenericKmlParser() noexcept { #ifdef DEBUG - qDebug("GenericKmlParser::~GenericKmlParser: DELETED"); + qDebug() << "GenericKmlParser::~GenericKmlParser: DELETED"; #endif } diff --git a/src/Plugins/Import/KmlImport/src/GenericKmlParser.h b/src/Plugins/Import/KmlImport/src/GenericKmlParser.h index cf7b2d517..96a63d9cd 100644 --- a/src/Plugins/Import/KmlImport/src/GenericKmlParser.h +++ b/src/Plugins/Import/KmlImport/src/GenericKmlParser.h @@ -35,19 +35,19 @@ class QXmlStreamReader; #include "AbstractKmlTrackParser.h" class Flight; -class GenericKmlParserPrivate; +struct GenericKmlParserPrivate; class GenericKmlParser : public AbstractKmlTrackParser { public: GenericKmlParser() noexcept; - virtual ~GenericKmlParser() noexcept; + ~GenericKmlParser() noexcept override; - virtual void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; - virtual QString getFlightNumber() const noexcept override; + void parse(QXmlStreamReader &xmlStreamReader, Flight &flight) noexcept override; + QString getFlightNumber() const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // GENERICKMLPARSER_H diff --git a/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.cpp b/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.cpp index eb41d9880..c6c2446bf 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.cpp +++ b/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.cpp @@ -23,15 +23,17 @@ * DEALINGS IN THE SOFTWARE. */ #include +#ifdef DEBUG +#include +#endif #include #include "KmlImportOptionWidget.h" #include "KmlImportSettings.h" #include "ui_KmlImportOptionWidget.h" -class KmlImportOptionWidgetPrivate +struct KmlImportOptionWidgetPrivate { -public: KmlImportOptionWidgetPrivate(KmlImportSettings &theImportSettings) noexcept : settings(theImportSettings) {} @@ -51,14 +53,14 @@ KmlImportOptionWidget::KmlImportOptionWidget(KmlImportSettings &settings, QWidge updateUi(); frenchConnection(); #ifdef DEBUG - qDebug("KmlImportOptionWidget::KmlImportOptionWidget: CREATED"); + qDebug() << "KmlImportOptionWidget::KmlImportOptionWidget: CREATED"; #endif } KmlImportOptionWidget::~KmlImportOptionWidget() noexcept { #ifdef DEBUG - qDebug("KmlImportOptionWidget::~KmlImportOptionWidget: DELETED"); + qDebug() << "KmlImportOptionWidget::~KmlImportOptionWidget: DELETED"; #endif } diff --git a/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.h b/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.h index b7d3c5a54..cb88f55ab 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.h +++ b/src/Plugins/Import/KmlImport/src/KmlImportOptionWidget.h @@ -34,18 +34,18 @@ namespace Ui { } class KmlImportSettings; -class KmlImportOptionWidgetPrivate; +struct KmlImportOptionWidgetPrivate; class KmlImportOptionWidget : public QWidget { Q_OBJECT public: explicit KmlImportOptionWidget(KmlImportSettings &settings, QWidget *parent = nullptr) noexcept; - virtual ~KmlImportOptionWidget() noexcept; + ~KmlImportOptionWidget() noexcept override; private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/Plugins/Import/KmlImport/src/KmlImportPlugin.cpp b/src/Plugins/Import/KmlImport/src/KmlImportPlugin.cpp index da0bb11d3..2aec290fa 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportPlugin.cpp +++ b/src/Plugins/Import/KmlImport/src/KmlImportPlugin.cpp @@ -32,6 +32,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -46,9 +49,8 @@ #include "KmlImportOptionWidget.h" #include "KmlImportPlugin.h" -class KmlImportPluginPrivate +struct KmlImportPluginPrivate { -public: KmlImportPluginPrivate() : flight(nullptr) {} @@ -69,14 +71,14 @@ KmlImportPlugin::KmlImportPlugin() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("KmlImportPlugin::KmlImportPlugin: PLUGIN LOADED"); + qDebug() << "KmlImportPlugin::KmlImportPlugin: PLUGIN LOADED"; #endif } KmlImportPlugin::~KmlImportPlugin() noexcept { #ifdef DEBUG - qDebug("KmlImportPlugin::~KmlImportPlugin: PLUGIN UNLOADED"); + qDebug() << "KmlImportPlugin::~KmlImportPlugin: PLUGIN UNLOADED"; #endif } @@ -108,7 +110,7 @@ bool KmlImportPlugin::importFlight(QFile &file, Flight &flight) noexcept d->xml.setDevice(&file); if (d->xml.readNextStartElement()) { #ifdef DEBUG - qDebug("KmlImportPlugin::readFile: XML start element: %s", qPrintable(d->xml.name().toString())); + qDebug() << "KmlImportPlugin::readFile: XML start element:" << d->xml.name().toString(); #endif if (d->xml.name() == QStringLiteral("kml")) { parseKML(); @@ -120,7 +122,7 @@ bool KmlImportPlugin::importFlight(QFile &file, Flight &flight) noexcept bool ok = !d->xml.hasError(); #ifdef DEBUG if (!ok) { - qDebug("KmlImportPlugin::readFile: XML error: %s", qPrintable(d->xml.errorString())); + qDebug() << "KmlImportPlugin::readFile: XML error:" << d->xml.errorString(); } #endif // We are done with the import diff --git a/src/Plugins/Import/KmlImport/src/KmlImportPlugin.h b/src/Plugins/Import/KmlImport/src/KmlImportPlugin.h index 5a71b4850..400325e62 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportPlugin.h +++ b/src/Plugins/Import/KmlImport/src/KmlImportPlugin.h @@ -42,7 +42,7 @@ class Flight; struct AircraftInfo; struct FlightCondition; class ImportPluginBaseSettings; -class KmlImportPluginPrivate; +struct KmlImportPluginPrivate; class KmlImportPlugin : public ImportPluginBase { @@ -51,25 +51,25 @@ class KmlImportPlugin : public ImportPluginBase Q_INTERFACES(ImportIntf) public: KmlImportPlugin() noexcept; - virtual ~KmlImportPlugin() noexcept; + ~KmlImportPlugin() noexcept override; protected: - virtual ImportPluginBaseSettings &getPluginSettings() const noexcept override; - virtual QString getFileSuffix() const noexcept override; - virtual QString getFileFilter() const noexcept override; - virtual std::unique_ptr createOptionWidget() const noexcept override; - virtual bool importFlight(QFile &file, Flight &flight) noexcept override; + ImportPluginBaseSettings &getPluginSettings() const noexcept override; + QString getFileSuffix() const noexcept override; + QString getFileFilter() const noexcept override; + std::unique_ptr createOptionWidget() const noexcept override; + bool importFlight(QFile &file, Flight &flight) noexcept override; - virtual FlightAugmentation::Procedures getProcedures() const noexcept override; - virtual FlightAugmentation::Aspects getAspects() const noexcept override; - virtual QDateTime getStartDateTimeUtc() noexcept override; - virtual QString getTitle() const noexcept override; - virtual void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; - virtual void updateExtendedFlightInfo(Flight &flight) noexcept override; - virtual void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; + FlightAugmentation::Procedures getProcedures() const noexcept override; + FlightAugmentation::Aspects getAspects() const noexcept override; + QDateTime getStartDateTimeUtc() noexcept override; + QString getTitle() const noexcept override; + void updateExtendedAircraftInfo(AircraftInfo &aircraftInfo) noexcept override; + void updateExtendedFlightInfo(Flight &flight) noexcept override; + void updateExtendedFlightCondition(FlightCondition &flightCondition) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void parseKML() noexcept; }; diff --git a/src/Plugins/Import/KmlImport/src/KmlImportSettings.cpp b/src/Plugins/Import/KmlImport/src/KmlImportSettings.cpp index 884558360..071355073 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportSettings.cpp +++ b/src/Plugins/Import/KmlImport/src/KmlImportSettings.cpp @@ -22,6 +22,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#ifdef DEBUG +#include +#endif #include #include @@ -37,9 +40,8 @@ namespace constexpr KmlImportSettings::Format DefaultFormat {KmlImportSettings::Format::FlightAware}; } -class KmlImportSettingsPrivate +struct KmlImportSettingsPrivate { -public: KmlImportSettingsPrivate() : format(::DefaultFormat) {} @@ -53,14 +55,14 @@ KmlImportSettings::KmlImportSettings() noexcept : d(std::make_unique()) { #ifdef DEBUG - qDebug("KmlImportSettings::KmlImportSettings: CREATED"); + qDebug() << "KmlImportSettings::KmlImportSettings: CREATED"; #endif } KmlImportSettings::~KmlImportSettings() noexcept { #ifdef DEBUG - qDebug("KmlImportSettings::~KmlImportSettings: DELETED"); + qDebug() << "KmlImportSettings::~KmlImportSettings: DELETED"; #endif } @@ -99,7 +101,7 @@ void KmlImportSettings::addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keys void KmlImportSettings::restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept { - bool ok; + bool ok {true}; const int enumeration = valuesByKey.at(::FormatKey).toInt(&ok); if (ok) { d->format = static_cast(enumeration); diff --git a/src/Plugins/Import/KmlImport/src/KmlImportSettings.h b/src/Plugins/Import/KmlImport/src/KmlImportSettings.h index 527499915..5557f3ff8 100644 --- a/src/Plugins/Import/KmlImport/src/KmlImportSettings.h +++ b/src/Plugins/Import/KmlImport/src/KmlImportSettings.h @@ -33,7 +33,7 @@ #include #include -class KmlImportSettingsPrivate; +struct KmlImportSettingsPrivate; class KmlImportSettings : public ImportPluginBaseSettings { @@ -49,7 +49,7 @@ class KmlImportSettings : public ImportPluginBaseSettings }; KmlImportSettings() noexcept; - virtual ~KmlImportSettings() noexcept; + ~KmlImportSettings() noexcept override; Format getFormat() const noexcept; void setFormat(Format format) noexcept; @@ -61,13 +61,13 @@ class KmlImportSettings : public ImportPluginBaseSettings void extendedSettingsChanged(); protected: - virtual void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; - virtual void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; - virtual void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; - virtual void restoreDefaultsExtn() noexcept override; + void addSettingsExtn(Settings::KeyValues &keyValues) const noexcept override; + void addKeysWithDefaultsExtn(Settings::KeysWithDefaults &keysWithDefaults) const noexcept override; + void restoreSettingsExtn(const Settings::ValuesByKey &valuesByKey) noexcept override; + void restoreDefaultsExtn() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // KMLIMPORTSETTINGS_H diff --git a/src/Plugins/Module/Formation/src/Formation.cpp b/src/Plugins/Module/Formation/src/Formation.cpp index 7f34a49be..d88a83073 100644 --- a/src/Plugins/Module/Formation/src/Formation.cpp +++ b/src/Plugins/Module/Formation/src/Formation.cpp @@ -115,7 +115,7 @@ PositionData Formation::calculateRelativePositionToUserAircraft(HorizontalDistan const double altitude = positionData.altitude + deltaAltitude; // Degrees - double bearing; + double bearing {0.0}; switch (relativePosition) { case RelativePosition::North: bearing = 0.0; diff --git a/src/Plugins/Module/Formation/src/FormationPlugin.cpp b/src/Plugins/Module/Formation/src/FormationPlugin.cpp index 72e37ce29..3493c4379 100644 --- a/src/Plugins/Module/Formation/src/FormationPlugin.cpp +++ b/src/Plugins/Module/Formation/src/FormationPlugin.cpp @@ -58,14 +58,14 @@ FormationPlugin::FormationPlugin(QObject *parent) noexcept { Q_INIT_RESOURCE(FormationPlugin); #ifdef DEBUG - qDebug() << "FormationPlugin::FormationPlugin: CREATED."; + qDebug() << "FormationPlugin::FormationPlugin: CREATED"; #endif } FormationPlugin::~FormationPlugin() noexcept { #ifdef DEBUG - qDebug() << "FormationPlugin::~FormationPlugin: DELETED."; + qDebug() << "FormationPlugin::~FormationPlugin: DELETED"; #endif } @@ -95,7 +95,7 @@ void FormationPlugin::onStartRecording() noexcept // The initial recording position is calculated for timestamp = 0 ("at the beginning") const InitialPosition initialPosition = Settings::getInstance().isRelativePositionPlacementEnabled() ? Formation::calculateInitialRelativePositionToUserAircraft(horizontalDistance, verticalDistance, relativePosition, 0) : - InitialPosition::NullData; + InitialPosition(); skyConnectManager.startRecording(SkyConnectIntf::RecordingMode::AddToFormation, initialPosition); } @@ -109,7 +109,7 @@ void FormationPlugin::onStartReplay() noexcept const std::int64_t timestamp = fromStart ? 0 : skyConnectManager.getCurrentTimestamp(); const InitialPosition initialPosition = Settings::getInstance().isRelativePositionPlacementEnabled() ? Formation::calculateInitialRelativePositionToUserAircraft(horizontalDistance, verticalDistance, relativePosition, timestamp) : - InitialPosition::NullData; + InitialPosition(); skyConnectManager.startReplay(fromStart, initialPosition); } diff --git a/src/Plugins/Module/Formation/src/FormationPlugin.h b/src/Plugins/Module/Formation/src/FormationPlugin.h index 82f1bb1cc..5430ce98b 100644 --- a/src/Plugins/Module/Formation/src/FormationPlugin.h +++ b/src/Plugins/Module/Formation/src/FormationPlugin.h @@ -55,7 +55,7 @@ protected slots: void onRecordingStopped() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // FORMATIONPLUGIN_H diff --git a/src/Plugins/Module/Formation/src/FormationWidget.cpp b/src/Plugins/Module/Formation/src/FormationWidget.cpp index 3c2dffe3f..5ce0b8f9b 100644 --- a/src/Plugins/Module/Formation/src/FormationWidget.cpp +++ b/src/Plugins/Module/Formation/src/FormationWidget.cpp @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include #include @@ -159,7 +159,7 @@ FormationWidget::FormationWidget(FlightService &flightService, AircraftService & updateUi(); frenchConnection(); #ifdef DEBUG - qDebug() << "FormationWidget::FormationWidget: CREATED."; + qDebug() << "FormationWidget::FormationWidget: CREATED"; #endif } @@ -168,7 +168,7 @@ FormationWidget::~FormationWidget() noexcept const QByteArray tableState = ui->aircraftTableWidget->horizontalHeader()->saveState(); Settings::getInstance().setFormationAircraftTableState(tableState); #ifdef DEBUG - qDebug() << "FormationWidget::~FormationWidget: DELETED."; + qDebug() << "FormationWidget::~FormationWidget: DELETED"; #endif } @@ -292,7 +292,7 @@ void FormationWidget::frenchConnection() noexcept { // Logbook const Logbook &logbook = Logbook::getInstance(); - connect(&LogbookManager::getInstance(), &LogbookManager::connectionChanged, + connect(&PersistenceManager::getInstance(), &PersistenceManager::connectionChanged, this, &FormationWidget::updateUi); // Flight @@ -362,7 +362,7 @@ void FormationWidget::updateAircraftTable() noexcept int aircraftIndex {0}; for (const auto &aircraft : flight) { - createRow(*aircraft, aircraftIndex); + createRow(aircraft, aircraftIndex); ++aircraftIndex; } @@ -504,7 +504,7 @@ void FormationWidget::updateToolTips() noexcept } // Time offset - if (d->selectedAircraftIndex != Flight::InvalidId) { + if (d->selectedAircraftIndex != Const::InvalidId) { Flight &flight = Logbook::getInstance().getCurrentFlight(); Aircraft &aircraft = flight[d->selectedAircraftIndex]; @@ -1034,9 +1034,9 @@ void FormationWidget::resetAllTimeOffsets() noexcept } if (doReset) { Flight &flight = Logbook::getInstance().getCurrentFlight(); - bool ok = true; + bool ok {true}; for (auto &aircraft : flight) { - ok = d->aircraftService.changeTimeOffset(*aircraft, 0); + ok = d->aircraftService.changeTimeOffset(aircraft, 0); if (!ok) { break; } diff --git a/src/Plugins/Module/Formation/src/FormationWidget.h b/src/Plugins/Module/Formation/src/FormationWidget.h index 797544c78..1670ee702 100644 --- a/src/Plugins/Module/Formation/src/FormationWidget.h +++ b/src/Plugins/Module/Formation/src/FormationWidget.h @@ -62,7 +62,7 @@ class FormationWidget : public QWidget private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void initTimeOffsetUi() noexcept; diff --git a/src/Plugins/Module/Location/src/EnumerationItemDelegate.cpp b/src/Plugins/Module/Location/src/EnumerationItemDelegate.cpp index 4ec051f44..97e773c99 100644 --- a/src/Plugins/Module/Location/src/EnumerationItemDelegate.cpp +++ b/src/Plugins/Module/Location/src/EnumerationItemDelegate.cpp @@ -51,14 +51,14 @@ EnumerationItemDelegate::EnumerationItemDelegate(QString enumerationName) noexce d(std::make_unique(enumerationName)) { #ifdef DEBUG - qDebug() << "EnumerationItemDelegate::EnumerationItemDelegate: CREATED."; + qDebug() << "EnumerationItemDelegate::EnumerationItemDelegate: CREATED"; #endif } EnumerationItemDelegate::~EnumerationItemDelegate() noexcept { #ifdef DEBUG - qDebug() << "EnumerationItemDelegate::~EnumerationItemDelegate: DELETED."; + qDebug() << "EnumerationItemDelegate::~EnumerationItemDelegate: DELETED"; #endif } diff --git a/src/Plugins/Module/Location/src/EnumerationItemDelegate.h b/src/Plugins/Module/Location/src/EnumerationItemDelegate.h index 03473a007..2abaa986e 100644 --- a/src/Plugins/Module/Location/src/EnumerationItemDelegate.h +++ b/src/Plugins/Module/Location/src/EnumerationItemDelegate.h @@ -45,7 +45,7 @@ class EnumerationItemDelegate : public QStyledItemDelegate void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; private slots: void commitAndCloseEditor() noexcept; diff --git a/src/Plugins/Module/Location/src/LocationPlugin.cpp b/src/Plugins/Module/Location/src/LocationPlugin.cpp index 95942b4a4..43cf01c39 100644 --- a/src/Plugins/Module/Location/src/LocationPlugin.cpp +++ b/src/Plugins/Module/Location/src/LocationPlugin.cpp @@ -51,14 +51,14 @@ LocationPlugin::LocationPlugin(QObject *parent) noexcept { frenchConnection(); #ifdef DEBUG - qDebug() << "LocationPlugin::LocationPlugin: CREATED."; + qDebug() << "LocationPlugin::LocationPlugin: CREATED"; #endif } LocationPlugin::~LocationPlugin() noexcept { #ifdef DEBUG - qDebug() << "LocationPlugin::~LocationPlugin: DELETED."; + qDebug() << "LocationPlugin::~LocationPlugin: DELETED"; #endif } diff --git a/src/Plugins/Module/Location/src/LocationPlugin.h b/src/Plugins/Module/Location/src/LocationPlugin.h index 231bc05fc..c2f674e56 100644 --- a/src/Plugins/Module/Location/src/LocationPlugin.h +++ b/src/Plugins/Module/Location/src/LocationPlugin.h @@ -49,7 +49,7 @@ class LocationPlugin : public AbstractModule QWidget *getWidget() const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; diff --git a/src/Plugins/Module/Location/src/LocationWidget.cpp b/src/Plugins/Module/Location/src/LocationWidget.cpp index a98469ddc..2355218ce 100644 --- a/src/Plugins/Module/Location/src/LocationWidget.cpp +++ b/src/Plugins/Module/Location/src/LocationWidget.cpp @@ -47,11 +47,12 @@ #include +#include #include #include #include #include -#include +#include #include #include #include @@ -100,13 +101,13 @@ struct LocationWidgetPrivate LocationWidgetPrivate() noexcept { if (typeEnumeration.count() == 0) { - enumerationService->getEnumerationByName(typeEnumeration); + typeEnumeration = enumerationService->getEnumerationByName(EnumerationService::LocationType); } if (categoryEnumeration.count() == 0) { - enumerationService->getEnumerationByName(categoryEnumeration); + categoryEnumeration = enumerationService->getEnumerationByName(EnumerationService::LocationCategory); } if (countryEnumeration.count() == 0) { - enumerationService->getEnumerationByName(countryEnumeration); + countryEnumeration = enumerationService->getEnumerationByName(EnumerationService::Country); } } @@ -136,9 +137,9 @@ struct LocationWidgetPrivate static inline int onGroundColumn {InvalidColumn}; static inline int attributesColumn {InvalidColumn}; - static inline Enumeration typeEnumeration {EnumerationService::LocationType}; - static inline Enumeration categoryEnumeration {EnumerationService::LocationCategory}; - static inline Enumeration countryEnumeration {EnumerationService::Country}; + static inline Enumeration typeEnumeration; + static inline Enumeration categoryEnumeration; + static inline Enumeration countryEnumeration; }; // PUBLIC @@ -153,7 +154,7 @@ LocationWidget::LocationWidget(QWidget *parent) noexcept updateUi(); frenchConnection(); #ifdef DEBUG - qDebug() << "LocationWidget::LocationWidget: CREATED."; + qDebug() << "LocationWidget::LocationWidget: CREATED"; #endif } @@ -162,7 +163,7 @@ LocationWidget::~LocationWidget() noexcept const QByteArray tableState = ui->locationTableWidget->horizontalHeader()->saveState(); Settings::getInstance().setLocationTableState(tableState); #ifdef DEBUG - qDebug() << "LocationWidget::~LocationWidget: DELETED."; + qDebug() << "LocationWidget::~LocationWidget: DELETED"; #endif } @@ -193,13 +194,13 @@ void LocationWidget::addUserLocation(double latitude, double longitude) void LocationWidget::addLocation(Location newLocation) { - if (newLocation.typeId == Location::InvalidId) { + if (newLocation.typeId == Const::InvalidId) { newLocation.typeId = PersistedEnumerationItem(EnumerationService::LocationType, EnumerationService::LocationTypeUserSymbolicId).id(); } - if (newLocation.categoryId == Location::InvalidId) { + if (newLocation.categoryId == Const::InvalidId) { newLocation.categoryId = PersistedEnumerationItem(EnumerationService::LocationCategory, EnumerationService::LocationCategoryNoneSymbolicId).id(); } - if (newLocation.countryId == Location::InvalidId) { + if (newLocation.countryId == Const::InvalidId) { newLocation.countryId = PersistedEnumerationItem(EnumerationService::Country, EnumerationService::CountryWorldSymbolicId).id(); } Location location {newLocation}; @@ -308,8 +309,7 @@ void LocationWidget::initUi() noexcept void LocationWidget::frenchConnection() noexcept { // Logbook - const Logbook &logbook = Logbook::getInstance(); - connect(&LogbookManager::getInstance(), &LogbookManager::connectionChanged, + connect(&PersistenceManager::getInstance(), &PersistenceManager::connectionChanged, this, &LocationWidget::updateUi); // Connection @@ -393,10 +393,9 @@ void LocationWidget::updateInfoUi() noexcept void LocationWidget::updateLocationTable() noexcept { - if (LogbookManager::getInstance().isConnected()) { + if (PersistenceManager::getInstance().isConnected()) { - std::vector locations; - d->locationService->getAll(std::back_inserter(locations)); + std::vector locations = d->locationService->getAll(); ui->locationTableWidget->blockSignals(true); ui->locationTableWidget->setSortingEnabled(false); @@ -651,7 +650,7 @@ int LocationWidget::getSelectedRow() const noexcept std::int64_t LocationWidget::getSelectedLocationId() const noexcept { - std::int64_t selectedLocationId {::Location::InvalidId}; + std::int64_t selectedLocationId {Const::InvalidId}; const int selectedRow = getSelectedRow(); if (selectedRow != ::InvalidRow) { selectedLocationId = ui->locationTableWidget->item(selectedRow, LocationWidgetPrivate::idColumn)->data(Qt::EditRole).toLongLong(); @@ -727,7 +726,7 @@ void LocationWidget::onTeleportToSelectedLocation() noexcept void LocationWidget::onDeleteLocation() noexcept { const std::int64_t selectedLocationId = getSelectedLocationId(); - if (selectedLocationId != ::Location::InvalidId) { + if (selectedLocationId != Const::InvalidId) { Settings &settings = Settings::getInstance(); bool doDelete {true}; if (settings.isDeleteLocationConfirmationEnabled()) { diff --git a/src/Plugins/Module/Location/src/LocationWidget.h b/src/Plugins/Module/Location/src/LocationWidget.h index 75a5a32c9..e3189f427 100644 --- a/src/Plugins/Module/Location/src/LocationWidget.h +++ b/src/Plugins/Module/Location/src/LocationWidget.h @@ -62,7 +62,7 @@ class LocationWidget : public QWidget private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void frenchConnection() noexcept; diff --git a/src/Plugins/Module/Logbook/src/LogbookPlugin.cpp b/src/Plugins/Module/Logbook/src/LogbookPlugin.cpp index 744e36e15..ee2674986 100644 --- a/src/Plugins/Module/Logbook/src/LogbookPlugin.cpp +++ b/src/Plugins/Module/Logbook/src/LogbookPlugin.cpp @@ -56,14 +56,14 @@ LogbookPlugin::LogbookPlugin(QObject *parent) noexcept d(std::make_unique(getFlightService())) { #ifdef DEBUG - qDebug() << "LogbookPlugin::LogbookPlugin: CREATED."; + qDebug() << "LogbookPlugin::LogbookPlugin: CREATED"; #endif } LogbookPlugin::~LogbookPlugin() noexcept { #ifdef DEBUG - qDebug() << "LogbookPlugin::~LogbookPlugin: DELETED."; + qDebug() << "LogbookPlugin::~LogbookPlugin: DELETED"; #endif } diff --git a/src/Plugins/Module/Logbook/src/LogbookPlugin.h b/src/Plugins/Module/Logbook/src/LogbookPlugin.h index ad5243199..4c2e78907 100644 --- a/src/Plugins/Module/Logbook/src/LogbookPlugin.h +++ b/src/Plugins/Module/Logbook/src/LogbookPlugin.h @@ -50,7 +50,7 @@ protected slots: void onRecordingStopped() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // LOGBOOKPLUGIN_H diff --git a/src/Plugins/Module/Logbook/src/LogbookWidget.cpp b/src/Plugins/Module/Logbook/src/LogbookWidget.cpp index 13ba548e3..d2a01ad1a 100644 --- a/src/Plugins/Module/Logbook/src/LogbookWidget.cpp +++ b/src/Plugins/Module/Logbook/src/LogbookWidget.cpp @@ -65,7 +65,7 @@ #include #include #include -#include +#include #include #include #include @@ -119,7 +119,7 @@ struct LogbookWidgetPrivate std::unique_ptr logbookService {std::make_unique()}; FlightService &flightService; - std::int64_t flightInMemoryId {Flight::InvalidId}; + std::int64_t flightInMemoryId {Const::InvalidId}; Unit unit; FlightSelector flightSelector; std::unique_ptr searchTimer {std::make_unique()}; @@ -146,7 +146,7 @@ LogbookWidget::LogbookWidget(FlightService &flightService, QWidget *parent) noex onSelectionChanged(); frenchConnection(); #ifdef DEBUG - qDebug() << "LogbookWidget::LogbookWidget: CREATED."; + qDebug() << "LogbookWidget::LogbookWidget: CREATED"; #endif } @@ -155,7 +155,7 @@ LogbookWidget::~LogbookWidget() noexcept const QByteArray logbookState = ui->logTableWidget->horizontalHeader()->saveState(); Settings::getInstance().setLogbookState(logbookState); #ifdef DEBUG - qDebug() << "LogbookWidget::~LogbookWidget: DELETED."; + qDebug() << "LogbookWidget::~LogbookWidget: DELETED"; #endif } @@ -234,7 +234,7 @@ void LogbookWidget::initFilterUi() noexcept void LogbookWidget::updateFlightTable() noexcept { - if (LogbookManager::getInstance().isConnected()) { + if (PersistenceManager::getInstance().isConnected()) { const Flight &flight = Logbook::getInstance().getCurrentFlight(); d->flightInMemoryId = flight.getId(); @@ -316,7 +316,7 @@ inline void LogbookWidget::updateFlightSummaryRow(const FlightSummary &summary, // Aircraft count newItem = std::make_unique(); - newItem->setData(Qt::DisplayRole, summary.aircraftCount); + newItem->setData(Qt::DisplayRole, QVariant::fromValue(summary.aircraftCount)); newItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); ui->logTableWidget->setItem(row, column, newItem.release()); ++column; @@ -366,7 +366,7 @@ inline void LogbookWidget::updateFlightSummaryRow(const FlightSummary &summary, void LogbookWidget::updateDateSelectorUi() noexcept { - if (LogbookManager::getInstance().isConnected()) { + if (PersistenceManager::getInstance().isConnected()) { // Sorted by year, month, day std::forward_list flightDates; d->logbookService->getFlightDates(std::front_insert_iterator(flightDates)); @@ -415,15 +415,15 @@ void LogbookWidget::updateEditUi() noexcept std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); const bool active = skyConnect && skyConnect->get().isActive(); const std::int64_t selectedFlightId = getSelectedFlightId(); - ui->loadPushButton->setEnabled(!active && selectedFlightId != Flight::InvalidId); - ui->deletePushButton->setEnabled(!active && selectedFlightId != Flight::InvalidId); + ui->loadPushButton->setEnabled(!active && selectedFlightId != Const::InvalidId); + ui->deletePushButton->setEnabled(!active && selectedFlightId != Const::InvalidId); } void LogbookWidget::frenchConnection() noexcept { // Logbook const Logbook &logbook = Logbook::getInstance(); - connect(&LogbookManager::getInstance(), &LogbookManager::connectionChanged, + connect(&PersistenceManager::getInstance(), &PersistenceManager::connectionChanged, this, &LogbookWidget::updateUi); connect(&logbook, &Logbook::flightTitleOrDescriptionChanged, this, &LogbookWidget::updateUi); @@ -579,7 +579,7 @@ int LogbookWidget::getSelectedRow() const noexcept std::int64_t LogbookWidget::getSelectedFlightId() const noexcept { - std::int64_t selectedFlightId {::Flight::InvalidId}; + std::int64_t selectedFlightId {Const::InvalidId}; const int selectedRow = getSelectedRow(); if (selectedRow != ::InvalidRow) { selectedFlightId = ui->logTableWidget->item(selectedRow, LogbookWidgetPrivate::flightIdColumn)->data(Qt::EditRole).toLongLong(); @@ -647,7 +647,7 @@ void LogbookWidget::loadFlight() noexcept { if (!SkyConnectManager::getInstance().isInRecordingState()) { const std::int64_t selectedFlightId = getSelectedFlightId(); - if (selectedFlightId != Flight::InvalidId) { + if (selectedFlightId != Const::InvalidId) { const bool ok = d->flightService.restore(selectedFlightId, Logbook::getInstance().getCurrentFlight()); if (!ok) { QMessageBox::critical(this, tr("Logbook error"), tr("The flight %1 could not be read from the logbook.").arg(selectedFlightId)); @@ -659,7 +659,7 @@ void LogbookWidget::loadFlight() noexcept void LogbookWidget::deleteFlight() noexcept { const std::int64_t selectedFlightId = getSelectedFlightId(); - if (selectedFlightId != Flight::InvalidId) { + if (selectedFlightId != Const::InvalidId) { Settings &settings = Settings::getInstance(); bool doDelete {true}; diff --git a/src/Plugins/Module/Logbook/src/LogbookWidget.h b/src/Plugins/Module/Logbook/src/LogbookWidget.h index b57bb7e26..3bb9b5406 100644 --- a/src/Plugins/Module/Logbook/src/LogbookWidget.h +++ b/src/Plugins/Module/Logbook/src/LogbookWidget.h @@ -59,9 +59,8 @@ class LogbookWidget : public QWidget ~LogbookWidget() noexcept override; private: - Q_DISABLE_COPY(LogbookWidget) std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void initFilterUi() noexcept; diff --git a/src/Plugins/Module/Template/src/TemplatePlugin.cpp b/src/Plugins/Module/Template/src/TemplatePlugin.cpp index 596e8b21a..6f447d52e 100644 --- a/src/Plugins/Module/Template/src/TemplatePlugin.cpp +++ b/src/Plugins/Module/Template/src/TemplatePlugin.cpp @@ -49,14 +49,14 @@ TemplatePlugin::TemplatePlugin(QObject *parent) noexcept d(std::make_unique()) { #ifdef DEBUG - qDebug() << "TemplatePlugin::TemplatePlugin: CREATED."; + qDebug() << "TemplatePlugin::TemplatePlugin: CREATED"; #endif } TemplatePlugin::~TemplatePlugin() noexcept { #ifdef DEBUG - qDebug() << "TemplatePlugin::~TemplatePlugin: DELETED."; + qDebug() << "TemplatePlugin::~TemplatePlugin: DELETED"; #endif } diff --git a/src/Plugins/Module/Template/src/TemplatePlugin.h b/src/Plugins/Module/Template/src/TemplatePlugin.h index 08b7abc6a..bbfe6b9bd 100644 --- a/src/Plugins/Module/Template/src/TemplatePlugin.h +++ b/src/Plugins/Module/Template/src/TemplatePlugin.h @@ -47,7 +47,7 @@ class TemplatePlugin : public AbstractModule QWidget *getWidget() const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // LOCATIONPLUGIN_H diff --git a/src/Plugins/Module/Template/src/TemplateWidget.cpp b/src/Plugins/Module/Template/src/TemplateWidget.cpp index 84d94355f..b780f042f 100644 --- a/src/Plugins/Module/Template/src/TemplateWidget.cpp +++ b/src/Plugins/Module/Template/src/TemplateWidget.cpp @@ -32,9 +32,8 @@ #include "TemplateWidget.h" #include "ui_TemplateWidget.h" -class TemplateWidgetPrivate +struct TemplateWidgetPrivate { -public: TemplateWidgetPrivate() noexcept {} }; @@ -51,14 +50,14 @@ TemplateWidget::TemplateWidget(QWidget *parent) noexcept updateUi(); frenchConnection(); #ifdef DEBUG - qDebug() << "TemplateWidget::TemplateWidget: CREATED."; + qDebug() << "TemplateWidget::TemplateWidget: CREATED"; #endif } TemplateWidget::~TemplateWidget() noexcept { #ifdef DEBUG - qDebug() << "TemplateWidget::~TemplateWidget: DELETED."; + qDebug() << "TemplateWidget::~TemplateWidget: DELETED"; #endif } diff --git a/src/Plugins/Module/Template/src/TemplateWidget.h b/src/Plugins/Module/Template/src/TemplateWidget.h index 1ca12fc7e..06cfbe1ad 100644 --- a/src/Plugins/Module/Template/src/TemplateWidget.h +++ b/src/Plugins/Module/Template/src/TemplateWidget.h @@ -44,7 +44,7 @@ class DatabaseService; class FlightService; class FlightDate; class FlightSummary; -class TemplateWidgetPrivate; +struct TemplateWidgetPrivate; namespace Ui { class TemplateWidget; @@ -58,9 +58,8 @@ class TemplateWidget : public QWidget ~TemplateWidget() noexcept override; private: - Q_DISABLE_COPY(TemplateWidget) std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void frenchConnection() noexcept; diff --git a/src/UserInterface/include/UserInterface/MainWindow.h b/src/UserInterface/include/UserInterface/MainWindow.h index 874e37a48..a9579c4e2 100644 --- a/src/UserInterface/include/UserInterface/MainWindow.h +++ b/src/UserInterface/include/UserInterface/MainWindow.h @@ -48,7 +48,7 @@ class SettingsDialog; class FlightDialog; class SimulationVariablesDialog; class StatisticsDialog; -class MainWindowPrivate; +struct MainWindowPrivate; class USERINTERFACE_API MainWindow : public QMainWindow { @@ -64,9 +64,8 @@ class USERINTERFACE_API MainWindow : public QMainWindow void closeEvent(QCloseEvent *event) noexcept override; private: - Q_DISABLE_COPY(MainWindow) std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void frenchConnection() noexcept; void initUi() noexcept; diff --git a/src/UserInterface/src/Dialog/AboutDialog.cpp b/src/UserInterface/src/Dialog/AboutDialog.cpp index 3af733468..dcee4332b 100644 --- a/src/UserInterface/src/Dialog/AboutDialog.cpp +++ b/src/UserInterface/src/Dialog/AboutDialog.cpp @@ -45,9 +45,8 @@ #include "AboutDialog.h" #include "ui_AboutDialog.h" -class AboutDialogPrivate +struct AboutDialogPrivate { -public: AboutDialogPrivate(QWidget &parent) noexcept { if (parent.devicePixelRatioF() >= 1.5) { diff --git a/src/UserInterface/src/Dialog/AboutDialog.h b/src/UserInterface/src/Dialog/AboutDialog.h index 08e81e8bf..d1e4001d0 100644 --- a/src/UserInterface/src/Dialog/AboutDialog.h +++ b/src/UserInterface/src/Dialog/AboutDialog.h @@ -31,7 +31,7 @@ class QMousePressEvent; -class AboutDialogPrivate; +struct AboutDialogPrivate; namespace Ui { class AboutDialog; @@ -49,9 +49,8 @@ class AboutDialog : public QDialog void mouseReleaseEvent(QMouseEvent *event) noexcept override; private: - Q_DISABLE_COPY(AboutDialog) std::unique_ptr d; - std::unique_ptr ui; + const std::unique_ptr ui; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/Dialog/FlightDialog.cpp b/src/UserInterface/src/Dialog/FlightDialog.cpp index 004c0a6cf..2f020fc28 100644 --- a/src/UserInterface/src/Dialog/FlightDialog.cpp +++ b/src/UserInterface/src/Dialog/FlightDialog.cpp @@ -51,9 +51,8 @@ #include "FlightDialog.h" #include "ui_FlightDialog.h" -class FlightDialogPrivate +struct FlightDialogPrivate { -public: FlightDialogPrivate(FlightService &theFlightService) noexcept : flightService(theFlightService), closeDialogShortcut(nullptr) diff --git a/src/UserInterface/src/Dialog/FlightDialog.h b/src/UserInterface/src/Dialog/FlightDialog.h index e20a76e25..23eea57c0 100644 --- a/src/UserInterface/src/Dialog/FlightDialog.h +++ b/src/UserInterface/src/Dialog/FlightDialog.h @@ -33,7 +33,7 @@ class QShowEvent; class QHideEvent; class FlightService; -class FlightDialogPrivate; +struct FlightDialogPrivate; namespace Ui { class FlightDialog; @@ -44,19 +44,18 @@ class FlightDialog : public QDialog Q_OBJECT public: explicit FlightDialog(FlightService &flightService, QWidget *parent = nullptr) noexcept; - virtual ~FlightDialog() noexcept; + ~FlightDialog() noexcept override; signals: void visibilityChanged(bool visible); protected: - virtual void showEvent(QShowEvent *event) noexcept override; - virtual void hideEvent(QHideEvent *event) noexcept override; + void showEvent(QShowEvent *event) noexcept override; + void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(FlightDialog) std::unique_ptr d; - std::unique_ptr ui; + const std::unique_ptr ui; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/Dialog/LogbookBackupDialog.cpp b/src/UserInterface/src/Dialog/LogbookBackupDialog.cpp index 0dbe5c559..1786bed37 100644 --- a/src/UserInterface/src/Dialog/LogbookBackupDialog.cpp +++ b/src/UserInterface/src/Dialog/LogbookBackupDialog.cpp @@ -35,14 +35,13 @@ #include #include #include -#include +#include #include #include "LogbookBackupDialog.h" #include "ui_LogbookBackupDialog.h" -class LogbookBackupDialogPrivate +struct LogbookBackupDialogPrivate { -public: LogbookBackupDialogPrivate() : databaseService(std::make_unique()) {} @@ -62,9 +61,10 @@ LogbookBackupDialog::LogbookBackupDialog(QWidget *parent) noexcept initUi(); frenchConnection(); - LogbookManager &logbookManager = LogbookManager::getInstance(); - Metadata metadata; - if (logbookManager.getMetadata(metadata)) { + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + bool ok {true}; + const Metadata metadata = persistenceManager.getMetadata(&ok); + if (ok) { d->originalBackupPeriodIntlId = metadata.backupPeriodSymId; } else { d->originalBackupPeriodIntlId = Const::BackupNeverSymId; @@ -144,12 +144,12 @@ void LogbookBackupDialog::initUi() noexcept void LogbookBackupDialog::updateUi() noexcept { - LogbookManager &logbookManager = LogbookManager::getInstance(); - Metadata metadata; - const bool ok = logbookManager.getMetadata(metadata); + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + bool ok {true}; + const Metadata metadata = persistenceManager.getMetadata(&ok); if (ok) { // Backup folder - const QString backupDirectoryPath = LogbookManager::createBackupPathIfNotExists(metadata.backupDirectoryPath); + const QString backupDirectoryPath = PersistenceManager::createBackupPathIfNotExists(metadata.backupDirectoryPath); ui->backupDirectoryLineEdit->setText(QDir::toNativeSeparators(backupDirectoryPath)); // Backup period @@ -182,7 +182,7 @@ void LogbookBackupDialog::chooseBackupFolder() noexcept QString path = ui->backupDirectoryLineEdit->text(); const QDir dir(path); if (!dir.exists()) { - path = QFileInfo(LogbookManager::getInstance().getLogbookPath()).absolutePath(); + path = QFileInfo(PersistenceManager::getInstance().getLogbookPath()).absolutePath(); } const QString backupDirectoryPath = QFileDialog::getExistingDirectory(this, tr("Select Backup Folder"), path); if (!backupDirectoryPath.isNull()) { diff --git a/src/UserInterface/src/Dialog/LogbookBackupDialog.h b/src/UserInterface/src/Dialog/LogbookBackupDialog.h index 5e76b426a..387411ce7 100644 --- a/src/UserInterface/src/Dialog/LogbookBackupDialog.h +++ b/src/UserInterface/src/Dialog/LogbookBackupDialog.h @@ -36,26 +36,25 @@ namespace Ui { class LogbookBackupDialog; } -class LogbookBackupDialogPrivate; +struct LogbookBackupDialogPrivate; class LogbookBackupDialog : public QDialog { Q_OBJECT public: explicit LogbookBackupDialog(QWidget *parent = nullptr) noexcept; - virtual ~LogbookBackupDialog() noexcept; + ~LogbookBackupDialog() noexcept override; public slots: - virtual void accept() noexcept override; - virtual void reject() noexcept override; + void accept() noexcept override; + void reject() noexcept override; protected: - virtual void showEvent(QShowEvent *event) noexcept override; + void showEvent(QShowEvent *event) noexcept override; private: - Q_DISABLE_COPY(LogbookBackupDialog) std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/Dialog/LogbookSettingsDialog.cpp b/src/UserInterface/src/Dialog/LogbookSettingsDialog.cpp index 903ddaa59..bb2907b92 100644 --- a/src/UserInterface/src/Dialog/LogbookSettingsDialog.cpp +++ b/src/UserInterface/src/Dialog/LogbookSettingsDialog.cpp @@ -40,15 +40,14 @@ #include #include #include -#include +#include #include #include #include "LogbookSettingsDialog.h" #include "ui_LogbookSettingsDialog.h" -class LogbookSettingsDialogPrivate +struct LogbookSettingsDialogPrivate { -public: LogbookSettingsDialogPrivate() noexcept : databaseService(std::make_unique()) {} @@ -68,9 +67,10 @@ LogbookSettingsDialog::LogbookSettingsDialog(QWidget *parent) noexcept : initUi(); frenchConnection(); - LogbookManager &logbookManager = LogbookManager::getInstance(); - Metadata metadata; - if (logbookManager.getMetadata(metadata)) { + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + bool ok {true}; + const Metadata metadata = persistenceManager.getMetadata(&ok); + if (ok) { d->originalBackupPeriodIntlId = metadata.backupPeriodSymId; } else { d->originalBackupPeriodIntlId = Const::BackupNeverSymId; @@ -124,11 +124,11 @@ void LogbookSettingsDialog::initUi() noexcept void LogbookSettingsDialog::updateUi() noexcept { - LogbookManager &logbookManager = LogbookManager::getInstance(); - Metadata metadata; - const bool ok = logbookManager.getMetadata(metadata); + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + bool ok {true}; + const Metadata metadata = persistenceManager.getMetadata(&ok); if (ok) { - const QString logbookPath = logbookManager.getLogbookPath(); + const QString logbookPath = persistenceManager.getLogbookPath(); QFileInfo fileInfo = QFileInfo(logbookPath); const QString logbookDirectoryPath = QDir::toNativeSeparators(fileInfo.absolutePath()); @@ -175,7 +175,7 @@ void LogbookSettingsDialog::frenchConnection() noexcept void LogbookSettingsDialog::openLogbookDirectory() noexcept { - const QString logbookPath = LogbookManager::getInstance().getLogbookPath(); + const QString logbookPath = PersistenceManager::getInstance().getLogbookPath(); const QFileInfo fileInfo = QFileInfo(logbookPath); const QUrl url = QUrl::fromLocalFile(fileInfo.absolutePath()); QDesktopServices::openUrl(url); diff --git a/src/UserInterface/src/Dialog/LogbookSettingsDialog.h b/src/UserInterface/src/Dialog/LogbookSettingsDialog.h index 75db106c3..f9c293335 100644 --- a/src/UserInterface/src/Dialog/LogbookSettingsDialog.h +++ b/src/UserInterface/src/Dialog/LogbookSettingsDialog.h @@ -36,7 +36,7 @@ namespace Ui { class LogbookSettingsDialog; } -class LogbookSettingsDialogPrivate; +struct LogbookSettingsDialogPrivate; class LogbookSettingsDialog : public QDialog { @@ -52,9 +52,8 @@ public slots: void showEvent(QShowEvent *event) noexcept override; private: - Q_DISABLE_COPY(LogbookSettingsDialog) std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/Dialog/SimulationVariablesDialog.cpp b/src/UserInterface/src/Dialog/SimulationVariablesDialog.cpp index ea4c4ec48..38670b807 100644 --- a/src/UserInterface/src/Dialog/SimulationVariablesDialog.cpp +++ b/src/UserInterface/src/Dialog/SimulationVariablesDialog.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include #include @@ -53,20 +55,15 @@ #include "SimulationVariablesDialog.h" #include "ui_SimulationVariablesDialog.h" -class SimulationVariablesDialogPrivate +struct SimulationVariablesDialogPrivate { -public: SimulationVariablesDialogPrivate() noexcept : closeDialogShortcut(nullptr) {} QShortcut *closeDialogShortcut; - - static const char WindowTitle[]; }; -const char SimulationVariablesDialogPrivate::WindowTitle[] = QT_TRANSLATE_NOOP("SimulationVariablesDialog", "Simulation Variables"); - // PUBLIC SimulationVariablesDialog::SimulationVariablesDialog(QWidget *parent) noexcept : @@ -77,17 +74,9 @@ SimulationVariablesDialog::SimulationVariablesDialog(QWidget *parent) noexcept : ui->setupUi(this); initUi(); frenchConnection(); -#ifdef DEBUG - qDebug() << "SimulationVariablesDialog::SimulationVariablesDialog: CREATED"; -#endif } -SimulationVariablesDialog::~SimulationVariablesDialog() noexcept -{ -#ifdef DEBUG - qDebug() << "SimulationVariablesDialog::~SimulationVariablesDialog: DELETED"; -#endif -} +SimulationVariablesDialog::~SimulationVariablesDialog() = default; // PROTECTED @@ -119,23 +108,24 @@ void SimulationVariablesDialog::initUi() noexcept { setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); - AircraftWidget *aircraftWidget = new AircraftWidget(this); - ui->simulationVariablesTab->addTab(aircraftWidget, tr("&Aircraft")); + std::unique_ptr aircraftWidget = std::make_unique(this); + // Transfer ownership to Qt + ui->simulationVariablesTab->addTab(aircraftWidget.release(), tr("&Aircraft")); - EngineWidget *engineWidget = new EngineWidget(this); - ui->simulationVariablesTab->addTab(engineWidget, tr("&Engine")); + std::unique_ptr engineWidget = std::make_unique(this); + ui->simulationVariablesTab->addTab(engineWidget.release(), tr("&Engine")); - PrimaryFlightControlWidget *primaryFlightControlWidget = new PrimaryFlightControlWidget(this); - ui->simulationVariablesTab->addTab(primaryFlightControlWidget, tr("&Primary Controls")); + std::unique_ptr primaryFlightControlWidget = std::make_unique(this); + ui->simulationVariablesTab->addTab(primaryFlightControlWidget.release(), tr("&Primary Controls")); - SecondaryFlightControlWidget *secondaryFlightControlWidget = new SecondaryFlightControlWidget(this); - ui->simulationVariablesTab->addTab(secondaryFlightControlWidget, tr("&Secondary Controls")); + std::unique_ptr secondaryFlightControlWidget = std::make_unique(this); + ui->simulationVariablesTab->addTab(secondaryFlightControlWidget.release(), tr("&Secondary Controls")); - AircraftHandleWidget *aircraftHandleWidget = new AircraftHandleWidget(this); - ui->simulationVariablesTab->addTab(aircraftHandleWidget, tr("&Handles && Brakes")); + std::unique_ptr aircraftHandleWidget = std::make_unique(this); + ui->simulationVariablesTab->addTab(aircraftHandleWidget.release(), tr("&Handles && Brakes")); - LightWidget *lightWidget = new LightWidget(this); - ui->simulationVariablesTab->addTab(lightWidget, tr("&Lights")); + std::unique_ptr lightWidget = std::make_unique(this); + ui->simulationVariablesTab->addTab(lightWidget.release(), tr("&Lights")); d->closeDialogShortcut = new QShortcut(QKeySequence(tr("V", "Window|Simulation Variables...")), this); } @@ -155,27 +145,27 @@ void SimulationVariablesDialog::frenchConnection() noexcept void SimulationVariablesDialog::updateTitle() noexcept { - QString windowTitle = QCoreApplication::translate("SimulationVariablesDialog", SimulationVariablesDialogPrivate::WindowTitle); + QString windowTitle = tr("Simulation Variables"); const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); const Connect::State state = skyConnect ? skyConnect->get().getState() : Connect::State::Disconnected; switch (state) { case Connect::State::Disconnected: - windowTitle.append(" - " + tr("DISCONNECTED")); + windowTitle.append(" - " % tr("DISCONNECTED")); break; case Connect::State::Connected: - windowTitle.append(" - " + tr("CONNECTED")); + windowTitle.append(" - " % tr("CONNECTED")); break; case Connect::State::Recording: - windowTitle.append(" - " + tr("RECORDING")); + windowTitle.append(" - " % tr("RECORDING")); break; case Connect::State::RecordingPaused: - windowTitle.append(" - " + tr("RECORDING PAUSED")); + windowTitle.append(" - " % tr("RECORDING PAUSED")); break; case Connect::State::Replay: - windowTitle.append(" - " + tr("PLAYBACK")); + windowTitle.append(" - " % tr("PLAYBACK")); break; case Connect::State::ReplayPaused: - windowTitle.append(" - " + tr("PLAYPACK PAUSED")); + windowTitle.append(" - " % tr("PLAYPACK PAUSED")); break; } setWindowTitle(windowTitle); diff --git a/src/UserInterface/src/Dialog/SimulationVariablesDialog.h b/src/UserInterface/src/Dialog/SimulationVariablesDialog.h index 0fa40d584..a9572bbae 100644 --- a/src/UserInterface/src/Dialog/SimulationVariablesDialog.h +++ b/src/UserInterface/src/Dialog/SimulationVariablesDialog.h @@ -32,7 +32,7 @@ class QShowEvent; class QHideEvent; -class SimulationVariablesDialogPrivate; +struct SimulationVariablesDialogPrivate; namespace Ui { class SimulationVariablesDialog; @@ -43,19 +43,18 @@ class SimulationVariablesDialog : public QDialog Q_OBJECT public: explicit SimulationVariablesDialog(QWidget *parent = nullptr) noexcept; - virtual ~SimulationVariablesDialog() noexcept; + ~SimulationVariablesDialog() override; signals: void visibilityChanged(bool visible); protected: - virtual void showEvent(QShowEvent *event) noexcept override; - virtual void hideEvent(QHideEvent *event) noexcept override; + void showEvent(QShowEvent *event) noexcept override; + void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(SimulationVariablesDialog) std::unique_ptr d; - std::unique_ptr ui; + const std::unique_ptr ui; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/Dialog/StatisticsDialog.cpp b/src/UserInterface/src/Dialog/StatisticsDialog.cpp index 0edfced57..a8dce7753 100644 --- a/src/UserInterface/src/Dialog/StatisticsDialog.cpp +++ b/src/UserInterface/src/Dialog/StatisticsDialog.cpp @@ -58,9 +58,8 @@ #include "StatisticsDialog.h" #include "ui_StatisticsDialog.h" -class StatisticsDialogPrivate +struct StatisticsDialogPrivate { -public: StatisticsDialogPrivate() noexcept : closeDialogShortcut(nullptr) {} @@ -79,17 +78,9 @@ StatisticsDialog::StatisticsDialog(QWidget *parent) noexcept : ui->setupUi(this); initUi(); frenchConnection(); -#ifdef DEBUG - qDebug() << "StatisticsDialog::StatisticsDialog: CREATED"; -#endif } -StatisticsDialog::~StatisticsDialog() noexcept -{ -#ifdef DEBUG - qDebug() << "StatisticsDialog::~StatisticsDialog: DELETED"; -#endif -} +StatisticsDialog::~StatisticsDialog() = default; // PROTECTED @@ -145,7 +136,6 @@ void StatisticsDialog::frenchConnection() noexcept void StatisticsDialog::updateRecordingSampleRate() noexcept { - const Flight &flight = Logbook::getInstance().getCurrentFlight(); if (Settings::getInstance().getRecordingSampleRate() != SampleRate::SampleRate::Auto) { ui->recordingSampleRateLineEdit->setText(d->unit.formatHz(Settings::getInstance().getRecordingSampleRateValue())); } else { @@ -175,12 +165,12 @@ void StatisticsDialog::updateRecordUi(std::int64_t timestamp) noexcept std::int64_t totalCount = 0; std::int64_t totalSize = 0; for (const auto &aircraft : flight) { - const int positionDataCount = aircraft->getPosition().count(); - const int engineDataCount = aircraft->getEngine().count(); - const int primaryFlightControlDataCount = aircraft->getPrimaryFlightControl().count(); - const int secondaryFlightControlDataCount = aircraft->getSecondaryFlightControl().count(); - const int aircraftHandleDataCount = aircraft->getAircraftHandle().count(); - const int lightDataCount = aircraft->getLight().count(); + const int positionDataCount = aircraft.getPosition().count(); + const int engineDataCount = aircraft.getEngine().count(); + const int primaryFlightControlDataCount = aircraft.getPrimaryFlightControl().count(); + const int secondaryFlightControlDataCount = aircraft.getSecondaryFlightControl().count(); + const int aircraftHandleDataCount = aircraft.getAircraftHandle().count(); + const int lightDataCount = aircraft.getLight().count(); totalCount = totalCount + positionDataCount + engineDataCount + primaryFlightControlDataCount + secondaryFlightControlDataCount + aircraftHandleDataCount + lightDataCount; const std::int64_t positionDataSize = positionDataCount * sizeof(PositionData); diff --git a/src/UserInterface/src/Dialog/StatisticsDialog.h b/src/UserInterface/src/Dialog/StatisticsDialog.h index 86b85ae2d..692649729 100644 --- a/src/UserInterface/src/Dialog/StatisticsDialog.h +++ b/src/UserInterface/src/Dialog/StatisticsDialog.h @@ -33,7 +33,7 @@ class QShowEvent; class QHideEvent; -class StatisticsDialogPrivate; +struct StatisticsDialogPrivate; namespace Ui { class StatisticsDialog; @@ -44,7 +44,7 @@ class StatisticsDialog : public QDialog Q_OBJECT public: explicit StatisticsDialog(QWidget *parent = nullptr) noexcept; - ~StatisticsDialog() noexcept override; + ~StatisticsDialog() override; signals: void visibilityChanged(bool visible); @@ -54,9 +54,8 @@ class StatisticsDialog : public QDialog void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(StatisticsDialog) std::unique_ptr d; - std::unique_ptr ui; + const std::unique_ptr ui; void initUi() noexcept; void updateUi() noexcept; diff --git a/src/UserInterface/src/MainWindow.cpp b/src/UserInterface/src/MainWindow.cpp index 10ffd989f..830e73d8e 100644 --- a/src/UserInterface/src/MainWindow.cpp +++ b/src/UserInterface/src/MainWindow.cpp @@ -73,7 +73,8 @@ #include #include #include -#include +#include +#include "Persistence/Metadata.h" #include #include #include @@ -127,9 +128,8 @@ namespace }; } -class MainWindowPrivate +struct MainWindowPrivate { -public: MainWindowPrivate() noexcept : previousState(Connect::State::Connected), connectedWithLogbook(false), @@ -213,13 +213,13 @@ MainWindow::MainWindow(const QString &filePath, QWidget *parent) noexcept MainWindow::~MainWindow() noexcept { #ifdef DEBUG - qDebug("MainWindow::~MainWindow: DELETED"); + qDebug() << "MainWindow::~MainWindow: DELETED"; #endif } bool MainWindow::connectWithLogbook(const QString &filePath) noexcept { - bool ok = LogbookManager::getInstance().connectWithLogbook(filePath, this); + bool ok = PersistenceManager::getInstance().connectWithLogbook(filePath, this); if (!ok) { QMessageBox::critical(this, tr("Logbook error"), tr("The logbook %1 could not be opened.").arg(QDir::toNativeSeparators(filePath))); } @@ -239,8 +239,9 @@ void MainWindow::closeEvent(QCloseEvent *event) noexcept { QMainWindow::closeEvent(event); - Metadata metaData; - if (LogbookManager::getInstance().getMetadata(metaData)) { + bool ok {true}; + const Metadata metaData = PersistenceManager::getInstance().getMetadata(&ok); + if (ok) { if (QDateTime::currentDateTime() > metaData.nextBackupDate) { std::unique_ptr backupDialog = std::make_unique(this); backupDialog->exec(); @@ -293,7 +294,7 @@ void MainWindow::frenchConnection() noexcept this, &MainWindow::onReplayLoopChanged); // Logbook connection - connect(&LogbookManager::getInstance(), &LogbookManager::connectionChanged, + connect(&PersistenceManager::getInstance(), &PersistenceManager::connectionChanged, this, &MainWindow::onLogbookConnectionChanged); // Ui elements @@ -1118,7 +1119,7 @@ void MainWindow::onTimestampChanged(std::int64_t timestamp) noexcept void MainWindow::onReplaySpeedSelected(QAction *action) noexcept { ReplaySpeed replaySpeed = static_cast(action->property(ReplaySpeedProperty).toInt()); - double replaySpeedFactor; + double replaySpeedFactor {1.0}; switch (replaySpeed) { case ReplaySpeed::Slow10: replaySpeedFactor = 0.1; @@ -1422,7 +1423,7 @@ void MainWindow::createNewLogbook() noexcept { const QString logbookPath = DatabaseService::getNewLogbookPath(this); if (!logbookPath.isNull()) { - const bool ok = LogbookManager::getInstance().connectWithLogbook(logbookPath, this); + const bool ok = PersistenceManager::getInstance().connectWithLogbook(logbookPath, this); if (!ok) { QMessageBox::critical(this, tr("Logbook error"), tr("The logbook %1 could not be created.").arg(QDir::toNativeSeparators(logbookPath))); } @@ -1439,8 +1440,8 @@ void MainWindow::openLogbook() noexcept void MainWindow::optimiseLogbook() noexcept { - LogbookManager &logbookManager = LogbookManager::getInstance(); - QString logbookPath = logbookManager.getLogbookPath(); + PersistenceManager &persistenceManager = PersistenceManager::getInstance(); + QString logbookPath = persistenceManager.getLogbookPath(); QFileInfo fileInfo = QFileInfo(logbookPath); std::unique_ptr messageBox = std::make_unique(this); @@ -1457,7 +1458,7 @@ void MainWindow::optimiseLogbook() noexcept const QAbstractButton *clickedButton = messageBox->clickedButton(); if (clickedButton == optimiseButton) { QGuiApplication::setOverrideCursor(Qt::WaitCursor); - const bool ok = LogbookManager::getInstance().optimise(); + const bool ok = persistenceManager.optimise(); QGuiApplication::restoreOverrideCursor(); if (ok) { fileInfo.refresh(); diff --git a/src/UserInterface/src/Widget/AbstractSimulationVariableWidget.h b/src/UserInterface/src/Widget/AbstractSimulationVariableWidget.h index 2b7158367..17102a253 100644 --- a/src/UserInterface/src/Widget/AbstractSimulationVariableWidget.h +++ b/src/UserInterface/src/Widget/AbstractSimulationVariableWidget.h @@ -48,9 +48,6 @@ class AbstractSimulationVariableWidget : public QWidget protected slots: virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept = 0; -private: - Q_DISABLE_COPY(AbstractSimulationVariableWidget) - private slots: void updateUiWithCurrentTime() noexcept; }; diff --git a/src/UserInterface/src/Widget/AircraftHandleWidget.cpp b/src/UserInterface/src/Widget/AircraftHandleWidget.cpp index 9d16cf9a6..7b6616cb4 100644 --- a/src/UserInterface/src/Widget/AircraftHandleWidget.cpp +++ b/src/UserInterface/src/Widget/AircraftHandleWidget.cpp @@ -44,9 +44,8 @@ #include "AircraftHandleWidget.h" #include "ui_AircraftHandleWidget.h" -class AircraftHandleWidgetPrivate +struct AircraftHandleWidgetPrivate { -public: AircraftHandleWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -61,8 +60,8 @@ class AircraftHandleWidgetPrivate AircraftHandleWidget::AircraftHandleWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -86,8 +85,9 @@ void AircraftHandleWidget::initUi() noexcept ui->rightWingFoldingLineEdit->setToolTip(SimVar::FoldingWingRightPercent); } -const AircraftHandleData &AircraftHandleWidget::getCurrentAircraftHandleData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +AircraftHandleData AircraftHandleWidget::getCurrentAircraftHandleData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { + AircraftHandleData aircraftHandleData; const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { @@ -95,14 +95,13 @@ const AircraftHandleData &AircraftHandleWidget::getCurrentAircraftHandleData(std return aircraft.getAircraftHandle().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getAircraftHandle().interpolate(timestamp, access); + aircraftHandleData = aircraft.getAircraftHandle().interpolate(timestamp, access); } else { - return aircraft.getAircraftHandle().interpolate(skyConnect->get().getCurrentTimestamp(), access); + aircraftHandleData = aircraft.getAircraftHandle().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return AircraftHandleData::NullData; } + return aircraftHandleData; } // PRIVATE SLOTS diff --git a/src/UserInterface/src/Widget/AircraftHandleWidget.h b/src/UserInterface/src/Widget/AircraftHandleWidget.h index dbc79d93f..ae0a2aefd 100644 --- a/src/UserInterface/src/Widget/AircraftHandleWidget.h +++ b/src/UserInterface/src/Widget/AircraftHandleWidget.h @@ -35,10 +35,9 @@ class QHideEvent; #include #include "AbstractSimulationVariableWidget.h" - class SkyConnectIntf; struct AircraftHandleData; -class AircraftHandleWidgetPrivate; +struct AircraftHandleWidgetPrivate; namespace Ui { class AircraftHandleWidget; @@ -49,17 +48,17 @@ class AircraftHandleWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit AircraftHandleWidget(QWidget *parent) noexcept; - virtual ~AircraftHandleWidget() noexcept; + ~AircraftHandleWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; - const AircraftHandleData &getCurrentAircraftHandleData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + AircraftHandleData getCurrentAircraftHandleData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // AIRCRAFTHANDLEWIDGET_H diff --git a/src/UserInterface/src/Widget/AircraftInfoWidget.cpp b/src/UserInterface/src/Widget/AircraftInfoWidget.cpp index c705ad987..afe6a062b 100644 --- a/src/UserInterface/src/Widget/AircraftInfoWidget.cpp +++ b/src/UserInterface/src/Widget/AircraftInfoWidget.cpp @@ -38,9 +38,8 @@ #include "AircraftInfoWidget.h" #include "ui_AircraftInfoWidget.h" -class AircraftInfoWidgetPrivate +struct AircraftInfoWidgetPrivate { -public: AircraftInfoWidgetPrivate() noexcept {} @@ -51,8 +50,8 @@ class AircraftInfoWidgetPrivate AircraftInfoWidget::AircraftInfoWidget(QWidget *parent) noexcept : QWidget(parent), - d(std::make_unique()), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique()) { ui->setupUi(this); initUi(); @@ -69,22 +68,28 @@ void AircraftInfoWidget::showEvent(QShowEvent *event) noexcept updateUi(); const Flight &flight = Logbook::getInstance().getCurrentFlight(); - const Aircraft &aircraft = flight.getUserAircraft(); - connect(&aircraft, &Aircraft::infoChanged, + connect(&flight, &Flight::infoChanged, this, &AircraftInfoWidget::updateUi); connect(&flight, &Flight::userAircraftChanged, this, &AircraftInfoWidget::updateUi); + connect(&flight, &Flight::flightStored, + this, &AircraftInfoWidget::updateUi); + connect(&flight, &Flight::flightRestored, + this, &AircraftInfoWidget::updateUi); } void AircraftInfoWidget::hideEvent(QHideEvent *event) noexcept { QWidget::hideEvent(event); const Flight &flight = Logbook::getInstance().getCurrentFlight(); - const Aircraft &aircraft = flight.getUserAircraft(); - disconnect(&aircraft, &Aircraft::infoChanged, - this, &AircraftInfoWidget::updateUi); + disconnect(&flight, &Flight::infoChanged, + this, &AircraftInfoWidget::updateUi); disconnect(&flight, &Flight::userAircraftChanged, this, &AircraftInfoWidget::updateUi); + disconnect(&flight, &Flight::flightStored, + this, &AircraftInfoWidget::updateUi); + disconnect(&flight, &Flight::flightRestored, + this, &AircraftInfoWidget::updateUi); } // PRIVATE diff --git a/src/UserInterface/src/Widget/AircraftInfoWidget.h b/src/UserInterface/src/Widget/AircraftInfoWidget.h index b08fd2ac7..66e56b3f3 100644 --- a/src/UserInterface/src/Widget/AircraftInfoWidget.h +++ b/src/UserInterface/src/Widget/AircraftInfoWidget.h @@ -32,8 +32,8 @@ class QShowEvent; class QHideEvent; -class AircraftInfoWidgetPrivate; struct PositionData; +struct AircraftInfoWidgetPrivate; namespace Ui { class AircraftInfoWidget; @@ -51,9 +51,8 @@ class AircraftInfoWidget : public QWidget void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(AircraftInfoWidget) - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; diff --git a/src/UserInterface/src/Widget/AircraftWidget.cpp b/src/UserInterface/src/Widget/AircraftWidget.cpp index 73324e93a..280c5d65f 100644 --- a/src/UserInterface/src/Widget/AircraftWidget.cpp +++ b/src/UserInterface/src/Widget/AircraftWidget.cpp @@ -41,9 +41,8 @@ #include "AircraftWidget.h" #include "ui_AircraftWidget.h" -class AircraftWidgetPrivate +struct AircraftWidgetPrivate { -public: AircraftWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -58,8 +57,8 @@ class AircraftWidgetPrivate AircraftWidget::AircraftWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -143,8 +142,9 @@ void AircraftWidget::initUi() noexcept ui->rotationVelocityZLineEdit->setToolTip(SimVar::RotationVelocityBodyZ); } -const PositionData &AircraftWidget::getCurrentPositionData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +PositionData AircraftWidget::getCurrentPositionData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { + PositionData positionData; const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { @@ -152,12 +152,11 @@ const PositionData &AircraftWidget::getCurrentPositionData(std::int64_t timestam return aircraft.getPosition().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getPosition().interpolate(timestamp, access); + positionData = aircraft.getPosition().interpolate(timestamp, access); } else { - return aircraft.getPosition().interpolate(skyConnect->get().getCurrentTimestamp(), access); + positionData = aircraft.getPosition().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return PositionData::NullData; } + return positionData; } diff --git a/src/UserInterface/src/Widget/AircraftWidget.h b/src/UserInterface/src/Widget/AircraftWidget.h index 87140972e..4a5484153 100644 --- a/src/UserInterface/src/Widget/AircraftWidget.h +++ b/src/UserInterface/src/Widget/AircraftWidget.h @@ -37,7 +37,7 @@ class QHideEvent; class SkyConnectIntf; struct PositionData; -class AircraftWidgetPrivate; +struct AircraftWidgetPrivate; namespace Ui { class AircraftWidget; @@ -48,17 +48,17 @@ class AircraftWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit AircraftWidget(QWidget *parent) noexcept; - virtual ~AircraftWidget() noexcept; + ~AircraftWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; - const PositionData &getCurrentPositionData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + PositionData getCurrentPositionData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // AIRCRAFTVARIABLESWIDGET_H diff --git a/src/UserInterface/src/Widget/EngineWidget.cpp b/src/UserInterface/src/Widget/EngineWidget.cpp index ad75b261f..4a045291a 100644 --- a/src/UserInterface/src/Widget/EngineWidget.cpp +++ b/src/UserInterface/src/Widget/EngineWidget.cpp @@ -44,9 +44,8 @@ #include "EngineWidget.h" #include "ui_EngineWidget.h" -class EngineWidgetPrivate +struct EngineWidgetPrivate { -public: EngineWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -61,8 +60,8 @@ class EngineWidgetPrivate EngineWidget::EngineWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -207,21 +206,21 @@ void EngineWidget::initUi() noexcept ui->generalEngineCombustion4CheckBox->setToolTip(SimVar::GeneralEngineCombustion4); } -const EngineData &EngineWidget::getCurrentEngineData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +EngineData EngineWidget::getCurrentEngineData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { + EngineData engineData; const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { if (skyConnect->get().getState() == Connect::State::Recording) { - return aircraft.getEngine().getLast(); + engineData = aircraft.getEngine().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getEngine().interpolate(timestamp, access); + engineData = aircraft.getEngine().interpolate(timestamp, access); } else { - return aircraft.getEngine().interpolate(skyConnect->get().getCurrentTimestamp(), access); + engineData = aircraft.getEngine().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return EngineData::NullData; } + return engineData; } diff --git a/src/UserInterface/src/Widget/EngineWidget.h b/src/UserInterface/src/Widget/EngineWidget.h index 3c9c7ad26..1c70d77a7 100644 --- a/src/UserInterface/src/Widget/EngineWidget.h +++ b/src/UserInterface/src/Widget/EngineWidget.h @@ -35,7 +35,7 @@ class QHideEvent; class SkyConnectIntf; struct EngineData; -class EngineWidgetPrivate; +struct EngineWidgetPrivate; namespace Ui { class EngineWidget; @@ -46,17 +46,17 @@ class EngineWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit EngineWidget(QWidget *parent) noexcept; - virtual ~EngineWidget() noexcept; + ~EngineWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; - const EngineData &getCurrentEngineData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + EngineData getCurrentEngineData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // ENGINEWIDGET_H diff --git a/src/UserInterface/src/Widget/FlightConditionWidget.cpp b/src/UserInterface/src/Widget/FlightConditionWidget.cpp index e533af8b9..dac7de66c 100644 --- a/src/UserInterface/src/Widget/FlightConditionWidget.cpp +++ b/src/UserInterface/src/Widget/FlightConditionWidget.cpp @@ -36,9 +36,8 @@ #include "FlightConditionWidget.h" #include "ui_FlightConditionWidget.h" -class FlightConditionWidgetPrivate +struct FlightConditionWidgetPrivate { -public: FlightConditionWidgetPrivate() noexcept {} @@ -49,8 +48,8 @@ class FlightConditionWidgetPrivate FlightConditionWidget::FlightConditionWidget(QWidget *parent) noexcept : QWidget(parent), - d(std::make_unique()), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique()) { ui->setupUi(this); initUi(); @@ -69,6 +68,10 @@ void FlightConditionWidget::showEvent(QShowEvent *event) noexcept const Flight &flight = Logbook::getInstance().getCurrentFlight(); connect(&flight, &Flight::flightConditionChanged, this, &FlightConditionWidget::updateUi); + connect(&flight, &Flight::flightStored, + this, &FlightConditionWidget::updateUi); + connect(&flight, &Flight::flightRestored, + this, &FlightConditionWidget::updateUi); } void FlightConditionWidget::hideEvent(QHideEvent *event) noexcept @@ -76,7 +79,11 @@ void FlightConditionWidget::hideEvent(QHideEvent *event) noexcept QWidget::hideEvent(event); const Flight &flight = Logbook::getInstance().getCurrentFlight(); disconnect(&flight, &Flight::flightConditionChanged, - this, &FlightConditionWidget::updateUi); + this, &FlightConditionWidget::updateUi); + disconnect(&flight, &Flight::flightStored, + this, &FlightConditionWidget::updateUi); + disconnect(&flight, &Flight::flightRestored, + this, &FlightConditionWidget::updateUi); } // PRIVATE diff --git a/src/UserInterface/src/Widget/FlightConditionWidget.h b/src/UserInterface/src/Widget/FlightConditionWidget.h index 145453a04..8276ad993 100644 --- a/src/UserInterface/src/Widget/FlightConditionWidget.h +++ b/src/UserInterface/src/Widget/FlightConditionWidget.h @@ -32,7 +32,7 @@ class QShowEvent; class QHideEvent; -class FlightConditionWidgetPrivate; +struct FlightConditionWidgetPrivate; namespace Ui { class FlightConditionWidget; @@ -43,16 +43,15 @@ class FlightConditionWidget : public QWidget Q_OBJECT public: explicit FlightConditionWidget(QWidget *parent = nullptr) noexcept; - virtual ~FlightConditionWidget() noexcept; + ~FlightConditionWidget() noexcept override; protected: void showEvent(QShowEvent *event) noexcept override; void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(FlightConditionWidget) - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; diff --git a/src/UserInterface/src/Widget/FlightDescriptionWidget.cpp b/src/UserInterface/src/Widget/FlightDescriptionWidget.cpp index 432d38b3b..fc2d454a5 100644 --- a/src/UserInterface/src/Widget/FlightDescriptionWidget.cpp +++ b/src/UserInterface/src/Widget/FlightDescriptionWidget.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -37,9 +38,8 @@ #include "FlightDescriptionWidget.h" #include "ui_FlightDescriptionWidget.h" -class FlightDescriptionWidgetPrivate +struct FlightDescriptionWidgetPrivate { -public: FlightDescriptionWidgetPrivate(FlightService &theFlightService) noexcept : flightService(theFlightService) {} @@ -55,8 +55,8 @@ class FlightDescriptionWidgetPrivate FlightDescriptionWidget::FlightDescriptionWidget(FlightService &flightService, QWidget *parent) : QWidget(parent), - d(std::make_unique(flightService)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(flightService)) { ui->setupUi(this); initUi(); @@ -79,6 +79,8 @@ void FlightDescriptionWidget::showEvent(QShowEvent *event) noexcept const Flight &flight = logbook.getCurrentFlight(); connect(&flight, &Flight::flightStored, this, &FlightDescriptionWidget::updateUi); + connect(&flight, &Flight::flightRestored, + this, &FlightDescriptionWidget::updateUi); } void FlightDescriptionWidget::hideEvent(QHideEvent *event) noexcept @@ -91,6 +93,8 @@ void FlightDescriptionWidget::hideEvent(QHideEvent *event) noexcept const Flight &flight = logbook.getCurrentFlight(); disconnect(&flight, &Flight::flightStored, this, &FlightDescriptionWidget::updateUi); + disconnect(&flight, &Flight::flightRestored, + this, &FlightDescriptionWidget::updateUi); } // PRIVATE @@ -112,7 +116,7 @@ void FlightDescriptionWidget::updateUi() noexcept { const Flight &flight = Logbook::getInstance().getCurrentFlight(); - bool enabled = flight.getId() != Flight::InvalidId; + bool enabled = flight.getId() != Const::InvalidId; ui->titleLineEdit->blockSignals(true); ui->focusPlainTextEdit->blockSignals(true); ui->titleLineEdit->setText(flight.getTitle()); diff --git a/src/UserInterface/src/Widget/FlightDescriptionWidget.h b/src/UserInterface/src/Widget/FlightDescriptionWidget.h index 4fede301c..5c1cfb6d2 100644 --- a/src/UserInterface/src/Widget/FlightDescriptionWidget.h +++ b/src/UserInterface/src/Widget/FlightDescriptionWidget.h @@ -33,7 +33,7 @@ class QShowEvent; class QHideEvent; class FlightService; -class FlightDescriptionWidgetPrivate; +struct FlightDescriptionWidgetPrivate; namespace Ui { class FlightDescriptionWidget; @@ -51,9 +51,8 @@ class FlightDescriptionWidget : public QWidget void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(FlightDescriptionWidget) - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; void frenchConnection() noexcept; diff --git a/src/UserInterface/src/Widget/FlightPlanWidget.cpp b/src/UserInterface/src/Widget/FlightPlanWidget.cpp index 01cf1972b..cbec4d975 100644 --- a/src/UserInterface/src/Widget/FlightPlanWidget.cpp +++ b/src/UserInterface/src/Widget/FlightPlanWidget.cpp @@ -25,6 +25,9 @@ #include #include +#ifdef DEBUG +#include +#endif #include #include @@ -37,9 +40,8 @@ #include "FlightPlanWidget.h" #include "ui_FlightPlanWidget.h" -class FlightPlanWidgetPrivate +struct FlightPlanWidgetPrivate { -public: FlightPlanWidgetPrivate() noexcept {} @@ -54,14 +56,14 @@ FlightPlanWidget::FlightPlanWidget(QWidget *parent) noexcept : { ui->setupUi(this); #ifdef DEBUG - qDebug("FlightPlanWidget::FlightPlanWidget: CREATED"); + qDebug() << "FlightPlanWidget::FlightPlanWidget: CREATED"; #endif } FlightPlanWidget::~FlightPlanWidget() noexcept { #ifdef DEBUG - qDebug("FlightPlanWidget::~FlightPlanWidget: DELETED"); + qDebug() << "FlightPlanWidget::~FlightPlanWidget: DELETED"; #endif } @@ -73,15 +75,18 @@ void FlightPlanWidget::showEvent(QShowEvent *event) noexcept updateUi(); const Flight &flight = Logbook::getInstance().getCurrentFlight(); - const FlightPlan &flightPlan = flight.getUserAircraft().getFlightPlan(); - connect(&flightPlan, &FlightPlan::waypointAdded, + connect(&flight, &Flight::waypointAdded, this, &FlightPlanWidget::addWaypoint); - connect(&flightPlan, &FlightPlan::waypointUpdated, + connect(&flight, &Flight::waypointUpdated, this, &FlightPlanWidget::updateWaypoint); - connect(&flightPlan, &FlightPlan::waypointsCleared, + connect(&flight, &Flight::waypointsCleared, this, &FlightPlanWidget::clear); connect(&flight, &Flight::userAircraftChanged, this, &FlightPlanWidget::updateUi); + connect(&flight, &Flight::flightStored, + this, &FlightPlanWidget::updateUi); + connect(&flight, &Flight::flightRestored, + this, &FlightPlanWidget::updateUi); } @@ -89,15 +94,18 @@ void FlightPlanWidget::hideEvent(QHideEvent *event) noexcept { QWidget::hideEvent(event); const Flight &flight = Logbook::getInstance().getCurrentFlight(); - const FlightPlan &flightPlan = flight.getUserAircraft().getFlightPlan(); - disconnect(&flightPlan, &FlightPlan::waypointAdded, + disconnect(&flight, &Flight::waypointAdded, this, &FlightPlanWidget::addWaypoint); - disconnect(&flightPlan, &FlightPlan::waypointUpdated, + disconnect(&flight, &Flight::waypointUpdated, this, &FlightPlanWidget::updateWaypoint); - disconnect(&flightPlan, &FlightPlan::waypointsCleared, + disconnect(&flight, &Flight::waypointsCleared, this, &FlightPlanWidget::clear); disconnect(&flight, &Flight::userAircraftChanged, this, &FlightPlanWidget::updateUi); + disconnect(&flight, &Flight::flightStored, + this, &FlightPlanWidget::updateUi); + disconnect(&flight, &Flight::flightRestored, + this, &FlightPlanWidget::updateUi); } // PRIVATE diff --git a/src/UserInterface/src/Widget/FlightPlanWidget.h b/src/UserInterface/src/Widget/FlightPlanWidget.h index fbb14d3c4..ca284623f 100644 --- a/src/UserInterface/src/Widget/FlightPlanWidget.h +++ b/src/UserInterface/src/Widget/FlightPlanWidget.h @@ -31,7 +31,7 @@ #include -class FlightPlanWidgetPrivate; +struct FlightPlanWidgetPrivate; namespace Ui { class FlightPlanWidget; @@ -42,16 +42,15 @@ class FlightPlanWidget : public QWidget Q_OBJECT public: explicit FlightPlanWidget(QWidget *parent = nullptr) noexcept; - virtual ~FlightPlanWidget() noexcept; + ~FlightPlanWidget() noexcept override; protected: void showEvent(QShowEvent *event) noexcept override; void hideEvent(QHideEvent *event) noexcept override; -private: - Q_DISABLE_COPY(FlightPlanWidget) +private: std::unique_ptr ui; - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; diff --git a/src/UserInterface/src/Widget/LightWidget.cpp b/src/UserInterface/src/Widget/LightWidget.cpp index 1ee6d1b3d..45dc48ba5 100644 --- a/src/UserInterface/src/Widget/LightWidget.cpp +++ b/src/UserInterface/src/Widget/LightWidget.cpp @@ -42,9 +42,8 @@ #include "LightWidget.h" #include "ui_LightWidget.h" -class LightWidgetPrivate +struct LightWidgetPrivate { -public: LightWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -58,8 +57,8 @@ class LightWidgetPrivate LightWidget::LightWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -109,24 +108,23 @@ void LightWidget::initUi() noexcept ui->cabinCheckBox->setFocusPolicy(Qt::NoFocus); } -const LightData &LightWidget::getCurrentLightData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +LightData LightWidget::getCurrentLightData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { - const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); LightData lightData; + const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { if (skyConnect->get().getState() == Connect::State::Recording) { return aircraft.getLight().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getLight().interpolate(timestamp, access); + lightData = aircraft.getLight().interpolate(timestamp, access); } else { - return aircraft.getLight().interpolate(skyConnect->get().getCurrentTimestamp(), access); + lightData = aircraft.getLight().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return LightData::NullData; } + return lightData; } // PRIVATE SLOTS diff --git a/src/UserInterface/src/Widget/LightWidget.h b/src/UserInterface/src/Widget/LightWidget.h index 54083b862..1f8bba9bd 100644 --- a/src/UserInterface/src/Widget/LightWidget.h +++ b/src/UserInterface/src/Widget/LightWidget.h @@ -37,7 +37,7 @@ class QHideEvent; class SkyConnectIntf; struct LightData; -class LightWidgetPrivate; +struct LightWidgetPrivate; namespace Ui { class LightWidget; @@ -48,17 +48,17 @@ class LightWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit LightWidget(QWidget *parent) noexcept; - virtual ~LightWidget() noexcept; + ~LightWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; - const LightData &getCurrentLightData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + LightData getCurrentLightData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // LIGHTWIDGET_H diff --git a/src/UserInterface/src/Widget/PrimaryFlightControlWidget.cpp b/src/UserInterface/src/Widget/PrimaryFlightControlWidget.cpp index beb5a464b..55ad9de6a 100644 --- a/src/UserInterface/src/Widget/PrimaryFlightControlWidget.cpp +++ b/src/UserInterface/src/Widget/PrimaryFlightControlWidget.cpp @@ -44,9 +44,8 @@ #include "PrimaryFlightControlWidget.h" #include "ui_PrimaryFlightControlWidget.h" -class PrimaryFlightControlWidgetPrivate +struct PrimaryFlightControlWidgetPrivate { -public: PrimaryFlightControlWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -61,8 +60,8 @@ class PrimaryFlightControlWidgetPrivate PrimaryFlightControlWidget::PrimaryFlightControlWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -103,22 +102,21 @@ void PrimaryFlightControlWidget::initUi() ui->aileronLineEdit->setToolTip(SimVar::AileronPosition); } -const PrimaryFlightControlData &PrimaryFlightControlWidget::getCurrentPrimaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +PrimaryFlightControlData PrimaryFlightControlWidget::getCurrentPrimaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { + PrimaryFlightControlData primaryFlightControlData; const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); - const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { if (skyConnect->get().getState() == Connect::State::Recording) { return aircraft.getPrimaryFlightControl().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getPrimaryFlightControl().interpolate(timestamp, access); + primaryFlightControlData = aircraft.getPrimaryFlightControl().interpolate(timestamp, access); } else { - return aircraft.getPrimaryFlightControl().interpolate(skyConnect->get().getCurrentTimestamp(), access); + primaryFlightControlData = aircraft.getPrimaryFlightControl().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return PrimaryFlightControlData::NullData; } + return primaryFlightControlData; } diff --git a/src/UserInterface/src/Widget/PrimaryFlightControlWidget.h b/src/UserInterface/src/Widget/PrimaryFlightControlWidget.h index 7f5915847..c2c562c4d 100644 --- a/src/UserInterface/src/Widget/PrimaryFlightControlWidget.h +++ b/src/UserInterface/src/Widget/PrimaryFlightControlWidget.h @@ -37,7 +37,7 @@ class QHideEvent; class SkyConnectIntf; struct PrimaryFlightControlData; -class PrimaryFlightControlWidgetPrivate; +struct PrimaryFlightControlWidgetPrivate; namespace Ui { class PrimaryFlightControlWidget; @@ -48,17 +48,17 @@ class PrimaryFlightControlWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit PrimaryFlightControlWidget(QWidget *parent) noexcept; - virtual ~PrimaryFlightControlWidget() noexcept; + ~PrimaryFlightControlWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi(); - const PrimaryFlightControlData &getCurrentPrimaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + PrimaryFlightControlData getCurrentPrimaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // PRIMARYFLIGHTCONTROLWIDGET_H diff --git a/src/UserInterface/src/Widget/SecondaryFlightControlWidget.cpp b/src/UserInterface/src/Widget/SecondaryFlightControlWidget.cpp index 93a949695..7cedfdbd6 100644 --- a/src/UserInterface/src/Widget/SecondaryFlightControlWidget.cpp +++ b/src/UserInterface/src/Widget/SecondaryFlightControlWidget.cpp @@ -44,9 +44,8 @@ #include "SecondaryFlightControlWidget.h" #include "ui_SecondaryFlightControlWidget.h" -class SecondaryFlightControlWidgetPrivate +struct SecondaryFlightControlWidgetPrivate { -public: SecondaryFlightControlWidgetPrivate(const QWidget &widget) noexcept : ActiveTextColor(widget.palette().color(QPalette::Active, QPalette::WindowText)), DisabledTextColor(widget.palette().color(QPalette::Disabled, QPalette::WindowText)) @@ -61,8 +60,8 @@ class SecondaryFlightControlWidgetPrivate SecondaryFlightControlWidget::SecondaryFlightControlWidget(QWidget *parent) noexcept : AbstractSimulationVariableWidget(parent), - d(std::make_unique(*this)), - ui(std::make_unique()) + ui(std::make_unique()), + d(std::make_unique(*this)) { ui->setupUi(this); initUi(); @@ -113,22 +112,21 @@ void SecondaryFlightControlWidget::initUi() noexcept ui->spoilerLineEdit->setToolTip(SimVar::SpoilersHandlePosition); } -const SecondaryFlightControlData &SecondaryFlightControlWidget::getCurrentSecondaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept +SecondaryFlightControlData SecondaryFlightControlWidget::getCurrentSecondaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept { + SecondaryFlightControlData secondaryFlightControlData; const Aircraft &aircraft = Logbook::getInstance().getCurrentFlight().getUserAircraft(); - const std::optional> skyConnect = SkyConnectManager::getInstance().getCurrentSkyConnect(); if (skyConnect) { if (skyConnect->get().getState() == Connect::State::Recording) { return aircraft.getSecondaryFlightControl().getLast(); } else { if (timestamp != TimeVariableData::InvalidTime) { - return aircraft.getSecondaryFlightControl().interpolate(timestamp, access); + secondaryFlightControlData = aircraft.getSecondaryFlightControl().interpolate(timestamp, access); } else { - return aircraft.getSecondaryFlightControl().interpolate(skyConnect->get().getCurrentTimestamp(), access); + secondaryFlightControlData = aircraft.getSecondaryFlightControl().interpolate(skyConnect->get().getCurrentTimestamp(), access); } }; - } else { - return SecondaryFlightControlData::NullData; } + return secondaryFlightControlData; } diff --git a/src/UserInterface/src/Widget/SecondaryFlightControlWidget.h b/src/UserInterface/src/Widget/SecondaryFlightControlWidget.h index f8951e1ef..77b8b4602 100644 --- a/src/UserInterface/src/Widget/SecondaryFlightControlWidget.h +++ b/src/UserInterface/src/Widget/SecondaryFlightControlWidget.h @@ -37,7 +37,7 @@ class QHideEvent; class SkyConnectIntf; struct SecondaryFlightControlData; -class SecondaryFlightControlWidgetPrivate; +struct SecondaryFlightControlWidgetPrivate; namespace Ui { class SecondaryFlightControlWidget; @@ -48,17 +48,17 @@ class SecondaryFlightControlWidget : public AbstractSimulationVariableWidget Q_OBJECT public: explicit SecondaryFlightControlWidget(QWidget *parent) noexcept; - virtual ~SecondaryFlightControlWidget() noexcept; + ~SecondaryFlightControlWidget() noexcept override; protected slots: - virtual void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; + void updateUi(std::int64_t timestamp, TimeVariableData::Access access) noexcept override; private: - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; - const SecondaryFlightControlData &getCurrentSecondaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; + SecondaryFlightControlData getCurrentSecondaryFlightControlData(std::int64_t timestamp, TimeVariableData::Access access) const noexcept; }; #endif // SECONDARYFLIGHTCONTROLWIDGET_H diff --git a/src/UserInterface/src/Widget/WaypointWidget.cpp b/src/UserInterface/src/Widget/WaypointWidget.cpp index 1955ccd6c..f0e16b1bf 100644 --- a/src/UserInterface/src/Widget/WaypointWidget.cpp +++ b/src/UserInterface/src/Widget/WaypointWidget.cpp @@ -24,15 +24,18 @@ */ #include +#ifdef DEBUG +#include +#endif + #include #include #include #include "WaypointWidget.h" #include "ui_WaypointWidget.h" -class WaypointWidgetPrivate +struct WaypointWidgetPrivate { -public: WaypointWidgetPrivate(const Waypoint &theWaypoint) noexcept : waypoint(theWaypoint) {} @@ -50,12 +53,15 @@ WaypointWidget::WaypointWidget(const Waypoint &waypoint, QWidget *parent) noexce { ui->setupUi(this); initUi(); +#ifdef DEBUG + qDebug() << "WaypointWidget::WaypointWidget(): CREATED"; +#endif } WaypointWidget::~WaypointWidget() noexcept { #ifdef DEBUG - qDebug("WaypointWidget::~WaypointWidget(): DELETED"); + qDebug() << "WaypointWidget::~WaypointWidget(): DELETED"; #endif } diff --git a/src/UserInterface/src/Widget/WaypointWidget.h b/src/UserInterface/src/Widget/WaypointWidget.h index 665a43dca..615ec2f85 100644 --- a/src/UserInterface/src/Widget/WaypointWidget.h +++ b/src/UserInterface/src/Widget/WaypointWidget.h @@ -32,8 +32,8 @@ class QShowEvent; class QHideEvent; -class Waypoint; -class WaypointWidgetPrivate; +struct Waypoint; +struct WaypointWidgetPrivate; namespace Ui { class WaypointWidget; @@ -45,7 +45,7 @@ class WaypointWidget : public QWidget public: explicit WaypointWidget(const Waypoint &data, QWidget *parent = nullptr) noexcept; - virtual ~WaypointWidget() noexcept; + ~WaypointWidget() noexcept override; void update(const Waypoint &waypoint) noexcept; @@ -54,9 +54,8 @@ class WaypointWidget : public QWidget void hideEvent(QHideEvent *event) noexcept override; private: - Q_DISABLE_COPY(WaypointWidget) - std::unique_ptr d; std::unique_ptr ui; + const std::unique_ptr d; void initUi() noexcept; diff --git a/src/Widget/include/Widget/ActionButton.h b/src/Widget/include/Widget/ActionButton.h index d9c1a4b4c..00f3a8889 100644 --- a/src/Widget/include/Widget/ActionButton.h +++ b/src/Widget/include/Widget/ActionButton.h @@ -77,8 +77,7 @@ class WIDGET_API ActionButton : public ActiveButton void setShowText(bool enable) noexcept; private: - Q_DISABLE_COPY(ActionButton) - std::unique_ptr d; + const std::unique_ptr d; private slots: diff --git a/src/Widget/include/Widget/ActionCheckBox.h b/src/Widget/include/Widget/ActionCheckBox.h index 1b942e90f..32fa01523 100644 --- a/src/Widget/include/Widget/ActionCheckBox.h +++ b/src/Widget/include/Widget/ActionCheckBox.h @@ -32,7 +32,7 @@ #include "WidgetLib.h" -class ActionCheckBoxPrivate; +struct ActionCheckBoxPrivate; /*! * An extension of a QRadioButton that supports QAction. @@ -50,7 +50,7 @@ class WIDGET_API ActionCheckBox : public QCheckBox Q_OBJECT public: explicit ActionCheckBox(bool withText, QWidget *parent = nullptr) noexcept; - virtual ~ActionCheckBox() noexcept; + ~ActionCheckBox() noexcept override; /*! * Sets the action to be associated with this radio button. This radio button is @@ -64,8 +64,7 @@ class WIDGET_API ActionCheckBox : public QCheckBox void setAction(const QAction *action) noexcept; private: - Q_DISABLE_COPY(ActionCheckBox) - std::unique_ptr d; + const std::unique_ptr d; private slots: diff --git a/src/Widget/include/Widget/ActionRadioButton.h b/src/Widget/include/Widget/ActionRadioButton.h index 39d7fa57d..e892105bc 100644 --- a/src/Widget/include/Widget/ActionRadioButton.h +++ b/src/Widget/include/Widget/ActionRadioButton.h @@ -32,7 +32,7 @@ #include "WidgetLib.h" -class ActionRadioButtonPrivate; +struct ActionRadioButtonPrivate; /*! * An extension of a QRadioButton that supports QAction. @@ -50,7 +50,7 @@ class WIDGET_API ActionRadioButton : public QRadioButton Q_OBJECT public: explicit ActionRadioButton(QWidget *parent = nullptr) noexcept; - virtual ~ActionRadioButton() noexcept; + ~ActionRadioButton() noexcept override; /*! * Sets the action to be associated with this radio button. This radio button is @@ -64,8 +64,7 @@ class WIDGET_API ActionRadioButton : public QRadioButton void setAction(const QAction *action) noexcept; private: - Q_DISABLE_COPY(ActionRadioButton) - std::unique_ptr d; + const std::unique_ptr d; private slots: diff --git a/src/Widget/include/Widget/ActiveButton.h b/src/Widget/include/Widget/ActiveButton.h index 38a888901..5168daf84 100644 --- a/src/Widget/include/Widget/ActiveButton.h +++ b/src/Widget/include/Widget/ActiveButton.h @@ -34,6 +34,8 @@ class QIcon; #include "WidgetLib.h" +struct ActiveButtonPrivate; + /*! * Displays the \e active icon when the button is pressed. * @@ -42,8 +44,6 @@ class QIcon; * to: * https://stackoverflow.com/questions/40318759/change-qpushbutton-icon-on-hover-and-pressed */ -class ActiveButtonPrivate; - class WIDGET_API ActiveButton : public QPushButton { Q_OBJECT @@ -56,7 +56,7 @@ class WIDGET_API ActiveButton : public QPushButton void mouseReleaseEvent(QMouseEvent *e) noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // ACTIVEBUTTON_H diff --git a/src/Widget/include/Widget/AircraftSelectionComboBox.h b/src/Widget/include/Widget/AircraftSelectionComboBox.h index 837ad5c3f..b99f3ff88 100644 --- a/src/Widget/include/Widget/AircraftSelectionComboBox.h +++ b/src/Widget/include/Widget/AircraftSelectionComboBox.h @@ -33,17 +33,17 @@ class QWidget; #include "WidgetLib.h" -class AircraftSelectionComboBoxPrivate; +struct AircraftSelectionComboBoxPrivate; class WIDGET_API AircraftSelectionComboBox : public QComboBox { Q_OBJECT public: AircraftSelectionComboBox(QWidget *parent = nullptr) noexcept; - virtual ~AircraftSelectionComboBox() noexcept; + ~AircraftSelectionComboBox() noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; void initialise() noexcept; }; diff --git a/src/Widget/include/Widget/BackupPeriodComboBox.h b/src/Widget/include/Widget/BackupPeriodComboBox.h index b41ca1358..fc4f432fe 100644 --- a/src/Widget/include/Widget/BackupPeriodComboBox.h +++ b/src/Widget/include/Widget/BackupPeriodComboBox.h @@ -32,7 +32,7 @@ #include "WidgetLib.h" -class BackupPeriodComboBoxPrivate; +struct BackupPeriodComboBoxPrivate; class WIDGET_API BackupPeriodComboBox : public QComboBox { @@ -55,13 +55,13 @@ class WIDGET_API BackupPeriodComboBox : public QComboBox }; BackupPeriodComboBox(QWidget *parent = nullptr, Selection selection = Selection::BackupPeriod) noexcept; - virtual ~BackupPeriodComboBox() noexcept; + ~BackupPeriodComboBox() noexcept override; Selection getSelection() const noexcept; void setSelection(Selection selection) noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; void updateUi() noexcept; }; diff --git a/src/Widget/include/Widget/EnumerationComboBox.h b/src/Widget/include/Widget/EnumerationComboBox.h index 020f82a77..fc9fd8ae2 100644 --- a/src/Widget/include/Widget/EnumerationComboBox.h +++ b/src/Widget/include/Widget/EnumerationComboBox.h @@ -45,7 +45,7 @@ class WIDGET_API EnumerationComboBox : public QComboBox void setCurrentId(std::int64_t id) noexcept; private: - std::unique_ptr d; + const std::unique_ptr d; void initUi() noexcept; }; diff --git a/src/Widget/include/Widget/TableDateItem.h b/src/Widget/include/Widget/TableDateItem.h index 8cf08b851..a2c1ae940 100644 --- a/src/Widget/include/Widget/TableDateItem.h +++ b/src/Widget/include/Widget/TableDateItem.h @@ -33,7 +33,7 @@ #include "WidgetLib.h" -class TableDateItemPrivate; +struct TableDateItemPrivate; /*! * Sortable QTableWidgetItem displaying a QDate. @@ -44,12 +44,12 @@ class WIDGET_API TableDateItem : public QTableWidgetItem { public: TableDateItem(const QString &dateString, const QDate &date) noexcept; - virtual ~TableDateItem() noexcept; + ~TableDateItem() noexcept override; - virtual bool operator<(const QTableWidgetItem &rhs) const noexcept override; + bool operator<(const QTableWidgetItem &rhs) const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // TABLEDATEITEM_H diff --git a/src/Widget/include/Widget/TableTimeItem.h b/src/Widget/include/Widget/TableTimeItem.h index fe592d99d..8ea0450ec 100644 --- a/src/Widget/include/Widget/TableTimeItem.h +++ b/src/Widget/include/Widget/TableTimeItem.h @@ -33,7 +33,7 @@ #include "WidgetLib.h" -class TableTimeItemPrivate; +struct TableTimeItemPrivate; /*! * Sortable QTableWidgetItem displaying time. @@ -44,12 +44,12 @@ class WIDGET_API TableTimeItem : public QTableWidgetItem { public: TableTimeItem(const QString &timeString, const QTime &time) noexcept; - virtual ~TableTimeItem() noexcept; + ~TableTimeItem() noexcept override; - virtual bool operator<(const QTableWidgetItem &rhs) const noexcept override; + bool operator<(const QTableWidgetItem &rhs) const noexcept override; private: - std::unique_ptr d; + const std::unique_ptr d; }; #endif // TABLETIMEITEM_H diff --git a/src/Widget/src/ActionCheckBox.cpp b/src/Widget/src/ActionCheckBox.cpp index 653ec7746..08c4d014a 100644 --- a/src/Widget/src/ActionCheckBox.cpp +++ b/src/Widget/src/ActionCheckBox.cpp @@ -27,9 +27,8 @@ #include "ActionCheckBox.h" -class ActionCheckBoxPrivate +struct ActionCheckBoxPrivate { -public: ActionCheckBoxPrivate(bool theWithText) noexcept : action(nullptr), withText(theWithText) diff --git a/src/Widget/src/ActionRadioButton.cpp b/src/Widget/src/ActionRadioButton.cpp index 45bf5667d..0d7a5e04c 100644 --- a/src/Widget/src/ActionRadioButton.cpp +++ b/src/Widget/src/ActionRadioButton.cpp @@ -27,9 +27,8 @@ #include "ActionRadioButton.h" -class ActionRadioButtonPrivate +struct ActionRadioButtonPrivate { -public: ActionRadioButtonPrivate() noexcept : action(nullptr) {} diff --git a/src/Widget/src/ActiveButton.cpp b/src/Widget/src/ActiveButton.cpp index 466f7ae31..7c852c3df 100644 --- a/src/Widget/src/ActiveButton.cpp +++ b/src/Widget/src/ActiveButton.cpp @@ -28,9 +28,8 @@ #include "ActiveButton.h" -class ActiveButtonPrivate +struct ActiveButtonPrivate { -public: ActiveButtonPrivate() {} diff --git a/src/Widget/src/AircraftSelectionComboBox.cpp b/src/Widget/src/AircraftSelectionComboBox.cpp index 536f02a07..32fd0731d 100644 --- a/src/Widget/src/AircraftSelectionComboBox.cpp +++ b/src/Widget/src/AircraftSelectionComboBox.cpp @@ -34,9 +34,8 @@ #include #include "AircraftSelectionComboBox.h" -class AircraftSelectionComboBoxPrivate +struct AircraftSelectionComboBoxPrivate { -public: AircraftSelectionComboBoxPrivate() noexcept : aircraftTypeService(std::make_unique()) {} @@ -60,14 +59,10 @@ AircraftSelectionComboBox::~AircraftSelectionComboBox() noexcept void AircraftSelectionComboBox::initialise() noexcept { - std::vector aircraftTypes; - const bool ok = d->aircraftTypeService->getAll(std::back_inserter(aircraftTypes)); - if (ok) { - for (AircraftType &aircraftType : aircraftTypes) { - this->addItem(aircraftType.type); - } + const std::vector aircraftTypes = d->aircraftTypeService->getAll(); + for (const AircraftType &aircraftType : aircraftTypes) { + this->addItem(aircraftType.type); } - setEditable(true); setInsertPolicy(QComboBox::NoInsert); QCompleter *autoCompleter = completer(); diff --git a/src/Widget/src/BackupPeriodComboBox.cpp b/src/Widget/src/BackupPeriodComboBox.cpp index 7c77da51c..e82f6a2b2 100644 --- a/src/Widget/src/BackupPeriodComboBox.cpp +++ b/src/Widget/src/BackupPeriodComboBox.cpp @@ -29,9 +29,8 @@ #include #include "BackupPeriodComboBox.h" -class BackupPeriodComboBoxPrivate +struct BackupPeriodComboBoxPrivate { -public: BackupPeriodComboBoxPrivate(BackupPeriodComboBox::Selection theSelection) : selection(theSelection) {} diff --git a/src/Widget/src/EnumerationComboBox.cpp b/src/Widget/src/EnumerationComboBox.cpp index a73666a34..cea1d2135 100644 --- a/src/Widget/src/EnumerationComboBox.cpp +++ b/src/Widget/src/EnumerationComboBox.cpp @@ -58,7 +58,7 @@ EnumerationComboBox::EnumerationComboBox(QString enumerationName, QWidget *paren EnumerationComboBox::~ EnumerationComboBox() noexcept { #ifdef DEBUG - qDebug() << "EnumerationComboBox::~EnumerationComboBox: DELETED."; + qDebug() << "EnumerationComboBox::~EnumerationComboBox: DELETED"; #endif } @@ -82,7 +82,9 @@ void EnumerationComboBox::setCurrentId(std::int64_t id) noexcept void EnumerationComboBox::initUi() noexcept { setAutoFillBackground(true); - if (d->enumerationService.getEnumerationByName(d->enumeration)) { + bool ok {true}; + d->enumeration = d->enumerationService.getEnumerationByName(d->enumeration.getName(), &ok); + if (ok) { for (const auto &item : d->enumeration) { addItem(item.name, QVariant::fromValue(item.id)); } diff --git a/src/Widget/src/EnumerationWidgetItem.cpp b/src/Widget/src/EnumerationWidgetItem.cpp index 32cb2912f..09dacceeb 100644 --- a/src/Widget/src/EnumerationWidgetItem.cpp +++ b/src/Widget/src/EnumerationWidgetItem.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include "EnumerationWidgetItem.h" @@ -34,6 +35,7 @@ EnumerationWidgetItem::EnumerationWidgetItem(const Enumeration &enumeration) : QTableWidgetItem(QTableWidgetItem::UserType), + m_id(Const::InvalidId), m_enumeration(enumeration) {} diff --git a/src/Widget/src/TableDateItem.cpp b/src/Widget/src/TableDateItem.cpp index b54cc6a0c..6f78663af 100644 --- a/src/Widget/src/TableDateItem.cpp +++ b/src/Widget/src/TableDateItem.cpp @@ -27,9 +27,8 @@ #include #include "TableDateItem.h" -class TableDateItemPrivate +struct TableDateItemPrivate { -public: TableDateItemPrivate(const QDate &theDate) noexcept : date(theDate) {} diff --git a/src/Widget/src/TableTimeItem.cpp b/src/Widget/src/TableTimeItem.cpp index 6e128481b..328b4ad54 100644 --- a/src/Widget/src/TableTimeItem.cpp +++ b/src/Widget/src/TableTimeItem.cpp @@ -27,9 +27,8 @@ #include #include "TableTimeItem.h" -class TableTimeItemPrivate +struct TableTimeItemPrivate { -public: TableTimeItemPrivate(const QTime &theTime) noexcept : time(theTime) {} diff --git a/src/main.cpp b/src/main.cpp index d476dfdba..cdd93c15f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,7 @@ static void destroySingletons() noexcept // Destroying the settings singleton also persists the settings Settings::destroyInstance(); Logbook::destroyInstance(); - LogbookManager::destroyInstance(); + PersistenceManager::destroyInstance(); PluginManager::destroyInstance(); SkyConnectManager::destroyInstance(); }