2020-10-28 05:07:14 +08:00
|
|
|
#include "xyplotaxisdialog.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
|
2020-10-28 05:08:05 +08:00
|
|
|
#include "ui_xyplotaxisdialog.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
|
2020-10-28 05:07:14 +08:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-01-31 00:40:46 +08:00
|
|
|
static void enableComboBoxItem(QComboBox *cb, int itemNum, bool enable) {
|
|
|
|
auto *model = qobject_cast<QStandardItemModel *>(cb->model());
|
|
|
|
auto item = model->item(itemNum);
|
|
|
|
item->setFlags(enable ? item->flags() | Qt::ItemIsEnabled
|
|
|
|
: item->flags() & ~Qt::ItemIsEnabled);
|
|
|
|
}
|
|
|
|
|
2020-10-28 05:07:14 +08:00
|
|
|
XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) :
|
|
|
|
QDialog(nullptr),
|
|
|
|
ui(new Ui::XYplotAxisDialog),
|
|
|
|
plot(plot)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-06-28 05:40:50 +08:00
|
|
|
ui->Y1type->clear();
|
|
|
|
ui->Y2type->clear();
|
2021-10-11 21:22:08 +08:00
|
|
|
ui->Y1type->setMaxVisibleItems(20);
|
|
|
|
ui->Y2type->setMaxVisibleItems(20);
|
2021-06-28 05:40:50 +08:00
|
|
|
|
|
|
|
for(int i=0;i<(int) TraceXYPlot::YAxisType::Last;i++) {
|
|
|
|
ui->Y1type->addItem(TraceXYPlot::AxisTypeToName((TraceXYPlot::YAxisType) i));
|
|
|
|
ui->Y2type->addItem(TraceXYPlot::AxisTypeToName((TraceXYPlot::YAxisType) i));
|
|
|
|
}
|
2020-10-28 05:07:14 +08:00
|
|
|
|
2021-07-10 00:42:22 +08:00
|
|
|
for(int i=0;i<(int) TraceXYPlot::XAxisType::Last;i++) {
|
|
|
|
ui->XType->addItem(TraceXYPlot::AxisTypeToName((TraceXYPlot::XAxisType) i));
|
|
|
|
}
|
|
|
|
|
2022-01-31 00:40:46 +08:00
|
|
|
if(plot->getModel().getSource() == TraceModel::DataSource::SA) {
|
|
|
|
for(int i=0;i<ui->XType->count();i++) {
|
|
|
|
auto xtype = TraceXYPlot::XAxisTypeFromName(ui->XType->itemText(i));
|
|
|
|
if(!isSupported(xtype)) {
|
|
|
|
enableComboBoxItem(ui->XType, i, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 05:07:14 +08:00
|
|
|
// Setup GUI connections
|
2022-01-31 00:40:46 +08:00
|
|
|
connect(ui->Y1type, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index) {
|
2020-10-28 05:07:14 +08:00
|
|
|
//ui->Y1log->setEnabled(index != 0);
|
|
|
|
ui->Y1linear->setEnabled(index != 0);
|
|
|
|
ui->Y1auto->setEnabled(index != 0);
|
|
|
|
bool autoRange = ui->Y1auto->isChecked();
|
|
|
|
ui->Y1min->setEnabled(index != 0 && !autoRange);
|
|
|
|
ui->Y1max->setEnabled(index != 0 && !autoRange);
|
|
|
|
ui->Y1divs->setEnabled(index != 0 && !autoRange);
|
|
|
|
auto type = (TraceXYPlot::YAxisType) index;
|
2022-01-31 00:40:46 +08:00
|
|
|
QString unit = plot->AxisUnit(type);
|
2022-02-04 19:47:07 +08:00
|
|
|
QString prefixes = plot->AxisPrefixes(type);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y1min->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y1min->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y1max->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y1max->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y1divs->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y1divs->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
});
|
|
|
|
connect(ui->Y1auto, &QCheckBox::toggled, [this](bool checked) {
|
|
|
|
ui->Y1min->setEnabled(!checked);
|
|
|
|
ui->Y1max->setEnabled(!checked);
|
|
|
|
ui->Y1divs->setEnabled(!checked);
|
|
|
|
});
|
|
|
|
|
2022-01-31 00:40:46 +08:00
|
|
|
connect(ui->Y2type, qOverload<int>(&QComboBox::currentIndexChanged), [=](int index) {
|
2020-10-28 05:07:14 +08:00
|
|
|
//ui->Y2log->setEnabled(index != 0);
|
|
|
|
ui->Y2linear->setEnabled(index != 0);
|
|
|
|
ui->Y2auto->setEnabled(index != 0);
|
|
|
|
bool autoRange = ui->Y2auto->isChecked();
|
|
|
|
ui->Y2min->setEnabled(index != 0 && !autoRange);
|
|
|
|
ui->Y2max->setEnabled(index != 0 && !autoRange);
|
|
|
|
ui->Y2divs->setEnabled(index != 0 && !autoRange);
|
|
|
|
auto type = (TraceXYPlot::YAxisType) index;
|
2022-01-31 00:40:46 +08:00
|
|
|
QString unit = plot->AxisUnit(type);
|
2022-02-04 19:47:07 +08:00
|
|
|
QString prefixes = plot->AxisPrefixes(type);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y2min->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y2min->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y2max->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y2max->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Y2divs->setUnit(unit);
|
2022-02-04 19:47:07 +08:00
|
|
|
ui->Y2divs->setPrefixes(prefixes);
|
2020-10-28 05:07:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->Y2auto, &QCheckBox::toggled, [this](bool checked) {
|
|
|
|
ui->Y2min->setEnabled(!checked);
|
|
|
|
ui->Y2max->setEnabled(!checked);
|
|
|
|
ui->Y2divs->setEnabled(!checked);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->Xauto, &QCheckBox::toggled, [this](bool checked) {
|
|
|
|
ui->Xmin->setEnabled(!checked);
|
|
|
|
ui->Xmax->setEnabled(!checked);
|
2022-01-05 21:59:25 +08:00
|
|
|
ui->Xdivs->setEnabled(!checked && ui->Xlinear->isChecked());
|
2020-11-02 05:56:31 +08:00
|
|
|
ui->Xautomode->setEnabled(checked);
|
2020-10-28 05:07:14 +08:00
|
|
|
});
|
|
|
|
|
2020-11-02 05:56:31 +08:00
|
|
|
ui->XType->setCurrentIndex((int) plot->XAxis.type);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Xmin->setPrefixes("pnum kMG");
|
|
|
|
ui->Xmax->setPrefixes("pnum kMG");
|
|
|
|
ui->Xdivs->setPrefixes("pnum kMG");
|
|
|
|
|
2022-01-31 03:35:13 +08:00
|
|
|
ui->Y1min->setPrefixes("pnum kMG");
|
|
|
|
ui->Y1max->setPrefixes("pnum kMG");
|
|
|
|
ui->Y1divs->setPrefixes("pnum kMG");
|
|
|
|
|
|
|
|
ui->Y2min->setPrefixes("pnum kMG");
|
|
|
|
ui->Y2max->setPrefixes("pnum kMG");
|
|
|
|
ui->Y2divs->setPrefixes("pnum kMG");
|
|
|
|
|
2020-11-27 23:36:21 +08:00
|
|
|
XAxisTypeChanged((int) plot->XAxis.type);
|
|
|
|
connect(ui->XType, qOverload<int>(&QComboBox::currentIndexChanged), this, &XYplotAxisDialog::XAxisTypeChanged);
|
2022-01-05 21:59:25 +08:00
|
|
|
connect(ui->Xlog, &QCheckBox::toggled, [=](bool checked){
|
|
|
|
ui->Xdivs->setEnabled(!checked && !ui->Xauto->isChecked());
|
|
|
|
});
|
2020-11-27 23:36:21 +08:00
|
|
|
|
2020-10-28 05:07:14 +08:00
|
|
|
// Fill initial values
|
2020-11-02 05:56:31 +08:00
|
|
|
ui->Y1type->setCurrentIndex((int) plot->YAxis[0].type);
|
2020-10-28 05:07:14 +08:00
|
|
|
if(plot->YAxis[0].log) {
|
|
|
|
ui->Y1log->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui->Y1linear->setChecked(true);
|
|
|
|
}
|
|
|
|
ui->Y1auto->setChecked(plot->YAxis[0].autorange);
|
|
|
|
ui->Y1min->setValueQuiet(plot->YAxis[0].rangeMin);
|
|
|
|
ui->Y1max->setValueQuiet(plot->YAxis[0].rangeMax);
|
|
|
|
ui->Y1divs->setValueQuiet(plot->YAxis[0].rangeDiv);
|
|
|
|
|
2020-11-02 05:56:31 +08:00
|
|
|
ui->Y2type->setCurrentIndex((int) plot->YAxis[1].type);
|
2020-10-28 05:07:14 +08:00
|
|
|
if(plot->YAxis[1].log) {
|
|
|
|
ui->Y2log->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui->Y2linear->setChecked(true);
|
|
|
|
}
|
|
|
|
ui->Y2auto->setChecked(plot->YAxis[1].autorange);
|
|
|
|
ui->Y2min->setValueQuiet(plot->YAxis[1].rangeMin);
|
|
|
|
ui->Y2max->setValueQuiet(plot->YAxis[1].rangeMax);
|
|
|
|
ui->Y2divs->setValueQuiet(plot->YAxis[1].rangeDiv);
|
|
|
|
|
2022-01-05 21:59:25 +08:00
|
|
|
if(plot->XAxis.log) {
|
|
|
|
ui->Xlog->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui->Xlinear->setChecked(true);
|
|
|
|
}
|
2020-11-02 05:56:31 +08:00
|
|
|
ui->Xauto->setChecked(plot->XAxis.mode != TraceXYPlot::XAxisMode::Manual);
|
|
|
|
if(plot->XAxis.mode == TraceXYPlot::XAxisMode::UseSpan) {
|
|
|
|
ui->Xautomode->setCurrentIndex(0);
|
|
|
|
} else {
|
|
|
|
ui->Xautomode->setCurrentIndex(1);
|
|
|
|
}
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Xmin->setValueQuiet(plot->XAxis.rangeMin);
|
|
|
|
ui->Xmax->setValueQuiet(plot->XAxis.rangeMax);
|
|
|
|
ui->Xdivs->setValueQuiet(plot->XAxis.rangeDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
XYplotAxisDialog::~XYplotAxisDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XYplotAxisDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
// set plot values to the ones selected in the dialog
|
|
|
|
plot->setYAxis(0, (TraceXYPlot::YAxisType) ui->Y1type->currentIndex(), ui->Y1log->isChecked(), ui->Y1auto->isChecked(), ui->Y1min->value(), ui->Y1max->value(), ui->Y1divs->value());
|
|
|
|
plot->setYAxis(1, (TraceXYPlot::YAxisType) ui->Y2type->currentIndex(), ui->Y2log->isChecked(), ui->Y2auto->isChecked(), ui->Y2min->value(), ui->Y2max->value(), ui->Y2divs->value());
|
2020-11-02 05:56:31 +08:00
|
|
|
TraceXYPlot::XAxisMode mode;
|
|
|
|
if(ui->Xauto->isChecked()) {
|
|
|
|
if(ui->Xautomode->currentIndex() == 0) {
|
|
|
|
mode = TraceXYPlot::XAxisMode::UseSpan;
|
|
|
|
} else {
|
|
|
|
mode = TraceXYPlot::XAxisMode::FitTraces;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mode = TraceXYPlot::XAxisMode::Manual;
|
|
|
|
}
|
2022-01-05 21:59:25 +08:00
|
|
|
plot->setXAxis((TraceXYPlot::XAxisType) ui->XType->currentIndex(), mode, ui->Xlog->isChecked(), ui->Xmin->value(), ui->Xmax->value(), ui->Xdivs->value());
|
2020-11-02 05:56:31 +08:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:07:14 +08:00
|
|
|
void XYplotAxisDialog::XAxisTypeChanged(int XAxisIndex)
|
|
|
|
{
|
|
|
|
auto type = (TraceXYPlot::XAxisType) XAxisIndex;
|
|
|
|
auto supported = supportedYAxis(type);
|
2021-12-11 06:36:28 +08:00
|
|
|
for(unsigned int i=0;i<(int) TraceXYPlot::YAxisType::Last;i++) {
|
|
|
|
auto t = (TraceXYPlot::YAxisType) i;
|
2020-10-28 05:07:14 +08:00
|
|
|
auto enable = supported.count(t) > 0;
|
|
|
|
auto index = (int) t;
|
2020-11-02 05:56:31 +08:00
|
|
|
enableComboBoxItem(ui->Y1type, index, enable);
|
|
|
|
enableComboBoxItem(ui->Y2type, index, enable);
|
2020-10-28 05:07:14 +08:00
|
|
|
}
|
|
|
|
// Disable Yaxis if previously selected type is not supported
|
|
|
|
if(!supported.count((TraceXYPlot::YAxisType)ui->Y1type->currentIndex())) {
|
|
|
|
ui->Y1type->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
if(!supported.count((TraceXYPlot::YAxisType)ui->Y2type->currentIndex())) {
|
|
|
|
ui->Y2type->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
2020-11-02 05:56:31 +08:00
|
|
|
if(type == TraceXYPlot::XAxisType::Frequency) {
|
|
|
|
enableComboBoxItem(ui->Xautomode, 0, true);
|
2022-01-05 21:59:25 +08:00
|
|
|
ui->Xlog->setEnabled(true);
|
2020-11-02 05:56:31 +08:00
|
|
|
} else {
|
|
|
|
// auto mode using span not supported in time mode
|
|
|
|
if(ui->Xautomode->currentIndex() == 0) {
|
|
|
|
ui->Xautomode->setCurrentIndex(1);
|
|
|
|
}
|
2022-01-05 21:59:25 +08:00
|
|
|
enableComboBoxItem(ui->Xautomode, 0, false);
|
|
|
|
// log option only available for frequency axis
|
|
|
|
if(ui->Xlog->isChecked()) {
|
|
|
|
ui->Xlinear->setChecked(true);
|
|
|
|
}
|
|
|
|
ui->Xlog->setEnabled(false);
|
2020-11-02 05:56:31 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 18:55:53 +08:00
|
|
|
QString unit = TraceXYPlot::AxisUnit(type);
|
2020-10-28 05:07:14 +08:00
|
|
|
ui->Xmin->setUnit(unit);
|
|
|
|
ui->Xmax->setUnit(unit);
|
|
|
|
ui->Xdivs->setUnit(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<TraceXYPlot::YAxisType> XYplotAxisDialog::supportedYAxis(TraceXYPlot::XAxisType type)
|
|
|
|
{
|
|
|
|
set<TraceXYPlot::YAxisType> ret = {TraceXYPlot::YAxisType::Disabled};
|
2022-01-31 00:40:46 +08:00
|
|
|
auto source = plot->getModel().getSource();
|
|
|
|
if(source == TraceModel::DataSource::VNA) {
|
|
|
|
switch(type) {
|
|
|
|
case TraceXYPlot::XAxisType::Frequency:
|
|
|
|
case TraceXYPlot::XAxisType::Power:
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Magnitude);
|
2022-03-14 06:00:06 +08:00
|
|
|
ret.insert(TraceXYPlot::YAxisType::MagnitudeLinear);
|
2022-01-31 00:40:46 +08:00
|
|
|
ret.insert(TraceXYPlot::YAxisType::Phase);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::UnwrappedPhase);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::VSWR);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Real);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Imaginary);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::SeriesR);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Reactance);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Capacitance);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Inductance);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::QualityFactor);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::GroupDelay);
|
|
|
|
break;
|
|
|
|
case TraceXYPlot::XAxisType::Time:
|
|
|
|
case TraceXYPlot::XAxisType::Distance:
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::ImpulseReal);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::ImpulseMag);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Step);
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Impedance);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(source == TraceModel::DataSource::SA) {
|
|
|
|
switch(type) {
|
|
|
|
case TraceXYPlot::XAxisType::Frequency:
|
|
|
|
ret.insert(TraceXYPlot::YAxisType::Magnitude);
|
2022-03-15 22:52:57 +08:00
|
|
|
ret.insert(TraceXYPlot::YAxisType::MagnitudedBuV);
|
2022-01-31 00:40:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-10-28 05:07:14 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2022-01-31 00:40:46 +08:00
|
|
|
|
|
|
|
bool XYplotAxisDialog::isSupported(TraceXYPlot::XAxisType type)
|
|
|
|
{
|
|
|
|
auto source = plot->getModel().getSource();
|
|
|
|
if(source == TraceModel::DataSource::VNA) {
|
|
|
|
// all X axis types are supported
|
|
|
|
return true;
|
|
|
|
} else if(source == TraceModel::DataSource::SA) {
|
|
|
|
if (type == TraceXYPlot::XAxisType::Frequency) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|