Skip to content

Commit db8ba00

Browse files
committed
fix cursors
1 parent 66b7dd8 commit db8ba00

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

gui/include/gui/cursorcontroller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define CURSORCONTROLLER_H
2424

2525
#include "scopy-gui_export.h"
26+
#include <plotaxis.h>
2627
#include <plotcursors.h>
2728
#include <widgets/cursorsettings.h>
2829
#include <widgets/plotcursorreadouts.h>
@@ -38,6 +39,7 @@ class SCOPY_GUI_EXPORT CursorController : public QObject
3839

3940
PlotCursors *getPlotCursors();
4041
void connectSignals(CursorSettings *cursorSettings);
42+
void setAxes(PlotAxis *xAxis, PlotAxis *yAxis);
4143

4244
void static syncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2);
4345
void static unsyncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2);

gui/src/cursorcontroller.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ void CursorController::updateTracking()
201201
}
202202
}
203203

204+
void CursorController::setAxes(PlotAxis *xAxis, PlotAxis *yAxis)
205+
{
206+
// Bootstrap the readouts with the current formatter and units of each axis.
207+
plotCursorReadouts->setXFormatter(xAxis->getFormatter());
208+
plotCursorReadouts->setYFormatter(yAxis->getFormatter());
209+
plotCursorReadouts->setXUnits(xAxis->getUnits());
210+
plotCursorReadouts->setYUnits(yAxis->getUnits());
211+
212+
// Stay in sync whenever the axes change.
213+
connect(xAxis, &PlotAxis::formatterChanged, plotCursorReadouts, &PlotCursorReadouts::setXFormatter);
214+
connect(xAxis, &PlotAxis::unitsChanged, plotCursorReadouts, &PlotCursorReadouts::setXUnits);
215+
connect(yAxis, &PlotAxis::formatterChanged, plotCursorReadouts, &PlotCursorReadouts::setYFormatter);
216+
connect(yAxis, &PlotAxis::unitsChanged, plotCursorReadouts, &PlotCursorReadouts::setYUnits);
217+
}
218+
204219
void CursorController::syncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2)
205220
{
206221
ctrl2->setVisible(ctrl1->isVisible());

packages/generic-plugins/plugins/adc/src/freq/fftplotcomponent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ FFTPlotComponent::FFTPlotComponent(QString name, uint32_t uuid, QWidget *parent)
9494
m_waterfallCursor = new CursorController(m_waterfallPlot, this);
9595
m_waterfallCursor->getPlotCursors()->setXHandlePos((HandlePos)xCursorPos);
9696
m_waterfallCursor->getPlotCursors()->setYHandlePos((HandlePos)yCursorPos);
97+
m_waterfallCursor->setAxes(m_waterfallPlot->xAxis(), m_waterfallPlot->yAxis());
9798

9899
CursorController::syncXCursorControllers(m_cursor, m_waterfallCursor);
99100
PlotNavigator::syncXNavigators(m_fftPlot->navigator(), m_waterfallPlot->navigator());

packages/generic-plugins/plugins/adc/src/freq/fftplotmanagersettings.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
145145
connect(xcb, qOverload<int>(&QComboBox::currentIndexChanged), this, [=](int idx) {
146146
for(PlotComponent *plt : m_plotManager->plots()) {
147147
auto p = dynamic_cast<FFTPlotComponent *>(plt);
148-
updateXMode(idx, p->fftPlot()->xAxis());
148+
updateXMode(idx, p->fftPlot()->xAxis(), p->waterfallPlot()->xAxis());
149149
}
150150
});
151151

@@ -186,7 +186,7 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
186186
return section;
187187
}
188188

