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

Method distributionChanged

src/frontend/dockwidgets/QQPlotDock.cpp:198–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198void QQPlotDock::distributionChanged(int index) {
199 const nsl_sf_stats_distribution dist = (nsl_sf_stats_distribution)ui.cbDistribution->itemData(index).toInt();
200
201 QString file =
202 QStandardPaths::locate(QStandardPaths::AppDataLocation,
203 QStringLiteral("pics/gsl_distributions/") + QLatin1String(nsl_sf_stats_distribution_pic_name[dist]) + QStringLiteral(".pdf"));
204 QImage image = GuiTools::importPDFFile(file);
205
206 // use system palette for background
207 if (GuiTools::isDarkMode()) {
208 // invert image if in dark mode
209 image.invertPixels();
210
211 for (int i = 0; i < image.size().width(); i++)
212 for (int j = 0; j < image.size().height(); j++)
213 if (qGray(image.pixel(i, j)) < 64) // 0-255: 0-64 covers all dark pixel
214 image.setPixel(QPoint(i, j), palette().color(QPalette::Base).rgb());
215 } else {
216 for (int i = 0; i < image.size().width(); i++)
217 for (int j = 0; j < image.size().height(); j++)
218 if (qGray(image.pixel(i, j)) > 192) // 0-255: 224-255 covers all light pixel
219 image.setPixel(QPoint(i, j), palette().color(QPalette::Base).rgb());
220 }
221
222 if (image.isNull()) {
223 ui.lFunc->hide();
224 ui.lFuncPic->hide();
225 } else {
226 // use light/dark background in the preview label
227 QPalette p;
228 p.setColor(QPalette::Window, palette().color(QPalette::Base));
229 ui.lFuncPic->setAutoFillBackground(true);
230 ui.lFuncPic->setPalette(p);
231 ui.lFuncPic->setScaledContents(false);
232
233 ui.lFuncPic->setPixmap(QPixmap::fromImage(image));
234 ui.lFuncPic->show();
235 }
236
237 CONDITIONAL_LOCK_RETURN;
238
239 for (auto* plot : m_plots)
240 plot->setDistribution(dist);
241}
242
243//*************************************************************
244//*********** SLOTs for changes triggered in QQPlot *******

Callers

nothing calls this directly

Calls 8

heightMethod · 0.80
isNullMethod · 0.80
showMethod · 0.80
setDistributionMethod · 0.80
widthMethod · 0.45
sizeMethod · 0.45
colorMethod · 0.45
setColorMethod · 0.45

Tested by

no test coverage detected