diff --git a/src/MissionManager/ComplexMissionItem.cc b/src/MissionManager/ComplexMissionItem.cc index c525a28b1b5034d633cc35d01a1622717d969e5b..a53c0c27e8ded3124cf4ad7c5d8d53d8d18b1bfe 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 53b0ba67c74187af540b5b6f61dfd97fd95bc4c1..782f80b296fe3eb70fdc9733cb0df5d11c25dd56 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