Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.

Sun, 03 Jul 2022 14:30:49 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 03 Jul 2022 14:30:49 +0200
changeset 333
499c95108bbd
parent 332
146874d7bb47
child 334
9203fa01ddbf

Moved Fermenter and iSpindel charts to their own functions. Added these to DetailFermenter and DetailiSpindel too.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/ChartFermenter.cpp file | annotate | diff | comparison | revisions
src/ChartFermenter.h file | annotate | diff | comparison | revisions
src/ChartiSpindel.cpp file | annotate | diff | comparison | revisions
src/ChartiSpindel.h file | annotate | diff | comparison | revisions
src/DetailFermenter.cpp file | annotate | diff | comparison | revisions
src/DetailFermenter.h file | annotate | diff | comparison | revisions
src/DetailiSpindel.cpp file | annotate | diff | comparison | revisions
src/DetailiSpindel.h file | annotate | diff | comparison | revisions
src/EditProduct.cpp file | annotate | diff | comparison | revisions
src/EditProductTab10.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sun Jul 03 13:12:22 2022 +0200
+++ b/CMakeLists.txt	Sun Jul 03 14:30:49 2022 +0200
@@ -225,6 +225,8 @@
     ${SRCDIR}/DetailCO2meter.cpp
     ${SRCDIR}/DetailiSpindel.cpp
     ${SRCDIR}/ChartCarbonate.cpp
+    ${SRCDIR}/ChartFermenter.cpp
+    ${SRCDIR}/ChartiSpindel.cpp
     ${SRCDIR}/EditProduct.cpp
     ${SRCDIR}/ImportXML.cpp
     ${SRCDIR}/Setup.cpp
@@ -285,6 +287,8 @@
     ${SRCDIR}/DetailCO2meter.h
     ${SRCDIR}/DetailiSpindel.h
     ${SRCDIR}/ChartCarbonate.h
+    ${SRCDIR}/ChartFermenter.h
+    ${SRCDIR}/ChartiSpindel.h
     ${SRCDIR}/EditProduct.h
     ${SRCDIR}/ImportXML.h
     ${SRCDIR}/Setup.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartFermenter.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -0,0 +1,134 @@
