Skip to content

Commit 0d422bf

Browse files
authored
Merge pull request #979 from simoninns/issues-20251207
ld-analyse charting - fix some bugs - fix performance
2 parents ee53939 + 3dc75d2 commit 0d422bf

10 files changed

+353
-110
lines changed

tools/ld-analyse/blacksnranalysisdialog.cpp

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ui_blacksnranalysisdialog.h"
1313

1414
#include <QPen>
15+
#include <QTimer>
1516
#include <algorithm>
1617
#include <algorithm>
1718

@@ -27,14 +28,14 @@ BlackSnrAnalysisDialog::BlackSnrAnalysisDialog(QWidget *parent) :
2728
plot->updateTheme();
2829
ui->verticalLayout->addWidget(plot);
2930

30-
// Set up curves and marker
31-
blackCurve = plot->addCurve("Black SNR");
31+
// Set up series and marker
32+
blackSeries = plot->addSeries("Black SNR");
3233
// Theme-aware color: white in dark mode, black in light mode
3334
QColor dataColor = PlotWidget::isDarkTheme() ? Qt::white : Qt::black;
34-
blackCurve->setPen(QPen(dataColor, 2));
35+
blackSeries->setPen(QPen(dataColor, 2));
3536

36-
trendCurve = plot->addCurve("Trend line");
37-
trendCurve->setPen(QPen(Qt::red, 2));
37+
trendSeries = plot->addSeries("Trend line");
38+
trendSeries->setPen(QPen(Qt::red, 2));
3839

3940
plotMarker = plot->addMarker();
4041
plotMarker->setStyle(PlotMarker::VLine);
@@ -46,6 +47,14 @@ BlackSnrAnalysisDialog::BlackSnrAnalysisDialog(QWidget *parent) :
4647
// Set the default number of frames
4748
numberOfFrames = 0;
4849

50+
// Set up update throttling timer
51+
updateTimer = new QTimer(this);
52+
updateTimer->setSingleShot(true);
53+
updateTimer->setInterval(16); // ~60fps max update rate
54+
connect(updateTimer, &QTimer::timeout, this, &BlackSnrAnalysisDialog::onUpdateTimerTimeout);
55+
hasPendingUpdate = false;
56+
pendingFrameNumber = 0;
57+
4958
// Connect to plot area changed signal
5059
connect(plot, &PlotWidget::plotAreaChanged, this, &BlackSnrAnalysisDialog::onPlotAreaChanged);
5160
}
@@ -106,12 +115,12 @@ void BlackSnrAnalysisDialog::finishUpdate(qint32 _currentFrameNumber)
106115
plot->setAxisRange(Qt::Horizontal, 0, numberOfFrames);
107116
plot->setAxisRange(Qt::Vertical, 20, maxY);
108117

109-
// Set the black curve data
110-
blackCurve->setData(blackPoints);
118+
// Set the black series data
119+
blackSeries->setData(blackPoints);
111120

112121
// Generate and set the trend line
113122
generateTrendLine();
114-
trendCurve->setData(trendPoints);
123+
trendSeries->setData(trendPoints);
115124

116125
// Set the frame marker position
117126
plotMarker->setPosition(QPointF(static_cast<double>(_currentFrameNumber), (maxY + 20) / 2));
@@ -120,11 +129,40 @@ void BlackSnrAnalysisDialog::finishUpdate(qint32 _currentFrameNumber)
120129
plot->replot();
121130
}
122131

