QGCConfigView.cc 2.86 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
    // The config screens are required for firmware uploading
    if (MainWindow::instance()->getCustomMode() == MainWindow::CUSTOM_MODE_PX4) {
21 22 23 24 25

        ui->gridLayout->removeWidget(ui->waitingLabel);
        ui->waitingLabel->setVisible(false);
        delete ui->waitingLabel;

26 27
        config = new QGCPX4VehicleConfig();
        ui->gridLayout->addWidget(config);
28

29 30 31 32
    } else {
        //don't show a configuration widget if no vehicle is connected
        //show a placeholder informational widget instead
    }
tstellanova's avatar
tstellanova committed
33

34 35 36 37 38 39 40 41 42
}

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

void QGCConfigView::activeUASChanged(UASInterface* uas)
{
43
    if (mav == uas)
44 45
        return;

46 47 48
    int type = -1;
    if (mav)
        type = mav->getAutopilotType();
49

50
    mav = uas;
51 52
    if (NULL != uas && type != uas->getAutopilotType()) {

tstellanova's avatar
tstellanova committed
53
        ui->gridLayout->removeWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
54
        ui->waitingLabel->setVisible(false);
tstellanova's avatar
tstellanova committed
55

56 57 58 59 60 61 62 63 64 65 66 67
        //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;
                }
            }
        }

68 69
        int autopilotType = mav->getAutopilotType();
        switch (autopilotType) {
tstellanova's avatar
tstellanova committed
70
        case MAV_AUTOPILOT_PX4:
71 72 73 74 75 76 77 78 79
            {
                QGCPX4VehicleConfig* px4config = qobject_cast<QGCPX4VehicleConfig*>(config);
                if (!px4config) {
                    if (config)
                        delete config;
                    config = new QGCPX4VehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
80 81
            break;
        default:
82 83 84 85 86 87 88 89 90
            {
                QGCVehicleConfig* generalconfig = qobject_cast<QGCVehicleConfig*>(config);
                if (!generalconfig) {
                    if (config)
                        delete config;
                    config = new QGCVehicleConfig();
                    ui->gridLayout->addWidget(config);
                }
            }
tstellanova's avatar
tstellanova committed
91
            break;
tstellanova's avatar
tstellanova committed
92
        }
93
    }
tstellanova's avatar
tstellanova committed
94 95 96
    else {
        //restore waiting label if we no longer have a connection
        ui->gridLayout->addWidget(ui->waitingLabel);
tstellanova's avatar
tstellanova committed
97
        ui->waitingLabel->setVisible(true);
tstellanova's avatar
tstellanova committed
98 99
    }

100
}