CustomCommandWidgetController.cc 2.25 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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11

#include "CustomCommandWidgetController.h"
12
#include "MultiVehicleManager.h"
Don Gagne's avatar
Don Gagne committed
13
#include "QGCMAVLink.h"
14
#include "QGCQFileDialog.h"
15
#include "UAS.h"
16
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
17 18

#include <QSettings>
Don Gagne's avatar
Don Gagne committed
19
#include <QUrl>
Don Gagne's avatar
Don Gagne committed
20 21 22 23

const char* CustomCommandWidgetController::_settingsKey = "CustomCommand.QmlFile";

CustomCommandWidgetController::CustomCommandWidgetController(void) :
24
    _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
25
{
dogmaphobic's avatar
dogmaphobic committed
26
    if(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
27
        _vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
dogmaphobic's avatar
dogmaphobic committed
28
    }
Don Gagne's avatar
Don Gagne committed
29 30 31 32 33 34
    QSettings settings;
    _customQmlFile = settings.value(_settingsKey).toString();
}

void CustomCommandWidgetController::sendCommand(int commandId, QVariant componentId, QVariant confirm, QVariant param1, QVariant param2, QVariant param3, QVariant param4, QVariant param5, QVariant param6, QVariant param7)
{
35 36 37 38 39 40 41
    Q_UNUSED(confirm);

    if(_vehicle) {
        _vehicle->sendMavCommand(componentId.toInt(),
                                 (MAV_CMD)commandId,
                                 true,  // show error if fails
                                 param1.toFloat(), param2.toFloat(), param3.toFloat(), param4.toFloat(), param5.toFloat(), param6.toFloat(), param7.toFloat());
dogmaphobic's avatar
dogmaphobic committed
42 43 44
    }
}

Don Gagne's avatar
Don Gagne committed
45 46 47
void CustomCommandWidgetController::selectQmlFile(void)
{
    QSettings settings;
48
    QString qmlFile = QGCQFileDialog::getOpenFileName(NULL, tr("Select custom Qml file"), QString(), tr("Qml files (*.qml)"));
Don Gagne's avatar
Don Gagne committed
49 50 51 52
    if (qmlFile.isEmpty()) {
        _customQmlFile.clear();
        settings.remove(_settingsKey);
    } else {
Don Gagne's avatar
Don Gagne committed
53 54
		QUrl url = QUrl::fromLocalFile(qmlFile);
		_customQmlFile = url.toString();
Don Gagne's avatar
Don Gagne committed
55 56 57 58 59 60 61 62 63 64 65 66
        settings.setValue(_settingsKey, _customQmlFile);
    }
    emit customQmlFileChanged(_customQmlFile);
}

void CustomCommandWidgetController::clearQmlFile(void)
{
    _customQmlFile.clear();
    QSettings settings;
    settings.remove(_settingsKey);
    emit customQmlFileChanged(_customQmlFile);
}