CustomCommandWidgetController.cc 2.55 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
    QSettings settings;
    _customQmlFile = settings.value(_settingsKey).toString();
dogmaphobic's avatar
dogmaphobic committed
31
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &CustomCommandWidgetController::_activeVehicleChanged);
Don Gagne's avatar
Don Gagne committed
32 33 34 35
}

void CustomCommandWidgetController::sendCommand(int commandId, QVariant componentId, QVariant confirm, QVariant param1, QVariant param2, QVariant param3, QVariant param4, QVariant param5, QVariant param6, QVariant param7)
{
36 37 38 39 40 41 42
    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
43 44 45 46 47
    }
}

void CustomCommandWidgetController::_activeVehicleChanged(Vehicle* activeVehicle)
{
48 49 50
    if (activeVehicle) {
        _vehicle = activeVehicle;
    }
Don Gagne's avatar
Don Gagne committed
51 52 53 54 55
}

void CustomCommandWidgetController::selectQmlFile(void)
{
    QSettings settings;
56
    QString qmlFile = QGCQFileDialog::getOpenFileName(NULL, "Select custom Qml file", QString(), "Qml files (*.qml)");
Don Gagne's avatar
Don Gagne committed
57 58 59 60
    if (qmlFile.isEmpty()) {
        _customQmlFile.clear();
        settings.remove(_settingsKey);
    } else {
Don Gagne's avatar
Don Gagne committed
61 62
		QUrl url = QUrl::fromLocalFile(qmlFile);
		_customQmlFile = url.toString();
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69 70 71 72 73 74
        settings.setValue(_settingsKey, _customQmlFile);
    }
    emit customQmlFileChanged(_customQmlFile);
}

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