QGroundControlQmlGlobal.h 11.3 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.
 *
 ****************************************************************************/
Gus Grubba's avatar
Gus Grubba committed
9

10 11 12 13 14 15 16

/// @file
///     @author Don Gagne <don@thegagnes.com>

#ifndef QGroundControlQmlGlobal_H
#define QGroundControlQmlGlobal_H

17
#include "QGCToolbox.h"
dogmaphobic's avatar
dogmaphobic committed
18
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
19
#include "LinkManager.h"
20
#include "SettingsFact.h"
21
#include "FactMetaData.h"
Jimmy Johnson's avatar
Jimmy Johnson committed
22
#include "SimulatedPosition.h"
23
#include "QGCLoggingCategory.h"
24
#include "AppSettings.h"
25
#ifndef __mobile__
26
#include "GPS/GPSManager.h"
27
#endif /* __mobile__ */
28
#include "GPSRTKFactGroup.h"
29

30 31 32 33
#ifdef QT_DEBUG
#include "MockLink.h"
#endif

34 35
class QGCToolbox;

36
class QGroundControlQmlGlobal : public QGCTool
37 38 39 40
{
    Q_OBJECT

public:
41
    QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox);
42 43
    ~QGroundControlQmlGlobal();

44 45
    Q_PROPERTY(QString              appName             READ appName                CONSTANT)

Don Gagne's avatar
Don Gagne committed
46 47
    Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
48
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
Jimmy Johnson's avatar
Jimmy Johnson committed
49
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
50
    Q_PROPERTY(MissionCommandTree*  missionCommandTree  READ missionCommandTree     CONSTANT)
