SetupView.cc 4.44 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 28 29
/*=====================================================================
 
 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"

#include "UASManager.h"
30
#include "AutoPilotPluginManager.h"
31 32
#include "VehicleComponent.h"
#include "PX4FirmwareUpgrade.h"
33 34 35
#include "ParameterEditor.h"
#include "SetupWidgetHolder.h"
#include "MainWindow.h"
36 37 38 39 40 41

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

SetupView::SetupView(QWidget* parent) :
42
    QGCQuickWidget(parent),
43 44
    _uasCurrent(NULL),
    _initComplete(false),
45
    _autoPilotPlugin(NULL)
46 47 48 49 50
{
    bool fSucceeded = connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(_setActiveUAS(UASInterface*)));
    Q_UNUSED(fSucceeded);
    Q_ASSERT(fSucceeded);
    
51
    _setActiveUAS(NULL);
52 53 54 55
}

SetupView::~SetupView()
{
56

57 58 59 60 61
}

void SetupView::_setActiveUAS(UASInterface* uas)
{
    if (_uasCurrent) {
62 63 64
        Q_ASSERT(_autoPilotPlugin);
        disconnect(_autoPilotPlugin);
        _autoPilotPlugin = NULL;
65
    }
66

67 68 69
    _uasCurrent = uas;
    
    if (_uasCurrent) {
70
        _autoPilotPlugin = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(_uasCurrent);
71
        
72 73 74
        connect(_autoPilotPlugin, &AutoPilotPlugin::pluginReady, this, &SetupView::_pluginReady);
        if (_autoPilotPlugin->pluginIsReady()) {
            _setConnectedView();
75
        }
76 77
    } else {
        _setDisconnectedView();
78 79 80
    }
}

81
void SetupView::_pluginReady(void)
82
{
83
    _setConnectedView();
84 85
}

86
void SetupView::_setViewConnections(void)
87
{
88 89 90
    QObject*button = rootObject()->findChild<QObject*>("firmwareButton");
    Q_ASSERT(button);
    connect(button, SIGNAL(clicked()), this, SLOT(_firmwareButtonClicked()));
91
    
92 93 94 95
    button = rootObject()->findChild<QObject*>("parametersButton");
    if (button) {
        connect(button, SIGNAL(clicked()), this, SLOT(_parametersButtonClicked()));
    }
96 97
}

98
void SetupView::_setDisconnectedView(void)
99
{
100 101
    setSource(QUrl::fromUserInput("qrc:qml/SetupViewDisconnected.qml"));
    _setViewConnections();
102 103
}

104
void SetupView::_setConnectedView(void)
105
{
106 107
    Q_ASSERT(_uasCurrent);
    Q_ASSERT(_autoPilotPlugin);
108
    
109
    setAutoPilot(_autoPilotPlugin);
110
    
111 112 113
    setSource(QUrl::fromUserInput("qrc:qml/SetupViewConnected.qml"));
    disconnect(_autoPilotPlugin);
    _setViewConnections();
114
    
115
    connect((QObject*)rootObject(), SIGNAL(buttonClicked(QVariant)), this, SLOT(_setupButtonClicked(QVariant)));
116 117
}

118
void SetupView::_firmwareButtonClicked(void)
119
{
120 121 122
    SetupWidgetHolder* dialog = new SetupWidgetHolder(MainWindow::instance());
    dialog->setModal(true);
    dialog->setWindowTitle("Firmware Upgrade");
123
    
124 125 126
    PX4FirmwareUpgrade* setup = new PX4FirmwareUpgrade(dialog);
    dialog->setInnerWidget(setup);
    dialog->exec();
127 128
}

129
void SetupView::_parametersButtonClicked(void)
130
{
131 132 133
    SetupWidgetHolder* dialog = new SetupWidgetHolder(MainWindow::instance());
    dialog->setModal(true);
    dialog->setWindowTitle("Parameter Editor");
134
    
135 136 137
    ParameterEditor* setup = new ParameterEditor(_uasCurrent, QStringList(), dialog);
    dialog->setInnerWidget(setup);
    dialog->exec();
138 139
}

140
void SetupView::_setupButtonClicked(const QVariant& component)
141
{
142 143 144 145 146 147 148 149 150 151 152 153
    VehicleComponent* vehicle = qobject_cast<VehicleComponent*>(component.value<QObject*>());
    Q_ASSERT(vehicle);
    
    SetupWidgetHolder* dialog = new SetupWidgetHolder(MainWindow::instance());
    dialog->setModal(true);
    dialog->setWindowTitle(vehicle->name());
    
    QWidget* setupWidget = vehicle->setupWidget();
    qDebug() << setupWidget->minimumSize();
    dialog->resize(setupWidget->minimumSize());
    dialog->setInnerWidget(setupWidget);
    dialog->exec();
154
}