| 377 | } |
| 378 | |
| 379 | void PlotWidget::printPlot(QPainter *painter, bool useSymbols) |
| 380 | { |
| 381 | QwtPlotRenderer renderer; |
| 382 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, true); |
| 383 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardCanvasBackground, true); |
| 384 | |
| 385 | // Change axis and legend color |
| 386 | auto currentStyle = m_plot->styleSheet(); |
| 387 | m_plot->setStyleSheet("color: #9E9E9F"); |
| 388 | |
| 389 | // Apply printable plot changes |
| 390 | // list of current curve colors |
| 391 | QList<QPen> plotChColors; |
| 392 | for(int i = 0; i < getChannels().length(); i++) { |
| 393 | QPen printPen = getChannels().at(i)->curve()->pen(); |
| 394 | // save current curve color |
| 395 | plotChColors.push_back(getChannels().at(i)->curve()->pen()); |
| 396 | // get channel colors from StyleHelper |
| 397 | printPen.setColor(StyleHelper::getChannelColor(i)); |
| 398 | printPen.setWidth(2); |
| 399 | getChannels().at(i)->curve()->setPen(printPen); |
| 400 | if(useSymbols) { |
| 401 | QwtSymbol *symbol = new QwtSymbol(getCurveStyle(i), Qt::white, printPen, QSize(10, 10)); |
| 402 | getChannels().at(i)->curve()->setSymbol(symbol); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | QwtLegend *legendDisplay = new QwtLegend(m_plot); |
| 407 | legendDisplay->setDefaultItemMode(QwtLegendData::ReadOnly); |
| 408 | m_plot->insertLegend(legendDisplay, QwtPlot::TopLegend); |
| 409 | m_plot->updateLegend(); |
| 410 | |
| 411 | m_plot->replot(); |
| 412 | |
| 413 | // Print plot to Painter |
| 414 | renderer.render(m_plot, painter, QRectF(0, 0, 400, 300)); |
| 415 | |
| 416 | // revert changes made for printable plot |
| 417 | m_plot->insertLegend(nullptr); |
| 418 | m_plot->setStyleSheet(currentStyle); |
| 419 | |
| 420 | // revert curves to original settings |
| 421 | for(int i = 0; i < getChannels().length(); i++) { |
| 422 | getChannels().at(i)->curve()->setPen(plotChColors.at(i)); |
| 423 | if(useSymbols) { |
| 424 | getChannels().at(i)->curve()->setSymbol(new QwtSymbol(QwtSymbol::NoSymbol)); |
| 425 | } |
| 426 | } |
| 427 | m_plot->replot(); |
| 428 | } |
| 429 | |
| 430 | PlotChannel *PlotWidget::selectedChannel() const { return m_selectedChannel; } |
| 431 | |