diff --git a/src/awards.cpp b/src/awards.cpp
index 6270e550..a2d7927f 100644
--- a/src/awards.cpp
+++ b/src/awards.cpp
@@ -215,6 +215,7 @@ int Awards::getDXCCWorked(const int _logNumber)
else
{
//qDebug() << "Awards::getDXCCWorked: 0";
+ query.finish();
return 0;
}
}
@@ -259,6 +260,7 @@ int Awards::getWAZWorked(const int _logNumber)
}
else
{
+ query.finish();
return 0;
}
}
@@ -298,6 +300,7 @@ int Awards::getWAZConfirmed(const int _logNumber)
}
else
{
+ query.finish();
return 0;
}
}
@@ -316,7 +319,7 @@ bool Awards::isThisSpotConfirmed(const QStringList &_qs)
int Awards::getDXStatus (const QStringList &_qs)
{
- qDebug() << Q_FUNC_INFO<< ": Entity: " << _qs.at(0) << "/ Band: " << _qs.at(1) << "/ Mode: " << _qs.at(2) << "/ Log: " << _qs.at(3) << QT_ENDL;
+ //qDebug() << Q_FUNC_INFO<< ": Entity: " << _qs.at(0) << "/ Band: " << _qs.at(1) << "/ Mode: " << _qs.at(2) << "/ Log: " << _qs.at(3) << QT_ENDL;
// Receives: QStringList _qs;
//_qs << Entity << BandId << << ModeId << lognumber;
@@ -356,7 +359,7 @@ int Awards::getDXStatus (const QStringList &_qs)
*/
if (_qs.length() != 4 )
{
- qDebug() << Q_FUNC_INFO<< ": Length != 4, return -1";
+ //qDebug() << Q_FUNC_INFO<< ": Length != 4, return -1";
return -1;
}
@@ -367,10 +370,10 @@ int Awards::getDXStatus (const QStringList &_qs)
int _logNumber = _qs.at(3).toInt();
int dxccEntity = (_qs.at(0)).toInt();
- qDebug() << Q_FUNC_INFO<< ": dxccEntity: " << QString::number(dxccEntity);
+ //qDebug() << Q_FUNC_INFO<< ": dxccEntity: " << QString::number(dxccEntity);
if (dxccEntity<=0)
{
- qDebug() << Q_FUNC_INFO<< ": dxccEntity <= 0, return -1";
+ //qDebug() << Q_FUNC_INFO<< ": dxccEntity <= 0, return -1";
return -1;
}
@@ -378,7 +381,7 @@ int Awards::getDXStatus (const QStringList &_qs)
if ( (_mode==-1) || (manageModes==false))
{
checkingMode = false;
- qDebug() << Q_FUNC_INFO<< ": checkingMode = FALSE";
+ //qDebug() << Q_FUNC_INFO<< ": checkingMode = FALSE";
}
int wb = dxccStatusBand(dxccEntity, _band, _logNumber); //-1 error / 0 Not worked / 1 worked / 2 confirmed
@@ -394,13 +397,13 @@ int Awards::getDXStatus (const QStringList &_qs)
checkingMode = false;
}
- qDebug() << Q_FUNC_INFO<< ": wb=" << QString::number(wb) << " - wm=" << QString::number(wm);
- qDebug() << Q_FUNC_INFO<< ": dxccStatus: " << QString::number(dxccStatus(dxccEntity, _logNumber));
+ //qDebug() << Q_FUNC_INFO<< ": wb=" << QString::number(wb) << " - wm=" << QString::number(wm);
+ //qDebug() << Q_FUNC_INFO<< ": dxccStatus: " << QString::number(dxccStatus(dxccEntity, _logNumber));
switch(dxccStatus(dxccEntity, _logNumber))
{
case 0:
- qDebug() << Q_FUNC_INFO<< ": return 0";
+ //qDebug() << Q_FUNC_INFO<< ": return 0";
return 0; // ATNO
//break;
case 1: // Worked, not confirmed
@@ -411,18 +414,18 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wm==1)
{
- qDebug() << Q_FUNC_INFO<< ": return 4";
+ //qDebug() << Q_FUNC_INFO<< ": return 4";
return 4;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 1";
+ //qDebug() << Q_FUNC_INFO<< ": return 1";
return 1;
}
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 4 nc";
+ //qDebug() << Q_FUNC_INFO<< ": return 4 nc";
return 4;
}
case 1: // Worked in this band
@@ -430,23 +433,23 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wm==1)
{
- qDebug() << Q_FUNC_INFO<< ": return 3";
+ //qDebug() << Q_FUNC_INFO<< ": return 3";
return 3;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 2";
+ //qDebug() << Q_FUNC_INFO<< ": return 2";
return 2;
}
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 3 nc";
+ //qDebug() << Q_FUNC_INFO<< ": return 3 nc";
return 3;
}
default: // ERROR
- qDebug() << Q_FUNC_INFO<< ": default return -1 - 1";
+ //qDebug() << Q_FUNC_INFO<< ": default return -1 - 1";
return -1;
}
case 2: // Confirmed
@@ -456,23 +459,23 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wm==2)
{
- qDebug() << Q_FUNC_INFO<< ": return 13";
+ //qDebug() << Q_FUNC_INFO<< ": return 13";
return 13;
}
else if (wm==1)
{
- qDebug() << Q_FUNC_INFO<< ": return 12";
+ //qDebug() << Q_FUNC_INFO<< ": return 12";
return 12;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 11";
+ //qDebug() << Q_FUNC_INFO<< ": return 11";
return 11;
}
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 13 nc";
+ //qDebug() << Q_FUNC_INFO<< ": return 13 nc";
return 13;
}
}
@@ -484,12 +487,12 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wm==1)
{
- qDebug() << Q_FUNC_INFO<< ": return 8";
+ //qDebug() << Q_FUNC_INFO<< ": return 8";
return 8;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 6";
+ //qDebug() << Q_FUNC_INFO<< ": return 6";
return 6;
}
}
@@ -497,12 +500,12 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wm==1)
{
- qDebug() << Q_FUNC_INFO<< ": return 7";
+ //qDebug() << Q_FUNC_INFO<< ": return 7";
return 7;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 5";
+ //qDebug() << Q_FUNC_INFO<< ": return 5";
return 5;
}
}
@@ -511,26 +514,26 @@ int Awards::getDXStatus (const QStringList &_qs)
{
if (wb==0)
{
- qDebug() << Q_FUNC_INFO<< ": return 7 nc";
+ //qDebug() << Q_FUNC_INFO<< ": return 7 nc";
return 7;
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return 8 nc";
+ //qDebug() << Q_FUNC_INFO<< ": return 8 nc";
return 8;
}
}
}
else
{
- qDebug() << Q_FUNC_INFO<< ": return -1 - 2";
+ //qDebug() << Q_FUNC_INFO<< ": return -1 - 2";
return -1;
}
default:
- qDebug() << Q_FUNC_INFO<< ": return -1 default2";
+ //qDebug() << Q_FUNC_INFO<< ": return -1 default2";
return -1;
} // END OF SWITCH
- qDebug() << Q_FUNC_INFO<< ": END, return -1";
+ //qDebug() << Q_FUNC_INFO<< ": END, return -1";
//return -1;
}
@@ -740,10 +743,10 @@ int Awards::dxccStatus(const int _ent, const int _logNumber)
QColor Awards::getQRZDXStatusColor(const QStringList &_qs)
{
//qs << Entity << spotBand << "-1" << QString::number(currentLog) ;
- qDebug() << Q_FUNC_INFO<< ": qs.length: " << QString::number(_qs.length());
+ //qDebug() << Q_FUNC_INFO<< ": qs.length: " << QString::number(_qs.length());
//From Search QSO to QSL: q << _call << bandid << _mode << QString::number(currentLog);
- qDebug() << Q_FUNC_INFO<< ": " << _qs.at(0) << "/" << _qs.at(1) << "/" << _qs.at(2) << _qs.at(3);
+ //qDebug() << Q_FUNC_INFO<< ": " << _qs.at(0) << "/" << _qs.at(1) << "/" << _qs.at(2) << _qs.at(3);
// Receives: QStringList _qs;
//_qs << Entity << BandID << ModeId << lognumber;
@@ -758,69 +761,69 @@ QColor Awards::getQRZDXStatusColor(const QStringList &_qs)
int status = getDXStatus(_qs);
- qDebug() << Q_FUNC_INFO<< ": status: " << QString::number(status) << "/" << getDXStatusString(status);
- qDebug() << Q_FUNC_INFO<< ": status: " << QString::number(status);
+ //qDebug() << Q_FUNC_INFO<< ": status: " << QString::number(status) << "/" << getDXStatusString(status);
+ //qDebug() << Q_FUNC_INFO<< ": status: " << QString::number(status);
switch (status) {
case 0:
- qDebug() << Q_FUNC_INFO<< ": returning newOneColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning newOneColor";
returnedColor = newOneColor;
break;
case 1:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 2:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 3:
- qDebug() << Q_FUNC_INFO<< ": returning workedColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning workedColor";
returnedColor = workedColor;
break;
case 4:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 5:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 6:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 7:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 8:
- qDebug() << Q_FUNC_INFO<< ": returning workedColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning workedColor";
returnedColor = workedColor;
break;
case 9:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 10:
- qDebug() << Q_FUNC_INFO<< ": returning workedColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning workedColor";
returnedColor = workedColor;
break;
case 11:
- qDebug() << Q_FUNC_INFO<< ": returning neededColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning neededColor";
returnedColor = neededColor;
break;
case 12:
- qDebug() << Q_FUNC_INFO<< ": returning workedColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning workedColor";
returnedColor = workedColor;
break;
case 13:
- qDebug() << Q_FUNC_INFO<< ": returning confirmedColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning confirmedColor";
returnedColor = confirmedColor;
break;
//break;
default:
- qDebug() << Q_FUNC_INFO<< ": returning defaultColor";
+ //qDebug() << Q_FUNC_INFO<< ": returning defaultColor";
returnedColor = defaultColor;
break;
}
@@ -1148,7 +1151,7 @@ Returns a valid format IOTA if possible and "" in other cases.
void Awards::setColors (const QString &_newOne, const QString &_needed, const QString &_worked, const QString &_confirmed, const QString &_default)
{
- qDebug() << Q_FUNC_INFO << ": " << _newOne << "/" << _needed << "/" << _worked << "/" << _confirmed << "/" << _default;
+ //qDebug() << Q_FUNC_INFO << ": " << _newOne << "/" << _needed << "/" << _worked << "/" << _confirmed << "/" << _default;
defaultColor = QColor(_default.toUpper());
neededColor = QColor(_needed.toUpper());
@@ -1831,6 +1834,7 @@ bool Awards::updateDXCCBandsStatus(const int _logNumber)
if (query.value(0).toInt()==0)
{
//qDebug() << Q_FUNC_INFO << " - Returning false for: QSOid" << QString::number(query.value(4).toInt());
+ query.finish();
return false;
}
ent.dxcc = query.value(0).toInt();
@@ -1872,14 +1876,6 @@ bool Awards::updateDXCCBandsStatus(const int _logNumber)
{
//qDebug() << Q_FUNC_INFO << ": dxccStatusList length <1 ";
}
- else if(qsos>0)
- {
- //qDebug() << Q_FUNC_INFO << ": qsos>0 ";
- }
- else
- {
- //qDebug() << Q_FUNC_INFO << ": ELSE";
- }
//qDebug() << Q_FUNC_INFO << ": dxccStatusList length: " << QString::number(dxccStatusList.length ()) ;
//qDebug() << Q_FUNC_INFO << ": QSOs: " << QString::number(qsos) ;
diff --git a/src/awardswidget.cpp b/src/awardswidget.cpp
index 2e357733..dae374f6 100644
--- a/src/awardswidget.cpp
+++ b/src/awardswidget.cpp
@@ -315,7 +315,7 @@ void AwardsWidget::slotOperatingYearComboBoxChanged()
void AwardsWidget::showAwards()
{ // Updates and show all the award status tab.
- //qDebug() << "AwardsWidget::showAwards";
+ //qDebug() << Q_FUNC_INFO << " - Start";
/*
WAZ
Local
@@ -358,7 +358,7 @@ void AwardsWidget::showAwards()
showDXMarathon(selectedYear);
emit debugLog(Q_FUNC_INFO, "END", logLevel);
- //qDebug() << "AwardsWidget::showAwards - END";
+ qDebug() << Q_FUNC_INFO << " - END";
}
void AwardsWidget::showDXMarathon(const int _year)
diff --git a/src/database.cpp b/src/database.cpp
index fa560e0f..ece21525 100644
--- a/src/database.cpp
+++ b/src/database.cpp
@@ -44,7 +44,8 @@ DataBase::DataBase(const QString &_parentClass, const QString &_DBName)
//db = QSqlDatabase::database();
dbVersion = DBVersionf;
- createConnection(QString(Q_FUNC_INFO)+"1");
+ if (!createConnection(QString(Q_FUNC_INFO)+"1"))
+ return;
//qDebug() << "DataBase::DataBase: PLAIN - connection Name: " << dbConnectionName ;
//qDebug() << "DataBase::DataBase: PLAIN - DB Name: " << db.databaseName() ;
insertPreparedQueries.clear();
@@ -71,7 +72,8 @@ DataBase::DataBase(const QString &_parentClass, const QString &_softVersion, con
if (util->getVersionDouble()>0)
{
- createConnection(QString(Q_FUNC_INFO)+"2");
+ if (!createConnection(QString(Q_FUNC_INFO)+"2"))
+ return;
}
//qDebug() << "DataBase::DataBase: - connection Name: " << dbConnectionName ;
//qDebug() << "DataBase::DataBase: - DB Name: " << db.databaseName() ;
@@ -104,7 +106,9 @@ QString DataBase::getSoftVersion()
if (query.isValid())
{
logEvent(Q_FUNC_INFO, "END-1", Debug);
- return (query.value(0)).toString();
+ QString aux = (query.value(0)).toString();
+ query.finish();
+ return aux;
}
else
{
@@ -136,7 +140,9 @@ QString DataBase::getDBVersion()
if (query.isValid())
{
logEvent(Q_FUNC_INFO, "END-1", Debug);
- return QString::number((query.value(0)).toDouble(), 'f', 3);
+ QString aux = QString::number((query.value(0)).toDouble(), 'f', 3);
+ query.finish();
+ return aux;
}
else
{
@@ -287,8 +293,8 @@ bool DataBase::createConnection(const QString &function, bool newDB)
query.exec(stringQuery);
stringQuery ="PRAGMA main.cache_size=10000;";
query.exec(stringQuery);
- stringQuery ="PRAGMA main.locking_mode=EXCLUSIVE;";
- query.exec(stringQuery);
+ //stringQuery ="PRAGMA main.locking_mode=EXCLUSIVE;";
+ //query.exec(stringQuery);
stringQuery ="PRAGMA main.synchronous=NORMAL;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.journal_mode=WAL;";
@@ -303,6 +309,7 @@ bool DataBase::createConnection(const QString &function, bool newDB)
//query.exec(stringQuery);
stringQuery ="PRAGMA case_sensitive_like=OFF;";
query.exec(stringQuery);
+ query.finish();
}
}
}
@@ -362,7 +369,7 @@ bool DataBase::isTheDBCreated()
{
//qDebug() << "DataBase::isTheDBCreated - not valid" ;
//qDebug() << "DataBase::isTheDBCreated: ------------------------------------------------- END FALSE-2" ;
- query.finish();
+ query.finish();
logEvent(Q_FUNC_INFO, "END-3", Debug);
return false;
}
@@ -863,7 +870,7 @@ bool DataBase::createDataBase()
//TODO: Awards are deprecated
execQuery(Q_FUNC_INFO, "INSERT INTO award_enumeration (name) VALUES ('AJA')");
execQuery(Q_FUNC_INFO, "INSERT INTO award_enumeration (name) VALUES ('CQDX')");
- execQuery(Q_FUNC_INFO, "INSERT INTO award_enumeration (nname) VALUES ('CQDXFIELD')");
+ execQuery(Q_FUNC_INFO, "INSERT INTO award_enumeration (name) VALUES ('CQDXFIELD')");
execQuery(Q_FUNC_INFO, "INSERT INTO award_enumeration (name) VALUES ('DXCC')");
execQuery(Q_FUNC_INFO, "INSERT INTO qso_complete_enumeration (shortname, name) VALUES ('Y', 'Yes')");
@@ -886,16 +893,18 @@ bool DataBase::recreateTableDXCC()
{
logEvent(Q_FUNC_INFO, "Start", Debug);
QSqlQuery query ("DROP TABLE awarddxcc");
+
if (!query.exec())
{
qDebug() << Q_FUNC_INFO << ": awarddxcc NOT dropped";
+ qDebug() << Q_FUNC_INFO << ": " << query.lastQuery();
+ qDebug() << Q_FUNC_INFO << ": " << query.lastError();
+ query.finish();
+ return false;
}
+ query.finish();
+ return createTableAwardDXCC();
- if (execQuery(Q_FUNC_INFO, "DROP TABLE awarddxcc"))
- {
- logEvent(Q_FUNC_INFO, "END-1", Debug);
- return createTableAwardDXCC();
- }
logEvent(Q_FUNC_INFO, "END", Debug);
return true;
}
@@ -1066,7 +1075,9 @@ int DataBase::getModeIdFromName(const QString &b)
if ( query.isValid() )
{
//qDebug() << "DataBase::getModeIdFromName: OK" << QString::number((query.value(0)).toInt()) ;
- return (query.value(0)).toInt();
+ int i = (query.value(0)).toInt();
+ query.finish();
+ return i;
}
else
{
@@ -5434,7 +5445,6 @@ bool DataBase::hasTheTableData(const QString &_tableName)
//qDebug() << "DataBase::hasTheTableData" << _tableName ;
QSqlQuery query;
-
QString stringQuery = QString("SELECT count(id) FROM %1").arg(_tableName);
bool sqlOK = query.exec(stringQuery);
@@ -5543,7 +5553,7 @@ bool DataBase::updateTo011()
if (!recreateTableDXCC())
{
- //qDebug() << "DataBase::updateTo011: - recreateTableDXCC NOK " ;
+ //qDebug() << "DataBase::updateTo011: - recreateTable DXCC NOK " ;
// emit debugLog(Q_FUNC_INFO, "3", 7);
return false;
}
@@ -7076,26 +7086,6 @@ void DataBase::queryErrorManagement(const QString &_functionFailed, const QStrin
qDebug() << Q_FUNC_INFO << ": Query failed: " << _failedQuery ;
}
-/*
- bool DataBase::beginTransaction()
- {
- //qDebug() << "DataBase::beginTransaction: " ;
- QSqlDatabase db = QSqlDatabase::database();
- db.setDatabaseName(dbName);
- return execQuery(Q_FUNC_INFO, "BEGIN IMMEDIATE TRANSACTION");
- }
-
-
- bool DataBase::commitTransaction()
-
-
- {
- //qDebug() << "DataBase::commitTransaction: " ;
- return db.commit();
- }
-
-*/
-
bool DataBase::execQuery(const QString &function, const QString &stringQuery)
{
//qDebug() << "DataBase::execQuery: " << function << " : " << stringQuery ;
@@ -7108,7 +7098,7 @@ void DataBase::queryErrorManagement(const QString &_functionFailed, const QStrin
qDebug() << "DataBase::execQuery: Still active... " ;
query.finish();
}
- qDebug() << "DataBase::execQuery: No longer active... " ;
+ qDebug() << "DataBase::execQuery: No longer active... let's continue" ;
return true;
}
else
diff --git a/src/database.h b/src/database.h
index 1d1488ac..37e9aead 100644
--- a/src/database.h
+++ b/src/database.h
@@ -65,6 +65,7 @@ struct AwarddxccEntryCheck
class DataBase : public QObject
{
Q_OBJECT
+ friend class tst_DataBase;
public:
DataBase(const QString &_parentClass, const QString &_DBName);
@@ -128,15 +129,13 @@ class DataBase : public QObject
bool updateAwardDXCCTable();
bool updateAwardDXCCTable2();
bool updateAwardWAZTable();
- int getNumberOfQsos(const int _logNumber);
+ int getNumberOfQsos(int _logNumber = -1);
int getLastInsertedQSO();
void setLogLevel (const DebugLogLevel _b);
//private slots:
// void slotPrintErrors(QString _func, QString _msg, int _level);
private:
- //bool beginTransaction();
- //bool commitTransaction();
bool execQuery(const QString &function, const QString &stringQuery);
bool updateEntity (const QString &_codeString, const int _code);
bool createDataBase();
diff --git a/src/dataproxy_sqlite.cpp b/src/dataproxy_sqlite.cpp
index b2870a4c..32ba21d3 100644
--- a/src/dataproxy_sqlite.cpp
+++ b/src/dataproxy_sqlite.cpp
@@ -2172,10 +2172,10 @@ QStringList DataProxy_SQLite::getFilteredLocators(const QString &_band, const QS
bool DataProxy_SQLite::updateAwardDXCC()
{
- //qDebug() << "DataProxy_SQLite::updateAwardDXCC";
+ qDebug() << Q_FUNC_INFO << " - Start";
fillEmptyDXCCInTheLog();
return db->updateAwardDXCCTable2();
- //qDebug() << "DataProxy_SQLite::updateAwardDXCC-END";
+ //qDebug() << Q_FUNC_INFO << " - END";
}
bool DataProxy_SQLite::updateAwardWAZ()
@@ -6033,6 +6033,7 @@ bool DataProxy_SQLite::fillEmptyDXCCInTheLog()
sqlOK = updateDXCCAndContinent(_id.toInt(), _dxcc.toInt(), _continent);
if (!sqlOK)
{
+ query.finish();
return false;
}
if (( (j % step )== 0) )
@@ -6051,6 +6052,7 @@ bool DataProxy_SQLite::fillEmptyDXCCInTheLog()
j++;
}
}
+ query.finish();
progress.setValue(qsos);
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
diff --git a/src/infowidget.cpp b/src/infowidget.cpp
index 6ede0c9d..251bbc91 100644
--- a/src/infowidget.cpp
+++ b/src/infowidget.cpp
@@ -370,13 +370,13 @@ void InfoWidget::setImperialSystem (const bool _imp)
QString InfoWidget::getStyleColorToLabelFromBand(const QString &_b, const QString &_q)
{ // Receives band name, Entity number (as a String)
- qDebug() << Q_FUNC_INFO << ": " << _b << "/" << _q;
+ //qDebug() << Q_FUNC_INFO << ": " << _b << "/" << _q;
QStringList _qs;
_qs.clear();
_qs << _q << QString::number(dataProxy->getIdFromBandName(_b)) << QString::number(-1) << QString::number(currentLog);
//TODO: Check if we can know the mode and replace the -1
- qDebug() << Q_FUNC_INFO << ": (Band/background-color): " << _b << (awards->getQRZDXStatusColor(_qs)).name(QColor::HexRgb) ;
+ //qDebug() << Q_FUNC_INFO << ": (Band/background-color): " << _b << (awards->getQRZDXStatusColor(_qs)).name(QColor::HexRgb) ;
return "* { background-color: " + (awards->getQRZDXStatusColor(_qs)).name(QColor::HexRgb) + "; }";
}
@@ -384,12 +384,12 @@ QString InfoWidget::getStyleColorToLabelFromBand(const QString &_b, const QStrin
//void InfoWidget::showInfo(const int _entity, const int _bandid, const int _modeid, const int _log)
void InfoWidget::showInfo(const int _entity)
{ // Default values of _modeid & _log = -1
- qDebug() << Q_FUNC_INFO << " - Start";
- qDebug() << Q_FUNC_INFO << ": " << QString::number(_entity);
+ //qDebug() << Q_FUNC_INFO << " - Start";
+ //qDebug() << Q_FUNC_INFO << ": " << QString::number(_entity);
//QColor getQRZDXStatusColor(const QStringList _qs); // Receives Entity, band, mode & log
if (_entity <1)
{
- qDebug() << Q_FUNC_INFO << ": entity <1";
+ //qDebug() << Q_FUNC_INFO << ": entity <1";
clearBandLabels();
}
@@ -405,7 +405,7 @@ void InfoWidget::showInfo(const int _entity)
bandLabel10->setStyleSheet(getStyleColorToLabelFromBand(bandLabel10->text(), QString::number(_entity)));
bandLabel11->setStyleSheet(getStyleColorToLabelFromBand(bandLabel11->text(), QString::number(_entity)));
bandLabel12->setStyleSheet(getStyleColorToLabelFromBand(bandLabel12->text(), QString::number(_entity)));
- qDebug() << Q_FUNC_INFO << " - END";
+ //qDebug() << Q_FUNC_INFO << " - END";
}
void InfoWidget::showEntityInfo(const int _enti, int _cq, int _itu)
diff --git a/src/utilities.cpp b/src/utilities.cpp
index d02a6d46..fbe8d768 100644
--- a/src/utilities.cpp
+++ b/src/utilities.cpp
@@ -537,22 +537,6 @@ QString Utilities::getKLogDBBackupFile()
return getDBPath() + "/" + QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss") + "-backup-logbook.dat" ;
}
-
-
-/*
-QString Utilities::getKLogDatabaseFile(const QString &_file)
-{
- //qDebug() << "Utilities::getKLogDatabaseFile:" << _file ;
- if ( QFile::exists(_file + "/logbook.dat") )
- {
- //qDebug() << "Utilities::getKLogDatabaseFile:returning: " << _file + "/logbook.dat" ;
- return _file + "/logbook.dat";
- }
- //qDebug() << "Utilities::getKLogDatabaseFile: Does not exist so default: " << getKLogDefaultDatabaseFile() ;
- return getKLogDefaultDatabaseFile();
-}
-*/
-
QString Utilities::getCfgFile()
{
//TODO: To be removed when the defaultDir is saved in the config file
@@ -625,7 +609,6 @@ QString Utilities::getTQSLsFileName()
QString Utilities::getTQSLsPath()
{
//qDebug() << "Utilities::getDefaultProgramsPath " ;
-
#if defined(Q_OS_WIN64)
//qDebug() << "WINDOWS DETECTED!: " ;
return "C:/Program Files/TrustedQSL/";
diff --git a/src/world.cpp b/src/world.cpp
index 6df6e5d1..4de50b3e 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -675,7 +675,13 @@ bool World::addPrefix(const QString &_pref, const int _dxcc, const int _cqz, con
bool World::readCTYCSV(const QString &_worldFile)
{
- //qDebug() << Q_FUNC_INFO << _worldFile;
+#ifdef KLOG_TESTING
+ qDebug() << Q_FUNC_INFO << " - We are testing";
+#endif
+#ifndef KLOG_TESTING
+ qDebug() << Q_FUNC_INFO << " - We are NOT testing";
+#endif
+ qDebug() << Q_FUNC_INFO << _worldFile;
QString tq;
tq.clear();
@@ -710,10 +716,10 @@ bool World::readCTYCSV(const QString &_worldFile)
// Starts with main data:
file.seek(beginingOfFile);
progressBarPosition = 0;
- //QProgressDialog progress(tr("Reading cty.csv..."), tr("Abort reading"), 0, numberOfLines, this);
+#ifndef KLOG_TESTING
QProgressDialog progress(tr("Reading cty.csv..."), tr("Abort reading"), 0, numberOfLines);
progress.setWindowModality(Qt::ApplicationModal);
-
+#endif
numberOfEntities = 0; // Reset this variable to reuse it and assign the "dxcc" to the entities (temp solution)
//qDebug() << Q_FUNC_INFO << " - 40";
@@ -721,18 +727,18 @@ bool World::readCTYCSV(const QString &_worldFile)
//qDebug() << Q_FUNC_INFO << " - 50";
- QStringList T9StringList;
- T9StringList.clear();
-
QStringList stringList, stringListPrefixes, stringListProcessedPrefix;
int entN;
//qDebug() << Q_FUNC_INFO << " - 60";
while (!file.atEnd()) {
+#ifndef KLOG_TESTING
progress.setValue(progressBarPosition);
- progressBarPosition++;
+
if (progress.wasCanceled())
break;
+#endif
+ progressBarPosition++;
stringList.clear();
stringListPrefixes.clear();
//
@@ -755,7 +761,6 @@ bool World::readCTYCSV(const QString &_worldFile)
//qDebug() << Q_FUNC_INFO << " Line stringList-0: " << stringList.at(0);
//qDebug() << Q_FUNC_INFO << " Line stringList Length: " << QString::number(stringList.length());
-
// stringList.at(9) contains an space separated list of prefixes for that entity
QString mPrefix = QString();
if (stringList.size()==10 )
@@ -829,11 +834,18 @@ bool World::readCTYCSV(const QString &_worldFile)
}
}
}
+#ifndef KLOG_TESTING
progress.setLabelText("Reading cty.csv ... \nNow reading " + mPrefix + " data");
+#endif
+#ifdef KLOG_TESTING
+ qDebug() << Q_FUNC_INFO << QString("Reading cty.csv... Now reading %1").arg(mPrefix);
+#endif
//qDebug() << Q_FUNC_INFO << " - progressBarPosition: " << QString::number(progressBarPosition);
}
//qDebug() << Q_FUNC_INFO << " - 100";
+#ifndef KLOG_TESTING
progress.setValue(numberOfLines);
+#endif
//qDebug() << Q_FUNC_INFO << " - 102";
if (created)
{
diff --git a/tests/tests.pro b/tests/tests.pro
index 215735a5..e6eb6a9d 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -8,6 +8,7 @@ SUBDIRS=\
tst_mainwindowsattab \
tst_mainwindow \
tst_dataproxy \
+ tst_database \
tst_locator \
tst_mainwindowinputqso \
tst_qso \
diff --git a/tests/tst_database/tst_database.cpp b/tests/tst_database/tst_database.cpp
new file mode 100644
index 00000000..b3c1df49
--- /dev/null
+++ b/tests/tst_database/tst_database.cpp
@@ -0,0 +1,322 @@
+/***************************************************************************
+ tst_database.h - description
+ -------------------
+ begin : Mar 2024
+ copyright : (C) 2024 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/database.h"
+#include "../../src/utilities.h"
+#include "../../src/world.h"
+#include "../../src/qso.h"
+#include "../../src/dataproxy_sqlite.h"
+/*
+ initTestCase() will be called before the first test function is executed.
+ initTestCase_data() will be called to create a global test data table.
+ cleanupTestCase() will be called after the last test function was executed.
+ init() will be called before each test function is executed.
+ cleanup() will be called after every test function.
+*/
+
+class tst_DataBase: public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_DataBase();
+ ~tst_DataBase();
+
+private slots:
+ void initTestCase(); // will be called before the first test function is executed.
+ void test_Constructor();
+ void test_CreateDB();
+ void test_ExistingTables();
+ void test_DataInTables();
+
+ void test_checks();
+ void test_addQSOs();
+ //void initTestCase_data(); // will be called to create a global test data table.
+
+ //void init(); // will be called before each test function is executed.
+ //void cleanup(); // will be called after every test function.
+ void cleanupTestCase(); // will be called after the last test function was executed.
+
+
+ //void test_getProgresStepForDialog();
+
+private:
+ DataBase *db;
+ Utilities *util;
+ QString version;
+};
+
+tst_DataBase::tst_DataBase()
+{
+ version = "999";
+}
+
+tst_DataBase::~tst_DataBase()
+{
+ //qDebug() << Q_FUNC_INFO;
+ delete (util);
+ delete (db);
+}
+
+void tst_DataBase::initTestCase()
+{
+ qDebug() << Q_FUNC_INFO;
+ Utilities util(Q_FUNC_INFO);
+ QFile file(util.getKLogDBFile());
+ if (file.exists())
+ if (file.rename(util.getKLogDBFile() + "-test"))
+ qDebug() << Q_FUNC_INFO << "DB deleted";
+
+ qDebug() << Q_FUNC_INFO << ": " << util.getCfgFile();
+ file.setFileName(util.getCfgFile());
+ if (file.exists())
+ if (file.rename(util.getCfgFile() + "-test"))
+ qDebug() << Q_FUNC_INFO << "Restoring the config file";
+}
+
+void tst_DataBase::test_ExistingTables()
+{
+ //DataBase db(Q_FUNC_INFO, version, util->getKLogDBFile());
+
+ QCOMPARE(db->isTheTableExisting("ant_path_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("arrl_sect_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("award_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("awarddxcc"), true);
+ QCOMPARE(db->isTheTableExisting("awardwaz"), true);
+ QCOMPARE(db->isTheTableExisting("band"), true);
+ QCOMPARE(db->isTheTableExisting("clublog_status"), true);
+ QCOMPARE(db->isTheTableExisting("contest"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatassisted"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatcategory"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatband"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatmode"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatoperator"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatoverlay"), true);
+ QCOMPARE(db->isTheTableExisting("contestcatpower"), true);
+
+ QCOMPARE(db->isTheTableExisting("continent"), true);
+ QCOMPARE(db->isTheTableExisting("entity"), true);
+ QCOMPARE(db->isTheTableExisting("log"), true);
+ QCOMPARE(db->isTheTableExisting("logs"), true);
+ QCOMPARE(db->isTheTableExisting("mode"), true);
+ QCOMPARE(db->isTheTableExisting("prefixesofentity"), true);
+ QCOMPARE(db->isTheTableExisting("primary_subdivisions"), true);
+ QCOMPARE(db->isTheTableExisting("prop_mode_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("qsl_rec_status"), true);
+ QCOMPARE(db->isTheTableExisting("qsl_sent_status"), true);
+ QCOMPARE(db->isTheTableExisting("qsl_via_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("satellites"), true);
+ QCOMPARE(db->isTheTableExisting("qso_complete_enumeration"), true);
+ QCOMPARE(db->isTheTableExisting("softwarecontrol"), true);
+ QCOMPARE(db->isTheTableExisting("supportedcontest"), true);
+}
+
+void tst_DataBase::test_DataInTables()
+{
+ //DataBase db(Q_FUNC_INFO, version, util->getKLogDBFile());
+
+ QCOMPARE(db->hasTheTableData("ant_path_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("arrl_sect_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("award_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("awarddxcc"), false);
+ QCOMPARE(db->hasTheTableData("awardwaz"), false);
+ QCOMPARE(db->hasTheTableData("band"), true);
+ QCOMPARE(db->hasTheTableData("clublog_status"), true);
+ QCOMPARE(db->hasTheTableData("contest"), true);
+ QCOMPARE(db->hasTheTableData("contestcatassisted"), true);
+ QCOMPARE(db->hasTheTableData("contestcatcategory"), false);
+ QCOMPARE(db->hasTheTableData("contestcatband"), true);
+ QCOMPARE(db->hasTheTableData("contestcatmode"), true);
+ QCOMPARE(db->hasTheTableData("contestcatoperator"), true);
+ QCOMPARE(db->hasTheTableData("contestcatoverlay"), true);
+ QCOMPARE(db->hasTheTableData("contestcatpower"), true);
+
+ QCOMPARE(db->hasTheTableData("continent"), true);
+ QCOMPARE(db->hasTheTableData("entity"), false);
+
+ QCOMPARE(db->hasTheTableData("log"), false);
+ QCOMPARE(db->hasTheTableData("logs"), false);
+ QCOMPARE(db->hasTheTableData("mode"), true);
+ QCOMPARE(db->hasTheTableData("prefixesofentity"), false);
+ QCOMPARE(db->hasTheTableData("primary_subdivisions"), false);
+ QCOMPARE(db->hasTheTableData("prop_mode_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("qsl_rec_status"), true);
+ QCOMPARE(db->hasTheTableData("qsl_sent_status"), true);
+ QCOMPARE(db->hasTheTableData("qsl_via_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("satellites"), true);
+ QCOMPARE(db->hasTheTableData("qso_complete_enumeration"), true);
+ QCOMPARE(db->hasTheTableData("softwarecontrol"), true);
+ QCOMPARE(db->hasTheTableData("supportedcontest"), true);
+}
+
+void tst_DataBase::test_checks()
+{
+ //DataBase db(Q_FUNC_INFO, version, util->getKLogDBFile());
+ QCOMPARE(db->isTheDBCreated(), true);
+ QString aux;
+ QStringList _bands = { "0", "1mm", "2mm", "2.5mm", "4mm", "6mm",
+ "1.25CM", "3CM", "6CM", "9CM", "13CM", "23CM",
+ "70CM", "1.25M", "2M", "4M", "6M", "8M", "10M",
+ "12M", "15M", "17M", "20M", "30M", "40M", "60M",
+ "80M", "160M", "560M", "630M", "2190M" };
+
+ QCOMPARE(db->isValidBand("0"), true);
+ QCOMPARE(db->isValidBand("1mm"), true);
+
+ foreach(aux, _bands)
+ {
+ qDebug() << aux;
+ QCOMPARE(db->isValidBand(aux), true);
+ }
+
+ QStringList _modes = {"AM", "ARDOP", "AMTORFEC", "ASCI", "ATV", "CHIP", "CHIP64",
+ "CHIP218", "CLO", "CONTESTI", "CW", "DIGITALVOICE", "C4FM"};
+ foreach(aux, _modes)
+ {
+ QCOMPARE(db->isValidMode(aux), true);
+ }
+
+ int i = db->getBandIDFromName2("10M");
+ QCOMPARE (db->getBandNameFromID2(i), "10M");
+ i = db->getBandIDFromName2("30M");
+ QCOMPARE (db->getBandNameFromID2(i), "30M");
+ i = db->getBandIDFromName2("0");
+ QCOMPARE (db->getBandNameFromID2(i), "0");
+
+ i = db->getModeIDFromName2("FT4");
+ QCOMPARE (db->getSubModeNameFromID2(i), "FT4");
+
+/*
+
+ QString getBandNameFromNumber(const int _n);
+ QString getModeNameFromNumber(const int _n, bool _tmp=false);
+ QString getSubModeNameFromNumber(const int _n, bool _tmp=false);
+
+ int getBandIdFromName(const QString &b);
+ int getModeIdFromName(const QString &b);
+ int getModeIdFromSubMode(const QString &b);
+
+ int getModeIDFromName2(const QString &b);
+ int getSubModeIDFromName2(const QString &b);
+
+ QString getModeNameFromID2(const int _i);
+ QString getSubModeNameFromID2(const int _i);
+
+ int getBandIdFromFreq(const QString &fr); //Freq should be in MHz
+ bool isThisFreqInBand(const QString &b, const QString &fr); //Freq should be in MHz
+
+ QString getFreqFromBandId(const int _i);
+ int getNumberOfQsos(int _logNumber = -1);
+ int getLastInsertedQSO();
+
+*/
+}
+
+void tst_DataBase::test_CreateDB()
+{
+ Utilities util(Q_FUNC_INFO);
+ QFile file(util.getCTYFile());
+ QCOMPARE( file.exists(), true); // Check if the CTYDAT file is available
+
+ DataProxy_SQLite dataProxy(Q_FUNC_INFO, version);
+ //qDebug() << Q_FUNC_INFO << "003";
+ World world(&dataProxy, Q_FUNC_INFO);
+ QCOMPARE(world.create(util.getCTYFile()), true); // Read the CTY.CSV file into the DB
+ QCOMPARE(db->hasTheTableData("entity"), true);
+ QCOMPARE(db->hasTheTableData("prefixesofentity"), true);
+}
+
+void tst_DataBase::test_addQSOs()
+{
+ int i = db->getNumberOfQsos();
+ QSO qso;
+ qso.clear();
+ qso.setCall("EA4K");
+ qso.setDate(QDate::fromString("20240327", "yyyyMMdd"));
+ qso.setTimeOn(QTime::fromString("1000", "hhmm"));
+ qso.setBand("10M");
+ qso.setMode("SSB");
+ qso.toDB();
+ QCOMPARE(db->getNumberOfQsos(), i+1);
+}
+
+void tst_DataBase::cleanupTestCase()
+{
+ qDebug() << Q_FUNC_INFO;
+ Utilities util(Q_FUNC_INFO);
+ QFile file(util.getKLogDBFile());
+ if (file.exists())
+ if (file.rename(util.getKLogDBFile() + "-test-db"))
+ qDebug() << Q_FUNC_INFO << "DB deleted";
+ qDebug() << Q_FUNC_INFO << ": " << util.getCfgFile();
+
+ file.setFileName(util.getCfgFile());
+ if (file.exists())
+ if (file.rename(util.getCfgFile() + "-test-db"))
+ qDebug() << Q_FUNC_INFO << "Restoring the config file";
+
+
+ file.setFileName(util.getKLogDBFile() + "-test");
+ if (file.exists())
+ if (file.rename(util.getKLogDBFile()))
+ qDebug() << Q_FUNC_INFO << "DB deleted";
+ file.setFileName(util.getCfgFile() + "-test");
+ if (file.exists())
+ if (file.rename(util.getCfgFile()))
+ qDebug() << Q_FUNC_INFO << "Restoring the config file";
+}
+
+/*
+void tst_DataBase::cleanupTestCase()
+{
+ //qDebug() << Q_FUNC_INFO;
+}
+
+void tst_DataBase::init()
+{
+ //qDebug() << Q_FUNC_INFO;
+}
+
+void tst_DataBase::cleanup()
+{
+ //qDebug() << Q_FUNC_INFO;
+}
+*/
+
+void tst_DataBase::test_Constructor()
+{
+ QString _version = QString ("99.9");
+ util = new Utilities(Q_FUNC_INFO);
+ db = new DataBase(Q_FUNC_INFO, _version, util->getKLogDBFile());
+ QCOMPARE(db->createConnection(Q_FUNC_INFO), true);
+}
+
+QTEST_APPLESS_MAIN(tst_DataBase)
+
+#include "tst_database.moc"
+
diff --git a/tests/tst_database/tst_database.pro b/tests/tst_database/tst_database.pro
new file mode 100644
index 00000000..aa2a1cf8
--- /dev/null
+++ b/tests/tst_database/tst_database.pro
@@ -0,0 +1,39 @@
+QT += testlib \
+ gui \
+ sql \
+ widgets
+
+DEFINES *= KLOG_TESTING
+CONFIG += qt console warn_on depend_includepath testcase
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+HEADERS += \
+ ../../src/database.h \
+ ../../src/adif.h \
+ ../../src/locator.h \
+ ../../src/world.h \
+ ../../src/dataproxy_sqlite.h \
+ ../../src/qso.h \
+ ../../src/utilities.h
+
+
+SOURCES += tst_database.cpp \
+ ../../src/adif.cpp \
+ ../../src/locator.cpp \
+ ../../src/utilities.cpp \
+ ../../src/world.cpp \
+ ../../src/dataproxy_sqlite.cpp \
+ ../../src/qso.cpp \
+ ../../src/database.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 }
+ }
+}
diff --git a/tests/tst_wizard/tst_wizard.cpp b/tests/tst_wizard/tst_wizard.cpp
index 3e969be5..8aa90a6e 100644
--- a/tests/tst_wizard/tst_wizard.cpp
+++ b/tests/tst_wizard/tst_wizard.cpp
@@ -79,8 +79,6 @@ void tst_Wizard::cleanupTestCase()
if (sfile.exists())
if (sfile.rename(util.getCfgFile()))
qDebug() << Q_FUNC_INFO << "Restoring the config file";
-
-
}
void tst_Wizard::test_Constructor()