improve domain handling for math traces

This commit is contained in:
Jan Käberich 2025-05-01 14:53:48 +02:00
parent 4f63a28b61
commit b3b3fa7718
4 changed files with 57 additions and 11 deletions

View file

@ -465,7 +465,21 @@ void Trace::updateMathTracePoints()
double startX = std::numeric_limits<double>::lowest();
double stopX = std::numeric_limits<double>::max();
double stepSize = std::numeric_limits<double>::max();
auto domain = DataType::Invalid;
for(auto t : mathSourceTraces) {
if(domain == DataType::Invalid) {
domain = t.first->outputType();
} else {
if(domain != t.first->outputType()) {
// not all traces have the same domain, clear output and do not calculate
data.resize(0);
mathUpdateBegin = 0;
mathUpdateEnd = 0;
dataType = DataType::Invalid;
emit outputTypeChanged(dataType);
return;
}
}
if(t.first->minX() > startX) {
startX = t.first->minX();
}
@ -480,7 +494,14 @@ void Trace::updateMathTracePoints()
stepSize = traceStepSize;
}
}
unsigned int samples = round((stopX - startX) / stepSize + 1);
if(domain != this->domain) {
this->domain = domain;
emit typeChanged(this);
}
unsigned int samples = 0;
if(stopX > startX) {
samples = round((stopX - startX) / stepSize + 1);
}
// qDebug() << "Updated trace points, now"<<samples<<"points from"<<startX<<"to"<<stopX;
if(samples != data.size()) {
auto oldSize = data.size();

View file

@ -21,6 +21,7 @@ class TraceModel;
class Trace : public TraceMath
{
Q_OBJECT
friend class TraceEditDialog;
public:
using Data = TraceMath::Data;

View file

@ -198,16 +198,7 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) :
variableItem->setText("");
variableItem->setFlags(variableItem->flags() & ~(Qt::ItemIsEnabled | Qt::ItemIsEditable));
}
// available trace selections may have changed, disable/enable other rows
for(unsigned int i=0;i<t.getModel()->getTraces().size();i++) {
auto traceItem = ui->mathTraceTable->item(i, 0);
auto flags = traceItem->flags();
if(t.canAddAsMathSource(t.getModel()->trace(i))) {
traceItem->setFlags(flags | Qt::ItemIsEnabled);
} else {
traceItem->setFlags(flags & ~Qt::ItemIsEnabled);
}
}
updateMathFormulaSelectableRows();
} else {
// changed the variable name text
t.addMathSource(trace, item->text());
@ -216,6 +207,8 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) :
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(updateMathFormulaStatus());
});
}
updateMathFormulaSelectableRows();
updateMathFormulaStatus();
switch(t.getSource()) {
case Trace::Source::Live: ui->bLive->click(); break;
@ -384,6 +377,21 @@ void TraceEditDialog::okClicked()
bool TraceEditDialog::updateMathFormulaStatus()
{
// check output domains first (there could be a problem if a trace changed its output domain
// after the math trace was created)
auto domain = TraceMath::DataType::Invalid;
for(auto t : trace.mathSourceTraces) {
if(domain == TraceMath::DataType::Invalid) {
domain = t.first->outputType();
} else {
if(domain != t.first->outputType()) {
// not all traces have the same domain
ui->lMathFormulaStatus->setText("Different output domains of selected source traces");
ui->lMathFormulaStatus->setStyleSheet("QLabel { color : red; }");
return false;
}
}
}
auto error = trace.getMathFormulaError();
if(error.isEmpty()) {
// all good
@ -397,6 +405,21 @@ bool TraceEditDialog::updateMathFormulaStatus()
}
}
void TraceEditDialog::updateMathFormulaSelectableRows()
{
// available trace selections may have changed, disable/enable other rows
for(unsigned int i=0;i<trace.getModel()->getTraces().size();i++) {
auto traceItem = ui->mathTraceTable->item(i, 0);
auto flags = traceItem->flags();
if(trace.canAddAsMathSource(trace.getModel()->trace(i)) || traceItem->checkState()) {
// Item can always be deselected but only selected if it is compatible
traceItem->setFlags(flags | Qt::ItemIsEnabled);
} else {
traceItem->setFlags(flags & ~Qt::ItemIsEnabled);
}
}
}
MathModel::MathModel(Trace &t, QObject *parent)
: QAbstractTableModel(parent),
t(t)

View file

@ -50,6 +50,7 @@ private slots:
private:
bool updateMathFormulaStatus();
void updateMathFormulaSelectableRows();
Ui::TraceEditDialog *ui;
Trace &trace;
bool VNAtrace;