PrimarySubdivisions starts working

This commit is contained in:
d 2024-06-28 16:53:43 +02:00
parent 84c9b0d0e0
commit b25cd2f8d5
14 changed files with 238 additions and 44 deletions

View File

@ -707,8 +707,7 @@ bool DataBase::createDataBase()
return false;
}
if (!createTableSubdivision(true))
if (!createTablePrimarySubdivisions(true))
return false;
@ -968,8 +967,7 @@ bool DataBase::createTableAwardWAZ()
}
bool DataBase::createTableSubdivision(const bool NoTmp)
bool DataBase::createTablePrimarySubdivisions(const bool NoTmp)
{
// NoTmp = false => TMP data table to operate and be deleted afterwards
//qDebug() << Q_FUNC_INFO ;
@ -1027,6 +1025,53 @@ bool DataBase::createTableSubdivision(const bool NoTmp)
//qDebug() << Q_FUNC_INFO << " - END" ;
}
bool DataBase::populateTablePrimarySubdivisions(const bool NoTmp)
{
if (!doesEntityTablehaveData())
return false;
DB_ADIF_Primary_Subdvisions_data primarySubDivisions(Q_FUNC_INFO);
return primarySubDivisions.addData();
}
bool DataBase::recreateTablePrimarySubdivisions()
{
qDebug() << Q_FUNC_INFO ;
QSqlQuery query;
if (isTheTableExisting("primary_subdivisions"))
{
if (execQuery(Q_FUNC_INFO, "DROP TABLE primary_subdivisions"))
{
if (createTablePrimarySubdivisions(true))
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table created" ;
return populateTablePrimarySubdivisions(true);
}
else
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table NOT created" ;
}
}
else
{
return false;//qDebug() << Q_FUNC_INFO << ": execQuery FAILED" ;
}
}
else
{
if (createTablePrimarySubdivisions(true))
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table created" ;
return populateTablePrimarySubdivisions(true);
}
else
{
//qDebug() << Q_FUNC_INFO << ": primary_subdivisions table NOT created" ;
}
}
//qDebug() << Q_FUNC_INFO << ": END FALSE" ;
return false;
}
int DataBase::getBandIdFromName(const QString &b)
{
@ -2093,33 +2138,32 @@ bool DataBase::recreateSatelliteData()
{
if (createTableSatellites(true))
{
//qDebug() << "DataBase::recreateSatelliteData SAT table created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table created" ;
return populateTableSatellites(true);
}
else
{
//qDebug() << "DataBase::recreateSatelliteData SAT table NOT created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table NOT created" ;
}
}
else
{
//qDebug() << "DataBase::recreateSatelliteData execQuery FAILED" ;
//qDebug() << Q_FUNC_INFO << ": execQuery FAILED" ;
}
}
else
{
if (createTableSatellites(true))
{
//qDebug() << "DataBase::recreateSatelliteData SAT table created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table created" ;
return populateTableSatellites(true);
}
else
{
//qDebug() << "DataBase::recreateSatelliteData SAT table NOT created" ;
//qDebug() << Q_FUNC_INFO << ": SAT table NOT created" ;
}
}
//qDebug() << "DataBase::recreateSatelliteData END FALSE" ;
//qDebug() << Q_FUNC_INFO << ": END FALSE" ;
return false;
}
@ -2269,18 +2313,18 @@ bool DataBase::createTableLogs(const bool real)
{ // NoTmp = false => TMP data table to operate and be deleted afterwards
//Creating the Sats DB to be able to include satellites to the LOTW
//qDebug() << "DataBase::createTableLogs" ;
qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(real);
QString stringQuery = QString();
//QSqlQuery query;
if (real)
{
//qDebug() << "DataBase::createTableLogs - logs" ;
qDebug() << Q_FUNC_INFO << " - logs" ;
stringQuery = "CREATE TABLE logs" ;
}
else
{
//qDebug() << "DataBase::createTableLogs - logstemp" ;
qDebug() << Q_FUNC_INFO << " - logstemp" ;
stringQuery = "CREATE TABLE logstemp" ;
}
@ -2296,7 +2340,7 @@ bool DataBase::createTableLogs(const bool real)
//qDebug() << "DataBase::createTableLogs - END" ;
qDebug() << Q_FUNC_INFO << " - END" ;
return execQuery(Q_FUNC_INFO, stringQuery);
}
@ -4973,6 +5017,21 @@ bool DataBase::updateEntity (const QString &_codeString, const int _code)
return execQuery(Q_FUNC_INFO, sq);
}
bool DataBase::doesEntityTablehaveData()
{
QString sq = QString("SELECT COUNT(id) FROM entity");
QSqlQuery query;
if (!query.exec(sq))
return false;
else if(!query.next())
return false;
else if (!query.isValid())
return false;
return ((query.value(0)).toInt() > 0);
}
bool DataBase::isTheTableExisting(const QString &_tableName)
{
QSqlQuery query;
@ -5709,7 +5768,9 @@ bool DataBase::updateTo018()
// Now I am in the previous version and I can update the DB.
if (!createTableSubdivision(true))
//if (recreateTablePrimarySubdivisions())
// return false;
if (!createTablePrimarySubdivisions(true))
return false;
DB_ADIF_Primary_Subdvisions_data primarySubDivisions(Q_FUNC_INFO);
if (!primarySubDivisions.addData())

View File

@ -118,12 +118,14 @@ public:
int getNumberOfQsos(int _logNumber = -1);
int getLastInsertedQSO();
void setLogLevel (const DebugLogLevel _b);
bool populateTablePrimarySubdivisions(const bool NoTmp);
//private slots:
// void slotPrintErrors(QString _func, QString _msg, int _level);
private:
bool execQuery(const QString &function, const QString &stringQuery);
bool updateEntity (const QString &_codeString, const int _code);
bool doesEntityTablehaveData();
bool createDataBase();
bool setPragma(); // Defines the PRAGMA for the DB
bool isTheDBCreated();
@ -187,7 +189,9 @@ private:
bool recreateTableWAZ();
bool createTableAwardWAZ();
bool createTableSubdivision(const bool NoTmp);
bool createTablePrimarySubdivisions(const bool NoTmp);
bool recreateTablePrimarySubdivisions();
bool recreateSatelliteData();
bool createTableSatellites(const bool NoTmp);

View File

@ -29,11 +29,43 @@ bool DB_ADIF_Primary_Subdvisions_data::addData()
"FOREIGN KEY (dxcc) REFERENCES entity (dxcc) )");
*/
qDebug() << Q_FUNC_INFO << " - Checking if DB exists";
if (!isDBCreated())
return false;
if (!add_EA6_21())
qDebug() << Q_FUNC_INFO << " - Adding 6";
if (!add_USA_6()) // Adds the data for Alaska
return false;
return add_EA_281();
qDebug() << Q_FUNC_INFO << " - Adding 21";
if (!add_EA6_21()) // Adds the data for Balearic Is
return false;
qDebug() << Q_FUNC_INFO << " - Adding 29";
if (!add_EA8_29()) // Adds the data for Canary Is
return false;
qDebug() << Q_FUNC_INFO << " - Adding 32";
if (!add_EA9_32()) // Adds the data for Ceuta y Melilla
return false;
qDebug() << Q_FUNC_INFO << " - Adding 110";
if (!add_USA_110()) // Adds the data for Hawaii
return false;
qDebug() << Q_FUNC_INFO << " - Adding 149";
if (!add_CT_149()) // Adds the data for Azores
return false;
qDebug() << Q_FUNC_INFO << " - Adding 256";
if (!add_CT_256()) // Adds the data for Madeira
return false;
qDebug() << Q_FUNC_INFO << " - Adding 272";
if (!add_CT_272()) // Adds the data for Portugal
return false;
qDebug() << Q_FUNC_INFO << " - Adding 281";
if (!add_EA_281()) // Adds the data for Spain
return false;
qDebug() << Q_FUNC_INFO << " - Adding 291";
if (!add_USA_291()) // Adds the data for United States of America
return false;
return true;
}
bool DB_ADIF_Primary_Subdvisions_data::isDBCreated()
@ -52,7 +84,7 @@ bool DB_ADIF_Primary_Subdvisions_data::addValues(const QString &rows, const QStr
foreach (aux, values)
{
oneValue = QString("%1 (%2))").arg(sq).arg(aux);
oneValue = QString("%1 (%2)").arg(sq).arg(aux);
if (!exe.execQuery(Q_FUNC_INFO, oneValue))
return false;
}
@ -88,7 +120,7 @@ bool DB_ADIF_Primary_Subdvisions_data::add_EA6_21()
return addValues(rows, values);
}
bool DB_ADIF_Primary_Subdvisions_data::add_EA6_29()
bool DB_ADIF_Primary_Subdvisions_data::add_EA8_29()
{
// This function contains the Primary Subdivision data for Canary island
// Source of data is https://www.adif.org (version 3.1.4)
@ -105,7 +137,7 @@ bool DB_ADIF_Primary_Subdvisions_data::add_EA6_29()
return addValues(rows, values);
}
bool DB_ADIF_Primary_Subdvisions_data::add_EA6_32()
bool DB_ADIF_Primary_Subdvisions_data::add_EA9_32()
{
// This function contains the Primary Subdivision data for Ceuta & Melilla
// Source of data is https://www.adif.org (version 3.1.4)

View File

@ -54,8 +54,8 @@ private:
bool addValues(const QString &rows, const QStringList &values);
bool add_USA_6(); // Adds the data for Alaska
bool add_EA6_21(); // Adds the data for Balearic Is
bool add_EA6_29(); // Adds the data for Canary Is
bool add_EA6_32(); // Adds the data for Ceuta y Melilla
bool add_EA8_29(); // Adds the data for Canary Is
bool add_EA9_32(); // Adds the data for Ceuta y Melilla
bool add_EA_281(); // Adds the data for Spain
bool add_USA_110(); // Adds the data for Hawaii
bool add_CT_149(); // Adds the data for Azores

View File

@ -12,11 +12,10 @@ void QueryExecutor::queryErrorManagement(const QString &_functionFailed, const Q
Q_UNUSED(errorCodeS);
Q_UNUSED(_nativeError);
Q_UNUSED(_failedQuery);
//qDebug() << Q_FUNC_INFO << ": constrid : " << QString::number(constrid) ;
//qDebug() << Q_FUNC_INFO << ": Function : " << _functionFailed ;
//qDebug() << Q_FUNC_INFO << ": Native : " << _nativeError ;
//qDebug() << Q_FUNC_INFO << ": Error : " << _functionFailed << errorCodeS ;
//qDebug() << Q_FUNC_INFO << ": Query failed: " << _failedQuery ;
qDebug() << Q_FUNC_INFO << ": Function : " << _functionFailed ;
qDebug() << Q_FUNC_INFO << ": Native : " << _nativeError ;
qDebug() << Q_FUNC_INFO << ": Error : " << _functionFailed << errorCodeS ;
qDebug() << Q_FUNC_INFO << ": Query failed: " << _failedQuery ;
}
bool QueryExecutor::execQuery(const QString &function, const QString &stringQuery)

View File

@ -5595,10 +5595,54 @@ bool DataProxy_SQLite::addDXCCEntitySubdivision(const QString &_name, const QStr
query.finish();
return false;
}
//qDebug() << "DataProxy_SQLite::addDXCCEntitySubdivision: END" ;
//qDebug() << Q_FUNC_INFO << " - END" ;
return true;
}
QList<PrimarySubdivision> DataProxy_SQLite::getPrimarySubDivisions(const int _entity)
{ // Returns the Primary Subdivision for an Entity
qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_entity) ;
QList<PrimarySubdivision> list;
list.clear();
if (_entity<=0)
return list;
QString queryString = QString("SELECT name, shortname, cqz, ituz FROM primary_subdivisions WHERE dxcc = :dxcc");
QSqlQuery query;
query.prepare(queryString);
query.bindValue(":dxcc", _entity);
bool sqlOK = query.exec();
if (sqlOK)
{
while (query.next())
{
if (query.isValid())
{
PrimarySubdivision ps;
ps.name = (query.value(0)).toString();
ps.shortName = (query.value(1)).toString();
ps.cqz = (query.value(2)).toInt();
ps.ituz = (query.value(3)).toInt();
list.append(ps);
qDebug() << Q_FUNC_INFO << " : " << ps.name ;
}
}
}
else
{
emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().nativeErrorCode(), query.lastQuery());
list.clear();
}
query.finish();
qDebug() << Q_FUNC_INFO << " - END" ;
return list;
}
int DataProxy_SQLite::getNumberOfManagedLogs()
{
//qDebug() << "DataProxy_SQLite::getNumberOfManagedLogs";
@ -5868,7 +5912,7 @@ QString DataProxy_SQLite::getOperatorsFromLog(const int _log)
QString DataProxy_SQLite::getCommentsFromLog(const int _log)
{
//qDebug() << "DataProxy_SQLite::getLogDateFromLog: " << QString::number(_log)<< QT_ENDL;
qDebug() << Q_FUNC_INFO << ": " << QString::number(_log);
QSqlQuery query;
QString queryString = QString("SELECT comment FROM logs WHERE id='%1'").arg(_log);
bool sqlOK = query.exec(queryString);
@ -5878,14 +5922,14 @@ QString DataProxy_SQLite::getCommentsFromLog(const int _log)
query.next();
if (query.isValid())
{
//qDebug() << "DataProxy_SQLite::getCommentsFromLog: " << (query.value(0)).toString();
QString v = (query.value(0)).toString();
query.finish();
return v;
qDebug() << Q_FUNC_INFO << ": " << (query.value(0)).toString();
QString v = (query.value(0)).toString();
query.finish();
return v;
}
else
{
//qDebug() << "DataProxy_SQLite::getCommentsFromLog: Not valid";
qDebug() << Q_FUNC_INFO << ": Not valid";
query.finish();
return QString();
}
@ -5893,12 +5937,10 @@ QString DataProxy_SQLite::getCommentsFromLog(const int _log)
else
{
emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().nativeErrorCode(), query.lastQuery());
//qDebug() << "DataProxy_SQLite::getLogDateFromLog: query failed";
qDebug() << Q_FUNC_INFO << ": query failed";
query.finish();
return QString();
}
//qDebug() << "DataProxy_SQLite::getCommentsFromLog: END";
//return QString();
}
QString DataProxy_SQLite::getLogDateFromLog(const int _log)
@ -7768,6 +7810,12 @@ QString DataProxy_SQLite::getISOName(const int _n)
}
}
bool DataProxy_SQLite::addPrimarySubdivisions()
{
qDebug() << Q_FUNC_INFO;
return db->populateTablePrimarySubdivisions(true);
}
int DataProxy_SQLite::getPrefixId(const QString &_qrz)
{
//qDebug() << "DataProxy_SQLite::getPrefixId: -" << _qrz <<"-";

View File

@ -301,14 +301,15 @@ public:
bool addNewLog (const QStringList _qs);
bool doesThisLogExist(const int _log);
bool updateISONames(); // Update the entities ISO 3166names for the flags
bool updateISONames(); // Update the entities ISO 3166names for the flags
QString getISOName(const int _n);
bool addPrimarySubdivisions(); // Add the primary subdivisions to the BD
bool setDXCCAwardStatus(const int _qsoId);
bool setWAZAwardStatus(const int _qsoId);
//bool addRegionalAward(RegionalAward _regionalAward);
bool addDXCCEntitySubdivision(const QString &_name, const QString &_short, const QString &_pref, const QString &_group, const int _regId, const int _dxcc, const int _cq, const int _itu, const QDate &_startDate, const QDate &_endDate, const bool _deleted);
QList<PrimarySubdivision> getPrimarySubDivisions(const int _entity); // Get the Primary subdivisions for an entity
//void getFoundInLog(const QString &_txt, const int _log=-1);
KLOG_DEPRECATED QString getADIFQSO(const int _qsoId, ExportMode _em = ModeADIF);
QString getADIFValueFromRec(QSqlRecord _rec, const QString &_fieldName); // To refactor the getADIFFromQSOQuery function

View File

@ -114,7 +114,7 @@ void MainWindowInputOthers::createUI()
userDefinedADIFComboBox->setToolTip(tr("Select the appropriate ADIF field for this QSO."));
userDefinedADIFValueLineEdit->setToolTip (tr("Value for the selected ADIF field."));
entityPrimDivComboBox->setEnabled(false);
entityPrimDivComboBox->setEnabled(true);
entitySecDivComboBox->setEnabled(false);
entityNameComboBox->setEnabled(true);
propModeComboBox->setEnabled(true);
@ -235,6 +235,7 @@ void MainWindowInputOthers::setEntity(const int _ent)
//qDebug() << "MainWindow::selectCorrectEntity: " << pref << "/" << QString::number(indexC);
entityNameComboBox->setCurrentIndex(indexC);
setIOTAContinentFromEntity(_ent);
updatePrimarySubDivisions(_ent);
logEvent (Q_FUNC_INFO, "END", Debug);
}
@ -690,6 +691,35 @@ bool MainWindowInputOthers::setInitialADIFValues()
return true;
}
void MainWindowInputOthers::updatePrimarySubDivisions(const int _n)
{
qDebug() << Q_FUNC_INFO << " - Start";
if (_n<1)
return;
QList<PrimarySubdivision> subdivisions;
subdivisions.clear();
subdivisions.append(dataProxy->getPrimarySubDivisions(_n));
qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
if (subdivisions.count()<1)
return;
QStringList listOfSubdivisions;
listOfSubdivisions.clear();
foreach (PrimarySubdivision ps, subdivisions)
{
QString subdivision = ps.shortName + "-" + ps.name;
listOfSubdivisions.append(subdivision);
qDebug() << Q_FUNC_INFO << ": " << subdivision;
}
if (listOfSubdivisions.count()<1)
return;
entityPrimDivComboBox->clear();
entityPrimDivComboBox->addItems(listOfSubdivisions);
qDebug() << Q_FUNC_INFO << " - END";
}
void MainWindowInputOthers::slotUSerDefinedADIFComboBoxChanged()
{
//qDebug() << Q_FUNC_INFO << ": " << getUserADIFTypeComboBox ();

View File

@ -103,6 +103,7 @@ private:
void setColorsForUserDefinedADIFValueLineEdit();
bool checkVUCC_GRIDS(const QString &_string);
bool setInitialADIFValues();
void updatePrimarySubDivisions(const int _n);
bool getDarkMode();
void logEvent(const QString &_func, const QString &_msg, DebugLogLevel _level);

View File

@ -59,6 +59,13 @@ struct Coordinate {
double lon;
};
struct PrimarySubdivision { // Used to return data to MainWindow for each prefix
QString name;
QString shortName;
int cqz;
int ituz;
};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 2))
#define QT_SKIP Qt::SkipEmptyParts
#define QT_ENDL Qt::endl