123-
// Method to update the frame marker
132+
// Method to update the frame marker (throttled for performance)
124133
void BlackSnrAnalysisDialog::updateFrameMarker(qint32 _currentFrameNumber)
125134
{
126-
plotMarker->setPosition(QPointF(static_cast<double>(_currentFrameNumber), (maxY + 20) / 2));
127-
plot->replot();
135+
// Always store the pending frame number
136+
pendingFrameNumber = _currentFrameNumber;
137+
hasPendingUpdate = true;
138+
139+
// Skip timer start if dialog is not visible - update will happen on show
140+
if (!isVisible()) return;
141+
142+
// Start or restart the timer
143+
if (!updateTimer->isActive()) {
144+
updateTimer->start();
145+
}
146+
}
147+
148+
void BlackSnrAnalysisDialog::onUpdateTimerTimeout()
149+
{
150+
if (!hasPendingUpdate) return;
151+
152+
plotMarker->setPosition(QPointF(static_cast<double>(pendingFrameNumber), (maxY + 20) / 2));
153+
// No need to call plot->replot() - marker update() handles the redraw
154+
155+
hasPendingUpdate = false;
156+
}
157+
158+
void BlackSnrAnalysisDialog::showEvent(QShowEvent *event)
159+
{
160+
QDialog::showEvent(event);
161+
162+
// Force immediate marker update if we have a pending position
163+
if (hasPendingUpdate) {
164+
onUpdateTimerTimeout();
165+
}
128166
}
129167

130168
void BlackSnrAnalysisDialog::onPlotAreaChanged()

tools/ld-analyse/blacksnranalysisdialog.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <cmath>
1515

1616
#include <QDialog>
17+
#include <QTimer>
18+
#include <QShowEvent>
1719
#include "plotwidget.h"
1820
#include "lddecodemetadata.h"
1921

@@ -34,23 +36,31 @@ class BlackSnrAnalysisDialog : public QDialog
3436
void finishUpdate(qint32 _currentFrameNumber);
3537
void updateFrameMarker(qint32 _currentFrameNumber);
3638

39+
protected:
40+
void showEvent(QShowEvent *event) override;
41+
3742
private slots:
3843
void onPlotAreaChanged();
44+
void onUpdateTimerTimeout();
3945

4046
private:
4147
void removeChartContents();
4248
void generateTrendLine();
4349

4450
Ui::BlackSnrAnalysisDialog *ui;
4551
PlotWidget *plot;
46-
PlotCurve *blackCurve;
47-
PlotCurve *trendCurve;
52+
PlotSeries *blackSeries;
53+
PlotSeries *trendSeries;
4854
PlotMarker *plotMarker;
4955

5056
double maxY;
5157
qint32 numberOfFrames;
5258
QVector<QPointF> blackPoints;
5359
QVector<QPointF> trendPoints;
60+
61+
QTimer *updateTimer;
62+
qint32 pendingFrameNumber;
63+
bool hasPendingUpdate;
5464
QVector<double> tlPoint;
5565
};
5666

tools/ld-analyse/dropoutanalysisdialog.cpp

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <QPen>
1515
#include <QDebug>
16+
#include <QTimer>
1617
#include <cmath>
1718

1819
DropoutAnalysisDialog::DropoutAnalysisDialog(QWidget *parent) :
@@ -27,9 +28,10 @@ DropoutAnalysisDialog::DropoutAnalysisDialog(QWidget *parent) :
2728
plot->updateTheme();
2829
ui->verticalLayout->addWidget(plot);
2930

30-
// Set up curve and marker
31-
curve = plot->addCurve("Dropout Length");
32-
curve->setPen(QPen(Qt::red, 1));
31+
// Set up series and marker
32+
series = plot->addSeries("Dropout Length");
33+
series->setPen(QPen(Qt::red, 1));
34+
series->setStyle(PlotSeries::Bars);
3335

3436
plotMarker = plot->addMarker();
3537
plotMarker->setStyle(PlotMarker::VLine);
@@ -41,6 +43,14 @@ DropoutAnalysisDialog::DropoutAnalysisDialog(QWidget *parent) :
4143
// Set the default number of frames
4244
numberOfFrames = 0;
4345

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, &DropoutAnalysisDialog::onUpdateTimerTimeout);
51+
hasPendingUpdate = false;
52+
pendingFrameNumber = 0;
53+
4454
// Connect to plot area changed signal
4555
connect(plot, &PlotWidget::plotAreaChanged, this, &DropoutAnalysisDialog::onPlotAreaChanged);
4656
}
@@ -98,8 +108,8 @@ void DropoutAnalysisDialog::finishUpdate(qint32 _currentFrameNumber)
98108

