diff options
| author | Christoph Berg <myon@debian.org> | 2026-04-07 19:04:48 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-04-07 19:04:48 +0200 |
| commit | 9b9d6a272fa4204d45956828da3f20b7be49f675 (patch) | |
| tree | b611f981259a12a2bfd4d7305843929447f1bb74 /validators/LiveFrequencyValidator.cpp | |
| parent | 2f7ab3ab46786fa2a5931dae22a1b119b5cfdafa (diff) | |
| parent | f647d78463c1250ce9c99af664615fafccf5e959 (diff) | |
Update upstream source from tag 'upstream/3.0.0'
Update to upstream version '3.0.0'
with Debian dir 3b764e9a4be12ad8351230b538640dd98ddb9d05
Diffstat (limited to 'validators/LiveFrequencyValidator.cpp')
| -rw-r--r--[-rwxr-xr-x] | validators/LiveFrequencyValidator.cpp | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/validators/LiveFrequencyValidator.cpp b/validators/LiveFrequencyValidator.cpp index 6bd826d7..4a15daf2 100755..100644 --- a/validators/LiveFrequencyValidator.cpp +++ b/validators/LiveFrequencyValidator.cpp @@ -1,101 +1,101 @@ -#include "LiveFrequencyValidator.hpp"
-
-#include <QLocale>
-#include <QString>
-#include <QComboBox>
-#include <QLineEdit>
-
-#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
- , bool kHz_without_k
- , 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}
- , kHz_without_k_ {kHz_without_k}
-{
-}
-
-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::CaseSensitive))
- {
- input = input.toLower ();
-
- QVector<QVariant> frequencies;
- for (auto const& item : *frequencies_)
- {
- if (bands_->find (item.frequency_) == input)
- {
- frequencies << item.frequency_;
- }
- }
- if (!frequencies.isEmpty ())
- {
- Q_EMIT valid (frequencies.first ().value<Frequency> ());
- }
- else
- {
- input = QString {};
- }
- }
- else if ((input.contains (QChar {'k'}, Qt::CaseInsensitive)) or (kHz_without_k_ && !input.contains (QChar {'M'}, Qt::CaseSensitive)))
- {
- // 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.remove (QChar {'M'}, Qt::CaseSensitive), 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 <QLocale> +#include <QString> +#include <QComboBox> +#include <QLineEdit> + +#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 + , bool kHz_without_k + , 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} + , kHz_without_k_ {kHz_without_k} +{ +} + +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::CaseSensitive)) + { + input = input.toLower (); + + QVector<QVariant> frequencies; + for (auto const& item : *frequencies_) + { + if (bands_->find (item.frequency_) == input) + { + frequencies << item.frequency_; + } + } + if (!frequencies.isEmpty ()) + { + Q_EMIT valid (frequencies.first ().value<Frequency> ()); + } + else + { + input = QString {}; + } + } + else if ((input.contains (QChar {'k'}, Qt::CaseInsensitive)) or (kHz_without_k_ && !input.contains (QChar {'M'}, Qt::CaseSensitive))) + { + // 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.remove (QChar {'M'}, Qt::CaseSensitive), 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); + } +} |
