ComplexMissionItem.cc 4.26 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 19 20 21
const char* ComplexMissionItem::_presetSettingsKey =        "_presets";
const char* ComplexMissionItem::_presetNameKey =            "complexItemPresetName";
const char* ComplexMissionItem::_saveCameraInPresetKey =    "complexItemCameraSavedInPreset";
const char* ComplexMissionItem::_builtInPresetKey =         "complexItemBuiltInPreset";

22
ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, bool flyView, QObject* parent)
Don Gagne's avatar
Don Gagne committed
23 24 25
    : VisualMissionItem (vehicle, flyView, parent)
    , _cameraInPreset   (true)
    , _builtInPreset    (false)
26
{
27

28 29
}

30 31
const ComplexMissionItem& ComplexMissionItem::operator=(const ComplexMissionItem& other)
{
32
    VisualMissionItem::operator=(other);
33

Don Gagne's avatar
Don Gagne committed
34 35 36
    _currentPreset =    other._currentPreset;
    _cameraInPreset =   other._cameraInPreset;
    _builtInPreset =    other._builtInPreset;
Don Gagne's avatar
Don Gagne committed
37

38 39
    return *this;
}
Don Gagne's avatar
Don Gagne committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

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."));
}

void ComplexMissionItem::clearCurrentPreset(void)
{
    _currentPreset.clear();
    emit currentPresetChanged(_currentPreset);
}

void ComplexMissionItem::deleteCurrentPreset(void)
{
    qDebug() << "deleteCurrentPreset" << _currentPreset;
    if (!_currentPreset.isEmpty()) {
        QSettings settings;

        settings.beginGroup(presetsSettingsGroup());
        settings.beginGroup(_presetSettingsKey);
        settings.remove(_currentPreset);
        emit presetNamesChanged();

        clearCurrentPreset();
    }
}

void ComplexMissionItem::_savePresetJson(const QString& name, QJsonObject& presetObject)
{
    presetObject[_presetNameKey] = name;

    QSettings settings;
    settings.beginGroup(presetsSettingsGroup());
    settings.beginGroup(_presetSettingsKey);
    settings.setValue(name, QJsonDocument(presetObject).toBinaryData());
    emit presetNamesChanged();

    _currentPreset = name;
    emit currentPresetChanged(name);
}

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

void ComplexMissionItem::_saveItem(QJsonObject& saveObject)
{
    qDebug() << "_saveItem" << _cameraInPreset;
    saveObject[_presetNameKey] =            _currentPreset;
    saveObject[_saveCameraInPresetKey] =    _cameraInPreset;
    saveObject[_builtInPresetKey] =         _builtInPreset;
}

void ComplexMissionItem::_loadItem(const QJsonObject& saveObject)
{
    _currentPreset =    saveObject[_presetNameKey].toString();
    _cameraInPreset =   saveObject[_saveCameraInPresetKey].toBool(false);
    _builtInPreset =    saveObject[_builtInPresetKey].toBool(false);

    if (!presetNames().contains(_currentPreset)) {
        _currentPreset.clear();
    }

    emit cameraInPresetChanged  (_cameraInPreset);
    emit currentPresetChanged   (_currentPreset);
    emit builtInPresetChanged   (_builtInPreset);
}

void ComplexMissionItem::setCameraInPreset(bool cameraInPreset)
{
    if (cameraInPreset != _cameraInPreset) {
        _cameraInPreset = cameraInPreset;
        emit cameraInPresetChanged(_cameraInPreset);
    }
}

void ComplexMissionItem::setBuiltInPreset(bool builtInPreset)
{
    if (builtInPreset != _builtInPreset) {
        _builtInPreset = builtInPreset;
        emit builtInPresetChanged(_builtInPreset);
    }
}