mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
GCS/uavobjectbrowser: Allow changing fields.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@447 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
c7d78f67c9
commit
ea6843ed83
@ -28,6 +28,17 @@
|
||||
#ifndef TREEITEM_H
|
||||
#define TREEITEM_H
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfieldenum.h"
|
||||
#include "uavobjects/uavobjectfieldint8.h"
|
||||
#include "uavobjects/uavobjectfieldint16.h"
|
||||
#include "uavobjects/uavobjectfieldint32.h"
|
||||
#include "uavobjects/uavobjectfielduint8.h"
|
||||
#include "uavobjects/uavobjectfielduint16.h"
|
||||
#include "uavobjects/uavobjectfielduint32.h"
|
||||
#include "uavobjects/uavobjectfieldfloat.h"
|
||||
#include "uavobjects/uavobjectfieldenum.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QStringList>
|
||||
@ -47,7 +58,7 @@ class TreeItem
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
QVariant data(int column) const;
|
||||
void setData(int column, QVariant value);
|
||||
virtual void setData(int column, QVariant value);
|
||||
int row() const;
|
||||
TreeItem *parent() { return m_parent; }
|
||||
void setParent(TreeItem *parent) { m_parent = parent; }
|
||||
@ -55,6 +66,7 @@ class TreeItem
|
||||
|
||||
private:
|
||||
QList<TreeItem*> m_children;
|
||||
// m_data contains: [0] property name, [1] value, and [2] unit
|
||||
QList<QVariant> m_data;
|
||||
TreeItem *m_parent;
|
||||
};
|
||||
@ -115,6 +127,7 @@ public:
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
TreeItem(data, parent), m_index(index) { }
|
||||
inline int index() { return m_index; }
|
||||
bool isEditable() { return true; }
|
||||
virtual bool isIntType() { return false; }
|
||||
virtual bool isEnum() { return false; }
|
||||
@ -126,12 +139,55 @@ private:
|
||||
class EnumFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
public:
|
||||
EnumFieldTreeItem(int index, const QList<QVariant> &data, QStringList enumOptions, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions) { }
|
||||
EnumFieldTreeItem(int index, const QVariant &data, QStringList enumOptions, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions) { }
|
||||
EnumFieldTreeItem(UAVMetaObject *mobj, int index, const QList<QVariant> &data,
|
||||
QStringList enumOptions, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_mobj(mobj), m_field(0) { }
|
||||
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QList<QVariant> &data,
|
||||
QStringList enumOptions, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
||||
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QVariant &data,
|
||||
QStringList enumOptions, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
if (m_field) {
|
||||
m_field->setSelectedIndex(value.toInt(), index());
|
||||
} else {
|
||||
UAVObject::Metadata md = m_mobj->getData();
|
||||
switch(index()) {
|
||||
case 0:
|
||||
md.flightTelemetryAcked = value.toInt();
|
||||
break;
|
||||
case 1:
|
||||
md.flightTelemetryUpdateMode = value.toInt();
|
||||
break;
|
||||
case 2:
|
||||
md.flightTelemetryUpdatePeriod = value.toInt();
|
||||
break;
|
||||
case 3:
|
||||
md.gcsTelemetryAcked = value.toInt();
|
||||
break;
|
||||
case 4:
|
||||
md.gcsTelemetryUpdateMode = value.toInt();
|
||||
break;
|
||||
case 5:
|
||||
md.gcsTelemetryUpdatePeriod = value.toInt();
|
||||
break;
|
||||
case 6:
|
||||
md.loggingUpdateMode = value.toInt();
|
||||
break;
|
||||
case 7:
|
||||
md.loggingUpdatePeriod = value.toInt();
|
||||
break;
|
||||
}
|
||||
m_mobj->setData(md);
|
||||
}
|
||||
}
|
||||
bool isEnum() { return true; }
|
||||
QStringList enumOptions;
|
||||
private:
|
||||
UAVObjectFieldEnum *m_field;
|
||||
UAVMetaObject *m_mobj;
|
||||
};
|
||||
|
||||
class IntFieldTreeItem : public FieldTreeItem
|
||||
@ -146,14 +202,145 @@ public:
|
||||
int MAX;
|
||||
};
|
||||
|
||||
class Int8FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toInt());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt8 *m_field;
|
||||
};
|
||||
|
||||
class Int16FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toInt());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt16 *m_field;
|
||||
};
|
||||
|
||||
class Int32FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
Int32FieldTreeItem(UAVMetaObject *mobj, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_mobj(mobj), m_field(0) { }
|
||||
Int32FieldTreeItem(UAVObjectFieldInt32 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field), m_mobj(0) { }
|
||||
Int32FieldTreeItem(UAVObjectFieldInt32 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field), m_mobj(0) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
if (m_field) {
|
||||
m_field->setValue(value.toInt());
|
||||
} else {
|
||||
UAVObject::Metadata md = m_mobj->getData();
|
||||
switch(index()) {
|
||||
case 0:
|
||||
md.flightTelemetryAcked = value.toInt();
|
||||
break;
|
||||
case 1:
|
||||
md.flightTelemetryUpdateMode = value.toInt();
|
||||
break;
|
||||
case 2:
|
||||
md.flightTelemetryUpdatePeriod = value.toInt();
|
||||
break;
|
||||
case 3:
|
||||
md.gcsTelemetryAcked = value.toInt();
|
||||
break;
|
||||
case 4:
|
||||
md.gcsTelemetryUpdateMode = value.toInt();
|
||||
break;
|
||||
case 5:
|
||||
md.gcsTelemetryUpdatePeriod = value.toInt();
|
||||
break;
|
||||
case 6:
|
||||
md.loggingUpdateMode = value.toInt();
|
||||
break;
|
||||
case 7:
|
||||
md.loggingUpdatePeriod = value.toInt();
|
||||
break;
|
||||
}
|
||||
m_mobj->setData(md);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt32 *m_field;
|
||||
UAVMetaObject *m_mobj;
|
||||
};
|
||||
|
||||
class UInt8FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toInt());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt8 *m_field;
|
||||
};
|
||||
|
||||
class UInt16FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toInt());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt16 *m_field;
|
||||
};
|
||||
|
||||
class UInt32FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
public:
|
||||
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toInt());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt32 *m_field;
|
||||
};
|
||||
|
||||
|
||||
class FloatFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
public:
|
||||
FloatFieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent) { }
|
||||
FloatFieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent) { }
|
||||
FloatFieldTreeItem(UAVObjectFieldFloat *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
FloatFieldTreeItem(UAVObjectFieldFloat *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
bool isFloatType() { return true; }
|
||||
void setData(int column, QVariant value) {
|
||||
TreeItem::setData(column, value);
|
||||
m_field->setValue(value.toDouble());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldFloat *m_field;
|
||||
};
|
||||
|
||||
|
||||
|
@ -122,28 +122,28 @@ void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
QList<QVariant> data;
|
||||
QString msUnit = tr("ms");
|
||||
data << tr("Flight Telemetry Acked") << md.flightTelemetryAcked;
|
||||
meta->appendChild(new EnumFieldTreeItem(0, data, boolList));
|
||||
meta->appendChild(new EnumFieldTreeItem(obj, 0, data, boolList));
|
||||
data.clear();
|
||||
data << tr("Flight Telemetry Update Mode") << md.flightTelemetryUpdateMode;
|
||||
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
|
||||
meta->appendChild(new EnumFieldTreeItem(obj, 1, data, updateModeList));
|
||||
data.clear();
|
||||
data << tr("Flight Telemetry Update Period") << md.flightTelemetryUpdatePeriod << msUnit;
|
||||
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
|
||||
meta->appendChild(new Int32FieldTreeItem(obj, 2, data, QINT32MIN, QINT32MAX));
|
||||
data.clear();
|
||||
data << tr("GCS Telemetry Acked") << md.gcsTelemetryAcked;
|
||||
meta->appendChild(new EnumFieldTreeItem(0, data, boolList));
|
||||
meta->appendChild(new EnumFieldTreeItem(obj, 3, data, boolList));
|
||||
data.clear();
|
||||
data << tr("GCS Telemetry Update Mode") << md.gcsTelemetryUpdateMode;
|
||||
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
|
||||
meta->appendChild(new EnumFieldTreeItem(obj, 4, data, updateModeList));
|
||||
data.clear();
|
||||
data << tr("GCS Telemetry Update Period") << md.gcsTelemetryUpdatePeriod << msUnit;
|
||||
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
|
||||
meta->appendChild(new Int32FieldTreeItem(obj, 5, data, QINT32MIN, QINT32MAX));
|
||||
data.clear();
|
||||
data << tr("Logging Update Mode") << md.loggingUpdateMode;
|
||||
meta->appendChild(new EnumFieldTreeItem(0, data, updateModeList));
|
||||
meta->appendChild(new EnumFieldTreeItem(obj, 6, data, updateModeList));
|
||||
data.clear();
|
||||
data << tr("Logging Update Period") << md.loggingUpdatePeriod << msUnit;
|
||||
meta->appendChild(new IntFieldTreeItem(0, data, QINT32MIN, QINT32MAX));
|
||||
meta->appendChild(new Int32FieldTreeItem(obj, 7, data, QINT32MIN, QINT32MAX));
|
||||
parent->appendChild(meta);
|
||||
}
|
||||
|
||||
@ -196,37 +196,37 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
|
||||
|
||||
FieldTreeItem *item;
|
||||
if (enumField) {
|
||||
data.append(enumField->getSelectedIndex());
|
||||
data.append(enumField->getSelectedIndex(index));
|
||||
data.append(field->getUnits());
|
||||
item = new EnumFieldTreeItem(index, data, enumField->getOptions());
|
||||
item = new EnumFieldTreeItem(enumField, index, data, enumField->getOptions());
|
||||
} else if (int8Field) {
|
||||
data.append(int8Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QINT8MIN, QINT8MAX);
|
||||
item = new Int8FieldTreeItem(int8Field, index, data, QINT8MIN, QINT8MAX);
|
||||
} else if (int16Field) {
|
||||
data.append(int16Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QINT16MIN, QINT16MAX);
|
||||
item = new Int16FieldTreeItem(int16Field, index, data, QINT16MIN, QINT16MAX);
|
||||
} else if (int32Field) {
|
||||
data.append(int32Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QINT32MIN, QINT32MAX);
|
||||
item = new Int32FieldTreeItem(int32Field, index, data, QINT32MIN, QINT32MAX);
|
||||
} else if (uInt8Field) {
|
||||
data.append(uInt8Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT8MAX);
|
||||
item = new UInt8FieldTreeItem(uInt8Field, index, data, QUINTMIN, QUINT8MAX);
|
||||
} else if (uInt16Field) {
|
||||
data.append(uInt16Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT16MAX);
|
||||
item = new UInt16FieldTreeItem(uInt16Field, index, data, QUINTMIN, QUINT16MAX);
|
||||
} else if (uInt32Field) {
|
||||
data.append(uInt32Field->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new IntFieldTreeItem(index, data, QUINTMIN, QUINT32MAX);
|
||||
item = new UInt32FieldTreeItem(uInt32Field, index, data, QUINTMIN, QUINT32MAX);
|
||||
} else if (floatField) {
|
||||
data.append(floatField->getValue());
|
||||
data.append(field->getUnits());
|
||||
item = new FloatFieldTreeItem(index, data);
|
||||
item = new FloatFieldTreeItem(floatField, index, data);
|
||||
} else {
|
||||
data.append("Data Error");
|
||||
data.append(field->getUnits());
|
||||
|
Loading…
x
Reference in New Issue
Block a user