Linecharts.cc 3.76 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 21 22 23 24
        addSystem(sys);
    }
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
            this, SLOT(addSystem(UASInterface*)));
    connect(UASManager::instance(), SIGNAL(activeUASSet(int)),
            this, SLOT(selectSystem(int)));
25 26
}

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

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

void Linecharts::selectSystem(int systemid)
{
64
	Q_UNUSED(systemid);
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
//    QWidget* prevWidget = currentWidget();
//    if (prevWidget)
//    {
//        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
//        if (chart)
//        {
//            chart->setActive(false);
//            chart->setActiveSystem(systemid);
//        }
//    }
//    QWidget* widget = plots.value(systemid, NULL);
//    if (widget)
//    {
//        setCurrentWidget(widget);
//        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(widget);
//        if (chart)
//        {
//            chart->setActive(true);
//            chart->setActiveSystem(systemid);
//        }
//    }
86 87 88 89
}

void Linecharts::addSystem(UASInterface* uas)
{
90 91 92 93 94
    // FIXME Add removeSystem() call

    // Compatibility hack
    int uasid = 0; /*uas->getUASID()*/
    if (!plots.contains(uasid))
lm's avatar
lm committed
95
    {
96
        LinechartWidget* widget = new LinechartWidget(uasid, this);
97
        addWidget(widget);
98
        plots.insert(uasid, widget);
99 100
		
		// Connect valueChanged signals
101
        connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), widget, SLOT(appendData(int,QString,QString,QVariant,quint64)));
102

103
        connect(widget, SIGNAL(logfileWritten(QString)), this, SIGNAL(logfileWritten(QString)));
104
        // Set system active if this is the only system
105 106 107 108
//        if (active)
//        {
//            if (plots.size() == 1)
//            {
lm's avatar
lm committed
109 110 111 112
                // FIXME XXX HACK
                // Connect generic sources
                for (int i = 0; i < genericSources.count(); ++i)
                {
113
                    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
114 115
                }
                // Select system
116 117
                widget->setActive(true);
                //widget->selectActiveSystem(0);
118
            }
119 120
//        }
//    }
121
}
lm's avatar
lm committed
122 123 124 125 126 127 128 129

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