From 4be6d929a6b70f224c637a3f239242a71372ed54 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Fri, 28 Feb 2020 16:12:55 -0900 Subject: [PATCH] Added compiler switch for developers to generate survey preset default json files for use as built-in survey presets in custom builds --- src/MissionManager/ComplexMissionItem.cc | 29 ++++++++++++++++++++++++ src/MissionManager/ComplexMissionItem.h | 9 ++++++++ 2 files changed, 38 insertions(+) diff --git a/src/MissionManager/ComplexMissionItem.cc b/src/MissionManager/ComplexMissionItem.cc index c525a28b1..a53c0c27e 100644 --- a/src/MissionManager/ComplexMissionItem.cc +++ b/src/MissionManager/ComplexMissionItem.cc @@ -20,6 +20,8 @@ const char* ComplexMissionItem::_presetSettingsKey = "_presets"; ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, bool flyView, QObject* parent) : VisualMissionItem (vehicle, flyView, parent) + , _toolbox(qgcApp()->toolbox()) + , _settingsManager(_toolbox->settingsManager()) { } @@ -74,6 +76,13 @@ void ComplexMissionItem::_savePresetJson(const QString& name, QJsonObject& prese settings.beginGroup(presetsSettingsGroup()); settings.beginGroup(_presetSettingsKey); settings.setValue(name, QJsonDocument(presetObject).toBinaryData()); + + // Use this to save a survey preset as a JSON file to be included in the build + // as a built-in survey preset that cannot be deleted. + #if 0 + _saveSettingsValueAsJson(settings, name); + #endif + emit presetNamesChanged(); } @@ -84,3 +93,23 @@ QJsonObject ComplexMissionItem::_loadPresetJson(const QString& name) settings.beginGroup(_presetSettingsKey); return QJsonDocument::fromBinaryData(settings.value(name).toByteArray()).object(); } + +void ComplexMissionItem::_saveSettingsValueAsJson(const QSettings& settings, const QString& name) +{ + QString savePath = _settingsManager->appSettings()->missionSavePath(); + QDir saveDir(savePath); + + QString fileName = saveDir.absoluteFilePath(name); + fileName.append(".json"); + QFile jsonFile(fileName); + + if (!jsonFile.open(QIODevice::WriteOnly)) { + qDebug() << "Couldn't open .json file."; + } + + qDebug() << "Saving survey preset to JSON"; + QJsonObject jsonObj = QJsonDocument::fromBinaryData(settings.value(name).toByteArray()).object(); + auto jsonDoc = QJsonDocument(jsonObj); + + jsonFile.write(jsonDoc.toJson()); +} diff --git a/src/MissionManager/ComplexMissionItem.h b/src/MissionManager/ComplexMissionItem.h index 53b0ba67c..782f80b29 100644 --- a/src/MissionManager/ComplexMissionItem.h +++ b/src/MissionManager/ComplexMissionItem.h @@ -15,6 +15,10 @@ #include +#include +#include + + class ComplexMissionItem : public VisualMissionItem { Q_OBJECT @@ -82,11 +86,16 @@ protected: void _savePresetJson (const QString& name, QJsonObject& presetObject); QJsonObject _loadPresetJson (const QString& name); + void _saveSettingsValueAsJson(const QSettings& settings, const QString& name); + bool _isIncomplete = true; QMap _metaDataMap; static const char* _presetSettingsKey; + + QGCToolbox* _toolbox; + SettingsManager* _settingsManager; }; #endif -- 2.22.0