Ejemplo n.º 1
0
void Dialog::addTrend(QString attrName)
{

    QString s;
    s = QString("Adding ");
//    attrName = QString("gunlaser/devices/redpitayaevents2/measurementdata2");
    s.append(attrName);
    this->ui->infoLabel->setText(s);

    cout << "In Dialog::addTrend...\n";
    QCPAxis* ax = this->ui->plotWidget->axisRect()->addAxis(QCPAxis::AxisType::atLeft);
    ui->plotWidget->yAxis->setVisible(false);
    ax->setVisible(false);

    QCPGraph* graph = this->ui->plotWidget->addGraph(0, ax);

    QColor attrColor = this->mLightColorList[this->mCurrentColorListIndex];
    this->mCurrentColorListIndex++;
    if (this->mCurrentColorListIndex > this->mLightColorList.count())
    {
        this->mCurrentColorListIndex=0;
    }

    QTrendLegendWidget* leg = new QTrendLegendWidget(attrName, attrColor, this);
//    leg->setName(attrName);
    leg->setAxis(ax);
    leg->setGraph(graph);
    this->ui->verticalLayout_2->insertWidget(this->ui->verticalLayout_2->count()-1, leg);
//    this->ui->verticalLayout_2->addWidget(leg);
    this->trendLegendList.append(leg);

//    this->graphList.append(graph);
//    this->axisList.append(ax);
//    TrendCurve newCurve(attrName, graph, ax);

//    TrendCurve newCurve();
//    TrendCurve* newCurve = new TrendCurve(attrName, this->ui->plotWidget);
//    delete newCurve;
    try
    {
        TrendDataCollector* newCurve = new TrendDataCollector(attrName);
        QThread* thread = new QThread;
        newCurve->moveToThread(thread);
        connect(newCurve, SIGNAL(new_data(double,double)), leg, SLOT(updateData(double, double)));
        connect(thread, SIGNAL(started()), newCurve, SLOT(process()));

        connect(newCurve, SIGNAL(finished()), thread, SLOT(quit()));
        connect(newCurve, SIGNAL(finished()), newCurve, SLOT(deleteLater()));
        connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
        this->trendDataCollectorList.append(newCurve);
        this->threadList.append(thread);
        thread->start();
    }
    catch (...)
    {
        cout << "Error creating trend curve";
    };
}