QGCUASFileViewMulti.cc 1.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "QGCUASFileViewMulti.h"
#include "ui_QGCUASFileViewMulti.h"
#include "UASInterface.h"
#include "UASManager.h"
#include "QGCUASFileView.h"

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

    if (UASManager::instance()->getActiveUAS()) {
        systemCreated(UASManager::instance()->getActiveUAS());
18
        systemSetActive(UASManager::instance()->getActiveUAS());
19 20 21 22 23 24
    }

}

void QGCUASFileViewMulti::systemDeleted(QObject* uas)
{
25 26 27 28 29 30 31 32
    Q_ASSERT(uas);
    
    // 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);
    QGCUASFileView* list = lists.value(mav, NULL);
    if (list)
33
    {
34 35
        delete list;
        lists.remove(mav);
36 37 38 39 40
    }
}

void QGCUASFileViewMulti::systemCreated(UASInterface* uas)
{
41
    Q_ASSERT(uas);
42 43

    QGCUASFileView* list = new QGCUASFileView(ui->stackedWidget, uas->getFileManager());
44
    lists.insert(uas, list);
45 46 47 48 49
    ui->stackedWidget->addWidget(list);
    // Ensure widget is deleted when system is deleted
    connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(systemDeleted(QObject*)));
}

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

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

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