Commit 4be6d929 authored by Jacob Dahl's avatar Jacob Dahl

Added compiler switch for developers to generate survey preset default json...

Added compiler switch for developers to generate survey preset default json files for use as built-in survey presets in custom builds
parent 988cd6a9
......@@ -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());
}
......@@ -15,6 +15,10 @@
#include <QSettings>
#include <QGCToolbox.h>
#include <SettingsManager.h>
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<QString, FactMetaData*> _metaDataMap;
static const char* _presetSettingsKey;
QGCToolbox* _toolbox;
SettingsManager* _settingsManager;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment