QGCConfigView.cc 1.54 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 37 38
    //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) {
            ui->gridLayout->removeWidget(w);
            if (obj != ui->waitingLabel)
39 40 41 42
                delete obj;
        }
    }

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

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

59
}