QGroundControlQmlGlobal.h 10.8 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 "FlightMapSettings.h"
21
#include "SettingsFact.h"
22
#include "FactMetaData.h"
Jimmy Johnson's avatar
Jimmy Johnson committed
23
#include "SimulatedPosition.h"
24
#include "QGCLoggingCategory.h"
25

26 27 28 29
#ifdef QT_DEBUG
#include "MockLink.h"
#endif

30 31
class QGCToolbox;

32
class QGroundControlQmlGlobal : public QGCTool
33 34 35 36
{
    Q_OBJECT

public:
37 38 39
    QGroundControlQmlGlobal(QGCApplication* app);
    ~QGroundControlQmlGlobal();

Don Gagne's avatar
Don Gagne committed
40
    Q_PROPERTY(FlightMapSettings*   flightMapSettings   READ flightMapSettings      CONSTANT)
Don Gagne's avatar
Don Gagne committed
41 42
    Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
Don Gagne's avatar
Don Gagne committed
43
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
Jimmy Johnson's avatar
Jimmy Johnson committed
44
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
45
    Q_PROPERTY(MissionCommandTree*  missionCommandTree  READ missionCommandTree     CONSTANT)
46
    Q_PROPERTY(VideoManager*        videoManager        READ videoManager           CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
47
    Q_PROPERTY(MAVLinkLogManager*   mavlinkLogManager   READ mavlinkLogManager      CONSTANT)
48
    Q_PROPERTY(QGCCorePlugin*       corePlugin          READ corePlugin             CONSTANT)
49 50 51
    Q_PROPERTY(SettingsManager*     settingsManager     READ settingsManager        CONSTANT)

    Q_PROPERTY(int      supportedFirmwareCount          READ supportedFirmwareCount             CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
52 53 54 55 56

    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

57 58
    // Various QGC settings exposed to Qml
    Q_PROPERTY(bool     isDarkStyle             READ isDarkStyle                WRITE setIsDarkStyle                NOTIFY isDarkStyleChanged)              // TODO: Should be in ScreenTools?
59
    Q_PROPERTY(bool     virtualTabletJoystick   READ virtualTabletJoystick      WRITE setVirtualTabletJoystick      NOTIFY virtualTabletJoystickChanged)
60
    Q_PROPERTY(qreal    baseFontPointSize       READ baseFontPointSize          WRITE setBaseFontPointSize          NOTIFY baseFontPointSizeChanged)
61

Gus Grubba's avatar
Gus Grubba committed
62
    //-------------------------------------------------------------------------
63
    // MavLink Protocol
Don Gagne's avatar
Don Gagne committed
64
    Q_PROPERTY(bool     isVersionCheckEnabled   READ isVersionCheckEnabled      WRITE setIsVersionCheckEnabled      NOTIFY isVersionCheckEnabledChanged)
65
    Q_PROPERTY(int      mavlinkSystemID         READ mavlinkSystemID            WRITE setMavlinkSystemID            NOTIFY mavlinkSystemIDChanged)
dogmaphobic's avatar
dogmaphobic committed
66

67 68
    Q_PROPERTY(QGeoCoordinate lastKnownHomePosition READ lastKnownHomePosition  CONSTANT)
    Q_PROPERTY(QGeoCoordinate flightMapPosition     MEMBER _flightMapPosition   NOTIFY flightMapPositionChanged)
69
    Q_PROPERTY(double         flightMapZoom         MEMBER _flightMapZoom       NOTIFY flightMapZoomChanged)
Don Gagne's avatar
Don Gagne committed
70

Don Gagne's avatar
Don Gagne committed
71 72 73 74
    Q_PROPERTY(QString  parameterFileExtension  READ parameterFileExtension CONSTANT)
    Q_PROPERTY(QString  missionFileExtension    READ missionFileExtension   CONSTANT)
    Q_PROPERTY(QString  telemetryFileExtension  READ telemetryFileExtension CONSTANT)

75 76
    /// Returns the string for distance units which has configued by user
    Q_PROPERTY(QString appSettingsDistanceUnitsString READ appSettingsDistanceUnitsString CONSTANT)
77
    Q_PROPERTY(QString appSettingsAreaUnitsString READ appSettingsAreaUnitsString CONSTANT)
78

79 80
    Q_PROPERTY(QString qgcVersion READ qgcVersion CONSTANT)

81 82 83 84 85
    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);

86 87
    Q_INVOKABLE void    deleteAllSettingsNextBoot       () { _app->deleteAllSettingsNextBoot(); }
    Q_INVOKABLE void    clearDeleteAllSettingsNextBoot  () { _app->clearDeleteAllSettingsNextBoot(); }
88

89 90 91 92
    Q_INVOKABLE void    startPX4MockLink            (bool sendStatusText);
    Q_INVOKABLE void    startGenericMockLink        (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduCopterMockLink  (bool sendStatusText);
    Q_INVOKABLE void    startAPMArduPlaneMockLink   (bool sendStatusText);
93
    Q_INVOKABLE void    startAPMArduSubMockLink     (bool sendStatusText);
94 95
    Q_INVOKABLE void    stopAllMockLinks            (void);

96 97 98 99 100 101 102 103
    /// 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(); }

104 105 106 107 108 109 110 111
    /// 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(); }

112 113 114 115
    /// 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
116
    Q_INVOKABLE void setCategoryLoggingOn(const QString& category, bool enable) { QGCLoggingCategoryRegister::instance()->setCategoryLoggingOn(category, enable); }
117 118

    /// Returns true if logging is turned on for the specified category.
Don Gagne's avatar
Don Gagne committed
119
    Q_INVOKABLE bool categoryLoggingOn(const QString& category) { return QGCLoggingCategoryRegister::instance()->categoryLoggingOn(category); }
120 121 122 123

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

124 125
    Q_INVOKABLE bool linesIntersect(QPointF xLine1, QPointF yLine1, QPointF xLine2, QPointF yLine2);

126 127
    Q_INVOKABLE QString urlToLocalFile(QUrl url) { return url.toLocalFile(); }

128
    // Property accesors
Gus Grubba's avatar
Gus Grubba committed
129

130 131 132 133 134 135 136 137 138 139 140 141 142 143
    FlightMapSettings*      flightMapSettings   ()  { return _flightMapSettings; }
    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; }

    qreal                   zOrderTopMost       ()  { return 1000; }
    qreal                   zOrderWidgets       ()  { return 100; }
    qreal                   zOrderMapItems      ()  { return 50; }
Gus Grubba's avatar
Gus Grubba committed
144

145
    bool    isDarkStyle             () { return _app->styleIsDark(); }
146
    bool    virtualTabletJoystick   () { return _virtualTabletJoystick; }
147
    qreal   baseFontPointSize       () { return _baseFontPointSize; }
148

Don Gagne's avatar
Don Gagne committed
149
    bool    isVersionCheckEnabled   () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
150 151
    int     mavlinkSystemID         () { return _toolbox->mavlinkProtocol()->getSystemId(); }

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

Gus Grubba's avatar
Gus Grubba committed
154 155
    int     supportedFirmwareCount      ();

156
    void    setIsDarkStyle              (bool dark);
157
    void    setVirtualTabletJoystick    (bool enabled);
158
    void    setBaseFontPointSize        (qreal size);
159

Don Gagne's avatar
Don Gagne committed
160
    void    setIsVersionCheckEnabled    (bool enable);
161
    void    setMavlinkSystemID          (int  id);
dogmaphobic's avatar
dogmaphobic committed
162

Don Gagne's avatar
Don Gagne committed
163 164 165 166
    QString parameterFileExtension(void) const  { return QGCApplication::parameterFileExtension; }
    QString missionFileExtension(void) const    { return QGCApplication::missionFileExtension; }
    QString telemetryFileExtension(void) const  { return QGCApplication::telemetryFileExtension; }

167 168
    QString qgcVersion(void) const { return qgcApp()->applicationVersion(); }

169 170 171
    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

dogmaphobic's avatar
dogmaphobic committed
172 173
signals:
    void isDarkStyleChanged             (bool dark);
174
    void virtualTabletJoystickChanged   (bool enabled);
175
    void baseFontPointSizeChanged       (qreal size);
dogmaphobic's avatar
dogmaphobic committed
176
    void isMultiplexingEnabledChanged   (bool enabled);
Don Gagne's avatar
Don Gagne committed
177
    void isVersionCheckEnabledChanged   (bool enabled);
178
    void mavlinkSystemIDChanged         (int id);
179
    void flightMapPositionChanged       (QGeoCoordinate flightMapPosition);
180
    void flightMapZoomChanged           (double flightMapZoom);
dogmaphobic's avatar
dogmaphobic committed
181

182
private:
183
    FlightMapSettings*      _flightMapSettings;
Don Gagne's avatar
Don Gagne committed
184 185
    LinkManager*            _linkManager;
    MultiVehicleManager*    _multiVehicleManager;
186
    QGCMapEngineManager*    _mapEngineManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
187
    QGCPositionManager*     _qgcPositionManager;
188
    MissionCommandTree*     _missionCommandTree;
189
    VideoManager*           _videoManager;
Gus Grubba's avatar
Gus Grubba committed
190
    MAVLinkLogManager*      _mavlinkLogManager;
191
    QGCCorePlugin*          _corePlugin;
Gus Grubba's avatar
Gus Grubba committed
192
    FirmwarePluginManager*  _firmwarePluginManager;
193
    SettingsManager*        _settingsManager;
194

195 196 197 198
    bool                    _virtualTabletJoystick;
    qreal                   _baseFontPointSize;
    QGeoCoordinate          _flightMapPosition;
    double                  _flightMapZoom;
199

200
    static const char*  _virtualTabletJoystickKey;
201
    static const char*  _baseFontPointSizeKey;
202 203 204
};

#endif