473 |
473 |
474 QLineSeries *pv_mlt = new QLineSeries(); |
474 QLineSeries *pv_mlt = new QLineSeries(); |
475 pv_mlt->setName("MLT"); |
475 pv_mlt->setName("MLT"); |
476 QLineSeries *sp_mlt = new QLineSeries(); |
476 QLineSeries *sp_mlt = new QLineSeries(); |
477 sp_mlt->setName("Set"); |
477 sp_mlt->setName("Set"); |
|
478 sp_mlt->setOpacity(0.75); |
478 QLineSeries *pv_hlt = new QLineSeries(); |
479 QLineSeries *pv_hlt = new QLineSeries(); |
479 pv_hlt->setName("HLT"); |
480 pv_hlt->setName("HLT"); |
|
481 QLineSeries *pwm_mlt1 = new QLineSeries(); // Top side of area |
|
482 QLineSeries *pwm_mlt0 = new QLineSeries(); // Bottom side of area |
480 |
483 |
481 query.prepare("SELECT * FROM log_brews WHERE code=:code ORDER BY datetime"); |
484 query.prepare("SELECT * FROM log_brews WHERE code=:code ORDER BY datetime"); |
482 query.bindValue(":code", product->code); |
485 query.bindValue(":code", product->code); |
483 query.exec(); |
486 query.exec(); |
484 while (query.next()) { |
487 while (query.next()) { |
485 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; |
488 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; |
486 pv_mlt->append(timestamp, query.value("pv_mlt").toDouble()); |
489 pv_mlt->append(timestamp, query.value("pv_mlt").toDouble()); |
487 sp_mlt->append(timestamp, query.value("sp_mlt").toDouble()); |
490 sp_mlt->append(timestamp, query.value("sp_mlt").toDouble()); |
488 pv_hlt->append(timestamp, query.value("pv_hlt").toDouble()); |
491 if (query.value("pv_hlt").toDouble() > 0) |
489 } |
492 pv_hlt->append(timestamp, query.value("pv_hlt").toDouble()); |
|
493 pwm_mlt0->append(timestamp, 0); |
|
494 pwm_mlt1->append(timestamp, query.value("pwm_mlt").toInt()); |
|
495 } |
|
496 |
|
497 QPen pen(QColorConstants::Svg::navy); |
|
498 pen.setWidth(3); |
|
499 pv_mlt->setPen(pen); |
|
500 QAreaSeries *pwm_mlt = new QAreaSeries(pwm_mlt0, pwm_mlt1); |
|
501 pwm_mlt->setName("MLT pwr"); |
|
502 pwm_mlt->setOpacity(0.25); |
490 |
503 |
491 QChart *chart = new QChart(); |
504 QChart *chart = new QChart(); |
492 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name)); |
505 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name)); |
493 chart->addSeries(pv_mlt); // Add dataset to chart |
506 chart->addSeries(pwm_mlt); // Order is important, first drawn is lowest layer. |
494 chart->addSeries(sp_mlt); |
507 chart->addSeries(sp_mlt); |
495 chart->addSeries(pv_hlt); |
508 chart->addSeries(pv_hlt); |
|
509 chart->addSeries(pv_mlt); // Top layer. |
496 |
510 |
497 QDateTimeAxis *axisX = new QDateTimeAxis; |
511 QDateTimeAxis *axisX = new QDateTimeAxis; |
498 axisX->setTickCount(20); |
512 axisX->setTickCount(20); |
499 axisX->setFormat("HH:mm"); |
513 axisX->setFormat("HH:mm"); |
500 axisX->setTitleText("Time"); |
514 axisX->setTitleText("Time"); |
501 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
515 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
502 chart->addAxis(axisX, Qt::AlignBottom); |
516 chart->addAxis(axisX, Qt::AlignBottom); |
503 pv_mlt->attachAxis(axisX); |
517 pv_mlt->attachAxis(axisX); |
|
518 pv_hlt->attachAxis(axisX); |
504 |
519 |
505 QValueAxis *axisY = new QValueAxis; |
520 QValueAxis *axisY = new QValueAxis; |
506 axisY->setRange(5, 105); |
521 axisY->setRange(0, 110); |
507 axisY->setTickCount(11); |
522 axisY->setTickCount(12); |
508 axisY->setMinorTickCount(1); |
523 axisY->setMinorTickCount(1); |
509 axisY->setLabelFormat("%i"); |
524 axisY->setLabelFormat("%i"); |
510 axisY->setTitleText("Temp"); |
525 axisY->setTitleText("Temp/Power"); |
511 axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
526 axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
512 chart->addAxis(axisY, Qt::AlignLeft); |
527 chart->addAxis(axisY, Qt::AlignLeft); |
|
528 |
|
529 pwm_mlt->attachAxis(axisY); |
513 pv_mlt->attachAxis(axisY); |
530 pv_mlt->attachAxis(axisY); |
514 sp_mlt->attachAxis(axisY); |
531 sp_mlt->attachAxis(axisY); |
515 pv_hlt->attachAxis(axisY); |
532 pv_hlt->attachAxis(axisY); |
516 |
533 |
517 QChartView *chartView = new QChartView(chart); |
534 QChartView *chartView = new QChartView(chart); |
518 chartView->setRenderHint(QPainter::Antialiasing); |
535 chartView->setRenderHint(QPainter::Antialiasing); |
519 // chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean); |
|
520 dialog->setLayout(new QVBoxLayout); |
536 dialog->setLayout(new QVBoxLayout); |
521 dialog->layout()->addWidget(chartView); |
537 dialog->layout()->addWidget(chartView); |
522 dialog->layout()->addWidget(buttonBox); |
538 dialog->layout()->addWidget(buttonBox); |
523 |
539 |
524 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
540 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |