461 QSqlQuery query; |
461 QSqlQuery query; |
462 double timestamp; |
462 double timestamp; |
463 |
463 |
464 QDialog* dialog = new QDialog(this); |
464 QDialog* dialog = new QDialog(this); |
465 dialog->resize(1024, 600); |
465 dialog->resize(1024, 600); |
|
466 |
|
467 QPushButton *saveButton = new QPushButton(tr("Save")); |
|
468 saveButton->setAutoDefault(false); |
|
469 QIcon icon1; |
|
470 icon1.addFile(QString::fromUtf8(":icons/silk/disk.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
471 saveButton->setIcon(icon1); |
|
472 |
466 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
473 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
467 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
474 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
468 buttonBox->setGeometry(QRect(40, 565, 944, 36)); |
475 buttonBox->setOrientation(Qt::Vertical); |
469 buttonBox->setLayoutDirection(Qt::LeftToRight); |
|
470 buttonBox->setOrientation(Qt::Horizontal); |
|
471 buttonBox->setStandardButtons(QDialogButtonBox::Ok); |
476 buttonBox->setStandardButtons(QDialogButtonBox::Ok); |
472 buttonBox->setCenterButtons(true); |
477 buttonBox->addButton(saveButton,QDialogButtonBox::ActionRole); |
473 |
478 |
474 QLineSeries *pv_mlt = new QLineSeries(); |
479 QLineSeries *pv_mlt = new QLineSeries(); |
475 pv_mlt->setName("MLT"); |
480 pv_mlt->setName("MLT"); |
476 QLineSeries *sp_mlt = new QLineSeries(); |
481 QLineSeries *sp_mlt = new QLineSeries(); |
477 sp_mlt->setName("Set"); |
482 sp_mlt->setName("Set"); |
499 pv_mlt->setPen(pen); |
504 pv_mlt->setPen(pen); |
500 QAreaSeries *pwm_mlt = new QAreaSeries(pwm_mlt0, pwm_mlt1); |
505 QAreaSeries *pwm_mlt = new QAreaSeries(pwm_mlt0, pwm_mlt1); |
501 pwm_mlt->setName("MLT pwr"); |
506 pwm_mlt->setName("MLT pwr"); |
502 pwm_mlt->setOpacity(0.25); |
507 pwm_mlt->setOpacity(0.25); |
503 |
508 |
504 QChart *chart = new QChart(); |
509 chart = new QChart(); |
505 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name)); |
510 chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name)); |
506 chart->addSeries(pwm_mlt); // Order is important, first drawn is lowest layer. |
511 chart->addSeries(pwm_mlt); // Order is important, first drawn is lowest layer. |
507 chart->addSeries(sp_mlt); |
512 chart->addSeries(sp_mlt); |
508 chart->addSeries(pv_hlt); |
513 chart->addSeries(pv_hlt); |
509 chart->addSeries(pv_mlt); // Top layer. |
514 chart->addSeries(pv_mlt); // Top layer. |
529 pwm_mlt->attachAxis(axisY); |
534 pwm_mlt->attachAxis(axisY); |
530 pv_mlt->attachAxis(axisY); |
535 pv_mlt->attachAxis(axisY); |
531 sp_mlt->attachAxis(axisY); |
536 sp_mlt->attachAxis(axisY); |
532 pv_hlt->attachAxis(axisY); |
537 pv_hlt->attachAxis(axisY); |
533 |
538 |
534 QChartView *chartView = new QChartView(chart); |
539 connect(pv_mlt, &QLineSeries::hovered, this, &EditProduct::tooltip); |
|
540 connect(pv_hlt, &QLineSeries::hovered, this, &EditProduct::tooltip); |
|
541 |
|
542 chartView = new QChartView(chart); |
535 chartView->setRenderHint(QPainter::Antialiasing); |
543 chartView->setRenderHint(QPainter::Antialiasing); |
536 dialog->setLayout(new QVBoxLayout); |
544 dialog->setLayout(new QHBoxLayout); |
537 dialog->layout()->addWidget(chartView); |
545 dialog->layout()->addWidget(chartView); |
538 dialog->layout()->addWidget(buttonBox); |
546 dialog->layout()->addWidget(buttonBox); |
539 |
547 |
540 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
548 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
|
549 connect(saveButton, SIGNAL(clicked()), this, SLOT(savePNG())); |
|
550 |
541 dialog->setModal(true); |
551 dialog->setModal(true); |
542 dialog->exec(); |
552 dialog->exec(); |
543 } |
553 } |
544 |
554 |
545 |
555 |
|
556 void EditProduct::savePNG() |
|
557 { |
|
558 QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::homePath() + "/brewday.png", tr("Image (*.png)")); |
|
559 if (path.isEmpty()) { |
|
560 QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); |
|
561 return; |
|
562 } |
|
563 |
|
564 QImage img((chartView->size()), QImage::Format_ARGB32); |
|
565 QPainter painter; |
|
566 painter.begin(&img); |
|
567 chartView->render(&painter); |
|
568 painter.setRenderHint(QPainter::Antialiasing); |
|
569 painter.end(); |
|
570 img.save(path); |
|
571 } |
|
572 |
|
573 |
|
574 void EditProduct::tooltip(QPointF point, bool state) |
|
575 { |
|
576 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); |
|
577 |
|
578 if (t_tooltip == 0) |
|
579 t_tooltip = new Callout(chart, series); |
|
580 |
|
581 if (state) { |
|
582 QDateTime timeis = QDateTime::fromMSecsSinceEpoch(point.x()); |
|
583 t_tooltip->setSeries(series); |
|
584 t_tooltip->setText(QString("%1\n%2 %3°C").arg(timeis.toString("dd-MM-yyyy hh:mm")).arg(series->name()).arg(point.y(), 2, 'f', 1)); |
|
585 t_tooltip->setAnchor(point); |
|
586 t_tooltip->setZValue(11); |
|
587 t_tooltip->updateGeometry(); |
|
588 t_tooltip->show(); |
|
589 } else { |
|
590 t_tooltip->hide(); |
|
591 } |
|
592 } |
|
593 |
|
594 |