SoapySDR support: GUI for ArgInfo types

pull/263/head
f4exb 2018-11-10 19:52:27 +01:00
rodzic 8a72372b28
commit 3c9d1a3637
4 zmienionych plików z 554 dodań i 0 usunięć

Wyświetl plik

@ -61,6 +61,7 @@ set(sdrgui_SOURCES
soapygui/dynamicitemsettinggui.cpp
soapygui/intervalslidergui.cpp
soapygui/complexfactorgui.cpp
soapygui/arginfogui.cpp
webapi/webapiadaptergui.cpp
)
@ -126,6 +127,7 @@ set(sdrgui_HEADERS
soapygui/dynamicitemsettinggui.h
soapygui/intervalslidergui.h
soapygui/complexfactorgui.h
soapygui/arginfogui.h
webapi/webapiadaptergui.h
)
@ -159,6 +161,7 @@ set(sdrgui_FORMS
soapygui/intervalrangegui.ui
soapygui/intervalslidergui.ui
soapygui/complexfactorgui.ui
soapygui/arginfogui.ui
)
set(sdrgui_RESOURCES

Wyświetl plik

@ -0,0 +1,374 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <math.h>
#include <QHBoxLayout>
#include "ui_arginfogui.h"
#include "arginfogui.h"
ArgInfoGUI::ArgInfoGUI(ArgInfoType type, ArgInfoValueType valueType, QWidget *parent) :
QWidget(parent),
ui(new Ui::ArgInfoGUI),
m_type(type),
m_valueType(valueType),
m_boolValue(false),
m_intValue(0),
m_floatValue(0.0),
m_hasRange(false),
m_minValue(0.0),
m_maxValue(0.0)
{
ui->setupUi(this);
QHBoxLayout *layout = ui->argLayout;
if (m_type != ArgInfoBinary) {
layout->removeWidget(ui->argCheck);
}
if (m_type != ArgInfoContinuous) {
layout->removeWidget(ui->argEdit);
}
if (m_type != ArgInfoDiscrete) {
layout->removeWidget(ui->argCombo);
}
}
ArgInfoGUI::~ArgInfoGUI()
{
delete ui;
}
void ArgInfoGUI::setRange(double min, double max)
{
m_hasRange = true;
m_minValue = min;
m_maxValue = max;
}
void ArgInfoGUI::setLabel(const QString& text)
{
ui->argLabel->setText(text);
}
void ArgInfoGUI::setUnits(const QString& units)
{
ui->argUnits->setText(units);
}
void ArgInfoGUI::setBoolValue(bool value)
{
if (m_valueType == ArgInfoValueBool)
{
m_boolValue = value;
updateUIFromBool();
}
else if (m_valueType == ArgInfoValueInt)
{
m_intValue = setIntegerValue(value ? 1 : 0);
updateUIFromInt();
}
else if (m_valueType == ArgInfoValueFloat)
{
m_floatValue = setDoubleValue(value ? 1.0 : 0.0);
updateUIFromFloat();
}
else if (m_valueType == ArgInfoValueString)
{
m_stringValue = QString(value ? "true" : "false");
updateUIFromString();
}
}
void ArgInfoGUI::addBoolValue(const QString& text, bool value)
{
if (m_type == ArgInfoDiscrete) {
ui->argCombo->addItem(text, QVariant(value));
}
}
void ArgInfoGUI::setIntValue(int value)
{
if (m_valueType == ArgInfoValueBool)
{
m_boolValue = (value != 0);
updateUIFromBool();
}
else if (m_valueType == ArgInfoValueInt)
{
m_intValue = setIntegerValue(value);
updateUIFromInt();
}
else if (m_valueType == ArgInfoValueFloat)
{
m_floatValue = setDoubleValue(value);
updateUIFromFloat();
}
else if (m_valueType == ArgInfoValueString)
{
m_stringValue = QString("%1").arg(value);
updateUIFromString();
}
}
void ArgInfoGUI::addIntValue(const QString& text, int value)
{
if (m_type == ArgInfoDiscrete) {
ui->argCombo->addItem(text, QVariant(setIntegerValue(value)));
}
}
void ArgInfoGUI::setFloatValue(double value)
{
if (m_valueType == ArgInfoValueBool)
{
m_boolValue = (value != 0.0);
updateUIFromBool();
}
else if (m_valueType == ArgInfoValueInt)
{
m_intValue = setIntegerValue(value);
updateUIFromInt();
}
else if (m_valueType == ArgInfoValueFloat)
{
m_floatValue = setDoubleValue(value);
updateUIFromFloat();
}
else if (m_valueType == ArgInfoValueString)
{
m_stringValue = QString("%1").arg(value);
updateUIFromString();
}
}
void ArgInfoGUI::addFloatValue(const QString& text, double value)
{
if (m_type == ArgInfoDiscrete) {
ui->argCombo->addItem(text, QVariant(setDoubleValue(value)));
}
}
void ArgInfoGUI::setStringValue(const QString& value)
{
if (m_valueType == ArgInfoValueBool)
{
m_boolValue = (value == "true");
updateUIFromBool();
}
else if (m_valueType == ArgInfoValueInt)
{
int intValue = atoi(value.toStdString().c_str());
m_intValue = setIntegerValue(intValue);
updateUIFromInt();
}
else if (m_valueType == ArgInfoValueFloat)
{
double doubleValue = atof(value.toStdString().c_str());
m_floatValue = setDoubleValue(doubleValue);
updateUIFromFloat();
}
else if (m_valueType == ArgInfoValueString)
{
m_stringValue = value;
updateUIFromString();
}
}
void ArgInfoGUI::addStringValue(const QString& text, const QString& value)
{
if (m_type == ArgInfoDiscrete) {
ui->argCombo->addItem(text, QVariant(value));
}
}
int ArgInfoGUI::setIntegerValue(int value)
{
if (m_hasRange) {
return value < round(m_minValue) ? round(m_minValue) : value > round(m_maxValue) ? round(m_maxValue) : value;
} else {
return value;
}
}
double ArgInfoGUI::setDoubleValue(double value)
{
if (m_hasRange) {
return value < m_minValue ? m_minValue : value > m_maxValue ? m_maxValue : value;
} else {
return value;
}
}
void ArgInfoGUI::updateUIFromBool()
{
if (m_type == ArgInfoBinary)
{
ui->argCheck->blockSignals(true);
ui->argCheck->setChecked(m_boolValue);
ui->argCheck->blockSignals(false);
}
else if (m_type == ArgInfoContinuous)
{
ui->argEdit->blockSignals(true);
ui->argEdit->setText(QString(m_boolValue ? "true" : "false"));
ui->argEdit->blockSignals(false);
}
else if (m_type == ArgInfoDiscrete)
{
if (ui->argCombo->count() > 1)
{
ui->argCombo->blockSignals(true);
ui->argCombo->setCurrentIndex(m_boolValue ? 0 : 1);
ui->argCombo->blockSignals(false);
}
}
}
void ArgInfoGUI::updateUIFromInt()
{
if (m_type == ArgInfoBinary)
{
ui->argCheck->blockSignals(true);
ui->argCheck->setChecked(m_intValue == 0 ? false : true);
ui->argCheck->blockSignals(false);
}
else if (m_type == ArgInfoContinuous)
{
ui->argEdit->blockSignals(true);
ui->argEdit->setText(QString("%1").arg(m_intValue));
ui->argEdit->blockSignals(false);
}
else if (m_type == ArgInfoDiscrete)
{
for (int i = 0; i < ui->argCombo->count(); i++)
{
if (ui->argCombo->itemData(i).type() == QVariant::Int)
{
bool ok = false;
QVariant v = ui->argCombo->itemData(i);
if (m_intValue >= v.toInt(&ok) && ok)
{
ui->argCombo->blockSignals(true);
ui->argCombo->setCurrentIndex(i);
ui->argCombo->blockSignals(false);
break;
}
}
}
}
}
void ArgInfoGUI::updateUIFromFloat()
{
if (m_type == ArgInfoBinary)
{
ui->argCheck->blockSignals(true);
ui->argCheck->setChecked(m_floatValue == 0.0 ? false : true);
ui->argCheck->blockSignals(false);
}
else if (m_type == ArgInfoContinuous)
{
ui->argEdit->blockSignals(true);
ui->argEdit->setText(QString("%1").arg(m_floatValue));
ui->argEdit->blockSignals(false);
}
else if (m_type == ArgInfoDiscrete)
{
for (int i = 0; i < ui->argCombo->count(); i++)
{
if (ui->argCombo->itemData(i).type() == QVariant::Double)
{
bool ok = false;
QVariant v = ui->argCombo->itemData(i);
if (m_floatValue >= v.toDouble(&ok) && ok)
{
ui->argCombo->blockSignals(true);
ui->argCombo->setCurrentIndex(i);
ui->argCombo->blockSignals(false);
break;
}
}
}
}
}
void ArgInfoGUI::updateUIFromString()
{
if (m_type == ArgInfoBinary)
{
ui->argCheck->blockSignals(true);
ui->argCheck->setChecked(m_stringValue == "true" ? true : false);
ui->argCheck->blockSignals(false);
}
else if (m_type == ArgInfoContinuous)
{
ui->argEdit->blockSignals(true);
ui->argEdit->setText(m_stringValue);
ui->argEdit->blockSignals(false);
}
}
void ArgInfoGUI::on_argCheck_toggled(bool checked)
{
setBoolValue(checked);
emit valueChanged();
}
void ArgInfoGUI::on_argEdit_editingFinished()
{
setStringValue(ui->argEdit->text());
emit valueChanged();
}
#ifdef _MSC_VER
void ArgInfoGUI::on_argCombo_currentIndexChanged(int index)
#else
void ArgInfoGUI::on_argCombo_currentIndexChanged(int index __attribute__((unused)))
#endif
{
QVariant v = ui->argCombo->currentData();
bool ok = false;
if (v.type() == QVariant::Bool)
{
setBoolValue(v.toBool());
emit valueChanged();
}
else if (v.type() == QVariant::Int)
{
setIntValue(v.toInt(&ok));
if (ok) {
emit valueChanged();
}
}
else if (v.type() == QVariant::Double)
{
setFloatValue(v.toDouble(&ok));
if (ok) {
emit valueChanged();
}
}
else if (v.type() ==QVariant::String)
{
setStringValue(v.toString());
emit valueChanged();
}
}

Wyświetl plik

@ -0,0 +1,101 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRGUI_SOAPYGUI_ARGINFOGUI_H_
#define SDRGUI_SOAPYGUI_ARGINFOGUI_H_
#include <QWidget>
#include <QString>
#include "export.h"
namespace Ui {
class ArgInfoGUI;
}
class SDRGUI_API ArgInfoGUI : public QWidget
{
Q_OBJECT
public:
enum ArgInfoType
{
ArgInfoBinary,
ArgInfoContinuous,
ArgInfoDiscrete
};
enum ArgInfoValueType
{
ArgInfoValueBool,
ArgInfoValueInt,
ArgInfoValueFloat,
ArgInfoValueString
};
explicit ArgInfoGUI(ArgInfoType type, ArgInfoValueType valueType, QWidget *parent = 0);
~ArgInfoGUI();
void setLabel(const QString& text);
void setUnits(const QString& units);
ArgInfoType getType() const { return m_type; }
void setRange(double min, double max);
bool getBoolValue() const { return m_boolValue; }
void setBoolValue(bool value);
void addBoolValue(const QString& text, bool value);
int getIntValue() const { return m_intValue; }
void setIntValue(int value);
void addIntValue(const QString& text, int value);
double getFloatValue() const { return m_floatValue; }
void setFloatValue(double value);
void addFloatValue(const QString& text, double value);
const QString& getStringValue() const { return m_stringValue; }
void setStringValue(const QString& value);
void addStringValue(const QString& text, const QString& value);
signals:
void valueChanged();
private slots:
void on_argCheck_toggled(bool checked);
void on_argEdit_editingFinished();
void on_argCombo_currentIndexChanged(int index);
private:
int setIntegerValue(int value);
double setDoubleValue(double value);
void updateUIFromBool();
void updateUIFromInt();
void updateUIFromFloat();
void updateUIFromString();
Ui::ArgInfoGUI* ui;
ArgInfoType m_type;
ArgInfoValueType m_valueType;
bool m_boolValue;
int m_intValue;
double m_floatValue;
QString m_stringValue;
bool m_hasRange;
double m_minValue;
double m_maxValue;
};
#endif /* SDRGUI_SOAPYGUI_ARGINFOGUI_H_ */

Wyświetl plik

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ArgInfoGUI</class>
<widget class="QWidget" name="ArgInfoGUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>29</height>
</rect>
</property>
<layout class="QHBoxLayout" name="argLayout">
<item>
<widget class="QLabel" name="argLabel">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="argCheck">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="argEdit"/>
</item>
<item>
<widget class="QComboBox" name="argCombo"/>
</item>
<item>
<widget class="QLabel" name="argUnits">
<property name="text">
<string>Unit</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>