1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

OP-1538 Added description to fields in the UAVObject description files.

Descriptions can be added to fields either as attributes or child nodes.
Descriptions are not mandatory at this stage.
The description shows up when hovering over objects and fields in the UAVObject browser.

Added example descriptions to a few fields in the UAVO descriptor files.
This commit is contained in:
Fredrik Arvidsson 2014-10-11 16:12:58 +02:00
parent 9fd4fb26b9
commit ef15064b26
12 changed files with 59 additions and 23 deletions

View File

@ -471,7 +471,6 @@ private:
{ {
return QVariant(str.toString().at(0).toLatin1()); return QVariant(str.toString().at(0).toLatin1());
} }
}; };
#endif // FIELDTREEITEM_H #endif // FIELDTREEITEM_H

View File

@ -250,7 +250,7 @@ QVariant ArrayFieldTreeItem::data(int column) const
.arg(m_field->getValue(i).toUInt(&ok), TreeItem::maxHexStringLength(m_field->getType()), .arg(m_field->getValue(i).toUInt(&ok), TreeItem::maxHexStringLength(m_field->getType()),
16, QChar('0')).toUpper()); 16, QChar('0')).toUpper());
} }
QString data = QString("{%1}").arg(dataString); QString data = QString("{%1}").arg(dataString);
return data; return data;
} else { } else {
return QVariant(); return QVariant();

View File

@ -184,16 +184,22 @@ public:
switch (type) { switch (type) {
case UAVObjectField::INT8: case UAVObjectField::INT8:
return 2; return 2;
case UAVObjectField::INT16: case UAVObjectField::INT16:
return 4; return 4;
case UAVObjectField::INT32: case UAVObjectField::INT32:
return 8; return 8;
case UAVObjectField::UINT8: case UAVObjectField::UINT8:
return 2; return 2;
case UAVObjectField::UINT16: case UAVObjectField::UINT16:
return 4; return 4;
case UAVObjectField::UINT32: case UAVObjectField::UINT32:
return 8; return 8;
default: default:
Q_ASSERT(false); Q_ASSERT(false);
} }
@ -352,7 +358,7 @@ public:
QVariant data(int column) const; QVariant data(int column) const;
private: private:
UAVObjectField*m_field; UAVObjectField *m_field;
}; };
#endif // TREEITEM_H #endif // TREEITEM_H

View File

@ -245,6 +245,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
Q_ASSERT(false); Q_ASSERT(false);
} }
item->setHighlightManager(m_highlightManager); item->setHighlightManager(m_highlightManager);
item->setDescription(field->getDescription());
connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *)));
parent->appendChild(item); parent->appendChild(item);
} }

View File

