From 78a2415f62bc741e9afd4cb95f7edcf56d76d8aa Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Sun, 17 Dec 2023 19:11:36 +0100 Subject: [PATCH] Rig Widget: RIT/XIT are displayed with user-friendly units --- Changelog | 1 + data/Data.cpp | 32 ++++++++++++++++++++++++++++++++ data/Data.h | 3 +++ ui/RigWidget.cpp | 12 ++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 6de92611..133de3b2 100644 --- a/Changelog +++ b/Changelog @@ -12,6 +12,7 @@ TBC - 0.31.0 - [NEW] - Main Window - Current profile name is shown (issue #282) - [NEW] - Import - Details can be saved to file (issue #284) - [NEW] - Added Simplified Chinese translation (PR #285 thank BG7JAF) +- [NEW] - RIG Widget - RIT/XIT are displayed with user-friendly units. - Fixed Missing Satellite Mode SX (issue #291) 2023/12/01 - 0.30.0 diff --git a/data/Data.cpp b/data/Data.cpp index bef6e5da..a7ecc7a3 100644 --- a/data/Data.cpp +++ b/data/Data.cpp @@ -486,6 +486,38 @@ QString Data::dbFilename() return dir.filePath("qlog.db"); } +double Data::MHz2UserFriendlyFreq(double freqMHz, + QString &unit, + unsigned char &efectiveDecP) +{ + FCT_IDENTIFICATION; + + if ( freqMHz < 0.001 ) + { + unit = tr("Hz"); + efectiveDecP = 0; + return freqMHz * 1000000.0; + } + + if ( freqMHz < 1 ) + { + unit = tr("kHz"); + efectiveDecP = 3; + return freqMHz * 1000.0; + } + + if ( freqMHz >= 1000 ) + { + unit = tr("GHz"); + efectiveDecP = 3; + return freqMHz / 1000.0; + } + + unit = tr("MHz"); + efectiveDecP = 3; + return freqMHz; +} + QPair Data::legacyMode(const QString &mode) { FCT_IDENTIFICATION; diff --git a/data/Data.h b/data/Data.h index f057788c..bc6066b1 100644 --- a/data/Data.h +++ b/data/Data.h @@ -83,6 +83,9 @@ class Data : public QObject static int getCQZMin(); static int getCQZMax(); static QString dbFilename(); + static double MHz2UserFriendlyFreq(double, + QString &unit, + unsigned char &efectiveDecP); QStringList contestList() { return contests.values(); } QStringList propagationModesList() { return propagationModes.values(); } diff --git a/ui/RigWidget.cpp b/ui/RigWidget.cpp index 19e2d670..3ed194f1 100644 --- a/ui/RigWidget.cpp +++ b/ui/RigWidget.cpp @@ -147,7 +147,11 @@ void RigWidget::updateXIT(VFOID, double xit) if ( xit != 0.0 ) { ui->xitOffset->setVisible(true); - ui->xitOffset->setText(QString("XIT: %1 MHz").arg(QSTRING_FREQ(xit))); + QString unit; + unsigned char decP; + double xitDisplay = Data::MHz2UserFriendlyFreq(xit, unit, decP); + ui->xitOffset->setText(QString("XIT: %1 %2").arg(QString::number(xitDisplay, 'f', decP), + unit)); } else { @@ -162,7 +166,11 @@ void RigWidget::updateRIT(VFOID, double rit) if ( rit != 0.0 ) { ui->ritOffset->setVisible(true); - ui->ritOffset->setText(QString("RIT: %1 MHz").arg(QSTRING_FREQ(rit))); + QString unit; + unsigned char decP; + double ritDisplay = Data::MHz2UserFriendlyFreq(rit, unit, decP); + ui->ritOffset->setText(QString("RIT: %1 %2").arg(QString::number(ritDisplay, 'f', decP), + unit)); } else {