View File

@ -915,6 +915,7 @@ void MainWindow::slotShowDXClusterAssistant()
}
void MainWindow::setMainWindowTitle()
{
qDebug() << Q_FUNC_INFO << " - Start";
QString aux = dataProxy->getCommentsFromLog(currentLog);
int numberOfQSOs = dataProxy->getHowManyQSOInLog (currentLog);
//qDebug() << Q_FUNC_INFO << " - (comment): " << aux ;
@ -2143,6 +2144,9 @@ void MainWindow::slotQRZTextChanged(QString _qrz)
showStatusOfDXCC(_entityStatus);
showDXMarathonNeeded(currentEntity, dx_CQz, mainQSOEntryWidget->getDate().year(), currentLog);
othersTabWidget->setIOTAContinentFromEntity(currentEntity);
// we need to update the list of Primary Subdivisions
}
else if ((dx_CQz == dxE_CQz) || (dx_ITUz == dxE_ITUz))
{
@ -3781,7 +3785,6 @@ void MainWindow::createUIDX()
dxUpLeftTab->addTab(eQSLTabWidget, tr("eQSL"));
dxUpLeftTab->addTab(commentTabWidget, tr("Comment"));
//othersTabWidget->setEntitiesList(world->getEntitiesNames());
othersTabWidget->setEntitiesList(dataProxy->getEntitiesNames());
dxUpLeftTab->addTab(othersTabWidget, tr("Others"));
@ -5110,7 +5113,7 @@ void MainWindow::slotFillEmptyDXCCInTheLog()
void MainWindow::slotUpdateCTYDAT()
{
//qDebug() << "MainWindow::slotUpdateCTYDAT" ;
qDebug() << "MainWindow::slotUpdateCTYDAT" ;
logEvent(Q_FUNC_INFO, "Start", Debug);
downloadcty->download();
logEvent(Q_FUNC_INFO, "END", Debug);

View File

@ -128,6 +128,7 @@ void SetupPageLogs::slotEditButtonClicked()
//qDebug() << "SetupPageLogs::slotEditButtonClicked";
newLog->setStationCallSign(dataProxy->getStationCallSignFromLog(selectedLog));
newLog->setOperators(dataProxy->getOperatorsFromLog(selectedLog));
qDebug() << Q_FUNC_INFO ;
newLog->setComment(dataProxy->getCommentsFromLog(selectedLog));
newLog->setDateString(dataProxy->getLogDateFromLog(selectedLog));
//newLog->setTypeN(dataProxy->getLogTypeNFromLog(selectedLog).toInt());

View File

@ -1228,6 +1228,8 @@ bool Utilities::isValidGrid(const QString &_b)
return locator.isValidLocator(_b);
}
bool Utilities::isValidGrid_ext(const QString &_b)
{// TODO: Implement the checks
// https://www.adif.org/314/ADIF_314.htm#QSO_Field_GRIDSQUARE_EXT

View File

@ -143,6 +143,7 @@ bool World::create(const QString &_worldFile)
created = false;
//qDebug() << Q_FUNC_INFO << " - FALSE" ;
}
//qDebug() << Q_FUNC_INFO << " - 30" ;
if (created)
{
@ -164,6 +165,10 @@ bool World::create(const QString &_worldFile)
}
//qDebug() << Q_FUNC_INFO << " - 80" ;
}
if (created)
{ // Let's add the Primary Subdivisions to the DB
created = dataProxy->addPrimarySubdivisions();
}
//qDebug() << Q_FUNC_INFO << " - 90" ;
readWorld ();
//qDebug() << Q_FUNC_INFO << " - END" ;