From 0aa8c47b48e249c345e5b5edc039f1a2d53719f7 Mon Sep 17 00:00:00 2001 From: m_thread Date: Fri, 3 Oct 2014 18:00:59 +0200 Subject: [PATCH] OP-1524 Added Array tree node value preview. --- .../plugins/uavobjectbrowser/fieldtreeitem.h | 32 +----------------- .../src/plugins/uavobjectbrowser/treeitem.cpp | 31 +++++++++++++++++ .../src/plugins/uavobjectbrowser/treeitem.h | 33 +++++++++++++++++-- .../uavobjectbrowser/uavobjecttreemodel.cpp | 2 +- shared/uavobjectdefinition/firmwareiapobj.xml | 2 +- 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h index e41371cba..793291c60 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h @@ -343,7 +343,7 @@ public: { QLineEdit *lineEdit = new QLineEdit(parent); - lineEdit->setInputMask(QString(maxLength(), 'H')); + lineEdit->setInputMask(QString(TreeItem::maxHexStringLength(m_field->getType()), 'H')); return lineEdit; } @@ -401,36 +401,6 @@ private: return str.toString().toUInt(&ok, 16); } - - int maxLength() - { - int maxLength = 0; - - switch (m_field->getType()) { - case UAVObjectField::INT8: - maxLength = 2; - break; - case UAVObjectField::INT16: - maxLength = 4; - break; - case UAVObjectField::INT32: - maxLength = 8; - break; - case UAVObjectField::UINT8: - maxLength = 2; - break; - case UAVObjectField::UINT16: - maxLength = 4; - break; - case UAVObjectField::UINT32: - maxLength = 8; - break; - default: - Q_ASSERT(false); - break; - } - return maxLength; - } }; class CharFieldTreeItem : public FieldTreeItem { diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.cpp index 0c34e0cff..d4e5fb968 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.cpp @@ -228,3 +228,34 @@ QList TopTreeItem::getMetaObjectItems() { return m_metaObjectTreeItemsPerObjectIds.values(); } + +QVariant ArrayFieldTreeItem::data(int column) const +{ + if (column == 1) { + if (m_field->getType() == UAVObjectField::UINT8 && m_field->getUnits().toLower() == "char") { + QString dataString; + for (uint i = 0; i < m_field->getNumElements(); ++i) { + dataString.append(m_field->getValue(i).toChar()); + } + QString data = QString("'%1'").arg(dataString); + return data; + } else if (m_field->getUnits().toLower() == "hex") { + QString dataString; + for (uint i = 0; i < m_field->getNumElements(); ++i) { + if (i > 0) { + dataString.append(' '); + } + bool ok; + dataString.append(QString("%1") + .arg(m_field->getValue(i).toUInt(&ok), TreeItem::maxHexStringLength(m_field->getType()), + 16, QChar('0')).toUpper()); + } + QString data = QString("{%1}").arg(dataString); + return data; + } else { + return QVariant(); + } + } else { + return TreeItem::data(column); + } +} diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h index 5e3b0d96e..08e4b2038 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h @@ -102,7 +102,7 @@ public: } int childCount() const; int columnCount() const; - QVariant data(int column = 1) const; + virtual QVariant data(int column = 1) const; QString description() { return m_description; @@ -179,6 +179,27 @@ public: return 0; } + static int maxHexStringLength(UAVObjectField::FieldType type) + { + switch (type) { + case UAVObjectField::INT8: + return 2; + case UAVObjectField::INT16: + return 4; + case UAVObjectField::INT32: + return 8; + case UAVObjectField::UINT8: + return 2; + case UAVObjectField::UINT16: + return 4; + case UAVObjectField::UINT32: + return 8; + default: + Q_ASSERT(false); + } + return 0; + } + signals: void updateHighlight(TreeItem *); @@ -324,8 +345,14 @@ public: class ArrayFieldTreeItem : public TreeItem { Q_OBJECT public: - ArrayFieldTreeItem(const QList &data, TreeItem *parent = 0) : TreeItem(data, parent) {} - ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) {} + ArrayFieldTreeItem(UAVObjectField *field, const QList &data, TreeItem *parent = 0) : TreeItem(data, parent), m_field(field) + {} + ArrayFieldTreeItem(UAVObjectField *field, const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent), m_field(field) + {} + QVariant data(int column) const; + +private: + UAVObjectField*m_field; }; #endif // TREEITEM_H diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp index 5a14c08c2..ca57295a8 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp @@ -188,7 +188,7 @@ void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent) void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent) { - TreeItem *item = new ArrayFieldTreeItem(field->getName()); + TreeItem *item = new ArrayFieldTreeItem(field, field->getName()); item->setHighlightManager(m_highlightManager); connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); diff --git a/shared/uavobjectdefinition/firmwareiapobj.xml b/shared/uavobjectdefinition/firmwareiapobj.xml index 754759583..74c12cca3 100644 --- a/shared/uavobjectdefinition/firmwareiapobj.xml +++ b/shared/uavobjectdefinition/firmwareiapobj.xml @@ -3,7 +3,7 @@ Queries board for SN, model, revision, and sends reset command - +