1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-137 Bargraph dials now also support multivalued fields.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1904 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-10-06 21:34:25 +00:00 committed by edouard
parent e32ddd5230
commit f9c41caaf3
3 changed files with 31 additions and 7 deletions

View File

@ -86,10 +86,7 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getSourceDataObject()) );
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->objectField->addItem(field->getName());
}
on_objectName_currentIndexChanged(m_config->getSourceDataObject());
// And set the highlighed value from the settings:
options_page->objectField->setCurrentIndex(options_page->objectField->findText(m_config->getSourceObjectField()));
}
@ -143,6 +140,14 @@ void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val)
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField->addItem(field->getName());
}
}

View File

@ -77,7 +77,18 @@ void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateIndex(UAVObject*)));
field1 = nfield1;
if(nfield1.contains("-"))
{
QStringList fieldSubfield = nfield1.split("-", QString::SkipEmptyParts);
field1 = fieldSubfield.at(0);
subfield1 = fieldSubfield.at(1);
haveSubField1 = true;
}
else
{
field1= nfield1;
haveSubField1 = false;
}
if (fieldName)
fieldName->setPlainText(nfield1);
updateIndex(obj1);
@ -99,7 +110,12 @@ void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
if (field) {
QString s;
if (field->isNumeric()) {
double v = field->getDouble()*factor;
double v;
if(haveSubField1){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield1, Qt::CaseSensitive, QRegExp::FixedString));
v = field->getDouble(indexOfSubField)*factor;
}else
v = field->getDouble()*factor;
setIndex(v);
s.sprintf("%.*f",places,v);
}
@ -115,6 +131,7 @@ void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
}
}
}
if (fieldValue)
fieldValue->setPlainText(s);

View File

@ -116,6 +116,8 @@ private:
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
QString field1;
QString subfield1;
bool haveSubField1;
};
#endif /* LINEARDIALGADGETWIDGET_H_ */