ComplexMissionItem.cc 2.48 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10

#include "ComplexMissionItem.h"
Don Gagne's avatar
Don Gagne committed
11
#include "QGCApplication.h"
12 13
#include "QGCCorePlugin.h"
#include "QGCOptions.h"
Don Gagne's avatar
Don Gagne committed
14 15

#include <QSettings>
16

Don Gagne's avatar
Don Gagne committed
17 18
const char* ComplexMissionItem::jsonComplexItemTypeKey = "complexItemType";

Don Gagne's avatar
Don Gagne committed
19 20
const char* ComplexMissionItem::_presetSettingsKey =        "_presets";

21
ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, bool flyView, QObject* parent)
Don Gagne's avatar
Don Gagne committed
22
    : VisualMissionItem (vehicle, flyView, parent)
23
{
24

25 26
}

27 28
const ComplexMissionItem& ComplexMissionItem::operator=(const ComplexMissionItem& other)
{
29
    VisualMissionItem::operator=(other);
30 31 32

    return *this;
}
Don Gagne's avatar
Don Gagne committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

QStringList ComplexMissionItem::presetNames(void)
{
    QStringList names;

    QSettings settings;

    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    return settings.childKeys();
}

void ComplexMissionItem::loadPreset(const QString& name)
{
    Q_UNUSED(name);
    qgcApp()->showMessage(tr("This Pattern does not support Presets."));
}

void ComplexMissionItem::savePreset(const QString& name)
{
    Q_UNUSED(name);
    qgcApp()->showMessage(tr("This Pattern does not support Presets."));
}

Don Gagne's avatar
Don Gagne committed
57
void ComplexMissionItem::deletePreset(const QString& name)
Don Gagne's avatar
Don Gagne committed
58
{
59 60 61 62
    if (qgcApp()->toolbox()->corePlugin()->options()->surveyBuiltInPresetNames().contains(name)) {
        qgcApp()->showMessage(tr("'%1' is a built-in preset which cannot be deleted.").arg(name));
        return;
    }
Don Gagne's avatar
Don Gagne committed
63

64
    QSettings settings;
Don Gagne's avatar
Don Gagne committed
65 66 67 68
    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    settings.remove(name);
    emit presetNamesChanged();
Don Gagne's avatar
Don Gagne committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
}

void ComplexMissionItem::_savePresetJson(const QString& name, QJsonObject& presetObject)
{
    QSettings settings;
    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    settings.setValue(name, QJsonDocument(presetObject).toBinaryData());
    emit presetNamesChanged();
}

QJsonObject ComplexMissionItem::_loadPresetJson(const QString& name)
{
    QSettings settings;
    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    return QJsonDocument::fromBinaryData(settings.value(name).toByteArray()).object();
}