Commit 365a330c authored by Michael Carpenter's avatar Michael Carpenter

Fix for Standard and Advanced param views not displaying or accepting edits properly

parent b38630b3
......@@ -12,7 +12,9 @@ AdvancedParamConfig::~AdvancedParamConfig()
}
void AdvancedParamConfig::addRange(QString title,QString description,QString param,double min,double max)
{
ParamWidget *widget = new ParamWidget(ui.scrollAreaWidgetContents);
ParamWidget *widget = new ParamWidget(param,ui.scrollAreaWidgetContents);
connect(widget,SIGNAL(doubleValueChanged(QString,double)),this,SLOT(doubleValueChanged(QString,double)));
connect(widget,SIGNAL(intValueChanged(QString,int)),this,SLOT(intValueChanged(QString,int)));
m_paramToWidgetMap[param] = widget;
widget->setupDouble(title + "(" + param + ")",description,0,min,max);
ui.verticalLayout->addWidget(widget);
......@@ -21,7 +23,9 @@ void AdvancedParamConfig::addRange(QString title,QString description,QString par
void AdvancedParamConfig::addCombo(QString title,QString description,QString param,QList<QPair<int,QString> > valuelist)
{
ParamWidget *widget = new ParamWidget(ui.scrollAreaWidgetContents);
ParamWidget *widget = new ParamWidget(param,ui.scrollAreaWidgetContents);
connect(widget,SIGNAL(doubleValueChanged(QString,double)),this,SLOT(doubleValueChanged(QString,double)));
connect(widget,SIGNAL(intValueChanged(QString,int)),this,SLOT(intValueChanged(QString,int)));
m_paramToWidgetMap[param] = widget;
widget->setupCombo(title + "(" + param + ")",description,valuelist);
ui.verticalLayout->addWidget(widget);
......@@ -30,7 +34,31 @@ void AdvancedParamConfig::addCombo(QString title,QString description,QString par
void AdvancedParamConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
if (m_paramToWidgetMap.contains(parameterName))
{
if (value.type() == QVariant::Double)
{
m_paramToWidgetMap[parameterName]->setValue(value.toDouble());
}
else
{
m_paramToWidgetMap[parameterName]->setValue(value.toInt());
}
}
}
void AdvancedParamConfig::doubleValueChanged(QString param,double value)
{
if (!m_uas)
{
this->showNullMAVErrorMessageBox();
}
m_uas->getParamManager()->setParameter(1,param,value);
}
void AdvancedParamConfig::intValueChanged(QString param,int value)
{
if (!m_uas)
{
this->showNullMAVErrorMessageBox();
}
m_uas->getParamManager()->setParameter(1,param,value);
}
......@@ -16,6 +16,8 @@ public:
void addCombo(QString title,QString description,QString param,QList<QPair<int,QString> > valuelist);
private slots:
void parameterChanged(int uas, int component, QString parameterName, QVariant value);
void doubleValueChanged(QString param,double value);
void intValueChanged(QString param,int value);
private:
QMap<QString,ParamWidget*> m_paramToWidgetMap;
Ui::AdvancedParamConfig ui;
......
......@@ -85,23 +85,27 @@ void ApmSoftwareConfig::activeUASSet(UASInterface *uas)
ui.advancedParamButton->setVisible(true);
ui.advParamListButton->setVisible(true);
QString compare = "";
if (uas->getSystemType() == MAV_TYPE_FIXED_WING)
{
ui.arduPlanePidButton->setVisible(true);
ui.arduCopterPidButton->setVisible(false);
ui.arduRoverPidButton->setVisible(false);
compare = "ArduPlane";
}
else if (uas->getSystemType() == MAV_TYPE_QUADROTOR)
{
ui.arduCopterPidButton->setVisible(true);
ui.arduPlanePidButton->setVisible(false);
ui.arduRoverPidButton->setVisible(false);
compare = "ArduCopter";
}
else if (uas->getSystemType() == MAV_TYPE_GROUND_ROVER)
{
ui.arduRoverPidButton->setVisible(true);
ui.arduCopterPidButton->setVisible(false);
ui.arduPlanePidButton->setVisible(false);
compare = "APMRover2";
}
......@@ -138,6 +142,7 @@ void ApmSoftwareConfig::activeUASSet(UASInterface *uas)
{
parametersname = xml.attributes().value("name").toString();
}
QVariantMap genset;
QVariantMap advset;
......@@ -301,6 +306,8 @@ void ApmSoftwareConfig::activeUASSet(UASInterface *uas)
{
valuelist.append(QPair<int,QString>(i.key().toInt(),i.value()));
}
if (compare == parametersname)
{
if (tab == "Standard")
{
m_standardParamConfig->addCombo(humanname,docs,name,valuelist);
......@@ -311,14 +318,13 @@ void ApmSoftwareConfig::activeUASSet(UASInterface *uas)
}
m_advParameterList->setParameterMetaData(name,humanname,docs);
}
}
else if (fieldmap.size() > 0)
{
float min = 0;
float max = 100;
float max = 65535;
if (fieldmap.contains("Range"))
{
float min = 0;
float max = 0;
//Some range fields list "0-10" and some list "0 10". Handle both.
if (fieldmap["Range"].split(" ").size() > 1)
{
......@@ -331,16 +337,19 @@ void ApmSoftwareConfig::activeUASSet(UASInterface *uas)
max = fieldmap["Range"].split("-")[1].trimmed().toFloat();
}
}
if (compare == parametersname)
{
if (tab == "Standard")
{
m_standardParamConfig->addRange(humanname,docs,name,min,max);
}
else if (tab == "Advanced")
{
m_advancedParamConfig->addRange(humanname,docs,name,max,min);
m_advancedParamConfig->addRange(humanname,docs,name,min,max);
}
m_advParameterList->setParameterMetaData(name,humanname,docs);
}
}
}
xml.readNext();
......
#include "ParamWidget.h"
ParamWidget::ParamWidget(QWidget *parent) : QWidget(parent)
ParamWidget::ParamWidget(QString param,QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
m_param = param;
connect(ui.doubleSpinBox,SIGNAL(editingFinished()),this,SLOT(doubleSpinEditFinished()));
connect(ui.intSpinBox,SIGNAL(editingFinished()),this,SLOT(intSpinEditFinished()));
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
connect(ui.valueSlider,SIGNAL(sliderReleased()),this,SLOT(valueSliderReleased()));
}
void ParamWidget::doubleSpinEditFinished()
{
ui.valueSlider->setValue(((ui.doubleSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
}
void ParamWidget::intSpinEditFinished()
{
ui.valueSlider->setValue(((ui.intSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
emit intValueChanged(m_param,ui.intSpinBox->value());
}
void ParamWidget::comboIndexChanged(int index)
{
emit intValueChanged(m_param,m_valueList[index].first);
}
void ParamWidget::valueSliderReleased()
{
//Set the spin box, and emit a signal.
if (type == INT)
{
ui.intSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
emit intValueChanged(m_param,ui.intSpinBox->value());
}
else if (type == DOUBLE)
{
ui.doubleSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
}
}
ParamWidget::~ParamWidget()
......@@ -19,8 +55,18 @@ void ParamWidget::setupInt(QString title,QString description,int value,int min,i
ui.valueSlider->show();
ui.intSpinBox->show();
ui.doubleSpinBox->hide();
if (min == 0 && max == 0)
{
m_min = 0;
m_max = 65535;
}
else
{
m_min = min;
m_max = max;
}
ui.intSpinBox->setMinimum(m_min);
ui.intSpinBox->setMaximum(m_max);
}
void ParamWidget::setupDouble(QString title,QString description,double value,double min,double max)
......@@ -32,8 +78,18 @@ void ParamWidget::setupDouble(QString title,QString description,double value,dou
ui.valueSlider->show();
ui.intSpinBox->hide();
ui.doubleSpinBox->show();
if (min == 0 && max == 0)
{
m_min = 0;
m_max = 65535;
}
else
{
m_min = min;
m_max = max;
}
ui.doubleSpinBox->setMinimum(m_min);
ui.doubleSpinBox->setMaximum(m_max);
}
void ParamWidget::setupCombo(QString title,QString description,QList<QPair<int,QString> > list)
......@@ -47,10 +103,12 @@ void ParamWidget::setupCombo(QString title,QString description,QList<QPair<int,Q
ui.doubleSpinBox->hide();
m_valueList = list;
ui.valueComboBox->clear();
disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
for (int i=0;i<m_valueList.size();i++)
{
ui.valueComboBox->addItem(m_valueList[i].second);
}
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
}
void ParamWidget::setValue(double value)
......@@ -58,12 +116,12 @@ void ParamWidget::setValue(double value)
if (type == INT)
{
ui.intSpinBox->setValue(value);
ui.valueSlider->setValue(((value + m_min) / (m_max + m_min)) * 100.0);
ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
}
else if (type == DOUBLE)
{
ui.doubleSpinBox->setValue(value);
ui.valueSlider->setValue(((value + m_min) / (m_max + m_min)) * 100.0);
ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
}
else if (type == COMBO)
{
......@@ -71,7 +129,9 @@ void ParamWidget::setValue(double value)
{
if ((int)value == m_valueList[i].first)
{
disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
ui.valueComboBox->setCurrentIndex(i);
connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
return;
}
}
......
......@@ -9,13 +9,22 @@ class ParamWidget : public QWidget
Q_OBJECT
public:
explicit ParamWidget(QWidget *parent = 0);
explicit ParamWidget(QString param,QWidget *parent = 0);
~ParamWidget();
void setupInt(QString title,QString description,int value,int min,int max);
void setupDouble(QString title,QString description,double value,double min,double max);
void setupCombo(QString title,QString description,QList<QPair<int,QString> > list);
void setValue(double value);
signals:
void doubleValueChanged(QString param,double value);
void intValueChanged(QString param,int value);
private slots:
void doubleSpinEditFinished();
void intSpinEditFinished();
void comboIndexChanged(int index);
void valueSliderReleased();
private:
QString m_param;
enum VIEWTYPE
{
INT,
......
......@@ -46,6 +46,9 @@
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......
......@@ -10,7 +10,9 @@ StandardParamConfig::~StandardParamConfig()
}
void StandardParamConfig::addRange(QString title,QString description,QString param,double min,double max)
{
ParamWidget *widget = new ParamWidget(ui.scrollAreaWidgetContents);
ParamWidget *widget = new ParamWidget(param,ui.scrollAreaWidgetContents);
connect(widget,SIGNAL(doubleValueChanged(QString,double)),this,SLOT(doubleValueChanged(QString,double)));
connect(widget,SIGNAL(intValueChanged(QString,int)),this,SLOT(intValueChanged(QString,int)));
paramToWidgetMap[param] = widget;
widget->setupDouble(title + "(" + param + ")",description,0,min,max);
ui.verticalLayout->addWidget(widget);
......@@ -19,7 +21,9 @@ void StandardParamConfig::addRange(QString title,QString description,QString par
void StandardParamConfig::addCombo(QString title,QString description,QString param,QList<QPair<int,QString> > valuelist)
{
ParamWidget *widget = new ParamWidget(ui.scrollAreaWidgetContents);
ParamWidget *widget = new ParamWidget(param,ui.scrollAreaWidgetContents);
connect(widget,SIGNAL(doubleValueChanged(QString,double)),this,SLOT(doubleValueChanged(QString,double)));
connect(widget,SIGNAL(intValueChanged(QString,int)),this,SLOT(intValueChanged(QString,int)));
paramToWidgetMap[param] = widget;
widget->setupCombo(title + "(" + param + ")",description,valuelist);
ui.verticalLayout->addWidget(widget);
......@@ -28,7 +32,32 @@ void StandardParamConfig::addCombo(QString title,QString description,QString par
void StandardParamConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
if (paramToWidgetMap.contains(parameterName))
{
if (value.type() == QVariant::Double)
{
paramToWidgetMap[parameterName]->setValue(value.toDouble());
}
else
{
paramToWidgetMap[parameterName]->setValue(value.toInt());
}
}
}
void StandardParamConfig::doubleValueChanged(QString param,double value)
{
if (!m_uas)
{
this->showNullMAVErrorMessageBox();
}
m_uas->getParamManager()->setParameter(1,param,value);
}
void StandardParamConfig::intValueChanged(QString param,int value)
{
if (!m_uas)
{
this->showNullMAVErrorMessageBox();
}
m_uas->getParamManager()->setParameter(1,param,value);
}
......@@ -16,6 +16,8 @@ public:
void addCombo(QString title,QString description,QString param,QList<QPair<int,QString> > valuelist);
private slots:
void parameterChanged(int uas, int component, QString parameterName, QVariant value);
void doubleValueChanged(QString param,double value);
void intValueChanged(QString param,int value);
private:
QMap<QString,ParamWidget*> paramToWidgetMap;
Ui::StandardParamConfig ui;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment