From ca5fb9d8d41b1ed3c8216362da00663e0df437df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Fri, 13 Nov 2026 10:11:37 +0100 Subject: [PATCH] Readable pixel values in the 2D image Labels - Integers are written out in full, other values with five significant digits. Only the gain plot showed integers before, the data plot always printed one decimal (1234.0). - One font size for all labels, as large as the longest label on screen allows. Labels appear as soon as they fit instead of at a fixed magnification, and not at all while they would not fit. Cursor readout - Position and value of the pixel under the cursor are drawn in a corner of the plot area and follow the cursor, the zoom and new frames. It was a tooltip that showed up after a delay. Axes - The ticks show the coordinates given to SetData(), which puts the pixel index at the centre of each pixel. They showed pixel edges counted from the lower left corner. The help text on the plot describes the mouse actions of the 2D image. --- slsDetectorGui/forms/form_detectormain.ui | 2 +- .../include/SlsQtFastImage.h | 24 ++- .../slsDetectorPlotting/src/SlsQt2DPlot.cpp | 2 + .../src/SlsQtFastImage.cpp | 200 +++++++++++++----- slsDetectorGui/tests/plotting_test.cpp | 122 +++++++++++ 5 files changed, 296 insertions(+), 54 deletions(-) diff --git a/slsDetectorGui/forms/form_detectormain.ui b/slsDetectorGui/forms/form_detectormain.ui index bca9705ce..0ed41d5d8 100755 --- a/slsDetectorGui/forms/form_detectormain.ui +++ b/slsDetectorGui/forms/form_detectormain.ui @@ -818,7 +818,7 @@ <html><head/><body> -<span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Left Click :zoom in</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Right Click : zoom out by 1</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Middle Click : panning</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Ctrl+Right Click : zoom out to full size</span></body></html> +<span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">2D image</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Wheel or pinch : zoom</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Drag : panning</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Double Click : whole image</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;"></span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">1D plot</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Left Drag : zoom in</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Right Click : zoom out by 1</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Middle Drag : panning</span><br><span style=" font-family:'Sans Serif'; font-size:9pt; color:#00007f;">Ctrl+Right Click : zoom out to full size</span></body></html> diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h index bad05f244..d15e166bc 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h @@ -28,7 +28,8 @@ namespace sls { * * The wheel or a pinch zooms around the cursor, dragging pans and a double * click shows the whole image again. Once the pixels are large enough they - * are outlined and labelled with their value. + * are outlined and labelled with their value. Position and value of the + * pixel under the cursor are shown in a corner. */ class SlsQtFastImage : public QWidget { Q_OBJECT @@ -76,6 +77,10 @@ class SlsQtFastImage : public QWidget { QPointF widgetToData(const QPointF &widgetPos) const; QPointF dataToWidget(const QPointF &dataPos) const; + /** Values on the axes at the edges of the image. Without it the axes + * show the pixel index, at the centre of each pixel. */ + void setAxisRange(double xmin, double xmax, double ymin, double ymax); + void setZoomEnabled(bool on); bool zoomEnabled() const; void setAxesVisible(bool on); @@ -113,6 +118,7 @@ class SlsQtFastImage : public QWidget { void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; + void leaveEvent(QEvent *event) override; void wheelEvent(QWheelEvent *event) override; void resizeEvent(QResizeEvent *event) override; @@ -138,11 +144,22 @@ class SlsQtFastImage : public QWidget { } }; + /** Value on an axis for an image coordinate */ + struct Axis { + double origin; + double perPixel; + double value(double pixel) const { return origin + pixel * perPixel; } + double pixel(double value) const { return (value - origin) / perPixel; } + }; + QRect plotRect() const; Mapping mapping() const; + Axis xAxis() const; + Axis yAxis() const; void clampViewport(); void showArea(const QRectF &area); void zoomAt(const QPointF &widgetPos, double factor); + void updateHover(const QPointF &cursor); void renderImage(); void updateHistogram(); void drawImage(QPainter &p, const Mapping &m) const; @@ -150,6 +167,7 @@ class SlsQtFastImage : public QWidget { void drawPixelDetail(QPainter &p, const Mapping &m) const; void drawOverlays(QPainter &p, const Mapping &m) const; void drawTitles(QPainter &p, const Mapping &m) const; + void drawReadout(QPainter &p, const Mapping &m) const; double value(int ix, int iy) const; std::vector m_data; @@ -171,8 +189,12 @@ class SlsQtFastImage : public QWidget { QRectF m_viewport; // (x, y) is the lower left corner bool m_fillPlot = true; // show more than m_viewport to fill the plot area + QRectF m_axisRange; // null: pixel index bool m_zoomEnabled = true; bool m_axesVisible = true; + bool m_hasHover = false; // the cursor is on a pixel + QPoint m_hover; // that pixel + QPointF m_cursor; // widget position of the cursor bool m_panning = false; QPointF m_panStart; // widget position of the press QRectF m_panStartArea; // visibleArea() at the press diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp index ae56788af..a930cb766 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp @@ -109,6 +109,8 @@ void SlsQt2DPlot::SetData(int nbinsx, double xmin, double xmax, int nbinsy, } m_view->setImage(m_hist.GetDataPtr(), m_hist.GetNBinsX(), m_hist.GetNBinsY()); + m_view->setAxisRange(m_hist.GetXMin(), m_hist.GetXMax(), m_hist.GetYMin(), + m_hist.GetYMax()); m_contourDirty = true; Update(); } diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp index 6bbe5f1c0..f2cf368b3 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp @@ -21,11 +21,22 @@ constexpr int kMaxTicks = 8; constexpr double kWheelZoomFactor = 1.18; // widget pixels per image pixel from which the pixels are outlined / labelled constexpr double kOutlineMinScale = 16.0; -constexpr double kLabelMinScale = 50.0; +constexpr double kLabelMinScale = 24.0; +// font size of the pixel labels, in widget pixels +constexpr int kLabelMinFont = 8; +constexpr int kLabelMaxFont = 20; +// part of the width and of the height of a pixel that a label may fill +constexpr double kLabelWidth = 0.75; +constexpr double kLabelHeight = 0.3; +// significant digits of values that are not integers +constexpr int kLabelDigits = 5; +constexpr int kReadoutDigits = 8; -QString formatValue(double v) { - const bool integer = (v == std::round(v)); - return QString::number(v, 'f', integer ? 0 : 1); +// Integers are written out in full so that counts can be read exactly +QString formatValue(double v, int digits) { + if (v == std::round(v) && std::abs(v) < 1e15) + return QString::number(v, 'f', 0); + return QString::number(v, 'g', digits); } } // namespace @@ -52,6 +63,7 @@ void SlsQtFastImage::setImage(const double *data, int nx, int ny) { m_ny = ny; m_viewport = QRectF(0, 0, nx, ny); m_fillPlot = true; + m_hasHover = false; m_histogramAge.invalidate(); } m_imageDirty = true; @@ -314,6 +326,26 @@ QPointF SlsQtFastImage::dataToWidget(const QPointF &dataPos) const { : QPointF(); } +void SlsQtFastImage::setAxisRange(double xmin, double xmax, double ymin, + double ymax) { + if (!(xmax > xmin) || !(ymax > ymin)) + return; + m_axisRange = QRectF(xmin, ymin, xmax - xmin, ymax - ymin); + update(); +} + +SlsQtFastImage::Axis SlsQtFastImage::xAxis() const { + if (m_axisRange.isNull()) + return {-0.5, 1.0}; + return {m_axisRange.x(), m_axisRange.width() / m_nx}; +} + +SlsQtFastImage::Axis SlsQtFastImage::yAxis() const { + if (m_axisRange.isNull()) + return {-0.5, 1.0}; + return {m_axisRange.y(), m_axisRange.height() / m_ny}; +} + void SlsQtFastImage::setZoomEnabled(bool on) { m_zoomEnabled = on; if (!on) @@ -398,6 +430,7 @@ void SlsQtFastImage::paintEvent(QPaintEvent *) { drawPixelDetail(p, m); drawOverlays(p, m); drawTitles(p, m); + drawReadout(p, m); } void SlsQtFastImage::drawImage(QPainter &p, const Mapping &m) const { @@ -415,40 +448,46 @@ void SlsQtFastImage::drawAxes(QPainter &p, const Mapping &m) const { if (!m_axesVisible) return; const QRect plot = m.plot; - const double x0 = m.area.x(); - const double x1 = x0 + m.area.width(); - const double y0 = m.area.y(); - const double y1 = y0 + m.area.height(); + const Axis xAxis = this->xAxis(); + const Axis yAxis = this->yAxis(); + const double x0 = xAxis.value(m.area.x()); + const double x1 = xAxis.value(m.area.x() + m.area.width()); + const double y0 = yAxis.value(m.area.y()); + const double y1 = yAxis.value(m.area.y() + m.area.height()); const auto ticksX = plot::computeLinearTicks(x0, x1, kMaxTicks); const auto ticksY = plot::computeLinearTicks(y0, y1, kMaxTicks); const double stepX = plot::niceStep(x1 - x0, kMaxTicks); const double stepY = plot::niceStep(y1 - y0, kMaxTicks); + const auto widgetX = [&](double x) { + return m.toWidget(xAxis.pixel(x), 0).x(); + }; + const auto widgetY = [&](double y) { + return m.toWidget(0, yAxis.pixel(y)).y(); + }; p.save(); p.setFont(m_theme.tickFont); p.setClipRect(plot); p.setPen(QPen(m_theme.grid, 1, Qt::DotLine)); - for (const double x : ticksX) { - const double wx = m.toWidget(x, 0).x(); - p.drawLine(QPointF(wx, plot.top()), QPointF(wx, plot.bottom())); - } - for (const double y : ticksY) { - const double wy = m.toWidget(0, y).y(); - p.drawLine(QPointF(plot.left(), wy), QPointF(plot.right(), wy)); - } + for (const double x : ticksX) + p.drawLine(QPointF(widgetX(x), plot.top()), + QPointF(widgetX(x), plot.bottom())); + for (const double y : ticksY) + p.drawLine(QPointF(plot.left(), widgetY(y)), + QPointF(plot.right(), widgetY(y))); p.setClipping(false); p.setPen(m_theme.tick); for (const double x : ticksX) { - const double wx = m.toWidget(x, 0).x(); + const double wx = widgetX(x); p.drawLine(QPointF(wx, plot.bottom() + 1), QPointF(wx, plot.bottom() + 4)); p.drawText(QRectF(wx - 30, plot.bottom() + 5, 60, 14), Qt::AlignHCenter | Qt::AlignTop, plot::formatTick(x, stepX)); } for (const double y : ticksY) { - const double wy = m.toWidget(0, y).y(); + const double wy = widgetY(y); p.drawLine(QPointF(plot.left() - 4, wy), QPointF(plot.left() - 1, wy)); p.drawText(QRectF(plot.left() - 50, wy - 7, 44, 14), Qt::AlignRight | Qt::AlignVCenter, @@ -459,51 +498,90 @@ void SlsQtFastImage::drawAxes(QPainter &p, const Mapping &m) const { p.restore(); } +// Outlines the pixels and writes their values into them void SlsQtFastImage::drawPixelDetail(QPainter &p, const Mapping &m) const { if (m.scale < kOutlineMinScale) return; - const QRect plot = m.plot; - const double right = m.area.x() + m.area.width(); - const double top = m.area.y() + m.area.height(); - const int ix0 = std::max(0, static_cast(std::floor(m.area.x()))); - const int iy0 = std::max(0, static_cast(std::floor(m.area.y()))); - const int ix1 = std::min(m_nx, static_cast(std::ceil(right))); - const int iy1 = std::min(m_ny, static_cast(std::ceil(top))); + const QRectF clip = m.areaRect(); + const int ix0 = static_cast(std::floor(m.area.x())); + const int iy0 = static_cast(std::floor(m.area.y())); + const int ix1 = static_cast(std::ceil(m.area.x() + m.area.width())); + const int iy1 = static_cast(std::ceil(m.area.y() + m.area.height())); p.save(); - p.setClipRect(m.areaRect()); + p.setClipRect(clip); p.setPen(QColor(55, 55, 55)); for (int ix = ix0; ix <= ix1; ++ix) { const double wx = m.toWidget(ix, 0).x(); - p.drawLine(QPointF(wx, plot.top()), QPointF(wx, plot.bottom())); + p.drawLine(QPointF(wx, clip.top()), QPointF(wx, clip.bottom())); } for (int iy = iy0; iy <= iy1; ++iy) { const double wy = m.toWidget(0, iy).y(); - p.drawLine(QPointF(plot.left(), wy), QPointF(plot.right(), wy)); + p.drawLine(QPointF(clip.left(), wy), QPointF(clip.right(), wy)); } if (m.scale >= kLabelMinScale) { - QFont f = m_theme.tickFont; - f.setPixelSize(std::clamp(static_cast(m.scale * 0.25), 7, 20)); - p.setFont(f); + // One font size for all labels: as large as the longest one allows + QString longest; for (int iy = iy0; iy < iy1; ++iy) { for (int ix = ix0; ix < ix1; ++ix) { - const double v = value(ix, iy); - if (!std::isfinite(v)) - continue; - // dark text on bright pixels and the other way round - const QRgb c = m_image.pixel(ix, m_ny - 1 - iy); - p.setPen(qGray(c) > 140 ? QColor(15, 15, 15) - : QColor(245, 245, 245)); - const QRectF cell(m.toWidget(ix, iy + 1), - QSizeF(m.scale, m.scale)); - p.drawText(cell, Qt::AlignCenter, formatValue(v)); + const QString text = formatValue(value(ix, iy), kLabelDigits); + if (text.size() > longest.size()) + longest = text; + } + } + QFont f = m_theme.tickFont; + f.setPixelSize(kLabelMaxFont); + const double width = QFontMetricsF(f).horizontalAdvance(longest); + const double byWidth = + kLabelMaxFont * kLabelWidth * m.scale / std::max(width, 1.0); + const double byHeight = kLabelHeight * m.scale; + const int fontSize = static_cast( + std::min({double(kLabelMaxFont), byWidth, byHeight})); + if (fontSize >= kLabelMinFont) { + f.setPixelSize(fontSize); + p.setFont(f); + for (int iy = iy0; iy < iy1; ++iy) { + for (int ix = ix0; ix < ix1; ++ix) { + // dark text on bright pixels and the other way round + const QRgb c = m_image.pixel(ix, m_ny - 1 - iy); + p.setPen(qGray(c) > 140 ? QColor(15, 15, 15) + : QColor(245, 245, 245)); + const QRectF cell(m.toWidget(ix, iy + 1), + QSizeF(m.scale, m.scale)); + p.drawText(cell, Qt::AlignCenter, + formatValue(value(ix, iy), kLabelDigits)); + } } } } p.restore(); } +// Position and value of the pixel under the cursor, in a corner of the plot +// area that the cursor is not in +void SlsQtFastImage::drawReadout(QPainter &p, const Mapping &m) const { + if (!m_hasHover) + return; + const QString text = + QStringLiteral("x %1 y %2 %3") + .arg(formatValue(xAxis().value(m_hover.x() + 0.5), kReadoutDigits), + formatValue(yAxis().value(m_hover.y() + 0.5), kReadoutDigits), + formatValue(value(m_hover.x(), m_hover.y()), kReadoutDigits)); + p.save(); + QFont f = m_theme.tickFont; + f.setPixelSize(12); + p.setFont(f); + QRectF box(QPointF(), p.fontMetrics().size(0, text) + QSize(12, 6)); + box.moveTopRight(m.plot.topRight() + QPointF(-4, 5)); + if (box.adjusted(-20, -20, 20, 20).contains(m_cursor)) + box.moveLeft(m.plot.left() + 5); + p.fillRect(box, QColor(0, 0, 0, 170)); + p.setPen(m_theme.text); + p.drawText(box, Qt::AlignCenter, text); + p.restore(); +} + void SlsQtFastImage::drawOverlays(QPainter &p, const Mapping &m) const { p.save(); p.setClipRect(m.areaRect()); @@ -569,17 +647,33 @@ void SlsQtFastImage::mouseMoveEvent(QMouseEvent *e) { return; } - const QPointF d = m.toData(e->position()); - const int ix = static_cast(std::floor(d.x())); - const int iy = static_cast(std::floor(d.y())); - const bool onImage = m.plot.contains(e->position().toPoint()) && ix >= 0 && - ix < m_nx && iy >= 0 && iy < m_ny; - setCursor(onImage && m_zoomEnabled ? Qt::OpenHandCursor : Qt::ArrowCursor); - setToolTip(onImage ? QStringLiteral("(x=%1, y=%2) = %3") - .arg(ix) - .arg(iy) - .arg(formatValue(value(ix, iy))) - : QString()); + updateHover(e->position()); +} + +// Finds the pixel under the cursor, for the readout +void SlsQtFastImage::updateHover(const QPointF &cursor) { + const Mapping m = mapping(); + const QPointF d = m.toData(cursor); + const QPoint pixel(static_cast(std::floor(d.x())), + static_cast(std::floor(d.y()))); + const bool onImage = m.areaRect().contains(cursor) && + QRect(0, 0, m_nx, m_ny).contains(pixel); + if (!m_panning) + setCursor(onImage && m_zoomEnabled ? Qt::OpenHandCursor + : Qt::ArrowCursor); + m_cursor = cursor; + if (onImage != m_hasHover || pixel != m_hover) { + m_hasHover = onImage; + m_hover = pixel; + update(); + } +} + +void SlsQtFastImage::leaveEvent(QEvent *) { + if (m_hasHover) { + m_hasHover = false; + update(); + } } void SlsQtFastImage::mouseReleaseEvent(QMouseEvent *e) { @@ -600,6 +694,7 @@ void SlsQtFastImage::wheelEvent(QWheelEvent *e) { return; // A mouse wheel sends 120 per notch, a touchpad many small steps zoomAt(e->position(), std::pow(kWheelZoomFactor, delta / 120.0)); + updateHover(e->position()); } // Pinch on a touchpad @@ -609,6 +704,7 @@ bool SlsQtFastImage::event(QEvent *e) { if (gesture->gestureType() == Qt::ZoomNativeGesture) { // value() is the change of size since the previous event zoomAt(gesture->position(), std::max(0.1, 1 + gesture->value())); + updateHover(gesture->position()); return true; } } diff --git a/slsDetectorGui/tests/plotting_test.cpp b/slsDetectorGui/tests/plotting_test.cpp index a7a2ba4c9..217c36d45 100644 --- a/slsDetectorGui/tests/plotting_test.cpp +++ b/slsDetectorGui/tests/plotting_test.cpp @@ -220,6 +220,9 @@ class PlottingTest : public QObject { void imageOverlays(); void imageInterpolation(); void imageTitles(); + void imagePixelLabels(); + void imageReadout(); + void imageAxisValues(); void scaleHistoDrag(); void scaleHistoLogAxis(); @@ -772,6 +775,125 @@ void PlottingTest::imageTitles() { QCOMPARE(widgetPos(view, 0.0, 0.0).x(), 0.0); } +void PlottingTest::imagePixelLabels() { + sls::SlsQtFastImage view; + view.resize(400, 300); + view.show(); + view.setPalette(Palette::Gray); + view.setColorRange(0.0, 1e9); + std::vector f(64 * 64, 0.0); + view.setImage(f.data(), 64, 64); + + // what is drawn on the black pixels of the lower left size x size pixels, + // without the frame of the plot area around them + int outlines = 0, labels = 0; + const auto show = [&](double size) { + view.setViewport(0.0, 0.0, size, size); + const QRectF shown(widgetPos(view, 0.0, size), + widgetPos(view, size, 0.0)); + const QImage img = + render(view).copy(shown.toRect().adjusted(2, 2, -2, -2)); + outlines = + countPixels(img, [](QRgb c) { return c == qRgb(55, 55, 55); }); + labels = countPixels(img, isBright); + }; + + // the plot area is 268 pixels high + show(20); // 13 widget pixels per pixel + QCOMPARE(outlines, 0); + QCOMPARE(labels, 0); + show(12); // 22 + QVERIFY(outlines > 0); + QCOMPARE(labels, 0); + show(8); // 33 + QVERIFY(outlines > 0); + QVERIFY(labels > 0); + + // longer labels need larger pixels: 1.2346e+06 + std::fill(f.begin(), f.end(), 1234567.5); + view.setImage(f.data(), 64, 64); + show(8); + QCOMPARE(labels, 0); + show(4); // 67 + 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 + QVERIFY(labels > 0); +} + +void PlottingTest::imageReadout() { + sls::SlsQtFastImage view; + view.resize(400, 300); + view.show(); + const std::vector ramp = xRamp(64, 64); + view.setImage(ramp.data(), 64, 64); + const QPointF center(200.0, 150.0); + for (int i = 0; i < 4; i++) + sendWheel(view, center, 120); // the image fills the plot area + const QRect plot = plotArea(view); + QEvent leave(QEvent::Leave); + QCoreApplication::sendEvent(&view, &leave); + const QImage plain = render(view); + + // in the upper right corner of the plot area + sendMouse(view, QEvent::MouseMove, center, Qt::NoButton, Qt::NoButton); + QRect box = differingArea(plain, render(view)); + QVERIFY(plot.contains(box)); + QVERIFY(box.right() > plot.right() - 10 && box.top() < plot.top() + 10); + QVERIFY(box.width() > 50 && box.width() < 200 && box.height() < 30); + + // or in the left one if the cursor is there + sendMouse(view, QEvent::MouseMove, plot.topRight() + QPointF(-20, 15), + Qt::NoButton, Qt::NoButton); + box = differingArea(plain, render(view)); + QVERIFY(plot.contains(box)); + QVERIFY(box.left() < plot.left() + 10 && box.top() < plot.top() + 10); + + // gone with the cursor + QCoreApplication::sendEvent(&view, &leave); + QCOMPARE(render(view), plain); + sendMouse(view, QEvent::MouseMove, QPointF(5.0, 150.0), Qt::NoButton, + Qt::NoButton); + QCOMPARE(render(view), plain); +} + +void PlottingTest::imageAxisValues() { + sls::SlsQtFastImage view; + view.resize(400, 300); + view.show(); + const std::vector ramp = xRamp(8, 8); + view.setImage(ramp.data(), 8, 8); + const QRect plot = plotArea(view); + // is there a tick below the plot area at this image coordinate + const auto tickAt = [&](double x) { + const QImage img = render(view); + const int wx = int(widgetPos(view, x, 0.0).x()); + for (int dx = -1; dx <= 1; dx++) + if (img.pixel(wx + dx, plot.bottom() + 2) != kBackground) + return true; + return false; + }; + + // the pixel index, at the centre of the pixels + QVERIFY(tickAt(0.5) && tickAt(3.5) && tickAt(7.5)); + QVERIFY(!tickAt(1.0) && !tickAt(4.0) && !tickAt(7.0)); + + // or the values given for the edges of the image + view.setAxisRange(0.0, 8.0, 0.0, 8.0); + QVERIFY(tickAt(1.0) && tickAt(4.0) && tickAt(7.0)); + QVERIFY(!tickAt(0.5) && !tickAt(3.5) && !tickAt(7.5)); + view.setAxisRange(100.0, 500.0, 0.0, 8.0); // ticks every 50 + QVERIFY(tickAt(1.0) && tickAt(4.0) && tickAt(7.0)); + QVERIFY(!tickAt(0.5) && !tickAt(3.5) && !tickAt(7.5)); + + // an empty range is ignored + view.setAxisRange(5.0, 5.0, 0.0, 8.0); + QVERIFY(tickAt(1.0) && !tickAt(0.5)); +} + // --------------------------------------------------------------------------- // SlsQtScaleHisto and SlsQtScalePanel // ---------------------------------------------------------------------------