Skip to content

Commit

Permalink
more refactor does not compile yet
Browse files Browse the repository at this point in the history
  • Loading branch information
ea4k committed Jan 31, 2025
1 parent 27db3cc commit 49d4838
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 131 deletions.
94 changes: 1 addition & 93 deletions src/dataproxy_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6975,101 +6975,9 @@ QMap<EntityData, int> 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 )
{
Expand Down
1 change: 0 additions & 1 deletion src/dataproxy_sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ class DataProxy_SQLite : public QObject
QString getEntityMainPrefix(const int _entityN);
QMap<EntityData, int> getAllEntiNameISOAndPrefix();

KLOG_DEPRECATED QStringList getEntiNameISOAndPrefixFromIdBAK(const int _dxcc);
int getEntityIdFromMainPrefix(const QString &_e);
bool isNewCQz(int _c);
bool isNewEntity(int _e);
Expand Down
2 changes: 1 addition & 1 deletion src/dxccstatuswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ;
Expand Down
3 changes: 2 additions & 1 deletion src/inputwidgets/mainwindowinputothers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/inputwidgets/mainwindowinputothers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../dataproxy_sqlite.h"
#include "../utilities.h"
#include "../klogdefinitions.h"
#include "../world.h"

class MainWindowInputOthers : public QWidget
{
Expand Down Expand Up @@ -121,6 +122,7 @@ private slots:

Utilities *util;
DataProxy_SQLite *dataProxy;
World *world;

QStringList entitiesList, propModeList;
//QLabel *entityPrimLabel, *entitySecLabel, *iotaAwardLabel, *entityNameLabel, *propModeLabel;
Expand Down
27 changes: 13 additions & 14 deletions src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 1 addition & 21 deletions tests/tst_dataproxy/tst_dataproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 49d4838

Please sign in to comment.