QGroundControlQmlGlobal.cc 7.96 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 28
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
DonLakeFlyer's avatar
DonLakeFlyer committed
29
    , _flightMapInitialZoom(17.0)
30 31
    , _linkManager(NULL)
    , _multiVehicleManager(NULL)
dogmaphobic's avatar
dogmaphobic committed
32
    , _mapEngineManager(NULL)
33 34
    , _qgcPositionManager(NULL)
    , _missionCommandTree(NULL)
35
    , _videoManager(NULL)
Gus Grubba's avatar
Gus Grubba committed
36
    , _mavlinkLogManager(NULL)
37
    , _corePlugin(NULL)
Gus Grubba's avatar
Gus Grubba committed
38
    , _firmwarePluginManager(NULL)
39
    , _settingsManager(NULL)
40
    , _skipSetupPage(false)
41
{
42 43
    // 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.
    setParent(NULL);
44 45 46 47 48
}

QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{

49
}
50

51 52 53
void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
54

dogmaphobic's avatar
dogmaphobic committed
55 56
    _linkManager            = toolbox->linkManager();
    _multiVehicleManager    = toolbox->multiVehicleManager();
Jimmy Johnson's avatar
Jimmy Johnson committed
57
    _mapEngineManager       = toolbox->mapEngineManager();
58 59
    _qgcPositionManager     = toolbox->qgcPositionManager();
    _missionCommandTree     = toolbox->missionCommandTree();
60
    _videoManager           = toolbox->videoManager();
Gus Grubba's avatar
Gus Grubba committed
61
    _mavlinkLogManager      = toolbox->mavlinkLogManager();
62
    _corePlugin             = toolbox->corePlugin();
Gus Grubba's avatar
Gus Grubba committed
63
    _firmwarePluginManager  = toolbox->firmwarePluginManager();
64
    _settingsManager        = toolbox->settingsManager();
65

66
#ifndef __mobile__
67 68 69 70 71 72 73
   GPSManager *gpsManager = toolbox->gpsManager();
   if (gpsManager) {
       connect(gpsManager, &GPSManager::onConnect, this, &QGroundControlQmlGlobal::_onGPSConnect);
       connect(gpsManager, &GPSManager::onDisconnect, this, &QGroundControlQmlGlobal::_onGPSDisconnect);
       connect(gpsManager, &GPSManager::surveyInStatus, this, &QGroundControlQmlGlobal::_GPSSurveyInStatus);
       connect(gpsManager, &GPSManager::satelliteUpdate, this, &QGroundControlQmlGlobal::_GPSNumSatellites);
   }
74
#endif /* __mobile__ */
75 76
}

77 78 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
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();
}
104 105 106 107

void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
108
    MockLink::startPX4MockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
109 110
#else
    Q_UNUSED(sendStatusText);
111 112 113 114 115 116
#endif
}

void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
117
    MockLink::startGenericMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
118 119
#else
    Q_UNUSED(sendStatusText);
120 121 122 123 124 125
#endif
}

void QGroundControlQmlGlobal::startAPMArduCopterMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
126
    MockLink::startAPMArduCopterMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
127 128
#else
    Q_UNUSED(sendStatusText);
129 130 131 132 133 134
#endif
}

void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
135
    MockLink::startAPMArduPlaneMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
136 137
#else
    Q_UNUSED(sendStatusText);
138 139 140
#endif
}

141 142 143 144 145 146 147 148 149
void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduSubMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

Don Gagne's avatar
Don Gagne committed
150
void QGroundControlQmlGlobal::stopOneMockLink(void)
151 152 153 154
{
#ifdef QT_DEBUG
    LinkManager* linkManager = qgcApp()->toolbox()->linkManager();

155 156
    for (int i=0; i<linkManager->links().count(); i++) {
        LinkInterface* link = linkManager->links()[i];
157
        MockLink* mockLink = qobject_cast<MockLink*>(link);
Don Gagne's avatar
Don Gagne committed
158

159
        if (mockLink) {
Don Gagne's avatar
Don Gagne committed
160
            linkManager->disconnectLink(mockLink);
Don Gagne's avatar
Don Gagne committed
161
            return;
162 163 164 165
        }
    }
#endif
}
166

