CustomCommandWidgetController.cc 2.8 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"
Don Gagne's avatar
Don Gagne committed
29 30

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

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

CustomCommandWidgetController::CustomCommandWidgetController(void) :
	_uas(NULL)
{
38
    _uas = MultiVehicleManager::instance()->activeVehicle()->uas();
Don Gagne's avatar
Don Gagne committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    Q_ASSERT(_uas);
    
    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)
{
    Q_UNUSED(commandId);
    Q_UNUSED(componentId);
    Q_UNUSED(confirm);
    Q_UNUSED(param1);
    Q_UNUSED(param2);
    Q_UNUSED(param3);
    Q_UNUSED(param4);
    Q_UNUSED(param5);
    Q_UNUSED(param6);
    Q_UNUSED(param7);
    _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::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
69 70
		QUrl url = QUrl::fromLocalFile(qmlFile);
		_customQmlFile = url.toString();
Don Gagne's avatar
Don Gagne committed
71 72 73 74 75 76 77 78 79 80 81 82 83
        settings.setValue(_settingsKey, _customQmlFile);
    }
    
    emit customQmlFileChanged(_customQmlFile);
}

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