SetupView.cc 4.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================
 
 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/>.
 
 ======================================================================*/

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "SetupView.h"
Don Gagne's avatar
Don Gagne committed
28
#include "ui_SetupView.h"
29 30

#include "UASManager.h"
31
#include "AutoPilotPluginManager.h"
32
#include "VehicleComponent.h"
Don Gagne's avatar
Don Gagne committed
33
#include "QGCQmlWidgetHolder.h"
34
#include "MainWindow.h"
35
#include "QGCMessageBox.h"
36
#ifndef __android__
37
#include "FirmwareUpgradeController.h"
38
#endif
Don Gagne's avatar
Don Gagne committed
39
#include "ParameterEditorController.h"
40 41 42 43 44 45

#include <QQmlError>
#include <QQmlContext>
#include <QDebug>

SetupView::SetupView(QWidget* parent) :
46
    QGCQmlWidgetHolder(parent),
47
    _uasCurrent(NULL),
48
    _initComplete(false)
49
{
50 51 52 53
#ifdef __android__
    _showFirmware = false;
#else
    _showFirmware = true;
54
#endif
55 56 57 58 59
    
    connect(UASManager::instance(), &UASManager::activeUASSet, this, &SetupView::_setActiveUAS);
    
    getRootContext()->setContextProperty("controller", this);
    setSource(QUrl::fromUserInput("qrc:/qml/SetupView.qml"));
60
    
61
    _setActiveUAS(UASManager::instance()->getActiveUAS());
62 63 64 65
}

SetupView::~SetupView()
{
66

67 68 69 70 71
}

void SetupView::_setActiveUAS(UASInterface* uas)
{
    if (_uasCurrent) {
72
        disconnect(_autopilot.data(), &AutoPilotPlugin::pluginReadyChanged, this, &SetupView::_pluginReadyChanged);
73
    }
74

75
    _pluginReadyChanged(false);
Don Gagne's avatar
Don Gagne committed
76
    
77 78 79
    _uasCurrent = uas;
    
    if (_uasCurrent) {
80 81 82 83 84
        _autopilot = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uasCurrent);
        if (_autopilot.data()->pluginReady()) {
            _pluginReadyChanged(_autopilot.data()->pluginReady());
        }
        connect(_autopilot.data(), &AutoPilotPlugin::pluginReadyChanged, this, &SetupView::_pluginReadyChanged);
85 86 87
    }
}

88
void SetupView::_pluginReadyChanged(bool pluginReady)
89
{
90
    if (pluginReady) {
91 92
        _readyAutopilot = _autopilot.data();
        emit autopilotChanged(_readyAutopilot);
93
    } else {
94 95 96
        _readyAutopilot = NULL;
        emit autopilotChanged(NULL);
        _autopilot.clear();
97
    }
98 99
}

100 101
#ifdef UNITTEST_BUILD
void SetupView::showFirmware(void)
102
{
103
#ifndef __android__
104 105 106 107 108
    QVariant returnedValue;
    bool success = QMetaObject::invokeMethod(getRootObject(),
                                             "showFirmwarePanel",
                                             Q_RETURN_ARG(QVariant, returnedValue));
    Q_ASSERT(success);
109
#endif
110 111
}

112
void SetupView::showParameters(void)
113
{
114 115 116 117 118
    QVariant returnedValue;
    bool success = QMetaObject::invokeMethod(getRootObject(),
                                             "showParametersPanel",
                                             Q_RETURN_ARG(QVariant, returnedValue));
    Q_ASSERT(success);
Don Gagne's avatar
Don Gagne committed
119 120
}

121
void SetupView::showSummary(void)
Don Gagne's avatar
Don Gagne committed
122
{
123 124 125 126 127
    QVariant returnedValue;
    bool success = QMetaObject::invokeMethod(getRootObject(),
                                             "showSummaryPanel",
                                             Q_RETURN_ARG(QVariant, returnedValue));
    Q_ASSERT(success);
128 129
}

130
void SetupView::showVehicleComponentSetup(const QUrl& url)
131
{
132 133 134 135 136 137 138
    QVariant returnedValue;
    QVariant varSource = url;
    bool success = QMetaObject::invokeMethod(getRootObject(),
                                             "showVehicleComponentPanel",
                                             Q_RETURN_ARG(QVariant, returnedValue),
                                             Q_ARG(QVariant, varSource));
    Q_ASSERT(success);
139
}
140 141 142 143 144 145
#endif

AutoPilotPlugin* SetupView::autopilot(void)
{
    return _readyAutopilot;
}