From d77215aecb197ac72e040fad904cfc407f50fd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Fri, 31 Oct 2025 15:42:42 +0100 Subject: [PATCH] initialize new plots with the correct span --- .../LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp | 2 +- .../PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp | 9 +++++++++ Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.h | 6 ++++++ .../PC_Application/LibreVNA-GUI/Traces/traceplot.cpp | 3 +-- .../PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp | 3 +-- Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp index 6f28d66..9deb7b4 100644 --- a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp +++ b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp @@ -914,7 +914,7 @@ void SpectrumAnalyzer::ConfigureDevice() average.reset(DeviceDriver::SApoints()); UpdateAverageCount(); traceModel.clearLiveData(); - emit traceModel.SpanChanged(settings.freqStart, settings.freqStop); + traceModel.setSpan(settings.freqStart, settings.freqStop); } else { if(window->getDevice()) { changingSettings = true; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp index e69e900..02646ef 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp @@ -9,6 +9,8 @@ using namespace std; TraceModel::TraceModel(QObject *parent) : QAbstractTableModel(parent) { + spanFmin = 0.0; + spanFmax = 6000000000.0; traces.clear(); source = DataSource::Unknown; lastSweepPosition = 0.0; @@ -368,6 +370,13 @@ double TraceModel::getSweepPosition() const } } +void TraceModel::setSpan(double fmin, double fmax) +{ + spanFmin = fmin; + spanFmax = fmax; + emit SpanChanged(fmin, fmax); +} + MarkerModel *TraceModel::getMarkerModel() const { return markerModel; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.h b/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.h index e8f32fc..4fa5edb 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.h @@ -62,6 +62,10 @@ public: double getSweepPosition() const; + void setSpan(double fmin, double fmax); + double getSpanStart() {return spanFmin;} + double getSpanStop() {return spanFmax;} + signals: void SpanChanged(double fmin, double fmax); void traceAdded(Trace *t); @@ -80,6 +84,8 @@ private: QDateTime lastReceivedData; std::vector traces; MarkerModel *markerModel; + + double spanFmin, spanFmax; }; #endif // TRACEMODEL_H diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp index 931032d..fc461b3 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp @@ -42,8 +42,7 @@ TracePlot::TracePlot(TraceModel &model, QWidget *parent) lastUpdate = QTime::currentTime(); replotTimer.setSingleShot(true); connect(&replotTimer, &QTimer::timeout, this, qOverload<>(&TracePlot::update)); - sweep_fmin = std::numeric_limits::lowest(); - sweep_fmax = std::numeric_limits::max(); + TracePlot::updateSpan(model.getSpanStart(), model.getSpanStop()); xSweep = std::numeric_limits::quiet_NaN(); // get notified when the span changes connect(&model, &TraceModel::SpanChanged, this, qOverload(&TracePlot::updateSpan)); diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index 3fcd8ea..3547eea 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -29,8 +29,7 @@ TraceXYPlot::TraceXYPlot(TraceModel &model, QWidget *parent) // Setup default axis setYAxis(0, YAxis::Type::Magnitude, false, false, YAxis::getDefaultLimitMin(YAxis::Type::Magnitude), YAxis::getDefaultLimitMax(YAxis::Type::Magnitude), 14, true); setYAxis(1, YAxis::Type::Phase, false, false, YAxis::getDefaultLimitMin(YAxis::Type::Phase), YAxis::getDefaultLimitMax(YAxis::Type::Phase), 12, true); - // enable autoscaling and set for full span (no information about actual span available yet) - updateSpan(0, 6000000000); + setXAxis(XAxis::Type::Frequency, XAxisMode::UseSpan, false, 0, 6000000000, 10, true); initializeTraceInfo(); } diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index e418b30..b87379e 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -1961,7 +1961,7 @@ void VNA::ConfigureDevice(bool resetTraces, std::function cb) double start = settings.sweepType == SweepType::Frequency ? settings.Freq.start : settings.Power.start; double stop = settings.sweepType == SweepType::Frequency ? settings.Freq.stop : settings.Power.stop; int npoints = settings.npoints; - emit traceModel.SpanChanged(start, stop); + traceModel.setSpan(start, stop); if (settings.segments > 1) { // more than one segment, adjust start/stop npoints = ceil((double) settings.npoints / settings.segments);