mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-1331 OP-1335 Added support in ConfigTaskWidget to bind a GComboBox to an integer property
This commit is contained in:
parent
4cee34a0ef
commit
07a828f971
@ -58,7 +58,7 @@ void ConfigTaskWidget::addUAVObject(QString objectName, QList<int> *reloadGroups
|
||||
|
||||
void ConfigTaskWidget::addUAVObject(UAVObject *objectName, QList<int> *reloadGroups)
|
||||
{
|
||||
addUAVObject(objectName ? objectName->getName() : QString(""), reloadGroups);
|
||||
addUAVObject(objectName ? objectName->getName() : QString(), reloadGroups);
|
||||
}
|
||||
|
||||
int ConfigTaskWidget::fieldIndexFromElementName(QString objectName, QString fieldName, QString elementName)
|
||||
@ -84,7 +84,7 @@ void ConfigTaskWidget::addWidgetBinding(QString objectName, QString fieldName, Q
|
||||
|
||||
void ConfigTaskWidget::addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName)
|
||||
{
|
||||
addWidgetBinding(object ? object->getName() : QString(""), field ? field->getName() : QString(""), widget, elementName);
|
||||
addWidgetBinding(object ? object->getName() : QString(), field ? field->getName() : QString(), widget, elementName);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addWidgetBinding(QString objectName, QString fieldName, QWidget *widget, QString elementName, double scale,
|
||||
@ -97,14 +97,14 @@ void ConfigTaskWidget::addWidgetBinding(QString objectName, QString fieldName, Q
|
||||
void ConfigTaskWidget::addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, QString elementName, double scale,
|
||||
bool isLimited, QList<int> *reloadGroupIDs, quint32 instID)
|
||||
{
|
||||
addWidgetBinding(object ? object->getName() : QString(""), field ? field->getName() : QString(""), widget, elementName, scale,
|
||||
addWidgetBinding(object ? object->getName() : QString(), field ? field->getName() : QString(), widget, elementName, scale,
|
||||
isLimited, reloadGroupIDs, instID);
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::addWidgetBinding(UAVObject *object, UAVObjectField *field, QWidget *widget, int index, double scale,
|
||||
bool isLimited, QList<int> *reloadGroupIDs, quint32 instID)
|
||||
{
|
||||
addWidgetBinding(object ? object->getName() : QString(""), field ? field->getName() : QString(""), widget, index, scale,
|
||||
addWidgetBinding(object ? object->getName() : QString(), field ? field->getName() : QString(), widget, index, scale,
|
||||
isLimited, reloadGroupIDs, instID);
|
||||
}
|
||||
|
||||
@ -146,7 +146,6 @@ void ConfigTaskWidget::doAddWidgetBinding(QString objectName, QString fieldName,
|
||||
binding->setIsEnabled(m_widgetBindingsPerWidget.count(widget) == 0);
|
||||
m_widgetBindingsPerWidget.insert(widget, binding);
|
||||
|
||||
|
||||
if (object) {
|
||||
m_widgetBindingsPerObject.insert(object, binding);
|
||||
if (m_saveButton) {
|
||||
@ -264,7 +263,8 @@ void ConfigTaskWidget::onAutopilotDisconnect()
|
||||
invalidateObjects();
|
||||
}
|
||||
|
||||
void ConfigTaskWidget::forceConnectedState() // dynamic widgets don't recieve the connected signal. This should be called instead.
|
||||
// dynamic widgets don't recieve the connected signal. This should be called instead.
|
||||
void ConfigTaskWidget::forceConnectedState()
|
||||
{
|
||||
m_isConnected = true;
|
||||
setDirty(false);
|
||||
@ -385,7 +385,7 @@ void ConfigTaskWidget::forceShadowUpdates()
|
||||
if (!binding->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
QVariant widgetValue = getVariantFromWidget(binding->widget(), binding->scale(), binding->units());
|
||||
QVariant widgetValue = getVariantFromWidget(binding->widget(), binding->scale(), binding->units(), binding->type());
|
||||
|
||||
foreach(ShadowWidgetBinding * shadow, binding->shadows()) {
|
||||
disconnectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
|
||||
@ -412,17 +412,17 @@ void ConfigTaskWidget::widgetsContentsChanged()
|
||||
if (binding->widget() == emitter) {
|
||||
scale = binding->scale();
|
||||
checkWidgetsLimits(emitter, binding->field(), binding->index(), binding->isLimited(),
|
||||
getVariantFromWidget(emitter, scale, binding->units()), scale);
|
||||
getVariantFromWidget(emitter, scale, binding->units(), binding->type()), scale);
|
||||
} else {
|
||||
foreach(ShadowWidgetBinding * shadow, binding->shadows()) {
|
||||
if (shadow->widget() == emitter) {
|
||||
scale = shadow->scale();
|
||||
checkWidgetsLimits(emitter, binding->field(), binding->index(), shadow->isLimited(),
|
||||
getVariantFromWidget(emitter, scale, binding->units()), scale);
|
||||
getVariantFromWidget(emitter, scale, binding->units(), binding->type()), scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
value = getVariantFromWidget(emitter, scale, binding->units());
|
||||
value = getVariantFromWidget(emitter, scale, binding->units(), binding->type());
|
||||
binding->setValue(value);
|
||||
|
||||
if (binding->widget() != emitter) {
|
||||
@ -851,9 +851,12 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, QString units)
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, QString units, QString type)
|
||||
{
|
||||
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
|
||||
if (type.startsWith("int") || type.startsWith("uint")) {
|
||||
return cb->currentIndex();
|
||||
}
|
||||
return (QString)cb->currentText();
|
||||
} else if (QDoubleSpinBox * cb = qobject_cast<QDoubleSpinBox *>(widget)) {
|
||||
return (double)(cb->value() * scale);
|
||||
@ -876,11 +879,16 @@ QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, Q
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale, QString units)
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale, QString units, QString type)
|
||||
{
|
||||
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
|
||||
bool ok = true;
|
||||
if (type.startsWith("int") || type.startsWith("uint")) {
|
||||
cb->setCurrentIndex(value.toInt(&ok));
|
||||
} else {
|
||||
cb->setCurrentIndex(cb->findText(value.toString()));
|
||||
return true;
|
||||
}
|
||||
return ok;
|
||||
} else if (QLabel * cb = qobject_cast<QLabel *>(widget)) {
|
||||
if (scale == 0) {
|
||||
cb->setText(value.toString());
|
||||
@ -919,7 +927,7 @@ bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, dou
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale)
|
||||
{
|
||||
return setWidgetFromVariant(widget, value, scale, QString(""));
|
||||
return setWidgetFromVariant(widget, value, scale, QString(), QString());
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits)
|
||||
@ -934,7 +942,7 @@ bool ConfigTaskWidget::setWidgetFromField(QWidget *widget, UAVObjectField *field
|
||||
}
|
||||
QVariant value = field->getValue(index);
|
||||
checkWidgetsLimits(widget, field, index, hasLimits, value, scale);
|
||||
bool result = setWidgetFromVariant(widget, value, scale, field->getUnits());
|
||||
bool result = setWidgetFromVariant(widget, value, scale, field->getUnits(), field->getTypeAsString());
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
@ -1098,7 +1106,15 @@ QString WidgetBinding::units() const
|
||||
if (m_field) {
|
||||
return m_field->getUnits();
|
||||
}
|
||||
return QString("");
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString WidgetBinding::type() const
|
||||
{
|
||||
if (m_field) {
|
||||
return m_field->getTypeAsString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
UAVObject *WidgetBinding::object() const
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
~WidgetBinding();
|
||||
|
||||
QString units() const;
|
||||
QString type() const;
|
||||
UAVObject *object() const;
|
||||
UAVObjectField *field() const;
|
||||
int index() const;
|
||||
@ -223,8 +224,8 @@ private:
|
||||
|
||||
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits);
|
||||
|
||||
QVariant getVariantFromWidget(QWidget *widget, double scale, const QString units);
|
||||
bool setWidgetFromVariant(QWidget *widget, QVariant value, double scale, QString units);
|
||||
QVariant getVariantFromWidget(QWidget *widget, double scale, const QString units, QString type);
|
||||
bool setWidgetFromVariant(QWidget *widget, QVariant value, double scale, QString units, QString type);
|
||||
bool setWidgetFromVariant(QWidget *widget, QVariant value, double scale);
|
||||
|
||||
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
|
||||
|
Loading…
x
Reference in New Issue
Block a user