ComplexMissionItem.cc 2.22 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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 12 13
#include "QGCApplication.h"

#include <QSettings>
14

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

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

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

23 24
}

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

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

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
55
void ComplexMissionItem::deletePreset(const QString& name)
Don Gagne's avatar
Don Gagne committed
56
{
Don Gagne's avatar
Don Gagne committed
57
    QSettings settings;
Don Gagne's avatar
Don Gagne committed
58

Don Gagne's avatar
Don Gagne committed
59 60 61 62
    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    settings.remove(name);
    emit presetNamesChanged();
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
}

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();
}