From cd8f13b57d1c35774ec3d3b37119639cc6825341 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Mon, 1 Oct 2018 16:48:36 -0400 Subject: [PATCH] Implement a validator for FD and RTTY exchange entries. --- CMakeLists.txt | 2 +- Configuration.cpp | 5 +-- ExchangeValidator.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ ExchangeValidator.hpp | 19 ++++++++++++ lib/77bit/exch_valid.f90 | 61 ------------------------------------ mainwindow.cpp | 1 + wsjtx.pro | 6 ++-- 7 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 ExchangeValidator.cpp create mode 100644 ExchangeValidator.hpp delete mode 100644 lib/77bit/exch_valid.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9565c5060..b5e872521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Configuration.cpp b/Configuration.cpp index ba9b74bcd..26425fca0 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -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::max ()); diff --git a/ExchangeValidator.cpp b/ExchangeValidator.cpp new file mode 100644 index 000000000..e825d00ca --- /dev/null +++ b/ExchangeValidator.cpp @@ -0,0 +1,67 @@ +#include +#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(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; +} diff --git a/ExchangeValidator.hpp b/ExchangeValidator.hpp new file mode 100644 index 000000000..1e7b508dc --- /dev/null +++ b/ExchangeValidator.hpp @@ -0,0 +1,19 @@ +#ifndef EXCHANGE_VALIDATOR_HPP__ +#define EXCHANGE_VALIDATOR_HPP__ + +#include + +// 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 diff --git a/lib/77bit/exch_valid.f90 b/lib/77bit/exch_valid.f90 deleted file mode 100644 index 70613fc9a..000000000 --- a/lib/77bit/exch_valid.f90 +++ /dev/null @@ -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 diff --git a/mainwindow.cpp b/mainwindow.cpp index 713ea4c13..b13b5b290 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -58,6 +58,7 @@ #include "MultiSettings.hpp" #include "MaidenheadLocatorValidator.hpp" #include "CallsignValidator.hpp" +#include "ExchangeValidator.hpp" #include "EqualizationToolsDialog.hpp" #include "ui_mainwindow.h" diff --git a/wsjtx.pro b/wsjtx.pro index 3d16edf02..5c2124af0 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -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