QGCCorePlugin.cc 5.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#include "QGCCorePlugin.h"
#include "QGCOptions.h"
#include "QGCSettings.h"
13
#include "FactMetaData.h"
Don Gagne's avatar
Don Gagne committed
14
#include "SettingsManager.h"
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

#include <QtQml>
#include <QQmlEngine>

/// @file
///     @brief Core Plugin Interface for QGroundControl - Default Implementation
///     @author Gus Grubba <mavlink@grubba.com>

class QGCCorePlugin_p
{
public:
    QGCCorePlugin_p()
        : pGeneral(NULL)
        , pCommLinks(NULL)
        , pOfflineMaps(NULL)
        , pMAVLink(NULL)
        , pConsole(NULL)
DonLakeFlyer's avatar
DonLakeFlyer committed
32
    #if defined(QT_DEBUG)
33 34
        , pMockLink(NULL)
        , pDebug(NULL)
DonLakeFlyer's avatar
DonLakeFlyer committed
35
    #endif
36 37 38
        , defaultOptions(NULL)
    {
    }
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    ~QGCCorePlugin_p()
    {
        if(pGeneral)
            delete pGeneral;
        if(pCommLinks)
            delete pCommLinks;
        if(pOfflineMaps)
            delete pOfflineMaps;
        if(pMAVLink)
            delete pMAVLink;
        if(pConsole)
            delete pConsole;
#if defined(QT_DEBUG)
        if(pMockLink)
            delete pMockLink;
        if(pDebug)
            delete pDebug;
#endif
        if(defaultOptions)
            delete defaultOptions;
    }
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    QGCSettings* pGeneral;
    QGCSettings* pCommLinks;
    QGCSettings* pOfflineMaps;
    QGCSettings* pMAVLink;
    QGCSettings* pConsole;
#if defined(QT_DEBUG)
    QGCSettings* pMockLink;
    QGCSettings* pDebug;
#endif
    QVariantList settingsList;
    QGCOptions*  defaultOptions;
};

QGCCorePlugin::~QGCCorePlugin()
{
    if(_p) {
        delete _p;
    }
}

82 83
QGCCorePlugin::QGCCorePlugin(QGCApplication *app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
84
    , _showTouchAreas(false)
85
    , _showAdvancedUI(true)
86 87 88 89 90 91
{
    _p = new QGCCorePlugin_p;
}

void QGCCorePlugin::setToolbox(QGCToolbox *toolbox)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
92 93 94 95
    QGCTool::setToolbox(toolbox);
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<QGCCorePlugin>("QGroundControl.QGCCorePlugin", 1, 0, "QGCCorePlugin", "Reference only");
    qmlRegisterUncreatableType<QGCOptions>("QGroundControl.QGCOptions",       1, 0, "QGCOptions",    "Reference only");
96 97
}

98
QVariantList &QGCCorePlugin::settingsPages()
99 100 101 102
{
    //-- If this hasn't been overridden, create default set of settings
    if(!_p->pGeneral) {
        //-- Default Settings
Gus Grubba's avatar
Gus Grubba committed
103
        _p->pGeneral = new QGCSettings(tr("General"),
DonLakeFlyer's avatar
DonLakeFlyer committed
104 105
                                       QUrl::fromUserInput("qrc:/qml/GeneralSettings.qml"),
                                       QUrl::fromUserInput("qrc:/res/gear-white.svg"));
Gus Grubba's avatar
Gus Grubba committed
106 107
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pGeneral));
        _p->pCommLinks = new QGCSettings(tr("Comm Links"),
DonLakeFlyer's avatar
DonLakeFlyer committed
108 109
                                         QUrl::fromUserInput("qrc:/qml/LinkSettings.qml"),
                                         QUrl::fromUserInput("qrc:/res/waves.svg"));
