Skip to content

Commit

Permalink
progressing slowly
Browse files Browse the repository at this point in the history
  • Loading branch information
ea4k committed Dec 11, 2024
1 parent 4b4c170 commit 7124274
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 79 deletions.
149 changes: 93 additions & 56 deletions src/callsign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Callsign::Callsign(const QString &callsign, QObject *parent) : QObject{parent},
fullCall(callsign.toUpper()), homeAreaNumber(0), valid(false), prefValid(false)
{
//qDebug() << Q_FUNC_INFO << ": " << callsign;
qDebug() << Q_FUNC_INFO << ": " << callsign;
hostAreaNumberExist = false;
homeAreaNumberExist = false;

Expand All @@ -37,65 +37,85 @@ Callsign::Callsign(const QString &callsign, QObject *parent) : QObject{parent},

QRegularExpression prefnRE = prefixRegEx();
QRegularExpressionMatch matchPrefix = prefnRE.match(fullCall);
/*
QRegularExpression re("^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$");
QRegularExpressionMatch match = re.match("08/12/1985");
if (match.hasMatch()) {
QString date = match.captured("date"); // date == "08"
QString month = match.captured("month"); // month == "12"
QString year = match.captured("year"); // year == 1985
}
*/
//QTest::newRow("fullcall") << "fullcall" << "hostfullcall" << "hostfullpref" << "hostpref" << "hostareanumber" << "homefullcall" << "homefullpref" << "homepref" << "homeareanumber" << "homesuffix" << "additionalsuffix" << true;
/*
QString fullCall; // KB1/EA4K/QRP
QString hostFullCall; // KB1/EA4K
QString hostFullPref; // KB1
QString hostPref; // KB
int hostAreaNumber; // 1
QString homeFullCall; // EA4K
QString homeFullPref; // EA4
QString homePref; // EA
int homeAreaNumber; // 4
QString homeSuffix; // K
QString additionalSuffix; // QRP
bool valid; // The entered strig is a correct callsign
*/
bool hasHost = false;
clear();
if ( match.hasMatch() )
{
qDebug() << Q_FUNC_INFO << " - 10";
//it is a valid callsign
valid = true;
fullCall = match.captured ("fullcall");
hostFullCall = match.captured("hostfullcall");
hostFullPref = match.captured("hostfullpref");
hostPref = match.captured("hostpref");
hostAreaNumber = match.captured("hostareanumber").toInt(&hostAreaNumberExist);

homeFullCall = match.captured("homefullcall");
homeFullPref = match.captured("homefullpref");
homePref = match.captured("homepref");
fullCall = match.captured("fullcall");
qDebug() << Q_FUNC_INFO << " - fullcall: " << fullCall;
if (match.captured("hostprefix").length()>0)
{
qDebug() << Q_FUNC_INFO << " - 20";
hostFullPref = match.captured("hostprefix") + match.captured("hostareanumber");
hostPref = match.captured("hostprefix");
hostAreaNumber = match.captured("hostareanumber").toInt(&hostAreaNumberExist);
qDebug() << Q_FUNC_INFO << " - hostFullPref : " << hostFullPref;
qDebug() << Q_FUNC_INFO << " - hostPref : " << hostPref;
qDebug() << Q_FUNC_INFO << " - hostAreaNumner : " << QString::number(hostAreaNumber);
hasHost = true;
}
else if (match.captured("").length()>0)
{
qDebug() << Q_FUNC_INFO << " - 30";
hostFullPref = match.captured("suffixprefix") + match.captured("suffixareanumber");
hostPref = match.captured("suffixprefix");
hostAreaNumber = match.captured("suffixareanumber").toInt(&hostAreaNumberExist);

qDebug() << Q_FUNC_INFO << " - hostFullPref : " << hostFullPref;
qDebug() << Q_FUNC_INFO << " - hostPref : " << hostPref;
qDebug() << Q_FUNC_INFO << " - hostAreaNumner : " << QString::number(hostAreaNumber);

}
qDebug() << Q_FUNC_INFO << " - 40";
homeFullCall = match.captured("homeprefix")+match.captured("homeareanumber")+match.captured("homesuffix");
homeFullPref = match.captured("homeprefix")+match.captured("homeareanumber");
homePref = match.captured("homeprefix");
homeAreaNumber = match.captured("homeareanumber").toInt(&homeAreaNumberExist);
homeSuffix = match.captured("homesuffix");
if (!hasHost)
{
hostPref = homePref;
hostFullPref = homeFullPref;
hostAreaNumber = homeAreaNumber;
}

additionalSuffix = match.captured("suffix");

qDebug() << Q_FUNC_INFO << " - homeFullCall : " << homeFullCall;
qDebug() << Q_FUNC_INFO << " - homeFullPref : " << homeFullPref;
qDebug() << Q_FUNC_INFO << " - homePref : " << homePref;
qDebug() << Q_FUNC_INFO << " - homeAreaNumner : " << QString::number(homeAreaNumber);
qDebug() << Q_FUNC_INFO << " - homeSuffix : " << homeSuffix;
qDebug() << Q_FUNC_INFO << " - AdditionalSuffix : " << additionalSuffix;

additionalSuffix = match.captured("additionalsuffix");
}
else if (matchPrefix.hasMatch())
{
qDebug() << Q_FUNC_INFO << " - 50";
prefValid = true;
hostPref = matchPrefix.captured("homeprefix");
hostFullPref = matchPrefix.captured("homefullprefix"); // The prefix without the area number
homePref = hostPref;
homeFullPref = hostFullPref;
homeAreaNumber = matchPrefix.captured("homeareanumber").toInt(&homeAreaNumberExist); // Just the area number (optional)

qDebug() << Q_FUNC_INFO << " - hostFullPref : " << hostFullPref;
qDebug() << Q_FUNC_INFO << " - hostPref : " << hostPref;
qDebug() << Q_FUNC_INFO << " - homeFullPref : " << homeFullPref;
qDebug() << Q_FUNC_INFO << " - homePref : " << homePref;
qDebug() << Q_FUNC_INFO << " - homeAreaNumner : " << QString::number(homeAreaNumber);
}
else
{
qDebug() << Q_FUNC_INFO << " - 60";
//it is an invalid callsign
fullCall = QString();
}

qDebug() << Q_FUNC_INFO << " - 100";
}

