MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / savePdf

Method savePdf

qcustomplot/qcustomplot.cpp:14513–14574  ·  view source on GitHub ↗

! Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale of texts and lines will be derived from the specified \a width and \a height. This means, the output will look like the normal on-screen output of a QCustomPlot widget with the corresponding pixel width and height. If either \a width or \a height is zero, the exported image will have the s

Source from the content-addressed store, hash-verified

14511 \see savePng, saveBmp, saveJpg, saveRastered
14512*/
14513bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle)
14514{
14515 bool success = false;
14516#ifdef QT_NO_PRINTER
14517 Q_UNUSED(fileName)
14518 Q_UNUSED(exportPen)
14519 Q_UNUSED(width)
14520 Q_UNUSED(height)
14521 Q_UNUSED(pdfCreator)
14522 Q_UNUSED(pdfTitle)
14523 qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created.";
14524#else
14525 int newWidth, newHeight;
14526 if (width == 0 || height == 0)
14527 {
14528 newWidth = this->width();
14529 newHeight = this->height();
14530 } else
14531 {
14532 newWidth = width;
14533 newHeight = height;
14534 }
14535
14536 QPrinter printer(QPrinter::ScreenResolution);
14537 printer.setOutputFileName(fileName);
14538 printer.setOutputFormat(QPrinter::PdfFormat);
14539 printer.setColorMode(QPrinter::Color);
14540 printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator);
14541 printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle);
14542 QRect oldViewport = viewport();
14543 setViewport(QRect(0, 0, newWidth, newHeight));
14544#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
14545 printer.setFullPage(true);
14546 printer.setPaperSize(viewport().size(), QPrinter::DevicePixel);
14547#else
14548 QPageLayout pageLayout;
14549 pageLayout.setMode(QPageLayout::FullPageMode);
14550 pageLayout.setOrientation(QPageLayout::Portrait);
14551 pageLayout.setMargins(QMarginsF(0, 0, 0, 0));
14552 pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch));
14553 printer.setPageLayout(pageLayout);
14554#endif
14555 QCPPainter printpainter;
14556 if (printpainter.begin(&printer))
14557 {
14558 printpainter.setMode(QCPPainter::pmVectorized);
14559 printpainter.setMode(QCPPainter::pmNoCaching);
14560 printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic);
14561 printpainter.setWindow(mViewport);
14562 if (mBackgroundBrush.style() != Qt::NoBrush &&
14563 mBackgroundBrush.color() != Qt::white &&
14564 mBackgroundBrush.color() != Qt::transparent &&
14565 mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent
14566 printpainter.fillRect(viewport(), mBackgroundBrush);
14567 draw(&printpainter);
14568 printpainter.end();
14569 success = true;
14570 }

Callers

nothing calls this directly

Calls 8

viewportFunction · 0.85
setModeMethod · 0.80
setMarginsMethod · 0.80
colorMethod · 0.80
alphaMethod · 0.80
endMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected