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

10
#include "QGCApplication.h"
11 12
#include "QGCCorePlugin.h"
#include "QGCOptions.h"
13
#include "QmlPageInfo.h"
14
#include "FactMetaData.h"
Don Gagne's avatar
Don Gagne committed
15
#include "SettingsManager.h"
16
#include "AppMessages.h"
17 18 19 20 21 22 23 24 25 26 27 28

#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()
29 30 31 32 33
        : pGeneral                  (NULL)
        , pCommLinks                (NULL)
        , pOfflineMaps              (NULL)
        , pMAVLink                  (NULL)
        , pConsole                  (NULL)
DonLakeFlyer's avatar
DonLakeFlyer committed
34
    #if defined(QT_DEBUG)
35 36
        , pMockLink                 (NULL)
        , pDebug                    (NULL)
DonLakeFlyer's avatar
DonLakeFlyer committed
37
    #endif
38 39 40 41 42
        , defaultOptions            (NULL)
        , valuesPageWidgetInfo      (NULL)
        , cameraPageWidgetInfo      (NULL)
        , healthPageWidgetInfo      (NULL)
        , vibrationPageWidgetInfo   (NULL)
43 44
    {
    }
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    ~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;
    }
67

68 69 70 71 72
    QmlPageInfo* pGeneral;
    QmlPageInfo* pCommLinks;
    QmlPageInfo* pOfflineMaps;
    QmlPageInfo* pMAVLink;
    QmlPageInfo* pConsole;
73
#if defined(QT_DEBUG)
74 75
    QmlPageInfo* pMockLink;
    QmlPageInfo* pDebug;
76 77 78
#endif
    QVariantList settingsList;
    QGCOptions*  defaultOptions;
79 80 81 82 83 84

    QmlPageInfo*    valuesPageWidgetInfo;
    QmlPageInfo*    cameraPageWidgetInfo;
    QmlPageInfo*    healthPageWidgetInfo;
    QmlPageInfo*    vibrationPageWidgetInfo;
    QVariantList    instrumentPageWidgetList;
85 86 87 88 89 90 91 92 93
};

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

94 95
QGCCorePlugin::QGCCorePlugin(QGCApplication *app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
96
    , _showTouchAreas(false)
97
    , _showAdvancedUI(true)
98 99 100 101 102 103
{
    _p = new QGCCorePlugin_p;
}

void QGCCorePlugin::setToolbox(QGCToolbox *toolbox)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
104 105 106 107
    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");
108 109
}

110
QVariantList &QGCCorePlugin::settingsPages()
111 112
{
    if(!_p->pGeneral) {
113
        _p->pGeneral = new QmlPageInfo(tr("General"),
DonLakeFlyer's avatar
DonLakeFlyer committed
114 115
                                       QUrl::fromUserInput("qrc:/qml/GeneralSettings.qml"),
                                       QUrl::fromUserInput("qrc:/res/gear-white.svg"));
116 117
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pGeneral));
        _p->pCommLinks = new QmlPageInfo(tr("Comm Links"),
DonLakeFlyer's avatar
DonLakeFlyer committed
118 119
                                         QUrl::fromUserInput("qrc:/qml/LinkSettings.qml"),
                                         QUrl::fromUserInput("qrc:/res/waves.svg"));
120 121
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pCommLinks));
        _p->pOfflineMaps = new QmlPageInfo(tr("Offline Maps"),
DonLakeFlyer's avatar
DonLakeFlyer committed
122 123
                                           QUrl::fromUserInput("qrc:/qml/OfflineMap.qml"),
                                           QUrl::fromUserInput("qrc:/res/waves.svg"));
124 125
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pOfflineMaps));
        _p->pMAVLink = new QmlPageInfo(tr("MAVLink"),
DonLakeFlyer's avatar
DonLakeFlyer committed
126 127
                                       QUrl::fromUserInput("qrc:/qml/MavlinkSettings.qml"),
                                       QUrl::fromUserInput("qrc:/res/waves.svg"));
128 129
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pMAVLink));
        _p->pConsole = new QmlPageInfo(tr("Console"),
DonLakeFlyer's avatar
DonLakeFlyer committed
130
                                       QUrl::fromUserInput("qrc:/qml/QGroundControl/Controls/AppMessages.qml"));
131
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pConsole));
DonLakeFlyer's avatar
DonLakeFlyer committed
132
#if defined(QT_DEBUG)
133
        //-- These are always present on Debug builds
134
        _p->pMockLink = new QmlPageInfo(tr("Mock Link"),
DonLakeFlyer's avatar
DonLakeFlyer committed
135
                                        QUrl::fromUserInput("qrc:/qml/MockLink.qml"));
136 137
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pMockLink));
        _p->pDebug = new QmlPageInfo(tr("Debug"),
DonLakeFlyer's avatar
DonLakeFlyer committed
138
                                     QUrl::fromUserInput("qrc:/qml/DebugWindow.qml"));