Callsign::~Callsign(){}
Expand All @@ -117,40 +137,36 @@ QString Callsign::callsignRegExString()

// Base callsign
// ^(?<basecall>(?<baseprefixwithnumber>(?<baseprefix>[A-Z][0-9]|[A-Z]|[A-Z]{1,2}|[0-9][A-Z]|E)(?<areanumber>[0-9]+))(?<basesuffix>[A-Z]+))

// REGEX created with Gemini:
//return QString("^(?<fullcall>(?<hostprefix>(?:[FGKNRWUGMI]|[A-Z]{2}|\\d[A-Z]|[A-Z]\\d))?\\/?(?<hostareanumber>\\d+)?\\/?(?<homeprefix>(?:[FGKNRWUGMI]|[A-Z]{2}|\\d[A-Z]|[A-Z]\\d))(?<homeareanumber>\\d+)(?<homesuffix>[A-Z]{0,3}))(?:\\/?(?:(?<suffixprefix>(?:[FGKNRWUGMI]|[A-Z]{2}|\\d[A-Z]|[A-Z]\\d))(?<suffixareanumber>\\d+)?|(?<suffix>(?!(?:[FGKNRWUGMI]|[A-Z]{2}|\\d[A-Z]|[A-Z]\\d)\\d)[^\\/\n]+)))$");
// Host prefix /must end in /
//^(?<fullcall>(?<hostfullcall>((?<hostpref>[A-Z0-9]{1,2}(?<hostareanumber>[0-9]|[0-9]+)?)\/)?(?<fullhomepref>(?<homepref>[A-Z][0-9]|[A-Z]{1,2}|[0-9][A-Z])(?<homeareanumber>[0-9]|[0-9]+))(?<basesuffix>[A-Z]+))(\/(?<additionalsuffix>[A-Z0-9]+))?)
return QString("^(?<fullcall>((?<hostfullcall>(?<hostfullpref>(?<hostpref>[A-Z0-9]{1,2})(?<hostareanumber>[0-9]|[0-9]+)?)\\/)?(?<homefullcall>(?<homefullpref>(?<homepref>[A-Z][0-9]|[A-Z]{1,2}|[0-9][A-Z])(?<homeareanumber>[0-9]|[0-9]+))(?<homesuffix>[A-Z]+)))(\\/(?<additionalsuffix>[A-Z0-9]+))?)");
//^(?<fullcall>(?<hostfullcall>((?<hostpref>[A-Z0-9]{1,2}(?<hostareanumber>[0-9]|[0-9]+)?)\/)?(?<homefullpref>(?<homepref>[A-Z][0-9]|[A-Z]{1,2}|[0-9][A-Z])(?<homeareanumber>[0-9]|[0-9]+))(?<homesuffix>[A-Z]+))(\/(?<additionalsuffix>[A-Z0-9]+))?)
return QString("^(?<fullcall>((?<hostfullcall>(?<hostfullprefix>(?<hostprefix>[A-Z0-9]{1,2})(?<hostareanumber>[0-9]|[0-9]+)?)\\/)?(?<homefullcall>(?<homefullprefix>(?<homeprefix>[A-Z][0-9]|[A-Z]{1,2}|[0-9][A-Z])(?<homeareanumber>[0-9]|[0-9]+))(?<homesuffix>[A-Z]+)))(\\/(?<additionalsuffix>[A-Z0-9]+))?)");
}

