From 6b81b307b7350c255553210375b8808104d26a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Mon, 12 May 2025 16:56:38 +0200 Subject: [PATCH] Fix: do not reset variable names for from math traces when opening trace edit dialog --- Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp | 9 +++++++++ .../LibreVNA-GUI/Traces/traceeditdialog.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp index 99d2d46..40b1761 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp @@ -551,6 +551,10 @@ void Trace::scheduleMathCalculation(unsigned int begin, unsigned int end) void Trace::calculateMath() { lastMathUpdate = QTime::currentTime(); + if(mathUpdateEnd <= mathUpdateBegin) { + // nothing to do + return; + } if(mathUpdateBegin >= data.size() || mathUpdateEnd >= data.size() + 1) { qWarning() << "Not calculating math trace, out of limits. Requested from" << mathUpdateBegin << "to" << mathUpdateEnd <<" but data is of size" << data.size(); return; @@ -660,6 +664,11 @@ bool Trace::canAddAsMathSource(Trace *t) bool Trace::addMathSource(Trace *t, QString variableName) { + if(mathSourceTraces.count(t)) { + // this trace is already used as a math source + mathSourceTraces[t] = variableName; + return true; + } // qDebug() << "Adding trace" << t << "as a math source to" << this << "as variable" << variableName; if(!canAddAsMathSource(t)) { return false; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp index ba4121b..1accf75 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp @@ -172,6 +172,7 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : if(t.mathDependsOn(ts, true)) { traceItem->setCheckState(Qt::Checked); variableItem->setFlags(variableItem->flags() | Qt::ItemIsEnabled | Qt::ItemIsEditable); + ui->mathTraceTable->blockSignals(false); } else { traceItem->setCheckState(Qt::Unchecked); } @@ -181,7 +182,7 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : connect(ui->mathTraceTable, &QTableWidget::itemChanged, [&](QTableWidgetItem *item){ auto row = ui->mathTraceTable->row(item); auto column = ui->mathTraceTable->column(item); - qDebug() << "Item changed at row"<mathTraceTable->blockSignals(true); auto trace = t.getModel()->trace(row); if(column == 0) { @@ -408,6 +409,9 @@ bool TraceEditDialog::updateMathFormulaStatus() void TraceEditDialog::updateMathFormulaSelectableRows() { // available trace selections may have changed, disable/enable other rows + + // block signals, otherwise the trace names will be reset + ui->mathTraceTable->blockSignals(true); for(unsigned int i=0;igetTraces().size();i++) { auto traceItem = ui->mathTraceTable->item(i, 0); auto flags = traceItem->flags(); @@ -418,6 +422,7 @@ void TraceEditDialog::updateMathFormulaSelectableRows() traceItem->setFlags(flags & ~Qt::ItemIsEnabled); } } + ui->mathTraceTable->blockSignals(false); } MathModel::MathModel(Trace &t, QObject *parent)