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

Method updateGradientImage

qcustomplot/qcustomplot.cpp:19860–19896  ·  view source on GitHub ↗

! \internal Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to generate a gradient image. This gradient image will be used in the \ref draw method. */

Source from the content-addressed store, hash-verified

19858 generate a gradient image. This gradient image will be used in the \ref draw method.
19859*/
19860void QCPColorScaleAxisRectPrivate::updateGradientImage()
19861{
19862 if (rect().isEmpty())
19863 return;
19864
19865 const QImage::Format format = QImage::Format_ARGB32_Premultiplied;
19866 int n = mParentColorScale->mGradient.levelCount();
19867 int w, h;
19868 QVector<double> data(n);
19869 for (int i=0; i<n; ++i)
19870 data[i] = i;
19871 if (mParentColorScale->mType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop)
19872 {
19873 w = n;
19874 h = rect().height();
19875 mGradientImage = QImage(w, h, format);
19876 QVector<QRgb*> pixels;
19877 for (int y=0; y<h; ++y)
19878 pixels.append(reinterpret_cast<QRgb*>(mGradientImage.scanLine(y)));
19879 mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n);
19880 for (int y=1; y<h; ++y)
19881 memcpy(pixels.at(y), pixels.first(), n*sizeof(QRgb));
19882 } else
19883 {
19884 w = rect().width();
19885 h = n;
19886 mGradientImage = QImage(w, h, format);
19887 for (int y=0; y<h; ++y)
19888 {
19889 QRgb *pixels = reinterpret_cast<QRgb*>(mGradientImage.scanLine(y));
19890 const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1));
19891 for (int x=0; x<w; ++x)
19892 pixels[x] = lineColor;
19893 }
19894 }
19895 mGradientImageInvalidated = false;
19896}
19897
19898/*! \internal
19899

Callers

nothing calls this directly

Calls 7

rectFunction · 0.85
levelCountMethod · 0.80
appendMethod · 0.80
colorizeMethod · 0.80
atMethod · 0.80
colorMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected