CustomCommandWidgetController.cc 2.4 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 14
#include "QGCMAVLink.h"
#include "QGCFileDialog.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 24 25

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

CustomCommandWidgetController::CustomCommandWidgetController(void) :
	_uas(NULL)
{
dogmaphobic's avatar
dogmaphobic committed
26 27 28
    if(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
        _uas = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas();
    }
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)
{
dogmaphobic's avatar
dogmaphobic committed
36 37 38 39 40 41 42 43 44
    if(_uas) {
        _uas->executeCommand((MAV_CMD)commandId, confirm.toInt(), param1.toFloat(), param2.toFloat(), param3.toFloat(), param4.toFloat(), param5.toFloat(), param6.toFloat(), param7.toFloat(), componentId.toInt());
    }
}

void CustomCommandWidgetController::_activeVehicleChanged(Vehicle* activeVehicle)
{
    if(activeVehicle)
        _uas = activeVehicle->uas();
Don Gagne's avatar
Don Gagne committed
45 46 47 48 49 50 51 52 53 54
}

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

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