139
        _p->settingsList.append(QVariant::fromValue((QmlPageInfo*)_p->pDebug));
DonLakeFlyer's avatar
DonLakeFlyer committed
140
#endif
141 142 143 144
    }
    return _p->settingsList;
}

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
QVariantList& QGCCorePlugin::instrumentPages(void)
{
    if (!_p->valuesPageWidgetInfo) {
        _p->valuesPageWidgetInfo = new QmlPageInfo(tr("Values"), QUrl::fromUserInput("qrc:/qml/ValuePageWidget.qml"));
        _p->cameraPageWidgetInfo = new QmlPageInfo(tr("Camera"), QUrl::fromUserInput("qrc:/qml/CameraPageWidget.qml"));
        _p->healthPageWidgetInfo = new QmlPageInfo(tr("Health"), QUrl::fromUserInput("qrc:/qml/HealthPageWidget.qml"));
        _p->vibrationPageWidgetInfo = new QmlPageInfo(tr("Vibration"), QUrl::fromUserInput("qrc:/qml/VibrationPageWidget.qml"));

        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->valuesPageWidgetInfo));
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->cameraPageWidgetInfo));
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->healthPageWidgetInfo));
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->vibrationPageWidgetInfo));
    }
    return _p->instrumentPageWidgetList;
}

161
int QGCCorePlugin::defaultSettings()
162 163 164 165
{
    return 0;
}

166 167 168 169 170 171 172 173
QGCOptions* QGCCorePlugin::options()
{
    if(!_p->defaultOptions) {
        _p->defaultOptions = new QGCOptions();
    }
    return _p->defaultOptions;
}

174 175 176
bool QGCCorePlugin::overrideSettingsGroupVisibility(QString name)
{
    Q_UNUSED(name);
177

178 179 180
    // Always show all
    return true;
}
181 182 183

bool QGCCorePlugin::adjustSettingMetaData(FactMetaData& metaData)
{
184
    //-- Default Palette
Don Gagne's avatar
Don Gagne committed
185 186 187 188 189 190 191 192
    if (metaData.name() == AppSettings::indoorPaletteName) {
        QVariant outdoorPalette;
#if defined (__mobile__)
        outdoorPalette = 0;
#else
        outdoorPalette = 1;
#endif
        metaData.setRawDefaultValue(outdoorPalette);
193 194 195 196 197
        return true;
    //-- Auto Save Telemetry Logs
    } else if (metaData.name() == AppSettings::telemetrySaveName) {
#if defined (__mobile__)
        metaData.setRawDefaultValue(false);
198
        return true;
199 200 201
#else
        metaData.setRawDefaultValue(true);
        return true;
202 203 204 205 206 207 208
#endif
#if defined(__ios__)
    } else if (metaData.name() == AppSettings::savePathName) {
        QString appName = qgcApp()->applicationName();
        QDir rootDir = QDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
        metaData.setRawDefaultValue(rootDir.filePath(appName));
        return false;
209
#endif
Don Gagne's avatar
Don Gagne committed
210
    }
211
    return true; // Show setting in ui
212
}
DonLakeFlyer's avatar
DonLakeFlyer committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

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);
    }
}
229 230 231 232 233 234

void QGCCorePlugin::paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
{
    Q_UNUSED(colorName);
    Q_UNUSED(colorInfo);
}
235 236 237 238 239 240 241 242

QString QGCCorePlugin::showAdvancedUIMessage(void) const
{
    return tr("WARNING: You are about to enter Advanced Mode. "
              "If used incorrectly, this may cause your vehicle to malfunction thus voiding your warranty. "
              "You should do so only if instructed by customer support. "
              "Are you sure you want to enable Advanced Mode?");
}
243 244 245 246 247 248

void QGCCorePlugin::valuesWidgetDefaultSettings(QStringList& largeValues, QStringList& smallValues)
{
    Q_UNUSED(smallValues);
    largeValues << "Vehicle.altitudeRelative" << "Vehicle.groundSpeed" << "Vehicle.flightTime";
}
249 250 251 252 253 254 255 256 257 258

QQmlApplicationEngine* QGCCorePlugin::createRootWindow(QObject *parent)
{
    QQmlApplicationEngine* pEngine = new QQmlApplicationEngine(parent);
    pEngine->addImportPath("qrc:/qml");
    pEngine->rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager());
    pEngine->rootContext()->setContextProperty("debugMessageModel", AppMessages::getModel());
    pEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml")));
    return pEngine;
}
259 260 261 262 263 264 265 266 267

bool QGCCorePlugin::mavlinkMessage(Vehicle* vehicle, LinkInterface* link, mavlink_message_t message)
{
    Q_UNUSED(vehicle);
    Q_UNUSED(link);
    Q_UNUSED(message);

    return true;
}