@ -41,10 +41,10 @@ UAVMetaObject::UAVMetaObject(quint32 objID, const QString & name, UAVObject *par
QStringList modesBitField; QStringList modesBitField;
modesBitField << tr("FlightReadOnly") << tr("GCSReadOnly") << tr("FlightTelemetryAcked") << tr("GCSTelemetryAcked") << tr("FlightUpdatePeriodic") << tr("FlightUpdateOnChange") << tr("GCSUpdatePeriodic") << tr("GCSUpdateOnChange") << tr("LoggingUpdatePeriodic") << tr("LoggingUpdateOnChange"); modesBitField << tr("FlightReadOnly") << tr("GCSReadOnly") << tr("FlightTelemetryAcked") << tr("GCSTelemetryAcked") << tr("FlightUpdatePeriodic") << tr("FlightUpdateOnChange") << tr("GCSUpdatePeriodic") << tr("GCSUpdateOnChange") << tr("LoggingUpdatePeriodic") << tr("LoggingUpdateOnChange");
QList<UAVObjectField *> fields; QList<UAVObjectField *> fields;
fields.append(new UAVObjectField(tr("Modes"), tr("boolean"), UAVObjectField::BITFIELD, modesBitField, QStringList())); fields.append(new UAVObjectField(tr("Modes"), tr("Metadata modes"), tr("boolean"), UAVObjectField::BITFIELD, modesBitField, QStringList()));
fields.append(new UAVObjectField(tr("Flight Telemetry Update Period"), tr("ms"), UAVObjectField::UINT16, 1, QStringList())); fields.append(new UAVObjectField(tr("Flight Telemetry Update Period"), tr("This is how often flight side will update telemetry data"), tr("ms"), UAVObjectField::UINT16, 1, QStringList()));
fields.append(new UAVObjectField(tr("GCS Telemetry Update Period"), tr("ms"), UAVObjectField::UINT16, 1, QStringList())); fields.append(new UAVObjectField(tr("GCS Telemetry Update Period"), tr("This is how often GCS will update telemetry data"), tr("ms"), UAVObjectField::UINT16, 1, QStringList()));
fields.append(new UAVObjectField(tr("Logging Update Period"), tr("ms"), UAVObjectField::UINT16, 1, QStringList())); fields.append(new UAVObjectField(tr("Logging Update Period"), tr("This is how often logging will be updated."), tr("ms"), UAVObjectField::UINT16, 1, QStringList()));
// Initialize parent // Initialize parent
UAVObject::initialize(0); UAVObject::initialize(0);
UAVObject::initializeFields(fields, (quint8 *)&parentMetadata, sizeof(Metadata)); UAVObject::initializeFields(fields, (quint8 *)&parentMetadata, sizeof(Metadata));

View File

@ -30,7 +30,7 @@
#include <QDebug> #include <QDebug>
#include <QtWidgets> #include <QtWidgets>
UAVObjectField::UAVObjectField(const QString & name, const QString & units, FieldType type, quint32 numElements, const QStringList & options, const QString &limits) UAVObjectField::UAVObjectField(const QString & name, const QString & description, const QString & units, FieldType type, quint32 numElements, const QStringList & options, const QString &limits)
{ {
QStringList elementNames; QStringList elementNames;
@ -39,18 +39,19 @@ UAVObjectField::UAVObjectField(const QString & name, const QString & units, Fiel
elementNames.append(QString("%1").arg(n)); elementNames.append(QString("%1").arg(n));
} }
// Initialize // Initialize
constructorInitialize(name, units, type, elementNames, options, limits); constructorInitialize(name, description, units, type, elementNames, options, limits);
} }
UAVObjectField::UAVObjectField(const QString & name, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits) UAVObjectField::UAVObjectField(const QString & name, const QString & description, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits)
{ {
constructorInitialize(name, units, type, elementNames, options, limits); constructorInitialize(name, description, units, type, elementNames, options, limits);
} }
void UAVObjectField::constructorInitialize(const QString & name, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits) void UAVObjectField::constructorInitialize(const QString & name, const QString & description, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits)
{ {
// Copy params // Copy params
this->name = name; this->name = name;
this->description = description;
this->units = units; this->units = units;
this->type = type; this->type = type;
this->options = options; this->options = options;
@ -609,6 +610,11 @@ QString UAVObjectField::getName()
return name; return name;
} }
QString UAVObjectField::getDescription()
{
return description;
}
QString UAVObjectField::getUnits() QString UAVObjectField::getUnits()
{ {
return units; return units;

View File

@ -52,13 +52,14 @@ public:
int board; int board;
} LimitStruct; } LimitStruct;
UAVObjectField(const QString & name, const QString & units, FieldType type, quint32 numElements, const QStringList & options, const QString & limits = QString()); UAVObjectField(const QString & name, const QString & description, const QString & units, FieldType type, quint32 numElements, const QStringList & options, const QString & limits = QString());
UAVObjectField(const QString & name, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString & limits = QString()); UAVObjectField(const QString & name, const QString & description, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString & limits = QString());
void initialize(quint8 *data, quint32 dataOffset, UAVObject *obj); void initialize(quint8 *data, quint32 dataOffset, UAVObject *obj);
UAVObject *getObject(); UAVObject *getObject();
FieldType getType(); FieldType getType();
QString getTypeAsString(); QString getTypeAsString();
QString getName(); QString getName();
QString getDescription();
QString getUnits(); QString getUnits();
quint32 getNumElements(); quint32 getNumElements();
QStringList getElementNames(); QStringList getElementNames();
@ -91,6 +92,7 @@ signals:
protected: protected:
QString name; QString name;
QString description;
QString units; QString units;
FieldType type; FieldType type;
QStringList elementNames; QStringList elementNames;
@ -102,7 +104,7 @@ protected:
UAVObject *obj; UAVObject *obj;
QMap<quint32, QList<LimitStruct> > elementLimits; QMap<quint32, QList<LimitStruct> > elementLimits;
void clear(); void clear();
void constructorInitialize(const QString & name, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits); void constructorInitialize(const QString & name, const QString & description, const QString & units, FieldType type, const QStringList & elementNames, const QStringList & options, const QString &limits);
void limitsInitialize(const QString &limits); void limitsInitialize(const QString &limits);
}; };

View File

