|
11 | 11 | #include "whitesnranalysisdialog.h" |
12 | 12 | #include "ui_whitesnranalysisdialog.h" |
13 | 13 |
|
| 14 | +#include <QTimer> |
14 | 15 | #include <algorithm> |
15 | 16 |
|
16 | 17 | WhiteSnrAnalysisDialog::WhiteSnrAnalysisDialog(QWidget *parent) : |
@@ -42,6 +43,14 @@ WhiteSnrAnalysisDialog::WhiteSnrAnalysisDialog(QWidget *parent) : |
42 | 43 | // Set the default number of frames |
43 | 44 | numberOfFrames = 0; |
44 | 45 |
|
| 46 | + // Set up update throttling timer |
| 47 | + updateTimer = new QTimer(this); |
| 48 | + updateTimer->setSingleShot(true); |
| 49 | + updateTimer->setInterval(16); // ~60fps max update rate |
| 50 | + connect(updateTimer, &QTimer::timeout, this, &WhiteSnrAnalysisDialog::onUpdateTimerTimeout); |
| 51 | + hasPendingUpdate = false; |
| 52 | + pendingFrameNumber = 0; |
| 53 | + |
45 | 54 | // Connect to plot area changed signal |
46 | 55 | connect(plot, &PlotWidget::plotAreaChanged, this, &WhiteSnrAnalysisDialog::onPlotAreaChanged); |
47 | 56 | } |
@@ -118,11 +127,40 @@ void WhiteSnrAnalysisDialog::finishUpdate(qint32 _currentFrameNumber) |
118 | 127 | plot->replot(); |
119 | 128 | } |
120 | 129 |
|
121 | | -// Method to update the frame marker |
| 130 | +// Method to update the frame marker (throttled for performance) |
122 | 131 | void WhiteSnrAnalysisDialog::updateFrameMarker(qint32 _currentFrameNumber) |
123 | 132 | { |
124 | | - plotMarker->setPosition(QPointF(static_cast<double>(_currentFrameNumber), (maxY + 14) / 2)); |
125 | | - plot->replot(); |
| 133 | + // Always store the pending frame number |
| 134 | + pendingFrameNumber = _currentFrameNumber; |
| 135 | + hasPendingUpdate = true; |
| 136 | + |
| 137 | + // Skip timer start if dialog is not visible - update will happen on show |
| 138 | + if (!isVisible()) return; |
| 139 | + |
| 140 | + // Start or restart the timer |
| 141 | + if (!updateTimer->isActive()) { |
| 142 | + updateTimer->start(); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +void WhiteSnrAnalysisDialog::onUpdateTimerTimeout() |
| 147 | +{ |
| 148 | + if (!hasPendingUpdate) return; |
| 149 | + |
| 150 | + plotMarker->setPosition(QPointF(static_cast<double>(pendingFrameNumber), (maxY + 14) / 2)); |
| 151 | + // No need to call plot->replot() - marker update() handles the redraw |
| 152 | + |
| 153 | + hasPendingUpdate = false; |
| 154 | +} |
| 155 | + |
| 156 | +void WhiteSnrAnalysisDialog::showEvent(QShowEvent *event) |
| 157 | +{ |
| 158 | + QDialog::showEvent(event); |
| 159 | + |
| 160 | + // Force immediate marker update if we have a pending position |
| 161 | + if (hasPendingUpdate) { |
| 162 | + onUpdateTimerTimeout(); |
| 163 | + } |
126 | 164 | } |
127 | 165 |
|
128 | 166 | void WhiteSnrAnalysisDialog::onPlotAreaChanged() |
|
0 commit comments