src/ChartiSpindel.cpp

changeset 333
499c95108bbd
child 334
9203fa01ddbf
--- /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() {}
+

mercurial