QGroundControlQmlGlobal.h 12.7 KB
Newer Older
1
/*=====================================================================
Gus Grubba's avatar
Gus Grubba committed
2

3
 QGroundControl Open Source Ground Control Station
Gus Grubba's avatar
Gus Grubba committed
4

5
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
Gus Grubba's avatar
Gus Grubba committed
6

7
 This file is part of the QGROUNDCONTROL project
Gus Grubba's avatar
Gus Grubba committed
8

9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
Gus Grubba's avatar
Gus Grubba committed
13

14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
Gus Grubba's avatar
Gus Grubba committed
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
Gus Grubba's avatar
Gus Grubba committed
21

22 23 24 25 26 27 28 29
 ======================================================================*/

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

#ifndef QGroundControlQmlGlobal_H
#define QGroundControlQmlGlobal_H

30
#include "QGCToolbox.h"
dogmaphobic's avatar
dogmaphobic committed
31
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
32
#include "LinkManager.h"
33
#include "HomePositionManager.h"
34
#include "FlightMapSettings.h"
Don Gagne's avatar
Don Gagne committed
35
#include "MissionCommands.h"
36
#include "SettingsFact.h"
37
#include "FactMetaData.h"
Jimmy Johnson's avatar
Jimmy Johnson committed
38
#include "SimulatedPosition.h"
39
#include "QGCLoggingCategory.h"
40

41 42 43 44
#ifdef QT_DEBUG
#include "MockLink.h"
#endif

45 46
class QGCToolbox;

47
class QGroundControlQmlGlobal : public QGCTool
48 49 50 51
{
    Q_OBJECT

public:
52 53 54
    QGroundControlQmlGlobal(QGCApplication* app);
    ~QGroundControlQmlGlobal();

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    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
70

Don Gagne's avatar
Don Gagne committed
71 72
    Q_PROPERTY(FlightMapSettings*   flightMapSettings   READ flightMapSettings      CONSTANT)
    Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
73
    Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
Don Gagne's avatar
Don Gagne committed
74
    Q_PROPERTY(MissionCommands*     missionCommands     READ missionCommands        CONSTANT)
Don Gagne's avatar
Don Gagne committed
75
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
76
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
Jimmy Johnson's avatar
Jimmy Johnson committed
77
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
78 79 80 81 82

    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

83 84 85 86 87 88
    // 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)
89
    Q_PROPERTY(bool     virtualTabletJoystick   READ virtualTabletJoystick      WRITE setVirtualTabletJoystick      NOTIFY virtualTabletJoystickChanged)
90
    Q_PROPERTY(qreal    baseFontPointSize       READ baseFontPointSize          WRITE setBaseFontPointSize          NOTIFY baseFontPointSizeChanged)
91 92

    // MavLink Protocol
93 94
    Q_PROPERTY(bool     isMultiplexingEnabled   READ isMultiplexingEnabled      WRITE setIsMultiplexingEnabled      NOTIFY isMultiplexingEnabledChanged)
    Q_PROPERTY(bool     isVersionCheckEnabled   READ isVersionCheckEnabled      WRITE setIsVersionCheckEnabled      NOTIFY isVersionCheckEnabledChanged)
95
    Q_PROPERTY(int      mavlinkSystemID         READ mavlinkSystemID            WRITE setMavlinkSystemID            NOTIFY mavlinkSystemIDChanged)
dogmaphobic's avatar
dogmaphobic committed
96

97 98 99
    Q_PROPERTY(Fact*    offlineEditingFirmwareType  READ offlineEditingFirmwareType CONSTANT)
    Q_PROPERTY(Fact*    distanceUnits               READ distanceUnits              CONSTANT)
    Q_PROPERTY(Fact*    speedUnits                  READ speedUnits                 CONSTANT)
100

101 102
    Q_PROPERTY(QGeoCoordinate lastKnownHomePosition READ lastKnownHomePosition  CONSTANT)
    Q_PROPERTY(QGeoCoordinate flightMapPosition     MEMBER _flightMapPosition   NOTIFY flightMapPositionChanged)
103
    Q_PROPERTY(double         flightMapZoom         MEMBER _flightMapZoom       NOTIFY flightMapZoomChanged)
Don Gagne's avatar
Don Gagne committed
104

Don Gagne's avatar
Don Gagne committed
105 106 107 108
    Q_PROPERTY(QString  parameterFileExtension  READ parameterFileExtension CONSTANT)
    Q_PROPERTY(QString  missionFileExtension    READ missionFileExtension   CONSTANT)
    Q_PROPERTY(QString  telemetryFileExtension  READ telemetryFileExtension CONSTANT)

109 110 111
    /// @ return: true: experimental survey ip code is turned on
    Q_PROPERTY(bool experimentalSurvey READ experimentalSurvey WRITE setExperimentalSurvey NOTIFY experimentalSurveyChanged)

112 113 114
    /// Returns the string for distance units which has configued by user
    Q_PROPERTY(QString appSettingsDistanceUnitsString READ appSettingsDistanceUnitsString CONSTANT)

115 116 117 118 119
    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);

120 121
    Q_INVOKABLE void    deleteAllSettingsNextBoot       () { _app->deleteAllSettingsNextBoot(); }
    Q_INVOKABLE void    clearDeleteAllSettingsNextBoot  () { _app->clearDeleteAllSettingsNextBoot(); }
