Implement a validator for FD and RTTY exchange entries.

This commit is contained in:
Joe Taylor 2018-10-01 16:48:36 -04:00
parent 1fbc51ddd9
commit cd8f13b57d
7 changed files with 95 additions and 66 deletions

View File

@ -257,6 +257,7 @@ set (wsjt_qt_CXXSRCS
MultiSettings.cpp
MaidenheadLocatorValidator.cpp
CallsignValidator.cpp
ExchangeValidator.cpp
SplashScreen.cpp
EqualizationToolsDialog.cpp
DoubleClickablePushButton.cpp
@ -411,7 +412,6 @@ set (wsjt_FSRCS
lib/ft8/encode174_91.f90
lib/entail.f90
lib/ephem.f90
lib/77bit/exch_valid.f90
lib/extract.f90
lib/extract4.f90
lib/extractmessage144.f90

View File

@ -180,6 +180,7 @@
#include "MessageBox.hpp"
#include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp"
#include "ExchangeValidator.hpp"
#include "ui_Configuration.h"
#include "moc_Configuration.cpp"
@ -997,12 +998,12 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
// this must be done after the default paths above are set
read_settings ();
//
// validation
//
ui_->callsign_line_edit->setValidator (new CallsignValidator {this});
ui_->grid_line_edit->setValidator (new MaidenheadLocatorValidator {this});
ui_->add_macro_line_edit->setValidator (new QRegExpValidator {message_alphabet, this});
ui_->FieldDay_Exchange->setValidator(new ExchangeValidator{this});
ui_->RTTY_Exchange->setValidator(new ExchangeValidator{this});
ui_->udp_server_port_spin_box->setMinimum (1);
ui_->udp_server_port_spin_box->setMaximum (std::numeric_limits<port_type>::max ());

67
ExchangeValidator.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <QDebug>
#include "ExchangeValidator.hpp"
ExchangeValidator::ExchangeValidator (QObject * parent)
: QValidator {parent}
{
}
auto ExchangeValidator::validate (QString& input, int& length) const -> State
{
bool ok=false;
QStringList w=input.split(" ");
int nwords=w.size();
length=input.size();
input = input.toUpper ();
if(nwords==1 and length<=3) {
//ARRL RTTY Roundup
// ntype=4;
// ok=exch_valid_(&ntype, const_cast<char *>(input.toLatin1().constData()),length);
QStringList states;
states << "AL" << "AK" << "AZ" << "AR" << "CA" << "CO"
<< "CT" << "DE" << "FL" << "GA" << "HI" << "ID"
<< "IL" << "IN" << "IA" << "KS" << "KY" << "LA"
<< "ME" << "MD" << "MA" << "MI" << "MN" << "MS"
<< "MO" << "MT" << "NE" << "NV" << "NH" << "NJ"
<< "NM" << "NY" << "NC" << "ND" << "OH" << "OK"
<< "OR" << "PA" << "RI" << "SC" << "SD" << "TN"
<< "TX" << "UT" << "VT" << "VA" << "WA" << "WV"
<< "WI" << "WY" << "NB" << "NS" << "QC" << "ON"
<< "MB" << "SK" << "AB" << "BC" << "NWT" << "NF"
<< "LB" << "NU" << "YT" << "PEI" << "DC" << "DX";
if(states.contains(input)) ok=true;
}
if(nwords==2 and w.at(1).size()<=3) {
//ARRL Field Day
int n=w.at(0).size();
if(n>3) goto done;
int ntx=w.at(0).left(n-1).toInt();
if(ntx<1 or ntx>32) goto done;
QString c1=w.at(0).right(1);
if(c1<"A" or c1>"F") goto done;
QStringList sections;
sections << "AB" << "AK" << "AL" << "AR" << "AZ" << "BC"
<< "CO" << "CT" << "DE" << "EB" << "EMA" << "ENY"
<< "EPA" << "EWA" << "GA" << "GTA" << "IA" << "ID"
<< "IL" << "IN" << "KS" << "KY" << "LA" << "LAX"
<< "MAR" << "MB" << "MDC" << "ME" << "MI" << "MN"
<< "MO" << "MS" << "MT" << "NC" << "ND" << "NE"
<< "NFL" << "NH" << "NL" << "NLI" << "NM" << "NNJ"
<< "NNY" << "NT" << "NTX" << "NV" << "OH" << "OK"
<< "ONE" << "ONN" << "ONS" << "OR" << "ORG" << "PAC"
<< "PR" << "QC" << "RI" << "SB" << "SC" << "SCV"
<< "SD" << "SDG" << "SF" << "SFL" << "SJV" << "SK"
<< "SNJ" << "STX" << "SV" << "TN" << "UT" << "VA"
<< "VI" << "VT" << "WCF" << "WI" << "WMA" << "WNY"
<< "WPA" << "WTX" << "WV" << "WWA" << "WY" << "DX";
if(sections.contains(w.at(1))) ok=true;
}
done:
qDebug() << input << ok;
if(ok) return Acceptable;
// return Invalid;
return Acceptable;
}

19
ExchangeValidator.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef EXCHANGE_VALIDATOR_HPP__
#define EXCHANGE_VALIDATOR_HPP__
#include <QValidator>
// ExchangeValidator - QValidator for Field Day and RTTY Roundup exchanges
class ExchangeValidator final
: public QValidator
{
public:
ExchangeValidator (QObject * parent = nullptr);
// QValidator implementation
State validate (QString& input, int& length) const override;
};
#endif

View File

@ -1,61 +0,0 @@
logical*1 function exch_valid(ntype,exch)
parameter (NSEC=84) !Number of ARRL Sections
parameter (NUSCAN=65) !Number of US states and Canadian provinces
character*(*) exch
character*3 c3
character*3 cmult(NUSCAN)
character*3 csec(NSEC)
data csec/ &
"AB ","AK ","AL ","AR ","AZ ","BC ","CO ","CT ","DE ","EB ", &
"EMA","ENY","EPA","EWA","GA ","GTA","IA ","ID ","IL ","IN ", &
"KS ","KY ","LA ","LAX","MAR","MB ","MDC","ME ","MI ","MN ", &
"MO ","MS ","MT ","NC ","ND ","NE ","NFL","NH ","NL ","NLI", &
"NM ","NNJ","NNY","NT ","NTX","NV ","OH ","OK ","ONE","ONN", &
"ONS","OR ","ORG","PAC","PR ","QC ","RI ","SB ","SC ","SCV", &
"SD ","SDG","SF ","SFL","SJV","SK ","SNJ","STX","SV ","TN ", &
"UT ","VA ","VI ","VT ","WCF","WI ","WMA","WNY","WPA","WTX", &
"WV ","WWA","WY ","DX "/
data cmult/ &
"AL ","AK ","AZ ","AR ","CA ","CO ","CT ","DE ","FL ","GA ", &
"HI ","ID ","IL ","IN ","IA ","KS ","KY ","LA ","ME ","MD ", &
"MA ","MI ","MN ","MS ","MO ","MT ","NE ","NV ","NH ","NJ ", &
"NM ","NY ","NC ","ND ","OH ","OK ","OR ","PA ","RI ","SC ", &
"SD ","TN ","TX ","UT ","VT ","VA ","WA ","WV ","WI ","WY ", &
"NB ","NS ","QC ","ON ","MB ","SK ","AB ","BC ","NWT","NF ", &
"LB ","NU ","YT ","PEI","DC "/
exch_valid=.false.
n=len(trim(exch))
if(ntype.ne.3 .and. ntype.ne.4) go to 900
if(ntype.eq.3 .and. (n.lt.2 .or. n.gt.7)) go to 900
if(ntype.eq.4 .and. (n.lt.2 .or. n.gt.3)) go to 900
if(ntype.eq.3) then !Field Day
i1=index(exch,' ')
if(i1.lt.3) go to 900
read(exch(1:i1-2),*,err=900) ntx
if(ntx.lt.1 .or. ntx.gt.32) go to 900
if(exch(i1-1:i1-1).lt.'A' .or. exch(i1-1:i1-1).gt.'F') go to 900
c3=exch(i1+1:)//' '
do i=1,NSEC
if(csec(i).eq.c3) then
exch_valid=.true.
go to 900
endif
enddo
else if(ntype.eq.4) then !RTTY Roundup
c3=exch//' '
do i=1,NUSCAN
if(cmult(i).eq.c3) then
exch_valid=.true.
go to 900
endif
enddo
endif
900 return
end function exch_valid

View File

@ -58,6 +58,7 @@
#include "MultiSettings.hpp"
#include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp"
#include "ExchangeValidator.hpp"
#include "EqualizationToolsDialog.hpp"
#include "ui_mainwindow.h"

View File

@ -67,7 +67,8 @@ SOURCES += \
echoplot.cpp echograph.cpp fastgraph.cpp fastplot.cpp Modes.cpp \
WSPRBandHopping.cpp MessageAggregator.cpp SampleDownloader.cpp qt_helpers.cpp\
MultiSettings.cpp PhaseEqualizationDialog.cpp IARURegions.cpp MessageBox.cpp \
EqualizationToolsDialog.cpp CallsignValidator.cpp colorhighlighting.cpp
EqualizationToolsDialog.cpp CallsignValidator.cpp ExchangeValidator.cpp \
colorhighlighting.cpp
HEADERS += qt_helpers.hpp \
pimpl_h.hpp pimpl_impl.hpp \
@ -83,7 +84,8 @@ HEADERS += qt_helpers.hpp \
logbook/logbook.h logbook/countrydat.h logbook/countriesworked.h logbook/adif.h \
messageaveraging.h echoplot.h echograph.h fastgraph.h fastplot.h Modes.hpp WSPRBandHopping.hpp \
WsprTxScheduler.h SampleDownloader.hpp MultiSettings.hpp PhaseEqualizationDialog.hpp \
IARURegions.hpp MessageBox.hpp EqualizationToolsDialog.hpp CallsignValidator.hpp colorhighlighting.h
IARURegions.hpp MessageBox.hpp EqualizationToolsDialog.hpp CallsignValidator.hpp \
ExchangeValidator.hpp colorhighlighting.h
INCLUDEPATH += qmake_only