Sun, 03 Jul 2022 13:12:22 +0200
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
332
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * ChartCarbonate.cpp is part of bmsapp. |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * bmsapp is free software: you can redistribute it and/or modify |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * it under the terms of the GNU General Public License as published by |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * the Free Software Foundation, either version 3 of the License, or |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * (at your option) any later version. |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * bmsapp is distributed in the hope that it will be useful, |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * GNU General Public License for more details. |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * You should have received a copy of the GNU General Public License |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | */ |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | #include "ChartCarbonate.h" |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | #include "MainWindow.h" |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | ChartCarbonate::ChartCarbonate(QString code, QString name, QWidget *parent) : QDialog(parent) |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | { |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | QSqlQuery query; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | double timestamp; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | qDebug() << "ChartCarbonate:" << code << name; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | QDialog* dialog = new QDialog(parent); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | dialog->setWindowTitle(tr("BMSapp - Carbonation ") + "\"" + name + "\""); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | dialog->setObjectName(QString::fromUtf8("ChartCarbonate")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | dialog->resize(1024, 600); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | buttonBox->setGeometry(QRect(40, 565, 944, 36)); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | buttonBox->setLayoutDirection(Qt::LeftToRight); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | buttonBox->setOrientation(Qt::Horizontal); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | buttonBox->setStandardButtons(QDialogButtonBox::Ok); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | buttonBox->setCenterButtons(true); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | QSplineSeries *temperature = new QSplineSeries(); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | QSplineSeries *pressure = new QSplineSeries(); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | query.prepare("SELECT * FROM log_co2pressure WHERE code=:code ORDER BY datetime"); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | query.bindValue(":code", code); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | query.exec(); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | while (query.next()) { |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | temperature->append(timestamp, query.value("temperature").toDouble()); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | pressure->append(timestamp, query.value("pressure").toDouble()); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | } |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | temperature->setName(tr("Temperature °C")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | temperature->setColor(QColorConstants::Svg::red); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | pressure->setName(tr("Pressure bar")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | QPen pen(QColorConstants::Svg::navy); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | pen.setWidth(3); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | pressure->setPen(pen); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | QChart *chart = new QChart(); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name)); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | chart->addSeries(temperature); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | chart->addSeries(pressure); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | QDateTimeAxis *axisX = new QDateTimeAxis; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | axisX->setTickCount(10); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | axisX->setFormat("dd MMM"); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | axisX->setTitleText(tr("Date")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | chart->addAxis(axisX, Qt::AlignBottom); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | temperature->attachAxis(axisX); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | pressure->attachAxis(axisX); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | QValueAxis *axisYT = new QValueAxis; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | axisYT->setTickCount(10); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | axisYT->setLabelFormat("%.1f"); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | axisYT->setTitleText(tr("Temperature °C")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | chart->addAxis(axisYT, Qt::AlignRight); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | temperature->attachAxis(axisYT); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | QValueAxis *axisYP = new QValueAxis; |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | axisYP->setTickCount(10); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | axisYP->setLabelFormat("%.1f"); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | axisYP->setTitleText(tr("Pressure bar")); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | axisYP->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | chart->addAxis(axisYP, Qt::AlignLeft); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | pressure->attachAxis(axisYP); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | QChartView *chartView = new QChartView(chart); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | chartView->setRenderHint(QPainter::Antialiasing); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | dialog->setLayout(new QVBoxLayout); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | dialog->layout()->addWidget(chartView); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | dialog->layout()->addWidget(buttonBox); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | dialog->setModal(true); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | dialog->exec(); |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | } |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | ChartCarbonate::~ChartCarbonate() {} |
146874d7bb47
Added carbonation chart to it's own function. Added this chart to DetailCO2meter too.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 |