189-
void FFTPlotManagerSettings::updateXMode(int mode, PlotAxis *axis)
189+
void FFTPlotManagerSettings::updateXMode(int mode, PlotAxis *fftAxis, PlotAxis *waterfallAxis)
190190
{
191191
QComboBox *xcb = m_xModeCb->combo();
192192
m_sampleRateSpin->setVisible(false);
@@ -198,10 +198,11 @@ void FFTPlotManagerSettings::updateXMode(int mode, PlotAxis *axis)
198198
m_plotManager->setXUnit("samples");
199199
m_sampleRateSpin->setValue(m_samplingInfo.bufferSize);
200200

201-
axis->scaleDraw()->setUnitType("");
202-
axis->scaleDraw()->setFloatPrecision(3);
203-
axis->scaleDraw()->setUnitsEnabled(false);
204-
axis->getFormatter()->setTwoDecimalMode(false);
201+
fftAxis->scaleDraw()->setUnitType("");
202+
fftAxis->scaleDraw()->setFloatPrecision(3);
203+
fftAxis->scaleDraw()->setUnitsEnabled(false);
204+
fftAxis->getFormatter()->setTwoDecimalMode(false);
205+
waterfallAxis->setUnits("samples");
205206
}
206207

207208
if(xcb->itemData(mode) == XMODE_TIME) {
@@ -214,10 +215,11 @@ void FFTPlotManagerSettings::updateXMode(int mode, PlotAxis *axis)
214215
m_freqOffsetSpin->setVisible(true);
215216
m_freqOffsetSpin->setEnabled(true);
216217

217-
axis->scaleDraw()->setUnitType("Hz");
218-
axis->scaleDraw()->setUnitsEnabled(true);
219-
axis->scaleDraw()->setFloatPrecision(3);
220-
axis->getFormatter()->setTwoDecimalMode(false);
218+
fftAxis->scaleDraw()->setUnitType("Hz");
219+
fftAxis->scaleDraw()->setUnitsEnabled(true);
220+
fftAxis->scaleDraw()->setFloatPrecision(3);
221+
fftAxis->getFormatter()->setTwoDecimalMode(false);
222+
waterfallAxis->setUnits("Hz");
221223
}
222224
if(xcb->itemData(mode) == XMODE_OVERRIDE) {
223225
m_xmin->setUnit("Hz");
@@ -229,10 +231,11 @@ void FFTPlotManagerSettings::updateXMode(int mode, PlotAxis *axis)
229231
m_freqOffsetSpin->setVisible(true);
230232
m_freqOffsetSpin->setEnabled(true);
231233

232-
axis->scaleDraw()->setUnitType("Hz");
233-
axis->scaleDraw()->setUnitsEnabled(true);
234-
axis->scaleDraw()->setFloatPrecision(3);
235-
axis->getFormatter()->setTwoDecimalMode(false);
234+
fftAxis->scaleDraw()->setUnitType("Hz");
235+
fftAxis->scaleDraw()->setUnitsEnabled(true);
236+
fftAxis->scaleDraw()->setFloatPrecision(3);
237+
fftAxis->getFormatter()->setTwoDecimalMode(false);
238+
waterfallAxis->setUnits("Hz");
236239
}
237240
updateXAxis();
238241
m_plotManager->updateAxisScales();
@@ -326,7 +329,7 @@ void FFTPlotManagerSettings::addPlot(FFTPlotComponent *p)
326329
// Set initial complex mode state
327330
p->plotMenu()->setComplexMode(m_samplingInfo.complexMode);
328331

329-
updateXMode(m_xModeCb->combo()->currentIndex(), p->fftPlot()->xAxis());
332+
updateXMode(m_xModeCb->combo()->currentIndex(), p->fftPlot()->xAxis(), p->waterfallPlot()->xAxis());
330333
}
331334

332335
void FFTPlotManagerSettings::setPlotComboVisible()

packages/generic-plugins/plugins/adc/src/freq/fftplotmanagersettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private Q_SLOTS:
103103
private:
104104
FFTPlotManager *m_plotManager;
105105

106-
void updateXMode(int mode, PlotAxis *axis);
106+
void updateXMode(int mode, PlotAxis *fftAxis, PlotAxis *waterfallAxis);
107107
QWidget *createMenu(QWidget *parent = nullptr);
108108
QWidget *createXAxisMenu(QWidget *parent = nullptr);
109109
QWidget *createYAxisMenu(QWidget *parent = nullptr);

0 commit comments

Comments
 (0)