--- a/src/EditProductTab11.cpp Sat Jun 18 20:39:59 2022 +0200 +++ b/src/EditProductTab11.cpp Sun Jun 19 10:40:37 2022 +0200 @@ -581,3 +581,81 @@ } +void EditProduct::carb_log_button() +{ + QSqlQuery query; + double timestamp; + + QDialog* dialog = new QDialog(this); + dialog->resize(1024, 600); + dialog->setWindowTitle(tr("Carbonation log")); + dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(40, 565, 944, 36)); + buttonBox->setLayoutDirection(Qt::LeftToRight); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Ok); + buttonBox->setCenterButtons(true); + + QSplineSeries *temperature = new QSplineSeries(); + QSplineSeries *pressure = new QSplineSeries(); + + query.prepare("SELECT * FROM log_co2pressure WHERE code=:code ORDER BY datetime"); + query.bindValue(":code", product->code); + query.exec(); + while (query.next()) { + timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; + temperature->append(timestamp, query.value("temperature").toDouble()); + pressure->append(timestamp, query.value("pressure").toDouble()); + } + + temperature->setName(tr("Temperature")); + temperature->setColor(QColorConstants::Svg::red); + pressure->setName(tr("Pressure bar")); + QPen pen(QColorConstants::Svg::navy); + pen.setWidth(3); + pressure->setPen(pen); + + QChart *chart = new QChart(); + chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name)); + chart->addSeries(temperature); + chart->addSeries(pressure); + + QDateTimeAxis *axisX = new QDateTimeAxis; + axisX->setTickCount(10); + axisX->setFormat("dd MMM"); + axisX->setTitleText("Date"); + axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); + chart->addAxis(axisX, Qt::AlignBottom); + temperature->attachAxis(axisX); + pressure->attachAxis(axisX); + + QValueAxis *axisYT = new QValueAxis; + axisYT->setTickCount(10); + axisYT->setLabelFormat("%.1f"); + axisYT->setTitleText("Temp"); + axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); + chart->addAxis(axisYT, Qt::AlignRight); + temperature->attachAxis(axisYT); + + QValueAxis *axisYP = new QValueAxis; + axisYP->setTickCount(10); + axisYP->setLabelFormat("%.1f"); + axisYP->setTitleText("Bar"); + axisYP->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); + chart->addAxis(axisYP, Qt::AlignLeft); + pressure->attachAxis(axisYP); + + QChartView *chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + dialog->setLayout(new QVBoxLayout); + dialog->layout()->addWidget(chartView); + dialog->layout()->addWidget(buttonBox); + + connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + dialog->setModal(true); + dialog->exec(); +} +