Merge remote-tracking branch 'origin/trace_math'

This commit is contained in:
Zoran Kostic 2020-12-07 00:52:56 +01:00
commit d5aca3d5e1
4 changed files with 61 additions and 2 deletions

View File

@ -709,6 +709,7 @@ bool Calibration::openFromFile(QString filename)
qWarning() << "Calibration file parsing failed: " << e.what();
return false;
}
this->currentCalFile = filename; // if all ok, remember this
return true;
}
@ -716,7 +717,14 @@ bool Calibration::openFromFile(QString filename)
bool Calibration::saveToFile(QString filename)
{
if(filename.isEmpty()) {
filename = QFileDialog::getSaveFileName(nullptr, "Save calibration data", "", "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog);
// Suggest descriptive name ie. "SOLT 40M-700M 1000pt"
QString fn = Calibration::TypeToString(this->getType())
+ " "
+ hzToString(minFreq) + "-" + hzToString(maxFreq)
+ " "
+ QString::number(points.size()) + "pt";
//
filename = QFileDialog::getSaveFileName(nullptr, "Save calibration data", fn, "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog);
if(filename.isEmpty()) {
// aborted selection
return false;
@ -734,10 +742,40 @@ bool Calibration::saveToFile(QString filename)
auto calkit_file = filename + ".calkit";
qDebug() << "Saving associated calibration kit to file" << calkit_file;
kit.toFile(calkit_file);
this->currentCalFile = calibration_file; // if all ok, remember this
return true;
}
/**
* @brief Calibration::hzToString
* @param freqHz - input frequency in Hz
* @return frequency in human-friendly form such as 145k 2M, 2.1M, 3.45G
*/
QString Calibration::hzToString(double freqHz){
int dgt = 3; // how many significant digits
QString res = ""; // initialize
if (freqHz <= 999) {
// 0-999Hz
res = QString::number(freqHz / 1, 'g', dgt) + "Hz"; // 1.23Hz, 45Hz, 88.5Hz
} else if (freqHz <= 999999) {
// 1k-999kHz
res = QString::number(freqHz / 1000, 'g', dgt) + "k";
} else if (freqHz <= 999999999) {
// 1M-999M
res = QString::number(freqHz / 1000000, 'g', dgt) + "M";
} else {
// 1G-...
res = QString::number(freqHz / 1000000000, 'g', dgt) + "G";
}
return res;
}
QString Calibration::getCurrentCalibrationFile(){
return this->currentCalFile;
}
ostream& operator<<(ostream &os, const Calibration &c)
{
for(auto m : c.measurements) {

View File

@ -137,6 +137,12 @@ private:
std::vector<Point> points;
Calkit kit;
QString hzToString(double freqHz);
private:
QString currentCalFile;
public:
QString getCurrentCalibrationFile();
};
#endif // CALIBRATION_H

View File

@ -287,7 +287,8 @@ VNA::VNA(AppWindow *window)
// Calibration toolbar (and populate calibration menu)
auto tb_cal = new QToolBar("Calibration");
tb_cal->addWidget(new QLabel("Calibration:"));
QLabel *cbEnableCal_label = new QLabel("Calibration:"); // correct object type
tb_cal->addWidget(cbEnableCal_label);
auto cbEnableCal = new QCheckBox;
tb_cal->addWidget(cbEnableCal);
auto cbType = new QComboBox();
@ -326,6 +327,8 @@ VNA::VNA(AppWindow *window)
cbEnableCal->blockSignals(true);
calDisable->setChecked(true);
cbEnableCal->setCheckState(Qt::CheckState::Unchecked);
cbEnableCal_label->setStyleSheet("background-color: yellow"); // visually indicate loss of calibration
cbEnableCal_label->setToolTip("none"); // cal. file unknown at this moment
cbType->blockSignals(false);
cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(false);
@ -343,6 +346,8 @@ VNA::VNA(AppWindow *window)
}
}
cbEnableCal->setCheckState(Qt::CheckState::Checked);
cbEnableCal_label->setStyleSheet(""); // restore default look of widget
cbEnableCal_label->setToolTip(cal.getCurrentCalibrationFile()); // on hover, show name of active cal. file
cbType->blockSignals(false);
cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(true);
@ -427,7 +432,12 @@ void VNA::initializeDevice()
if(cal.openFromFile(filename)) {
ApplyCalibration(cal.getType());
portExtension.setCalkit(&cal.getCalibrationKit());
qDebug() << "Calibration successful from " << filename;
} else {
qDebug() << "Calibration not successfull from: " << filename;
}
} else {
qDebug() << "Calibration file not found: " << filename;
}
removeDefaultCal->setEnabled(true);
} else {

View File

@ -163,6 +163,11 @@ void PreferencesDialog::setInitialGUIState()
ui->GeneralGraphBackground->setColor(p->General.graphColors.background);
ui->GeneralGraphAxis->setColor(p->General.graphColors.axis);
ui->GeneralGraphDivisions->setColor(p->General.graphColors.divisions);
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(0);
if (item != nullptr) {
ui->treeWidget->setCurrentItem(item); // visually select first item
}
}
void Preferences::load()