QGCWaypointListMulti.cc 2.37 KB
Newer Older
1
#include "QGCWaypointListMulti.h"
2
#include "MultiVehicleManager.h"
3 4 5
#include "UAS.h"

#include "ui_QGCWaypointListMulti.h"
6

7 8
void* QGCWaypointListMulti::_offlineUAS = NULL;

9 10
QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) :
    QWidget(parent),
11
    _ui(new Ui::QGCWaypointListMulti)
12
{
13
    _ui->setupUi(this);
14
    setMinimumSize(600, 80);
15
    
16 17 18 19 20
    connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &QGCWaypointListMulti::_vehicleAdded);
    connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &QGCWaypointListMulti::_vehicleRemoved);
    connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &QGCWaypointListMulti::_activeVehicleChanged);
    
    WaypointList* list = new WaypointList(_ui->stackedWidget, MultiVehicleManager::instance()->activeWaypointManager());
21 22
    _lists.insert(_offlineUAS, list);
    _ui->stackedWidget->addWidget(list);
23

24 25 26
    if (MultiVehicleManager::instance()->activeVehicle()) {
        _vehicleAdded(MultiVehicleManager::instance()->activeVehicle());
        _activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
27
    }
28 29
}

30 31 32 33 34
QGCWaypointListMulti::~QGCWaypointListMulti()
{
    delete _ui;
}

35
void QGCWaypointListMulti::_vehicleRemoved(Vehicle* vehicle)
36
{
37 38 39
    // Do not dynamic cast or de-reference QObject, since object is either in destructor or may have already
    // been destroyed.

40 41 42
    if (vehicle) {
        UAS* uas = vehicle->uas();
        
43 44
        WaypointList* list = _lists.value(uas, NULL);
        if (list) {
45
            delete list;
46
            _lists.remove(uas);
47 48 49 50
        }
    }
}

51
void QGCWaypointListMulti::_vehicleAdded(Vehicle* vehicle)
52
{
53 54
    UAS* uas = vehicle->uas();
    
55 56 57
    WaypointList* list = new WaypointList(_ui->stackedWidget, uas->getWaypointManager());
    _lists.insert(uas, list);
    _ui->stackedWidget->addWidget(list);
58 59
}

60
void QGCWaypointListMulti::_activeVehicleChanged(Vehicle* vehicle)
61
{
62 63 64 65 66 67 68
    if (vehicle) {
        UAS* uas = vehicle->uas();
        
        WaypointList* list = _lists.value(uas, NULL);
        if (list) {
            _ui->stackedWidget->setCurrentWidget(list);
        }
69 70 71 72 73 74 75 76
    }
}

void QGCWaypointListMulti::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
77
        _ui->retranslateUi(this);
78 79 80 81 82
        break;
    default:
        break;
    }
}