13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
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/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 #include "ChartFermenter.h" |
17 #include "ChartFermenter.h" |
|
18 #include "callout.h" |
18 #include "MainWindow.h" |
19 #include "MainWindow.h" |
19 |
20 |
20 |
21 |
21 ChartFermenter::ChartFermenter(QString code, QString name, QWidget *parent) : QDialog(parent) |
22 ChartFermenter::ChartFermenter(QString code, QString name, QWidget *parent) : QDialog(parent) |
22 { |
23 { |
29 dialog->setWindowTitle(tr("BMSapp - Fermenter log ") + "\"" + name + "\""); |
30 dialog->setWindowTitle(tr("BMSapp - Fermenter log ") + "\"" + name + "\""); |
30 dialog->setObjectName(QString::fromUtf8("ChartFermenter")); |
31 dialog->setObjectName(QString::fromUtf8("ChartFermenter")); |
31 dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
32 dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
32 dialog->resize(1024, 600); |
33 dialog->resize(1024, 600); |
33 |
34 |
|
35 QPushButton *saveButton = new QPushButton(tr("Save")); |
|
36 saveButton->setAutoDefault(false); |
|
37 QIcon icon1; |
|
38 icon1.addFile(QString::fromUtf8(":icons/silk/disk.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
39 saveButton->setIcon(icon1); |
|
40 |
34 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
41 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
35 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
42 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
36 buttonBox->setGeometry(QRect(40, 565, 944, 36)); |
43 buttonBox->setOrientation(Qt::Vertical); |
37 buttonBox->setLayoutDirection(Qt::LeftToRight); |
|
38 buttonBox->setOrientation(Qt::Horizontal); |
|
39 buttonBox->setStandardButtons(QDialogButtonBox::Ok); |
44 buttonBox->setStandardButtons(QDialogButtonBox::Ok); |
40 buttonBox->setCenterButtons(true); |
45 buttonBox->addButton(saveButton,QDialogButtonBox::ActionRole); |
41 |
46 |
42 QSplineSeries *pv_air = new QSplineSeries(); |
47 QSplineSeries *pv_air = new QSplineSeries(); |
43 QSplineSeries *pv_beer = new QSplineSeries(); |
48 QSplineSeries *pv_beer = new QSplineSeries(); |
44 QSplineSeries *pv_chiller = new QSplineSeries(); |
49 QSplineSeries *pv_chiller = new QSplineSeries(); |
45 QSplineSeries *pwr_cool = new QSplineSeries(); |
50 QSplineSeries *pwr_cool = new QSplineSeries(); |
73 pwr_cool->setColor(QColorConstants::Blue); |
78 pwr_cool->setColor(QColorConstants::Blue); |
74 pwr_heat->setName("Heat %"); |
79 pwr_heat->setName("Heat %"); |
75 pwr_heat->setOpacity(0.25); |
80 pwr_heat->setOpacity(0.25); |
76 pwr_heat->setColor(QColorConstants::Red); |
81 pwr_heat->setColor(QColorConstants::Red); |
77 |
82 |
78 QChart *chart = new QChart(); |
83 chart = new QChart(); |
79 chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name)); |
84 chart->setTitle(QString("%1 \"%2\"").arg(code).arg(name)); |
80 chart->addSeries(pwr_cool); |
85 chart->addSeries(pwr_cool); |
81 chart->addSeries(pwr_heat); |
86 chart->addSeries(pwr_heat); |
82 chart->addSeries(pv_chiller); |
87 chart->addSeries(pv_chiller); |
83 chart->addSeries(pv_air); |
88 chart->addSeries(pv_air); |
112 axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
117 axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal)); |
113 chart->addAxis(axisYR, Qt::AlignRight); |
118 chart->addAxis(axisYR, Qt::AlignRight); |
114 pwr_cool->attachAxis(axisYR); |
119 pwr_cool->attachAxis(axisYR); |
115 pwr_heat->attachAxis(axisYR); |
120 pwr_heat->attachAxis(axisYR); |
116 |
121 |
|
122 connect(pv_air, &QSplineSeries::hovered, this, &ChartFermenter::tooltip); |
|
123 connect(pv_beer, &QSplineSeries::hovered, this, &ChartFermenter::tooltip); |
|
124 connect(pv_chiller, &QSplineSeries::hovered, this, &ChartFermenter::tooltip); |
117 |
125 |
118 |
126 chartView = new QChartView(chart); |
119 QChartView *chartView = new QChartView(chart); |
|
120 chartView->setRenderHint(QPainter::Antialiasing); |
127 chartView->setRenderHint(QPainter::Antialiasing); |
121 dialog->setLayout(new QVBoxLayout); |
128 dialog->setLayout(new QHBoxLayout); |
122 dialog->layout()->addWidget(chartView); |
129 dialog->layout()->addWidget(chartView); |
123 dialog->layout()->addWidget(buttonBox); |
130 dialog->layout()->addWidget(buttonBox); |
124 |
131 |
125 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
132 QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
126 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
133 QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
|
134 QObject::connect(saveButton, SIGNAL(clicked()), this, SLOT(savePNG())); |
127 |
135 |
128 dialog->setModal(true); |
136 dialog->setModal(true); |
129 dialog->exec(); |
137 dialog->exec(); |
130 } |
138 } |
131 |
139 |
132 |
140 |
133 ChartFermenter::~ChartFermenter() {} |
141 ChartFermenter::~ChartFermenter() {} |
134 |
142 |
|
143 |
|
144 void ChartFermenter::savePNG() |
|
145 { |
|
146 QString path = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::homePath() + "/fermenter.png", tr("Image (*.png)")); |
|
147 if (path.isEmpty()) { |
|
148 QMessageBox::warning(this, tr("Save File"), tr("No image file selected.")); |
|
149 return; |
|
150 } |
|
151 |
|
152 QImage img((chartView->size()), QImage::Format_ARGB32); |
|
153 QPainter painter; |
|
154 painter.begin(&img); |
|
155 chartView->render(&painter); |
|
156 painter.setRenderHint(QPainter::Antialiasing); |
|
157 painter.end(); |
|
158 img.save(path); |
|
159 } |
|
160 |
|
161 |
|
162 void ChartFermenter::tooltip(QPointF point, bool state) |
|
163 { |
|
164 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); |
|
165 |
|
166 if (t_tooltip == 0) |
|
167 t_tooltip = new Callout(chart, series); |
|
168 |
|
169 if (state) { |
|
170 QDateTime timeis = QDateTime::fromMSecsSinceEpoch(point.x()); |
|
171 //qDebug() << "tooltip" << QString("%1 %2°C").arg( timeis.toString("dd-MM-yyyy hh:mm") ).arg(point.y(), 2, 'f', 1); |
|
172 |
|
173 t_tooltip->setSeries(series); |
|
174 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)); |
|
175 t_tooltip->setAnchor(point); |
|
176 t_tooltip->setZValue(11); |
|
177 t_tooltip->updateGeometry(); |
|
178 t_tooltip->show(); |
|
179 } else { |
|
180 t_tooltip->hide(); |
|
181 } |
|
182 } |
|
183 |