Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.

Sun, 03 Jul 2022 13:12:22 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 03 Jul 2022 13:12:22 +0200
changeset 332
146874d7bb47
parent 331
612925137029
child 333
499c95108bbd

Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/ChartCarbonate.cpp file | annotate | diff | comparison | revisions
src/ChartCarbonate.h file | annotate | diff | comparison | revisions
src/DetailCO2meter.cpp file | annotate | diff | comparison | revisions
src/DetailCO2meter.h file | annotate | diff | comparison | revisions
src/EditProduct.cpp file | annotate | diff | comparison | revisions
src/EditProductTab11.cpp file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Jul 02 15:45:01 2022 +0200
+++ b/CMakeLists.txt	Sun Jul 03 13:12:22 2022 +0200
@@ -224,6 +224,7 @@
     ${SRCDIR}/DetailFermenter.cpp
     ${SRCDIR}/DetailCO2meter.cpp
     ${SRCDIR}/DetailiSpindel.cpp
+    ${SRCDIR}/ChartCarbonate.cpp
     ${SRCDIR}/EditProduct.cpp
     ${SRCDIR}/ImportXML.cpp
     ${SRCDIR}/Setup.cpp
@@ -283,6 +284,7 @@
     ${SRCDIR}/DetailFermenter.h
     ${SRCDIR}/DetailCO2meter.h
     ${SRCDIR}/DetailiSpindel.h
+    ${SRCDIR}/ChartCarbonate.h
     ${SRCDIR}/EditProduct.h
     ${SRCDIR}/ImportXML.h
     ${SRCDIR}/Setup.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartCarbonate.cpp	Sun Jul 03 13:12:22 2022 +0200
@@ -0,0 +1,106 @@
+/**
+ * ChartCarbonate.cpp is part of bmsapp.
+ *
+ * bmsapp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bmsapp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "ChartCarbonate.h"
+#include "MainWindow.h"
+
+
+ChartCarbonate::ChartCarbonate(QString code, QString name, QWidget *parent) : QDialog(parent)
+{
+    QSqlQuery query;
+    double timestamp;
+
+    qDebug() << "ChartCarbonate:" << code << name;
+
+    QDialog* dialog = new QDialog(parent);
+    dialog->setWindowTitle(tr("BMSapp - Carbonation ") + "\"" + name + "\"");
+    dialog->setObjectName(QString::fromUtf8("ChartCarbonate"));
+    dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+    dialog->resize(1024, 600);
+
+    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", 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 °C"));
+    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(code).arg(name));
+    chart->addSeries(temperature);
+    chart->addSeries(pressure);
+
+    QDateTimeAxis *axisX = new QDateTimeAxis;
+    axisX->setTickCount(10);
+    axisX->setFormat("dd MMM");
+    axisX->setTitleText(tr("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(tr("Temperature °C"));
+    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(tr("Pressure 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);
+
+    QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
+    QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
+
+    dialog->setModal(true);
+    dialog->exec();
+}
+
+
+ChartCarbonate::~ChartCarbonate() {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartCarbonate.h	Sun Jul 03 13:12:22 2022 +0200
@@ -0,0 +1,22 @@
+#ifndef _CHARTCARBONATE_H
+#define _CHARTCARBONATE_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+
+
+namespace Ui {
+class ChartCarbonate;
+}
+
+class ChartCarbonate : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ChartCarbonate(QString code, QString name, QWidget *parent = 0);
+    ~ChartCarbonate();
+
+};
+
+#endif
--- a/src/DetailCO2meter.cpp	Sat Jul 02 15:45:01 2022 +0200
+++ b/src/DetailCO2meter.cpp	Sun Jul 03 13:12:22 2022 +0200
@@ -15,6 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "DetailCO2meter.h"
+#include "ChartCarbonate.h"
 #include "../ui/ui_DetailCO2meter.h"
 #include "global.h"
 #include "MainWindow.h"
@@ -53,6 +54,7 @@
     }
 
     connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailCO2meter::code_changed);
+    connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked()));
     connect(parent, SIGNAL(updateCO2meter(QString)), this, SLOT(refreshCO2meter(QString)));
     emit refreshTable();
 }
@@ -139,6 +141,12 @@
 }
 
 
+void DetailCO2meter::on_ChartButton_clicked()
+{
+    ChartCarbonate dialog(_beercode, _beername, this);
+}
+
+
 void DetailCO2meter::on_quitButton_clicked()
 {
     this->close();
--- a/src/DetailCO2meter.h	Sat Jul 02 15:45:01 2022 +0200
+++ b/src/DetailCO2meter.h	Sun Jul 03 13:12:22 2022 +0200
@@ -29,6 +29,7 @@
     void on_quitButton_clicked();
     void refreshTable(void);
     void code_changed(int val);
+    void on_ChartButton_clicked();
 
 public slots:
     void refreshCO2meter(QString);
--- a/src/EditProduct.cpp	Sat Jul 02 15:45:01 2022 +0200
+++ b/src/EditProduct.cpp	Sun Jul 03 13:12:22 2022 +0200
@@ -17,6 +17,7 @@
 #include "MainWindow.h"
 #include "EditProduct.h"
 #include "PrinterDialog.h"
+#include "ChartCarbonate.h"
 #include "../ui/ui_EditProduct.h"
 #include "Utils.h"
 #include "global.h"
--- a/src/EditProductTab11.cpp	Sat Jul 02 15:45:01 2022 +0200
+++ b/src/EditProductTab11.cpp	Sun Jul 03 13:12:22 2022 +0200
@@ -583,79 +583,6 @@
 
 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 °C"));
-    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(tr("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(tr("Temp °C"));
-    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(tr("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();
+    ChartCarbonate dialog(product->code, product->name, this);
 }
 
--- a/src/MainWindow.cpp	Sat Jul 02 15:45:01 2022 +0200
+++ b/src/MainWindow.cpp	Sun Jul 03 13:12:22 2022 +0200
@@ -466,7 +466,7 @@
     ui->mainStack->addWidget(MonCO2metersWindow);
     ui->mainStack->setCurrentIndex(index);
     setWindowTitle( QString("BMSapp - %1 - Monitor CO2meters").arg(VERSIONSTRING));
-//    ui->menuBar->setVisible(false);
+    ui->menuBar->setVisible(false);
 }
 
 

mercurial