MCPcopy Create free account
hub / github.com/LUX-Core/lux / toPixmap

Method toPixmap

src/qt/qcustomplot.cpp:15635–15677  ·  view source on GitHub ↗

! Renders the plot to a pixmap and returns it. The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead to a full resolution pixmap with width 200.) \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf */

Source from the content-addressed store, hash-verified

15633 \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf
15634*/
15635QPixmap QCustomPlot::toPixmap(int width, int height, double scale)
15636{
15637 // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too.
15638 int newWidth, newHeight;
15639 if (width == 0 || height == 0)
15640 {
15641 newWidth = this->width();
15642 newHeight = this->height();
15643 } else
15644 {
15645 newWidth = width;
15646 newHeight = height;
15647 }
15648 int scaledWidth = qRound(scale*newWidth);
15649 int scaledHeight = qRound(scale*newHeight);
15650
15651 QPixmap result(scaledWidth, scaledHeight);
15652 result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later
15653 QCPPainter painter;
15654 painter.begin(&result);
15655 if (painter.isActive())
15656 {
15657 QRect oldViewport = viewport();
15658 setViewport(QRect(0, 0, newWidth, newHeight));
15659 painter.setMode(QCPPainter::pmNoCaching);
15660 if (!qFuzzyCompare(scale, 1.0))
15661 {
15662 if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales
15663 painter.setMode(QCPPainter::pmNonCosmetic);
15664 painter.scale(scale, scale);
15665 }
15666 if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill
15667 painter.fillRect(mViewport, mBackgroundBrush);
15668 draw(&painter);
15669 setViewport(oldViewport);
15670 painter.end();
15671 } else // might happen if pixmap has width or height zero
15672 {
15673 qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap";
15674 return QPixmap();
15675 }
15676 return result;
15677}
15678
15679/*!
15680 Renders the plot using the passed \a painter.

Callers

nothing calls this directly

Calls 7

viewportFunction · 0.85
fillMethod · 0.80
colorMethod · 0.80
isActiveMethod · 0.80
setModeMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected