From f9c41caaf3cf7759e5222ec5769f86ed9bc5eb0b Mon Sep 17 00:00:00 2001 From: edouard Date: Wed, 6 Oct 2010 21:34:25 +0000 Subject: [PATCH] OP-137 Bargraph dials now also support multivalued fields. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1904 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../lineardialgadgetoptionspage.cpp | 15 ++++++++----- .../lineardial/lineardialgadgetwidget.cpp | 21 +++++++++++++++++-- .../lineardial/lineardialgadgetwidget.h | 2 ++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp index 1136eaa95..2e34939b2 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp @@ -86,10 +86,7 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent) // Now load the object field values: UAVDataObject* obj = dynamic_cast( objManager->getObject(m_config->getSourceDataObject()) ); if (obj != NULL ) { - QList 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,7 +140,15 @@ void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val) UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { - options_page->objectField->addItem(field->getName()); + if(field->getElementNames().count() > 1) + { + foreach(QString elemName , field->getElementNames()) + { + options_page->objectField->addItem(field->getName() + "-" + elemName); + } + } + else + options_page->objectField->addItem(field->getName()); } } diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp index 362871ea2..284f2a972 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp @@ -77,7 +77,18 @@ void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) { obj1 = dynamic_cast( 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); diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.h b/ground/src/plugins/lineardial/lineardialgadgetwidget.h index 35c805dd4..62adbcc45 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetwidget.h +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.h @@ -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_ */