src/EditProductTab10.cpp

changeset 296
2f4e250cfed9
parent 219
fa7cad488e27
child 298
180c77a81e15
equal deleted inserted replaced
295:4b2ac345b982 296:2f4e250cfed9
263 } 263 }
264 264
265 265
266 void EditProduct::ferm_log1_button() 266 void EditProduct::ferm_log1_button()
267 { 267 {
268 QSqlQuery query;
269 double timestamp;
270
271 QDialog* dialog = new QDialog(this);
272 dialog->resize(1024, 600);
273 dialog->setWindowTitle(tr("Fermenter log"));
274 dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
275
276 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
277 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
278 buttonBox->setGeometry(QRect(40, 565, 944, 36));
279 buttonBox->setLayoutDirection(Qt::LeftToRight);
280 buttonBox->setOrientation(Qt::Horizontal);
281 buttonBox->setStandardButtons(QDialogButtonBox::Ok);
282 buttonBox->setCenterButtons(true);
283
284 QSplineSeries *pv_air = new QSplineSeries();
285 QSplineSeries *pv_beer = new QSplineSeries();
286 QSplineSeries *pv_chiller = new QSplineSeries();
287 QSplineSeries *pwr_cool = new QSplineSeries();
288 QSplineSeries *pwr_heat = new QSplineSeries();
289
290 query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime");
291 query.bindValue(":code", product->code);
292 query.exec();
293 while (query.next()) {
294 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
295 pv_air->append(timestamp, query.value("temp_air").toDouble());
296 pv_beer->append(timestamp, query.value("temp_beer").toDouble());
297 if (query.value("temp_chiller").toDouble() > 0)
298 pv_chiller->append(timestamp, query.value("temp_chiller").toDouble());
299 pwr_cool->append(timestamp, query.value("cooler_power").toDouble());
300 pwr_heat->append(timestamp, query.value("heater_power").toDouble());
301 }
302
303 pv_air->setName(tr("Air"));
304 pv_air->setColor(QColorConstants::Svg::lightgreen);
305 pv_beer->setName(tr("Beer"));
306 QPen pen(QColorConstants::Svg::navy);
307 pen.setWidth(3);
308 pv_beer->setPen(pen);
309 pv_chiller->setName(tr("Chiller"));
310 pv_chiller->setColor(QColorConstants::Svg::lightsalmon);
311 pv_chiller->setOpacity(0.75);
312
313 pwr_cool->setName("Cool %");
314 pwr_cool->setOpacity(0.25);
315 pwr_cool->setColor(QColorConstants::Blue);
316 pwr_heat->setName("Heat %");
317 pwr_heat->setOpacity(0.25);
318 pwr_heat->setColor(QColorConstants::Red);
319
320 QChart *chart = new QChart();
321 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
322 chart->addSeries(pwr_cool);
323 chart->addSeries(pwr_heat);
324 chart->addSeries(pv_chiller);
325 chart->addSeries(pv_air);
326 chart->addSeries(pv_beer);
327
328 QDateTimeAxis *axisX = new QDateTimeAxis;
329 axisX->setTickCount(10);
330 axisX->setFormat("dd MMM");
331 axisX->setTitleText("Date");
332 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
333 chart->addAxis(axisX, Qt::AlignBottom);
334 pv_air->attachAxis(axisX);
335 pv_beer->attachAxis(axisX);
336 pv_chiller->attachAxis(axisX);
337
338 QValueAxis *axisY = new QValueAxis;
339 axisY->setTickCount(11);
340 axisY->setMinorTickCount(1);
341 axisY->setLabelFormat("%i");
342 axisY->setTitleText("Temp");
343 axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
344 chart->addAxis(axisY, Qt::AlignLeft);
345 pv_air->attachAxis(axisY);
346 pv_beer->attachAxis(axisY);
347 pv_chiller->attachAxis(axisY);
348
349 QValueAxis *axisYR = new QValueAxis;
350 axisYR->setRange(0, 100);
351 axisYR->setTickCount(11);
352 axisYR->setLabelFormat("%i");
353 axisYR->setTitleText("Power %");
354 axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
355 chart->addAxis(axisYR, Qt::AlignRight);
356 pwr_cool->attachAxis(axisYR);
357 pwr_heat->attachAxis(axisYR);
358
359 QChartView *chartView = new QChartView(chart);
360 chartView->setRenderHint(QPainter::Antialiasing);
361 dialog->setLayout(new QVBoxLayout);
362 dialog->layout()->addWidget(chartView);
363 dialog->layout()->addWidget(buttonBox);
364
365 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
366 dialog->setModal(true);
367 dialog->exec();
268 } 368 }
269 369
270 370
271 void EditProduct::ferm_log2_button() 371 void EditProduct::ferm_log2_button()
272 { 372 {
273 } 373 QSqlQuery query;
274 374 double timestamp;
275 375
376 QDialog* dialog = new QDialog(this);
377 dialog->resize(1024, 600);
378 dialog->setWindowTitle(tr("iSpindel log"));
379 dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
380
381 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
382 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
383 buttonBox->setGeometry(QRect(40, 565, 944, 36));
384 buttonBox->setLayoutDirection(Qt::LeftToRight);
385 buttonBox->setOrientation(Qt::Horizontal);
386 buttonBox->setStandardButtons(QDialogButtonBox::Ok);
387 buttonBox->setCenterButtons(true);
388
389 QSplineSeries *temperature = new QSplineSeries();
390 QSplineSeries *density = new QSplineSeries();
391 QSplineSeries *battery = new QSplineSeries();
392
393 query.prepare("SELECT * FROM log_ispindel WHERE code=:code ORDER BY datetime");
394 query.bindValue(":code", product->code);
395 query.exec();
396 while (query.next()) {
397 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
398 temperature->append(timestamp, query.value("temperature").toDouble());
399 density->append(timestamp, query.value("sg").toDouble());
400 battery ->append(timestamp, query.value("battery").toDouble());
401 }
402
403 temperature->setName(tr("Temperature"));
404 temperature->setColor(QColorConstants::Svg::red);
405 density->setName(tr("SG"));
406 QPen pen(QColorConstants::Svg::navy);
407 pen.setWidth(3);
408 density->setPen(pen);
409 battery->setName(tr("Battery"));
410 battery->setColor(QColorConstants::Svg::lightgreen);
411
412 QChart *chart = new QChart();
413 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
414 chart->addSeries(battery);
415 chart->addSeries(temperature);
416 chart->addSeries(density);
417
418 QDateTimeAxis *axisX = new QDateTimeAxis;
419 axisX->setTickCount(10);
420 axisX->setFormat("dd MMM");
421 axisX->setTitleText("Date");
422 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
423 chart->addAxis(axisX, Qt::AlignBottom);
424 battery->attachAxis(axisX);
425 temperature->attachAxis(axisX);
426 density->attachAxis(axisX);
427
428 QValueAxis *axisYT = new QValueAxis;
429 axisYT->setTickCount(10);
430 axisYT->setLabelFormat("%.1f");
431 axisYT->setTitleText("Temp");
432 axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
433 chart->addAxis(axisYT, Qt::AlignRight);
434 temperature->attachAxis(axisYT);
435
436 QValueAxis *axisYD = new QValueAxis;
437 axisYD->setTickCount(10);
438 axisYD->setLabelFormat("%.4f");
439 axisYD->setTitleText("SG");
440 axisYD->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
441 chart->addAxis(axisYD, Qt::AlignLeft);
442 density->attachAxis(axisYD);
443
444 QValueAxis *axisYB = new QValueAxis;
445 axisYB->setTickCount(10);
446 axisYB->setLabelFormat("%.2f");
447 axisYB->setTitleText("Battery");
448 axisYB->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
449 chart->addAxis(axisYB, Qt::AlignRight);
450 battery->attachAxis(axisYB);
451
452 QChartView *chartView = new QChartView(chart);
453 chartView->setRenderHint(QPainter::Antialiasing);
454 dialog->setLayout(new QVBoxLayout);
455 dialog->layout()->addWidget(chartView);
456 dialog->layout()->addWidget(buttonBox);
457
458 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
459 dialog->setModal(true);
460 dialog->exec();
461 }
462
463

mercurial