src/ChartFermenter.cpp

changeset 333
499c95108bbd
child 371
d03a426e0b6b
equal deleted inserted replaced
332:146874d7bb47 333:499c95108bbd
1 /**
2 * ChartFermenter.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 "ChartFermenter.h"
18 #include "MainWindow.h"
19
20
21 ChartFermenter::ChartFermenter(QString code, QString name, QWidget *parent) : QDialog(parent)
22 {
23 QSqlQuery query;
24 double timestamp;
25
26 qDebug() << "ChartFermenter:" << code << name;
27
28 QDialog* dialog = new QDialog(parent);
29 dialog->setWindowTitle(tr("BMSapp - Fermenter log ") + "\"" + name + "\"");
30 dialog->setObjectName(QString::fromUtf8("ChartFermenter"));
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 *pv_air = new QSplineSeries();
43 QSplineSeries *pv_beer = new QSplineSeries();
44 QSplineSeries *pv_chiller = new QSplineSeries();
45 QSplineSeries *pwr_cool = new QSplineSeries();
46 QSplineSeries *pwr_heat = new QSplineSeries();
47
48 query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime");
49 query.bindValue(":code", code);
50 query.exec();
51 while (query.next()) {
52 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
53 pv_air->append(timestamp, query.value("temp_air").toDouble());
54 pv_beer->append(timestamp, query.value("temp_beer").toDouble());
55 if (query.value("temp_chiller").toDouble() > 0)
56 pv_chiller->append(timestamp, query.value("temp_chiller").toDouble());
57 pwr_cool->append(timestamp, query.value("cooler_power").toDouble());
58 pwr_heat->append(timestamp, query.value("heater_power").toDouble());
59 }
60
61 pv_air->setName(tr("Air"));
62 pv_air->setColor(QColorConstants::Svg::lightgreen);
63 pv_beer->setName(tr("Beer"));
64 QPen pen(QColorConstants::Svg::navy);
65 pen.setWidth(3);
66 pv_beer->setPen(pen);
67 pv_chiller->setName(tr("Chiller"));
68 pv_chiller->setColor(QColorConstants::Svg::lightsalmon);
69 pv_chiller->setOpacity(0.75);
70
71 pwr_cool->setName("Cool %");
72 pwr_cool->setOpacity(0.25);
73 pwr_cool->setColor(QColorConstants::Blue);
74 pwr_heat->setName("Heat %");
75 pwr_heat->setOpacity(0.25);
76 pwr_heat->setColor(QColorConstants::Red);
77
78 QChart *chart = new QChart();
79 chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name));
80 chart->addSeries(pwr_cool);
81 chart->addSeries(pwr_heat);
82 chart->addSeries(pv_chiller);
83 chart->addSeries(pv_air);
84 chart->addSeries(pv_beer);
85
86 QDateTimeAxis *axisX = new QDateTimeAxis;
87 axisX->setTickCount(10);
88 axisX->setFormat("dd MMM");
89 axisX->setTitleText(tr("Date"));
90 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
91 chart->addAxis(axisX, Qt::AlignBottom);
92 pv_air->attachAxis(axisX);
93 pv_beer->attachAxis(axisX);
94 pv_chiller->attachAxis(axisX);
95
96 QValueAxis *axisY = new QValueAxis;
97 axisY->setTickCount(11);
98 axisY->setMinorTickCount(1);
99 axisY->setLabelFormat("%i");
100 axisY->setTitleText(tr("Temp °C"));
101 axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
102 chart->addAxis(axisY, Qt::AlignLeft);
103 pv_air->attachAxis(axisY);
104 pv_beer->attachAxis(axisY);
105 pv_chiller->attachAxis(axisY);
106
107 QValueAxis *axisYR = new QValueAxis;
108 axisYR->setRange(0, 100);
109 axisYR->setTickCount(11);
110 axisYR->setLabelFormat("%i");
111 axisYR->setTitleText(tr("Power %"));
112 axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
113 chart->addAxis(axisYR, Qt::AlignRight);
114 pwr_cool->attachAxis(axisYR);
115 pwr_heat->attachAxis(axisYR);
116
117
118
119 QChartView *chartView = new QChartView(chart);
120 chartView->setRenderHint(QPainter::Antialiasing);
121 dialog->setLayout(new QVBoxLayout);
122 dialog->layout()->addWidget(chartView);
123 dialog->layout()->addWidget(buttonBox);
124
125 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
126 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
127
128 dialog->setModal(true);
129 dialog->exec();
130 }
131
132
133 ChartFermenter::~ChartFermenter() {}
134

mercurial