diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp index 7f82690..ee017db 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp @@ -408,10 +408,10 @@ void Trace::setMathFormula(const QString &newMathFormula) scheduleMathCalculation(0, data.size()); } -bool Trace::mathFormularValid() const +QString Trace::getMathFormulaError() const { if(mathFormula.isEmpty()) { - return false; + return "Math formula must not be empty"; } try { ParserX parser(pckCOMMON | pckUNIT | pckCOMPLEX); @@ -428,15 +428,15 @@ bool Trace::mathFormularValid() const } } if(!found) { - return false; + return "Unknown variable: "+varName; } } } catch (const ParserError &e) { // parser error occurred - return false; + return "Parsing failed: " + QString::fromStdString(e.GetMsg()); } // all variables used in the expression are set as math sources - return true; + return ""; } bool Trace::resolveMathSourceHashes() diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.h b/Software/PC_Application/LibreVNA-GUI/Traces/trace.h index d4b813a..2e4a500 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.h @@ -166,7 +166,7 @@ public: const QString &getMathFormula() const; void setMathFormula(const QString &newMathFormula); - bool mathFormularValid() const; + QString getMathFormulaError() const; // When loading setups, some traces may be used as a math source before they are loaded. // If that happens, their hashes are added to a list. Call this function for every new trace diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp index fab0edb..02195a7 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.cpp @@ -56,7 +56,7 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : connect(ui->bMath, &QPushButton::clicked, [&](bool math){ if(math) { ui->stack->setCurrentIndex(3); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid()); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(updateMathFormulaStatus()); ui->impedance->setEnabled(true); } }); @@ -146,10 +146,11 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : connect(ui->csvImport, &CSVImport::filenameChanged, updateCSVFileStatus); // Math source configuration + ui->lMathFormula->setText(t.getMathFormula()); if(t.getModel()) { connect(ui->lMathFormula, &QLineEdit::textChanged, [&](){ t.setMathFormula(ui->lMathFormula->text()); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid()); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(updateMathFormulaStatus()); }); ui->mathTraceTable->setColumnCount(2); @@ -212,7 +213,7 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) : t.addMathSource(trace, item->text()); } ui->mathTraceTable->blockSignals(false); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid()); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(updateMathFormulaStatus()); }); } @@ -381,6 +382,21 @@ void TraceEditDialog::okClicked() delete this; } +bool TraceEditDialog::updateMathFormulaStatus() +{ + auto error = trace.getMathFormulaError(); + if(error.isEmpty()) { + // all good + ui->lMathFormulaStatus->setText("Math formula valid"); + ui->lMathFormulaStatus->setStyleSheet(""); + return true; + } else { + ui->lMathFormulaStatus->setText(error); + ui->lMathFormulaStatus->setStyleSheet("QLabel { color : red; }"); + return false; + } +} + MathModel::MathModel(Trace &t, QObject *parent) : QAbstractTableModel(parent), t(t) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h index e8b31b1..f00d237 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.h @@ -49,6 +49,7 @@ private slots: void okClicked(); private: + bool updateMathFormulaStatus(); Ui::TraceEditDialog *ui; Trace &trace; bool VNAtrace; diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui index da30276..ea98621 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceeditdialog.ui @@ -143,7 +143,7 @@ - 0 + 3 @@ -239,6 +239,16 @@ + + + + + + + true + + +