QGCConfigView.cc 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "QGCConfigView.h"
#include "ui_QGCConfigView.h"
#include "UASManager.h"
#include "QGCPX4VehicleConfig.h"
#include "QGCVehicleConfig.h"
#include "QGCPX4VehicleConfig.h"

QGCConfigView::QGCConfigView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::QGCConfigView),
    currUAS(NULL)
{
    ui->setupUi(this);

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

tstellanova's avatar
tstellanova committed
17 18 19
    //don't show a configuration widget if no vehicle is connected
    //show a placeholder informational widget instead

20 21 22 23 24 25 26 27 28 29 30 31
}

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

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
    if (currUAS == uas)
        return;

tstellanova's avatar
tstellanova committed
32 33 34 35 36
    //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) {
tstellanova's avatar
tstellanova committed
37 38
            if (obj != ui->waitingLabel) {
                ui->gridLayout->removeWidget(w);
39
                delete obj;
tstellanova's avatar
tstellanova committed
40
            }
41 42 43
        }
    }

tstellanova's avatar
tstellanova committed
44 45
    if (NULL != uas) {
        ui->gridLayout->removeWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
46
        ui->waitingLabel->setVisible(false);
tstellanova's avatar
tstellanova committed
47 48 49 50 51 52 53

        switch (uas->getAutopilotType()) {
        case MAV_AUTOPILOT_PX4:
            ui->gridLayout->addWidget(new QGCPX4VehicleConfig());
            break;
        default:
            ui->gridLayout->addWidget(new QGCVehicleConfig());
tstellanova's avatar
tstellanova committed
54
            break;
tstellanova's avatar
tstellanova committed
55
        }
56
    }
tstellanova's avatar
tstellanova committed
57 58 59
    else {
        //restore waiting label if we no longer have a connection
        ui->gridLayout->addWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
60
        ui->waitingLabel->setVisible(true);
tstellanova's avatar
tstellanova committed
61 62
    }

63
}