SimpleMissionItem.h 7.65 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10 11 12 13

#ifndef SimpleMissionItem_H
#define SimpleMissionItem_H

14
#include "VisualMissionItem.h"
15
#include "MissionItem.h"
16
#include "MissionCommandTree.h"
17
#include "CameraSection.h"
18

19 20
/// A SimpleMissionItem is used to represent a single MissionItem to the ui.
class SimpleMissionItem : public VisualMissionItem
21 22 23 24 25
{
    Q_OBJECT
    
public:
    SimpleMissionItem(Vehicle* vehicle, QObject* parent = NULL);
26
    SimpleMissionItem(Vehicle* vehicle, const MissionItem& missionItem, QObject* parent = NULL);
27 28
    SimpleMissionItem(const SimpleMissionItem& other, QObject* parent = NULL);

29 30
    ~SimpleMissionItem();

31
    const SimpleMissionItem& operator=(const SimpleMissionItem& other);
32 33 34 35 36 37 38
    
    Q_PROPERTY(QString          category                READ category                                           NOTIFY commandChanged)
    Q_PROPERTY(MavlinkQmlSingleton::Qml_MAV_CMD command READ command                WRITE setCommand            NOTIFY commandChanged)
    Q_PROPERTY(bool             friendlyEditAllowed     READ friendlyEditAllowed                                NOTIFY friendlyEditAllowedChanged)
    Q_PROPERTY(bool             rawEdit                 READ rawEdit                WRITE setRawEdit            NOTIFY rawEditChanged)              ///< true: raw item editing with all params
    Q_PROPERTY(bool             relativeAltitude        READ relativeAltitude                                   NOTIFY frameChanged)

39 40 41
    /// Optional sections
    Q_PROPERTY(QObject*         cameraSection           READ cameraSection                                      NOTIFY cameraSectionChanged)

42 43 44 45 46
    // These properties are used to display the editing ui
    Q_PROPERTY(QmlObjectListModel*  checkboxFacts   READ checkboxFacts  NOTIFY uiModelChanged)
    Q_PROPERTY(QmlObjectListModel*  comboboxFacts   READ comboboxFacts  NOTIFY uiModelChanged)
    Q_PROPERTY(QmlObjectListModel*  textFieldFacts  READ textFieldFacts NOTIFY uiModelChanged)

47 48 49 50
    /// Scans the loaded items for additional section settings
    ///     @param visualItems List of all visual items
    ///     @param scanIndex Index to start scanning from
    ///     @param vehicle Vehicle associated with this mission
51 52
    /// @return true: section found
    bool scanForSections(QmlObjectListModel* visualItems, int scanIndex, Vehicle* vehicle);
53

54 55 56
    // Property accesors
    
    QString         category            (void) const;
Don Gagne's avatar
Don Gagne committed
57
    MavlinkQmlSingleton::Qml_MAV_CMD command(void) const { return (MavlinkQmlSingleton::Qml_MAV_CMD)_missionItem._commandFact.cookedValue().toInt(); }
58 59
    bool            friendlyEditAllowed (void) const;
    bool            rawEdit             (void) const;
60
    CameraSection*  cameraSection       (void) { return _cameraSection; }
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    QmlObjectListModel* textFieldFacts  (void);
    QmlObjectListModel* checkboxFacts   (void);
    QmlObjectListModel* comboboxFacts   (void);

    void setRawEdit(bool rawEdit);
    
    void setCommandByIndex(int index);

    void setCommand(MavlinkQmlSingleton::Qml_MAV_CMD command);

    void setAltDifference   (double altDifference);
    void setAltPercent      (double altPercent);
    void setAzimuth         (double azimuth);
    void setDistance        (double distance);

    bool load(QTextStream &loadStream);
Don Gagne's avatar
Don Gagne committed
78
    bool load(const QJsonObject& json, int sequenceNumber, QString& errorString);
79 80

    bool relativeAltitude(void) { return _missionItem.frame() == MAV_FRAME_GLOBAL_RELATIVE_ALT; }
81

82
    MissionItem& missionItem(void) { return _missionItem; }
83
    const MissionItem& missionItem(void) const { return _missionItem; }
84 85 86 87 88 89 90

    // Overrides from VisualMissionItem

    bool            dirty                   (void) const final { return _dirty; }
    bool            isSimpleItem            (void) const final { return true; }
    bool            isStandaloneCoordinate  (void) const final;
    bool            specifiesCoordinate     (void) const final;
91
    bool            specifiesAltitudeOnly   (void) const final;
92 93
    QString         commandDescription      (void) const final;
    QString         commandName             (void) const final;
94
    QString         abbreviation            (void) const final;
95 96
    QGeoCoordinate  coordinate              (void) const final { return _missionItem.coordinate(); }
    QGeoCoordinate  exitCoordinate          (void) const final { return coordinate(); }
97
    int             sequenceNumber          (void) const final { return _missionItem.sequenceNumber(); }
DonLakeFlyer's avatar
DonLakeFlyer committed
98 99
    double          specifiedFlightSpeed    (void) final;
    double          specifiedGimbalYaw      (void) final;
100
    QString         mapVisualQML            (void) const final { return QStringLiteral("SimpleItemMapVisual.qml"); }
101
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
102 103 104 105 106 107

    bool coordinateHasRelativeAltitude      (void) const final { return _missionItem.relativeAltitude(); }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return coordinateHasRelativeAltitude(); }
    bool exitCoordinateSameAsEntry          (void) const final { return true; }

    void setDirty           (bool dirty) final;
