Preparations for math functions on traces

This commit is contained in:
Jan Käberich 2020-11-25 16:47:29 +01:00
parent 978842a2ff
commit 66f8b86159
21 changed files with 819 additions and 124 deletions

View file

@ -52,7 +52,7 @@ void TraceModel::toggleVisibility(unsigned int index)
{
if (index < traces.size()) {
traces[index]->setVisible(!traces[index]->isVisible());
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
emit dataChanged(createIndex(index, ColIndexVisible), createIndex(index, ColIndexVisible));
}
}
@ -64,11 +64,23 @@ void TraceModel::togglePause(unsigned int index)
} else {
traces[index]->pause();
}
emit dataChanged(createIndex(index, 1), createIndex(index, 1));
emit dataChanged(createIndex(index, ColIndexPlayPause), createIndex(index, ColIndexPlayPause));
emit requiredExcitation(PortExcitationRequired(1), PortExcitationRequired(2));
}
}
void TraceModel::toggleMath(unsigned int index)
{
if (index >= traces.size()) {
return;
}
auto trace = traces[index];
if(trace->hasMathOperations()) {
trace->enableMath(!trace->mathEnabled());
emit dataChanged(createIndex(index, ColIndexMath), createIndex(index, ColIndexMath));
}
}
int TraceModel::rowCount(const QModelIndex &) const
{
return traces.size();
@ -76,7 +88,7 @@ int TraceModel::rowCount(const QModelIndex &) const
int TraceModel::columnCount(const QModelIndex &) const
{
return 3;
return ColIndexLast;
}
QVariant TraceModel::data(const QModelIndex &index, int role) const
@ -86,37 +98,47 @@ QVariant TraceModel::data(const QModelIndex &index, int role) const
if ((unsigned int) index.row() >= traces.size())
return QVariant();
if (index.column() == 0) {
auto trace = traces[index.row()];
switch(index.column()) {
case ColIndexVisible:
if (role == Qt::DecorationRole) {
if (traces[index.row()]->isVisible()) {
if (trace->isVisible()) {
return QIcon(":/icons/visible.svg");
} else {
return QIcon(":/icons/invisible.svg");
}
} else {
return QVariant();
}
} else if (index.column() == 1) {
if (role == Qt::DecorationRole && !traces[index.row()]->isTouchstone()) {
if (traces[index.row()]->isPaused()) {
break;
case ColIndexPlayPause:
if (role == Qt::DecorationRole && !trace->isTouchstone()) {
if (trace->isPaused()) {
return QIcon(":/icons/pause.svg");
} else {
return QIcon(":/icons/play.svg");
}
} else {
return QVariant();
}
} else if (index.column() == 2) {
break;
case ColIndexMath:
if (role == Qt::DecorationRole && trace->hasMathOperations()) {
if(trace->mathEnabled()) {
return QIcon(":icons/math_enabled");
} else {
return QIcon(":icons/math_disabled");
}
}
break;
case ColIndexName:
if (role == Qt::DisplayRole) {
return traces[index.row()]->name();
return trace->name();
} else if (role == Qt::ForegroundRole) {
return traces[index.row()]->color();
} else {
return QVariant();
return trace->color();
}
} else {
return QVariant();
break;
default:
break;
}
return QVariant();
}
std::vector<Trace *> TraceModel::getTraces()
@ -156,12 +178,12 @@ void TraceModel::addVNAData(const Protocol::Datapoint &d, const Protocol::SweepS
for(auto t : traces) {
if (t->isLive() && !t->isPaused()) {
Trace::Data td;
td.frequency = d.frequency;
td.x = d.frequency;
switch(t->liveParameter()) {
case Trace::LiveParameter::S11: td.S = complex<double>(d.real_S11, d.imag_S11); break;
case Trace::LiveParameter::S12: td.S = complex<double>(d.real_S12, d.imag_S12); break;
case Trace::LiveParameter::S21: td.S = complex<double>(d.real_S21, d.imag_S21); break;
case Trace::LiveParameter::S22: td.S = complex<double>(d.real_S22, d.imag_S22); break;
case Trace::LiveParameter::S11: td.y = complex<double>(d.real_S11, d.imag_S11); break;
case Trace::LiveParameter::S12: td.y = complex<double>(d.real_S12, d.imag_S12); break;
case Trace::LiveParameter::S21: td.y = complex<double>(d.real_S21, d.imag_S21); break;
case Trace::LiveParameter::S22: td.y = complex<double>(d.real_S22, d.imag_S22); break;
default:
// not a VNA trace, skip
continue;
@ -176,10 +198,10 @@ void TraceModel::addSAData(const Protocol::SpectrumAnalyzerResult& d, const Prot
for(auto t : traces) {
if (t->isLive() && !t->isPaused()) {
Trace::Data td;
td.frequency = d.frequency;
td.x = d.frequency;
switch(t->liveParameter()) {
case Trace::LiveParameter::Port1: td.S = complex<double>(d.port1, 0); break;
case Trace::LiveParameter::Port2: td.S = complex<double>(d.port2, 0); break;
case Trace::LiveParameter::Port1: td.y = complex<double>(d.port1, 0); break;
case Trace::LiveParameter::Port2: td.y = complex<double>(d.port2, 0); break;
default:
// not a SA trace, skip
continue;