QString Callsign::prefixRegExString()
{
//qDebug() << Q_FUNC_INFO;

// Matches prefix: ^(?<homefullpref>(?<homepref>[A-Z]{1,2}|F|G|I|K|M|N|R|U|W|[A-Z][0-9]|[0-9][A-Z]|)(?<homeareanumber>[0-9]+)?)
// Matches prefix: ^(?<homefullprefix>(?<homeprefix>[A-Z]{1,2}|F|G|I|K|M|N|R|U|W|[A-Z][0-9]|[0-9][A-Z]|)(?<homeareanumber>[0-9]+)?)

return QString("^(?<homefullpref>(?<homepref>[A-Z]{1,2}|F|G|I|K|M|N|R|U|W|[A-Z][0-9]|[0-9][A-Z]|)(?<homeareanumber>[0-9]+)?)");
}

QString Callsign::getCallsign()
{
return fullCall;
return QString("^(?<homefullprefix>(?<homeprefix>[A-Z]{1,2}|F|G|I|K|M|N|R|U|W|[A-Z][0-9]|[0-9][A-Z]|)(?<homeareanumber>[0-9]+)?)");
}

QString Callsign::getCallsign(){return fullCall;}

QString Callsign::getHostFullPrefix(){return hostFullPref;}
QString Callsign::getHostPrefix(){return hostPref;}
int Callsign::getHostAreaNuber(){return hostAreaNumber;}

QString Callsign::getHomePrefix(){return homePref;}

QString Callsign::getHomeFullPrefix(){return homeFullPref;}
QString Callsign::getHomePrefix(){return homePref;}
QString Callsign::getHomeSuffix(){return homeSuffix;}
int Callsign::getHomeAreaNuber(){return homeAreaNumber;}
int Callsign::getHomeAreaNumber(){return homeAreaNumber;}

QString Callsign::getAdditionalSuffix(){ return additionalSuffix;}
QString Callsign::getHostPrefix(){return hostPref;}
{
return hostPref;
}
QString Callsign::getHomeCallsign(){return homeFullCall;}

int Callsign::getAreaNuber()
{
Expand All @@ -174,6 +190,27 @@ bool Callsign::isValidPrefix()
return prefValid;
}

void Callsign::clear()
{
fullCall.clear();
hostFullPref.clear();
hostPref.clear();
hostAreaNumber = -1;
hostAreaNumberExist = false;

homeFullCall.clear(); // EA4K
homeFullPref.clear(); // EA4
homePref.clear(); // EA
homeAreaNumber = -1; // 4
homeAreaNumberExist = false;
homeSuffix.clear();

additionalSuffix.clear();

valid = false; // The entered string is a correct callsign
prefValid = false; // The entered string is a correct prefix
}

// Based on wiki information
// https://en.wikipedia.org/wiki/Amateur_radio_call_signs
QStringList Callsign::secondarySpecialSuffixes =
Expand Down
13 changes: 8 additions & 5 deletions src/callsign.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Callsign : public QObject
~Callsign();
static QStringList secondarySpecialSuffixes;