Gus Grubba's avatar
Gus Grubba committed
110 111
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pCommLinks));
        _p->pOfflineMaps = new QGCSettings(tr("Offline Maps"),
DonLakeFlyer's avatar
DonLakeFlyer committed
112 113
                                           QUrl::fromUserInput("qrc:/qml/OfflineMap.qml"),
                                           QUrl::fromUserInput("qrc:/res/waves.svg"));
Gus Grubba's avatar
Gus Grubba committed
114 115
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pOfflineMaps));
        _p->pMAVLink = new QGCSettings(tr("MAVLink"),
DonLakeFlyer's avatar
DonLakeFlyer committed
116 117
                                       QUrl::fromUserInput("qrc:/qml/MavlinkSettings.qml"),
                                       QUrl::fromUserInput("qrc:/res/waves.svg"));
Gus Grubba's avatar
Gus Grubba committed
118 119
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pMAVLink));
        _p->pConsole = new QGCSettings(tr("Console"),
DonLakeFlyer's avatar
DonLakeFlyer committed
120
                                       QUrl::fromUserInput("qrc:/qml/QGroundControl/Controls/AppMessages.qml"));
Gus Grubba's avatar
Gus Grubba committed
121
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pConsole));
DonLakeFlyer's avatar
DonLakeFlyer committed
122
#if defined(QT_DEBUG)
123
        //-- These are always present on Debug builds
Gus Grubba's avatar
Gus Grubba committed
124
        _p->pMockLink = new QGCSettings(tr("Mock Link"),
DonLakeFlyer's avatar
DonLakeFlyer committed
125
                                        QUrl::fromUserInput("qrc:/qml/MockLink.qml"));
Gus Grubba's avatar
Gus Grubba committed
126 127
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pMockLink));
        _p->pDebug = new QGCSettings(tr("Debug"),
DonLakeFlyer's avatar
DonLakeFlyer committed
128
                                     QUrl::fromUserInput("qrc:/qml/DebugWindow.qml"));
Gus Grubba's avatar
Gus Grubba committed
129
        _p->settingsList.append(QVariant::fromValue((QGCSettings*)_p->pDebug));
DonLakeFlyer's avatar
DonLakeFlyer committed
130
#endif
131 132 133 134
    }
    return _p->settingsList;
}

135
int QGCCorePlugin::defaultSettings()
136 137 138 139
{
    return 0;
}

140 141 142 143 144 145 146 147
QGCOptions* QGCCorePlugin::options()
{
    if(!_p->defaultOptions) {
        _p->defaultOptions = new QGCOptions();
    }
    return _p->defaultOptions;
}

148 149 150
bool QGCCorePlugin::overrideSettingsGroupVisibility(QString name)
{
    Q_UNUSED(name);
151

152 153 154
    // Always show all
    return true;
}
155 156 157

bool QGCCorePlugin::adjustSettingMetaData(FactMetaData& metaData)
{
Don Gagne's avatar
Don Gagne committed
158 159 160 161 162 163 164 165 166 167 168
    if (metaData.name() == AppSettings::indoorPaletteName) {
        // Set up correct default for palette setting
        QVariant outdoorPalette;
#if defined (__mobile__)
        outdoorPalette = 0;
#else
        outdoorPalette = 1;
#endif
        metaData.setRawDefaultValue(outdoorPalette);
    }

169 170
    return true;        // Show setting in ui
}
DonLakeFlyer's avatar
DonLakeFlyer committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

void QGCCorePlugin::setShowTouchAreas(bool show)
{
    if (show != _showTouchAreas) {
        _showTouchAreas = show;
        emit showTouchAreasChanged(show);
    }
}

void QGCCorePlugin::setShowAdvancedUI(bool show)
{
    if (show != _showAdvancedUI) {
        _showAdvancedUI = show;
        emit showAdvancedUIChanged(show);
    }
}
187 188 189 190 191 192

void QGCCorePlugin::paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
{
    Q_UNUSED(colorName);
    Q_UNUSED(colorInfo);
}