QGCConfigView.cc 2.99 KB
Newer Older
1 2 3 4 5 6
#include "QGCConfigView.h"
#include "ui_QGCConfigView.h"
#include "UASManager.h"
#include "QGCPX4VehicleConfig.h"
#include "QGCVehicleConfig.h"
#include "QGCPX4VehicleConfig.h"
7
#include "MainWindow.h"
8 9 10 11

QGCConfigView::QGCConfigView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::QGCConfigView),
12
    config(NULL),
13
    mav(NULL)
14 15 16 17 18
{
    ui->setupUi(this);

    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(activeUASChanged(UASInterface*)));

19 20
    // The config screens are required for firmware uploading
    if (MainWindow::instance()->getCustomMode() == MainWindow::CUSTOM_MODE_PX4) {
21 22 23 24

        ui->gridLayout->removeWidget(ui->waitingLabel);
        ui->waitingLabel->setVisible(false);
        delete ui->waitingLabel;
25
        ui->waitingLabel = NULL;
26

27 28
        config = new QGCPX4VehicleConfig();
        ui->gridLayout->addWidget(config);
29

30 31 32 33
    } else {
        //don't show a configuration widget if no vehicle is connected
        //show a placeholder informational widget instead
    }
tstellanova's avatar
tstellanova committed
34

35 36 37 38 39 40 41 42 43
}

QGCConfigView::~QGCConfigView()
{
    delete ui;
}

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
44
    if (mav == uas)
45 46
        return;

47 48 49
    int type = -1;
    if (mav)
        type = mav->getAutopilotType();
50

51
    mav = uas;
52
    if (uas && type != uas->getAutopilotType()) {
53

54 55 56 57
        if (ui->waitingLabel) {
            ui->gridLayout->removeWidget(ui->waitingLabel);
            ui->waitingLabel->setVisible(false);
        }
tstellanova's avatar
tstellanova committed
58

59 60 61 62 63 64 65 66 67 68 69 70
        //remove all child widgets since they could contain stale data
        //for example, when we switch from one PX4 UAS to another UAS
        foreach (QObject* obj, ui->gridLayout->children()) {
            QWidget* w = dynamic_cast<QWidget*>(obj);
            if (w) {
                if (obj != ui->waitingLabel) {
                    ui->gridLayout->removeWidget(w);
                    delete obj;
                }
            }
        }

71 72
        int autopilotType = mav->getAutopilotType();
        switch (autopilotType) {
tstellanova's avatar
tstellanova committed
73
        case MAV_AUTOPILOT_PX4:
74 75 76 77 78 79 80 81 82
            {
                QGCPX4VehicleConfig* px4config = qobject_cast<QGCPX4VehicleConfig*>(config);
                if (!px4config) {
                    if (config)
                        delete config;
                    config = new QGCPX4VehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
83 84
            break;
        default:
85 86 87 88 89 90 91 92 93
            {
                QGCVehicleConfig* generalconfig = qobject_cast<QGCVehicleConfig*>(config);
                if (!generalconfig) {
                    if (config)
                        delete config;
                    config = new QGCVehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
94
            break;
tstellanova's avatar
tstellanova committed
95
        }
96
    }
tstellanova's avatar
tstellanova committed
97
    else {
98 99 100 101 102
        if (ui->waitingLabel) {
            //restore waiting label if we no longer have a connection
            ui->gridLayout->addWidget(ui->waitingLabel);
            ui->waitingLabel->setVisible(true);
        }
tstellanova's avatar
tstellanova committed
103 104
    }

105
}