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

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

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

17 18 19 20
    ui->gridLayout->removeWidget(ui->waitingLabel);
    ui->waitingLabel->setVisible(false);
    delete ui->waitingLabel;
    ui->waitingLabel = NULL;
tstellanova's avatar
tstellanova committed
21

22 23
    config = new QGCPX4VehicleConfig();
    ui->gridLayout->addWidget(config);
24 25 26 27 28 29 30 31 32
}

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

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
33
    if (mav == uas)
34 35
        return;

36 37 38
    int type = -1;
    if (mav)
        type = mav->getAutopilotType();
39

40
    mav = uas;
41
    if (uas && type != uas->getAutopilotType()) {
42

43 44 45 46
        if (ui->waitingLabel) {
            ui->gridLayout->removeWidget(ui->waitingLabel);
            ui->waitingLabel->setVisible(false);
        }
tstellanova's avatar
tstellanova committed
47

48 49 50 51 52 53 54 55 56 57 58 59
        //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;
                }
            }
        }

60 61 62 63 64 65
        QGCPX4VehicleConfig* px4config = qobject_cast<QGCPX4VehicleConfig*>(config);
        if (!px4config) {
            if (config)
                delete config;
            config = new QGCPX4VehicleConfig();
            ui->gridLayout->addWidget(config);
tstellanova's avatar
tstellanova committed
66
        }
67
    }
tstellanova's avatar
tstellanova committed
68
    else {
69 70 71 72 73
        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
74 75
    }

76
}