MCPcopy Create free account
hub / github.com/KDE/labplot / exportToFile

Method exportToFile

src/frontend/worksheet/WorksheetView.cpp:2077–2209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2075}
2076
2077bool WorksheetView::exportToFile(const QString& path,
2078 const Worksheet::ExportFormat format,
2079 const Worksheet::ExportArea area,
2080 const bool background,
2081 const int resolution) {
2082 PERFTRACE(QLatin1String(Q_FUNC_INFO));
2083 bool rc = false;
2084 QRectF sourceRect;
2085
2086 if (area == Worksheet::ExportArea::BoundingBox) {
2087 sourceRect = scene()->itemsBoundingRect();
2088 sourceRect = QRect(0, 0, sourceRect.width() + sourceRect.x(), sourceRect.height());
2089 } else if (area == Worksheet::ExportArea::Selection) {
2090 if (!m_selectedItems.isEmpty()) {
2091 // Union the bounding rectangles of selected items
2092 for (const auto* item : m_selectedItems) {
2093 QRectF itemRect = item->mapToScene(item->boundingRect()).boundingRect();
2094 sourceRect = sourceRect.united(itemRect);
2095 }
2096 } else
2097 sourceRect = scene()->sceneRect();
2098 } else
2099 sourceRect = scene()->sceneRect();
2100 switch (format) {
2101 case Worksheet::ExportFormat::PDF: {
2102 QPrinter printer;
2103 printer.setOutputFormat(QPrinter::PdfFormat);
2104 printer.setOutputFileName(path);
2105 int w = Worksheet::convertFromSceneUnits(sourceRect.width(), Worksheet::Unit::Millimeter);
2106 int h = Worksheet::convertFromSceneUnits(sourceRect.height(), Worksheet::Unit::Millimeter);
2107 printer.setPageSize(QPageSize(QSizeF(w, h), QPageSize::Millimeter));
2108 printer.setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Millimeter);
2109 printer.setPrintRange(QPrinter::PageRange);
2110 printer.setCreator(QStringLiteral("LabPlot ") + QLatin1String(LVERSION));
2111
2112 QPainter painter;
2113 rc = painter.begin(&printer);
2114 if (!rc)
2115 return false;
2116 painter.setRenderHint(QPainter::Antialiasing);
2117 QRectF targetRect(0, 0, w, h);
2118 exportPaint(&painter, targetRect, sourceRect, background);
2119 painter.end();
2120 break;
2121 }
2122 case Worksheet::ExportFormat::SVG: {
2123#ifdef HAVE_QTSVG
2124 QSvgGenerator generator;
2125 generator.setFileName(path);
2126 int w = Worksheet::convertFromSceneUnits(sourceRect.width(), Worksheet::Unit::Millimeter);
2127 int h = Worksheet::convertFromSceneUnits(sourceRect.height(), Worksheet::Unit::Millimeter);
2128 // Adjust for DPI conversion
2129 w = w * GuiTools::dpi(this).first / (GSL_CONST_CGS_INCH * Worksheet::convertToSceneUnits(1, Worksheet::Unit::Millimeter));
2130 h = h * GuiTools::dpi(this).second / (GSL_CONST_CGS_INCH * Worksheet::convertToSceneUnits(1, Worksheet::Unit::Millimeter));
2131
2132 generator.setSize(QSize(w, h));
2133 QRectF targetRect(0, 0, w, h);
2134 generator.setViewBox(targetRect);

Callers

nothing calls this directly

Calls 11

xMethod · 0.80
heightMethod · 0.80
setImageMethod · 0.80
widthMethod · 0.45
isEmptyMethod · 0.45
boundingRectMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
setFileNameMethod · 0.45
setSizeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected