From 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Thu, 9 Jan 2025 22:12:06 +0100 Subject: New upstream version 2.7.0~rc8+repack --- validators/CallsignValidator.cpp | 54 ++++---- validators/CallsignValidator.hpp | 46 +++---- validators/LiveFrequencyValidator.cpp | 198 +++++++++++++++--------------- validators/LiveFrequencyValidator.hpp | 108 ++++++++-------- validators/MaidenheadLocatorValidator.cpp | 146 +++++++++++----------- validators/MaidenheadLocatorValidator.hpp | 52 ++++---- validators/validators.pri | 14 +-- 7 files changed, 309 insertions(+), 309 deletions(-) (limited to 'validators') diff --git a/validators/CallsignValidator.cpp b/validators/CallsignValidator.cpp index 7b770181..d6aba538 100755 --- a/validators/CallsignValidator.cpp +++ b/validators/CallsignValidator.cpp @@ -1,27 +1,27 @@ -#include "CallsignValidator.hpp" - -CallsignValidator::CallsignValidator (QObject * parent, bool allow_compound) - : QValidator {parent} - , re_ {allow_compound ? R"(^[A-Z0-9/]+$)" : R"(^[A-Z0-9]+$)"} -{ -} - -auto CallsignValidator::validate (QString& input, int& pos) const -> State -{ - input = input.toUpper (); - while (input.size () && input[0].isSpace ()) - { - input.remove (0, 1); - if (pos > 0) --pos; - } - while (input.size () && input[input.size () - 1].isSpace ()) - { - if (pos > input.size ()) --pos; - input.chop (1); - } - auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch); - if (match.hasMatch ()) return Acceptable; - if (!input.size () || match.hasPartialMatch ()) return Intermediate; - pos = input.size (); - return Invalid; -} +#include "CallsignValidator.hpp" + +CallsignValidator::CallsignValidator (QObject * parent, bool allow_compound) + : QValidator {parent} + , re_ {allow_compound ? R"(^[A-Z0-9/]+$)" : R"(^[A-Z0-9]+$)"} +{ +} + +auto CallsignValidator::validate (QString& input, int& pos) const -> State +{ + input = input.toUpper (); + while (input.size () && input[0].isSpace ()) + { + input.remove (0, 1); + if (pos > 0) --pos; + } + while (input.size () && input[input.size () - 1].isSpace ()) + { + if (pos > input.size ()) --pos; + input.chop (1); + } + auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch); + if (match.hasMatch ()) return Acceptable; + if (!input.size () || match.hasPartialMatch ()) return Intermediate; + pos = input.size (); + return Invalid; +} diff --git a/validators/CallsignValidator.hpp b/validators/CallsignValidator.hpp index d7583cf1..f38bc3e3 100755 --- a/validators/CallsignValidator.hpp +++ b/validators/CallsignValidator.hpp @@ -1,23 +1,23 @@ -#ifndef CALLSIGN_VALIDATOR_HPP__ -#define CALLSIGN_VALIDATOR_HPP__ - -#include -#include - -// -// CallsignValidator - QValidator implementation for callsigns -// -class CallsignValidator final - : public QValidator -{ -public: - CallsignValidator (QObject * parent = nullptr, bool allow_compound = true); - - // QValidator implementation - State validate (QString& input, int& pos) const override; - -private: - QRegularExpression re_; -}; - -#endif +#ifndef CALLSIGN_VALIDATOR_HPP__ +#define CALLSIGN_VALIDATOR_HPP__ + +#include +#include + +// +// CallsignValidator - QValidator implementation for callsigns +// +class CallsignValidator final + : public QValidator +{ +public: + CallsignValidator (QObject * parent = nullptr, bool allow_compound = true); + + // QValidator implementation + State validate (QString& input, int& pos) const override; + +private: + QRegularExpression re_; +}; + +#endif diff --git a/validators/LiveFrequencyValidator.cpp b/validators/LiveFrequencyValidator.cpp index 01034c54..70c992a9 100755 --- a/validators/LiveFrequencyValidator.cpp +++ b/validators/LiveFrequencyValidator.cpp @@ -1,99 +1,99 @@ -#include "LiveFrequencyValidator.hpp" - -#include -#include -#include -#include - -#include "models/Bands.hpp" -#include "models/FrequencyList.hpp" - -#include "moc_LiveFrequencyValidator.cpp" - -LiveFrequencyValidator::LiveFrequencyValidator (QComboBox * combo_box - , Bands const * bands - , FrequencyList_v2_101 const * frequencies - , Frequency const * nominal_frequency - , QWidget * parent) - : QRegExpValidator { - QRegExp { // frequency in MHz or band - bands->data (QModelIndex {}).toString () // out of band string - + QString {R"(|((\d{0,6}(\)"} // or up to 6 digits - + QLocale {}.decimalPoint () // (followed by decimal separator - + R"(\d{0,2})?)([Mm]{1,2}|([Cc][Mm])))|(\d{0,6}(\)" // followed by up to 2 digits and either 'm' or 'cm' or 'mm' (case insensitive)) - + QLocale {}.decimalPoint () // or a decimal separator - + R"(\d{0,6})?)|(\d{0,3}(\)" // followed by up to 6 - // digits or a decimal number - + QLocale {}.decimalPoint () // or a decimal separator - + R"(\d{0,6})?[Kk]))" // followed by a 'k' or 'K' - } - , parent - } - , bands_ {bands} - , frequencies_ {frequencies} - , nominal_frequency_ {nominal_frequency} - , combo_box_ {combo_box} -{ -} - -auto LiveFrequencyValidator::validate (QString& input, int& pos) const -> State -{ - auto state = QRegExpValidator::validate (input, pos); - // by never being Acceptable we force fixup calls on ENTER or - // losing focus - return Acceptable == state ? Intermediate : state; -} - -void LiveFrequencyValidator::fixup (QString& input) const -{ - QRegExpValidator::fixup (input); - if (!bands_->oob ().startsWith (input)) - { - if (input.contains ('m', Qt::CaseInsensitive)) - { - input = input.toLower (); - - QVector frequencies; - for (auto const& item : *frequencies_) - { - if (bands_->find (item.frequency_) == input) - { - frequencies << item.frequency_; - } - } - if (!frequencies.isEmpty ()) - { - Q_EMIT valid (frequencies.first ().value ()); - } - else - { - input = QString {}; - } - } - else if (input.contains (QChar {'k'}, Qt::CaseInsensitive)) - { - // kHz in current MHz input - auto f = Radio::frequency (input.remove (QChar {'k'}, Qt::CaseInsensitive), 3); - f += *nominal_frequency_ / 1000000u * 1000000u; - input = bands_->find (f); - Q_EMIT valid (f); - } - else - { - // frequency input - auto f = Radio::frequency (input, 6); - input = bands_->find (f); - Q_EMIT valid (f); - } - - if (bands_->oob () == input) - { - combo_box_->lineEdit ()->setStyleSheet ("QLineEdit {color: yellow; background-color : red;}"); - } - else - { - combo_box_->lineEdit ()->setStyleSheet ({}); - } - combo_box_->setCurrentText (input); - } -} +#include "LiveFrequencyValidator.hpp" + +#include +#include +#include +#include + +#include "models/Bands.hpp" +#include "models/FrequencyList.hpp" + +#include "moc_LiveFrequencyValidator.cpp" + +LiveFrequencyValidator::LiveFrequencyValidator (QComboBox * combo_box + , Bands const * bands + , FrequencyList_v2_101 const * frequencies + , Frequency const * nominal_frequency + , QWidget * parent) + : QRegExpValidator { + QRegExp { // frequency in MHz or band + bands->data (QModelIndex {}).toString () // out of band string + + QString {R"(|((\d{0,6}(\)"} // or up to 6 digits + + QLocale {}.decimalPoint () // (followed by decimal separator + + R"(\d{0,2})?)([Mm]{1,2}|([Cc][Mm])))|(\d{0,6}(\)" // followed by up to 2 digits and either 'm' or 'cm' or 'mm' (case insensitive)) + + QLocale {}.decimalPoint () // or a decimal separator + + R"(\d{0,6})?)|(\d{0,3}(\)" // followed by up to 6 + // digits or a decimal number + + QLocale {}.decimalPoint () // or a decimal separator + + R"(\d{0,6})?[Kk]))" // followed by a 'k' or 'K' + } + , parent + } + , bands_ {bands} + , frequencies_ {frequencies} + , nominal_frequency_ {nominal_frequency} + , combo_box_ {combo_box} +{ +} + +auto LiveFrequencyValidator::validate (QString& input, int& pos) const -> State +{ + auto state = QRegExpValidator::validate (input, pos); + // by never being Acceptable we force fixup calls on ENTER or + // losing focus + return Acceptable == state ? Intermediate : state; +} + +void LiveFrequencyValidator::fixup (QString& input) const +{ + QRegExpValidator::fixup (input); + if (!bands_->oob ().startsWith (input)) + { + if (input.contains ('m', Qt::CaseInsensitive)) + { + input = input.toLower (); + + QVector frequencies; + for (auto const& item : *frequencies_) + { + if (bands_->find (item.frequency_) == input) + { + frequencies << item.frequency_; + } + } + if (!frequencies.isEmpty ()) + { + Q_EMIT valid (frequencies.first ().value ()); + } + else + { + input = QString {}; + } + } + else if (input.contains (QChar {'k'}, Qt::CaseInsensitive)) + { + // kHz in current MHz input + auto f = Radio::frequency (input.remove (QChar {'k'}, Qt::CaseInsensitive), 3); + f += *nominal_frequency_ / 1000000u * 1000000u; + input = bands_->find (f); + Q_EMIT valid (f); + } + else + { + // frequency input + auto f = Radio::frequency (input, 6); + input = bands_->find (f); + Q_EMIT valid (f); + } + + if (bands_->oob () == input) + { + combo_box_->lineEdit ()->setStyleSheet ("QLineEdit {color: yellow; background-color : red;}"); + } + else + { + combo_box_->lineEdit ()->setStyleSheet ({}); + } + combo_box_->setCurrentText (input); + } +} diff --git a/validators/LiveFrequencyValidator.hpp b/validators/LiveFrequencyValidator.hpp index 48c78dc1..4224d89a 100755 --- a/validators/LiveFrequencyValidator.hpp +++ b/validators/LiveFrequencyValidator.hpp @@ -1,54 +1,54 @@ -#ifndef LIVE_FREQUENCY_VALIDATOR_HPP__ -#define LIVE_FREQUENCY_VALIDATOR_HPP__ - -#include -#include - -#include "Radio.hpp" - -class Bands; -class FrequencyList_v2_101; -class QComboBox; -class QWidget; - -// -// Class LiveFrequencyValidator -// -// QLineEdit validator that controls input to an editable -// QComboBox where the user can enter a valid band or a valid -// frequency in megahetz. -// -// Collabrations -// -// Implements the QRegExpValidator interface. Validates input -// from the supplied QComboBox as either a valid frequency in -// megahertz or a valid band as defined by the supplied column of -// the supplied QAbstractItemModel. -// -class LiveFrequencyValidator final - : public QRegExpValidator -{ - Q_OBJECT; - -public: - using Frequency = Radio::Frequency; - - LiveFrequencyValidator (QComboBox * combo_box // associated combo box - , Bands const * bands // bands model - , FrequencyList_v2_101 const * frequencies // working frequencies model - , Frequency const * nominal_frequency - , QWidget * parent = nullptr); - - State validate (QString& input, int& pos) const override; - void fixup (QString& input) const override; - - Q_SIGNAL void valid (Frequency) const; - -private: - Bands const * bands_; - FrequencyList_v2_101 const * frequencies_; - Frequency const * nominal_frequency_; - QComboBox * combo_box_; -}; - -#endif +#ifndef LIVE_FREQUENCY_VALIDATOR_HPP__ +#define LIVE_FREQUENCY_VALIDATOR_HPP__ + +#include +#include + +#include "Radio.hpp" + +class Bands; +class FrequencyList_v2_101; +class QComboBox; +class QWidget; + +// +// Class LiveFrequencyValidator +// +// QLineEdit validator that controls input to an editable +// QComboBox where the user can enter a valid band or a valid +// frequency in megahetz. +// +// Collabrations +// +// Implements the QRegExpValidator interface. Validates input +// from the supplied QComboBox as either a valid frequency in +// megahertz or a valid band as defined by the supplied column of +// the supplied QAbstractItemModel. +// +class LiveFrequencyValidator final + : public QRegExpValidator +{ + Q_OBJECT; + +public: + using Frequency = Radio::Frequency; + + LiveFrequencyValidator (QComboBox * combo_box // associated combo box + , Bands const * bands // bands model + , FrequencyList_v2_101 const * frequencies // working frequencies model + , Frequency const * nominal_frequency + , QWidget * parent = nullptr); + + State validate (QString& input, int& pos) const override; + void fixup (QString& input) const override; + + Q_SIGNAL void valid (Frequency) const; + +private: + Bands const * bands_; + FrequencyList_v2_101 const * frequencies_; + Frequency const * nominal_frequency_; + QComboBox * combo_box_; +}; + +#endif diff --git a/validators/MaidenheadLocatorValidator.cpp b/validators/MaidenheadLocatorValidator.cpp index 452e5583..e7e1134c 100755 --- a/validators/MaidenheadLocatorValidator.cpp +++ b/validators/MaidenheadLocatorValidator.cpp @@ -1,73 +1,73 @@ -#include "MaidenheadLocatorValidator.hpp" - -MaidenheadLocatorValidator::MaidenheadLocatorValidator (QObject * parent, Length length, Length required) - : QValidator {parent} -{ - switch (length) - { - case Length::field: - re_.setPattern ({R"(^(?[A-Ra-r]{2})$)"}); - break; - case Length::square: - if (Length::field == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}){0,1}$)"}); - } - else - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}$)"}); - } - break; - case Length::subsquare: - if (Length::field == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}((?[A-Xa-x]{2}){0,1})){0,1}$)"}); - } - else if (Length::square == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2}){0,1}$)"}); - } - else - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})$)"}); - } - break; - case Length::extended: - if (Length::field == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}((?[A-Xa-x]{2}){0,1}([0-9]{2}){0,1})){0,1}$)"}); - } - else if (Length::square == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}((?[A-Xa-x]{2})([0-9]{2}){0,1}){0,1}$)"}); - } - else if (Length::subsquare == required) - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})([0-9]{2}){0,1}$)"}); - } - else - { - re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})[0-9]{2}$)"}); - } - break; - } -} - -auto MaidenheadLocatorValidator::validate (QString& input, int& pos) const -> State -{ - auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch); - auto field = match.captured ("field"); - if (field.size ()) - { - input.replace (match.capturedStart ("field"), match.capturedLength ("field"), field.toUpper ()); - } - auto subsquare = match.captured ("subsquare"); - if (subsquare.size ()) - { - input.replace (match.capturedStart ("subsquare"), match.capturedLength ("subsquare"), subsquare.toUpper ()); - } - if (match.hasMatch ()) return Acceptable; - if (!input.size () || match.hasPartialMatch ()) return Intermediate; - pos = input.size (); - return Invalid; -} +#include "MaidenheadLocatorValidator.hpp" + +MaidenheadLocatorValidator::MaidenheadLocatorValidator (QObject * parent, Length length, Length required) + : QValidator {parent} +{ + switch (length) + { + case Length::field: + re_.setPattern ({R"(^(?[A-Ra-r]{2})$)"}); + break; + case Length::square: + if (Length::field == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}){0,1}$)"}); + } + else + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}$)"}); + } + break; + case Length::subsquare: + if (Length::field == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}((?[A-Xa-x]{2}){0,1})){0,1}$)"}); + } + else if (Length::square == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2}){0,1}$)"}); + } + else + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})$)"}); + } + break; + case Length::extended: + if (Length::field == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})([0-9]{2}((?[A-Xa-x]{2}){0,1}([0-9]{2}){0,1})){0,1}$)"}); + } + else if (Length::square == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}((?[A-Xa-x]{2})([0-9]{2}){0,1}){0,1}$)"}); + } + else if (Length::subsquare == required) + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})([0-9]{2}){0,1}$)"}); + } + else + { + re_.setPattern ({R"(^(?[A-Ra-r]{2})[0-9]{2}(?[A-Xa-x]{2})[0-9]{2}$)"}); + } + break; + } +} + +auto MaidenheadLocatorValidator::validate (QString& input, int& pos) const -> State +{ + auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch); + auto field = match.captured ("field"); + if (field.size ()) + { + input.replace (match.capturedStart ("field"), match.capturedLength ("field"), field.toUpper ()); + } + auto subsquare = match.captured ("subsquare"); + if (subsquare.size ()) + { + input.replace (match.capturedStart ("subsquare"), match.capturedLength ("subsquare"), subsquare.toUpper ()); + } + if (match.hasMatch ()) return Acceptable; + if (!input.size () || match.hasPartialMatch ()) return Intermediate; + pos = input.size (); + return Invalid; +} diff --git a/validators/MaidenheadLocatorValidator.hpp b/validators/MaidenheadLocatorValidator.hpp index 104f7d88..25c2664b 100755 --- a/validators/MaidenheadLocatorValidator.hpp +++ b/validators/MaidenheadLocatorValidator.hpp @@ -1,26 +1,26 @@ -#ifndef MAIDENHEAD_LOCATOR_VALIDATOR_HPP__ -#define MAIDENHEAD_LOCATOR_VALIDATOR_HPP__ - -#include -#include - -// -// MaidenheadLocatorValidator - QValidator implementation for grid locators -// -class MaidenheadLocatorValidator final - : public QValidator -{ -public: - enum class Length {field = 2, square = 4, subsquare = 6, extended = 8}; - MaidenheadLocatorValidator (QObject * parent = nullptr - , Length length = Length::subsquare - , Length required = Length::square); - - // QValidator implementation - State validate (QString& input, int& pos) const override; - -private: - QRegularExpression re_; -}; - -#endif +#ifndef MAIDENHEAD_LOCATOR_VALIDATOR_HPP__ +#define MAIDENHEAD_LOCATOR_VALIDATOR_HPP__ + +#include +#include + +// +// MaidenheadLocatorValidator - QValidator implementation for grid locators +// +class MaidenheadLocatorValidator final + : public QValidator +{ +public: + enum class Length {field = 2, square = 4, subsquare = 6, extended = 8}; + MaidenheadLocatorValidator (QObject * parent = nullptr + , Length length = Length::subsquare + , Length required = Length::square); + + // QValidator implementation + State validate (QString& input, int& pos) const override; + +private: + QRegularExpression re_; +}; + +#endif diff --git a/validators/validators.pri b/validators/validators.pri index 6c126903..b8adf226 100755 --- a/validators/validators.pri +++ b/validators/validators.pri @@ -1,7 +1,7 @@ -SOURCES += \ - validators/LiveFrequencyValidator.cpp \ - validators/CallsignValidator.cpp - -HEADERS += \ - validators/LiveFrequencyValidator.hpp \ - validators/CallsignValidator.hpp +SOURCES += \ + validators/LiveFrequencyValidator.cpp \ + validators/CallsignValidator.cpp + +HEADERS += \ + validators/LiveFrequencyValidator.hpp \ + validators/CallsignValidator.hpp -- cgit v1.2.3