QGCCorePlugin.cc 11.8 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 "QmlComponentInfo.h"
14
#include "FactMetaData.h"
Don Gagne's avatar
Don Gagne committed
15
#include "SettingsManager.h"
16
#include "AppMessages.h"
17
#include "QmlObjectListModel.h"
18
#include "VideoReceiver.h"
19
#include "QGCLoggingCategory.h"
20 21 22 23 24 25 26 27 28 29 30 31 32 33

#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()
    {
    }
34

35 36 37 38 39 40 41 42
    ~QGCCorePlugin_p()
    {
        if(pGeneral)
            delete pGeneral;
        if(pCommLinks)
            delete pCommLinks;
        if(pOfflineMaps)
            delete pOfflineMaps;
43 44 45 46
#if defined(QGC_GST_TAISYNC_ENABLED)
        if(pTaisync)
            delete pTaisync;
#endif
47 48 49 50
#if defined(QGC_GST_MICROHARD_ENABLED)
        if(pMicrohard)
            delete pMicrohard;
#endif
Gus Grubba's avatar
Gus Grubba committed
51
#if defined(QGC_AIRMAP_ENABLED)
Gus Grubba's avatar
Gus Grubba committed
52 53
        if(pAirmap)
            delete pAirmap;
Gus Grubba's avatar
Gus Grubba committed
54
#endif
55 56 57 58 59 60 61 62 63 64 65 66 67
        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;
    }
68

69 70 71 72 73 74
    QmlComponentInfo* pGeneral                  = nullptr;
    QmlComponentInfo* pCommLinks                = nullptr;
    QmlComponentInfo* pOfflineMaps              = nullptr;
#if defined(QGC_GST_TAISYNC_ENABLED)
    QmlComponentInfo* pTaisync                  = nullptr;
#endif
75 76 77
#if defined(QGC_GST_MICROHARD_ENABLED)
    QmlComponentInfo* pMicrohard                = nullptr;
#endif
Gus Grubba's avatar
Gus Grubba committed
78
#if defined(QGC_AIRMAP_ENABLED)
79
    QmlComponentInfo* pAirmap                   = nullptr;
Gus Grubba's avatar
Gus Grubba committed
80
#endif
81 82 83
    QmlComponentInfo* pMAVLink                  = nullptr;
    QmlComponentInfo* pConsole                  = nullptr;
    QmlComponentInfo* pHelp                     = nullptr;
84
#if defined(QT_DEBUG)
85 86
    QmlComponentInfo* pMockLink                 = nullptr;
    QmlComponentInfo* pDebug                    = nullptr;
87
#endif
88

89 90 91 92 93 94 95 96
    QmlComponentInfo*   valuesPageWidgetInfo    = nullptr;
    QmlComponentInfo*   cameraPageWidgetInfo    = nullptr;
    QmlComponentInfo*   videoPageWidgetInfo     = nullptr;
    QmlComponentInfo*   healthPageWidgetInfo    = nullptr;
    QmlComponentInfo*   vibrationPageWidgetInfo = nullptr;

    QGCOptions*         defaultOptions          = nullptr;
    QVariantList        settingsList;
97 98 99
    QVariantList        instrumentPageWidgetList;

    QmlObjectListModel _emptyCustomMapItems;
100 101 102 103 104 105 106 107 108
};

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

109 110
QGCCorePlugin::QGCCorePlugin(QGCApplication *app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
111
    , _showTouchAreas(false)
112
    , _showAdvancedUI(true)
113 114 115 116 117 118
{
    _p = new QGCCorePlugin_p;
}

void QGCCorePlugin::setToolbox(QGCToolbox *toolbox)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
119 120 121 122
    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");
123 124
}

125
QVariantList &QGCCorePlugin::settingsPages()
126 127
{
    if(!_p->pGeneral) {
128
        _p->pGeneral = new QmlComponentInfo(tr("General"),
129 130 131
            QUrl::fromUserInput("qrc:/qml/GeneralSettings.qml"),
            QUrl::fromUserInput("qrc:/res/gear-white.svg"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pGeneral)));
132
        _p->pCommLinks = new QmlComponentInfo(tr("Comm Links"),
133 134 135
            QUrl::fromUserInput("qrc:/qml/LinkSettings.qml"),
            QUrl::fromUserInput("qrc:/res/waves.svg"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pCommLinks)));
