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

QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) :
    QWidget(parent),
7 8
    offline_uas_id(0),
    ui(new Ui::QGCWaypointListMulti)
9 10
{
    ui->setupUi(this);
11
    setMinimumSize(600, 80);
12 13
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(systemCreated(UASInterface*)));
    connect(UASManager::instance(), SIGNAL(activeUASSet(int)), this, SLOT(systemSetActive(int)));
14

15
    WaypointList* list = new WaypointList(ui->stackedWidget, UASManager::instance()->getActiveUASWaypointManager());
16
    lists.insert(offline_uas_id, list);
17
    ui->stackedWidget->addWidget(list);
18 19 20 21 22 23

    if (UASManager::instance()->getActiveUAS()) {
        systemCreated(UASManager::instance()->getActiveUAS());
        systemSetActive(UASManager::instance()->getActiveUAS()->getUASID());
    }

24 25 26 27
}

void QGCWaypointListMulti::systemDeleted(QObject* uas)
{
28 29 30 31
    // Do not dynamic cast or de-reference QObject, since object is either in destructor or may have already
    // been destroyed.

    UASInterface* mav = static_cast<UASInterface*>(uas);
lm's avatar
lm committed
32 33
    if (mav)
    {
34 35
        int id = mav->getUASID();
        WaypointList* list = lists.value(id, NULL);
lm's avatar
lm committed
36 37
        if (list)
        {
38 39 40 41 42 43 44 45
            delete list;
            lists.remove(id);
        }
    }
}

void QGCWaypointListMulti::systemCreated(UASInterface* uas)
{
46
    WaypointList* list = new WaypointList(ui->stackedWidget, uas->getWaypointManager());
47 48 49 50 51 52 53 54 55
    lists.insert(uas->getUASID(), list);
    ui->stackedWidget->addWidget(list);
    // Ensure widget is deleted when system is deleted
    connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(systemDeleted(QObject*)));
}

void QGCWaypointListMulti::systemSetActive(int uas)
{
    WaypointList* list = lists.value(uas, NULL);
56
    if (list) {
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        ui->stackedWidget->setCurrentWidget(list);
    }
}

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

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