From bea37e6f5a721badbeb6ff6a74763a21e88476a6 Mon Sep 17 00:00:00 2001 From: Qt6 Port Date: Fri, 13 Nov 2026 09:27:04 +0100 Subject: [PATCH] Throttle display statistics and add a detach shortcut Display Statistics used to scan the whole frame and update three QLabels under the mPlots mutex for every incoming frame; on large frames or high rates this starves the GUI thread and blocks the receiver callback, which looks like a freeze. Statistics are now computed at most 4 times per second, the widget is shown/hidden only when its state changes, and min/max are initialised from the first pixel (correct for all-negative data). The detachable Plot settings action is also available as Ctrl+Shift+D, with a status tip; docs updated. Verified Qt5 and Qt6 builds, 31/31 plotting tests, and an acquisition run with statistics on/off and detach/reattach on both Qt majors. --- README.md | 4 ++-- docs/src/gui_plotting.rst | 8 ++++++- slsDetectorGui/include/qDrawPlot.h | 3 +++ slsDetectorGui/src/qDetectorMain.cpp | 5 ++++ slsDetectorGui/src/qDrawPlot.cpp | 36 ++++++++++++++++++++++------ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6d84f14ed..b41981922 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ To use the basic building blocks, meaning sls_detector_get/put and the shared li The GUI plotting (1D/2D plots, colour maps, scale panel) is implemented with plain Qt Widgets painting; Qwt, ROOT and OpenGL are no longer dependencies and the bundled Qwt copy has been removed. The Plot settings tab can be detached -with **View -> Detach Plot Settings**, so the configuration stays reachable -while an acquisition is started/stopped. +with **View -> Detach Plot Settings** (or **Ctrl+Shift+D**), so the +configuration stays reachable while an acquisition is started/stopped. #### Moench executables diff --git a/docs/src/gui_plotting.rst b/docs/src/gui_plotting.rst index 92c65c50f..50e91d3cb 100644 --- a/docs/src/gui_plotting.rst +++ b/docs/src/gui_plotting.rst @@ -97,7 +97,13 @@ The Plot settings tab can be detached into a movable/floating dock with **View -> Detach Plot Settings**. The tab contents are reparented between two ``QScrollArea`` widgets (the tab and the dock), so the same ``qTabPlot`` instance keeps working while the rest of the main window is busy starting or -stopping an acquisition. Selecting the action again reattaches the tab. +stopping an acquisition. Selecting the action again reattaches the tab; the +shortcut **Ctrl+Shift+D** toggles it without opening the menu. + +With **Display Statistics** enabled, the min/max/sum labels are refreshed at +most four times per second instead of once per frame. Scanning a large frame +and updating three labels for every incoming frame otherwise starves the GUI +thread and blocks the receiver callback. Demo and tests -------------- diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index c4b3b2a9d..67aed074f 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -4,6 +4,7 @@ #include "qDefs.h" #include "sls/Detector.h" #include "ui_form_plot.h" +#include #include class QResizeEvent; @@ -156,6 +157,8 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { bool isAccumulate{false}; bool resetAccumulate{false}; bool displayStatistics{false}; + bool statisticsVisible{false}; + QElapsedTimer statisticsTimer; QString fileSavePath{"/tmp"}; QString fileSaveName{"Image"}; bool hasGainData{false}; diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 1aa17ee34..624332332 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -273,6 +273,11 @@ void qDetectorMain::Initialization() { QMenu *menuView = menuBar()->addMenu(tr("&View")); actionDetachPlotSettings = new QAction(tr("Detach Plot Settings"), this); actionDetachPlotSettings->setCheckable(true); + actionDetachPlotSettings->setShortcut( + QKeySequence(QStringLiteral("Ctrl+Shift+D"))); + actionDetachPlotSettings->setStatusTip( + tr("Move the Plot settings into a movable dock so they stay usable " + "while the acquisition is started or stopped")); menuView->addAction(actionDetachPlotSettings); connect(actionDetachPlotSettings, &QAction::toggled, this, &qDetectorMain::SetPlotSettingsDetached); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index d8b260004..742046d21 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -453,6 +453,9 @@ void qDrawPlot::DisplayStatistics(bool enable) { LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Statistics Display"; displayStatistics = enable; + if (!enable) { + statisticsTimer.invalidate(); + } } void qDrawPlot::SetNumDiscardBits(int value) { @@ -583,6 +586,12 @@ void qDrawPlot::GetStatistics(double &min, double &max, double &sum) { array = datay1d[0]; size = nPixelsX; } + if (size <= 0) { + return; + } + min = array[0]; + max = array[0]; + sum = 0.0; for (int i = 0; i < size; ++i) { if (array[i] < min) min = array[i]; @@ -1229,14 +1238,27 @@ void qDrawPlot::UpdatePlot() { } if (displayStatistics) { - double min = 0, max = 0, sum = 0; - GetStatistics(min, max, sum); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - widgetStatistics->show(); - } else { + // Statistics are a slow readout. Do not scan the whole frame and + // relayout the labels for every incoming frame: that starves the GUI + // thread and blocks the receiver callback for large/high-rate frames. + constexpr qint64 statsIntervalMs = 250; + if (!statisticsTimer.isValid() || + statisticsTimer.elapsed() >= statsIntervalMs) { + double min = 0, max = 0, sum = 0; + GetStatistics(min, max, sum); + lblMinDisp->setText(QString("%1").arg(min)); + lblMaxDisp->setText(QString("%1").arg(max)); + lblSumDisp->setText(QString("%1").arg(sum)); + statisticsTimer.restart(); + } + if (!statisticsVisible) { + widgetStatistics->show(); + statisticsVisible = true; + } + } else if (statisticsVisible) { widgetStatistics->hide(); + statisticsVisible = false; + statisticsTimer.invalidate(); } LOG(logDEBUG) << "End of Update Plot";