QGroundControlQmlGlobal.cc 5.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
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
    : QGCTool(app)
    , _flightMapSettings(NULL)
    , _linkManager(NULL)
    , _multiVehicleManager(NULL)
dogmaphobic's avatar
dogmaphobic committed
27
    , _mapEngineManager(NULL)
28 29
    , _qgcPositionManager(NULL)
    , _missionCommandTree(NULL)
30
    , _videoManager(NULL)
Gus Grubba's avatar
Gus Grubba committed
31
    , _mavlinkLogManager(NULL)
32
    , _corePlugin(NULL)
Gus Grubba's avatar
Gus Grubba committed
33
    , _firmwarePluginManager(NULL)
34
    , _settingsManager(NULL)
35
    , _skipSetupPage(false)
36
{
37 38
    // 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);
39 40 41 42 43
}

QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{

44
}
45

46 47 48
void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
49

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

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
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();
}
90 91 92 93

void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
94
    MockLink::startPX4MockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
95 96
#else
    Q_UNUSED(sendStatusText);
97 98 99 100 101 102
#endif
}

void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
103
    MockLink::startGenericMockLink(sendStatusText);
Don Gagne's avatar
Don Gagne committed
104 105
#else
    Q_UNUSED(sendStatusText);
106 107 108 109 110 111
#endif
}

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

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

127 128 129 130 131 132 133 134 135
void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText)
{
#ifdef QT_DEBUG
    MockLink::startAPMArduSubMockLink(sendStatusText);
#else
    Q_UNUSED(sendStatusText);
#endif
}

136 137 138 139 140
void QGroundControlQmlGlobal::stopAllMockLinks(void)
{
#ifdef QT_DEBUG
    LinkManager* linkManager = qgcApp()->toolbox()->linkManager();

141 142
    for (int i=0; i<linkManager->links().count(); i++) {
        LinkInterface* link = linkManager->links()[i];
143
        MockLink* mockLink = qobject_cast<MockLink*>(link);
Don Gagne's avatar
Don Gagne committed
144

145
        if (mockLink) {
Don Gagne's avatar
Don Gagne committed
146
            linkManager->disconnectLink(mockLink);
147 148 149 150
        }
    }
#endif
}
151

Don Gagne's avatar
Don Gagne committed
152 153 154 155 156 157
void QGroundControlQmlGlobal::setIsVersionCheckEnabled(bool enable)
{
    qgcApp()->toolbox()->mavlinkProtocol()->enableVersionCheck(enable);
    emit isVersionCheckEnabledChanged(enable);
}

158 159 160 161 162 163
void QGroundControlQmlGlobal::setMavlinkSystemID(int id)
{
    qgcApp()->toolbox()->mavlinkProtocol()->setSystemId(id);
    emit mavlinkSystemIDChanged(id);
}

Gus Grubba's avatar
Gus Grubba committed
164 165
int QGroundControlQmlGlobal::supportedFirmwareCount()
{
166
    return _firmwarePluginManager->supportedFirmwareTypes().count();
Gus Grubba's avatar
Gus Grubba committed
167 168 169
}


170 171 172 173 174 175 176
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;
}
177 178 179 180 181 182 183 184

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