QGCWaypointListMulti.cc 2.09 KB
Newer Older
1 2 3 4
#include "QGCWaypointListMulti.h"
#include "ui_QGCWaypointListMulti.h"
#include "UASManager.h"

5 6
void* QGCWaypointListMulti::_offlineUAS = NULL;

7 8
QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) :
    QWidget(parent),
9
    _ui(new Ui::QGCWaypointListMulti)
10
{
11
    _ui->setupUi(this);
12
    setMinimumSize(600, 80);
13 14 15
    
    connect(UASManager::instance(), &UASManager::UASCreated, this, &QGCWaypointListMulti::_systemCreated);
    connect(UASManager::instance(), &UASManager::activeUASSet, this, &QGCWaypointListMulti::_systemSetActive);
16

17 18 19
    WaypointList* list = new WaypointList(_ui->stackedWidget, UASManager::instance()->getActiveUASWaypointManager());
    _lists.insert(_offlineUAS, list);
    _ui->stackedWidget->addWidget(list);
20 21

    if (UASManager::instance()->getActiveUAS()) {
22 23
        _systemCreated(UASManager::instance()->getActiveUAS());
        _systemSetActive(UASManager::instance()->getActiveUAS());
24 25
    }

26 27
}

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

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

38 39 40
    if (uas) {
        WaypointList* list = _lists.value(uas, NULL);
        if (list) {
41
            delete list;
42
            _lists.remove(uas);
43 44 45 46
        }
    }
}

47
void QGCWaypointListMulti::_systemCreated(UASInterface* uas)
48
{
49 50 51
    WaypointList* list = new WaypointList(_ui->stackedWidget, uas->getWaypointManager());
    _lists.insert(uas, list);
    _ui->stackedWidget->addWidget(list);
52
    // Ensure widget is deleted when system is deleted
53
    connect(uas, &QObject::destroyed, this, &QGCWaypointListMulti::_systemDeleted);
54 55
}

56
void QGCWaypointListMulti::_systemSetActive(UASInterface* uas)
57
{
58
    WaypointList* list = _lists.value(uas, NULL);
59
    if (list) {
60
        _ui->stackedWidget->setCurrentWidget(list);
61 62 63 64 65 66 67 68
    }
}

void QGCWaypointListMulti::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
69
        _ui->retranslateUi(this);
70 71 72 73 74
        break;
    default:
        break;
    }
}