QGCConfigView.cc 2.58 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 21 22 23 24 25 26
    // The config screens are required for firmware uploading
    if (MainWindow::instance()->getCustomMode() == MainWindow::CUSTOM_MODE_PX4) {
        config = new QGCPX4VehicleConfig();
        ui->gridLayout->addWidget(config);
    } else {
        //don't show a configuration widget if no vehicle is connected
        //show a placeholder informational widget instead
    }
tstellanova's avatar
tstellanova committed
27

28 29 30 31 32 33 34 35 36
}

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

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
37
    if (mav == uas)
38 39
        return;

tstellanova's avatar
tstellanova committed
40 41 42 43 44
    //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
45 46
            if (obj != ui->waitingLabel) {
                ui->gridLayout->removeWidget(w);
47
                delete obj;
tstellanova's avatar
tstellanova committed
48
            }
49 50 51
        }
    }

52 53
    mav = uas;
    if (NULL != mav) {
tstellanova's avatar
tstellanova committed
54
        ui->gridLayout->removeWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
55
        ui->waitingLabel->setVisible(false);
tstellanova's avatar
tstellanova committed
56

57 58
        int autopilotType = mav->getAutopilotType();
        switch (autopilotType) {
tstellanova's avatar
tstellanova committed
59
        case MAV_AUTOPILOT_PX4:
60 61 62 63 64 65 66 67 68
            {
                QGCPX4VehicleConfig* px4config = qobject_cast<QGCPX4VehicleConfig*>(config);
                if (!px4config) {
                    if (config)
                        delete config;
                    config = new QGCPX4VehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
69 70
            break;
        default:
71 72 73 74 75 76 77 78 79
            {
                QGCVehicleConfig* generalconfig = qobject_cast<QGCVehicleConfig*>(config);
                if (!generalconfig) {
                    if (config)
                        delete config;
                    config = new QGCVehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
80
            break;
tstellanova's avatar
tstellanova committed
81
        }
82
    }
tstellanova's avatar
tstellanova committed
83 84 85
    else {
        //restore waiting label if we no longer have a connection
        ui->gridLayout->addWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
86
        ui->waitingLabel->setVisible(true);
tstellanova's avatar
tstellanova committed
87 88
    }

89
}