QGroundControlQmlGlobal.cc 8.06 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.
 *
 ****************************************************************************/
9

10 11 12 13 14

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

#include "QGroundControlQmlGlobal.h"
15 16

#include <QSettings>
Don Gagne's avatar
Don Gagne committed
17 18
#include <QLineF>
#include <QPointF>
19

Don Gagne's avatar
Don Gagne committed
20
static const char* kQmlGlobalKeyName = "QGCQml";
21

22 23 24 25 26
const char* QGroundControlQmlGlobal::_flightMapPositionSettingsGroup =          "FlightMapPosition";
const char* QGroundControlQmlGlobal::_flightMapPositionLatitudeSettingsKey =    "Latitude";
const char* QGroundControlQmlGlobal::_flightMapPositionLongitudeSettingsKey =   "Longitude";
const char* QGroundControlQmlGlobal::_flightMapZoomSettingsKey =                "FlightMapZoom";

27
QGeoCoordinate   QGroundControlQmlGlobal::_coord = QGeoCoordinate(0.0,0.0);
28
double           QGroundControlQmlGlobal::_zoom = 2;
29

30
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox)
31
    : QGCTool               (app, toolbox)
32
{
33
    // We clear the parent on this object since we run into shutdown problems caused by hybrid qml app. Instead we let it leak on shutdown.
34
    setParent(nullptr);
35 36 37
    // Load last coordinates and zoom from config file
    QSettings settings;
    settings.beginGroup(_flightMapPositionSettingsGroup);
38 39 40
    _coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey,    _coord.latitude()).toDouble());
    _coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey,  _coord.longitude()).toDouble());
    _zoom = settings.value(_flightMapZoomSettingsKey, _zoom).toDouble();
41 42 43 44
}

QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{
45 46 47 48 49 50
    // Save last coordinates and zoom to config file
    QSettings settings;
    settings.beginGroup(_flightMapPositionSettingsGroup);
    settings.setValue(_flightMapPositionLatitudeSettingsKey, _coord.latitude());
    settings.setValue(_flightMapPositionLongitudeSettingsKey, _coord.longitude());
    settings.setValue(_flightMapZoomSettingsKey, _zoom);
51
}
52

53 54 55
void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
56

dogmaphobic's avatar
dogmaphobic committed
57 58
    _linkManager            = toolbox->linkManager();
    _multiVehicleManager    = toolbox->multiVehicleManager();
Jimmy Johnson's avatar
Jimmy Johnson committed
59
    _mapEngineManager       = toolbox->mapEngineManager();
60 61
    _qgcPositionManager     = toolbox->qgcPositionManager();
    _missionCommandTree     = toolbox->missionCommandTree();
62
    _videoManager           = toolbox->videoManager();
Gus Grubba's avatar
Gus Grubba committed
63
    _mavlinkLogManager      = toolbox->mavlinkLogManager();
64
    _corePlugin             = toolbox->corePlugin();
Gus Grubba's avatar
Gus Grubba committed
65
    _firmwarePluginManager  = toolbox->firmwarePluginManager();
66
    _settingsManager        = toolbox->settingsManager();
67
    _gpsRtkFactGroup        = qgcApp()->gpsRtkFactGroup();
68
    _airspaceManager        = toolbox->airspaceManager();
69
    _adsbVehicleManager     = toolbox->adsbVehicleManager();
Gus Grubba's avatar
Gus Grubba committed
70 71 72
#if defined(QGC_ENABLE_PAIRING)
    _pairingManager         = toolbox->pairingManager();
#endif
73
#if defined(QGC_GST_TAISYNC_ENABLED)
74 75
    _taisyncManager         = toolbox->taisyncManager();
#endif
76 77 78
#if defined(QGC_GST_MICROHARD_ENABLED)
    _microhardManager       = toolbox->microhardManager();
#endif
79 80
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
void QGroundControlQmlGlobal::saveGlobalSetting (const QString& key, const QString& value)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    settings.setValue(key, value);
}

QString QGroundControlQmlGlobal::loadGlobalSetting (const QString& key, const QString& defaultValue)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    return settings.value(key, defaultValue).toString();
}

void QGroundControlQmlGlobal::saveBoolGlobalSetting (const QString& key, bool value)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    settings.setValue(key, value);
}

bool QGroundControlQmlGlobal::loadBoolGlobalSetting (const QString& key, bool defaultValue)
{
    QSettings settings;
    settings.beginGroup(kQmlGlobalKeyName);
    return settings.value(key, defaultValue).toBool();
}
108 109 110 111

void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
112
    MockLink::startPX4MockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
113 114
#else
    Q_UNUSED(sendStatusText);
115 116 117 118 119 120
#endif
}

void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
121
    MockLink::startGenericMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
