QGCWaypointListMulti.cc 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9
#include "QGCWaypointListMulti.h"
#include "ui_QGCWaypointListMulti.h"
#include "UASManager.h"

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

void QGCWaypointListMulti::systemDeleted(QObject* uas)
{
    UASInterface* mav = dynamic_cast<UASInterface*>(uas);
lm's avatar
lm committed
18 19
    if (mav)
    {
20 21
        int id = mav->getUASID();
        WaypointList* list = lists.value(id, NULL);
lm's avatar
lm committed
22 23
        if (list)
        {
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
            delete list;
            lists.remove(id);
        }
    }
}

void QGCWaypointListMulti::systemCreated(UASInterface* uas)
{
    WaypointList* list = new WaypointList(ui->stackedWidget, uas);
    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);
42
    if (list) {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        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;
    }
}