136
        _p->pOfflineMaps = new QmlComponentInfo(tr("Offline Maps"),
137 138 139
            QUrl::fromUserInput("qrc:/qml/OfflineMap.qml"),
            QUrl::fromUserInput("qrc:/res/waves.svg"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pOfflineMaps)));
140 141 142 143 144 145
#if defined(QGC_GST_TAISYNC_ENABLED)
        _p->pTaisync = new QmlComponentInfo(tr("Taisync"),
            QUrl::fromUserInput("qrc:/qml/TaisyncSettings.qml"),
            QUrl::fromUserInput(""));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pTaisync)));
#endif
146 147 148 149 150 151
#if defined(QGC_GST_MICROHARD_ENABLED)
        _p->pMicrohard = new QmlComponentInfo(tr("Microhard"),
            QUrl::fromUserInput("qrc:/qml/MicrohardSettings.qml"),
            QUrl::fromUserInput(""));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pMicrohard)));
#endif
Gus Grubba's avatar
Gus Grubba committed
152
#if defined(QGC_AIRMAP_ENABLED)
Gus Grubba's avatar
Gus Grubba committed
153
        _p->pAirmap = new QmlComponentInfo(tr("AirMap"),
154 155 156
            QUrl::fromUserInput("qrc:/qml/AirmapSettings.qml"),
            QUrl::fromUserInput(""));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pAirmap)));
Gus Grubba's avatar
Gus Grubba committed
157
#endif
158
        _p->pMAVLink = new QmlComponentInfo(tr("MAVLink"),
159 160 161
            QUrl::fromUserInput("qrc:/qml/MavlinkSettings.qml"),
            QUrl::fromUserInput("qrc:/res/waves.svg"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pMAVLink)));
162
        _p->pConsole = new QmlComponentInfo(tr("Console"),
163 164
            QUrl::fromUserInput("qrc:/qml/QGroundControl/Controls/AppMessages.qml"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pConsole)));
165
        _p->pHelp = new QmlComponentInfo(tr("Help"),
166 167
            QUrl::fromUserInput("qrc:/qml/HelpSettings.qml"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pHelp)));
DonLakeFlyer's avatar
DonLakeFlyer committed
168
#if defined(QT_DEBUG)
169
        //-- These are always present on Debug builds
170
        _p->pMockLink = new QmlComponentInfo(tr("Mock Link"),
171 172
            QUrl::fromUserInput("qrc:/qml/MockLink.qml"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pMockLink)));
173
        _p->pDebug = new QmlComponentInfo(tr("Debug"),
174 175
            QUrl::fromUserInput("qrc:/qml/DebugWindow.qml"));
        _p->settingsList.append(QVariant::fromValue(reinterpret_cast<QmlComponentInfo*>(_p->pDebug)));
DonLakeFlyer's avatar
DonLakeFlyer committed
176
#endif
177 178 179 180
    }
    return _p->settingsList;
}

181 182 183
QVariantList& QGCCorePlugin::instrumentPages(void)
{
    if (!_p->valuesPageWidgetInfo) {
Gus Grubba's avatar
Gus Grubba committed
184 185 186
        _p->valuesPageWidgetInfo    = new QmlComponentInfo(tr("Values"),    QUrl::fromUserInput("qrc:/qml/ValuePageWidget.qml"));
        _p->cameraPageWidgetInfo    = new QmlComponentInfo(tr("Camera"),    QUrl::fromUserInput("qrc:/qml/CameraPageWidget.qml"));
#if defined(QGC_GST_STREAMING)
187
        _p->videoPageWidgetInfo     = new QmlComponentInfo(tr("Video Stream"), QUrl::fromUserInput("qrc:/qml/VideoPageWidget.qml"));
Gus Grubba's avatar
Gus Grubba committed
188 189
#endif
        _p->healthPageWidgetInfo    = new QmlComponentInfo(tr("Health"),    QUrl::fromUserInput("qrc:/qml/HealthPageWidget.qml"));
190
        _p->vibrationPageWidgetInfo = new QmlComponentInfo(tr("Vibration"), QUrl::fromUserInput("qrc:/qml/VibrationPageWidget.qml"));
191 192 193

        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->valuesPageWidgetInfo));
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->cameraPageWidgetInfo));
Gus Grubba's avatar
Gus Grubba committed
194 195 196
#if defined(QGC_GST_STREAMING)
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->videoPageWidgetInfo));
#endif
197 198 199 200 201 202
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->healthPageWidgetInfo));
        _p->instrumentPageWidgetList.append(QVariant::fromValue(_p->vibrationPageWidgetInfo));
    }
    return _p->instrumentPageWidgetList;
}

