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