QGCConfigView.cc 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#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),
11
    mav(NULL)
12 13 14 15 16
{
    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
}

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

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
29
    if (mav == uas)
30 31
        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
        }
    }

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

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

65
}