QGroundControlQmlGlobal.cc 7.03 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 32 33 34 35 36 37 38 39 40
    : QGCTool               (app, toolbox)
    , _flightMapInitialZoom (17.0)
    , _linkManager          (NULL)
    , _multiVehicleManager  (NULL)
    , _mapEngineManager     (NULL)
    , _qgcPositionManager   (NULL)
    , _missionCommandTree   (NULL)
    , _videoManager         (NULL)
    , _mavlinkLogManager    (NULL)
    , _corePlugin           (NULL)
Gus Grubba's avatar
Gus Grubba committed
41
    , _firmwarePluginManager(NULL)
42 43 44 45
    , _settingsManager      (NULL)
    , _gpsRtkFactGroup      (nullptr)
    , _airspaceManager      (NULL)
    , _skipSetupPage        (false)
46
{
47 48
    // 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);
49 50 51
    // Load last coordinates and zoom from config file
    QSettings settings;
    settings.beginGroup(_flightMapPositionSettingsGroup);
52 53 54
    _coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey,    _coord.latitude()).toDouble());
    _coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey,  _coord.longitude()).toDouble());
    _zoom = settings.value(_flightMapZoomSettingsKey, _zoom).toDouble();
55 56 57 58
}

QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{
59 60 61 62 63 64
    // 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);
65
}
66

67 68 69
void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
70

dogmaphobic's avatar
dogmaphobic committed
71 72
    _linkManager            = toolbox->linkManager();
    _multiVehicleManager    = toolbox->multiVehicleManager();
Jimmy Johnson's avatar
Jimmy Johnson committed
73
    _mapEngineManager       = toolbox->mapEngineManager();
74 75
    _qgcPositionManager     = toolbox->qgcPositionManager();
    _missionCommandTree     = toolbox->missionCommandTree();
76
    _videoManager           = toolbox->videoManager();
Gus Grubba's avatar
Gus Grubba committed
77
    _mavlinkLogManager      = toolbox->mavlinkLogManager();
78
    _corePlugin             = toolbox->corePlugin();
Gus Grubba's avatar
Gus Grubba committed
79
    _firmwarePluginManager  = toolbox->firmwarePluginManager();
80
    _settingsManager        = toolbox->settingsManager();
81
    _gpsRtkFactGroup        = qgcApp()->gpsRtkFactGroup();
82
    _airspaceManager        = toolbox->airspaceManager();
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 108 109 110 111
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();
}
112 113 114 115

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

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

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

void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
143
    MockLink::startAPMArduPlaneMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
144 145
#else
    Q_UNUSED(sendStatusText);
146 147 148
#endif
}

149 150 151 152 153 154 155 156 157
void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduSubMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

Don Gagne's avatar
Don Gagne committed
158
void QGroundControlQmlGlobal::stopOneMockLink(void)
159 160 161 162
{
#ifdef QT_DEBUG
    LinkManager* linkManager = qgcApp()->toolbox()->linkManager();

163 164
    for (int i=0; i<linkManager->links().count(); i++) {
        LinkInterface* link = linkManager->links()[i];
165
        MockLink* mockLink = qobject_cast<MockLink*>(link);
Don Gagne's avatar
Don Gagne committed
166

167
        if (mockLink) {
Don Gagne's avatar
Don Gagne committed
168
            linkManager->disconnectLink(mockLink);
Don Gagne's avatar
Don Gagne committed
169
            return;
170 171 172 173
        }
    }
#endif
}
174

Don Gagne's avatar
Don Gagne committed
175 176 177 178 179 180
void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
    qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
    emit isVersionCheckEnabledChanged(enable);
}

181 182 183 184 185 186
void QGroundControlQmlGlobal::setMavlinkSystemID(int id)
{
    qgcApp()->toolbox()->mavlinkProtocol()->setSystemId(id);
    emit mavlinkSystemIDChanged(id);
}

Gus Grubba's avatar
Gus Grubba committed
187 188
int QGroundControlQmlGlobal::supportedFirmwareCount()
{
189
    return _firmwarePluginManager->supportedFirmwareTypes().count();
Gus Grubba's avatar
Gus Grubba committed
190 191 192
}


193 194 195 196 197 198 199
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;
}
200 201 202 203 204 205 206 207

void QGroundControlQmlGlobal::setSkipSetupPage(bool skip)
{
    if(_skipSetupPage != skip) {
        _skipSetupPage = skip;
        emit skipSetupPageChanged();
    }
}
208 209 210 211

void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate)
{
    if (coordinate != flightMapPosition()) {
212 213
        _coord.setLatitude(coordinate.latitude());
        _coord.setLongitude(coordinate.longitude());
214 215 216 217 218 219 220 221

        emit flightMapPositionChanged(coordinate);
    }
}

void QGroundControlQmlGlobal::setFlightMapZoom(double zoom)
{
    if (zoom != flightMapZoom()) {
222
        _zoom = zoom;
223 224 225
        emit flightMapZoomChanged(zoom);
    }
}