Skip to content

Commit

Permalink
Improved the PNG export quality of plots
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Aug 16, 2019
1 parent 55e2dbd commit 28e53ad
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -1646,12 +1646,12 @@ void PlotWindow::exportDocument()
lastOpenDir = QFileInfo(fileName).absoluteDir().absolutePath();
// export svg
if (fileName.endsWith(".svg")) {
#if QWT_VERSION < 0x060000
QSvgGenerator generator;
generator.setTitle(tr("OMPlot - OpenModelica Plot"));
generator.setDescription(tr("Generated by OpenModelica Plot Tool"));
generator.setFileName(fileName);
generator.setSize(mpPlot->rect().size());
#if QWT_VERSION < 0x060000
mpPlot->print(generator);
#else
QwtPlotRenderer plotRenderer;
Expand All @@ -1667,14 +1667,19 @@ void PlotWindow::exportDocument()
/* removes the gray widget background when OMPlot is used as library. */
pixmap.fill(Qt::white);
mpPlot->render(&pixmap, QPoint(), QRegion(), DrawChildren);
if (!pixmap.save(fileName)) {
QMessageBox::critical(this, "Error", "Failed to save image " + fileName);
}
#else
QwtPlotRenderer plotRenderer;
plotRenderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground); /* removes the gray widget background when OMPlot is used as library. */
plotRenderer.renderDocument(mpPlot, fileName, QSizeF(mpPlot->widthMM(), mpPlot->heightMM()));
QPixmap pixmap(mpPlot->size());
pixmap.fill(Qt::white);
QPainter painter(&pixmap);
QRect rect = mpPlot->geometry();
painter.setWindow(rect);
plotRenderer.render(mpPlot, &painter, rect);
#endif
if (!pixmap.save(fileName)) {
QMessageBox::critical(this, "Error", "Failed to save image " + fileName);
}
}
}
}
Expand Down

0 comments on commit 28e53ad

Please sign in to comment.