CustomCommandWidgetController.cc 2.98 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

#include "CustomCommandWidgetController.h"
25
#include "MultiVehicleManager.h"
Don Gagne's avatar
Don Gagne committed
26 27
#include "QGCMAVLink.h"
#include "QGCFileDialog.h"
28
#include "UAS.h"
29
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
30 31

#include <QSettings>
Don Gagne's avatar
Don Gagne committed
32
#include <QUrl>
Don Gagne's avatar
Don Gagne committed
33 34 35 36 37 38

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

CustomCommandWidgetController::CustomCommandWidgetController(void) :
	_uas(NULL)
{
dogmaphobic's avatar
dogmaphobic committed
39 40 41
    if(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
        _uas = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas();
    }
Don Gagne's avatar
Don Gagne committed
42 43
    QSettings settings;
    _customQmlFile = settings.value(_settingsKey).toString();
dogmaphobic's avatar
dogmaphobic committed
44
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &CustomCommandWidgetController::_activeVehicleChanged);
Don Gagne's avatar
Don Gagne committed
45 46 47 48
}

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

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
68 69
		QUrl url = QUrl::fromLocalFile(qmlFile);
		_customQmlFile = url.toString();
Don Gagne's avatar
Don Gagne committed
70 71 72 73 74 75 76 77 78 79 80 81
        settings.setValue(_settingsKey, _customQmlFile);
    }
    emit customQmlFileChanged(_customQmlFile);
}

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