src/EditProductTab11.cpp

changeset 332
146874d7bb47
parent 298
180c77a81e15
child 397
877420a13815
equal deleted inserted replaced
331:612925137029 332:146874d7bb47
581 } 581 }
582 582
583 583
584 void EditProduct::carb_log_button() 584 void EditProduct::carb_log_button()
585 { 585 {
586 QSqlQuery query; 586 ChartCarbonate dialog(product->code, product->name, this);
587 double timestamp; 587 }
588 588
589 QDialog* dialog = new QDialog(this);
590 dialog->resize(1024, 600);
591 dialog->setWindowTitle(tr("Carbonation log"));
592 dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
593
594 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
595 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
596 buttonBox->setGeometry(QRect(40, 565, 944, 36));
597 buttonBox->setLayoutDirection(Qt::LeftToRight);
598 buttonBox->setOrientation(Qt::Horizontal);
599 buttonBox->setStandardButtons(QDialogButtonBox::Ok);
600 buttonBox->setCenterButtons(true);
601
602 QSplineSeries *temperature = new QSplineSeries();
603 QSplineSeries *pressure = new QSplineSeries();
604
605 query.prepare("SELECT * FROM log_co2pressure WHERE code=:code ORDER BY datetime");
606 query.bindValue(":code", product->code);
607 query.exec();
608 while (query.next()) {
609 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
610 temperature->append(timestamp, query.value("temperature").toDouble());
611 pressure->append(timestamp, query.value("pressure").toDouble());
612 }
613
614 temperature->setName(tr("Temperature °C"));
615 temperature->setColor(QColorConstants::Svg::red);
616 pressure->setName(tr("Pressure bar"));
617 QPen pen(QColorConstants::Svg::navy);
618 pen.setWidth(3);
619 pressure->setPen(pen);
620
621 QChart *chart = new QChart();
622 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
623 chart->addSeries(temperature);
624 chart->addSeries(pressure);
625
626 QDateTimeAxis *axisX = new QDateTimeAxis;
627 axisX->setTickCount(10);
628 axisX->setFormat("dd MMM");
629 axisX->setTitleText(tr("Date"));
630 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
631 chart->addAxis(axisX, Qt::AlignBottom);
632 temperature->attachAxis(axisX);
633 pressure->attachAxis(axisX);
634
635 QValueAxis *axisYT = new QValueAxis;
636 axisYT->setTickCount(10);
637 axisYT->setLabelFormat("%.1f");
638 axisYT->setTitleText(tr("Temp °C"));
639 axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
640 chart->addAxis(axisYT, Qt::AlignRight);
641 temperature->attachAxis(axisYT);
642
643 QValueAxis *axisYP = new QValueAxis;
644 axisYP->setTickCount(10);
645 axisYP->setLabelFormat("%.1f");
646 axisYP->setTitleText(tr("Bar"));
647 axisYP->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
648 chart->addAxis(axisYP, Qt::AlignLeft);
649 pressure->attachAxis(axisYP);
650
651 QChartView *chartView = new QChartView(chart);
652 chartView->setRenderHint(QPainter::Antialiasing);
653 dialog->setLayout(new QVBoxLayout);
654 dialog->layout()->addWidget(chartView);
655 dialog->layout()->addWidget(buttonBox);
656
657 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
658 dialog->setModal(true);
659 dialog->exec();
660 }
661

mercurial