mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-26 22:28:41 -05:00
Fix some frequency display and l10n issues
Frequency display in the band combo box line edit was suffering floating point precision issues. Input of frequencies was not honoring current locale rules. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5881 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
74ada0ff4c
commit
d97e804347
@ -1,40 +1,41 @@
|
||||
#include "FrequencyLineEdit.hpp"
|
||||
|
||||
#include <QRegExpValidator>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
|
||||
#include "moc_FrequencyLineEdit.cpp"
|
||||
|
||||
FrequencyLineEdit::FrequencyLineEdit (QWidget * parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
setValidator (new QRegExpValidator {QRegExp {R"(\d{0,6}(\.\d{0,6})?)"}, this});
|
||||
}
|
||||
|
||||
auto FrequencyLineEdit::frequency () const -> Frequency
|
||||
{
|
||||
return Radio::frequency (text (), 6);
|
||||
}
|
||||
|
||||
void FrequencyLineEdit::frequency (Frequency f)
|
||||
{
|
||||
setText (Radio::frequency_MHz_string (f));
|
||||
}
|
||||
|
||||
|
||||
FrequencyDeltaLineEdit::FrequencyDeltaLineEdit (QWidget * parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
setValidator (new QRegExpValidator {QRegExp {R"(-?\d{0,6}(\.\d{0,6})?)"}, this});
|
||||
}
|
||||
|
||||
auto FrequencyDeltaLineEdit::frequency_delta () const -> FrequencyDelta
|
||||
{
|
||||
return Radio::frequency_delta (text (), 6);
|
||||
}
|
||||
|
||||
void FrequencyDeltaLineEdit::frequency_delta (FrequencyDelta d)
|
||||
{
|
||||
setText (Radio::frequency_MHz_string (d));
|
||||
}
|
||||
#include "FrequencyLineEdit.hpp"
|
||||
|
||||
#include <QRegExpValidator>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <QLocale>
|
||||
|
||||
#include "moc_FrequencyLineEdit.cpp"
|
||||
|
||||
FrequencyLineEdit::FrequencyLineEdit (QWidget * parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
setValidator (new QRegExpValidator {QRegExp {QString {R"(\d{0,6}(\)"} + QLocale {}.decimalPoint () + R"(\d{0,6})?)"}, this});
|
||||
}
|
||||
|
||||
auto FrequencyLineEdit::frequency () const -> Frequency
|
||||
{
|
||||
return Radio::frequency (text (), 6);
|
||||
}
|
||||
|
||||
void FrequencyLineEdit::frequency (Frequency f)
|
||||
{
|
||||
setText (Radio::frequency_MHz_string (f));
|
||||
}
|
||||
|
||||
|
||||
FrequencyDeltaLineEdit::FrequencyDeltaLineEdit (QWidget * parent)
|
||||
: QLineEdit (parent)
|
||||
{
|
||||
setValidator (new QRegExpValidator {QRegExp {QString {R"(-?\d{0,6}(\)"} + QLocale {}.decimalPoint () + R"(\d{0,6})?)"}, this});
|
||||
}
|
||||
|
||||
auto FrequencyDeltaLineEdit::frequency_delta () const -> FrequencyDelta
|
||||
{
|
||||
return Radio::frequency_delta (text (), 6);
|
||||
}
|
||||
|
||||
void FrequencyDeltaLineEdit::frequency_delta (FrequencyDelta d)
|
||||
{
|
||||
setText (Radio::frequency_MHz_string (d));
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ QVariant FrequencyList::impl::data (QModelIndex const& index, int role) const
|
||||
{
|
||||
case Qt::EditRole:
|
||||
case Qt::AccessibleTextRole:
|
||||
item = frequency_item.frequency_ / 1.e6;
|
||||
item = Radio::frequency_MHz_string (frequency_item.frequency_);
|
||||
break;
|
||||
|
||||
case Qt::DisplayRole:
|
||||
|
26
Radio.cpp
26
Radio.cpp
@ -22,14 +22,32 @@ namespace Radio
|
||||
}
|
||||
|
||||
|
||||
Frequency frequency (QVariant const& v, int scale)
|
||||
Frequency frequency (QVariant const& v, int scale, 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> ());
|
||||
}
|
||||
else
|
||||
{
|
||||
value = v.toDouble ();
|
||||
}
|
||||
return std::llround (value * std::pow (10., scale));
|
||||
}
|
||||
|
||||
FrequencyDelta frequency_delta (QVariant const& v, int scale)
|
||||
FrequencyDelta frequency_delta (QVariant const& v, int scale, 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> ());
|
||||
}
|
||||
else
|
||||
{
|
||||
value = v.toDouble ();
|
||||
}
|
||||
return std::llround (value * std::pow (10., scale));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,8 +25,8 @@ namespace Radio
|
||||
// QVariant argument is convertible to double and is assumed to
|
||||
// be scaled by (10 ** -scale).
|
||||
//
|
||||
Frequency frequency (QVariant const&, int scale);
|
||||
FrequencyDelta frequency_delta (QVariant const&, int scale);
|
||||
Frequency frequency (QVariant const&, int scale, QLocale const& = QLocale ());
|
||||
FrequencyDelta frequency_delta (QVariant const&, int scale, QLocale const& = QLocale ());
|
||||
|
||||
//
|
||||
// Frequency type formatting
|
||||
|
Loading…
Reference in New Issue
Block a user