Calibration - highlight state; save/load cosmetics

This commit is contained in:
Zoran Kostic 2020-11-30 17:05:15 +01:00
parent 49f9b5442d
commit cde385935d
3 changed files with 44 additions and 3 deletions

View File

@ -679,7 +679,7 @@ bool Calibration::openFromFile(QString filename)
return false; return false;
} }
} }
qDebug() << "Attempting to open calibration from file" << filename; qDebug() << "Attempting to open calibration from file" << filename;
// reset all data before loading new calibration // reset all data before loading new calibration
clearMeasurements(); clearMeasurements();
@ -716,7 +716,14 @@ qDebug() << "Attempting to open calibration from file" << filename;
bool Calibration::saveToFile(QString filename) bool Calibration::saveToFile(QString filename)
{ {
if(filename.isEmpty()) { if(filename.isEmpty()) {
filename = QFileDialog::getSaveFileName(nullptr, "Save calibration data", "", "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog); // suggest descriptive name
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()) { if(filename.isEmpty()) {
// aborted selection // aborted selection
return false; return false;
@ -738,6 +745,31 @@ bool Calibration::saveToFile(QString filename)
return true; return true;
} }
/**
* @brief Calibration::hzToString
* @param freqHz - input frequency in Hz
* @return frequency in human-readable 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;
}
ostream& operator<<(ostream &os, const Calibration &c) ostream& operator<<(ostream &os, const Calibration &c)
{ {
for(auto m : c.measurements) { for(auto m : c.measurements) {

View File

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

View File

@ -287,7 +287,8 @@ VNA::VNA(AppWindow *window)
// Calibration toolbar (and populate calibration menu) // Calibration toolbar (and populate calibration menu)
auto tb_cal = new QToolBar("Calibration"); auto tb_cal = new QToolBar("Calibration");
tb_cal->addWidget(new QLabel("Calibration:")); auto cbEnableCal_label = new QLabel("Calibration:");
tb_cal->addWidget(cbEnableCal_label);
auto cbEnableCal = new QCheckBox; auto cbEnableCal = new QCheckBox;
tb_cal->addWidget(cbEnableCal); tb_cal->addWidget(cbEnableCal);
auto cbType = new QComboBox(); auto cbType = new QComboBox();
@ -326,6 +327,7 @@ VNA::VNA(AppWindow *window)
cbEnableCal->blockSignals(true); cbEnableCal->blockSignals(true);
calDisable->setChecked(true); calDisable->setChecked(true);
cbEnableCal->setCheckState(Qt::CheckState::Unchecked); cbEnableCal->setCheckState(Qt::CheckState::Unchecked);
cbEnableCal_label->setStyleSheet("background-color: yellow");
cbType->blockSignals(false); cbType->blockSignals(false);
cbEnableCal->blockSignals(false); cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(false); calImportTerms->setEnabled(false);
@ -343,6 +345,7 @@ VNA::VNA(AppWindow *window)
} }
} }
cbEnableCal->setCheckState(Qt::CheckState::Checked); cbEnableCal->setCheckState(Qt::CheckState::Checked);
cbEnableCal_label->setStyleSheet("");
cbType->blockSignals(false); cbType->blockSignals(false);
cbEnableCal->blockSignals(false); cbEnableCal->blockSignals(false);
calImportTerms->setEnabled(true); calImportTerms->setEnabled(true);
@ -427,7 +430,12 @@ void VNA::initializeDevice()
if(cal.openFromFile(filename)) { if(cal.openFromFile(filename)) {
ApplyCalibration(cal.getType()); ApplyCalibration(cal.getType());
portExtension.setCalkit(&cal.getCalibrationKit()); 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); removeDefaultCal->setEnabled(true);
} else { } else {