QGroundControlQmlGlobal.h 12.2 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 "HomePositionManager.h"
21
#include "FlightMapSettings.h"
Don Gagne's avatar
Don Gagne committed
22
#include "MissionCommands.h"
23
#include "SettingsFact.h"
24
#include "FactMetaData.h"
Jimmy Johnson's avatar
Jimmy Johnson committed
25
#include "SimulatedPosition.h"
26
#include "QGCLoggingCategory.h"
27

28 29 30 31
#ifdef QT_DEBUG
#include "MockLink.h"
#endif

32 33
class QGCToolbox;

34
class QGroundControlQmlGlobal : public QGCTool
35 36 37 38
{
    Q_OBJECT

public:
39 40 41
    QGroundControlQmlGlobal(QGCApplication* app);
    ~QGroundControlQmlGlobal();

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    enum DistanceUnits {
        DistanceUnitsFeet = 0,
        DistanceUnitsMeters
    };

    enum SpeedUnits {
        SpeedUnitsFeetPerSecond = 0,
        SpeedUnitsMetersPerSecond,
        SpeedUnitsMilesPerHour,
        SpeedUnitsKilometersPerHour,
        SpeedUnitsKnots,
    };

    Q_ENUMS(DistanceUnits)
    Q_ENUMS(SpeedUnits)
Gus Grubba's avatar
Gus Grubba committed
57

Don Gagne's avatar
Don Gagne committed
58 59
    Q_PROPERTY(FlightMapSettings*   flightMapSettings   READ flightMapSettings      CONSTANT)
    Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
60
    Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
Don Gagne's avatar
Don Gagne committed
61
    Q_PROPERTY(MissionCommands*     missionCommands     READ missionCommands        CONSTANT)
Don Gagne's avatar
Don Gagne committed
62
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
63
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
Jimmy Johnson's avatar
Jimmy Johnson committed
64
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
65 66 67 68 69

    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) ///< z order value for map items, for example: mission item indicators

70 71 72 73 74 75
    // Various QGC settings exposed to Qml
    Q_PROPERTY(bool     isAdvancedMode          READ isAdvancedMode                                                 CONSTANT)                               ///< Global "Advance Mode" preference. Certain UI elements and features are different based on this.
    Q_PROPERTY(bool     isDarkStyle             READ isDarkStyle                WRITE setIsDarkStyle                NOTIFY isDarkStyleChanged)              // TODO: Should be in ScreenTools?
    Q_PROPERTY(bool     isAudioMuted            READ isAudioMuted               WRITE setIsAudioMuted               NOTIFY isAudioMutedChanged)
    Q_PROPERTY(bool     isSaveLogPrompt         READ isSaveLogPrompt            WRITE setIsSaveLogPrompt            NOTIFY isSaveLogPromptChanged)
    Q_PROPERTY(bool     isSaveLogPromptNotArmed READ isSaveLogPromptNotArmed    WRITE setIsSaveLogPromptNotArmed    NOTIFY isSaveLogPromptNotArmedChanged)
76
    Q_PROPERTY(bool     virtualTabletJoystick   READ virtualTabletJoystick      WRITE setVirtualTabletJoystick      NOTIFY virtualTabletJoystickChanged)
77
    Q_PROPERTY(qreal    baseFontPointSize       READ baseFontPointSize          WRITE setBaseFontPointSize          NOTIFY baseFontPointSizeChanged)
78 79

    // MavLink Protocol
80 81
    Q_PROPERTY(bool     isMultiplexingEnabled   READ isMultiplexingEnabled      WRITE setIsMultiplexingEnabled      NOTIFY isMultiplexingEnabledChanged)
    Q_PROPERTY(bool     isVersionCheckEnabled   READ isVersionCheckEnabled      WRITE setIsVersionCheckEnabled      NOTIFY isVersionCheckEnabledChanged)
82
    Q_PROPERTY(int      mavlinkSystemID         READ mavlinkSystemID            WRITE setMavlinkSystemID            NOTIFY mavlinkSystemIDChanged)
dogmaphobic's avatar
dogmaphobic committed
83

84 85 86
    Q_PROPERTY(Fact*    offlineEditingFirmwareType  READ offlineEditingFirmwareType CONSTANT)
    Q_PROPERTY(Fact*    distanceUnits               READ distanceUnits              CONSTANT)
    Q_PROPERTY(Fact*    speedUnits                  READ speedUnits                 CONSTANT)
