mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
GCS/uavobjectbrowser: Highlight manually changed fields.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@449 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
5f6de054fd
commit
0b4edfc940
@ -58,6 +58,8 @@ class TreeItem
|
|||||||
int childCount() const;
|
int childCount() const;
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
|
// only column 1 is changed with setData currently
|
||||||
|
// other columns are initialized in constructor
|
||||||
virtual void setData(int column, QVariant value);
|
virtual void setData(int column, QVariant value);
|
||||||
int row() const;
|
int row() const;
|
||||||
TreeItem *parent() { return m_parent; }
|
TreeItem *parent() { return m_parent; }
|
||||||
@ -124,16 +126,20 @@ class FieldTreeItem : public TreeItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
TreeItem(data, parent), m_index(index) { }
|
TreeItem(data, parent), m_index(index), m_changed(false) { }
|
||||||
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
TreeItem(data, parent), m_index(index) { }
|
TreeItem(data, parent), m_index(index), m_changed(false) { }
|
||||||
inline int index() { return m_index; }
|
|
||||||
bool isEditable() { return true; }
|
bool isEditable() { return true; }
|
||||||
|
bool isChanged() { return m_changed; }
|
||||||
|
void setChanged(bool changed) { m_changed = changed; }
|
||||||
virtual bool isIntType() { return false; }
|
virtual bool isIntType() { return false; }
|
||||||
virtual bool isEnum() { return false; }
|
virtual bool isEnum() { return false; }
|
||||||
virtual bool isFloatType() { return false; }
|
virtual bool isFloatType() { return false; }
|
||||||
private:
|
virtual void apply(int column) { }
|
||||||
|
protected:
|
||||||
int m_index;
|
int m_index;
|
||||||
|
private:
|
||||||
|
bool m_changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EnumFieldTreeItem : public FieldTreeItem
|
class EnumFieldTreeItem : public FieldTreeItem
|
||||||
@ -141,7 +147,7 @@ class EnumFieldTreeItem : public FieldTreeItem
|
|||||||
public:
|
public:
|
||||||
EnumFieldTreeItem(UAVMetaObject *mobj, int index, const QList<QVariant> &data,
|
EnumFieldTreeItem(UAVMetaObject *mobj, int index, const QList<QVariant> &data,
|
||||||
QStringList enumOptions, TreeItem *parent = 0) :
|
QStringList enumOptions, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_mobj(mobj), m_field(0) { }
|
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(0), m_mobj(mobj) { }
|
||||||
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QList<QVariant> &data,
|
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QList<QVariant> &data,
|
||||||
QStringList enumOptions, TreeItem *parent = 0) :
|
QStringList enumOptions, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
||||||
@ -149,35 +155,69 @@ public:
|
|||||||
QStringList enumOptions, TreeItem *parent = 0) :
|
QStringList enumOptions, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
FieldTreeItem(index, data, parent), enumOptions(enumOptions), m_field(field), m_mobj(0) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
TreeItem::setData(column, value);
|
if (m_field)
|
||||||
if (m_field) {
|
setChanged(m_field->getSelectedIndex(m_index) != value);
|
||||||
m_field->setSelectedIndex(value.toInt(), index());
|
else {
|
||||||
} else {
|
|
||||||
UAVObject::Metadata md = m_mobj->getData();
|
UAVObject::Metadata md = m_mobj->getData();
|
||||||
switch(index()) {
|
switch(m_index) {
|
||||||
case 0:
|
case 0:
|
||||||
md.flightTelemetryAcked = value.toInt();
|
setChanged(md.flightTelemetryAcked != value);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
md.flightTelemetryUpdateMode = value.toInt();
|
setChanged(md.flightTelemetryUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
md.flightTelemetryUpdatePeriod = value.toInt();
|
setChanged(md.flightTelemetryUpdatePeriod != value);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
md.gcsTelemetryAcked = value.toInt();
|
setChanged(md.gcsTelemetryAcked != value);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
md.gcsTelemetryUpdateMode = value.toInt();
|
setChanged(md.gcsTelemetryUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
md.gcsTelemetryUpdatePeriod = value.toInt();
|
setChanged(md.gcsTelemetryUpdatePeriod != value);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
md.loggingUpdateMode = value.toInt();
|
setChanged(md.loggingUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
md.loggingUpdatePeriod = value.toInt();
|
setChanged(md.loggingUpdatePeriod != value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TreeItem::setData(column, value);
|
||||||
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
int value = data(column).toInt();
|
||||||
|
if (m_field) {
|
||||||
|
m_field->setSelectedIndex(value, m_index);
|
||||||
|
} else {
|
||||||
|
UAVObject::Metadata md = m_mobj->getData();
|
||||||
|
switch(m_index) {
|
||||||
|
case 0:
|
||||||
|
md.flightTelemetryAcked = value;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
md.flightTelemetryUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
md.flightTelemetryUpdatePeriod = value;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
md.gcsTelemetryAcked = value;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
md.gcsTelemetryUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
md.gcsTelemetryUpdatePeriod = value;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
md.loggingUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
md.loggingUpdatePeriod = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_mobj->setData(md);
|
m_mobj->setData(md);
|
||||||
@ -210,8 +250,11 @@ public:
|
|||||||
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toInt());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toInt());
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldInt8 *m_field;
|
UAVObjectFieldInt8 *m_field;
|
||||||
@ -225,8 +268,11 @@ public:
|
|||||||
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toInt());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toInt());
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldInt16 *m_field;
|
UAVObjectFieldInt16 *m_field;
|
||||||
@ -236,41 +282,75 @@ class Int32FieldTreeItem : public IntFieldTreeItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Int32FieldTreeItem(UAVMetaObject *mobj, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 0) :
|
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) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(0), m_mobj(mobj) { }
|
||||||
Int32FieldTreeItem(UAVObjectFieldInt32 *field, int index, const QList<QVariant> &data, int min, int max, TreeItem *parent = 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) { }
|
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) :
|
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) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field), m_mobj(0) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
TreeItem::setData(column, value);
|
if (m_field)
|
||||||
if (m_field) {
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
m_field->setValue(value.toInt());
|
else {
|
||||||
} else {
|
|
||||||
UAVObject::Metadata md = m_mobj->getData();
|
UAVObject::Metadata md = m_mobj->getData();
|
||||||
switch(index()) {
|
switch(m_index) {
|
||||||
case 0:
|
case 0:
|
||||||
md.flightTelemetryAcked = value.toInt();
|
setChanged(md.flightTelemetryAcked != value);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
md.flightTelemetryUpdateMode = value.toInt();
|
setChanged(md.flightTelemetryUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
md.flightTelemetryUpdatePeriod = value.toInt();
|
setChanged(md.flightTelemetryUpdatePeriod != value);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
md.gcsTelemetryAcked = value.toInt();
|
setChanged(md.gcsTelemetryAcked != value);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
md.gcsTelemetryUpdateMode = value.toInt();
|
setChanged(md.gcsTelemetryUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
md.gcsTelemetryUpdatePeriod = value.toInt();
|
setChanged(md.gcsTelemetryUpdatePeriod != value);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
md.loggingUpdateMode = value.toInt();
|
setChanged(md.loggingUpdateMode != value);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
md.loggingUpdatePeriod = value.toInt();
|
setChanged(md.loggingUpdatePeriod != value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TreeItem::setData(column, value);
|
||||||
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
int value = data(column).toInt();
|
||||||
|
if (m_field) {
|
||||||
|
m_field->setValue(value);
|
||||||
|
} else {
|
||||||
|
UAVObject::Metadata md = m_mobj->getData();
|
||||||
|
switch(m_index) {
|
||||||
|
case 0:
|
||||||
|
md.flightTelemetryAcked = value;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
md.flightTelemetryUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
md.flightTelemetryUpdatePeriod = value;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
md.gcsTelemetryAcked = value;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
md.gcsTelemetryUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
md.gcsTelemetryUpdatePeriod = value;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
md.loggingUpdateMode = value;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
md.loggingUpdatePeriod = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_mobj->setData(md);
|
m_mobj->setData(md);
|
||||||
@ -289,8 +369,11 @@ public:
|
|||||||
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toInt());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toInt());
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldUInt8 *m_field;
|
UAVObjectFieldUInt8 *m_field;
|
||||||
@ -304,8 +387,11 @@ public:
|
|||||||
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toInt());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toInt());
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldUInt16 *m_field;
|
UAVObjectFieldUInt16 *m_field;
|
||||||
@ -319,8 +405,11 @@ public:
|
|||||||
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QVariant &data, int min, int max, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
IntFieldTreeItem(index, data, min, max, parent), m_field(field) { }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toInt());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toInt());
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldUInt32 *m_field;
|
UAVObjectFieldUInt32 *m_field;
|
||||||
@ -336,8 +425,11 @@ public:
|
|||||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||||
bool isFloatType() { return true; }
|
bool isFloatType() { return true; }
|
||||||
void setData(int column, QVariant value) {
|
void setData(int column, QVariant value) {
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(column, value);
|
TreeItem::setData(column, value);
|
||||||
m_field->setValue(value.toDouble());
|
}
|
||||||
|
void apply(int column) {
|
||||||
|
m_field->setValue(data(column).toDouble(), m_index);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UAVObjectFieldFloat *m_field;
|
UAVObjectFieldFloat *m_field;
|
||||||
|
@ -301,15 +301,23 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
|||||||
return item->data(index.column());
|
return item->data(index.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
//XXX
|
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||||
// if (index.column() == 1 && role == Qt::ForegroundRole)
|
|
||||||
// return QVariant( QColor( Qt::red ) );
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// if (index.column() == 1 && role == Qt::ForegroundRole) {
|
||||||
|
// FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
|
||||||
|
// if (fieldItem && fieldItem->isChanged())
|
||||||
|
// return QVariant(QColor(Qt::darkBlue));
|
||||||
|
// }
|
||||||
|
if (index.column() == 1 && role == Qt::BackgroundRole) {
|
||||||
|
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
|
||||||
|
if (fieldItem && fieldItem->isChanged())
|
||||||
|
return QVariant(QColor(230, 230, 255));
|
||||||
|
}
|
||||||
|
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
|
||||||
if (index.column() == 1) {
|
if (index.column() == 1) {
|
||||||
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
|
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem*>(item);
|
||||||
if (fieldItem) {
|
if (fieldItem) {
|
||||||
|
Loading…
Reference in New Issue
Block a user