From 8516b746b1f5fd57362078cc7110721ab9e21fb5 Mon Sep 17 00:00:00 2001 From: d Date: Tue, 30 Apr 2024 19:40:02 +0200 Subject: [PATCH] Frequency work --- src/database.cpp | 2 - src/database.h | 9 -- src/dxcluster/dxcluster.cpp | 114 +++++--------------- src/dxcluster/dxcluster.h | 33 ++++-- src/dxcluster/dxclusterassistant.cpp | 9 -- src/dxcluster/dxclusterassistant.h | 13 ++- src/frequency.cpp | 87 ++++++++++++--- src/frequency.h | 19 +++- src/inputwidgets/mainwindowinputqso.cpp | 1 - src/mainwindow.cpp | 110 +++++++++---------- src/mainwindow.h | 2 +- tests/tests.pro | 1 + tests/tst_frequency/tst_frequency.cpp | 134 ++++++++++++++++++++++++ tests/tst_frequency/tst_frequency.pro | 29 +++++ 14 files changed, 362 insertions(+), 201 deletions(-) create mode 100644 tests/tst_frequency/tst_frequency.cpp create mode 100644 tests/tst_frequency/tst_frequency.pro diff --git a/src/database.cpp b/src/database.cpp index 457fc748..ba6a4c50 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -6649,9 +6649,7 @@ bool DataBase::updateAwardWAZTable() { //qDebug() << "DataBase::updateAwardWAZTable" ; QList dxccStatusList; - //QList dxccStatusListCheck; dxccStatusList.clear(); - //dxccStatusListCheck.clear(); AwarddxccEntry awardEntry; awardEntry.dxcc = QString(); diff --git a/src/database.h b/src/database.h index d27faf60..3c13e3c2 100644 --- a/src/database.h +++ b/src/database.h @@ -54,15 +54,6 @@ struct AwarddxccEntry QString qsoID; }; -struct AwarddxccEntryCheck -{ // Information to update the awarddxcc table; For other Award tables, the DXCC is just the ID of the award element - QString dxcc; - QString band; - QString mode; - QString status; - QString logNumber; -}; - class DataBase : public QObject { Q_OBJECT diff --git a/src/dxcluster/dxcluster.cpp b/src/dxcluster/dxcluster.cpp index c1824721..19e983c4 100644 --- a/src/dxcluster/dxcluster.cpp +++ b/src/dxcluster/dxcluster.cpp @@ -184,14 +184,13 @@ void DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked( QListWidgetIt { //qDebug() << Q_FUNC_INFO << item->text(); - DXSpot spot; QStringList ql; ql.clear(); if (!item) return; - spot = readItem(((item->data(0)).toString()).simplified()); + DXSpot spot = readItem(((item->data(0)).toString()).simplified()); if (!spot.valid) return; @@ -339,7 +338,7 @@ void DXClusterWidget::slotClusterDataArrived() QString dxCall; QString spotBand; Frequency freq; - DXSpot spot; + spotBand = "-1"; @@ -355,14 +354,17 @@ void DXClusterWidget::slotClusterDataArrived() dxClusterString = dxClusterString.trimmed(); // Remove BELL-string if exists dxClusterString = dxClusterString.remove("\a"); + qDebug() << Q_FUNC_INFO << ": Line: " << dxClusterString; + saveSpot(dxClusterString); - spot = readItem(dxClusterString); + DXSpot spot = readItem(dxClusterString); if (spot.valid) { + qDebug() << Q_FUNC_INFO << " - Spot IS valid"; _entityStatus.entityId = world->getQRZARRLId(dxCall); - spotBand = QString::number(dataProxy->getBandIdFromFreq(freq.toDouble()) ); + dxSpotColor = awards->getQRZDXStatusColor(_entityStatus); if (showDxMarathon) { @@ -374,6 +376,7 @@ void DXClusterWidget::slotClusterDataArrived() } else { + qDebug() << Q_FUNC_INFO << " - Spot IS NOT valid"; dxSpotColor = awards->getDefaultColor(); } @@ -396,10 +399,12 @@ void DXClusterWidget::slotClusterDataArrived() if (!spot.valid) return; + qDebug() << Q_FUNC_INFO << " - DXCall: " << spot.dxcall; qDebug() << Q_FUNC_INFO << " - Freq-string: " << freq.toQString(); qDebug() << Q_FUNC_INFO << " - Freq-double: " << QString::number(freq.toDouble()); qDebug() << Q_FUNC_INFO << " - Everything OK emitting..."; - emit dxspotArrived(spot.dxcall, freq); + + emit dxspotArrived(spot.dxcall, freq.toDouble()); } qDebug() << Q_FUNC_INFO << " - END"; @@ -553,16 +558,10 @@ void DXClusterWidget::slotClusterDXClusterWidgetItemSelected() { //qDebug() << Q_FUNC_INFO; QListWidgetItem * item = dxClusterListWidget->currentItem(); - DXSpot spot; - QStringList ql; - ql.clear(); - spot = readItem(((item->data(0)).toString()).simplified()); - if (ql.length()==2) - { - ql << "selected"; + DXSpot spot = readItem(((item->data(0)).toString()).simplified()); + if (spot.valid) emit dxspotclicked(spot); - } } void DXClusterWidget::slotClusterDXClusterWidgetItemEntered( QListWidgetItem * item ) @@ -571,13 +570,13 @@ void DXClusterWidget::slotClusterDXClusterWidgetItemEntered( QListWidgetItem * i /* This code comes from slotClusterDXClusterWidgetItemDoubleClicked */ - DXSpot spot; + QString tip; tip.clear(); if (item) { - spot = readItem(((item->data(0)).toString()).simplified()); + DXSpot spot = readItem(((item->data(0)).toString()).simplified()); if (spot.valid) { tip = world->getQRZEntityName(spot.dxcall); @@ -595,9 +594,11 @@ bool DXClusterWidget::isConnected() DXSpot DXClusterWidget::readItem(const QString _stringSpot) { - //qDebug() << Q_FUNC_INFO; - // Returns: dxSpot - DXSpot spot; + qDebug() << Q_FUNC_INFO; + + DXSpot spot = DXSpot(); + spot.valid = false; + if (_stringSpot.length()<5) return spot; Frequency _fr; @@ -612,6 +613,12 @@ DXSpot DXClusterWidget::readItem(const QString _stringSpot) if ( (fields.at(0) == "DX" ) && (fields.at(1) == "de" ) ) { // DX de EA0XXX: 21200.1 EA0K The comment 1550 qDebug() << Q_FUNC_INFO << ": Identified: DX de"; + qDebug() << Q_FUNC_INFO << ": 0: " << fields.at(0); + qDebug() << Q_FUNC_INFO << ": 1: " << fields.at(1); + qDebug() << Q_FUNC_INFO << ": 2: " << fields.at(2); + qDebug() << Q_FUNC_INFO << ": 3: " << fields.at(3); + qDebug() << Q_FUNC_INFO << ": 4: " << fields.at(4); + qDebug() << Q_FUNC_INFO << ": 5: " << fields.at(5); spot.spotter = fields.at(2); spot.freq.fromQString((fields.at(3)), KHz); spot.dxcall = fields.at(4); @@ -637,70 +644,6 @@ DXSpot DXClusterWidget::readItem(const QString _stringSpot) } return spot; - - /* - /////// NEW CODE - //int currentEntity; - QString dxCallsign, dxFreq; - - - if (!item) - return spot; - - fields.clear(); - dxClusterString = ((item->data(0)).toString()).simplified(); - fields << dxClusterString.split(" "); - - if ( (fields.at(0) == "DX" ) && (fields.at(1) == "de" ) ) - { // DX de EA0XXX: 21200.1 EA0K The comment 1550 - if ( world->getQRZARRLId(fields.at(4))> 0 ) - { - spot.dxcall = (fields.at(4)).toUpper(); - spot.freq().fromQString(fields.at(3), KHz); - if (spot.freq().isValid()) - { // The frecuency is valid - return spot; - } - else - { // the frecuency is not a number! - dxCallsign.clear(); - dxFreq.clear(); - fields.clear(); - } - } - else - { // The callsign is not from a valid country - // TODO: if it is from a new entity/prefix it would not work. - //qDebug() << Q_FUNC_INFO << " Entity not valid" ; - spot.dxcall = QString(); - spot.spotter = QString(); - spot.comment = QString(); - spot.freq().clear(); - } - } - //else if (( isAFrecuency(fields.at(0) ) ) && ( isACall(fields.at(1)) ) ) - else if ( (((fields.at(0)).toDouble()) > 0.0 )&& ( world->getQRZARRLId(fields.at(1))> 0 ) ) - { // 14205.0 EA0K 5-Mar-2012 1500Z - dxCallsign = (fields.at(1)).toUpper(); - dxFreq = fields.at(0); - fields.clear(); - fields << dxCallsign << dxFreq; - spot.dxcall = dxCallsign; - spot.freq().fromQString(dxFreq, KHz); - return spot; - } - else - { - spot.dxcall = QString(); - spot.spotter = QString(); - spot.comment = QString(); - spot.freq().clear(); - spot.clickStatus = NoClick; - spot.dateTime = QDateTime(); - } - - return spot; - */ } void DXClusterWidget::setDXClusterServer(const QString &clusterToConnect, const int portToConnect) @@ -758,16 +701,15 @@ void DXClusterWidget::slotRightButton(const QPoint& pos) //int row = (dxClusterListWidget->indexAt(pos)).row(); //qDebug() << Q_FUNC_INFO << " row: " << QString::number(row); QListWidgetItem * item = dxClusterListWidget->currentItem(); - DXSpot spot; - spot = readItem(((item->data(0)).toString()).simplified()); + DXSpot spot = readItem(((item->data(0)).toString()).simplified()); if ((spot.valid) && (spot.clickStatus == RightClick) ) { rightButtonFromLogMenu(spot); } } -void DXClusterWidget::rightButtonFromLogMenu(DXSpot _spot) +void DXClusterWidget::rightButtonFromLogMenu(const DXSpot &_spot) { // This function creates the context menu //qDebug() << Q_FUNC_INFO; diff --git a/src/dxcluster/dxcluster.h b/src/dxcluster/dxcluster.h index da807cb3..4ebab3c0 100644 --- a/src/dxcluster/dxcluster.h +++ b/src/dxcluster/dxcluster.h @@ -41,15 +41,26 @@ email : jaime@robles.es class QWidget; class QTcpSocket; +class Frequency; struct DXSpot { // Used to pass a list of data from Awards to dxccstatuswidget - QString dxcall = QString(); - Frequency freq = Frequency(); - QString spotter = QString(); - QString comment = QString(); - QDateTime dateTime = QDateTime(); - MouseClicks clickStatus = SingleClick; - bool valid = false; + QString dxcall; + Frequency freq; + QString spotter; + QString comment; + QDateTime dateTime; + MouseClicks clickStatus; + bool valid; + DXSpot() {valid = false;} + DXSpot(const DXSpot& other) { + dxcall = other.dxcall; + freq = other.freq; // Might need a copy constructor for Frequency as well + spotter = other.spotter; + comment = other.comment; + dateTime = other.dateTime; + clickStatus = other.clickStatus; + valid = other.valid; + } }; class DXClusterWidget : public QWidget @@ -72,7 +83,7 @@ class DXClusterWidget : public QWidget void loadSettings(); void setDXClusterServer(const QString &clusterToConnect, const int portToConnect); - void rightButtonFromLogMenu(DXSpot _spot); + void rightButtonFromLogMenu(const DXSpot &_spot); //void sendSpotToCluster(const QString &_dx, const QString &_freq); private slots: @@ -91,8 +102,8 @@ private slots: void slotCheckQRZCom(); signals: - void dxspotclicked(DXSpot _dxSpot); // DXSpotCall, DX-Freq, doubleClicked - void dxspotArrived(const QString &_call, Frequency _freq); + void dxspotclicked(const DXSpot &_dxSpot); // DXSpotCall, DX-Freq, doubleClicked + void dxspotArrived(const QString &_call, double _f); //void dxspot(const QString &_spot); // The text string to be saved private: @@ -101,7 +112,7 @@ private slots: void createActions(); void connectToDXCluster(); //QStringList readItem(QListWidgetItem * _stringSpot); - DXSpot readItem (const QString _stringSpot); + DXSpot readItem(const QString _stringSpot); bool checkIfNeedsToBePrinted(EntityStatus _entityStatus); void saveSpot (const QString &_spot); bool openFile(); diff --git a/src/dxcluster/dxclusterassistant.cpp b/src/dxcluster/dxclusterassistant.cpp index db1fe3ae..7923d55a 100644 --- a/src/dxcluster/dxclusterassistant.cpp +++ b/src/dxcluster/dxclusterassistant.cpp @@ -154,15 +154,6 @@ void DXClusterAssistant::addCall() tableWidget->setItem(row-1, 0, newItemCall); //tableWidget->setItem(row-1, 1, newItemFreq); tableWidget->setItem(row-1, 2, newItemStatus); - } //qDebug() << Q_FUNC_INFO << " - END"; } - -/* - QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( - (row+1)*(column+1))); - tableWidget->setItem(row, column, newItem); - - -*/ diff --git a/src/dxcluster/dxclusterassistant.h b/src/dxcluster/dxclusterassistant.h index b4d153eb..2e16d275 100644 --- a/src/dxcluster/dxclusterassistant.h +++ b/src/dxcluster/dxclusterassistant.h @@ -40,11 +40,14 @@ email : jaime@robles.es #include "../utilities.h" #include "../frequency.h" -struct proposedQSOs { // Used to pass a list of data from Awards to dxccstatuswidget - QString call = QString(); - Frequency freq; - int priority = -1; - QSOStatus status = unknown; +class Frequency; + +struct proposedQSOs +{ // Used to pass a list of data from Awards to dxccstatuswidget + QString call; + //Frequency freq; + int priority; + QSOStatus status; }; class DXClusterAssistant : public QWidget diff --git a/src/frequency.cpp b/src/frequency.cpp index b7a8d37c..2778e586 100644 --- a/src/frequency.cpp +++ b/src/frequency.cpp @@ -28,14 +28,25 @@ Frequency::Frequency(){} -Frequency::Frequency(const Frequency &_f) +Frequency::Frequency(Frequency *f){ + freq = f->freq; +} + +Frequency::Frequency(const double _f, FreqUnits _u) +{ + freq = normalize(_f, _u); +} +//Frequency::Frequency(const QString &_parentName){} + +/* + Frequency::Frequency(const QString &_parentName, const Frequency &_f) { if(this != &_f) { *this = _f; } } - +*/ Frequency::~Frequency(){} void Frequency::clear() @@ -72,26 +83,17 @@ bool Frequency::fromBand(const QString &_bandName) double Frequency::toDouble(FreqUnits _u) { - switch (_u) { - case Hz: - return freq * 1000000; - break; - case KHz: - return freq * 1000; - break; - default: - return freq; - break; - } + return deNormalize(freq, _u); } QString Frequency::toQString(int _decimals, FreqUnits _u) { double d = toDouble(_u); - qDebug() << Q_FUNC_INFO << ": " << QString::number(toDouble()); - qDebug() << Q_FUNC_INFO << ": " << QString::number(fmod(toDouble(), 1.0)); + int dec = getDecimals(_u); + //qDebug() << Q_FUNC_INFO << ": " << QString::number(toDouble()); + //qDebug() << Q_FUNC_INFO << ": " << QString::number(fmod(toDouble(), 1.0)); - return QString("%1").arg(d, 0, 'f', _decimals); + return QString("%1").arg(d, 0, 'f', dec); } double Frequency::normalize(const double _f, const FreqUnits _u) @@ -103,12 +105,63 @@ double Frequency::normalize(const double _f, const FreqUnits _u) case KHz: return _f / 1000; break; - default: + case GHz: + return _f * 1000; + break; + case THz: + return _f * 1000000; + break; + default: // Default is in MHz return _f; break; } } +double Frequency::deNormalize(const double _f, const FreqUnits _u) +{ // Convert MHz to other unit + switch (_u) { + case Hz: + return _f * 1000000; + break; + case KHz: + return _f * 1000; + break; + case GHz: + return _f / 1000; + break; + case THz: + return _f / 1000000; + break; + default: // Default is in MHz + return _f; + break; + } +} + +int Frequency::getDecimals(const FreqUnits _u) +{ // Get the right number of decimals to display + switch (_u) { + case Hz: + return 0; + break; + case KHz: + return 3; + break; + case MHz: + return 6; + break; + case GHz: + return 9; + break; + case THz: + return 12; + break; + default: // Default is in MHz + return 6; + break; + } +} + void Frequency::setTolerance(const double _t, FreqUnits _u) { if (_t<=0.0) diff --git a/src/frequency.h b/src/frequency.h index 905c0049..a14effbc 100644 --- a/src/frequency.h +++ b/src/frequency.h @@ -32,11 +32,18 @@ #include #include "klogdefinitions.h" -class Frequency: public QObject { + +class Frequency: public QObject +{ Q_OBJECT + friend class tst_Frequency; + public: Frequency(); - Frequency(const Frequency &_f); + Frequency(Frequency *f); + Frequency(const double _f, FreqUnits _u = MHz); + //Frequency(const QString &_parentName); + //Frequency(const QString &_parentName, const Frequency &_f); ~Frequency(); void clear(); bool fromDouble(const double _f, FreqUnits _u = MHz); @@ -45,14 +52,16 @@ class Frequency: public QObject { double toDouble(FreqUnits _u = MHz); // Returns in MHz QString toQString(int _decimals = 3, FreqUnits _u = MHz); // Returns in MHz with decimals void setTolerance(const double _t, FreqUnits _u = Hz); // Defines the tolerance - //QString band(); // Returns the band - //int bandId(); // Returns the bandId + //QString band(); // Returns the band + //int bandId(); // Returns the bandId bool isValid(); - void operator=(Frequency const &_f2); // Redefinition of = + void operator=(Frequency const &_f2); // Redefinition of = private: double normalize(const double _f, const FreqUnits _u = MHz); + double deNormalize(const double _f, const FreqUnits _u = MHz); + int getDecimals(const FreqUnits _u = MHz); double freq; // This must be in MHz QString bandInMHz; // double tolerance; // This must be in Hz diff --git a/src/inputwidgets/mainwindowinputqso.cpp b/src/inputwidgets/mainwindowinputqso.cpp index fa96a6fc..c06ed7d5 100644 --- a/src/inputwidgets/mainwindowinputqso.cpp +++ b/src/inputwidgets/mainwindowinputqso.cpp @@ -45,7 +45,6 @@ MainWindowInputQSO::MainWindowInputQSO(DataProxy_SQLite *dp, QWidget *parent) : rxFreqSpinBox = new QDoubleSpinBox; splitCheckBox = new QCheckBox; rxPowerSpinBox = new QDoubleSpinBox; - dataProxy = dp; createUI(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0934ee2f..8acb8c68 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -659,7 +659,7 @@ void MainWindow::createActionsCommon(){ //CLUSTER connect(dxClusterWidget, SIGNAL(dxspotclicked(DXSpot)), this, SLOT(slotAnalyzeDxClusterSignal(DXSpot) ) ); - connect(dxClusterWidget, SIGNAL(dxspotArrived(QString, Frequency)), this, SLOT(slotDXClusterSpotArrived(QString, Frequency) ) ); + connect(dxClusterWidget, SIGNAL(dxspotArrived(QString, double)), this, SLOT(slotDXClusterSpotArrived(QString, Frequency) ) ); // CLUBLOG connect (elogClublog, SIGNAL (showMessage(QString)), this, SLOT (slotElogClubLogShowMessage(QString))); @@ -1995,27 +1995,27 @@ void MainWindow::exitQuestion() void MainWindow::slotQRZTextChanged(QString _qrz) { - qDebug()<< Q_FUNC_INFO << ": " << _qrz ; + //qDebug()<< Q_FUNC_INFO << ": " << _qrz ; logEvent(Q_FUNC_INFO, QString("Start: %1").arg(_qrz), Debug); - qDebug()<< Q_FUNC_INFO << " - 10" ; + //qDebug()<< Q_FUNC_INFO << " - 10" ; if (_qrz.length()<1) { - qDebug()<< Q_FUNC_INFO << " - 11" ; + //qDebug()<< Q_FUNC_INFO << " - 11" ; infoLabel1->clear(); infoLabel2->clear(); slotClearButtonClicked(Q_FUNC_INFO); logEvent(Q_FUNC_INFO, "END-Empty", Devel); return; } - qDebug()<< Q_FUNC_INFO << " - 20" ; + //qDebug()<< Q_FUNC_INFO << " - 20" ; if (cleaning) { //qDebug()<< Q_FUNC_INFO << ": Cleaning" ; logEvent(Q_FUNC_INFO, "END-Cleaning", Devel); return; } - qDebug()<< Q_FUNC_INFO << " - 30" ; + //qDebug()<< Q_FUNC_INFO << " - 30" ; if (modify) { logEvent(Q_FUNC_INFO, "END-Modify", Devel); @@ -2031,7 +2031,7 @@ void MainWindow::slotQRZTextChanged(QString _qrz) logEvent(Q_FUNC_INFO, "END-Small QRZ, don't calculate", Devel); return; } - qDebug()<< Q_FUNC_INFO << " - 40" ; + //qDebug()<< Q_FUNC_INFO << " - 40" ; //qDebug()<< Q_FUNC_INFO << ": running ..." ; qrzSmallModDontCalculate = true; // A kind of flag to prevent multiple calls to this method. //int i; @@ -2047,7 +2047,7 @@ void MainWindow::slotQRZTextChanged(QString _qrz) //currentEntity = world->getQRZARRLId(pref); //validar por que no puedo tirar o usar el prefijo directamente currentEntity = world->getQRZARRLId(_qrz); - qDebug()<< Q_FUNC_INFO << " - 50" ; + //qDebug()<< Q_FUNC_INFO << " - 50" ; /* if (pref.length ()>0) { @@ -2065,7 +2065,7 @@ void MainWindow::slotQRZTextChanged(QString _qrz) dx_CQz = world->getQRZCqz(_qrz); dx_ITUz = world->getQRZItuz(_qrz); dxE_ITUz = world->getEntityItuz(currentEntity); - qDebug()<< Q_FUNC_INFO << " - 60" ; + //qDebug()<< Q_FUNC_INFO << " - 60" ; //qDebug()<< Q_FUNC_INFO << ": CQ: " << QString::number(dx_CQz) ; //qDebug()<< Q_FUNC_INFO << ": CQe: " << QString::number(dxE_CQz) ; //qDebug()<< Q_FUNC_INFO << ": ITU: " << QString::number(dx_ITUz) ; @@ -2087,7 +2087,7 @@ void MainWindow::slotQRZTextChanged(QString _qrz) _entityStatus.modeId = currentModeShown; _entityStatus.log = currentLog; - qDebug()<< Q_FUNC_INFO << ": 60 - currentEntity: " << QString::number(currentEntity) ; + //qDebug()<< Q_FUNC_INFO << ": 60 - currentEntity: " << QString::number(currentEntity) ; if ( locator->isValidLocator(QSOTabWidget->getDXLocator())) { dxLocator = QSOTabWidget->getDXLocator(); @@ -2097,18 +2097,18 @@ void MainWindow::slotQRZTextChanged(QString _qrz) dxLocator = world->getLocator(currentEntity); } - qDebug()<< Q_FUNC_INFO << ": Going to check the DXCC" ; - qDebug()<< Q_FUNC_INFO << ": current/previous" << QString::number(currentEntity) << "/" << QString::number(previousEntity) ; + //qDebug()<< Q_FUNC_INFO << ": Going to check the DXCC" ; + //qDebug()<< Q_FUNC_INFO << ": current/previous" << QString::number(currentEntity) << "/" << QString::number(previousEntity) ; if ( (currentEntity != previousEntity) || ((infoLabel2->text()).length() < 1) || (InValidCharsInPrevCall) || (dx_CQz != dxE_CQz) || (dx_ITUz != dxE_ITUz)) { - qDebug()<< Q_FUNC_INFO << ": currentEntity=" << QString::number(currentEntity) << "/previousEntity=" << QString::number(previousEntity) ; + //qDebug()<< Q_FUNC_INFO << ": currentEntity=" << QString::number(currentEntity) << "/previousEntity=" << QString::number(previousEntity) ; previousEntity = currentEntity; InValidCharsInPrevCall = false; infoLabel2->setText(world->getEntityName(currentEntity)); infoWidget->showEntityInfo(currentEntity, dx_CQz, dx_ITUz); infoWidget->showDistanceAndBearing(myDataTabWidget->getMyLocator(), dxLocator); - qDebug()<< Q_FUNC_INFO << ": 70"; + //qDebug()<< Q_FUNC_INFO << ": 70"; showStatusOfDXCC(_entityStatus); showDXMarathonNeeded(currentEntity, dx_CQz, mainQSOEntryWidget->getDate().year(), currentLog); @@ -2116,29 +2116,29 @@ void MainWindow::slotQRZTextChanged(QString _qrz) } else if ((dx_CQz == dxE_CQz) || (dx_ITUz == dxE_ITUz)) { - qDebug()<< Q_FUNC_INFO << ": 101" ; + //qDebug()<< Q_FUNC_INFO << ": 101" ; //slotShowInfoLabel(world->getEntityName(currentEntity), 2); infoLabel2->setText(world->getEntityName(currentEntity)); infoWidget->showEntityInfo(currentEntity, dx_CQz, dx_ITUz); } else { - qDebug()<< Q_FUNC_INFO << ": 110" ; + //qDebug()<< Q_FUNC_INFO << ": 110" ; } - qDebug()<< Q_FUNC_INFO << ": 120" ; + //qDebug()<< Q_FUNC_INFO << ": 120" ; qrzSmallModDontCalculate = false; // If the text has not been modified in this method - qDebug()<< Q_FUNC_INFO << ": 150 - cursorP at the end : " ; + //qDebug()<< Q_FUNC_INFO << ": 150 - cursorP at the end : " ; if (completeWithPrevious) { - qDebug()<< Q_FUNC_INFO << ": 160" ; + //qDebug()<< Q_FUNC_INFO << ": 160" ; completeWithPreviousQSO(_qrz); } - qDebug()<< Q_FUNC_INFO << ": 170" ; + //qDebug()<< Q_FUNC_INFO << ": 170" ; if (!modify) { - qDebug()<< Q_FUNC_INFO << ": 180" ; + //qDebug()<< Q_FUNC_INFO << ": 180" ; searchWidget->setCallToSearch(_qrz); //qDebug() << Q_FUNC_INFO << " qrz.length>2: " << _qrz; //qDebug() << Q_FUNC_INFO << " qrzcomActive: " << util->boolToQString (qrzcomActive); @@ -2154,10 +2154,10 @@ void MainWindow::slotQRZTextChanged(QString _qrz) //qDebug()<< Q_FUNC_INFO << ": 189 NOT checking QRZ.com"; } } - qDebug()<< Q_FUNC_INFO << ": 190" ; + //qDebug()<< Q_FUNC_INFO << ": 190" ; //qrzAutoChanging = false; logEvent(Q_FUNC_INFO, "END", Debug); - qDebug()<< Q_FUNC_INFO << ": END" ; + //qDebug()<< Q_FUNC_INFO << ": END" ; } void MainWindow::setCleaning(const bool _c) @@ -3171,52 +3171,52 @@ void MainWindow::slotSetup(const int _page) void MainWindow::openSetup(const int _page) { - qDebug() << Q_FUNC_INFO << ": " << QString::number(_page) ; + //qDebug() << Q_FUNC_INFO << ": " << QString::number(_page) ; logEvent(Q_FUNC_INFO, "Start", Debug); //int result = -1; - qDebug() << Q_FUNC_INFO << " - 000 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 000 - " << (QTime::currentTime()).toString("HH:mm:ss"); hamlib->stop(); - qDebug() << Q_FUNC_INFO << " - 001 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 001 - " << (QTime::currentTime()).toString("HH:mm:ss"); if (!needToEnd) { - qDebug() << Q_FUNC_INFO << " - 010 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 010 - " << (QTime::currentTime()).toString("HH:mm:ss"); logEvent(Q_FUNC_INFO, "Just before setData", Devel); - qDebug() << "MainWindow::openSetup - Just before setupDialog->exec-1" ; + //qDebug() << "MainWindow::openSetup - Just before setupDialog->exec-1" ; if (upAndRunning) { - qDebug() << Q_FUNC_INFO << " - 011 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 011 - " << (QTime::currentTime()).toString("HH:mm:ss"); setupDialog->setData(softwareVersion, _page, !configured); - qDebug() << Q_FUNC_INFO << " - 012 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 012 - " << (QTime::currentTime()).toString("HH:mm:ss"); } else { - qDebug() << Q_FUNC_INFO << " - 013 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 013 - " << (QTime::currentTime()).toString("HH:mm:ss"); setupDialog->setData(softwareVersion, 0, !configured); - qDebug() << Q_FUNC_INFO << " - 014 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 014 - " << (QTime::currentTime()).toString("HH:mm:ss"); } if ( (!configured) || (itIsANewversion) ) { - qDebug() << Q_FUNC_INFO << " - 015 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 015 - " << (QTime::currentTime()).toString("HH:mm:ss"); logEvent(Q_FUNC_INFO, "Just before SetupDialog->exec", Devel); itIsANewversion = false; //setupDialog->exec(); setupDialog->setModal(true); - qDebug() << Q_FUNC_INFO << " - 016 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 016 - " << (QTime::currentTime()).toString("HH:mm:ss"); setupDialog->show(); - qDebug() << Q_FUNC_INFO << " - 017 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 017 - " << (QTime::currentTime()).toString("HH:mm:ss"); // move part of this code to slotSetupDialogFinished logEvent(Q_FUNC_INFO, "Just after setupDialog->show", Devel); - qDebug() << "MainWindow::openSetup - Just after setupDialog->show" ; + //qDebug() << "MainWindow::openSetup - Just after setupDialog->show" ; } else { - qDebug() << Q_FUNC_INFO << " - 020 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 020 - " << (QTime::currentTime()).toString("HH:mm:ss"); logEvent(Q_FUNC_INFO, "No setupDialog->exec needed", Devel); - qDebug() << "MainWindow::openSetup - No setupDialog->show needed" ; + //qDebug() << "MainWindow::openSetup - No setupDialog->show needed" ; } } - qDebug() << Q_FUNC_INFO << " - 050 - " << (QTime::currentTime()).toString("HH:mm:ss"); + //qDebug() << Q_FUNC_INFO << " - 050 - " << (QTime::currentTime()).toString("HH:mm:ss"); //qDebug() << Q_FUNC_INFO << " - END"; logEvent(Q_FUNC_INFO, "END", Debug); } @@ -3465,8 +3465,8 @@ void MainWindow::slotOpenWiki() bool MainWindow::applySettings() { - qDebug() << Q_FUNC_INFO << " - Start"; - qDebug() << Q_FUNC_INFO << " - NewOneColor: " << newOneColor.name(QColor::HexRgb); + //qDebug() << Q_FUNC_INFO << " - Start"; + //qDebug() << Q_FUNC_INFO << " - NewOneColor: " << newOneColor.name(QColor::HexRgb); if ((useDefaultLogFileName) && (defaultADIFLogFile.length()>0)) { useDefaultLogFileName = true; @@ -4840,33 +4840,33 @@ void MainWindow::showStatusOfDXCC(EntityStatus _entityStatus) 2 - Worked 3 - Confirmed */ - qDebug() << Q_FUNC_INFO << " - 10"; + //qDebug() << Q_FUNC_INFO << " - 10"; if (_entityStatus.bandId <= 0) // is the status valid? { - qDebug() << Q_FUNC_INFO << " - 20"; + //qDebug() << Q_FUNC_INFO << " - 20"; infoWidget->clear(); slotShowInfoLabel("--"); //infoLabel1->setText("--"); logEvent(Q_FUNC_INFO, "END-1", Debug); - qDebug() << Q_FUNC_INFO << " - END-1" ; + //qDebug() << Q_FUNC_INFO << " - END-1" ; return; } - qDebug() << Q_FUNC_INFO << " - 30"; + //qDebug() << Q_FUNC_INFO << " - 30"; // Set the status bar with the appropriate message int status = awards->getDXStatus (_entityStatus); - qDebug() << Q_FUNC_INFO << " - " << QString::number(status) ; + //qDebug() << Q_FUNC_INFO << " - " << QString::number(status) ; QString message = awards->getDXStatusString(status); - qDebug() << Q_FUNC_INFO << " - 40"; + //qDebug() << Q_FUNC_INFO << " - 40"; slotShowInfoLabel(message); - qDebug() << Q_FUNC_INFO << " - 10"; + //qDebug() << Q_FUNC_INFO << " - 10"; //infoLabel1->setText(message); //infoWidget->showInfo((_qs.at(0)).toInt(), (_qs.at(1)).toInt(), (_qs.at(2)).toInt(), (_qs.at(3)).toInt() ); - qDebug() << Q_FUNC_INFO << " - 50"; + //qDebug() << Q_FUNC_INFO << " - 50"; infoWidget->showInfo(_entityStatus.entityId); - qDebug() << Q_FUNC_INFO << " - 51"; - qDebug() << Q_FUNC_INFO << " - END-2" ; + //qDebug() << Q_FUNC_INFO << " - 51"; + //qDebug() << Q_FUNC_INFO << " - END-2" ; logEvent(Q_FUNC_INFO, "END", Debug); } @@ -5332,10 +5332,10 @@ void MainWindow::slotAnalyzeDxClusterSignal(DXSpot _spot) logEvent(Q_FUNC_INFO, "END", Debug); } -void MainWindow::slotDXClusterSpotArrived(const QString _dxCall, Frequency _freq) +void MainWindow::slotDXClusterSpotArrived(const QString _dxCall, const double _freq) { qDebug() << Q_FUNC_INFO << ": " << _dxCall; - qDebug() << Q_FUNC_INFO << ": " << _freq.toQString(); + //qDebug() << Q_FUNC_INFO << ": " << _freq.toQString(); //(void)_dxCall; //(void)_freq; @@ -5345,10 +5345,10 @@ void MainWindow::slotDXClusterSpotArrived(const QString _dxCall, Frequency _freq proposedQSOs pQSO; pQSO.call = _dxCall; pQSO.status = ATNO; - pQSO.freq = _freq; + //pQSO.freq = _freq; dxClusterAssistant->newDXClusterSpot(pQSO); qDebug() << Q_FUNC_INFO << ": Calling assistant with DXCall Valid: " << _dxCall; - qDebug() << Q_FUNC_INFO << ": Calling assistant with Freq: " << _freq.toQString(); + //qDebug() << Q_FUNC_INFO << ": Calling assistant with Freq: " << _freq.toQString(); //dxClusterAssistant->newDXClusterSpot(_dxCall, ATNO, _freq.toDouble()); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 56c46113..03d503fa 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -262,7 +262,7 @@ private slots: // CLUSTER void slotAnalyzeDxClusterSignal(DXSpot _spot); - void slotDXClusterSpotArrived(const QString _dxCall, Frequency _freq); + void slotDXClusterSpotArrived(const QString _dxCall, const double _freq); // CLUSTER //CLUBLOG diff --git a/tests/tests.pro b/tests/tests.pro index e6eb6a9d..507ff9fc 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -3,6 +3,7 @@ SUBDIRS=\ tst_main \ tst_wizard \ tst_adif \ + tst_frequency \ tst_utilities \ tst_mainqsoentrywidget \ tst_mainwindowsattab \ diff --git a/tests/tst_frequency/tst_frequency.cpp b/tests/tst_frequency/tst_frequency.cpp new file mode 100644 index 00000000..48a9b9af --- /dev/null +++ b/tests/tst_frequency/tst_frequency.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + tst_Frequency.h - description + ------------------- + begin : Jan 2021 + copyright : (C) 2021 by Jaime Robles + email : jaime@robles.es + ***************************************************************************/ + +/**************************************************************************** + * This file is part of Testing suite of KLog. * + * * + * KLog is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * The testing suite of KLog is distributed in the hope that it will * + * be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with Testing suite of KLog. * + * If not, see . * + * * + *****************************************************************************/ + +#include +#include "../../src/frequency.h" +#include "../../src/klogdefinitions.h" +#include "QtTest/qtestcase.h" + + +class tst_Frequency : public QObject +{ + Q_OBJECT + +public: + tst_Frequency(); + ~tst_Frequency(); + +private slots: + void initTestCase(); //will be called before the first test function is executed. + //void initTestCase_data(); // will be called to create a global test data table. + void cleanupTestCase(); //will be called after the last test function was executed. + void test_Constructors(); + void test_Basic(); + void test_toDouble(); + void test_toQString(); + + +private: + Frequency *freq; + Frequency *freq2; +}; + +tst_Frequency::tst_Frequency() +{ + freq = new Frequency(); + freq2 = new Frequency(); +} + +tst_Frequency::~tst_Frequency(){} + +void tst_Frequency::initTestCase() +{ + //qDebug("Called before everything else."); +} + +void tst_Frequency::cleanupTestCase() +{ + //qDebug("Called after last test."); +} + +void tst_Frequency::test_Constructors() +{ + Frequency freq3(freq); + QVERIFY2(qFuzzyCompare(freq->toDouble(),freq3.toDouble()), "Freq assignment (freq) not working"); + Frequency freq4(7.090,MHz); + QVERIFY2(qFuzzyCompare(freq4.toDouble(),(double)7.090), "Freq assignment (double,unit) not working"); + Frequency freq5(7.091); + QVERIFY2(qFuzzyCompare(freq5.toDouble(),(double)7.091), "Freq assignment (double) not working"); +} + +void tst_Frequency::test_Basic() +{ //num FreqUnits {Hz, KHz, MHz, GHz, THz}; + freq->clear(); + QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)0.0), "Freq cleared"); + + freq->fromDouble(28.495); + freq2->clear(); + freq2 = freq; + QVERIFY2(qFuzzyCompare(freq->toDouble(),freq2->toDouble()), "Freq assignment (=) not working"); + QVERIFY2(freq2->isValid(), "Freq isValid not working"); + + + +} + +void tst_Frequency::test_toDouble() +{ + QVERIFY2(freq->fromDouble(14.195, MHz) == true, "Could not import the double from MHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(THz), (double)0.000014195), "Freq 14.195 in THz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(GHz), (double)0.014195), "Freq 14.195 in GHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)14.195), "Freq 14.195 in MHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(MHz),(double)14.195), "Freq 14.195 in MHz Stating MHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(KHz),(double)14195), "Freq 14.195 in KHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)14195000), "Freq 14.195in Hz"); + + QVERIFY2(freq->fromDouble(1.296, GHz) == true, "Could not import the double from GHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(GHz),(double)1.296), "Freq 1.296GHz in GHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(MHz),(double)1296.0), "Freq 1.296GHz in MHz stating MHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)1296.0), "Freq 1.296GHz in MHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(KHz),(double)1296000.0), "Freq 1.296GHz in KHz"); + QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)1296000000.0), "Freq 1.296GHz in Hz"); +} + +void tst_Frequency::test_toQString() +{ + Frequency freq1(21.295); + qDebug() << Q_FUNC_INFO << ": " << freq1.toQString(); + +} +/* + + bool fromQString(const QString &_f, FreqUnits _u = MHz); + QString toQString(int _decimals = 3, FreqUnits _u = MHz); // Returns in MHz with decimals + void setTolerance(const double _t, FreqUnits _u = Hz); // Defines the tolerance +*/ + +QTEST_APPLESS_MAIN(tst_Frequency) + +#include "tst_frequency.moc" + diff --git a/tests/tst_frequency/tst_frequency.pro b/tests/tst_frequency/tst_frequency.pro new file mode 100644 index 00000000..d12cfbed --- /dev/null +++ b/tests/tst_frequency/tst_frequency.pro @@ -0,0 +1,29 @@ +QT += testlib + + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +#QMAKE_CXXFLAGS += -Wall -Wextra -Werror +#QMAKE_CFLAGS += -Wall -Wextra -Werror + +HEADERS += \ + ../../src/frequency.h \ + ../../src/klogdefinitions.h + +SOURCES += tst_frequency.cpp \ + ../../src/frequency.cpp \ + + + +isEmpty(QMAKE_LRELEASE) { + win32|os2:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe + else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease + unix { + !exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease-qt5 } + } else { + !exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease } + } +}