Skip to content

Commit

Permalink
work on subdivisions
Browse files Browse the repository at this point in the history
ea4k committed Aug 16, 2024
1 parent f8c1b08 commit 1d4e272
Showing 7 changed files with 63 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
TODO-Bug: Add QSOs from wsjtx does not work. Failure close to int QSO::toDB(int _qsoId)
WIP: Subdivisions only works with the main prefix. It is needed to find the prefix (EB, EC for EA and so on)
TODO-Test: Add tests to test the subsivisions
TODO-Test: the copy constructor of QSO
Complete: void MainWindow::slotQSOReceived(const QSO &_qso) to add the QSO
1 change: 0 additions & 1 deletion src/database.cpp
Original file line number Diff line number Diff line change
@@ -6597,7 +6597,6 @@ int DataBase::getLastInsertedQSO()
}
query.finish();
return id;

//qDebug() << Q_FUNC_INFO << " - END";
}

8 changes: 6 additions & 2 deletions src/inputwidgets/mainwindowinputothers.cpp
Original file line number Diff line number Diff line change
@@ -770,21 +770,25 @@ void MainWindowInputOthers::updatePrimarySubDivisions(const int _n, const QStrin
//qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_n) << "/" << _qrz;
currentPref = _qrz;
QString currentPrefTMP = util->getPrefixFromCall(_qrz, !showAllCheckBox->isChecked());
QString mainPref = dataProxy->getEntityMainPrefix(_n);
//qDebug() << Q_FUNC_INFO << " - currentPref: " << QString::number(_n) << "/" << currentPrefTMP;
int a = util->getAreaNumberFromCall(_qrz);
if (_n<1)
return;
currentInt = _n;
setEntity(_n);
if (currentPrefTMP.isEmpty())
if ((currentPrefTMP.isEmpty()) && (mainPref.isEmpty()))
return;

QList<PrimarySubdivision> subdivisions;
subdivisions.clear();
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, currentPrefTMP));
if (subdivisions.isEmpty())
{
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, mainPref));
if (subdivisions.isEmpty())
//qDebug() << Q_FUNC_INFO << " - Subdivisions is empty, running just with the entity";
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, QString()));
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, QString()));
}

//qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
38 changes: 34 additions & 4 deletions src/qso.cpp
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
* *
*****************************************************************************/
#include "qso.h"
#include "QtSql/qsqlerror.h"

QSO::QSO()
{
@@ -3385,7 +3386,7 @@ int QSO::toDB(int _qsoId)
return -1;
}
qDebug() << Q_FUNC_INFO << "Mode: " << getMode();
qDebug() << Q_FUNC_INFO << "Mode: " << getSubmode();
qDebug() << Q_FUNC_INFO << "Submode: " << getSubmode();
//qDebug() << Q_FUNC_INFO << " - QSO Complete... adding";
QString queryString;
queryString.clear();
@@ -3400,20 +3401,23 @@ int QSO::toDB(int _qsoId)
queryString = getModifyQueryString();
}
//qDebug() << Q_FUNC_INFO << " Query: " << queryString;;

