src/ChartiSpindel.cpp

changeset 333
499c95108bbd
child 334
9203fa01ddbf
equal deleted inserted replaced
332:146874d7bb47 333:499c95108bbd
1 /**
2 * ChartiSpindel.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 "ChartiSpindel.h"
18 #include "MainWindow.h"
19
20
21 ChartiSpindel::ChartiSpindel(QString code, QString name, QWidget *parent) : QDialog(parent)
22 {
23 QSqlQuery query;
24 double timestamp;
25
26 qDebug() << "ChartiSpindel:" << code << name;
27
28 QDialog* dialog = new QDialog(parent);
29 dialog->setWindowTitle(tr("BMSapp - Carbonation ") + "\"" + name + "\"");
30 dialog->setObjectName(QString::fromUtf8("ChartiSpindel"));
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 *density = new QSplineSeries();
44 QSplineSeries *battery = new QSplineSeries();
45
46 query.prepare("SELECT * FROM log_ispindel WHERE code=:code ORDER BY datetime");
47 query.bindValue(":code", code);
48 query.exec();
49 while (query.next()) {
50 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
51 temperature->append(timestamp, query.value("temperature").toDouble());
52 density->append(timestamp, query.value("sg").toDouble());
53 battery ->append(timestamp, query.value("battery").toDouble());
54 }
55
56 temperature->setName(tr("Temp °C"));
57 temperature->setColor(QColorConstants::Svg::red);
58 density->setName(tr("SG"));
59 QPen pen(QColorConstants::Svg::navy);
60 pen.setWidth(3);
61 density->setPen(pen);
62 battery->setName(tr("Battery"));
63 battery->setColor(QColorConstants::Svg::limegreen);
64
65 QChart *chart = new QChart();
66 chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name));
67 chart->addSeries(battery);
68 chart->addSeries(temperature);
69 chart->addSeries(density);
70
71 QDateTimeAxis *axisX = new QDateTimeAxis;
72 axisX->setTickCount(10);
73 axisX->setFormat("dd MMM");
74 axisX->setTitleText(tr("Date"));
75 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
76 chart->addAxis(axisX, Qt::AlignBottom);
77 battery->attachAxis(axisX);
78 temperature->attachAxis(axisX);
79 density->attachAxis(axisX);
80
81 QValueAxis *axisYT = new QValueAxis;
82 axisYT->setTickCount(10);
83 axisYT->setLabelFormat("%.1f");
84 axisYT->setTitleText(tr("Temperature °C"));
85 axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
86 chart->addAxis(axisYT, Qt::AlignRight);
87 temperature->attachAxis(axisYT);
88
89 QValueAxis *axisYD = new QValueAxis;
90 axisYD->setTickCount(10);
91 axisYD->setLabelFormat("%.3f");
92 axisYD->setTitleText("SG");
93 axisYD->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
94 chart->addAxis(axisYD, Qt::AlignLeft);
95 density->attachAxis(axisYD);
96
97 QValueAxis *axisYB = new QValueAxis;
98 axisYB->setTickCount(10);
99 axisYB->setLabelFormat("%.2f");
100 axisYB->setTitleText(tr("Battery volt"));
101 axisYB->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
102 chart->addAxis(axisYB, Qt::AlignRight);
103 battery->attachAxis(axisYB);
104
105 QChartView *chartView = new QChartView(chart);
106 chartView->setRenderHint(QPainter::Antialiasing);
107 dialog->setLayout(new QVBoxLayout);
108 dialog->layout()->addWidget(chartView);
109 dialog->layout()->addWidget(buttonBox);
110
111 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
112 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
113
114 dialog->setModal(true);
115 dialog->exec();
116 }
117
118
119 ChartiSpindel::~ChartiSpindel() {}
120

mercurial