QGCUASFileViewMulti.cc 2.15 KB
Newer Older
1 2 3
#include "QGCUASFileViewMulti.h"
#include "ui_QGCUASFileViewMulti.h"
#include "UASInterface.h"
4
#include "MultiVehicleManager.h"
5
#include "QGCUASFileView.h"
6
#include "QGCApplication.h"
7

8 9
QGCUASFileViewMulti::QGCUASFileViewMulti(const QString& title, QAction* action, QWidget *parent) :
    QGCDockWidget(title, action, parent),
10 11 12 13
    ui(new Ui::QGCUASFileViewMulti)
{
    ui->setupUi(this);
    setMinimumSize(600, 80);
14 15 16
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &QGCUASFileViewMulti::_activeVehicleChanged);
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &QGCUASFileViewMulti::_vehicleAdded);
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleRemoved, this, &QGCUASFileViewMulti::_vehicleRemoved);
17

18 19 20
    if (qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
        _vehicleAdded(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
        _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
21
    }
22 23
    
    loadSettings();
24 25
}

26
void QGCUASFileViewMulti::_vehicleRemoved(Vehicle* vehicle)
27
{
28
    UAS* uas = vehicle->uas();
29 30
    Q_ASSERT(uas);
    
31
    QGCUASFileView* list = lists.value(uas, NULL);
32
    if (list)
33
    {
34
        delete list;
35
        lists.remove(uas);
36 37 38
    }
}

39
void QGCUASFileViewMulti::_vehicleAdded(Vehicle* vehicle)
40
{
41 42 43
    UAS* uas = vehicle->uas();
    
    if (!lists.contains(uas)) {
Don Gagne's avatar
Don Gagne committed
44
        QGCUASFileView* list = new QGCUASFileView(ui->stackedWidget, vehicle);
45 46 47
        lists.insert(uas, list);
        ui->stackedWidget->addWidget(list);
    }
48 49
}

50
void QGCUASFileViewMulti::_activeVehicleChanged(Vehicle* vehicle)
51
{
52 53 54 55 56
    if (vehicle) {
        QGCUASFileView* list = lists.value(vehicle->uas(), NULL);
        if (list) {
            ui->stackedWidget->setCurrentWidget(list);
        }
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    }
}

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

void QGCUASFileViewMulti::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}