Don Gagne's avatar
Don Gagne committed
167 168 169 170 171 172
void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
    qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
    emit isVersionCheckEnabledChanged(enable);
}

173 174 175 176 177 178
void QGroundControlQmlGlobal::setMavlinkSystemID(int id)
{
    qgcApp()->toolbox()->mavlinkProtocol()->setSystemId(id);
    emit mavlinkSystemIDChanged(id);
}

Gus Grubba's avatar
Gus Grubba committed
179 180
int QGroundControlQmlGlobal::supportedFirmwareCount()
{
181
    return _firmwarePluginManager->supportedFirmwareTypes().count();
Gus Grubba's avatar
Gus Grubba committed
182 183 184
}


185 186 187 188 189 190 191
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;
}
192 193 194 195 196 197 198 199

void QGroundControlQmlGlobal::setSkipSetupPage(bool skip)
{
    if(_skipSetupPage != skip) {
        _skipSetupPage = skip;
        emit skipSetupPageChanged();
    }
}
200 201 202 203 204 205 206

QGeoCoordinate QGroundControlQmlGlobal::flightMapPosition(void)
{
    QSettings       settings;
    QGeoCoordinate  coord;

    settings.beginGroup(_flightMapPositionSettingsGroup);
207 208
    coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, 0).toDouble());
    coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, 0).toDouble());
209 210 211 212 213 214 215 216

    return coord;
}

double QGroundControlQmlGlobal::flightMapZoom(void)
{
    QSettings settings;

217 218
    settings.beginGroup(_flightMapPositionSettingsGroup);
    return settings.value(_flightMapZoomSettingsKey, 2).toDouble();
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
}

void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate)
{
    if (coordinate != flightMapPosition()) {
        QSettings settings;

        settings.beginGroup(_flightMapPositionSettingsGroup);
        settings.setValue(_flightMapPositionLatitudeSettingsKey, coordinate.latitude());
        settings.setValue(_flightMapPositionLongitudeSettingsKey, coordinate.longitude());
        emit flightMapPositionChanged(coordinate);
    }
}

void QGroundControlQmlGlobal::setFlightMapZoom(double zoom)
{
    if (zoom != flightMapZoom()) {
        QSettings settings;

238
        settings.beginGroup(_flightMapPositionSettingsGroup);
239 240 241 242
        settings.setValue(_flightMapZoomSettingsKey, zoom);
        emit flightMapZoomChanged(zoom);
    }
}
243 244 245 246 247 248 249 250 251 252 253 254

void QGroundControlQmlGlobal::_onGPSConnect()
{
    _gpsRtkFactGroup.connected()->setRawValue(true);
}
void QGroundControlQmlGlobal::_onGPSDisconnect()
{
    _gpsRtkFactGroup.connected()->setRawValue(false);
}
void QGroundControlQmlGlobal::_GPSSurveyInStatus(float duration, float accuracyMM, bool valid, bool active)
{
    _gpsRtkFactGroup.currentDuration()->setRawValue(duration);
DonLakeFlyer's avatar
DonLakeFlyer committed
255
    _gpsRtkFactGroup.currentAccuracy()->setRawValue(accuracyMM/1000.0);
256 257 258 259 260 261 262 263
    _gpsRtkFactGroup.valid()->setRawValue(valid);
    _gpsRtkFactGroup.active()->setRawValue(active);
}
void QGroundControlQmlGlobal::_GPSNumSatellites(int numSatellites)
{
    _gpsRtkFactGroup.numSatellites()->setRawValue(numSatellites);
}