From cde385935d12411213766047011e43fad7ac34af Mon Sep 17 00:00:00 2001 From: Zoran Kostic <60575976+nbgsmk@users.noreply.github.com> Date: Mon, 30 Nov 2020 17:05:15 +0100 Subject: [PATCH 1/3] Calibration - highlight state; save/load cosmetics --- .../Calibration/calibration.cpp | 36 +++++++++++++++++-- .../PC_Application/Calibration/calibration.h | 1 + Software/PC_Application/VNA/vna.cpp | 10 +++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Software/PC_Application/Calibration/calibration.cpp b/Software/PC_Application/Calibration/calibration.cpp index 3b27a6f..54f02c9 100644 --- a/Software/PC_Application/Calibration/calibration.cpp +++ b/Software/PC_Application/Calibration/calibration.cpp @@ -679,7 +679,7 @@ bool Calibration::openFromFile(QString filename) 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 clearMeasurements(); @@ -716,7 +716,14 @@ qDebug() << "Attempting to open calibration from file" << 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 + 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; @@ -738,6 +745,31 @@ bool Calibration::saveToFile(QString filename) 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) { for(auto m : c.measurements) { diff --git a/Software/PC_Application/Calibration/calibration.h b/Software/PC_Application/Calibration/calibration.h index 47b496d..76e40b7 100644 --- a/Software/PC_Application/Calibration/calibration.h +++ b/Software/PC_Application/Calibration/calibration.h @@ -137,6 +137,7 @@ private: std::vector points; Calkit kit; + QString hzToString(double freqHz); }; #endif // CALIBRATION_H diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp index 96ab4fb..08d7fb2 100644 --- a/Software/PC_Application/VNA/vna.cpp +++ b/Software/PC_Application/VNA/vna.cpp @@ -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:")); + auto cbEnableCal_label = new QLabel("Calibration:"); + tb_cal->addWidget(cbEnableCal_label); auto cbEnableCal = new QCheckBox; tb_cal->addWidget(cbEnableCal); auto cbType = new QComboBox(); @@ -326,6 +327,7 @@ VNA::VNA(AppWindow *window) cbEnableCal->blockSignals(true); calDisable->setChecked(true); cbEnableCal->setCheckState(Qt::CheckState::Unchecked); + cbEnableCal_label->setStyleSheet("background-color: yellow"); cbType->blockSignals(false); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(false); @@ -343,6 +345,7 @@ VNA::VNA(AppWindow *window) } } cbEnableCal->setCheckState(Qt::CheckState::Checked); + cbEnableCal_label->setStyleSheet(""); cbType->blockSignals(false); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(true); @@ -427,7 +430,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 { From 3fae95b33f1ff946ec40e7cd7e2b9aafa8e23c8b Mon Sep 17 00:00:00 2001 From: Zoran Kostic <60575976+nbgsmk@users.noreply.github.com> Date: Mon, 30 Nov 2020 18:16:33 +0100 Subject: [PATCH 2/3] Calibration - show in tooltip --- Software/PC_Application/Calibration/calibration.cpp | 6 ++++++ Software/PC_Application/Calibration/calibration.h | 5 +++++ Software/PC_Application/VNA/vna.cpp | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Software/PC_Application/Calibration/calibration.cpp b/Software/PC_Application/Calibration/calibration.cpp index 54f02c9..655f7ad 100644 --- a/Software/PC_Application/Calibration/calibration.cpp +++ b/Software/PC_Application/Calibration/calibration.cpp @@ -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 and show on widget return true; } @@ -741,6 +742,7 @@ 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 and show on widget return true; } @@ -770,6 +772,10 @@ QString Calibration::hzToString(double freqHz){ return res; } +QString Calibration::getCurrentCalibrationFile(){ + return this->currentCalFile; +} + ostream& operator<<(ostream &os, const Calibration &c) { for(auto m : c.measurements) { diff --git a/Software/PC_Application/Calibration/calibration.h b/Software/PC_Application/Calibration/calibration.h index 76e40b7..4e700ff 100644 --- a/Software/PC_Application/Calibration/calibration.h +++ b/Software/PC_Application/Calibration/calibration.h @@ -138,6 +138,11 @@ private: Calkit kit; QString hzToString(double freqHz); + +private: + QString currentCalFile; +public: + QString getCurrentCalibrationFile(); }; #endif // CALIBRATION_H diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp index 08d7fb2..c4cb26a 100644 --- a/Software/PC_Application/VNA/vna.cpp +++ b/Software/PC_Application/VNA/vna.cpp @@ -287,7 +287,7 @@ VNA::VNA(AppWindow *window) // Calibration toolbar (and populate calibration menu) auto tb_cal = new QToolBar("Calibration"); - auto cbEnableCal_label = new QLabel("Calibration:"); + QLabel *cbEnableCal_label = new QLabel("Calibration:"); tb_cal->addWidget(cbEnableCal_label); auto cbEnableCal = new QCheckBox; tb_cal->addWidget(cbEnableCal); @@ -328,6 +328,7 @@ VNA::VNA(AppWindow *window) calDisable->setChecked(true); cbEnableCal->setCheckState(Qt::CheckState::Unchecked); cbEnableCal_label->setStyleSheet("background-color: yellow"); + cbEnableCal_label->setToolTip("none"); cbType->blockSignals(false); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(false); @@ -346,6 +347,7 @@ VNA::VNA(AppWindow *window) } cbEnableCal->setCheckState(Qt::CheckState::Checked); cbEnableCal_label->setStyleSheet(""); + cbEnableCal_label->setToolTip(cal.getCurrentCalibrationFile()); cbType->blockSignals(false); cbEnableCal->blockSignals(false); calImportTerms->setEnabled(true); From 18526407fb683f8bc2831ff5dea730ba2d43cce2 Mon Sep 17 00:00:00 2001 From: Zoran Kostic <60575976+nbgsmk@users.noreply.github.com> Date: Mon, 30 Nov 2020 22:27:38 +0100 Subject: [PATCH 3/3] Calibration - minor changes --- Software/PC_Application/Calibration/calibration.cpp | 8 ++++---- Software/PC_Application/VNA/vna.cpp | 10 +++++----- Software/PC_Application/preferences.cpp | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Software/PC_Application/Calibration/calibration.cpp b/Software/PC_Application/Calibration/calibration.cpp index 655f7ad..312be66 100644 --- a/Software/PC_Application/Calibration/calibration.cpp +++ b/Software/PC_Application/Calibration/calibration.cpp @@ -709,7 +709,7 @@ bool Calibration::openFromFile(QString filename) qWarning() << "Calibration file parsing failed: " << e.what(); return false; } - this->currentCalFile = filename; // if all ok, remember this and show on widget + this->currentCalFile = filename; // if all ok, remember this return true; } @@ -717,7 +717,7 @@ bool Calibration::openFromFile(QString filename) bool Calibration::saveToFile(QString filename) { if(filename.isEmpty()) { - // suggest descriptive name + // Suggest descriptive name ie. "SOLT 40M-700M 1000pt" QString fn = Calibration::TypeToString(this->getType()) + " " + hzToString(minFreq) + "-" + hzToString(maxFreq) @@ -742,7 +742,7 @@ 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 and show on widget + this->currentCalFile = calibration_file; // if all ok, remember this return true; } @@ -750,7 +750,7 @@ bool Calibration::saveToFile(QString filename) /** * @brief Calibration::hzToString * @param freqHz - input frequency in Hz - * @return frequency in human-readable form such as 145k 2M, 2.1M, 3.45G + * @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 diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp index c4cb26a..8d41d61 100644 --- a/Software/PC_Application/VNA/vna.cpp +++ b/Software/PC_Application/VNA/vna.cpp @@ -287,7 +287,7 @@ VNA::VNA(AppWindow *window) // Calibration toolbar (and populate calibration menu) auto tb_cal = new QToolBar("Calibration"); - QLabel *cbEnableCal_label = 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); @@ -327,8 +327,8 @@ VNA::VNA(AppWindow *window) cbEnableCal->blockSignals(true); calDisable->setChecked(true); cbEnableCal->setCheckState(Qt::CheckState::Unchecked); - cbEnableCal_label->setStyleSheet("background-color: yellow"); - cbEnableCal_label->setToolTip("none"); + 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); @@ -346,8 +346,8 @@ VNA::VNA(AppWindow *window) } } cbEnableCal->setCheckState(Qt::CheckState::Checked); - cbEnableCal_label->setStyleSheet(""); - cbEnableCal_label->setToolTip(cal.getCurrentCalibrationFile()); + 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); diff --git a/Software/PC_Application/preferences.cpp b/Software/PC_Application/preferences.cpp index 6ca99dd..d1bc3b0 100644 --- a/Software/PC_Application/preferences.cpp +++ b/Software/PC_Application/preferences.cpp @@ -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()