mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-1524 Added Array tree node value preview.
This commit is contained in:
parent
5c2a013433
commit
0aa8c47b48
@ -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 {
|
||||
|
@ -228,3 +228,34 @@ QList<MetaObjectTreeItem *> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) {}
|
||||
ArrayFieldTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) {}
|
||||
ArrayFieldTreeItem(UAVObjectField *field, const QList<QVariant> &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
|
||||
|
@ -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 *)));
|
||||
|
@ -3,7 +3,7 @@
|
||||
<description>Queries board for SN, model, revision, and sends reset command</description>
|
||||
<field name="Command" units="" type="uint16" elements="1"/>
|
||||
<field name="Description" units="" type="uint8" elements="100"/>
|
||||
<field name="CPUSerial" units="" type="uint8" elements="12" />
|
||||
<field name="CPUSerial" units="hex" type="uint8" elements="12" />
|
||||
<field name="BoardRevision" units="" type="uint16" elements="1"/>
|
||||
<field name="BoardType" units="" type="uint8" elements="1"/>
|
||||
<field name="BootloaderRevision" units="" type="uint8" elements="1"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user