From 3bf6c5611eb81ffdab9b7af36d62ccb4d134c841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Fri, 13 Nov 2026 10:38:00 +0100 Subject: [PATCH] Make the plotting tests independent of the font The tick labels at the ends of the axes reach into the corners next to the plot area by an amount that depends on the font, so those corners are no longer part of the "nothing is drawn outside the plot area" checks. The pixel label test leaves more room for wider fonts. findChildren() is called with the overload that exists in Qt 6.2. --- slsDetectorGui/tests/plotting_test.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/slsDetectorGui/tests/plotting_test.cpp b/slsDetectorGui/tests/plotting_test.cpp index 217c36d45..4796860ea 100644 --- a/slsDetectorGui/tests/plotting_test.cpp +++ b/slsDetectorGui/tests/plotting_test.cpp @@ -173,12 +173,17 @@ QRect plotArea(const sls::SlsQtFastImage &view) { return sls::plot::plotRectFor(view.size(), sls::plot::PlotTheme()); } -// Number of matching pixels above and to the right of the plot area +// Number of matching pixels to the right of the plot area and above it, where +// an image view without titles draws nothing. The corners below and to the +// left are left out: how far the last tick labels reach into them depends on +// the font. int countOutside(const QImage &img, const QRect &plot, bool (*pred)(QRgb)) { int n = 0; for (int y = 0; y < img.height(); y++) { for (int x = 0; x < img.width(); x++) { - if ((x > plot.right() || y < plot.top()) && pred(img.pixel(x, y))) + const bool right = x > plot.right() && y <= plot.bottom(); + const bool above = y < plot.top() && x >= plot.left(); + if ((right || above) && pred(img.pixel(x, y))) n++; } } @@ -809,18 +814,19 @@ void PlottingTest::imagePixelLabels() { QVERIFY(outlines > 0); QVERIFY(labels > 0); - // longer labels need larger pixels: 1.2346e+06 + // longer labels need larger pixels: 1.2346e+06. The sizes leave room for + // fonts of different width. std::fill(f.begin(), f.end(), 1234567.5); view.setImage(f.data(), 64, 64); show(8); QCOMPARE(labels, 0); - show(4); // 67 + show(3); // 89 QVERIFY(labels > 0); // integers are written out: 1234567 std::fill(f.begin(), f.end(), 1234567.0); view.setImage(f.data(), 64, 64); - show(5); // 53 + show(4); // 67 QVERIFY(labels > 0); } @@ -1388,7 +1394,7 @@ void PlottingTest::plot2dTitles() { // the z title has its own row above the scale panel const QList labels = - plot.findChildren(Qt::FindDirectChildrenOnly); + plot.findChildren(QString(), Qt::FindDirectChildrenOnly); QCOMPARE(labels.size(), 1); QVERIFY(!labels[0]->isVisible()); plot.SetZTitle(QStringLiteral("counts"));