Sat, 09 Jul 2022 23:05:25 +0200
Increased some labels sizes.
/** * ChartFermenter.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 "ChartFermenter.h" #include "MainWindow.h" ChartFermenter::ChartFermenter(QString code, QString name, QWidget *parent) : QDialog(parent) { QSqlQuery query; double timestamp; qDebug() << "ChartFermenter:" << code << name; QDialog* dialog = new QDialog(parent); dialog->setWindowTitle(tr("BMSapp - Fermenter log ") + "\"" + name + "\""); dialog->setObjectName(QString::fromUtf8("ChartFermenter")); 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 *pv_air = new QSplineSeries(); QSplineSeries *pv_beer = new QSplineSeries(); QSplineSeries *pv_chiller = new QSplineSeries(); QSplineSeries *pwr_cool = new QSplineSeries(); QSplineSeries *pwr_heat = new QSplineSeries(); query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime"); query.bindValue(":code", code); query.exec(); while (query.next()) { timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; pv_air->append(timestamp, query.value("temp_air").toDouble()); pv_beer->append(timestamp, query.value("temp_beer").toDouble()); if (query.value("temp_chiller").toDouble() > 0) pv_chiller->append(timestamp, query.value("temp_chiller").toDouble()); pwr_cool->append(timestamp, query.value("cooler_power").toDouble()); pwr_heat->append(timestamp, query.value("heater_power").toDouble()); } pv_air->setName(tr("Air")); pv_air->setColor(QColorConstants::Svg::lightgreen); pv_beer->setName(tr("Beer")); QPen pen(QColorConstants::Svg::navy); pen.setWidth(3); pv_beer->setPen(pen); pv_chiller->setName(tr("Chiller")); pv_chiller->setColor(QColorConstants::Svg::lightsalmon); pv_chiller->setOpacity(0.75); pwr_cool->setName("Cool %"); pwr_cool->setOpacity(0.25); pwr_cool->setColor(QColorConstants::Blue); pwr_heat->setName("Heat %"); pwr_heat->setOpacity(0.25); pwr_heat->setColor(QColorConstants::Red); QChart *chart = new QChart(); chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name)); chart->addSeries(pwr_cool); chart->addSeries(pwr_heat); chart->addSeries(pv_chiller); chart->addSeries(pv_air); chart->addSeries(pv_beer); 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); pv_air->attachAxis(axisX); pv_beer->attachAxis(axisX); pv_chiller->attachAxis(axisX); QValueAxis *axisY = new QValueAxis; axisY->setTickCount(11); axisY->setMinorTickCount(1); axisY->setLabelFormat("%i"); axisY->setTitleText(tr("Temp °C")); axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); chart->addAxis(axisY, Qt::AlignLeft); pv_air->attachAxis(axisY); pv_beer->attachAxis(axisY); pv_chiller->attachAxis(axisY); QValueAxis *axisYR = new QValueAxis; axisYR->setRange(0, 100); axisYR->setTickCount(11); axisYR->setLabelFormat("%i"); axisYR->setTitleText(tr("Power %")); axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); chart->addAxis(axisYR, Qt::AlignRight); pwr_cool->attachAxis(axisYR); pwr_heat->attachAxis(axisYR); 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(); } ChartFermenter::~ChartFermenter() {}