mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-07 16:34:45 -04:00
Add frequency scanner channel plugin
This commit is contained in:
@@ -15,9 +15,11 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "frequencydelegate.h"
|
||||
|
||||
FrequencyDelegate::FrequencyDelegate(QString units, int precision, bool group) :
|
||||
FrequencyDelegate::FrequencyDelegate(const QString& units, int precision, bool group) :
|
||||
m_units(units),
|
||||
m_precision(precision),
|
||||
m_group(group)
|
||||
@@ -30,29 +32,107 @@ QString FrequencyDelegate::displayText(const QVariant &value, const QLocale &loc
|
||||
qlonglong v = value.toLongLong(&ok);
|
||||
if (ok)
|
||||
{
|
||||
double d;
|
||||
if (m_units == "GHz") {
|
||||
d = v / 1000000000.0;
|
||||
} else if (m_units == "MHz") {
|
||||
d = v / 1000000.0;
|
||||
} else if (m_units == "kHz") {
|
||||
d = v / 1000.0;
|
||||
} else {
|
||||
d = v;
|
||||
}
|
||||
|
||||
QLocale l(locale);
|
||||
if (m_group) {
|
||||
l.setNumberOptions(l.numberOptions() & ~QLocale::OmitGroupSeparator);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
l.setNumberOptions(l.numberOptions() | QLocale::OmitGroupSeparator);
|
||||
}
|
||||
QString s = l.toString(d, 'f', m_precision);
|
||||
|
||||
return QString("%1 %2").arg(s).arg(m_units);
|
||||
if (m_units == "Auto")
|
||||
{
|
||||
if (v == 0)
|
||||
{
|
||||
return "0 Hz";
|
||||
}
|
||||
else
|
||||
{
|
||||
QString s = QString::number(v);
|
||||
int scale = 1;
|
||||
while (s.endsWith("000"))
|
||||
{
|
||||
s.chop(3);
|
||||
scale *= 1000;
|
||||
}
|
||||
v /= scale;
|
||||
double d = v;
|
||||
if ((abs(v) >= 1000) && (m_precision >= 3))
|
||||
{
|
||||
scale *= 1000;
|
||||
d /= 1000.0;
|
||||
}
|
||||
QString units;
|
||||
if (scale == 1) {
|
||||
units = "Hz";
|
||||
} else if (scale == 1000) {
|
||||
units = "kHz";
|
||||
} else if (scale == 1000000) {
|
||||
units = "MHz";
|
||||
} else if (scale == 1000000000) {
|
||||
units = "GHz";
|
||||
}
|
||||
if (scale == 1) {
|
||||
s = l.toString(d, 'f', 0);
|
||||
} else {
|
||||
s = l.toString(d, 'f', m_precision);
|
||||
}
|
||||
|
||||
return QString("%1 %2").arg(s).arg(units);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double d;
|
||||
if (m_units == "GHz") {
|
||||
d = v / 1000000000.0;
|
||||
}
|
||||
else if (m_units == "MHz") {
|
||||
d = v / 1000000.0;
|
||||
}
|
||||
else if (m_units == "kHz") {
|
||||
d = v / 1000.0;
|
||||
}
|
||||
else {
|
||||
d = v;
|
||||
}
|
||||
|
||||
|
||||
QString s = l.toString(d, 'f', m_precision);
|
||||
|
||||
return QString("%1 %2").arg(s).arg(m_units);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* FrequencyDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* editor = new QLineEdit(parent);
|
||||
QIntValidator* validator = new QIntValidator();
|
||||
validator->setBottom(0);
|
||||
editor->setValidator(validator);
|
||||
return editor;
|
||||
}
|
||||
|
||||
void FrequencyDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
QString value = index.model()->data(index, Qt::EditRole).toString();
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(value);
|
||||
}
|
||||
|
||||
void FrequencyDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
QString value = line->text();
|
||||
model->setData(index, value);
|
||||
}
|
||||
|
||||
void FrequencyDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user