summaryrefslogtreecommitdiff
path: root/Radio.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:18:44 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:18:44 +0000
commit368f5331a7641772aa7e0cd1feea57d09a394a36 (patch)
treeb421ac60cc6eb726896ea268ea24e47fc4ce7c88 /Radio.cpp
parent71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff)
parent37f727ac0746fd85504aa46c1f023c09b3eff33a (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.cpp65
1 files changed, 44 insertions, 21 deletions
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 <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);
}