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

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

17 18 19
    if (MultiVehicleManager::instance()->activeVehicle()) {
        _vehicleAdded(MultiVehicleManager::instance()->activeVehicle());
        _activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
20
    }
21 22
    
    loadSettings();
23 24
}

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

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

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

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

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