Skip to content

Commit

Permalink
show frequency range info in cal kit settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nanovna committed Jan 24, 2020
1 parent 083a2f7 commit 06fc6fa
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
51 changes: 38 additions & 13 deletions vna_qt/calkitsettingsdialog.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,40 @@ void CalKitSettingsDialog::fromSettings(const CalKitSettings &settings) {
for(auto& item:idealCalStds) {
string name = item.first;
string desc = name;
auto& inf = info[name];
if(calStdDesc.find(name) != calStdDesc.end())
desc = calStdDesc[name];

Ui::CalKitSettingsWidget& ui1 = info[name].ui;
Ui::CalKitSettingsWidget& ui1 = inf.ui;
QWidget* w = new QWidget();
ui1.setupUi(w);
layout->addWidget(w);

ui1.l_desc->setText(qs(desc));

auto it = settings.calKitModels.find(name);
if(it != settings.calKitModels.end()) {
if(it != settings.calKitModels.end() && (*it).second.values.size() != 0) {
ui1.r_s_param->setChecked(true);
info[name].data = (*it).second;
info[name].useIdeal = false;
const SParamSeries& series = (*it).second;
inf.data = series;
inf.useIdeal = false;
auto it2 = settings.calKitNames.find(name);
if(it2 != settings.calKitNames.end())
ui1.l_status->setText(qs((*it2).second));
} else info[name].useIdeal = true;
inf.fileName = (*it2).second;
ui1.l_status->setText(generateLabel(inf));
} else {
inf.useIdeal = true;
ui1.l_status->setText("");
}

connect(ui1.r_ideal, &QRadioButton::clicked, [this, name](){
info[name].useIdeal = true;
info[name].ui.l_status->setText("");
auto& inf = info[name];
inf.useIdeal = true;
inf.ui.l_status->setText("");
});

connect(ui1.r_s_param, &QRadioButton::clicked, [this, name](){
auto& inf = info[name];
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open S parameters file"), "",
tr("S parameters (*.s1p *.s2p);;All Files (*)"));
Expand All @@ -87,9 +95,10 @@ void CalKitSettingsDialog::fromSettings(const CalKitSettings &settings) {
try {
QFileInfo fileInfo(fileName);
parseTouchstone(data,nPorts,series.values);
info[name].useIdeal = false;
info[name].data = series;
info[name].ui.l_status->setText(fileInfo.fileName());
inf.useIdeal = false;
inf.data = series;
inf.fileName = fileName.toStdString();
inf.ui.l_status->setText(generateLabel(inf));
} catch(exception& ex) {
QMessageBox::warning(this, tr("Error parsing S parameter file"), ex.what());
goto fail;
Expand All @@ -99,7 +108,7 @@ void CalKitSettingsDialog::fromSettings(const CalKitSettings &settings) {
return;
fail:
// revert radiobutton state
info[name].ui.r_ideal->setChecked(info[name].useIdeal);
inf.ui.r_ideal->setChecked(inf.useIdeal);
});
}
}
Expand All @@ -113,7 +122,23 @@ void CalKitSettingsDialog::toSettings(CalKitSettings &settings) {
if(it == info.end()) continue;
if(!(*it).second.useIdeal) {
settings.calKitModels[name] = (*it).second.data;
settings.calKitNames[name] = (*it).second.ui.l_status->text().toStdString();
settings.calKitNames[name] = (*it).second.fileName;
}
}
}

QString CalKitSettingsDialog::generateLabel(const CalKitSettingsDialog::calKitInfo &inf) {
QString status;
status = qs(inf.fileName);
if(status == "")
status = "<no filename>";

status = status.toHtmlEscaped();

double startFreqHz = inf.data.values.begin()->first;
double stopFreqHz = inf.data.values.rbegin()->first;
status = "<pre>" + status
+ qs(ssprintf(256, "\n <b>%8.3f</b> MHz - <b>%8.3f</b> MHz, <b>%d</b> points</pre>",
startFreqHz*1e-6, stopFreqHz*1e-6, (int)inf.data.values.size()));
return status;
}
2 changes: 2 additions & 0 deletions vna_qt/calkitsettingsdialog.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CalKitSettingsDialog : public QDialog

struct calKitInfo {
Ui::CalKitSettingsWidget ui;
string fileName;
SParamSeries data;
bool useIdeal;
};
Expand All @@ -24,6 +25,7 @@ public:
void fromSettings(const CalKitSettings& settings);
void toSettings(CalKitSettings& settings);

QString generateLabel(const calKitInfo& inf);
map<string, calKitInfo> info;
private:
Ui::CalKitSettingsDialog *ui;
Expand Down
6 changes: 3 additions & 3 deletions vna_qt/calkitsettingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>389</height>
<width>772</width>
<height>511</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -45,7 +45,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<width>752</width>
<height>16</height>
</rect>
</property>
Expand Down
19 changes: 17 additions & 2 deletions vna_qt/calkitsettingswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>611</width>
<height>44</height>
<height>45</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -16,6 +16,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>45</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
Expand Down Expand Up @@ -85,8 +91,17 @@
</item>
<item>
<widget class="QLabel" name="l_status">
<property name="styleSheet">
<string notr="true">color: #0066aa; font-family: Monospace</string>
</property>
<property name="text">
<string/>
<string>aaaaa&lt;br /&gt;sssss</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="indent">
<number>8</number>
</property>
</widget>
</item>
Expand Down

0 comments on commit 06fc6fa

Please sign in to comment.