87

88 89
    Q_PROPERTY(QGeoCoordinate lastKnownHomePosition READ lastKnownHomePosition  CONSTANT)
    Q_PROPERTY(QGeoCoordinate flightMapPosition     MEMBER _flightMapPosition   NOTIFY flightMapPositionChanged)
90
    Q_PROPERTY(double         flightMapZoom         MEMBER _flightMapZoom       NOTIFY flightMapZoomChanged)
Don Gagne's avatar
Don Gagne committed
91

Don Gagne's avatar
Don Gagne committed
92 93 94 95
    Q_PROPERTY(QString  parameterFileExtension  READ parameterFileExtension CONSTANT)
    Q_PROPERTY(QString  missionFileExtension    READ missionFileExtension   CONSTANT)
    Q_PROPERTY(QString  telemetryFileExtension  READ telemetryFileExtension CONSTANT)

96 97 98
    /// @ return: true: experimental survey ip code is turned on
    Q_PROPERTY(bool experimentalSurvey READ experimentalSurvey WRITE setExperimentalSurvey NOTIFY experimentalSurveyChanged)

99 100 101
    /// Returns the string for distance units which has configued by user
    Q_PROPERTY(QString appSettingsDistanceUnitsString READ appSettingsDistanceUnitsString CONSTANT)

102 103 104 105 106
    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);

107 108
    Q_INVOKABLE void    deleteAllSettingsNextBoot       () { _app->deleteAllSettingsNextBoot(); }
    Q_INVOKABLE void    clearDeleteAllSettingsNextBoot  () { _app->clearDeleteAllSettingsNextBoot(); }
109

