Skip to content

Commit

Permalink
handle call area suffixes
Browse files Browse the repository at this point in the history
In the callsign KH6XX/W0, the actual DXCC is determined by the suffix W0
instead of the callsign prefix KH6

Resolves #226
  • Loading branch information
ftl committed Jul 16, 2023
1 parent d8b946d commit 46a3bdb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/Callsign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Callsign::Callsign(const QString &callsign,
hostPrefixWithDelimiter = match.captured(1);
hostPrefix = match.captured(2);
base = match.captured(3);
basePrefix = match.captured(4);
suffixWithDelimiter = match.captured(7);
suffix = match.captured(8);

Expand Down Expand Up @@ -73,6 +74,13 @@ QString Callsign::getBase() const
return base;
}

QString Callsign::getBasePrefix() const
{
FCT_IDENTIFICATION;

return basePrefix;
}

QString Callsign::getSuffix() const
{
FCT_IDENTIFICATION;
Expand Down
2 changes: 2 additions & 0 deletions core/Callsign.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Callsign : public QObject
QString getHostPrefix() const;
QString getHostPrefixWithDelimiter() const;
QString getBase() const;
QString getBasePrefix() const;
QString getSuffix() const;
QString getSuffixWithDelimiter() const;
bool isValid() const;
Expand All @@ -26,6 +27,7 @@ class Callsign : public QObject
QString hostPrefix;
QString hostPrefixWithDelimiter;
QString base;
QString basePrefix;
QString suffix;
QString suffixWithDelimiter;
bool valid;
Expand Down
19 changes: 18 additions & 1 deletion data/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QSqlError>
#include <QColor>
#include "Data.h"
#include "core/Callsign.h"
#include "core/debug.h"

MODULE_IDENTIFICATION("qlog.data.data");
Expand Down Expand Up @@ -989,7 +990,23 @@ DxccEntity Data::lookupDxcc(const QString &callsign)
return DxccEntity();
}

queryDXCC.bindValue(":callsign", callsign);
QString lookupPrefix = callsign; // use the callsign with optional prefix as default to find the dxcc

Callsign parsedCallsign(callsign); // use Callsign to split the callsign into its parts
if ( parsedCallsign.isValid() ) {
QString suffix = parsedCallsign.getSuffix();
if ( suffix.length() == 1 ) { // some countries add single numbers as suffix to designate a call area, e.g. /4
bool isNumber = false;
int number = suffix.toInt(&isNumber);
if ( isNumber ) {
lookupPrefix = parsedCallsign.getBasePrefix() + suffix; // use the call prefix and the number from the suffix to find the dxcc
}
} else if ( suffix.length() > 1 ) { // if there is more than one character we definitely have a call prefix as suffix
lookupPrefix = suffix;
}
}

queryDXCC.bindValue(":callsign", lookupPrefix);

if ( ! queryDXCC.exec() )
{
Expand Down

0 comments on commit 46a3bdb

Please sign in to comment.