mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-1183 UAVObjectBrowser now displays and allows editing of integers in
hex format (when unit is set to hex) +review OPReview
This commit is contained in:
parent
98d061d647
commit
d8e1d849f5
@ -51,18 +51,23 @@
|
|||||||
class FieldTreeItem : public TreeItem {
|
class FieldTreeItem : public TreeItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
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) {}
|
||||||
|
|
||||||
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) {}
|
||||||
|
|
||||||
bool isEditable()
|
bool isEditable()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual QWidget *createEditor(QWidget *parent) = 0;
|
virtual QWidget *createEditor(QWidget *parent) = 0;
|
||||||
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
||||||
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
||||||
virtual void apply() {}
|
virtual void apply() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_index;
|
int m_index;
|
||||||
};
|
};
|
||||||
@ -70,12 +75,12 @@ protected:
|
|||||||
class EnumFieldTreeItem : public FieldTreeItem {
|
class EnumFieldTreeItem : public FieldTreeItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
TreeItem *parent = 0) :
|
|
||||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) {}
|
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) {}
|
||||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
|
||||||
TreeItem *parent = 0) :
|
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) {}
|
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) {}
|
||||||
|
|
||||||
void setData(QVariant value, int column)
|
void setData(QVariant value, int column)
|
||||||
{
|
{
|
||||||
QStringList options = m_field->getOptions();
|
QStringList options = m_field->getOptions();
|
||||||
@ -85,6 +90,7 @@ public:
|
|||||||
setChanged(tmpValIndex != value);
|
setChanged(tmpValIndex != value);
|
||||||
TreeItem::setData(value, column);
|
TreeItem::setData(value, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString enumOptions(int index)
|
QString enumOptions(int index)
|
||||||
{
|
{
|
||||||
if ((index < 0) || (index >= m_enumOptions.length())) {
|
if ((index < 0) || (index >= m_enumOptions.length())) {
|
||||||
@ -92,6 +98,7 @@ public:
|
|||||||
}
|
}
|
||||||
return m_enumOptions.at(index);
|
return m_enumOptions.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply()
|
void apply()
|
||||||
{
|
{
|
||||||
int value = data(dataColumn).toInt();
|
int value = data(dataColumn).toInt();
|
||||||
@ -100,6 +107,7 @@ public:
|
|||||||
m_field->setValue(options[value], m_index);
|
m_field->setValue(options[value], m_index);
|
||||||
setChanged(false);
|
setChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update()
|
||||||
{
|
{
|
||||||
QStringList options = m_field->getOptions();
|
QStringList options = m_field->getOptions();
|
||||||
@ -111,14 +119,16 @@ public:
|
|||||||
setHighlight(true);
|
setHighlight(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent)
|
QWidget *createEditor(QWidget *parent)
|
||||||
{
|
{
|
||||||
QComboBox *editor = new QComboBox(parent);
|
QComboBox *editor = new QComboBox(parent);
|
||||||
|
|
||||||
// Setting ClickFocus lets the ComboBox stay open on Mac OSX.
|
// Setting ClickFocus lets the ComboBox stay open on Mac OSX.
|
||||||
editor->setFocusPolicy(Qt::ClickFocus);
|
editor->setFocusPolicy(Qt::ClickFocus);
|
||||||
foreach(QString option, m_enumOptions)
|
foreach(QString option, m_enumOptions) {
|
||||||
editor->addItem(option);
|
editor->addItem(option);
|
||||||
|
}
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +145,7 @@ public:
|
|||||||
|
|
||||||
comboBox->setCurrentIndex(value.toInt());
|
comboBox->setCurrentIndex(value.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_enumOptions;
|
QStringList m_enumOptions;
|
||||||
UAVObjectField *m_field;
|
UAVObjectField *m_field;
|
||||||
@ -148,6 +159,7 @@ public:
|
|||||||
{
|
{
|
||||||
setMinMaxValues();
|
setMinMaxValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), m_field(field)
|
FieldTreeItem(index, data, parent), m_field(field)
|
||||||
{
|
{
|
||||||
@ -210,16 +222,19 @@ public:
|
|||||||
|
|
||||||
spinBox->setValue(value.toInt());
|
spinBox->setValue(value.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void setData(QVariant value, int column)
|
void setData(QVariant value, int column)
|
||||||
{
|
{
|
||||||
setChanged(m_field->getValue(m_index) != value);
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(value, column);
|
TreeItem::setData(value, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply()
|
void apply()
|
||||||
{
|
{
|
||||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||||
setChanged(false);
|
setChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update()
|
||||||
{
|
{
|
||||||
int value = m_field->getValue(m_index).toInt();
|
int value = m_field->getValue(m_index).toInt();
|
||||||
@ -241,18 +256,22 @@ class FloatFieldTreeItem : public FieldTreeItem {
|
|||||||
public:
|
public:
|
||||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, bool scientific = false, TreeItem *parent = 0) :
|
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, bool scientific = false, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) {}
|
FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) {}
|
||||||
|
|
||||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, bool scientific = false, TreeItem *parent = 0) :
|
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, bool scientific = false, TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) {}
|
FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) {}
|
||||||
|
|
||||||
void setData(QVariant value, int column)
|
void setData(QVariant value, int column)
|
||||||
{
|
{
|
||||||
setChanged(m_field->getValue(m_index) != value);
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
TreeItem::setData(value, column);
|
TreeItem::setData(value, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply()
|
void apply()
|
||||||
{
|
{
|
||||||
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
||||||
setChanged(false);
|
setChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update()
|
||||||
{
|
{
|
||||||
double value = m_field->getValue(m_index).toDouble();
|
double value = m_field->getValue(m_index).toDouble();
|
||||||
@ -303,9 +322,115 @@ public:
|
|||||||
spinBox->setValue(value.toDouble());
|
spinBox->setValue(value.toDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UAVObjectField *m_field;
|
UAVObjectField *m_field;
|
||||||
bool m_useScientificNotation;
|
bool m_useScientificNotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class HexFieldTreeItem : public FieldTreeItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
HexFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
|
FieldTreeItem(index, data, parent), m_field(field)
|
||||||
|
{}
|
||||||
|
|
||||||
|
HexFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
|
FieldTreeItem(index, data, parent), m_field(field)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QWidget *createEditor(QWidget *parent)
|
||||||
|
{
|
||||||
|
QLineEdit *lineEdit = new QLineEdit(parent);
|
||||||
|
|
||||||
|
lineEdit->setInputMask(QString(maxLength(), 'H'));
|
||||||
|
|
||||||
|
return lineEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant getEditorValue(QWidget *editor)
|
||||||
|
{
|
||||||
|
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
|
||||||
|
|
||||||
|
return lineEdit->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEditorValue(QWidget *editor, QVariant value)
|
||||||
|
{
|
||||||
|
QLineEdit *lineEdit = static_cast<QLineEdit *>(editor);
|
||||||
|
|
||||||
|
lineEdit->setText(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setData(QVariant value, int column)
|
||||||
|
{
|
||||||
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
|
TreeItem::setData(value, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply()
|
||||||
|
{
|
||||||
|
m_field->setValue(toUInt(data(dataColumn)), m_index);
|
||||||
|
setChanged(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
QVariant value = toHexString(m_field->getValue(m_index));
|
||||||
|
|
||||||
|
if (data() != value || changed()) {
|
||||||
|
TreeItem::setData(value);
|
||||||
|
setHighlight(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
UAVObjectField *m_field;
|
||||||
|
|
||||||
|
QVariant toHexString(QVariant value)
|
||||||
|
{
|
||||||
|
QString str;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
return str.setNum(value.toUInt(&ok), 16).toUpper();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant toUInt(QVariant str)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif // FIELDTREEITEM_H
|
#endif // FIELDTREEITEM_H
|
||||||
|
@ -228,7 +228,11 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
|
|||||||
case UAVObjectField::UINT32:
|
case UAVObjectField::UINT32:
|
||||||
data.append(field->getValue(index));
|
data.append(field->getValue(index));
|
||||||
data.append(field->getUnits());
|
data.append(field->getUnits());
|
||||||
|
if (field->getUnits().toLower() == "hex") {
|
||||||
|
item = new HexFieldTreeItem(field, index, data);
|
||||||
|
} else {
|
||||||
item = new IntFieldTreeItem(field, index, data);
|
item = new IntFieldTreeItem(field, index, data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UAVObjectField::FLOAT32:
|
case UAVObjectField::FLOAT32:
|
||||||
data.append(field->getValue(index));
|
data.append(field->getValue(index));
|
||||||
@ -351,9 +355,6 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
|||||||
return item->data(index.column());
|
return item->data(index.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (role == Qt::DecorationRole)
|
|
||||||
// return QIcon(":/core/images/openpilot_logo_128.png");
|
|
||||||
|
|
||||||
if (role == Qt::ToolTipRole) {
|
if (role == Qt::ToolTipRole) {
|
||||||
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
||||||
return item->description();
|
return item->description();
|
||||||
|
Loading…
Reference in New Issue
Block a user