2020-08-31 04:03:41 +08:00
|
|
|
#include "traceeditdialog.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
|
2020-08-31 04:03:41 +08:00
|
|
|
#include "ui_traceeditdialog.h"
|
2021-02-23 04:50:28 +08:00
|
|
|
#include "ui_newtracemathdialog.h"
|
2021-05-13 04:55:05 +08:00
|
|
|
#include "Math/tdr.h"
|
2022-03-03 19:28:59 +08:00
|
|
|
#include "appwindow.h"
|
2021-05-13 04:55:05 +08:00
|
|
|
|
2021-10-21 19:00:34 +08:00
|
|
|
#include <QColorDialog>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
2021-02-23 04:50:28 +08:00
|
|
|
namespace Ui {
|
|
|
|
class NewTraceMathDialog;
|
|
|
|
}
|
2020-08-31 04:03:41 +08:00
|
|
|
|
|
|
|
TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::TraceEditDialog),
|
|
|
|
trace(t)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-02-12 05:49:47 +08:00
|
|
|
ui->vFactor->setPrecision(3);
|
2020-08-31 04:03:41 +08:00
|
|
|
ui->name->setText(t.name());
|
2020-10-23 03:12:33 +08:00
|
|
|
ui->color->setColor(trace.color());
|
2021-02-12 05:49:47 +08:00
|
|
|
ui->vFactor->setValue(t.velocityFactor());
|
2022-03-18 01:24:18 +08:00
|
|
|
ui->impedance->setUnit("Ω");
|
|
|
|
ui->impedance->setPrecision(3);
|
|
|
|
ui->impedance->setValue(t.getReferenceImpedance());
|
2021-07-14 01:57:01 +08:00
|
|
|
|
2022-07-12 03:37:06 +08:00
|
|
|
if(!t.getModel()) {
|
|
|
|
// without information about the other traces in the model, math is not available as a source
|
|
|
|
ui->bMath->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2021-07-14 01:57:01 +08:00
|
|
|
connect(ui->bLive, &QPushButton::clicked, [=](bool live) {
|
|
|
|
if(live) {
|
|
|
|
ui->stack->setCurrentIndex(0);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(ui->bFile, &QPushButton::clicked, [&](bool file) {
|
|
|
|
if(file) {
|
|
|
|
if(t.getFilename().endsWith(".csv")) {
|
|
|
|
ui->stack->setCurrentIndex(2);
|
|
|
|
ui->csvImport->setFile(t.getFilename());
|
|
|
|
ui->csvImport->selectTrace(t.getFileParameter());
|
|
|
|
} else {
|
|
|
|
// attempt to parse as touchstone
|
|
|
|
ui->stack->setCurrentIndex(1);
|
|
|
|
ui->touchstoneImport->setFile(t.getFilename());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-12 03:37:06 +08:00
|
|
|
connect(ui->bMath, &QPushButton::clicked, [&](bool math){
|
|
|
|
if(math) {
|
|
|
|
ui->stack->setCurrentIndex(3);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid());
|
|
|
|
}
|
|
|
|
});
|
2021-07-14 01:57:01 +08:00
|
|
|
|
2020-10-23 03:12:33 +08:00
|
|
|
connect(ui->color, &ColorPickerButton::colorChanged, [=](const QColor& color){
|
|
|
|
trace.setColor(color);
|
|
|
|
});
|
2020-08-31 04:03:41 +08:00
|
|
|
|
|
|
|
ui->GSource->setId(ui->bLive, 0);
|
|
|
|
ui->GSource->setId(ui->bFile, 1);
|
2022-07-12 03:37:06 +08:00
|
|
|
ui->GSource->setId(ui->bFile, 2);
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2022-07-12 03:37:06 +08:00
|
|
|
if(t.getSource() == Trace::Source::Calibration) {
|
2020-12-13 05:51:38 +08:00
|
|
|
// prevent editing imported calibration traces (and csv files for now)
|
2020-08-31 04:03:41 +08:00
|
|
|
ui->bLive->setEnabled(false);
|
|
|
|
ui->bFile->setEnabled(false);
|
|
|
|
ui->CLiveType->setEnabled(false);
|
|
|
|
ui->CLiveParam->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2021-07-14 01:57:01 +08:00
|
|
|
auto updateTouchstoneFileStatus = [this]() {
|
2020-08-31 04:03:41 +08:00
|
|
|
// remove all options from paramater combo box
|
|
|
|
while(ui->CParameter->count() > 0) {
|
|
|
|
ui->CParameter->removeItem(0);
|
|
|
|
}
|
|
|
|
if (ui->bFile->isChecked() && !ui->touchstoneImport->getStatus()) {
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
auto touchstone = ui->touchstoneImport->getTouchstone();
|
|
|
|
for(unsigned int i=0;i<touchstone.ports();i++) {
|
|
|
|
for(unsigned int j=0;j<touchstone.ports();j++) {
|
|
|
|
QString name = "S"+QString::number(i+1)+QString::number(j+1);
|
|
|
|
ui->CParameter->addItem(name);
|
|
|
|
}
|
|
|
|
}
|
2020-12-13 05:51:38 +08:00
|
|
|
if(trace.getFileParameter() < touchstone.ports()*touchstone.ports()) {
|
|
|
|
ui->CParameter->setCurrentIndex(trace.getFileParameter());
|
2020-08-31 04:03:41 +08:00
|
|
|
} else {
|
|
|
|
ui->CParameter->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 01:57:01 +08:00
|
|
|
if(ui->touchstoneImport->getFilename().endsWith(".csv")) {
|
|
|
|
// switch to csv import dialog
|
|
|
|
ui->stack->setCurrentIndex(2);
|
|
|
|
ui->csvImport->setFile(ui->touchstoneImport->getFilename());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto updateCSVFileStatus = [this]() {
|
|
|
|
if (ui->bFile->isChecked() && !ui->csvImport->getStatus()) {
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
auto touchstone = ui->touchstoneImport->getTouchstone();
|
|
|
|
}
|
|
|
|
if(!(ui->touchstoneImport->getFilename().endsWith(".csv"))) {
|
|
|
|
// switch to touchstone import dialog
|
|
|
|
ui->stack->setCurrentIndex(1);
|
|
|
|
ui->touchstoneImport->setFile(ui->csvImport->getFilename());
|
|
|
|
}
|
2020-08-31 04:03:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
switch(t.liveType()) {
|
|
|
|
case Trace::LivedataType::Overwrite: ui->CLiveType->setCurrentIndex(0); break;
|
|
|
|
case Trace::LivedataType::MaxHold: ui->CLiveType->setCurrentIndex(1); break;
|
|
|
|
case Trace::LivedataType::MinHold: ui->CLiveType->setCurrentIndex(2); break;
|
2021-04-14 03:33:51 +08:00
|
|
|
default: break;
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
|
2021-04-14 03:33:51 +08:00
|
|
|
VNAtrace = Trace::isVNAParameter(t.liveParameter());
|
2022-08-05 02:12:15 +08:00
|
|
|
if(VirtualDevice::getConnected()) {
|
|
|
|
if(VNAtrace) {
|
|
|
|
ui->CLiveParam->addItems(VirtualDevice::getConnected()->availableVNAMeasurements());
|
|
|
|
} else {
|
|
|
|
ui->CLiveParam->addItems(VirtualDevice::getConnected()->availableSAMeasurements());
|
|
|
|
}
|
2020-09-17 21:51:20 +08:00
|
|
|
}
|
|
|
|
|
2022-08-05 02:12:15 +08:00
|
|
|
ui->CLiveParam->setCurrentText(t.liveParameter());
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2021-07-14 01:57:01 +08:00
|
|
|
connect(ui->touchstoneImport, &TouchstoneImport::statusChanged, updateTouchstoneFileStatus);
|
|
|
|
connect(ui->touchstoneImport, &TouchstoneImport::filenameChanged, updateTouchstoneFileStatus);
|
|
|
|
connect(ui->csvImport, &CSVImport::filenameChanged, updateCSVFileStatus);
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2022-07-12 03:37:06 +08:00
|
|
|
// Math source configuration
|
|
|
|
if(t.getModel()) {
|
|
|
|
ui->lMathFormula->setText(t.getMathFormula());
|
|
|
|
connect(ui->lMathFormula, &QLineEdit::editingFinished, [&](){
|
|
|
|
t.setMathFormula(ui->lMathFormula->text());
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid());
|
|
|
|
});
|
|
|
|
|
|
|
|
ui->mathTraceTable->setColumnCount(2);
|
|
|
|
ui->mathTraceTable->setHorizontalHeaderItem(0, new QTableWidgetItem("Trace Name"));
|
|
|
|
ui->mathTraceTable->setHorizontalHeaderItem(1, new QTableWidgetItem("Variable Name"));
|
|
|
|
auto traces = t.getModel()->getTraces();
|
|
|
|
ui->mathTraceTable->setRowCount(traces.size());
|
|
|
|
for(unsigned int i=0;i<traces.size();i++) {
|
|
|
|
auto ts = traces[i];
|
|
|
|
auto traceItem = new QTableWidgetItem(ts->name());
|
|
|
|
auto flags = traceItem->flags() | Qt::ItemIsUserCheckable;
|
|
|
|
flags &= ~(Qt::ItemIsEditable | Qt::ItemIsEnabled);
|
|
|
|
if(t.canAddAsMathSource(ts)) {
|
|
|
|
flags |= Qt::ItemIsEnabled;
|
|
|
|
}
|
|
|
|
traceItem->setFlags(flags);
|
|
|
|
auto variableItem = new QTableWidgetItem(t.getSourceVariableName(ts));
|
|
|
|
variableItem->setFlags(variableItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
if(t.mathDependsOn(ts, true)) {
|
|
|
|
traceItem->setCheckState(Qt::Checked);
|
|
|
|
variableItem->setFlags(variableItem->flags() | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
|
|
|
} else {
|
|
|
|
traceItem->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
|
|
|
ui->mathTraceTable->setItem(i, 0, traceItem);
|
|
|
|
ui->mathTraceTable->setItem(i, 1, variableItem);
|
|
|
|
}
|
|
|
|
connect(ui->mathTraceTable, &QTableWidget::itemChanged, [&](QTableWidgetItem *item){
|
|
|
|
auto row = ui->mathTraceTable->row(item);
|
|
|
|
auto column = ui->mathTraceTable->column(item);
|
|
|
|
qDebug() << "Item changed at row"<<row<<"column"<<column;
|
|
|
|
ui->mathTraceTable->blockSignals(true);
|
|
|
|
auto trace = t.getModel()->trace(row);
|
|
|
|
if(column == 0) {
|
|
|
|
auto variableItem = ui->mathTraceTable->item(row, 1);
|
|
|
|
// checked state changed
|
|
|
|
if(item->checkState() == Qt::Checked) {
|
|
|
|
// add this trace to the math sources, enable editing of variable name
|
|
|
|
t.addMathSource(trace, trace->name());
|
|
|
|
variableItem->setText(trace->name());
|
|
|
|
variableItem->setFlags(variableItem->flags() | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
|
|
|
} else {
|
|
|
|
// trace disabled, remove from math sources
|
|
|
|
t.removeMathSource(trace);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// changed the variable name text
|
|
|
|
t.addMathSource(trace, item->text());
|
|
|
|
}
|
|
|
|
ui->mathTraceTable->blockSignals(false);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(t.mathFormularValid());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(t.getSource()) {
|
|
|
|
case Trace::Source::Live: ui->bLive->click(); break;
|
|
|
|
case Trace::Source::File: ui->bFile->click(); break;
|
|
|
|
case Trace::Source::Math: ui->bMath->click(); break;
|
|
|
|
default: break;
|
2021-07-14 01:57:01 +08:00
|
|
|
}
|
2021-02-23 04:50:28 +08:00
|
|
|
|
|
|
|
// setup math part of the GUI
|
|
|
|
auto model = new MathModel(t);
|
|
|
|
ui->view->setModel(model);
|
|
|
|
|
|
|
|
QHeaderView *headerView = ui->view->horizontalHeader();
|
|
|
|
headerView->setSectionResizeMode(MathModel::ColIndexDescription, QHeaderView::Stretch);
|
|
|
|
headerView->setSectionResizeMode(MathModel::ColIndexStatus, QHeaderView::ResizeToContents);
|
|
|
|
headerView->setSectionResizeMode(MathModel::ColIndexDomain, QHeaderView::ResizeToContents);
|
|
|
|
|
|
|
|
connect(ui->view->selectionModel(), &QItemSelectionModel::currentRowChanged, [=](const QModelIndex ¤t, const QModelIndex &previous){
|
|
|
|
Q_UNUSED(previous)
|
|
|
|
if(!current.isValid()) {
|
|
|
|
ui->bDelete->setEnabled(false);
|
|
|
|
ui->bMoveUp->setEnabled(false);
|
|
|
|
ui->bMoveDown->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->bDelete->setEnabled(true);
|
|
|
|
ui->bMoveUp->setEnabled(current.row() > 1);
|
|
|
|
ui->bMoveDown->setEnabled(current.row() + 1 < model->rowCount());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->view, &QTableView::doubleClicked, [&](const QModelIndex &index) {
|
|
|
|
if(index.isValid()) {
|
|
|
|
auto math = t.getMathOperations().at(index.row()).math;
|
|
|
|
math->edit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->bAdd, &QPushButton::clicked, [=](){
|
|
|
|
auto d = new QDialog();
|
|
|
|
auto ui = new Ui::NewTraceMathDialog();
|
|
|
|
ui->setupUi(d);
|
2022-01-14 02:34:57 +08:00
|
|
|
connect(d, &QDialog::rejected, [=](){
|
2021-12-11 03:46:04 +08:00
|
|
|
delete ui;
|
|
|
|
});
|
2021-02-23 04:50:28 +08:00
|
|
|
for(int i = 0; i < (int) TraceMath::Type::Last;i++) {
|
|
|
|
auto info = TraceMath::getInfo(static_cast<TraceMath::Type>(i));
|
|
|
|
ui->list->addItem(info.name);
|
|
|
|
if(!info.explanationWidget) {
|
|
|
|
info.explanationWidget = new QWidget();
|
|
|
|
}
|
|
|
|
ui->stack->addWidget(info.explanationWidget);
|
|
|
|
}
|
|
|
|
// always show the widget for the selected function
|
|
|
|
connect(ui->list, &QListWidget::currentRowChanged, ui->stack, &QStackedWidget::setCurrentIndex);
|
|
|
|
|
|
|
|
connect(ui->list, &QListWidget::doubleClicked, ui->buttonBox, &QDialogButtonBox::accepted);
|
2022-01-14 02:34:57 +08:00
|
|
|
connect(d, &QDialog::accepted, [=](){
|
2021-04-25 21:46:34 +08:00
|
|
|
auto type = static_cast<TraceMath::Type>(ui->list->currentRow());
|
2022-01-14 02:34:57 +08:00
|
|
|
delete ui;
|
2021-04-25 21:46:34 +08:00
|
|
|
auto newMath = TraceMath::createMath(type);
|
|
|
|
model->addOperations(newMath);
|
|
|
|
if(newMath.size() == 1) {
|
2021-05-13 04:55:05 +08:00
|
|
|
// any normal math operation added, edit now
|
|
|
|
newMath[0]->edit();
|
2021-04-25 21:46:34 +08:00
|
|
|
} else {
|
2021-05-13 04:55:05 +08:00
|
|
|
// composite operation added, check which one and edit the correct suboperation
|
|
|
|
switch(type) {
|
|
|
|
case TraceMath::Type::TimeDomainGating:
|
|
|
|
// Automatically select bandpass/lowpass TDR, depending on selected span
|
|
|
|
if(newMath[0]->getInput()->rData().size() > 0) {
|
|
|
|
// Automatically select bandpass/lowpass TDR, depending on selected span
|
|
|
|
auto tdr = (Math::TDR*) newMath[0];
|
|
|
|
auto fstart = tdr->getInput()->rData().front().x;
|
|
|
|
auto fstop = tdr->getInput()->rData().back().x;
|
|
|
|
|
|
|
|
if(fstart < fstop / 100.0) {
|
|
|
|
tdr->setMode(Math::TDR::Mode::Lowpass);
|
|
|
|
} else {
|
|
|
|
// lowpass mode would result in very few points in the time domain, switch to bandpass mode
|
|
|
|
tdr->setMode(Math::TDR::Mode::Bandpass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TDR/DFT can be left at default, edit the actual gate
|
|
|
|
newMath[1]->edit();
|
2021-04-25 21:46:34 +08:00
|
|
|
break;
|
2021-05-13 04:55:05 +08:00
|
|
|
default:
|
2021-04-25 21:46:34 +08:00
|
|
|
break;
|
2021-05-13 04:55:05 +08:00
|
|
|
}
|
2021-04-25 21:46:34 +08:00
|
|
|
}
|
2021-02-23 04:50:28 +08:00
|
|
|
});
|
|
|
|
ui->list->setCurrentRow(0);
|
|
|
|
ui->stack->setCurrentIndex(0);
|
|
|
|
|
2022-03-03 19:28:59 +08:00
|
|
|
if(AppWindow::showGUI()) {
|
|
|
|
d->show();
|
|
|
|
}
|
2021-02-23 04:50:28 +08:00
|
|
|
});
|
|
|
|
connect(ui->bDelete, &QPushButton::clicked, [=](){
|
|
|
|
model->deleteRow(ui->view->currentIndex().row());
|
|
|
|
});
|
|
|
|
connect(ui->bMoveUp, &QPushButton::clicked, [&](){
|
|
|
|
auto index = ui->view->currentIndex();
|
|
|
|
t.swapMathOrder(index.row() - 1);
|
|
|
|
ui->view->setCurrentIndex(index.sibling(index.row() - 1, 0));
|
|
|
|
});
|
|
|
|
connect(ui->bMoveDown, &QPushButton::clicked, [&](){
|
|
|
|
auto index = ui->view->currentIndex();
|
|
|
|
t.swapMathOrder(index.row());
|
|
|
|
ui->view->setCurrentIndex(index.sibling(index.row() + 1, 0));
|
|
|
|
});
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TraceEditDialog::~TraceEditDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraceEditDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
trace.setName(ui->name->text());
|
2021-02-12 05:49:47 +08:00
|
|
|
trace.setVelocityFactor(ui->vFactor->value());
|
2022-07-12 03:37:06 +08:00
|
|
|
if(trace.getSource() != Trace::Source::Calibration) {
|
2020-08-31 04:03:41 +08:00
|
|
|
// only apply changes if it is not a calibration trace
|
|
|
|
if (ui->bFile->isChecked()) {
|
2021-07-14 01:57:01 +08:00
|
|
|
if(ui->stack->currentIndex() == 1) {
|
|
|
|
// touchstone page active
|
|
|
|
auto t = ui->touchstoneImport->getTouchstone();
|
|
|
|
trace.fillFromTouchstone(t, ui->CParameter->currentIndex());
|
|
|
|
} else {
|
|
|
|
// CSV page active
|
|
|
|
ui->csvImport->fillTrace(trace);
|
|
|
|
}
|
2022-07-12 03:37:06 +08:00
|
|
|
} else if(ui->bLive->isChecked()) {
|
2020-11-20 00:10:47 +08:00
|
|
|
Trace::LivedataType type = Trace::LivedataType::Overwrite;
|
2020-08-31 04:03:41 +08:00
|
|
|
switch(ui->CLiveType->currentIndex()) {
|
|
|
|
case 0: type = Trace::LivedataType::Overwrite; break;
|
|
|
|
case 1: type = Trace::LivedataType::MaxHold; break;
|
|
|
|
case 2: type = Trace::LivedataType::MinHold; break;
|
|
|
|
}
|
2022-08-05 02:12:15 +08:00
|
|
|
trace.fromLivedata(type, ui->CLiveParam->currentText());
|
2022-07-12 03:37:06 +08:00
|
|
|
} else {
|
|
|
|
// math operation trace
|
|
|
|
trace.fromMath();
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
}
|
2021-02-23 04:50:28 +08:00
|
|
|
|
|
|
|
MathModel::MathModel(Trace &t, QObject *parent)
|
|
|
|
: QAbstractTableModel(parent),
|
|
|
|
t(t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int MathModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return t.getMathOperations().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MathModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return ColIndexLast;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant MathModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if(!index.isValid()) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
auto math = t.getMathOperations().at(index.row());
|
|
|
|
switch(index.column()) {
|
|
|
|
case ColIndexStatus:
|
|
|
|
if(role == Qt::DecorationRole) {
|
|
|
|
switch(math.math->getStatus()) {
|
|
|
|
case TraceMath::Status::Ok:
|
|
|
|
return QApplication::style()->standardIcon(QStyle::SP_DialogApplyButton);
|
|
|
|
case TraceMath::Status::Warning:
|
|
|
|
return QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
|
|
|
|
case TraceMath::Status::Error:
|
|
|
|
return QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
|
|
|
}
|
|
|
|
} else if(role == Qt::ToolTipRole) {
|
|
|
|
if(math.math->getStatus() != TraceMath::Status::Ok) {
|
|
|
|
return math.math->getStatusDescription();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ColIndexDescription:
|
|
|
|
if(role == Qt::DisplayRole) {
|
|
|
|
return math.math->description();
|
|
|
|
}
|
|
|
|
// else if(role == Qt::CheckStateRole){
|
|
|
|
// return math.enabled ? Qt::Checked : Qt::Unchecked;
|
|
|
|
// }
|
|
|
|
break;
|
|
|
|
case ColIndexDomain:
|
|
|
|
if(role == Qt::DisplayRole) {
|
|
|
|
switch(math.math->getDataType()) {
|
|
|
|
case TraceMath::DataType::Time:
|
|
|
|
return "Time";
|
|
|
|
case TraceMath::DataType::Frequency:
|
|
|
|
return "Frequency";
|
2021-07-10 00:42:22 +08:00
|
|
|
case TraceMath::DataType::Power:
|
|
|
|
return "Power";
|
2022-06-23 05:50:21 +08:00
|
|
|
case TraceMath::DataType::TimeZeroSpan:
|
|
|
|
return "Time (Zero Span)";
|
2021-02-23 04:50:28 +08:00
|
|
|
case TraceMath::DataType::Invalid:
|
2022-06-23 05:50:21 +08:00
|
|
|
default:
|
2021-02-23 04:50:28 +08:00
|
|
|
return "Invalid";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant MathModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if(orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
switch(section) {
|
|
|
|
case ColIndexStatus: return "Status"; break;
|
|
|
|
case ColIndexDescription: return "Description"; break;
|
|
|
|
case ColIndexDomain: return "Output domain"; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags MathModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
int flags = Qt::NoItemFlags;
|
|
|
|
if(index.row() >= 1) {
|
|
|
|
// the first entry is always the trace itself and not enabled
|
|
|
|
flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
}
|
|
|
|
// switch(index.column()) {
|
|
|
|
// case ColIndexDescription: flags |= Qt::ItemIsUserCheckable; break;
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
return (Qt::ItemFlags) flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathModel::addOperation(TraceMath *math)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), t.getMathOperations().size(), t.getMathOperations().size());
|
|
|
|
t.addMathOperation(math);
|
|
|
|
endInsertRows();
|
2021-04-25 21:46:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MathModel::addOperations(std::vector<TraceMath *> maths)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), t.getMathOperations().size(), t.getMathOperations().size() + maths.size() - 1);
|
|
|
|
t.addMathOperations(maths);
|
|
|
|
endInsertRows();
|
2021-02-23 04:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MathModel::deleteRow(unsigned int row)
|
|
|
|
{
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
t.removeMathOperation(row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|