MCPcopy Index your code
hub / github.com/Audio4Linux/JDSP4Linux / toPixmap

Method toPixmap

3rdparty/qcustomplot/qcustomplot.cpp:16416–16458  ·  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

16414 \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf
16415*/
16416QPixmap QCustomPlot::toPixmap(int width, int height, double scale)
16417{
16418 // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too.
16419 int newWidth, newHeight;
16420 if (width == 0 || height == 0)
16421 {
16422 newWidth = this->width();
16423 newHeight = this->height();
16424 } else
16425 {
16426 newWidth = width;
16427 newHeight = height;
16428 }
16429 int scaledWidth = qRound(scale*newWidth);
16430 int scaledHeight = qRound(scale*newHeight);
16431
16432 QPixmap result(scaledWidth, scaledHeight);
16433 result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later
16434 QCPPainter painter;
16435 painter.begin(&result);
16436 if (painter.isActive())
16437 {
16438 QRect oldViewport = viewport();
16439 setViewport(QRect(0, 0, newWidth, newHeight));
16440 painter.setMode(QCPPainter::pmNoCaching);
16441 if (!qFuzzyCompare(scale, 1.0))
16442 {
16443 if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales
16444 painter.setMode(QCPPainter::pmNonCosmetic);
16445 painter.scale(scale, scale);
16446 }
16447 if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill
16448 painter.fillRect(mViewport, mBackgroundBrush);
16449 draw(&painter);
16450 setViewport(oldViewport);
16451 painter.end();
16452 } else // might happen if pixmap has width or height zero
16453 {
16454 qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap";
16455 return QPixmap();
16456 }
16457 return result;
16458}
16459
16460/*!
16461 Renders the plot using the passed \a painter.

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected