Linecharts.cc 3.25 KB
Newer Older
1 2
#include <QShowEvent>

3
#include "Linecharts.h"
lm's avatar
lm committed
4
#include "UASManager.h"
5

6 7
#include "MainWindow.h"

8 9 10 11 12
Linecharts::Linecharts(QWidget *parent) :
        QStackedWidget(parent),
        plots(),
        active(true)
{
13 14 15
    this->setVisible(false);
    // Get current MAV list
    QList<UASInterface*> systems = UASManager::instance()->getUASList();
lm's avatar
lm committed
16

17 18 19 20 21 22 23 24 25 26 27
    // Add each of them
    foreach (UASInterface* sys, systems)
    {
        addSystem(sys);
    }
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
            this, SLOT(addSystem(UASInterface*)));
    connect(UASManager::instance(), SIGNAL(activeUASSet(int)),
            this, SLOT(selectSystem(int)));
    connect(this, SIGNAL(logfileWritten(QString)),
            MainWindow::instance(), SLOT(loadDataView(QString)));
28 29
}

30
void Linecharts::showEvent(QShowEvent* event)
31
{
32 33
    // React only to internal (pre-display)
    // events
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    Q_UNUSED(event)
    {
        QWidget* prevWidget = currentWidget();
        if (prevWidget)
        {
            LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
            if (chart)
            {
                this->active = true;
                chart->setActive(true);
            }
        }
    }
}

void Linecharts::hideEvent(QHideEvent* event)
{
    // React only to internal (pre-display)
    // events
    Q_UNUSED(event)
54
    {
55 56
        QWidget* prevWidget = currentWidget();
        if (prevWidget)
57
        {
58 59 60
            LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
            if (chart)
            {
61 62
                this->active = false;
                chart->setActive(false);
63
            }
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        }
    }
}

void Linecharts::selectSystem(int systemid)
{
    QWidget* prevWidget = currentWidget();
    if (prevWidget)
    {
        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
        if (chart)
        {
            chart->setActive(false);
        }
    }
    QWidget* widget = plots.value(systemid, NULL);
    if (widget)
    {
        setCurrentWidget(widget);
        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(widget);
        if (chart)
        {
            chart->setActive(true);
        }
    }
}

void Linecharts::addSystem(UASInterface* uas)
{
    if (!plots.contains(uas->getUASID()))
    {
        LinechartWidget* widget = new LinechartWidget(uas->getUASID(), this);
        addWidget(widget);
        plots.insert(uas->getUASID(), widget);
98
#ifndef MAVLINK_ENABLED_SLUGS
99 100 101 102 103
        // Values without unit
        //connect(uas, SIGNAL(valueChanged(int,QString,double,quint64)), widget, SLOT(appendData(int,QString,double,quint64)));
        // Values with unit as double
        connect(uas, SIGNAL(valueChanged(int,QString,QString,double,quint64)), widget, SLOT(appendData(int,QString,QString,double,quint64)));
        // Values with unit as integer
104
        connect(uas, SIGNAL(valueChanged(int,QString,QString,int,quint64)), widget, SLOT(appendData(int,QString,QString,int,quint64)));
105
#endif
106
        connect(widget, SIGNAL(logfileWritten(QString)), this, SIGNAL(logfileWritten(QString)));
107 108 109 110 111 112 113 114 115 116
        // Set system active if this is the only system
        if (active)
        {
            if (plots.size() == 1)
            {
                selectSystem(uas->getUASID());
            }
        }
    }
}