QSqlQuery query = getPreparedQuery(queryString);
qDebug() << Q_FUNC_INFO << " qsoId: " << QString::number(_qsoId);
if (_qsoId>0)
{
//qDebug() << Q_FUNC_INFO << " - binding ID";
query.bindValue (":id", _qsoId);
}
//qDebug() << Q_FUNC_INFO << " - executing query";
qDebug() << Q_FUNC_INFO << " - executing query";
if (query.exec())
{
//qDebug() << Q_FUNC_INFO << QString(": QSO ADDED/Modified: %1 - %2").arg(callsign).arg(getDateTimeOn().toString("yyyyMMdd-hhmm"));
//qDebug() << Q_FUNC_INFO << ": QSO ADDED/Modified: " << query.lastQuery ();
if (_qsoId>0)
return _qsoId;
return 1;//db->getLastInsertedQSO();
//db = new DataBase(Q_FUNC_INFO, _softVersion, util->getKLogDBFile());
return getLastInsertedQSO();
}
else
{
@@ -3588,11 +3592,13 @@ int QSO::getModeIdFromModeName()
//
// SELECT mode.id FROM mode WHERE mode.submode="FT4"
// SELECT mode.id FROM mode WHERE mode.name="MFSK"
bool ok = query.prepare ("SELECT mode.id FROM mode WHERE mode.submode= :submode");
bool ok = query.prepare ("SELECT mode.id FROM mode WHERE mode.submode= ':submode'");
if (!ok)
{
qDebug() << Q_FUNC_INFO << " - Failed to prepare";
return -1;
}
qDebug() << Q_FUNC_INFO << " - Binding mode" << getMode();
query.bindValue (":submode", getMode ());
//if (haveSubMode)
//{
@@ -3613,6 +3619,7 @@ int QSO::getModeIdFromModeName()
{
if (query.isValid ())
{
qDebug() << Q_FUNC_INFO << ": " << query.value (0).toString();
return query.value (0).toInt ();
}
else
@@ -4381,3 +4388,26 @@ bool QSO::fromDB(int _qsoId)
logEvent (Q_FUNC_INFO, "END", Debug);
return false;
}

int QSO::getLastInsertedQSO()
{
//qDebug() << Q_FUNC_INFO << " - Start";
QString stringQuery = QString("SELECT last_insert_rowid()");

QSqlQuery query;
bool sqlOK = query.exec(stringQuery);
int id = -1;

if (sqlOK)
{
query.next();
id = (query.value(0)).toInt();
}
else
{
//queryErrorManagement(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().nativeErrorCode(), query.lastQuery());
}
query.finish();
return id;
//qDebug() << Q_FUNC_INFO << " - END";
}
6 changes: 4 additions & 2 deletions src/qso.h
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
#include "utilities.h"
#include "klogdefinitions.h"
#include "adif.h"
#include "database.h"
//#include "database.h"


//#include <functional>
@@ -442,7 +442,7 @@ class QSO : public QObject
int getModeIdFromModeName(); // It really returns submode
QString getModeNameFromModeId(int _modeId, bool _submode=true);
void setBandFromFreq(const double _fr, bool TX = true);
DataBase *db;
//DataBase *db;


int qsoId, logId, dxcc, a_index, k_index, cqz, fists, fists_cc, my_fists, iota_ID, itu_zone, nr_bursts, max_bursts, nr_pings, my_cqz, my_itu_zone, my_dxcc, my_iota_ID, srx, stx, uksmg;
@@ -540,6 +540,8 @@ class QSO : public QObject
bool setLoTWQSLRDate2(const QString& data);
bool setLoTWQSLSDate1(const QString& data);
bool setLoTWQSLSDate2(const QString& data);

int getLastInsertedQSO(); // just a query to get the latest inserted QSO
};

#endif // QSO_H
16 changes: 16 additions & 0 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
@@ -1102,6 +1102,22 @@ bool Utilities::isValidCall(const QString &_c, bool _force)
return isValidSimpleCall(call);
}

int Utilities::getAreaNumberFromCall(const QString &_c)
{
qDebug() << Q_FUNC_INFO << ": " << _c;
QString withAreaNumberPref = getPrefixFromCall(_c, true);
QString withOutAreaNumberPref = getPrefixFromCall(_c, false);

qDebug() << Q_FUNC_INFO << ": With Area: " << withAreaNumberPref;
qDebug() << Q_FUNC_INFO << ": WithOut Area: " << withOutAreaNumberPref;

QString areaString = withAreaNumberPref.remove(withOutAreaNumberPref);
qDebug() << Q_FUNC_INFO << ": Area Number: " << areaString;
int areaNumber = -1;

return areaNumber;
}

QString Utilities::getPrefixFromCall(const QString &_c, bool withAreaNumber)
{
//qDebug() << Q_FUNC_INFO << ": " << _c << " - WithAreaNumber=" << boolToQString(withAreaNumber);
1 change: 1 addition & 0 deletions src/utilities.h
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@ class Utilities : public QObject {
QString getMainCallFromComplexCall(const QString &_complexCall); // F from F/EA4K/p, EA4K from EA4K/p or EA4K from EA4K
QString getAValidCall (const QString &_wrongCall);
QString getPrefixFromCall(const QString &_c, bool withAreaNumber = false);
int getAreaNumberFromCall(const QString &_c);
bool isAOneLetterPrefix(const QChar &_c);

// Write DATE/TIME to DB

0 comments on commit 1d4e272

Please sign in to comment.