@ -259,8 +259,9 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *info)
.arg(varOptionName) .arg(varOptionName)
.arg(options[m])); .arg(options[m]));
} }
finit.append(QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::ENUM, %3, %4, QString(\"%5\")));\n") finit.append(QString(" fields.append( new UAVObjectField(QString(\"%1\"), tr(\"%2\"), QString(\"%3\"), UAVObjectField::ENUM, %4, %5, QString(\"%6\")));\n")
.arg(info->fields[n]->name) .arg(info->fields[n]->name)
.arg(info->fields[n]->description)
.arg(info->fields[n]->units) .arg(info->fields[n]->units)
.arg(varElemName) .arg(varElemName)
.arg(varOptionName) .arg(varOptionName)
@ -268,8 +269,9 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo *info)
} }
// For all other types // For all other types
else { else {
finit.append(QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::%3, %4, QStringList(), QString(\"%5\")));\n") finit.append(QString(" fields.append( new UAVObjectField(QString(\"%1\"), tr(\"%2\"), QString(\"%3\"), UAVObjectField::%4, %5, QStringList(), QString(\"%6\")));\n")
.arg(info->fields[n]->name) .arg(info->fields[n]->name)
.arg(info->fields[n]->description)
.arg(info->fields[n]->units) .arg(info->fields[n]->units)
.arg(fieldTypeStrCPPClass[info->fields[n]->type]) .arg(fieldTypeStrCPPClass[info->fields[n]->type])
.arg(varElemName) .arg(varElemName)

View File

@ -25,7 +25,7 @@
*/ */
#include "uavobjectparser.h" #include "uavobjectparser.h"
#include <QDebug>
/** /**
* Constructor * Constructor
*/ */
@ -441,6 +441,21 @@ QString UAVObjectParser::processObjectFields(QDomNode & childNode, ObjectInfo *i
field->name = name; field->name = name;
} }
// Get description attribute if any
elemAttr = elemAttributes.namedItem("description");
if (!elemAttr.isNull()) {
field->description = elemAttr.nodeValue();
} else {
// Look for a child description node
QDomNode node = childNode.firstChildElement("description");
if (!node.isNull()) {
QDomNode description = node.firstChild();
if (!description.isNull()) {
field->description = description.nodeValue();
}
}
}
// Get units attribute // Get units attribute
elemAttr = elemAttributes.namedItem("units"); elemAttr = elemAttributes.namedItem("units");
if (elemAttr.isNull()) { if (elemAttr.isNull()) {
@ -572,6 +587,7 @@ QString UAVObjectParser::processObjectFields(QDomNode & childNode, ObjectInfo *i
} }
// Add field to object // Add field to object
info->fields.append(field); info->fields.append(field);
qDebug() << "field added" << info->name << ", description" << field->description;
// Done // Done
return QString(); return QString();
} }

View File

@ -49,6 +49,7 @@ typedef enum {
typedef struct { typedef struct {
QString name; QString name;
QString description;
QString units; QString units;
FieldType type; FieldType type;
int numElements; int numElements;

View File

@ -1,7 +1,10 @@
<xml> <xml>
<object name="DebugLogSettings" singleinstance="true" settings="true" category="System"> <object name="DebugLogSettings" singleinstance="true" settings="true" category="System">
<description>Configure On Board Logging Facilities</description> <description>Configure On Board Logging Facilities</description>
<field name="LoggingEnabled" units="" type="enum" elements="1" options="Disabled,OnlyWhenArmed,Always" defaultvalue="Disabled" />
<field name="LoggingEnabled" units="" type="enum" elements="1" options="Disabled,OnlyWhenArmed,Always" defaultvalue="Disabled">
<description>If set to OnlyWhenArmed logs will only be saved when craft is armed. Disabled turns logging off, and Always will always log.</description>
</field>
<access gcs="readwrite" flight="readwrite"/> <access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/> <telemetrygcs acked="true" updatemode="onchange" period="0"/>

View File

@ -1,10 +1,10 @@
<xml> <xml>
<object name="DebugLogStatus" singleinstance="true" settings="false" category="System"> <object name="DebugLogStatus" singleinstance="true" settings="false" category="System">
<description>Log Status Object, contains log partition status information</description> <description>Log Status Object, contains log partition status information</description>
<field name="Flight" units="" type="uint16" elements="1" /> <field name="Flight" units="" type="uint16" elements="1" description="The current flight number (logging session)"/>
<field name="Entry" units="" type="uint16" elements="1" /> <field name="Entry" units="" type="uint16" elements="1" description="The current log entry id"/>
<field name="UsedSlots" units="" type="uint16" elements="1" /> <field name="UsedSlots" units="" type="uint16" elements="1" description="Holds the total log entries saved"/>
<field name="FreeSlots" units="" type="uint16" elements="1" /> <field name="FreeSlots" units="" type="uint16" elements="1" description="The number of free log slots available"/>
<access gcs="readwrite" flight="readwrite"/> <access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="false" updatemode="manual" period="0"/> <telemetrygcs acked="false" updatemode="manual" period="0"/>
<telemetryflight acked="false" updatemode="periodic" period="1000"/> <telemetryflight acked="false" updatemode="periodic" period="1000"/>