ComplexMissionItem.h 3.63 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 11 12
#ifndef ComplexMissionItem_H
#define ComplexMissionItem_H

13
#include "VisualMissionItem.h"
14
#include "QGCGeo.h"
15

Don Gagne's avatar
Don Gagne committed
16 17
#include <QSettings>

18
class ComplexMissionItem : public VisualMissionItem
19 20
{
    Q_OBJECT
21

22
public:
23
    ComplexMissionItem(Vehicle* vehicle, bool flyView, QObject* parent);
24

25 26
    const ComplexMissionItem& operator=(const ComplexMissionItem& other);

27 28 29 30
    Q_PROPERTY(double       complexDistance     READ complexDistance    NOTIFY complexDistanceChanged)
    Q_PROPERTY(bool         presetsSupported    READ presetsSupported   CONSTANT)
    Q_PROPERTY(QStringList  presetNames         READ presetNames        NOTIFY presetNamesChanged)
    Q_PROPERTY(bool         isIncomplete        READ isIncomplete       NOTIFY isIncompleteChanged)
31

32
    /// @return The distance covered the complex mission item in meters.
33
    /// Signals complexDistanceChanged
34
    virtual double complexDistance(void) const = 0;
35

36 37
    /// Load the complex mission item from Json
    ///     @param complexObject Complex mission item json object
Don Gagne's avatar
Don Gagne committed
38
    ///     @param sequenceNumber Sequence number for first MISSION_ITEM in survey
39 40
    ///     @param[out] errorString Error if load fails
    /// @return true: load success, false: load failed, errorString set
Don Gagne's avatar
Don Gagne committed
41
    virtual bool load(const QJsonObject& complexObject, int sequenceNumber, QString& errorString) = 0;
42

Don Gagne's avatar
Don Gagne committed
43 44 45 46 47 48 49 50
    /// Loads the specified preset into the complex item.
    ///     @param name Preset name.
    Q_INVOKABLE virtual void loadPreset(const QString& name);

    /// Saves the current state of the complex item as the named preset.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    Q_INVOKABLE virtual void savePreset(const QString& name);

Don Gagne's avatar
Don Gagne committed
51 52
     Q_INVOKABLE void deletePreset(const QString& name);

Don Gagne's avatar
Don Gagne committed
53

54 55 56
    /// Get the point of complex mission item furthest away from a coordinate
    ///     @param other QGeoCoordinate to which distance is calculated
    /// @return the greatest distance from any point of the complex item to some coordinate
57
    /// Signals greatestDistanceToChanged
58
    virtual double greatestDistanceTo(const QGeoCoordinate &other) const = 0;
59

Don Gagne's avatar
Don Gagne committed
60 61 62 63 64 65 66 67
    /// Returns the list of currently saved presets for this complex item type.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    virtual QStringList presetNames(void);

    /// Returns the name of the settings group for presets.
    ///     Empty string signals no support for presets.
    virtual QString presetsSettingsGroup(void) { return QString(); }

68 69
    bool presetsSupported   (void) { return !presetsSettingsGroup().isEmpty(); }
    bool isIncomplete       (void) const { return _isIncomplete; }
Don Gagne's avatar
Don Gagne committed
70

Don Gagne's avatar
Don Gagne committed
71 72 73
    /// This mission item attribute specifies the type of the complex item.
    static const char* jsonComplexItemTypeKey;

74
signals:
75
    void complexDistanceChanged     (void);
76
    void boundingCubeChanged        (void);
77
    void greatestDistanceToChanged  (void);
Don Gagne's avatar
Don Gagne committed
78
    void presetNamesChanged         (void);
79
    void isIncompleteChanged        (void);
Don Gagne's avatar
Don Gagne committed
80 81 82 83 84

protected:
    void        _savePresetJson (const QString& name, QJsonObject& presetObject);
    QJsonObject _loadPresetJson (const QString& name);

85
    bool _isIncomplete = true;
Don Gagne's avatar
Don Gagne committed
86 87 88 89

    QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _presetSettingsKey;
90 91 92
};

#endif