SimpleMissionItem.h 8.6 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
#include "SpeedSection.h"
19

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

30 31
    ~SimpleMissionItem();

32
    const SimpleMissionItem& operator=(const SimpleMissionItem& other);
33 34 35 36 37
    
    Q_PROPERTY(QString          category                READ category                                           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)
38
    Q_PROPERTY(MavlinkQmlSingleton::Qml_MAV_CMD command READ command                WRITE setCommand            NOTIFY commandChanged)
39

40
    /// Optional sections
41
    Q_PROPERTY(QObject*         speedSection            READ speedSection                                       NOTIFY speedSectionChanged)
42 43
    Q_PROPERTY(QObject*         cameraSection           READ cameraSection                                      NOTIFY cameraSectionChanged)

44
    // These properties are used to display the editing ui
45 46 47 48
    Q_PROPERTY(QmlObjectListModel*  checkboxFacts   READ checkboxFacts  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  comboboxFacts   READ comboboxFacts  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  textFieldFacts  READ textFieldFacts CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  nanFacts        READ nanFacts       CONSTANT)
49

50 51 52 53
    /// 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
54
    /// @return true: section found, scanIndex updated
55
    bool scanForSections(QmlObjectListModel* visualItems, int scanIndex, Vehicle* vehicle);
56

57 58 59
    // Property accesors
    
    QString         category            (void) const;
Don Gagne's avatar
Don Gagne committed
60
    MavlinkQmlSingleton::Qml_MAV_CMD command(void) const { return (MavlinkQmlSingleton::Qml_MAV_CMD)_missionItem._commandFact.cookedValue().toInt(); }
61 62
    bool            friendlyEditAllowed (void) const;
    bool            rawEdit             (void) const;
63
    CameraSection*  cameraSection       (void) { return _cameraSection; }
64
    SpeedSection*   speedSection        (void) { return _speedSection; }
65

66 67 68 69
    QmlObjectListModel* textFieldFacts  (void) { return &_textFieldFacts; }
    QmlObjectListModel* nanFacts        (void) { return &_nanFacts; }
    QmlObjectListModel* checkboxFacts   (void) { return &_checkboxFacts; }
    QmlObjectListModel* comboboxFacts   (void) { return &_comboboxFacts; }
70 71 72 73 74 75 76 77 78 79 80 81 82

    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
83
    bool load(const QJsonObject& json, int sequenceNumber, QString& errorString);
84 85

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

87
    MissionItem& missionItem(void) { return _missionItem; }
88
    const MissionItem& missionItem(void) const { return _missionItem; }
89 90 91 92 93 94 95

    // 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;
96
    bool            specifiesAltitudeOnly   (void) const final;
97 98
    QString         commandDescription      (void) const final;
    QString         commandName             (void) const final;
99
    QString         abbreviation            (void) const final;
100 101
    QGeoCoordinate  coordinate              (void) const final { return _missionItem.coordinate(); }
    QGeoCoordinate  exitCoordinate          (void) const final { return coordinate(); }
102
    int             sequenceNumber          (void) const final { return _missionItem.sequenceNumber(); }
DonLakeFlyer's avatar
DonLakeFlyer committed
103 104
    double          specifiedFlightSpeed    (void) final;
    double          specifiedGimbalYaw      (void) final;
105
    QString         mapVisualQML            (void) const final { return QStringLiteral("SimpleItemMapVisual.qml"); }
106
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
107
    void            applyNewAltitude        (double newAltitude) final;
108 109 110 111 112 113

    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;
114 115
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
116 117
    int  lastSequenceNumber (void) const final;
    void save               (QJsonArray&  missionItems) final;
118 119 120 121 122 123 124 125 126 127

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);
128
    void cameraSectionChanged       (QObject* cameraSection);
129
    void speedSectionChanged        (QObject* cameraSection);
130

131
private slots:
132 133
    void _setDirtyFromSignal                (void);
    void _sectionDirtyChanged               (bool dirty);
134 135 136 137 138 139 140 141
    void _sendCommandChanged                (void);
    void _sendCoordinateChanged             (void);
    void _sendFrameChanged                  (void);
    void _sendFriendlyEditAllowedChanged    (void);
    void _syncAltitudeRelativeToHomeToFrame (const QVariant& value);
    void _syncFrameToAltitudeRelativeToHome (void);
    void _updateLastSequenceNumber          (void);
    void _rebuildFacts                      (void);
142 143

private:
144 145
    void _connectSignals        (void);
    void _setupMetaData         (void);
146
    void _updateOptionalSections(void);
147 148 149 150
    void _rebuildTextFieldFacts (void);
    void _rebuildNaNFacts       (void);
    void _rebuildCheckboxFacts  (void);
    void _rebuildComboBoxFacts  (void);
151 152 153 154

    MissionItem _missionItem;
    bool        _rawEdit;
    bool        _dirty;
155
    bool        _ignoreDirtyChangeSignals;
156

157
    SpeedSection*   _speedSection;
158 159
    CameraSection* _cameraSection;

160 161
    MissionCommandTree* _commandTree;

162 163
    Fact    _altitudeRelativeToHomeFact;
    Fact    _supportedCommandFact;
164 165 166 167 168

    QmlObjectListModel  _textFieldFacts;
    QmlObjectListModel  _nanFacts;
    QmlObjectListModel  _checkboxFacts;
    QmlObjectListModel  _comboboxFacts;
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    
    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
187 188 189
};

#endif