summaryrefslogtreecommitdiff
path: root/Radio.cpp
diff options
context:
space:
mode:
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);
}