diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /validators | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg'
with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'validators')
| -rw-r--r-- | validators/CallsignValidator.cpp | 11 | ||||
| -rw-r--r-- | validators/CallsignValidator.hpp | 2 | ||||
| -rw-r--r-- | validators/LiveCQCallsign.cpp | 64 | ||||
| -rw-r--r-- | validators/LiveCQCallsign.hpp | 11 | ||||
| -rw-r--r-- | validators/LiveFrequencyValidator.cpp | 16 | ||||
| -rw-r--r-- | validators/LiveFrequencyValidator.hpp | 1 | ||||
| -rw-r--r-- | validators/validators.pri | 7 |
7 files changed, 102 insertions, 10 deletions
diff --git a/validators/CallsignValidator.cpp b/validators/CallsignValidator.cpp index d6aba538..5fbebfe4 100644 --- a/validators/CallsignValidator.cpp +++ b/validators/CallsignValidator.cpp @@ -6,6 +6,17 @@ CallsignValidator::CallsignValidator (QObject * parent, bool allow_compound) { } +QString CallsignValidator::normalizeStoredInput (QString input, int max_length, + bool allow_compound) +{ + input = input.trimmed (); + input.truncate (max_length); + CallsignValidator validator {nullptr, allow_compound}; + auto pos = input.size (); + if (Invalid == validator.validate (input, pos)) input.clear (); + return input; +} + auto CallsignValidator::validate (QString& input, int& pos) const -> State { input = input.toUpper (); diff --git a/validators/CallsignValidator.hpp b/validators/CallsignValidator.hpp index f38bc3e3..ef061b01 100644 --- a/validators/CallsignValidator.hpp +++ b/validators/CallsignValidator.hpp @@ -12,6 +12,8 @@ class CallsignValidator final { public: CallsignValidator (QObject * parent = nullptr, bool allow_compound = true); + static QString normalizeStoredInput (QString input, int max_length, + bool allow_compound = true); // QValidator implementation State validate (QString& input, int& pos) const override; diff --git a/validators/LiveCQCallsign.cpp b/validators/LiveCQCallsign.cpp new file mode 100644 index 00000000..14f151bf --- /dev/null +++ b/validators/LiveCQCallsign.cpp @@ -0,0 +1,64 @@ +#include "LiveCQCallsign.hpp" + +#include <QStringList> +#include <QtGlobal> + +namespace LiveCQ +{ + bool isValidCallsign (QString const& callsign) + { + auto callsignWithoutMarkers = callsign; + if (callsignWithoutMarkers.contains('.') + || callsignWithoutMarkers.contains('+') + || callsignWithoutMarkers.contains('-') + || callsignWithoutMarkers.contains('?')) { + return false; + } + callsignWithoutMarkers.remove('<'); + callsignWithoutMarkers.remove('>'); + if (callsignWithoutMarkers.length() > 11) { + return false; + } + + auto const parts = callsignWithoutMarkers.split('/'); + auto baseCall = callsignWithoutMarkers; + if (parts.size() > 1) { + baseCall = parts.at(0).length() > parts.at(1).length() + ? parts.at(0) : parts.at(1); + } + baseCall = baseCall.trimmed(); + auto const baseLength = baseCall.length(); + if (baseLength < 3 || baseLength > 8) { + return false; + } + + if (!baseCall.at(0).isLetter() && !baseCall.at(1).isLetter()) { + return false; + } + if (baseCall.at(0) == 'Q' && baseCall.mid(0, 5) != "QU1RK") { + return false; + } + + int digitPosition = 0; + for (int i = 1; i < qMin<int>(static_cast<int> (baseLength), 4); ++i) { + if (baseCall.at(i).isDigit()) { + digitPosition = i; + } + } + if (digitPosition == 0 || digitPosition == baseLength) { + return false; + } + + auto const suffixLength = baseLength - digitPosition - 1; + if (suffixLength < 1 || suffixLength > 4) { + return false; + } + for (int i = digitPosition + 1; i < baseLength; ++i) { + auto const character = baseCall.at(i); + if (character < QChar {'A'} || character > QChar {'Z'}) { + return false; + } + } + return true; + } +} diff --git a/validators/LiveCQCallsign.hpp b/validators/LiveCQCallsign.hpp new file mode 100644 index 00000000..489e1857 --- /dev/null +++ b/validators/LiveCQCallsign.hpp @@ -0,0 +1,11 @@ +#ifndef LIVE_CQ_CALLSIGN_HPP__ +#define LIVE_CQ_CALLSIGN_HPP__ + +#include <QString> + +namespace LiveCQ +{ + bool isValidCallsign (QString const& callsign); +} + +#endif diff --git a/validators/LiveFrequencyValidator.cpp b/validators/LiveFrequencyValidator.cpp index 4a15daf2..11b35654 100644 --- a/validators/LiveFrequencyValidator.cpp +++ b/validators/LiveFrequencyValidator.cpp @@ -36,6 +36,8 @@ LiveFrequencyValidator::LiveFrequencyValidator (QComboBox * combo_box , combo_box_ {combo_box} , kHz_without_k_ {kHz_without_k} { + connect (combo_box_->lineEdit (), &QLineEdit::textEdited, this, + [this] (QString const&) {user_edited_ = true;}); } auto LiveFrequencyValidator::validate (QString& input, int& pos) const -> State @@ -48,6 +50,10 @@ auto LiveFrequencyValidator::validate (QString& input, int& pos) const -> State void LiveFrequencyValidator::fixup (QString& input) const { + auto const user_edited = user_edited_; + user_edited_ = false; + Frequency requested_frequency {0}; + bool has_requested_frequency {false}; QRegExpValidator::fixup (input); if (!bands_->oob ().startsWith (input)) { @@ -65,7 +71,8 @@ void LiveFrequencyValidator::fixup (QString& input) const } if (!frequencies.isEmpty ()) { - Q_EMIT valid (frequencies.first ().value<Frequency> ()); + requested_frequency = frequencies.first ().value<Frequency> (); + has_requested_frequency = true; } else { @@ -78,14 +85,16 @@ void LiveFrequencyValidator::fixup (QString& input) const auto f = Radio::frequency (input.remove (QChar {'k'}, Qt::CaseInsensitive), 3); f += *nominal_frequency_ / 1000000u * 1000000u; input = bands_->find (f); - Q_EMIT valid (f); + requested_frequency = f; + has_requested_frequency = true; } else { // frequency input auto f = Radio::frequency (input.remove (QChar {'M'}, Qt::CaseSensitive), 6); input = bands_->find (f); - Q_EMIT valid (f); + requested_frequency = f; + has_requested_frequency = true; } if (bands_->oob () == input) @@ -97,5 +106,6 @@ void LiveFrequencyValidator::fixup (QString& input) const combo_box_->lineEdit ()->setStyleSheet ({}); } combo_box_->setCurrentText (input); + if (user_edited && has_requested_frequency) Q_EMIT valid (requested_frequency); } } diff --git a/validators/LiveFrequencyValidator.hpp b/validators/LiveFrequencyValidator.hpp index f0ab05fb..9a70327c 100644 --- a/validators/LiveFrequencyValidator.hpp +++ b/validators/LiveFrequencyValidator.hpp @@ -52,6 +52,7 @@ private: Frequency const * nominal_frequency_; QComboBox * combo_box_; bool kHz_without_k_ = false; + mutable bool user_edited_ = false; }; #endif diff --git a/validators/validators.pri b/validators/validators.pri deleted file mode 100644 index b8adf226..00000000 --- a/validators/validators.pri +++ /dev/null @@ -1,7 +0,0 @@ -SOURCES += \ - validators/LiveFrequencyValidator.cpp \ - validators/CallsignValidator.cpp - -HEADERS += \ - validators/LiveFrequencyValidator.hpp \ - validators/CallsignValidator.hpp |