122 123
#else
    Q_UNUSED(sendStatusText);
124 125 126 127 128 129
#endif
}

void QGroundControlQmlGlobal::startAPMArduCopterMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
130
    MockLink::startAPMArduCopterMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
131 132
#else
    Q_UNUSED(sendStatusText);
133 134 135 136 137 138
#endif
}

void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
139
    MockLink::startAPMArduPlaneMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
140 141
#else
    Q_UNUSED(sendStatusText);
142 143 144
#endif
}

145 146 147 148 149 150 151 152 153
void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduSubMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

154 155 156 157 158 159 160 161 162
void QGroundControlQmlGlobal::startAPMArduRoverMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduRoverMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

Don Gagne's avatar
Don Gagne committed
163
void QGroundControlQmlGlobal::stopOneMockLink(void)
164 165 166 167
{
#ifdef QT_DEBUG
    LinkManager* linkManager = qgcApp()->toolbox()->linkManager();

168 169
    for (int i=0; i<linkManager->links().count(); i++) {
        LinkInterface* link = linkManager->links()[i];
170
        MockLink* mockLink = qobject_cast<MockLink*>(link);
Don Gagne's avatar
Don Gagne committed
171

172
        if (mockLink) {
Don Gagne's avatar
Don Gagne committed
173
            linkManager->disconnectLink(mockLink);
Don Gagne's avatar
Don Gagne committed
174
            return;
175 176 177 178
        }
    }
#endif
}
179

Don Gagne's avatar
Don Gagne committed
180 181 182 183 184 185
void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
    qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
    emit isVersionCheckEnabledChanged(enable);
}

186 187 188 189 190 191
void QGroundControlQmlGlobal::setMavlinkSystemID(int id)
{
    qgcApp()->toolbox()->mavlinkProtocol()->setSystemId(id);
    emit mavlinkSystemIDChanged(id);
}

Gus Grubba's avatar
Gus Grubba committed
192 193
int QGroundControlQmlGlobal::supportedFirmwareCount()
{
194
    return _firmwarePluginManager->supportedFirmwareTypes().count();
Gus Grubba's avatar
Gus Grubba committed
195 196
}

197 198 199 200 201 202 203 204 205 206 207 208
int QGroundControlQmlGlobal::supportedVehicleCount()
{
    int count = 0;
    QList<MAV_AUTOPILOT> list = _firmwarePluginManager->supportedFirmwareTypes();
    foreach(auto firmware, list) {
        if(firmware != MAV_AUTOPILOT_GENERIC) {
            count += _firmwarePluginManager->supportedVehicleTypes(firmware).count();
        }
    }
    return count;
}

209 210 211 212 213 214 215 216 217
bool QGroundControlQmlGlobal::px4ProFirmwareSupported()
{
    return _firmwarePluginManager->supportedFirmwareTypes().contains(MAV_AUTOPILOT_PX4);
}

bool QGroundControlQmlGlobal::apmFirmwareSupported()
{
    return _firmwarePluginManager->supportedFirmwareTypes().contains(MAV_AUTOPILOT_ARDUPILOTMEGA);
}
Gus Grubba's avatar
Gus Grubba committed
218

219 220 221 222 223 224 225
bool QGroundControlQmlGlobal::linesIntersect(QPointF line1A, QPointF line1B, QPointF line2A, QPointF line2B)
{
    QPointF intersectPoint;

    return QLineF(line1A, line1B).intersect(QLineF(line2A, line2B), &intersectPoint) == QLineF::BoundedIntersection &&
            intersectPoint != line1A && intersectPoint != line1B;
}
226 227 228 229 230 231 232 233

void QGroundControlQmlGlobal::setSkipSetupPage(bool skip)
{
    if(_skipSetupPage != skip) {
        _skipSetupPage = skip;
        emit skipSetupPageChanged();
    }
}
234 235 236 237

void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate)
{
    if (coordinate != flightMapPosition()) {
238 239
        _coord.setLatitude(coordinate.latitude());
        _coord.setLongitude(coordinate.longitude());
240 241 242 243 244 245 246 247

        emit flightMapPositionChanged(coordinate);
    }
}

void QGroundControlQmlGlobal::setFlightMapZoom(double zoom)
{
    if (zoom != flightMapZoom()) {
248
        _zoom = zoom;
249 250 251
        emit flightMapZoomChanged(zoom);
    }
}
252 253 254 255 256 257 258 259 260 261 262

QString QGroundControlQmlGlobal::qgcVersion(void) const
{
    QString versionStr = qgcApp()->applicationVersion();
#ifdef __androidArm32__
    versionStr += QStringLiteral(" %1").arg(tr("32 bit"));
#elif __androidArm64__
    versionStr += QStringLiteral(" %1").arg(tr("64 bit"));
#endif
    return versionStr;
}