99109
// Set the dropout curve data with theme-aware color
100110
QColor dataColor = PlotWidget::isDarkTheme() ? Qt::yellow : Qt::darkMagenta;
101-
curve->setPen(QPen(dataColor, 2));
102-
curve->setData(points);
111+
series->setPen(QPen(dataColor, 2));
112+
series->setData(points);
103113

104114
// Set the frame marker position
105115
plotMarker->setPosition(QPointF(static_cast<double>(_currentFrameNumber), yMax / 2));
@@ -108,12 +118,41 @@ void DropoutAnalysisDialog::finishUpdate(qint32 _currentFrameNumber)
108118
plot->replot();
109119
}
110120

111-
// Method to update the frame marker
121+
// Method to update the frame marker (throttled for performance)
112122
void DropoutAnalysisDialog::updateFrameMarker(qint32 _currentFrameNumber)
113123
{
124+
// Always store the pending frame number
125+
pendingFrameNumber = _currentFrameNumber;
126+
hasPendingUpdate = true;
127+
128+
// Skip timer start if dialog is not visible - update will happen on show
129+
if (!isVisible()) return;
130+
131+
// Start or restart the timer
132+
if (!updateTimer->isActive()) {
133+
updateTimer->start();
134+
}
135+
}
136+
137+
void DropoutAnalysisDialog::onUpdateTimerTimeout()
138+
{
139+
if (!hasPendingUpdate) return;
140+
114141
double yMax = (maxY < 10) ? 10 : ceil(maxY + (maxY * 0.1));
115-
plotMarker->setPosition(QPointF(static_cast<double>(_currentFrameNumber), yMax / 2));
116-
plot->replot();
142+
plotMarker->setPosition(QPointF(static_cast<double>(pendingFrameNumber), yMax / 2));
143+
// No need to call plot->replot() - marker update() handles the redraw
144+
145+
hasPendingUpdate = false;
146+
}
147+
148+
void DropoutAnalysisDialog::showEvent(QShowEvent *event)
149+
{
150+
QDialog::showEvent(event);
151+
152+
// Force immediate marker update if we have a pending position
153+
if (hasPendingUpdate) {
154+
onUpdateTimerTimeout();
155+
}
117156
}
118157

119158
void DropoutAnalysisDialog::onPlotAreaChanged()

tools/ld-analyse/dropoutanalysisdialog.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define DROPOUTANALYSISDIALOG_H
1313

1414
#include <QDialog>
15+
#include <QTimer>
16+
#include <QShowEvent>
1517
#include "plotwidget.h"
1618
#include "lddecodemetadata.h"
1719

@@ -32,20 +34,28 @@ class DropoutAnalysisDialog : public QDialog
3234
void finishUpdate(qint32 _currentFrameNumber);
3335
void updateFrameMarker(qint32 _currentFrameNumber);
3436

37+
protected:
38+
void showEvent(QShowEvent *event) override;
39+
3540
private slots:
3641
void onPlotAreaChanged();
42+
void onUpdateTimerTimeout();
3743

3844
private:
3945
void removeChartContents();
4046

4147
Ui::DropoutAnalysisDialog *ui;
4248
PlotWidget *plot;
43-
PlotCurve *curve;
49+
PlotSeries *series;
4450
PlotMarker *plotMarker;
4551

4652
double maxY;
4753
qint32 numberOfFrames;
4854
QVector<QPointF> points;
55+
56+
QTimer *updateTimer;
57+
qint32 pendingFrameNumber;
58+
bool hasPendingUpdate;
4959
};
5060

5161
#endif // DROPOUTANALYSISDIALOG_H

0 commit comments

Comments
 (0)