From 9a945c156dfee142a3c9c27b1daee2225fc01711 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Fri, 20 Jul 2018 11:40:55 -0400 Subject: [PATCH] Proper SNR formatting +00 +30 -09 --- mainwindow.cpp | 19 +++++-------------- varicode.cpp | 9 ++++++++- varicode.h | 2 ++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index f9bfa79..45a626f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -214,13 +214,6 @@ namespace return QString {}; } - QString formatSNR(int snr){ - if(snr < -60 || snr > 60){ - return QString(); - } - return QString("%1%2").arg(snr >= 0 ? "+" : "").arg(snr); - } - void clearTableWidget(QTableWidget *widget){ if(!widget){ return; @@ -6857,16 +6850,14 @@ void MainWindow::on_snrMacroButton_clicked(){ if(!items.isEmpty()){ QString selectedCall = items.first()->text(); int snr = m_callActivity[selectedCall].snr; - QString text = QString("%1").arg(formatSNR(snr)); - addMessageText(text); + addMessageText(Varicode::formatSNR(snr)); return; } int offset = ui->RxFreqSpinBox->value(); if(m_bandActivity.contains(offset)){ int snr = m_bandActivity[offset].last().snr; - QString text = QString("%1").arg(snr); - addMessageText(text); + addMessageText(Varicode::formatSNR(snr)); return; } } @@ -8137,7 +8128,7 @@ void MainWindow::displayActivity(bool force){ auto offsetItem = new QTableWidgetItem(QString("%1").arg(offset)); ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 0, offsetItem); - auto snrItem = new QTableWidgetItem(QString("%1").arg(formatSNR(snr))); + auto snrItem = new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(snr))); snrItem->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); ui->tableWidgetRXAll->setItem(ui->tableWidgetRXAll->rowCount() - 1, 1, snrItem); @@ -8209,7 +8200,7 @@ void MainWindow::displayActivity(bool force){ ui->tableWidgetCalls->insertRow(ui->tableWidgetCalls->rowCount()); ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 0, new QTableWidgetItem(call)); ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 1, new QTableWidgetItem(QString("(%1)").arg(since(d.utcTimestamp)))); - ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 2, new QTableWidgetItem(QString("%1").arg(formatSNR(d.snr)))); + ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 2, new QTableWidgetItem(QString("%1").arg(Varicode::formatSNR(d.snr)))); ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, 3, new QTableWidgetItem(QString("%1").arg(d.grid))); auto distanceItem = new QTableWidgetItem(calculateDistance(d.grid)); @@ -8287,7 +8278,7 @@ void MainWindow::displayActivity(bool force){ if(d.cmd == "?"){ // standard FT8 reply // reply = QString("%1 %2 %3").arg(d.from).arg(m_config.my_callsign()).arg(d.snr); - reply = QString("%1 %2").arg(d.from).arg(d.snr); + reply = QString("%1 %2").arg(d.from).arg(Varicode::formatSNR(d.snr)); } // QTH else if(d.cmd == "@" && !isAllCall){ diff --git a/varicode.cpp b/varicode.cpp index aa58d42..22fd862 100644 --- a/varicode.cpp +++ b/varicode.cpp @@ -120,6 +120,13 @@ QMap basecalls = { { "ALLCALL", nbasecall + 3 }, }; +QString Varicode::formatSNR(int snr){ + if(snr < -60 || snr > 60){ + return QString(); + } + return QString("%1%2%3").arg(snr >= 0 ? "+" : "").arg(snr <= 9 && snr >= -9 ? "0" : "").arg(snr); +} + QStringList Varicode::parseCallsigns(QString const &input){ QStringList callsigns; QRegularExpression re(callsign_pattern2); @@ -616,7 +623,7 @@ QStringList Varicode::unpackDirectedMessage(const QString &text){ int num = (flag ? -1 : 1) * extra; if(num != -31){ - unpacked.append(QString(num > 0 ? "+%1" : "%1").arg(num)); + unpacked.append(Varicode::formatSNR(num)); } return unpacked; diff --git a/varicode.h b/varicode.h index 4299b6b..a1f8c89 100644 --- a/varicode.h +++ b/varicode.h @@ -27,6 +27,8 @@ public: //Varicode(); + static QString formatSNR(int snr); + static QStringList parseCallsigns(QString const &input); static QStringList parseGrids(QString const &input);