From 37f727ac0746fd85504aa46c1f023c09b3eff33a Mon Sep 17 00:00:00 2001 From: hibby Date: Fri, 16 Feb 2018 15:17:14 +0000 Subject: New upstream version 1.8.0+repack --- Radio.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'Radio.cpp') diff --git a/Radio.cpp b/Radio.cpp index 961fc1d4..4eecd931 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -1,32 +1,16 @@ #include "Radio.hpp" #include +#include -#include #include #include -#include -#include -#include #include namespace Radio { namespace { - struct init - { - init () - { - qRegisterMetaType ("Frequency"); - - qRegisterMetaType ("Frequencies"); - qRegisterMetaTypeStreamOperators ("Frequencies"); - - qRegisterMetaType ("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 (), ok); + } + else + { + value = v.toDouble (); + if (ok) *ok = true; + } + value *= std::pow (10., scale); + if (ok) + { + if (value < 0. || value > std::numeric_limits::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 (), ok); + } + else + { + value = v.toDouble (); + if (ok) *ok = true; + } + value *= std::pow (10., scale); + if (ok) + { + if (value < -std::numeric_limits::max () + || value > std::numeric_limits::max ()) + { + value = 0.; + *ok = false; + } + } + return std::llround (value); } -- cgit v1.2.3