diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.cpp index c4512d7..0d3541c 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.cpp @@ -317,6 +317,11 @@ YAxis::Type YAxis::getType() const return type; } +bool YAxis::isSupported(XAxis::Type type, TraceModel::DataSource source) +{ + return getSupported(type, source).count(this->type); +} + std::set YAxis::getSupported(XAxis::Type type, TraceModel::DataSource source) { std::set ret = {YAxis::Type::Disabled}; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.h b/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.h index 53e8570..9334664 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceaxis.h @@ -98,6 +98,7 @@ public: Type getType() const; + bool isSupported(XAxis::Type type, TraceModel::DataSource source); static std::set getSupported(XAxis::Type type, TraceModel::DataSource source); static std::complex reconstructValueFromYAxisType(std::map yaxistypes); diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp index 282c9b7..e5f567c 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp @@ -788,12 +788,18 @@ void TracePlot::checkIfStillSupported(Trace *t) // attempt to configure the graph for the changed trace, remove only if this fails if(!configureForTrace(t)) { enableTrace(t, false); - } - // remove non-supported traces after graph has been adjusted - for(auto t : activeTraces()) { - if(!supported(t)) { - enableTrace(t, false); - } + } else { + // other trace may need to be removed because the graph no longer supports them. However, they (the traces) + // may change soon as well (e.g. because multiple traces changed at the same time and we are only handling + // the first changed trace right now). Postpone the deletion of other traces until all currently executing + // slots have completed + QTimer::singleShot(0, [this]{ + for(auto t : activeTraces()) { + if(!supported(t)) { + enableTrace(t, false); + } + } + }); } break; } diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp index 6e9bb61..1047da5 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracewaterfall.cpp @@ -159,14 +159,16 @@ void TraceWaterfall::resetWaterfall() bool TraceWaterfall::configureForTrace(Trace *t) { + YAxis::Type yDefault = YAxis::Type::Disabled; + switch(t->outputType()) { case Trace::DataType::Frequency: xAxis.set(XAxis::Type::Frequency, false, true, 0, 1, 0.1); - yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0); + yDefault = YAxis::Type::Magnitude; break; case Trace::DataType::Power: xAxis.set(XAxis::Type::Power, false, true, 0, 1, 0.1); - yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0); + yDefault = YAxis::Type::Magnitude; break; case Trace::DataType::Time: case Trace::DataType::TimeZeroSpan: @@ -174,6 +176,9 @@ bool TraceWaterfall::configureForTrace(Trace *t) // unable to add return false; } + if(!yAxis.isSupported(xAxis.getType(), getModel().getSource())) { + yAxis.set(yDefault, false, true, 0, 1, 1.0); + } traceRemovalPending = true; return true; } diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index e2874c3..07b96c9 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -287,31 +287,39 @@ void TraceXYPlot::axisSetupDialog() bool TraceXYPlot::configureForTrace(Trace *t) { + YAxis::Type yLeftDefault = YAxis::Type::Disabled; + YAxis::Type yRightDefault = YAxis::Type::Disabled; + switch(t->outputType()) { case Trace::DataType::Frequency: setXAxis(XAxis::Type::Frequency, XAxisMode::FitTraces, false, 0, 1, 0.1); - setYAxis(0, YAxis::Type::Magnitude, false, true, 0, 1, 1.0); - setYAxis(1, YAxis::Type::Phase, false, true, 0, 1, 1.0); + yLeftDefault = YAxis::Type::Magnitude; + yRightDefault = YAxis::Type::Phase; break; case Trace::DataType::Time: setXAxis(XAxis::Type::Time, XAxisMode::FitTraces, false, 0, 1, 0.1); - setYAxis(0, YAxis::Type::ImpulseMag, false, true, 0, 1, 1.0); - setYAxis(1, YAxis::Type::Disabled, false, true, 0, 1, 1.0); + yLeftDefault = YAxis::Type::ImpulseMag; break; case Trace::DataType::Power: setXAxis(XAxis::Type::Power, XAxisMode::FitTraces, false, 0, 1, 0.1); - setYAxis(0, YAxis::Type::Magnitude, false, true, 0, 1, 1.0); - setYAxis(1, YAxis::Type::Phase, false, true, 0, 1, 1.0); + yLeftDefault = YAxis::Type::Magnitude; + yRightDefault = YAxis::Type::Phase; break; case Trace::DataType::TimeZeroSpan: setXAxis(XAxis::Type::TimeZeroSpan, XAxisMode::FitTraces, false, 0, 1, 0.1); - setYAxis(0, YAxis::Type::Magnitude, false, true, 0, 1, 1.0); - setYAxis(1, YAxis::Type::Phase, false, true, 0, 1, 1.0); + yLeftDefault = YAxis::Type::Magnitude; + yRightDefault = YAxis::Type::Phase; break; case Trace::DataType::Invalid: // unable to add return false; } + if(!yAxis[0].isSupported(xAxis.getType(), getModel().getSource())) { + setYAxis(0, yLeftDefault, false, true, 0, 1, 1.0); + } + if(!yAxis[1].isSupported(xAxis.getType(), getModel().getSource())) { + setYAxis(1, yRightDefault, false, true, 0, 1, 1.0); + } traceRemovalPending = true; return true; }