+/**
+ * ChartFermenter.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 "ChartFermenter.h"
+#include "MainWindow.h"
+
+
+ChartFermenter::ChartFermenter(QString code, QString name, QWidget *parent) : QDialog(parent)
+{
+    QSqlQuery query;
+    double timestamp;
+
+    qDebug() << "ChartFermenter:" << code << name;
+
+    QDialog* dialog = new QDialog(parent);
+    dialog->setWindowTitle(tr("BMSapp - Fermenter log ") + "\"" + name + "\"");
+    dialog->setObjectName(QString::fromUtf8("ChartFermenter"));
+    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 *pv_air = new QSplineSeries();
+    QSplineSeries *pv_beer = new QSplineSeries();
+    QSplineSeries *pv_chiller = new QSplineSeries();
+    QSplineSeries *pwr_cool = new QSplineSeries();
+    QSplineSeries *pwr_heat = new QSplineSeries();
+
+    query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime");
+    query.bindValue(":code", code);
+    query.exec();
+    while (query.next()) {
+        timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
+        pv_air->append(timestamp, query.value("temp_air").toDouble());
+        pv_beer->append(timestamp, query.value("temp_beer").toDouble());
+        if (query.value("temp_chiller").toDouble() > 0)
+            pv_chiller->append(timestamp, query.value("temp_chiller").toDouble());
+        pwr_cool->append(timestamp, query.value("cooler_power").toDouble());
+        pwr_heat->append(timestamp, query.value("heater_power").toDouble());
+    }
+
+    pv_air->setName(tr("Air"));
+    pv_air->setColor(QColorConstants::Svg::lightgreen);
+    pv_beer->setName(tr("Beer"));
+    QPen pen(QColorConstants::Svg::navy);
+    pen.setWidth(3);
+    pv_beer->setPen(pen);
+    pv_chiller->setName(tr("Chiller"));
+    pv_chiller->setColor(QColorConstants::Svg::lightsalmon);
+    pv_chiller->setOpacity(0.75);
+
+    pwr_cool->setName("Cool %");
+    pwr_cool->setOpacity(0.25);
+    pwr_cool->setColor(QColorConstants::Blue);
+    pwr_heat->setName("Heat %");
+    pwr_heat->setOpacity(0.25);
+    pwr_heat->setColor(QColorConstants::Red);
+
+    QChart *chart = new QChart();
+    chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name));
+    chart->addSeries(pwr_cool);
+    chart->addSeries(pwr_heat);
+    chart->addSeries(pv_chiller);
+    chart->addSeries(pv_air);
+    chart->addSeries(pv_beer);
+
+    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);
+    pv_air->attachAxis(axisX);
+    pv_beer->attachAxis(axisX);
+    pv_chiller->attachAxis(axisX);
+
+    QValueAxis *axisY = new QValueAxis;
+    axisY->setTickCount(11);
+    axisY->setMinorTickCount(1);
+    axisY->setLabelFormat("%i");
+    axisY->setTitleText(tr("Temp °C"));
+    axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisY, Qt::AlignLeft);
+    pv_air->attachAxis(axisY);
+    pv_beer->attachAxis(axisY);
+    pv_chiller->attachAxis(axisY);
+
+    QValueAxis *axisYR = new QValueAxis;
+    axisYR->setRange(0, 100);
+    axisYR->setTickCount(11);
+    axisYR->setLabelFormat("%i");
+    axisYR->setTitleText(tr("Power %"));
+    axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYR, Qt::AlignRight);
+    pwr_cool->attachAxis(axisYR);
+    pwr_heat->attachAxis(axisYR);
+
+
+
+    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();
+}
+
+
+ChartFermenter::~ChartFermenter() {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartFermenter.h	Sun Jul 03 14:30:49 2022 +0200
@@ -0,0 +1,22 @@
+#ifndef _CHARTFERMENTER_H
+#define _CHARTFERMENTER_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+
+
+namespace Ui {
+class ChartFermenter;
+}
+
+class ChartFermenter : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ChartFermenter(QString code, QString name, QWidget *parent = 0);
+    ~ChartFermenter();
+
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartiSpindel.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -0,0 +1,120 @@
+/**
+ * ChartiSpindel.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 "ChartiSpindel.h"
+#include "MainWindow.h"
+
+
+ChartiSpindel::ChartiSpindel(QString code, QString name, QWidget *parent) : QDialog(parent)
+{
+    QSqlQuery query;
+    double timestamp;
+
+    qDebug() << "ChartiSpindel:" << code << name;
+
+    QDialog* dialog = new QDialog(parent);
+    dialog->setWindowTitle(tr("BMSapp - Carbonation ") + "\"" + name + "\"");
+    dialog->setObjectName(QString::fromUtf8("ChartiSpindel"));
+    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 *density = new QSplineSeries();
+    QSplineSeries *battery = new QSplineSeries();
+
+    query.prepare("SELECT * FROM log_ispindel 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());
+        density->append(timestamp, query.value("sg").toDouble());
+        battery ->append(timestamp, query.value("battery").toDouble());
+    }
+
+    temperature->setName(tr("Temp °C"));
+    temperature->setColor(QColorConstants::Svg::red);
+    density->setName(tr("SG"));
+    QPen pen(QColorConstants::Svg::navy);
+    pen.setWidth(3);
+    density->setPen(pen);
+    battery->setName(tr("Battery"));
+    battery->setColor(QColorConstants::Svg::limegreen);
+
+    QChart *chart = new QChart();
+    chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name));
+    chart->addSeries(battery);
+    chart->addSeries(temperature);
+    chart->addSeries(density);
+
+    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);
+    battery->attachAxis(axisX);
+    temperature->attachAxis(axisX);
+    density->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 *axisYD = new QValueAxis;
+    axisYD->setTickCount(10);
+    axisYD->setLabelFormat("%.3f");
+    axisYD->setTitleText("SG");
+    axisYD->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYD, Qt::AlignLeft);
+    density->attachAxis(axisYD);
+
+    QValueAxis *axisYB = new QValueAxis;
+    axisYB->setTickCount(10);
+    axisYB->setLabelFormat("%.2f");
+    axisYB->setTitleText(tr("Battery volt"));
+    axisYB->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYB, Qt::AlignRight);
+    battery->attachAxis(axisYB);
+
+    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();
+}
+
+
+ChartiSpindel::~ChartiSpindel() {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ChartiSpindel.h	Sun Jul 03 14:30:49 2022 +0200
@@ -0,0 +1,22 @@
+#ifndef _CHARTISPINDEL_H
+#define _CHARTISPINDEL_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+
+
+namespace Ui {
+class ChartiSpindel;
+}
+
+class ChartiSpindel : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ChartiSpindel(QString code, QString name, QWidget *parent = 0);
+    ~ChartiSpindel();
+
+};
+
+#endif
--- a/src/DetailFermenter.cpp	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/DetailFermenter.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -15,6 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "DetailFermenter.h"
+#include "ChartFermenter.h"
 #include "../ui/ui_DetailFermenter.h"
 #include "global.h"
 #include "MainWindow.h"
@@ -86,6 +87,7 @@
     connect(ui->stageEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::stage_changed);
     connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::code_changed);
     connect(ui->profilePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::profile_changed);
+    connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked()));
     connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString)));
     emit refreshTable();
 }
@@ -332,6 +334,12 @@
 }
 
 
+void DetailFermenter::on_ChartButton_clicked()
+{
+    ChartFermenter dialog(_beercode, _beername, this);
+}
+
+
 void DetailFermenter::on_quitButton_clicked()
 {
     this->close();
--- a/src/DetailFermenter.h	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/DetailFermenter.h	Sun Jul 03 14:30:49 2022 +0200
@@ -39,6 +39,7 @@
     void stage_changed(int val);
     void code_changed(int val);
     void profile_changed(int val);
+    void on_ChartButton_clicked();
 
 public slots:
     void refreshFermenter(QString);
--- a/src/DetailiSpindel.cpp	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/DetailiSpindel.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -15,6 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "DetailiSpindel.h"
+#include "ChartiSpindel.h"
 #include "../ui/ui_DetailiSpindel.h"
 #include "global.h"
 #include "Utils.h"
@@ -53,6 +54,7 @@
 
     connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::code_changed);
     connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailiSpindel::mode_changed);
+    connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked()));
     connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString)));
     emit refreshTable();
 }
@@ -170,6 +172,12 @@
 }
 
 
+void DetailiSpindel::on_ChartButton_clicked()
+{
+    ChartiSpindel dialog(_beercode, _beername, this);
+}
+
+
 void DetailiSpindel::on_quitButton_clicked()
 {
     this->close();
--- a/src/DetailiSpindel.h	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/DetailiSpindel.h	Sun Jul 03 14:30:49 2022 +0200
@@ -30,6 +30,7 @@
     void refreshTable(void);
     void mode_changed(int val);
     void code_changed(int val);
+    void on_ChartButton_clicked();
 
 public slots:
     void refreshiSpindel(QString);
--- a/src/EditProduct.cpp	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/EditProduct.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -18,6 +18,8 @@
 #include "EditProduct.h"
 #include "PrinterDialog.h"
 #include "ChartCarbonate.h"
+#include "ChartFermenter.h"
+#include "ChartiSpindel.h"
 #include "../ui/ui_EditProduct.h"
 #include "Utils.h"
 #include "global.h"
--- a/src/EditProductTab10.cpp	Sun Jul 03 13:12:22 2022 +0200
+++ b/src/EditProductTab10.cpp	Sun Jul 03 14:30:49 2022 +0200
@@ -265,199 +265,13 @@
 
 void EditProduct::ferm_log1_button()
 {
-    QSqlQuery query;
-    double timestamp;
-
-    QDialog* dialog = new QDialog(this);
-    dialog->resize(1024, 600);
-    dialog->setWindowTitle(tr("Fermenter 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 *pv_air = new QSplineSeries();
-    QSplineSeries *pv_beer = new QSplineSeries();
-    QSplineSeries *pv_chiller = new QSplineSeries();
-    QSplineSeries *pwr_cool = new QSplineSeries();
-    QSplineSeries *pwr_heat = new QSplineSeries();
-
-    query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime");
-    query.bindValue(":code", product->code);
-    query.exec();
-    while (query.next()) {
-	timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
-	pv_air->append(timestamp, query.value("temp_air").toDouble());
-	pv_beer->append(timestamp, query.value("temp_beer").toDouble());
-	if (query.value("temp_chiller").toDouble() > 0)
-	    pv_chiller->append(timestamp, query.value("temp_chiller").toDouble());
-	pwr_cool->append(timestamp, query.value("cooler_power").toDouble());
-        pwr_heat->append(timestamp, query.value("heater_power").toDouble());
-    }
-
-    pv_air->setName(tr("Air"));
-    pv_air->setColor(QColorConstants::Svg::lightgreen);
-    pv_beer->setName(tr("Beer"));
-    QPen pen(QColorConstants::Svg::navy);
-    pen.setWidth(3);
-    pv_beer->setPen(pen);
-    pv_chiller->setName(tr("Chiller"));
-    pv_chiller->setColor(QColorConstants::Svg::lightsalmon);
-    pv_chiller->setOpacity(0.75);
-
-    pwr_cool->setName("Cool %");
-    pwr_cool->setOpacity(0.25);
-    pwr_cool->setColor(QColorConstants::Blue);
-    pwr_heat->setName("Heat %");
-    pwr_heat->setOpacity(0.25);
-    pwr_heat->setColor(QColorConstants::Red);
-
-    QChart *chart = new QChart();
-    chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
-    chart->addSeries(pwr_cool);
-    chart->addSeries(pwr_heat);
-    chart->addSeries(pv_chiller);
-    chart->addSeries(pv_air);
-    chart->addSeries(pv_beer);
-
-    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);
-    pv_air->attachAxis(axisX);
-    pv_beer->attachAxis(axisX);
-    pv_chiller->attachAxis(axisX);
-
-    QValueAxis *axisY = new QValueAxis;
-    axisY->setTickCount(11);
-    axisY->setMinorTickCount(1);
-    axisY->setLabelFormat("%i");
-    axisY->setTitleText(tr("Temp °C"));
-    axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
-    chart->addAxis(axisY, Qt::AlignLeft);
-    pv_air->attachAxis(axisY);
-    pv_beer->attachAxis(axisY);
-    pv_chiller->attachAxis(axisY);
-
-    QValueAxis *axisYR = new QValueAxis;
-    axisYR->setRange(0, 100);
-    axisYR->setTickCount(11);
-    axisYR->setLabelFormat("%i");
-    axisYR->setTitleText(tr("Power %"));
-    axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
-    chart->addAxis(axisYR, Qt::AlignRight);
-    pwr_cool->attachAxis(axisYR);
-    pwr_heat->attachAxis(axisYR);
-
-    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();
+    ChartFermenter dialog(product->code, product->name, this);
 }
 
 
 void EditProduct::ferm_log2_button()
 {
-    QSqlQuery query;
-    double timestamp;
-
-    QDialog* dialog = new QDialog(this);
-    dialog->resize(1024, 600);
-    dialog->setWindowTitle(tr("iSpindel 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 *density = new QSplineSeries();
-    QSplineSeries *battery = new QSplineSeries();
-
-    query.prepare("SELECT * FROM log_ispindel 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());
-        density->append(timestamp, query.value("sg").toDouble());
-        battery ->append(timestamp, query.value("battery").toDouble());
-    }
-
-    temperature->setName(tr("Temp °C"));
-    temperature->setColor(QColorConstants::Svg::red);
-    density->setName(tr("SG"));
-    QPen pen(QColorConstants::Svg::navy);
-    pen.setWidth(3);
-    density->setPen(pen);
-    battery->setName(tr("Battery"));
-    battery->setColor(QColorConstants::Svg::lightgreen);
-
-    QChart *chart = new QChart();
-    chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
-    chart->addSeries(battery);
-    chart->addSeries(temperature);
-    chart->addSeries(density);
-
-    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);
-    battery->attachAxis(axisX);
-    temperature->attachAxis(axisX);
-    density->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 *axisYD = new QValueAxis;
-    axisYD->setTickCount(10);
-    axisYD->setLabelFormat("%.3f");
-    axisYD->setTitleText("SG");
-    axisYD->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
-    chart->addAxis(axisYD, Qt::AlignLeft);
-    density->attachAxis(axisYD);
-
-    QValueAxis *axisYB = new QValueAxis;
-    axisYB->setTickCount(10);
-    axisYB->setLabelFormat("%.2f");
-    axisYB->setTitleText(tr("Battery volt"));
-    axisYB->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
-    chart->addAxis(axisYB, Qt::AlignRight);
-    battery->attachAxis(axisYB);
-
-    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();
+    ChartiSpindel dialog(product->code, product->name, this);
 }
 
 

mercurial