Linecharts.cc 1.66 KB
Newer Older
1 2 3 4 5 6 7
#include "Linecharts.h"

Linecharts::Linecharts(QWidget *parent) :
        QStackedWidget(parent),
        plots(),
        active(true)
{
8
  this->setVisible(false);
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
}


void Linecharts::setActive(bool active)
{
    this->active = active;
    QWidget* prevWidget = currentWidget();
    if (prevWidget)
    {
        LinechartWidget* chart = dynamic_cast<LinechartWidget*>(prevWidget);
        if (chart)
        {
            chart->setActive(active);
        }
    }
}


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);
        connect(uas, SIGNAL(valueChanged(int,QString,double,quint64)), widget, SLOT(appendData(int,QString,double,quint64)));
58
        connect(widget, SIGNAL(logfileWritten(QString)), this, SIGNAL(logfileWritten(QString)));
59 60 61 62 63 64 65 66 67 68
        // Set system active if this is the only system
        if (active)
        {
            if (plots.size() == 1)
            {
                selectSystem(uas->getUASID());
            }
        }
    }
}