51
    Q_PROPERTY(VideoManager*        videoManager        READ videoManager           CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
52
    Q_PROPERTY(MAVLinkLogManager*   mavlinkLogManager   READ mavlinkLogManager      CONSTANT)
53
    Q_PROPERTY(QGCCorePlugin*       corePlugin          READ corePlugin             CONSTANT)
54
    Q_PROPERTY(SettingsManager*     settingsManager     READ settingsManager        CONSTANT)
55
    Q_PROPERTY(FactGroup*           gpsRtk              READ gpsRtkFactGroup        CONSTANT)
56

57
    Q_PROPERTY(int      supportedFirmwareCount          READ supportedFirmwareCount CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
58

DonLakeFlyer's avatar
DonLakeFlyer committed
59 60 61 62 63 64 65
    Q_PROPERTY(qreal zOrderTopMost              READ zOrderTopMost              CONSTANT) ///< z order for top most items, toolbar, main window sub view
    Q_PROPERTY(qreal zOrderWidgets              READ zOrderWidgets              CONSTANT) ///< z order value to widgets, for example: zoom controls, hud widgetss
    Q_PROPERTY(qreal zOrderMapItems             READ zOrderMapItems             CONSTANT)
    Q_PROPERTY(qreal zOrderVehicles             READ zOrderVehicles             CONSTANT)
    Q_PROPERTY(qreal zOrderWaypointIndicators   READ zOrderWaypointIndicators   CONSTANT)
    Q_PROPERTY(qreal zOrderTrajectoryLines      READ zOrderTrajectoryLines      CONSTANT)
    Q_PROPERTY(qreal zOrderWaypointLines        READ zOrderWaypointLines        CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
66

Gus Grubba's avatar
Gus Grubba committed
67
    //-------------------------------------------------------------------------
68
    // MavLink Protocol
Don Gagne's avatar
Don Gagne committed
69
    Q_PROPERTY(bool     isVersionCheckEnabled   READ isVersionCheckEnabled      WRITE setIsVersionCheckEnabled      NOTIFY isVersionCheckEnabledChanged)
70
    Q_PROPERTY(int      mavlinkSystemID         READ mavlinkSystemID            WRITE setMavlinkSystemID            NOTIFY mavlinkSystemIDChanged)
dogmaphobic's avatar
dogmaphobic committed
71

72 73
    Q_PROPERTY(QGeoCoordinate flightMapPosition     READ flightMapPosition      WRITE setFlightMapPosition          NOTIFY flightMapPositionChanged)
    Q_PROPERTY(double         flightMapZoom         READ flightMapZoom          WRITE setFlightMapZoom              NOTIFY flightMapZoomChanged)
74
    Q_PROPERTY(double         flightMapInitialZoom  MEMBER _flightMapInitialZoom                                    CONSTANT)                               ///< Zoom level to use when either gcs or vehicle shows up for first time
Don Gagne's avatar
Don Gagne committed
75

Don Gagne's avatar
Don Gagne committed
76 77 78 79
    Q_PROPERTY(QString  parameterFileExtension  READ parameterFileExtension CONSTANT)
    Q_PROPERTY(QString  missionFileExtension    READ missionFileExtension   CONSTANT)
    Q_PROPERTY(QString  telemetryFileExtension  READ telemetryFileExtension CONSTANT)

80 81
    /// Returns the string for distance units which has configued by user
    Q_PROPERTY(QString appSettingsDistanceUnitsString READ appSettingsDistanceUnitsString CONSTANT)
82
    Q_PROPERTY(QString appSettingsAreaUnitsString READ appSettingsAreaUnitsString CONSTANT)
83

84 85
    Q_PROPERTY(QString qgcVersion       READ qgcVersion         CONSTANT)
    Q_PROPERTY(bool    skipSetupPage    READ skipSetupPage      WRITE setSkipSetupPage NOTIFY skipSetupPageChanged)
86

87 88 89 90 91
    Q_INVOKABLE void    saveGlobalSetting       (const QString& key, const QString& value);
    Q_INVOKABLE QString loadGlobalSetting       (const QString& key, const QString& defaultValue);
    Q_INVOKABLE void    saveBoolGlobalSetting   (const QString& key, bool value);
    Q_INVOKABLE bool    loadBoolGlobalSetting   (const QString& key, bool defaultValue);

92 93
    Q_INVOKABLE void    deleteAllSettingsNextBoot       () { _app->deleteAllSettingsNextBoot(); }
    Q_INVOKABLE void    clearDeleteAllSettingsNextBoot  () { _app->clearDeleteAllSettingsNextBoot(); }
94

95 96 97 98
    Q_INVOKABLE void    startPX4MockLink            (bool sendStatusText);
    Q_INVOKABLE void    startGenericMockLink        (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduCopterMockLink  (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduPlaneMockLink   (bool sendStatusText);
99
    Q_INVOKABLE void    startAPMArduSubMockLink     (bool sendStatusText);
Don Gagne's avatar
Don Gagne committed
100
    Q_INVOKABLE void    stopOneMockLink             (void);
101

102 103 104 105 106 107 108 109
    /// Converts from meters to the user specified distance unit
    Q_INVOKABLE QVariant metersToAppSettingsDistanceUnits(const QVariant& meters) const { return FactMetaData::metersToAppSettingsDistanceUnits(meters); }

    /// Converts from user specified distance unit to meters
    Q_INVOKABLE QVariant appSettingsDistanceUnitsToMeters(const QVariant& distance) const { return FactMetaData::appSettingsDistanceUnitsToMeters(distance); }

    QString appSettingsDistanceUnitsString(void) const { return FactMetaData::appSettingsDistanceUnitsString(); }

110 111 112 113 114 115 116 117
    /// Converts from square meters to the user specified area unit
    Q_INVOKABLE QVariant squareMetersToAppSettingsAreaUnits(const QVariant& meters) const { return FactMetaData::squareMetersToAppSettingsAreaUnits(meters); }

    /// Converts from user specified area unit to square meters
    Q_INVOKABLE QVariant appSettingsAreaUnitsToSquareMeters(const QVariant& area) const { return FactMetaData::appSettingsAreaUnitsToSquareMeters(area); }

    QString appSettingsAreaUnitsString(void) const { return FactMetaData::appSettingsAreaUnitsString(); }

118 119 120 121
    /// Returns the list of available logging category names.
    Q_INVOKABLE QStringList loggingCategories(void) const { return QGCLoggingCategoryRegister::instance()->registeredCategories(); }

    /// Turns on/off logging for the specified category. State is saved in app settings.
Don Gagne's avatar
Don Gagne committed
122
    Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable) { QGCLoggingCategoryRegister::instance()->setCategoryLoggingOn(category, enable); }
123 124

    /// Returns true if logging is turned on for the specified category.
Don Gagne's avatar
Don Gagne committed
125
    Q_INVOKABLE bool categoryLoggingOn(const QString& category) { return QGCLoggingCategoryRegister::instance()->categoryLoggingOn(category); }
126 127 128 129

    /// Updates the logging filter rules after settings have changed
    Q_INVOKABLE void updateLoggingFilterRules(void) { QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(QString()); }

130 131
    Q_INVOKABLE bool linesIntersect(QPointF xLine1, QPointF yLine1, QPointF xLine2, QPointF yLine2);

132
    // Property accesors
Gus Grubba's avatar
Gus Grubba committed
133

134
    QString                 appName             ()  { return qgcApp()->applicationName(); }
135 136 137 138 139 140 141 142 143
    LinkManager*            linkManager         ()  { return _linkManager; }
    MultiVehicleManager*    multiVehicleManager ()  { return _multiVehicleManager; }
    QGCMapEngineManager*    mapEngineManager    ()  { return _mapEngineManager; }
    QGCPositionManager*     qgcPositionManger   ()  { return _qgcPositionManager; }
    MissionCommandTree*     missionCommandTree  ()  { return _missionCommandTree; }
    VideoManager*           videoManager        ()  { return _videoManager; }
    MAVLinkLogManager*      mavlinkLogManager   ()  { return _mavlinkLogManager; }
    QGCCorePlugin*          corePlugin          ()  { return _corePlugin; }
    SettingsManager*        settingsManager     ()  { return _settingsManager; }
144
    FactGroup*              gpsRtkFactGroup     ()  { return &_gpsRtkFactGroup; }
145 146
    static QGeoCoordinate   flightMapPosition   ();
    static double           flightMapZoom       ();
147

DonLakeFlyer's avatar
DonLakeFlyer committed
148 149 150 151 152 153 154
    qreal zOrderTopMost             () { return 1000; }
    qreal zOrderWidgets             () { return 100; }
    qreal zOrderMapItems            () { return 50; }
    qreal zOrderWaypointIndicators  () { return 50; }
    qreal zOrderVehicles            () { return 49; }
    qreal zOrderTrajectoryLines     () { return 48; }
    qreal zOrderWaypointLines       () { return 47; }
Gus Grubba's avatar
Gus Grubba committed
155

Don Gagne's avatar
Don Gagne committed
156
    bool    isVersionCheckEnabled   () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
157 158
    int     mavlinkSystemID         () { return _toolbox->mavlinkProtocol()->getSystemId(); }

159 160 161
    int     supportedFirmwareCount  ();
    bool    skipSetupPage           () { return _skipSetupPage; }
    void    setSkipSetupPage        (bool skip);
Gus Grubba's avatar
Gus Grubba committed
162

Don Gagne's avatar
Don Gagne committed
163
    void    setIsVersionCheckEnabled    (bool enable);
164
    void    setMavlinkSystemID          (int  id);
165 166
    void    setFlightMapPosition        (QGeoCoordinate& coordinate);
    void    setFlightMapZoom            (double zoom);
dogmaphobic's avatar
dogmaphobic committed
167

168 169 170
    QString parameterFileExtension(void) const  { return AppSettings::parameterFileExtension; }
    QString missionFileExtension(void) const    { return AppSettings::missionFileExtension; }
    QString telemetryFileExtension(void) const  { return AppSettings::telemetryFileExtension; }
Don Gagne's avatar
Don Gagne committed
171

172 173
    QString qgcVersion(void) const { return qgcApp()->applicationVersion(); }

174

175 176 177
    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

dogmaphobic's avatar
dogmaphobic committed
178 179
signals:
    void isMultiplexingEnabledChanged   (bool enabled);
Don Gagne's avatar
Don Gagne committed
180
    void isVersionCheckEnabledChanged   (bool enabled);
181
    void mavlinkSystemIDChanged         (int id);
182
    void flightMapPositionChanged       (QGeoCoordinate flightMapPosition);
183
    void flightMapZoomChanged           (double flightMapZoom);
184
    void skipSetupPageChanged           ();
dogmaphobic's avatar
dogmaphobic committed
185

186 187 188 189 190 191
private slots:
    void _onGPSConnect();
    void _onGPSDisconnect();
    void _GPSSurveyInStatus(float duration, float accuracyMM, bool valid, bool active);
    void _GPSNumSatellites(int numSatellites);

192
private:
193
    double                  _flightMapInitialZoom;
Don Gagne's avatar
Don Gagne committed
194 195
    LinkManager*            _linkManager;
    MultiVehicleManager*    _multiVehicleManager;
196
    QGCMapEngineManager*    _mapEngineManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
197
    QGCPositionManager*     _qgcPositionManager;
198
    MissionCommandTree*     _missionCommandTree;
199
    VideoManager*           _videoManager;
Gus Grubba's avatar
Gus Grubba committed
200
    MAVLinkLogManager*      _mavlinkLogManager;
201
    QGCCorePlugin*          _corePlugin;
Gus Grubba's avatar
Gus Grubba committed
202
    FirmwarePluginManager*  _firmwarePluginManager;
203
    SettingsManager*        _settingsManager;
204
    GPSRTKFactGroup         _gpsRtkFactGroup;
205

206
    bool                    _skipSetupPage;
207 208 209 210 211

    static const char* _flightMapPositionSettingsGroup;
    static const char* _flightMapPositionLatitudeSettingsKey;
    static const char* _flightMapPositionLongitudeSettingsKey;
    static const char* _flightMapZoomSettingsKey;
212 213 214
};

#endif