QString getCallsign();
QString getCallsign(); // Returns the FULL callsign
QString getHomeCallsign(); // Returns the base / home callsign like EA4K in K1/EA4K, or EA4K/QRP
int getAreaNuber(); // Get host area number (host if exists or home if host does note xist)

QString getHostPrefix(); // The Host prefix without area number
Expand All @@ -56,12 +57,14 @@ class Callsign : public QObject
QString getHomePrefix(); // The Home prefix without area number
QString getHomeFullPrefix(); // The complete home prefix (simple + area number if exists)
QString getHomeSuffix(); // The suffix of the base call
int getHomeAreaNuber(); // Get the home area number
int getHomeAreaNumber(); // Get the home area number


QString getAdditionalSuffix(); // Additional suffixes like /P, /QRP, /MM, ...

bool isValid(); // True if it is a full callsign
bool isValidPrefix(); // True if it is a prefix, but not a call
void clear();

private:
static QString callsignRegExString();
Expand All @@ -71,7 +74,7 @@ class Callsign : public QObject

// KB1/EA4K/QRP
QString fullCall; // KB1/EA4K/QRP
QString hostFullCall; // KB1/EA4K
//QString hostFullCall; // KB1/EA4K
QString hostFullPref; // KB1
QString hostPref; // KB
int hostAreaNumber; // 1
Expand All @@ -86,8 +89,8 @@ class Callsign : public QObject

QString additionalSuffix; // QRP

bool valid; // The entered strig is a correct callsign
bool prefValid; // The entered strig is a correct prefix
bool valid; // The entered string is a correct callsign
bool prefValid; // The entered string is a correct prefix
};

#endif // CALLSIGN_H
51 changes: 34 additions & 17 deletions src/inputwidgets/mainwindowinputothers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MainWindowInputOthers::MainWindowInputOthers(DataProxy_SQLite *dp, QWidget *pare
connect(userDefinedADIFComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUSerDefinedADIFComboBoxChanged() ) ) ;
connect(userDefinedADIFValueLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSetCurrentUserData() ) );
connect(entityPrimDivComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotPrimarySubdivisionsComboBoxChanged()) ) ;
connect(showAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotShowAllChecBoxChanged() ) ) ;
connect(showAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotShowAllCheckBoxChanged() ) ) ;

