mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-1331 OP-1335 revisited GComboBox to integer binding (less hacky now ;) )
This commit is contained in:
parent
9cf24a9731
commit
88100a72c2
@ -199,14 +199,14 @@ void UAVObjectField::limitsInitialize(const QString &limits)
|
||||
elementLimits.insert(index, limitList);
|
||||
++index;
|
||||
}
|
||||
// foreach(QList<LimitStruct> limitList, elementLimits) {
|
||||
// foreach(LimitStruct limit, limitList) {
|
||||
// qDebug() << "Limit type" << limit.type << "for board" << limit.board << "for field" << getName();
|
||||
// foreach(QVariant var, limit.values) {
|
||||
// qDebug() << "value" << var;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// foreach(QList<LimitStruct> limitList, elementLimits) {
|
||||
// foreach(LimitStruct limit, limitList) {
|
||||
// qDebug() << "Limit type" << limit.type << "for board" << limit.board << "for field" << getName();
|
||||
// foreach(QVariant var, limit.values) {
|
||||
// qDebug() << "value" << var;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
bool UAVObjectField::isWithinLimits(QVariant var, quint32 index, int board)
|
||||
{
|
||||
@ -811,44 +811,31 @@ bool UAVObjectField::isNumeric()
|
||||
{
|
||||
switch (type) {
|
||||
case INT8:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case INT16:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case INT32:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case UINT8:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case UINT16:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case UINT32:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case FLOAT32:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case ENUM:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case BITFIELD:
|
||||
bool UAVObjectField::isInteger()
|
||||
{
|
||||
switch (type) {
|
||||
case INT8:
|
||||
case INT16:
|
||||
case INT32:
|
||||
case UINT8:
|
||||
case UINT16:
|
||||
case UINT32:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case STRING:
|
||||
return false;
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -858,42 +845,7 @@ bool UAVObjectField::isNumeric()
|
||||
bool UAVObjectField::isText()
|
||||
{
|
||||
switch (type) {
|
||||
case INT8:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case INT16:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case INT32:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case UINT8:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case UINT16:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case UINT32:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case FLOAT32:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case ENUM:
|
||||
return true;
|
||||
|
||||
break;
|
||||
case BITFIELD:
|
||||
return false;
|
||||
|
||||
break;
|
||||
case STRING:
|
||||
return true;
|
||||
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
quint32 getDataOffset();
|
||||
quint32 getNumBytes();
|
||||
bool isNumeric();
|
||||
bool isInteger();
|
||||
bool isText();
|
||||
QString toString();
|
||||
void toXML(QXmlStreamWriter *xmlWriter);
|
||||
|
@ -182,9 +182,9 @@ void ConfigTaskWidget::setWidgetBindingObjectEnabled(QString objectName, bool en
|
||||
binding->setIsEnabled(enabled);
|
||||
if (enabled) {
|
||||
if (binding->value().isValid() && !binding->value().isNull()) {
|
||||
setWidgetFromVariant(binding->widget(), binding->value(), binding->scale());
|
||||
setWidgetFromVariant(binding->widget(), binding->value(), binding);
|
||||
} else {
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding->index(), binding->scale(), binding->isLimited());
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -289,7 +289,7 @@ void ConfigTaskWidget::populateWidgets()
|
||||
|
||||
foreach(WidgetBinding * binding, m_widgetBindingsPerObject) {
|
||||
if (binding->isEnabled() && binding->object() != NULL && binding->field() != NULL && binding->widget() != NULL) {
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding->index(), binding->scale(), binding->isLimited());
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding);
|
||||
}
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
@ -305,7 +305,7 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
|
||||
emit refreshWidgetsValuesRequested();
|
||||
foreach(WidgetBinding * binding, m_widgetBindingsPerObject.values(obj)) {
|
||||
if (binding->isEnabled() && binding->field() != NULL && binding->widget() != NULL) {
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding->index(), binding->scale(), binding->isLimited());
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding);
|
||||
}
|
||||
}
|
||||
setDirty(dirtyBack);
|
||||
@ -385,13 +385,15 @@ void ConfigTaskWidget::forceShadowUpdates()
|
||||
if (!binding->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
QVariant widgetValue = getVariantFromWidget(binding->widget(), binding->scale(), binding->units(), binding->type());
|
||||
QVariant widgetValue = getVariantFromWidget(binding->widget(), binding);
|
||||
|
||||
foreach(ShadowWidgetBinding * shadow, binding->shadows()) {
|
||||
disconnectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
|
||||
|
||||
checkWidgetsLimits(shadow->widget(), binding->field(), binding->index(), shadow->isLimited(), widgetValue, shadow->scale());
|
||||
setWidgetFromVariant(shadow->widget(), widgetValue, shadow->scale());
|
||||
|
||||
WidgetBinding tmpBinding(shadow->widget(), binding->object(), binding->field(), binding->index(), shadow->scale(), shadow->isLimited());
|
||||
setWidgetFromVariant(shadow->widget(), widgetValue, &tmpBinding);
|
||||
|
||||
emit widgetContentsChanged(shadow->widget());
|
||||
connectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
|
||||
@ -410,19 +412,18 @@ void ConfigTaskWidget::widgetsContentsChanged()
|
||||
foreach(WidgetBinding * binding, m_widgetBindingsPerWidget.values(emitter)) {
|
||||
if (binding && binding->isEnabled()) {
|
||||
if (binding->widget() == emitter) {
|
||||
scale = binding->scale();
|
||||
checkWidgetsLimits(emitter, binding->field(), binding->index(), binding->isLimited(),
|
||||
getVariantFromWidget(emitter, scale, binding->units(), binding->type()), scale);
|
||||
getVariantFromWidget(emitter, binding), binding->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(), binding->type()), scale);
|
||||
WidgetBinding tmpBinding(shadow->widget(), binding->object(), binding->field(), binding->index(), shadow->scale(), shadow->isLimited());
|
||||
QVariant value = getVariantFromWidget(emitter, &tmpBinding);
|
||||
checkWidgetsLimits(emitter, binding->field(), binding->index(), shadow->isLimited(), value, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
value = getVariantFromWidget(emitter, scale, binding->units(), binding->type());
|
||||
value = getVariantFromWidget(emitter, binding);
|
||||
binding->setValue(value);
|
||||
|
||||
if (binding->widget() != emitter) {
|
||||
@ -430,7 +431,7 @@ void ConfigTaskWidget::widgetsContentsChanged()
|
||||
|
||||
checkWidgetsLimits(binding->widget(), binding->field(), binding->index(), binding->isLimited(),
|
||||
value, binding->scale());
|
||||
setWidgetFromVariant(binding->widget(), value, binding->scale());
|
||||
setWidgetFromVariant(binding->widget(), value, binding);
|
||||
emit widgetContentsChanged(binding->widget());
|
||||
|
||||
connectWidgetUpdatesToSlot(binding->widget(), SLOT(widgetsContentsChanged()));
|
||||
@ -441,7 +442,8 @@ void ConfigTaskWidget::widgetsContentsChanged()
|
||||
|
||||
checkWidgetsLimits(shadow->widget(), binding->field(), binding->index(), shadow->isLimited(),
|
||||
value, shadow->scale());
|
||||
setWidgetFromVariant(shadow->widget(), value, shadow->scale());
|
||||
WidgetBinding tmp(shadow->widget(), binding->object(), binding->field(), binding->index(), shadow->scale(), shadow->isLimited());
|
||||
setWidgetFromVariant(shadow->widget(), value, &tmp);
|
||||
emit widgetContentsChanged(shadow->widget());
|
||||
|
||||
connectWidgetUpdatesToSlot(shadow->widget(), SLOT(widgetsContentsChanged()));
|
||||
@ -736,7 +738,7 @@ void ConfigTaskWidget::defaultButtonClicked()
|
||||
continue;
|
||||
}
|
||||
UAVDataObject *temp = ((UAVDataObject *)binding->object())->dirtyClone();
|
||||
setWidgetFromField(binding->widget(), temp->getField(binding->field()->getName()), binding->index(), binding->scale(), binding->isLimited());
|
||||
setWidgetFromField(binding->widget(), temp->getField(binding->field()->getName()), binding);
|
||||
}
|
||||
}
|
||||
|
||||
@ -779,7 +781,7 @@ void ConfigTaskWidget::reloadButtonClicked()
|
||||
if (m_realtimeUpdateTimer->isActive()) {
|
||||
binding->object()->requestUpdate();
|
||||
if (binding->widget()) {
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding->index(), binding->scale(), binding->isLimited());
|
||||
setWidgetFromField(binding->widget(), binding->field(), binding);
|
||||
}
|
||||
}
|
||||
m_realtimeUpdateTimer->stop();
|
||||
@ -851,10 +853,12 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, QString units, QString type)
|
||||
QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, WidgetBinding *binding)
|
||||
{
|
||||
double scale = binding->scale();
|
||||
|
||||
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
|
||||
if (type.startsWith("int") || type.startsWith("uint")) {
|
||||
if (binding->isInteger()) {
|
||||
return cb->currentIndex();
|
||||
}
|
||||
return (QString)cb->currentText();
|
||||
@ -868,7 +872,7 @@ QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, Q
|
||||
return (QString)(cb->isChecked() ? "TRUE" : "FALSE");
|
||||
} else if (QLineEdit * cb = qobject_cast<QLineEdit *>(widget)) {
|
||||
QString value = (QString)cb->displayText();
|
||||
if (units == "hex") {
|
||||
if (binding->units() == "hex") {
|
||||
bool ok;
|
||||
return value.toUInt(&ok, 16);
|
||||
} else {
|
||||
@ -879,11 +883,13 @@ QVariant ConfigTaskWidget::getVariantFromWidget(QWidget *widget, double scale, Q
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale, QString units, QString type)
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, WidgetBinding *binding)
|
||||
{
|
||||
double scale = binding->scale();
|
||||
|
||||
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
|
||||
bool ok = true;
|
||||
if (type.startsWith("int") || type.startsWith("uint")) {
|
||||
if (binding->isInteger()) {
|
||||
cb->setCurrentIndex(value.toInt(&ok));
|
||||
} else {
|
||||
cb->setCurrentIndex(cb->findText(value.toString()));
|
||||
@ -911,7 +917,7 @@ bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, dou
|
||||
return true;
|
||||
} else if (QLineEdit * cb = qobject_cast<QLineEdit *>(widget)) {
|
||||
if ((scale == 0) || (scale == 1)) {
|
||||
if (units == "hex") {
|
||||
if (binding->units() == "hex") {
|
||||
cb->setText(QString::number(value.toUInt(), 16).toUpper());
|
||||
} else {
|
||||
cb->setText(value.toString());
|
||||
@ -925,24 +931,19 @@ bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, dou
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromVariant(QWidget *widget, QVariant value, double scale)
|
||||
{
|
||||
return setWidgetFromVariant(widget, value, scale, QString(), QString());
|
||||
}
|
||||
|
||||
bool ConfigTaskWidget::setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits)
|
||||
bool ConfigTaskWidget::setWidgetFromField(QWidget *widget, UAVObjectField *field, WidgetBinding *binding)
|
||||
{
|
||||
if (!widget || !field) {
|
||||
return false;
|
||||
}
|
||||
if (QComboBox * cb = qobject_cast<QComboBox *>(widget)) {
|
||||
if (cb->count() == 0) {
|
||||
loadWidgetLimits(cb, field, index, hasLimits, scale);
|
||||
loadWidgetLimits(cb, field, binding->index(), binding->isLimited(), binding->scale());
|
||||
}
|
||||
}
|
||||
QVariant value = field->getValue(index);
|
||||
checkWidgetsLimits(widget, field, index, hasLimits, value, scale);
|
||||
bool result = setWidgetFromVariant(widget, value, scale, field->getUnits(), field->getTypeAsString());
|
||||
QVariant value = field->getValue(binding->index());
|
||||
checkWidgetsLimits(widget, field, binding->index(), binding->isLimited(), value, binding->scale());
|
||||
bool result = setWidgetFromVariant(widget, value, binding);
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
@ -1117,6 +1118,14 @@ QString WidgetBinding::type() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool WidgetBinding::isInteger() const
|
||||
{
|
||||
if (m_field) {
|
||||
return m_field->isInteger();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UAVObject *WidgetBinding::object() const
|
||||
{
|
||||
return m_object;
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
|
||||
QString units() const;
|
||||
QString type() const;
|
||||
bool isInteger() const;
|
||||
UAVObject *object() const;
|
||||
UAVObjectField *field() const;
|
||||
int index() const;
|
||||
@ -222,11 +223,10 @@ private:
|
||||
QString m_outOfLimitsStyle;
|
||||
QTimer *m_realtimeUpdateTimer;
|
||||
|
||||
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, int index, double scale, bool hasLimits);
|
||||
bool setWidgetFromField(QWidget *widget, UAVObjectField *field, WidgetBinding *binding);
|
||||
|
||||
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);
|
||||
QVariant getVariantFromWidget(QWidget *widget, WidgetBinding *binding);
|
||||
bool setWidgetFromVariant(QWidget *widget, QVariant value, WidgetBinding *binding);
|
||||
|
||||
void connectWidgetUpdatesToSlot(QWidget *widget, const char *function);
|
||||
void disconnectWidgetUpdatesToSlot(QWidget *widget, const char *function);
|
||||
|
Loading…
x
Reference in New Issue
Block a user