From 49d4838b8baaa4210f5635798b249fb832060896 Mon Sep 17 00:00:00 2001 From: ea4k Date: Fri, 31 Jan 2025 23:49:00 +0100 Subject: [PATCH] more refactor does not compile yet --- src/dataproxy_sqlite.cpp | 94 +--------------------- src/dataproxy_sqlite.h | 1 - src/dxccstatuswidget.cpp | 2 +- src/inputwidgets/mainwindowinputothers.cpp | 3 +- src/inputwidgets/mainwindowinputothers.h | 2 + src/world.cpp | 27 +++---- src/world.h | 1 + tests/tst_dataproxy/tst_dataproxy.cpp | 22 +---- 8 files changed, 21 insertions(+), 131 deletions(-) diff --git a/src/dataproxy_sqlite.cpp b/src/dataproxy_sqlite.cpp index b98cc1e5..b2ac1d84 100644 --- a/src/dataproxy_sqlite.cpp +++ b/src/dataproxy_sqlite.cpp @@ -6975,101 +6975,9 @@ QMap DataProxy_SQLite::getAllEntiNameISOAndPrefix() return entities; } -QStringList DataProxy_SQLite::getEntiNameISOAndPrefixFromIdBAK(const int _dxcc) -{ - //qDebug() << Q_FUNC_INFO << ": " << QString::number(_dxcc); - - if (_dxcc <= 0 ) - { - return QStringList(); - } - bool sqlOK; - QString queryString; - QSqlQuery query; - QString motherEntName = QString(); - if (_dxcc > 1000) - { - QString aux = (QString::number(_dxcc)).right(3); - QString queryString2 = QString("SELECT name FROM entity WHERE dxcc='%1'").arg(aux); - sqlOK = query.exec(queryString2); - - if (sqlOK) - { - if (query.next()) - { - if (query.isValid()) - { - motherEntName = (query.value(0)).toString(); - if (motherEntName.length ()<1) - { - return QStringList(); - } - } - } - } - else - { - emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().text(), query.lastQuery()); - query.finish (); - return QStringList(); - } - } - query.finish (); - - QStringList result; - result.clear(); - queryString = QString("SELECT mainprefix, name, isoname FROM entity WHERE dxcc='%1'").arg(_dxcc); - - sqlOK = query.exec(queryString); - - if (!sqlOK) - { - emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().text(), query.lastQuery()); - query.finish(); - return QStringList(); - } - else - { - query.next(); - - if (query.isValid()) - { - //queryString = (query.value(0)).toString(); - QString prefix = (query.value(0)).toString(); - QString name = (query.value(1)).toString(); - QString isoName = (query.value(2)).toString(); - query.finish(); - if (prefix.length ()<1) - { - return QStringList(); - } - if (name.length ()<1) - { - return QStringList(); - } - if ((_dxcc>1000) && (motherEntName.length ()>2)) - { - name = name + "(" + motherEntName + ")"; - } - if (isoName.length ()<2) - { - return QStringList(); - } - - result << prefix << name << isoName; - return result; - } - else - { - query.finish(); - return QStringList(); - } - } -} - QString DataProxy_SQLite::getEntityMainPrefix(const int _entityN) { - //qDebug() << "DataProxy_SQLite::getEntityMainPrefix:" << QString::number(_entityN); + //qDebug() << "DataProxy_SQLite::getEntityMainPrefix:" << QString::number(_entityN); if (_entityN <= 0 ) { diff --git a/src/dataproxy_sqlite.h b/src/dataproxy_sqlite.h index 18beccaf..e21e6121 100644 --- a/src/dataproxy_sqlite.h +++ b/src/dataproxy_sqlite.h @@ -205,7 +205,6 @@ class DataProxy_SQLite : public QObject QString getEntityMainPrefix(const int _entityN); QMap getAllEntiNameISOAndPrefix(); - KLOG_DEPRECATED QStringList getEntiNameISOAndPrefixFromIdBAK(const int _dxcc); int getEntityIdFromMainPrefix(const QString &_e); bool isNewCQz(int _c); bool isNewEntity(int _e); diff --git a/src/dxccstatuswidget.cpp b/src/dxccstatuswidget.cpp index ba9e1598..390c742e 100644 --- a/src/dxccstatuswidget.cpp +++ b/src/dxccstatuswidget.cpp @@ -501,7 +501,7 @@ void DXCCStatusWidget::refresh() if ((column == 0) || (column == 1)) { //tip = tr("Pref: ") + (dxccView->item(row, 1))->text() + " - "; - tip = tr("Pref: ") + dataProxy->getEntityMainPrefix(entiID) + " - "; + tip = tr("Pref: ") + world->getEntityMainPrefix(entiID) + " - "; tip = tip + tr("CQ: ") + QString::number(dataProxy->getCQzFromEntity(entiID)) + " - "; tip = tip + tr("ITU: ") + QString::number(dataProxy->getITUzFromEntity(entiID)) + " - "; QString dxLoc = locator->getLocator(dataProxy->getLongitudeFromEntity(entiID), dataProxy->getLatitudeFromEntity(entiID)) ; diff --git a/src/inputwidgets/mainwindowinputothers.cpp b/src/inputwidgets/mainwindowinputothers.cpp index e24f5677..76b141e4 100644 --- a/src/inputwidgets/mainwindowinputothers.cpp +++ b/src/inputwidgets/mainwindowinputothers.cpp @@ -35,6 +35,7 @@ MainWindowInputOthers::MainWindowInputOthers(DataProxy_SQLite *dp, QWidget *pare //qDebug() << Q_FUNC_INFO; logLevel = None; dataProxy = dp; + world = new World(dataProxy,Q_FUNC_INFO); util = new Utilities(Q_FUNC_INFO); //util->setLongPrefixes(dataProxy->getLongPrefixes()); @@ -799,7 +800,7 @@ void MainWindowInputOthers::setEntityAndPrefix(const int _entity, const QString if (callsign.isValid() || callsign.isValidPrefix()) currentPref = callsign.getHostFullPrefix(); - QString prefixFromEntityNumber = dataProxy->getEntityMainPrefix(_entity); // The main prefix of the entity. + QString prefixFromEntityNumber = world->getEntityMainPrefix(_entity); // The main prefix of the entity. QString hostFullPrefix = callsign.getHostFullPrefix(); // The default is that showAll is not checked. Main prefix+ the area QString hostPrefix = callsign.getHostPrefix(); // The default is that showAll is not checked diff --git a/src/inputwidgets/mainwindowinputothers.h b/src/inputwidgets/mainwindowinputothers.h index 93160eb4..11d6fc34 100644 --- a/src/inputwidgets/mainwindowinputothers.h +++ b/src/inputwidgets/mainwindowinputothers.h @@ -33,6 +33,7 @@ #include "../dataproxy_sqlite.h" #include "../utilities.h" #include "../klogdefinitions.h" +#include "../world.h" class MainWindowInputOthers : public QWidget { @@ -121,6 +122,7 @@ private slots: Utilities *util; DataProxy_SQLite *dataProxy; + World *world; QStringList entitiesList, propModeList; //QLabel *entityPrimLabel, *entitySecLabel, *iotaAwardLabel, *entityNameLabel, *propModeLabel; diff --git a/src/world.cpp b/src/world.cpp index 9c70ca44..25b54791 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -63,7 +63,7 @@ World::~World() bool World::readEntities() { - qDebug() << Q_FUNC_INFO << " - Start"; + //qDebug() << Q_FUNC_INFO << " - Start"; entities = dataProxy->getAllEntiNameISOAndPrefix(); if (entities.count()<1) return false; @@ -73,7 +73,7 @@ bool World::readEntities() // i.next(); // qDebug() << " - " << i.key().name; //} - qDebug() << Q_FUNC_INFO << " - END" ; + //qDebug() << Q_FUNC_INFO << " - END" ; return true; } @@ -91,6 +91,16 @@ EntityData World::getEntityDataFromDXCC(const int _dxcc) const return EntityData(); } + +QString World::getEntityMainPrefix(const int _dxcc) +{ + EntityData entity = getEntityDataFromDXCC(_dxcc); + Callsign prefix(entity.mainprefix); + if (prefix.isValidPrefix()) + return entity.mainprefix; + return QString(); +} + bool World::readWorld() { // Used to link a prefix with an Entity quickly, without quering the DB. //qDebug() << Q_FUNC_INFO << " - Start"; @@ -320,17 +330,6 @@ QString World::getQRZEntityMainPrefix(const QString &_qrz) return getEntityMainPrefix(i); } -QString World::getEntityMainPrefix(const int _entityN) -{ - //qDebug() << Q_FUNC_INFO << ": " << _entityN; - if (_entityN <= 0 ) - { - return QString(); - //return tr("NONE"); - } - return dataProxy->getEntityMainPrefix(_entityN); -} - bool World::isNewCQz(const int _cqz) { //qDebug() << Q_FUNC_INFO << ": " << _cqz; @@ -674,7 +673,7 @@ int World::extractEntityNumber(const QStringList &stringList) int entityNumber; if (stringList.at(0).contains(QChar('*'), Qt::CaseInsensitive)) { entityNumber = stringList.at(2).toInt() + 1000; - while (!dataProxy->getEntityMainPrefix(entityNumber).isEmpty()) { + while ( !(getEntityMainPrefix((entityNumber)).isEmpty())) { entityNumber += 1000; } } else { diff --git a/src/world.h b/src/world.h index 6415ed8e..eb7efd73 100644 --- a/src/world.h +++ b/src/world.h @@ -115,6 +115,7 @@ private slots: bool insertSpecialEntities(); bool readEntities(); // Read all the entities and fill entities QMap int getPrefixId(const QString &_prefix); + //bool readCTYDAT(); bool readCTYCSV(const QString &_worldFile); bool addEntity(const QString &_name, const int _cq, const int _itu, const int _contId, const double _lat, const double _lon, const double _utc, const int _dxcc, const QString &_mainpref); diff --git a/tests/tst_dataproxy/tst_dataproxy.cpp b/tests/tst_dataproxy/tst_dataproxy.cpp index 6abe3bc0..c8b97fe8 100644 --- a/tests/tst_dataproxy/tst_dataproxy.cpp +++ b/tests/tst_dataproxy/tst_dataproxy.cpp @@ -53,7 +53,7 @@ private slots: void test_modes_data(); void test_modes(); void test_bands(); - void test_EntityAndPrefixes(); // getEntityMainPrefix + //void test_EntityAndPrefixes(); // getEntityMainPrefix void test_continents(); void test_subdivisions_data(); @@ -206,26 +206,6 @@ void tst_DataProxy::test_bands() QVERIFY2(dataProxy->getNameFromBandId (dataProxy->getIdFromBandName ("20M")) == "20M", "Band names and Id failed"); } -void tst_DataProxy::test_EntityAndPrefixes() -{ // getEntityMainPrefix should return: - // EA -> EA (281) - // EA4 -> EA (281) - // EA8 -> EA8 - // K -> K - // W -> K - // W1 -> K - // K1 -> K - // KA7 -> K - // KH6 -> KH6 - - QVERIFY2(dataProxy->getEntityMainPrefix (29) == "EA8", "Main prefix for Canary Island (dxcc=29) failed"); - QVERIFY2(dataProxy->getEntityMainPrefix (110) == "KH6", "Main prefix for Hawaii (dxcc=110) failed"); - QVERIFY2(dataProxy->getEntityMainPrefix (281) == "EA", "Main prefix for Spain (dxcc=281) failed"); - QVERIFY2(dataProxy->getEntityMainPrefix (291) == "K", "Main prefix for the US (dxcc=291) failed"); - - -} - void tst_DataProxy::test_continents() { //qDebug() << Q_FUNC_INFO << ": Shortname 281: " << dataProxy->getContinentShortNameFromEntity (281);