createUI();
setInitialADIFValues ();
Expand Down Expand Up @@ -743,78 +743,95 @@ void MainWindowInputOthers::updatePrimarySubdivisionsComboBox(QList<PrimarySubdi

void MainWindowInputOthers::setEntity(const int _ent)
{// Select the appropriate entity in the ComboBox
//qDebug() << Q_FUNC_INFO << ": " << QString::number(_ent);
qDebug() << Q_FUNC_INFO << ": " << QString::number(_ent);
logEvent (Q_FUNC_INFO, "Start", Debug);
qDebug() << Q_FUNC_INFO << " - 10" ;
if (_ent<=0)
{
qDebug() << Q_FUNC_INFO << " - 11" ;
entityNameComboBox->setCurrentIndex(0);
logEvent (Q_FUNC_INFO, "END-1", Debug);
return;
}
qDebug() << Q_FUNC_INFO << " - 20" ;
currentInt = _ent;
QString aux = QString();
aux = QString::number(_ent);
if (_ent > 1000)
{
qDebug() << Q_FUNC_INFO << " - 30" ;
aux = (QString::number(_ent)).right(3);
}
qDebug() << Q_FUNC_INFO << " - 40" ;

int indexC = entityNameComboBox->findText("(" + aux + ")", Qt::MatchEndsWith);

entityNameComboBox->setCurrentIndex(indexC);
setIOTAContinent(dataProxy->getContinentShortNameFromEntity(_ent)) ;
qDebug() << Q_FUNC_INFO << " - 100" ;
logEvent (Q_FUNC_INFO, "END", Debug);
}

void MainWindowInputOthers::setEntityAndPrefix(const int _entity, const QString &_qrz)
{
//qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_n) << "/" << _qrz;
qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_entity) << "/" << _qrz;
if (_entity<=0)
{
qDebug() << Q_FUNC_INFO << " - 10";
entityNameComboBox->setCurrentIndex(0);
logEvent (Q_FUNC_INFO, "END-1", Debug);
return;
}
qDebug() << Q_FUNC_INFO << " - 15";
setEntity(_entity);

Callsign callsign(_qrz);

QString mainPref = dataProxy->getEntityMainPrefix(_entity); // The main prefix of the entity.
QString mainToUse = mainPref + QString::number(callsign.getAreaNumber()); // The default is that showAll is not checked. Main prefix+ the area
QString prefUsed = callsign.getHostPrefix(); // The default is that showAll is not checked
QString mainPref = dataProxy->getEntityMainPrefix(_entity); // The main prefix of the entity.
QString mainToUse = callsign.getHostFullPrefix(); // The default is that showAll is not checked. Main prefix+ the area
QString prefUsed = callsign.getHostPrefix(); // The default is that showAll is not checked

qDebug() << Q_FUNC_INFO << " - 20";
if (showAllCheckBox->isChecked())
{ // The prefix without the number should be used.
// be careful with prefixes like EA8/EA or E73 / E7
mainToUse = mainPref;
prefUsed = callsign.getHostPrefixWithoutNumber();
// be careful with prefixes like EA8/EA/EA6 or E73 / E7
qDebug() << Q_FUNC_INFO << " - 21";
mainToUse = mainPref;
prefUsed = callsign.getHostPrefix();
}
qDebug() << Q_FUNC_INFO << " - 30";

//qDebug() << Q_FUNC_INFO << "mainPref: " << mainPref;
//qDebug() << Q_FUNC_INFO << "prefUsed: " << prefUsed;
qDebug() << Q_FUNC_INFO << "mainToUse: " << mainToUse;
qDebug() << Q_FUNC_INFO << "mainPref: " << mainPref;
qDebug() << Q_FUNC_INFO << "prefUsed: " << prefUsed;

if ((mainToUse.isEmpty()) && (prefUsed.isEmpty()))
return;

qDebug() << Q_FUNC_INFO << " - 40";
QList<PrimarySubdivision> subdivisions;
subdivisions.clear();
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, prefUsed));
if (subdivisions.length()<1)
{
//qDebug() << Q_FUNC_INFO << " - Subdivisions is empty with prefUSed, running for the main prefix";
qDebug() << Q_FUNC_INFO << " - 50";
qDebug() << Q_FUNC_INFO << " - Subdivisions is empty with prefUSed, running for the main prefix";
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, mainToUse));
if (subdivisions.length()<1)
{
//qDebug() << Q_FUNC_INFO << " - Subdivisions is empty with mainpref, running just with the entity";
qDebug() << Q_FUNC_INFO << " - 55";
qDebug() << Q_FUNC_INFO << " - Subdivisions is empty with mainpref, running just with the entity";
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, QString()));
}
qDebug() << Q_FUNC_INFO << " - 59";
}
qDebug() << Q_FUNC_INFO << " - 60";

//qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
if (subdivisions.count()<1)
return;
qDebug() << Q_FUNC_INFO << " - 70 ";
updatePrimarySubdivisionsComboBox(subdivisions);
//qDebug() << Q_FUNC_INFO << " - END";
qDebug() << Q_FUNC_INFO << " - END";
}

void MainWindowInputOthers::slotUSerDefinedADIFComboBoxChanged()
Expand Down Expand Up @@ -1025,7 +1042,7 @@ void MainWindowInputOthers::slotPrimarySubdivisionsComboBoxChanged()
logEvent (Q_FUNC_INFO, "END", Debug);
}

void MainWindowInputOthers::slotShowAllChecBoxChanged()
void MainWindowInputOthers::slotShowAllCheckBoxChanged()
{
setEntityAndPrefix(currentInt, currentPref);
}
Expand Down
2 changes: 1 addition & 1 deletion src/inputwidgets/mainwindowinputothers.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private slots:
void slotUSerDefinedADIFComboBoxChanged();
void slotSetCurrentUserData();
void slotPrimarySubdivisionsComboBoxChanged();
void slotShowAllChecBoxChanged();
void slotShowAllCheckBoxChanged();


private:
Expand Down

0 comments on commit 7124274

Please sign in to comment.