108 109
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
110 111
    int  lastSequenceNumber (void) const final;
    void save               (QJsonArray&  missionItems) final;
112 113 114 115 116 117 118 119 120 121 122

public slots:
    void setDefaultsForCommand(void);

signals:
    void commandChanged             (int command);
    void frameChanged               (int frame);
    void friendlyEditAllowedChanged (bool friendlyEditAllowed);
    void headingDegreesChanged      (double heading);
    void rawEditChanged             (bool rawEdit);
    void uiModelChanged             (void);
123
    void cameraSectionChanged       (QObject* cameraSection);
124

125 126
private slots:
    void _setDirtyFromSignal(void);
127
    void _cameraSectionDirtyChanged(bool dirty);
128 129 130 131 132 133 134
    void _sendCommandChanged(void);
    void _sendCoordinateChanged(void);
    void _sendFrameChanged(void);
    void _sendFriendlyEditAllowedChanged(void);
    void _sendUiModelChanged(void);
    void _syncAltitudeRelativeToHomeToFrame(const QVariant& value);
    void _syncFrameToAltitudeRelativeToHome(void);
135
    void _updateLastSequenceNumber(void);
136 137

private:
138 139 140
    void _clearParamMetaData(void);
    void _connectSignals(void);
    void _setupMetaData(void);
141
    void _updateCameraSection(void);
142 143 144 145 146

private:
    MissionItem _missionItem;
    bool        _rawEdit;
    bool        _dirty;
147
    bool        _ignoreDirtyChangeSignals;
148

149 150
    CameraSection* _cameraSection;

151 152
    MissionCommandTree* _commandTree;

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    Fact    _altitudeRelativeToHomeFact;
    Fact    _supportedCommandFact;
    
    static FactMetaData*    _altitudeMetaData;
    static FactMetaData*    _commandMetaData;
    static FactMetaData*    _defaultParamMetaData;
    static FactMetaData*    _frameMetaData;
    static FactMetaData*    _latitudeMetaData;
    static FactMetaData*    _longitudeMetaData;

    FactMetaData    _param1MetaData;
    FactMetaData    _param2MetaData;
    FactMetaData    _param3MetaData;
    FactMetaData    _param4MetaData;
    FactMetaData    _param5MetaData;
    FactMetaData    _param6MetaData;
    FactMetaData    _param7MetaData;

    bool _syncingAltitudeRelativeToHomeAndFrame;    ///< true: already in a sync signal, prevents signal loop
    bool _syncingHeadingDegreesAndParam4;           ///< true: already in a sync signal, prevents signal loop
173 174 175
};

#endif