1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-706 Added support for isKnown for Settings objects in UAVOBrowser.

This commit is contained in:
m_thread 2014-10-17 00:47:59 +02:00
parent 1e08528d54
commit 3246cf9756
6 changed files with 106 additions and 104 deletions

View File

@ -52,11 +52,13 @@ class FieldTreeItem : public TreeItem {
Q_OBJECT
public:
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) {}
FieldTreeItem(int index, const QList<QVariant> &data, UAVObjectField *field, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index), m_field(field)
{}
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index) {}
FieldTreeItem(int index, const QVariant &data, UAVObjectField *field, TreeItem *parent = 0) :
TreeItem(data, parent), m_index(index), m_field(field)
{}
bool isEditable()
{
@ -67,19 +69,27 @@ public:
virtual QVariant getEditorValue(QWidget *editor) = 0;
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
virtual void apply() {}
virtual bool isKnown()
{
return !m_field->getObject()->isSettingsObject() || m_field->getObject()->isKnown();
}
protected:
int m_index;
UAVObjectField *m_field;
};
class EnumFieldTreeItem : public FieldTreeItem {
Q_OBJECT
public:
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) {}
FieldTreeItem(index, data, field, parent), m_enumOptions(field->getOptions())
{}
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, field, parent), m_enumOptions(field->getOptions())
{}
void setData(QVariant value, int column)
{
@ -148,20 +158,19 @@ public:
private:
QStringList m_enumOptions;
UAVObjectField *m_field;
};
class IntFieldTreeItem : public FieldTreeItem {
Q_OBJECT
public:
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field)
FieldTreeItem(index, data, field, parent)
{
setMinMaxValues();
}
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field)
FieldTreeItem(index, data, field, parent)
{
setMinMaxValues();
}
@ -246,7 +255,6 @@ public:
}
private:
UAVObjectField *m_field;
int m_minValue;
int m_maxValue;
};
@ -255,10 +263,10 @@ class FloatFieldTreeItem : public FieldTreeItem {
Q_OBJECT
public:
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, field, parent), m_useScientificNotation(scientific) {}
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, field, parent), m_useScientificNotation(scientific) {}
void setData(QVariant value, int column)
{
@ -324,7 +332,6 @@ public:
}
private:
UAVObjectField *m_field;
bool m_useScientificNotation;
};
@ -332,11 +339,11 @@ 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)
FieldTreeItem(index, data, field, parent)
{}
HexFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field)
FieldTreeItem(index, data, field, parent)
{}
QWidget *createEditor(QWidget *parent)
@ -385,8 +392,6 @@ public:
}
private:
UAVObjectField *m_field;
QVariant toHexString(QVariant value)
{
QString str;
@ -407,11 +412,11 @@ class CharFieldTreeItem : public FieldTreeItem {
Q_OBJECT
public:
CharFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field)
FieldTreeItem(index, data, field, parent)
{}
CharFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field)
FieldTreeItem(index, data, field, parent)
{}
QWidget *createEditor(QWidget *parent)
@ -460,8 +465,6 @@ public:
}
private:
UAVObjectField *m_field;
QVariant toChar(QVariant value)
{
return value.toChar();

View File

@ -102,16 +102,14 @@ TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
m_data(data),
m_parent(parent),
m_highlight(false),
m_changed(false),
m_known(true)
m_changed(false)
{}
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
QObject(0),
m_parent(parent),
m_highlight(false),
m_changed(false),
m_known(true)
m_changed(false)
{
m_data << data << "" << "";
}

View File

@ -88,6 +88,9 @@ private:
class TreeItem : public QObject {
Q_OBJECT
public:
static const int TITLE_COLUMN = 0;
static const int DATA_COLUMN = 1;
TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
TreeItem(const QVariant &data, TreeItem *parent = 0);
virtual ~TreeItem();
@ -205,27 +208,31 @@ public:
}
return 0;
}
void setKnown(bool known)
void updateIsKnown(bool isKnown)
{
m_known = known;
if (isKnown != this->isKnown()) {
m_changed = false;
foreach(TreeItem * child, m_children) {
child->setKnown(known);
child->updateIsKnown(isKnown);
}
updateHighlight(this);
emit updateIsKnown(this);
}
inline bool isKnown()
}
virtual bool isKnown()
{
return m_known;
return true;
}
signals:
void updateHighlight(TreeItem *);
void updateHighlight(TreeItem *item);
void updateIsKnown(TreeItem *item);
private slots:
private:
static int m_highlightTimeMs;
QList<TreeItem *> m_children;
// m_data contains: [0] property name, [1] value, [2] unit
QList<QVariant> m_data;
QString m_description;
@ -234,11 +241,6 @@ private:
bool m_changed;
QTime m_highlightExpires;
HighLightManager *m_highlightManager;
static int m_highlightTimeMs;
bool m_known;
public:
static const int dataColumn = 1;
};
class DataObjectTreeItem;
@ -280,19 +282,25 @@ private:
class ObjectTreeItem : public TreeItem {
Q_OBJECT
public:
ObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(0) {}
ObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(0) {}
void setObject(UAVObject *obj)
ObjectTreeItem(const QList<QVariant> &data, UAVObject *object, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(object)
{
m_obj = obj;
setDescription(obj->getDescription());
setDescription(m_obj->getDescription());
}
ObjectTreeItem(const QVariant &data, UAVObject *object, TreeItem *parent = 0) :
TreeItem(data, parent), m_obj(object)
{
setDescription(m_obj->getDescription());
}
inline UAVObject *object()
{
return m_obj;
}
bool isKnown()
{
return !m_obj->isSettingsObject() || m_obj->isKnown();
}
private:
UAVObject *m_obj;
};
@ -300,25 +308,21 @@ private:
class MetaObjectTreeItem : public ObjectTreeItem {
Q_OBJECT
public:
MetaObjectTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent)
{
setObject(obj);
}
MetaObjectTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent)
{
setObject(obj);
}
MetaObjectTreeItem(UAVObject *object, const QList<QVariant> &data, TreeItem *parent = 0) :
ObjectTreeItem(data, object, parent)
{}
MetaObjectTreeItem(UAVObject *object, const QVariant &data, TreeItem *parent = 0) :
ObjectTreeItem(data, object, parent)
{}
};
class DataObjectTreeItem : public ObjectTreeItem {
Q_OBJECT
public:
DataObjectTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) {}
DataObjectTreeItem(const QVariant &data, TreeItem *parent = 0) :
ObjectTreeItem(data, parent) {}
DataObjectTreeItem(const QList<QVariant> &data, UAVObject *object, TreeItem *parent = 0) :
ObjectTreeItem(data, object, parent) {}
DataObjectTreeItem(const QVariant &data, UAVObject *object, TreeItem *parent = 0) :
ObjectTreeItem(data, object, parent) {}
virtual void apply()
{
foreach(TreeItem * child, treeChildren()) {
@ -344,16 +348,12 @@ public:
class InstanceTreeItem : public DataObjectTreeItem {
Q_OBJECT
public:
InstanceTreeItem(UAVObject *obj, const QList<QVariant> &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, parent)
{
setObject(obj);
}
InstanceTreeItem(UAVObject *obj, const QVariant &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, parent)
{
setObject(obj);
}
InstanceTreeItem(UAVObject *object, const QList<QVariant> &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, object, parent)
{}
InstanceTreeItem(UAVObject *object, const QVariant &data, TreeItem *parent = 0) :
DataObjectTreeItem(data, object, parent)
{}
virtual void apply()
{
TreeItem::apply();
@ -372,6 +372,10 @@ public:
ArrayFieldTreeItem(UAVObjectField *field, const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent), m_field(field)
{}
QVariant data(int column) const;
bool isKnown()
{
return !m_field->getObject()->isSettingsObject() || m_field->getObject()->isKnown();
}
private:
UAVObjectField *m_field;

View File

@ -1,5 +1,4 @@
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavtalk/uavtalk.pri)
include(../../libs/utils/utils.pri)
include(../../libs/qscispinbox/qscispinbox.pri)

View File

@ -42,9 +42,9 @@ UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize, bool us
m_useScientificFloatNotation(useScientificNotation),
m_categorize(categorize),
m_recentlyUpdatedTimeout(500), // ms
m_unknownObjectColor(QColor(Qt::gray)),
m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255))
m_manuallyChangedColor(QColor(230, 230, 255)),
m_unknownObjectColor(QColor(Qt::gray))
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
@ -57,12 +57,6 @@ UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize, bool us
connect(objManager, SIGNAL(newInstance(UAVObject *)), this, SLOT(newObject(UAVObject *)));
TreeItem::setHighlightTime(m_recentlyUpdatedTimeout);
TelemetryManager *telManager = pm->getObject<TelemetryManager>();
Q_ASSERT(telManager);
m_telemetryManager = telManager;
connect(m_telemetryManager, SIGNAL(knownObjectsChanged(UAVObject *, bool)), this, SLOT(knownObjectsChanged(UAVObject *, bool)));
setupModelData(objManager);
}
@ -121,17 +115,16 @@ void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
if (existing) {
addInstance(obj, existing);
} else {
DataObjectTreeItem *dataTreeItem = new DataObjectTreeItem(obj->getName());
DataObjectTreeItem *dataTreeItem = new DataObjectTreeItem(obj->getName(), obj);
dataTreeItem->setHighlightManager(m_highlightManager);
connect(dataTreeItem, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *)));
connect(dataTreeItem, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
parent->insertChild(dataTreeItem);
root->addObjectTreeItem(obj->getObjID(), dataTreeItem);
UAVMetaObject *meta = obj->getMetaObject();
MetaObjectTreeItem *metaTreeItem = addMetaObject(meta, dataTreeItem);
metaTreeItem->setKnown(root == m_nonSettingsTree || m_telemetryManager->isObjectKnown(obj));
root->addMetaObjectTreeItem(meta->getObjID(), metaTreeItem);
addInstance(obj, dataTreeItem);
dataTreeItem->setKnown(root == m_nonSettingsTree || m_telemetryManager->isObjectKnown(obj));
}
}
@ -176,16 +169,18 @@ MetaObjectTreeItem *UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeIt
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
{
connect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(highlightUpdatedObject(UAVObject *)));
connect(obj, SIGNAL(isKnownChanged(UAVObject *, bool)), this, SLOT(isKnownChanged(UAVObject *, bool)));
TreeItem *item;
if (obj->isSingleInstance()) {
item = parent;
DataObjectTreeItem *p = static_cast<DataObjectTreeItem *>(parent);
p->setObject(obj);
DataObjectTreeItem *objectItem = static_cast<DataObjectTreeItem *>(parent);
connect(objectItem, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
} else {
QString name = tr("Instance") + " " + QString::number(obj->getInstID());
item = new InstanceTreeItem(obj, name);
item->setHighlightManager(m_highlightManager);
connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *)));
connect(item, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
parent->appendChild(item);
}
foreach(UAVObjectField * field, obj->getFields()) {
@ -203,6 +198,7 @@ void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
item->setHighlightManager(m_highlightManager);
connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *)));
connect(item, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
for (uint i = 0; i < field->getNumElements(); ++i) {
addSingleField(i, field, item);
}
@ -258,6 +254,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
item->setHighlightManager(m_highlightManager);
item->setDescription(field->getDescription());
connect(item, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *)));
connect(item, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
parent->appendChild(item);
}
@ -366,7 +363,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
if (index.column() == TreeItem::DATA_COLUMN && role == Qt::EditRole) {
return item->data(index.column());
}
@ -386,7 +383,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
}
}
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
if (index.column() == TreeItem::DATA_COLUMN && role == Qt::BackgroundRole) {
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem *>(item);
if (fieldItem && fieldItem->highlighted()) {
return QVariant(m_recentlyUpdatedColor);
@ -401,7 +398,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}
if (index.column() == TreeItem::dataColumn) {
if (index.column() == TreeItem::DATA_COLUMN) {
EnumFieldTreeItem *fieldItem = dynamic_cast<EnumFieldTreeItem *>(item);
if (fieldItem) {
int enumIndex = fieldItem->data(index.column()).toInt();
@ -427,7 +424,7 @@ Qt::ItemFlags UAVObjectTreeModel::flags(const QModelIndex &index) const
return 0;
}
if (index.column() == TreeItem::dataColumn) {
if (index.column() == TreeItem::DATA_COLUMN) {
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
if (item->isEditable()) {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
@ -498,20 +495,22 @@ void UAVObjectTreeModel::updateHighlight(TreeItem *item)
QModelIndex itemIndex = index(item);
Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::DATA_COLUMN));
}
void UAVObjectTreeModel::knownObjectsChanged(UAVObject *object, bool known)
void UAVObjectTreeModel::updateIsKnown(TreeItem *item)
{
if (object->isSettingsObject()) {
TreeItem *item;
if (object->isMetaDataObject()) {
item = m_settingsTree->findMetaObjectTreeItemByObjectId(object->getObjID());
} else {
item = m_settingsTree->findDataObjectTreeItemByObjectId(object->getObjID());
QModelIndex itemIndex = index(item);
Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::TITLE_COLUMN));
}
void UAVObjectTreeModel::isKnownChanged(UAVObject *object, bool isKnown)
{
Q_UNUSED(isKnown);
ObjectTreeItem *item = findObjectTreeItem(object);
if (item) {
item->setKnown(known);
}
item->updateIsKnown(isKnown);
}
}

View File

@ -29,7 +29,6 @@
#define UAVOBJECTTREEMODEL_H
#include "treeitem.h"
#include "uavtalk/telemetrymanager.h"
#include <QAbstractItemModel>
#include <QtCore/QMap>
#include <QtCore/QList>
@ -93,9 +92,10 @@ public slots:
void newObject(UAVObject *obj);
private slots:
void updateHighlight(TreeItem *item);
void updateIsKnown(TreeItem *item);
void highlightUpdatedObject(UAVObject *obj);
void updateHighlight(TreeItem *);
void knownObjectsChanged(UAVObject *object, bool known);
void isKnownChanged(UAVObject *object, bool isKnown);
private:
void setupModelData(UAVObjectManager *objManager);
@ -126,7 +126,6 @@ private:
// Highlight manager to handle highlighting of tree items.
HighLightManager *m_highlightManager;
TelemetryManager *m_telemetryManager;
};
#endif // UAVOBJECTTREEMODEL_H