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

17
    // Add each of them
18
    foreach (UASInterface* sys, systems) {
19 20
        addSystem(sys);
    }
21
    connect(UASManager::instance(), &UASManager::UASCreated, this, &Linecharts::addSystem);
22 23
}

24
void Linecharts::showEvent(QShowEvent* event)
25
{
26 27
    // React only to internal (pre-display)
    // events
LM's avatar
LM committed
28 29 30 31 32 33 34 35
    Q_UNUSED(event)
    QWidget* prevWidget = currentWidget();
    if (prevWidget)
    {
        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
        if (chart) {
            this->active = true;
            chart->setActive(true);
36 37
        }
    }
LM's avatar
LM committed
38 39
    QWidget::showEvent(event);
    emit visibilityChanged(true);
40 41 42 43 44 45
}

void Linecharts::hideEvent(QHideEvent* event)
{
    // React only to internal (pre-display)
    // events
LM's avatar
LM committed
46 47 48 49 50 51 52
    Q_UNUSED(event)
    QWidget* prevWidget = currentWidget();
    if (prevWidget) {
        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
        if (chart) {
            this->active = false;
            chart->setActive(false);
53 54
        }
    }
LM's avatar
LM committed
55 56
    QWidget::hideEvent(event);
    emit visibilityChanged(false);
57 58 59 60
}

void Linecharts::addSystem(UASInterface* uas)
{
61 62 63 64 65
    // FIXME Add removeSystem() call

    // Compatibility hack
    int uasid = 0; /*uas->getUASID()*/
    if (!plots.contains(uasid))
lm's avatar
lm committed
66
    {
67
        LinechartWidget* widget = new LinechartWidget(uasid, this);
68
        addWidget(widget);
69
        plots.insert(uasid, widget);
70 71
		
		// Connect valueChanged signals
72
        connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), widget, SLOT(appendData(int,QString,QString,QVariant,quint64)));
73

74
        connect(widget, SIGNAL(logfileWritten(QString)), this, SIGNAL(logfileWritten(QString)));
75
        // Set system active if this is the only system
76 77 78 79
//        if (active)
//        {
//            if (plots.size() == 1)
//            {
lm's avatar
lm committed
80 81 82 83
                // FIXME XXX HACK
                // Connect generic sources
                for (int i = 0; i < genericSources.count(); ++i)
                {
84
                    connect(genericSources[i], SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), plots.values().first(), SLOT(appendData(int,QString,QString,QVariant,quint64)));
lm's avatar
lm committed
85 86
                }
                // Select system
87 88
                widget->setActive(true);
                //widget->selectActiveSystem(0);
89
            }
90 91
//        }
//    }
92
}
lm's avatar
lm committed
93 94 95 96 97 98 99 100

void Linecharts::addSource(QObject* obj)
{
    genericSources.append(obj);
    // FIXME XXX HACK
    if (plots.size() > 0)
    {
        // Connect generic source
101
        connect(obj, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), plots.values().first(), SLOT(appendData(int,QString,QString,QVariant,quint64)));
lm's avatar
lm committed
102
    }
103
}