diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:17:14 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:17:14 +0000 |
| commit | 37f727ac0746fd85504aa46c1f023c09b3eff33a (patch) | |
| tree | c8a7ce04545040a8f161ba279528730bd9a3e6ab /Radio.cpp | |
| parent | d63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff) | |
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'Radio.cpp')
| -rw-r--r-- | Radio.cpp | 65 |
1 files changed, 44 insertions, 21 deletions
@@ -1,32 +1,16 @@ #include "Radio.hpp" #include <cmath> +#include <limits> -#include <QMetaType> #include <QString> #include <QChar> -#include <QDebug> -#include <QRegExpValidator> -#include <QDataStream> #include <QRegularExpression> namespace Radio { namespace { - struct init - { - init () - { - qRegisterMetaType<Frequency> ("Frequency"); - - qRegisterMetaType<Frequencies> ("Frequencies"); - qRegisterMetaTypeStreamOperators<Frequencies> ("Frequencies"); - - qRegisterMetaType<FrequencyDelta> ("FrequencyDelta"); - } - } static_initaializer; - double constexpr MHz_factor {1.e6}; int constexpr frequency_precsion {6}; @@ -36,14 +20,53 @@ namespace Radio } - Frequency frequency (QVariant const& v, int scale) + Frequency frequency (QVariant const& v, int scale, bool * ok, QLocale const& locale) { - return std::llround (v.toDouble () * std::pow (10., scale)); + double value {0.}; + if (QVariant::String == v.type ()) + { + value = locale.toDouble (v.value<QString> (), ok); + } + else + { + value = v.toDouble (); + if (ok) *ok = true; + } + value *= std::pow (10., scale); + if (ok) + { + if (value < 0. || value > std::numeric_limits<Frequency>::max ()) + { + value = 0.; + *ok = false; + } + } + return std::llround (value); } - FrequencyDelta frequency_delta (QVariant const& v, int scale) + FrequencyDelta frequency_delta (QVariant const& v, int scale, bool * ok, QLocale const& locale) { - return std::llround (v.toDouble () * std::pow (10., scale)); + double value {0.}; + if (QVariant::String == v.type ()) + { + value = locale.toDouble (v.value<QString> (), ok); + } + else + { + value = v.toDouble (); + if (ok) *ok = true; + } + value *= std::pow (10., scale); + if (ok) + { + if (value < -std::numeric_limits<Frequency>::max () + || value > std::numeric_limits<Frequency>::max ()) + { + value = 0.; + *ok = false; + } + } + return std::llround (value); } |
