SetupView.cc 4.26 KB
Newer Older
1
/*=====================================================================
dogmaphobic's avatar
dogmaphobic committed
2

3
 QGroundControl Open Source Ground Control Station
dogmaphobic's avatar
dogmaphobic committed
4

5
 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
dogmaphobic's avatar
dogmaphobic committed
6

7
 This file is part of the QGROUNDCONTROL project
dogmaphobic's avatar
dogmaphobic committed
8

9 10 11 12
 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.
dogmaphobic's avatar
dogmaphobic committed
13

14 15 16 17
 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.
dogmaphobic's avatar
dogmaphobic committed
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
dogmaphobic's avatar
dogmaphobic committed
21

22 23 24 25 26 27 28 29
 ======================================================================*/

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

#include "SetupView.h"

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

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

SetupView::SetupView(QWidget* parent) :
45
    QGCQmlWidgetHolder(parent),
46
    _uasCurrent(NULL),
Don Gagne's avatar
Don Gagne committed
47
    _initComplete(false),
dogmaphobic's avatar
dogmaphobic committed
48
    _readyAutopilot(NULL)
49
{
dogmaphobic's avatar
dogmaphobic committed
50
#ifdef __mobile__
51 52 53
    _showFirmware = false;
#else
    _showFirmware = true;
54
#endif
dogmaphobic's avatar
dogmaphobic committed
55

56
    connect(UASManager::instance(), &UASManager::activeUASSet, this, &SetupView::_setActiveUAS);
dogmaphobic's avatar
dogmaphobic committed
57

58 59
    getRootContext()->setContextProperty("controller", this);
    setSource(QUrl::fromUserInput("qrc:/qml/SetupView.qml"));
dogmaphobic's avatar
dogmaphobic committed
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);
dogmaphobic's avatar
dogmaphobic committed
76

77
    _uasCurrent = uas;
dogmaphobic's avatar
dogmaphobic committed
78

79
    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
{
dogmaphobic's avatar
dogmaphobic committed
103
#ifndef __mobile__
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
}

Don Gagne's avatar
Don Gagne committed
130
void SetupView::showVehicleComponentSetup(VehicleComponent* vehicleComponent)
131
{
132 133 134 135
    QVariant returnedValue;
    bool success = QMetaObject::invokeMethod(getRootObject(),
                                             "showVehicleComponentPanel",
                                             Q_RETURN_ARG(QVariant, returnedValue),
Don Gagne's avatar
Don Gagne committed
136
                                             Q_ARG(QVariant, QVariant::fromValue((VehicleComponent*)vehicleComponent)));
137
    Q_ASSERT(success);
138
}
139 140 141 142 143
#endif

AutoPilotPlugin* SetupView::autopilot(void)
{
    return _readyAutopilot;
dogmaphobic's avatar
dogmaphobic committed
144
}