Throttle display statistics and add a detach shortcut
Build on RHEL9 / build (push) Successful in 3m4s
Build on RHEL8 / build (push) Successful in 4m58s

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.
This commit is contained in:
Qt6 Port committed 2026-11-13 09:27:04 +01:00
1 parent fdc457feeb
commit bea37e6f5a
5 files changed
+46 -10

No files matched your search

+2 -2
View File
@@ -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
+7 -1
View File
@@ -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
--------------
+3
View File
@@ -4,6 +4,7 @@
#include "qDefs.h"
#include "sls/Detector.h"
#include "ui_form_plot.h"
#include <QElapsedTimer>
#include <mutex>
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};
+5
View File
@@ -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);
+29 -7
View File
@@ -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";