110 111 112 113 114 115
    Q_INVOKABLE void    startPX4MockLink            (bool sendStatusText);
    Q_INVOKABLE void    startGenericMockLink        (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduCopterMockLink  (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduPlaneMockLink   (bool sendStatusText);
    Q_INVOKABLE void    stopAllMockLinks            (void);

116 117 118 119 120 121 122 123
    /// 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(); }

124 125 126 127 128 129 130 131 132 133 134 135
    /// 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.
    Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable) { QGCLoggingCategoryRegister::instance()->setCategoryLoggingOn(category, enable); };

    /// Returns true if logging is turned on for the specified category.
    Q_INVOKABLE bool categoryLoggingOn(const QString& category) { return QGCLoggingCategoryRegister::instance()->categoryLoggingOn(category); };

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

136
    // Property accesors
Gus Grubba's avatar
Gus Grubba committed
137

Don Gagne's avatar
Don Gagne committed
138 139
    FlightMapSettings*      flightMapSettings   ()      { return _flightMapSettings; }
    HomePositionManager*    homePositionManager ()      { return _homePositionManager; }
dogmaphobic's avatar
dogmaphobic committed
140 141
    LinkManager*            linkManager         ()      { return _linkManager; }
    MissionCommands*        missionCommands     ()      { return _missionCommands; }
Don Gagne's avatar
Don Gagne committed
142
    MultiVehicleManager*    multiVehicleManager ()      { return _multiVehicleManager; }
Jimmy Johnson's avatar
Jimmy Johnson committed
143 144
    QGCMapEngineManager*    mapEngineManager    ()      { return _mapEngineManager; }
    QGCPositionManager*     qgcPositionManger   ()      { return _qgcPositionManager; }
Gus Grubba's avatar
Gus Grubba committed
145 146 147 148 149

    qreal                   zOrderTopMost       ()      { return 1000; }
    qreal                   zOrderWidgets       ()      { return 100; }
    qreal                   zOrderMapItems      ()      { return 50; }

150 151 152 153
    bool    isDarkStyle             () { return _app->styleIsDark(); }
    bool    isAudioMuted            () { return _toolbox->audioOutput()->isMuted(); }
    bool    isSaveLogPrompt         () { return _app->promptFlightDataSave(); }
    bool    isSaveLogPromptNotArmed () { return _app->promptFlightDataSaveNotArmed(); }
154
    bool    virtualTabletJoystick   () { return _virtualTabletJoystick; }
155
    qreal   baseFontPointSize       () { return _baseFontPointSize; }
156

157 158 159 160
    bool    isMultiplexingEnabled   () { return _toolbox->mavlinkProtocol()->multiplexingEnabled(); }
    bool    isVersionCheckEnabled   () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
    int     mavlinkSystemID         () { return _toolbox->mavlinkProtocol()->getSystemId(); }

161
    QGeoCoordinate lastKnownHomePosition() { return qgcApp()->lastKnownHomePosition(); }
Don Gagne's avatar
Don Gagne committed
162

163 164 165
    static Fact* offlineEditingFirmwareType (void);
    static Fact* distanceUnits              (void);
    static Fact* speedUnits                 (void);
dogmaphobic's avatar
dogmaphobic committed
166

dogmaphobic's avatar
dogmaphobic committed
167
    //-- TODO: Make this into an actual preference.
168
    bool    isAdvancedMode          () { return false; }
dogmaphobic's avatar
dogmaphobic committed
169

170 171 172 173
    void    setIsDarkStyle              (bool dark);
    void    setIsAudioMuted             (bool muted);
    void    setIsSaveLogPrompt          (bool prompt);
    void    setIsSaveLogPromptNotArmed  (bool prompt);
174
    void    setVirtualTabletJoystick    (bool enabled);
175
    void    setBaseFontPointSize        (qreal size);
176

177 178
    void    setIsMultiplexingEnabled    (bool enable);
    void    setIsVersionCheckEnabled    (bool enable);
179
    void    setMavlinkSystemID          (int  id);
dogmaphobic's avatar
dogmaphobic committed
180

181 182 183
    bool experimentalSurvey(void) const;
    void setExperimentalSurvey(bool experimentalSurvey);

Don Gagne's avatar
Don Gagne committed
184 185 186 187
    QString parameterFileExtension(void) const  { return QGCApplication::parameterFileExtension; }
    QString missionFileExtension(void) const    { return QGCApplication::missionFileExtension; }
    QString telemetryFileExtension(void) const  { return QGCApplication::telemetryFileExtension; }

188 189 190
    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

dogmaphobic's avatar
dogmaphobic committed
191 192 193 194
signals:
    void isDarkStyleChanged             (bool dark);
    void isAudioMutedChanged            (bool muted);
    void isSaveLogPromptChanged         (bool prompt);
195
    void isSaveLogPromptNotArmedChanged (bool prompt);
196
    void virtualTabletJoystickChanged   (bool enabled);
197
    void baseFontPointSizeChanged       (qreal size);
dogmaphobic's avatar
dogmaphobic committed
198 199
    void isMultiplexingEnabledChanged   (bool enabled);
    void isVersionCheckEnabledChanged   (bool enabled);
200
    void mavlinkSystemIDChanged         (int id);
201
    void flightMapPositionChanged       (QGeoCoordinate flightMapPosition);
202
    void flightMapZoomChanged           (double flightMapZoom);
203
    void experimentalSurveyChanged      (bool experimentalSurvey);
dogmaphobic's avatar
dogmaphobic committed
204

205
private:
206
    FlightMapSettings*      _flightMapSettings;
Don Gagne's avatar
Don Gagne committed
207 208 209 210
    HomePositionManager*    _homePositionManager;
    LinkManager*            _linkManager;
    MissionCommands*        _missionCommands;
    MultiVehicleManager*    _multiVehicleManager;
211
    QGCMapEngineManager*    _mapEngineManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
212
    QGCPositionManager*     _qgcPositionManager;
213

214 215 216 217
    bool                    _virtualTabletJoystick;
    qreal                   _baseFontPointSize;
    QGeoCoordinate          _flightMapPosition;
    double                  _flightMapZoom;
218 219 220 221 222 223 224 225

    // These are static so they are available to C++ code as well as Qml
    static SettingsFact*    _offlineEditingFirmwareTypeFact;
    static FactMetaData*    _offlineEditingFirmwareTypeMetaData;
    static SettingsFact*    _distanceUnitsFact;
    static FactMetaData*    _distanceUnitsMetaData;
    static SettingsFact*    _speedUnitsFact;
    static FactMetaData*    _speedUnitsMetaData;
226

227
    static const char*  _virtualTabletJoystickKey;
228
    static const char*  _baseFontPointSizeKey;
229 230 231
};

#endif