diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
| commit | 368f5331a7641772aa7e0cd1feea57d09a394a36 (patch) | |
| tree | b421ac60cc6eb726896ea268ea24e47fc4ce7c88 /Radio.cpp | |
| parent | 71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff) | |
| parent | 37f727ac0746fd85504aa46c1f023c09b3eff33a (diff) | |
Update upstream source from tag 'upstream/1.8.0+repack'
Update to upstream version '1.8.0+repack'
with Debian dir a83ef78cb70a32d1211871fdc08f3ffa295e45a8
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); } |