203
int QGCCorePlugin::defaultSettings()
204 205 206 207
{
    return 0;
}

208 209 210 211 212 213 214 215
QGCOptions* QGCCorePlugin::options()
{
    if(!_p->defaultOptions) {
        _p->defaultOptions = new QGCOptions();
    }
    return _p->defaultOptions;
}

216 217 218
bool QGCCorePlugin::overrideSettingsGroupVisibility(QString name)
{
    Q_UNUSED(name);
219

220 221 222
    // Always show all
    return true;
}
223

224
bool QGCCorePlugin::adjustSettingMetaData(const QString& settingsGroup, FactMetaData& metaData)
225
{
226 227 228 229 230
    if (settingsGroup != AppSettings::settingsGroup) {
        // All changes refer to AppSettings
        return true;
    }

231
    //-- Default Palette
Don Gagne's avatar
Don Gagne committed
232 233 234 235 236 237 238 239
    if (metaData.name() == AppSettings::indoorPaletteName) {
        QVariant outdoorPalette;
#if defined (__mobile__)
        outdoorPalette = 0;
#else
        outdoorPalette = 1;
#endif
        metaData.setRawDefaultValue(outdoorPalette);
240 241 242 243 244
        return true;
    //-- Auto Save Telemetry Logs
    } else if (metaData.name() == AppSettings::telemetrySaveName) {
#if defined (__mobile__)
        metaData.setRawDefaultValue(false);
245
        return true;
246 247 248
#else
        metaData.setRawDefaultValue(true);
        return true;
249 250 251 252 253 254 255
#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;
256
#endif
Don Gagne's avatar
Don Gagne committed
257
    }
258
    return true; // Show setting in ui
259
}
DonLakeFlyer's avatar
DonLakeFlyer committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275

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);
    }
}
276 277 278 279 280 281

void QGCCorePlugin::paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
{
    Q_UNUSED(colorName);
    Q_UNUSED(colorInfo);
}
282 283 284 285 286 287 288 289

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?");
}
290 291 292 293 294 295

void QGCCorePlugin::valuesWidgetDefaultSettings(QStringList& largeValues, QStringList& smallValues)
{
    Q_UNUSED(smallValues);
    largeValues << "Vehicle.altitudeRelative" << "Vehicle.groundSpeed" << "Vehicle.flightTime";
}
296 297 298 299 300 301 302 303 304 305

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;
}
306 307 308 309 310 311 312 313 314

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

    return true;
}
315 316 317 318 319

QmlObjectListModel* QGCCorePlugin::customMapItems(void)
{
    return &_p->_emptyCustomMapItems;
}
320 321 322 323 324

VideoReceiver* QGCCorePlugin::createVideoReceiver(QObject* parent)
{
    return new VideoReceiver(parent);
}
325 326 327 328 329

bool QGCCorePlugin::guidedActionsControllerLogging(void) const
{
    return GuidedActionsControllerLog().isDebugEnabled();
}
330 331 332 333 334 335 336 337 338 339

QString QGCCorePlugin::stableVersionCheckFileUrl(void) const
{
#ifdef QGC_CUSTOM_BUILD
    // Custom builds must override to turn on and provide their own location
    return QString();
#else
    return QString("https://s3-us-west-2.amazonaws.com/qgroundcontrol/latest/QGC.version.txt");
#endif
}