122

123 124 125 126 127 128
    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);

129 130 131 132 133 134 135 136
    /// 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(); }

137 138 139 140 141 142 143 144 145 146 147 148
    /// 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()); }

149
    // Property accesors
Gus Grubba's avatar
Gus Grubba committed
150

Don Gagne's avatar
Don Gagne committed
151 152
    FlightMapSettings*      flightMapSettings   ()      { return _flightMapSettings; }
    HomePositionManager*    homePositionManager ()      { return _homePositionManager; }
dogmaphobic's avatar
dogmaphobic committed
153 154
    LinkManager*            linkManager         ()      { return _linkManager; }
    MissionCommands*        missionCommands     ()      { return _missionCommands; }
Don Gagne's avatar
Don Gagne committed
155
    MultiVehicleManager*    multiVehicleManager ()      { return _multiVehicleManager; }
Jimmy Johnson's avatar
Jimmy Johnson committed
156 157
    QGCMapEngineManager*    mapEngineManager    ()      { return _mapEngineManager; }
    QGCPositionManager*     qgcPositionManger   ()      { return _qgcPositionManager; }
Gus Grubba's avatar
Gus Grubba committed
158 159 160 161 162

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

163 164 165 166
    bool    isDarkStyle             () { return _app->styleIsDark(); }
    bool    isAudioMuted            () { return _toolbox->audioOutput()->isMuted(); }
    bool    isSaveLogPrompt         () { return _app->promptFlightDataSave(); }
    bool    isSaveLogPromptNotArmed () { return _app->promptFlightDataSaveNotArmed(); }
167
    bool    virtualTabletJoystick   () { return _virtualTabletJoystick; }
168
    qreal   baseFontPointSize       () { return _baseFontPointSize; }
169

170 171 172 173
    bool    isMultiplexingEnabled   () { return _toolbox->mavlinkProtocol()->multiplexingEnabled(); }
    bool    isVersionCheckEnabled   () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
    int     mavlinkSystemID         () { return _toolbox->mavlinkProtocol()->getSystemId(); }

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

176 177 178
    static Fact* offlineEditingFirmwareType (void);
    static Fact* distanceUnits              (void);
    static Fact* speedUnits                 (void);
dogmaphobic's avatar
dogmaphobic committed
179

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

183 184 185 186
    void    setIsDarkStyle              (bool dark);
    void    setIsAudioMuted             (bool muted);
    void    setIsSaveLogPrompt          (bool prompt);
    void    setIsSaveLogPromptNotArmed  (bool prompt);
187
    void    setVirtualTabletJoystick    (bool enabled);
188
    void    setBaseFontPointSize        (qreal size);
189

190 191
    void    setIsMultiplexingEnabled    (bool enable);
    void    setIsVersionCheckEnabled    (bool enable);
192
    void    setMavlinkSystemID          (int  id);
dogmaphobic's avatar
dogmaphobic committed
193

194 195 196
    bool experimentalSurvey(void) const;
    void setExperimentalSurvey(bool experimentalSurvey);

Don Gagne's avatar
Don Gagne committed
197 198 199 200
    QString parameterFileExtension(void) const  { return QGCApplication::parameterFileExtension; }
    QString missionFileExtension(void) const    { return QGCApplication::missionFileExtension; }
    QString telemetryFileExtension(void) const  { return QGCApplication::telemetryFileExtension; }

201 202 203
    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

dogmaphobic's avatar
dogmaphobic committed
204 205 206 207
signals:
    void isDarkStyleChanged             (bool dark);
    void isAudioMutedChanged            (bool muted);
    void isSaveLogPromptChanged         (bool prompt);
208
    void isSaveLogPromptNotArmedChanged (bool prompt);
209
    void virtualTabletJoystickChanged   (bool enabled);
210
    void baseFontPointSizeChanged       (qreal size);
dogmaphobic's avatar
dogmaphobic committed
211 212
    void isMultiplexingEnabledChanged   (bool enabled);
    void isVersionCheckEnabledChanged   (bool enabled);
213
    void mavlinkSystemIDChanged         (int id);
214
    void flightMapPositionChanged       (QGeoCoordinate flightMapPosition);
215
    void flightMapZoomChanged           (double flightMapZoom);
216
    void experimentalSurveyChanged      (bool experimentalSurvey);
dogmaphobic's avatar
dogmaphobic committed
217

218
private:
219
    FlightMapSettings*      _flightMapSettings;
Don Gagne's avatar
Don Gagne committed
220 221 222 223
    HomePositionManager*    _homePositionManager;
    LinkManager*            _linkManager;
    MissionCommands*        _missionCommands;
    MultiVehicleManager*    _multiVehicleManager;
224
    QGCMapEngineManager*    _mapEngineManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
225
    QGCPositionManager*     _qgcPositionManager;
226

227 228 229 230
    bool                    _virtualTabletJoystick;
    qreal                   _baseFontPointSize;
    QGeoCoordinate          _flightMapPosition;
    double                  _flightMapZoom;
231 232 233 234 235 236 237 238

    // 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;
239

240
    static const char*  _virtualTabletJoystickKey;
241
    static const char*  _baseFontPointSizeKey;
242 243 244
};

#endif