mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Merge branch 'next' of ssh://git.openpilot.org/OpenPilot into next
This commit is contained in:
commit
58a9e9a6f7
@ -129,21 +129,23 @@ void TreeItem::appendChild(TreeItem *child)
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
void TreeItem::insert(int index, TreeItem *child)
|
||||
void TreeItem::insertChild(TreeItem *child)
|
||||
{
|
||||
int index = nameIndex(child->data(0).toString());
|
||||
m_children.insert(index, child);
|
||||
child->setParentTree(this);
|
||||
}
|
||||
|
||||
TreeItem *TreeItem::child(int row)
|
||||
TreeItem *TreeItem::getChild(int index)
|
||||
{
|
||||
return m_children.value(row);
|
||||
return m_children.value(index);
|
||||
}
|
||||
|
||||
int TreeItem::childCount() const
|
||||
{
|
||||
return m_children.count();
|
||||
}
|
||||
|
||||
int TreeItem::row() const
|
||||
{
|
||||
if (m_parent)
|
||||
@ -224,3 +226,8 @@ QTime TreeItem::getHiglightExpires()
|
||||
{
|
||||
return m_highlightExpires;
|
||||
}
|
||||
|
||||
QList<MetaObjectTreeItem *> TopTreeItem::getMetaObjectItems()
|
||||
{
|
||||
return m_metaObjectTreeItemsPerObjectIds.values();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QLinkedList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QTimer>
|
||||
@ -94,9 +95,9 @@ public:
|
||||
virtual ~TreeItem();
|
||||
|
||||
void appendChild(TreeItem *child);
|
||||
void insert(int index, TreeItem *child);
|
||||
void insertChild(TreeItem *child);
|
||||
|
||||
TreeItem *child(int row);
|
||||
TreeItem *getChild(int index);
|
||||
inline QList<TreeItem*> treeChildren() const { return m_children; }
|
||||
int childCount() const;
|
||||
int columnCount() const;
|
||||
@ -131,6 +132,24 @@ public:
|
||||
|
||||
virtual void removeHighlight();
|
||||
|
||||
int nameIndex(QString name) {
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
if (name < getChild(i)->data(0).toString())
|
||||
return i;
|
||||
}
|
||||
return childCount();
|
||||
}
|
||||
|
||||
TreeItem* findChildByName(QString name)
|
||||
{
|
||||
foreach (TreeItem* child, m_children) {
|
||||
if (name == child->data(0).toString()) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
signals:
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
@ -152,6 +171,9 @@ private:
|
||||
static int m_highlightTimeMs;
|
||||
};
|
||||
|
||||
class DataObjectTreeItem;
|
||||
class MetaObjectTreeItem;
|
||||
|
||||
class TopTreeItem : public TreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -159,19 +181,27 @@ public:
|
||||
TopTreeItem(const QList<QVariant> &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
TopTreeItem(const QVariant &data, TreeItem *parent = 0) : TreeItem(data, parent) { }
|
||||
|
||||
QList<quint32> objIds() { return m_objIds; }
|
||||
void addObjId(quint32 objId) { m_objIds.append(objId); }
|
||||
void insertObjId(int index, quint32 objId) { m_objIds.insert(index, objId); }
|
||||
int nameIndex(QString name) {
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
if (name < child(i)->data(0).toString())
|
||||
return i;
|
||||
}
|
||||
return childCount();
|
||||
void addObjectTreeItem(quint32 objectId, DataObjectTreeItem* oti) {
|
||||
m_objectTreeItemsPerObjectIds[objectId] = oti;
|
||||
}
|
||||
|
||||
DataObjectTreeItem* findDataObjectTreeItemByObjectId(quint32 objectId) {
|
||||
return m_objectTreeItemsPerObjectIds.contains(objectId) ? m_objectTreeItemsPerObjectIds[objectId] : 0;
|
||||
}
|
||||
|
||||
void addMetaObjectTreeItem(quint32 objectId, MetaObjectTreeItem* oti) {
|
||||
m_metaObjectTreeItemsPerObjectIds[objectId] = oti;
|
||||
}
|
||||
|
||||
MetaObjectTreeItem* findMetaObjectTreeItemByObjectId(quint32 objectId) {
|
||||
return m_metaObjectTreeItemsPerObjectIds.contains(objectId) ? m_metaObjectTreeItemsPerObjectIds[objectId] : 0;
|
||||
}
|
||||
|
||||
QList<MetaObjectTreeItem*> getMetaObjectItems();
|
||||
|
||||
private:
|
||||
QList<quint32> m_objIds;
|
||||
QMap<quint32, DataObjectTreeItem*> m_objectTreeItemsPerObjectIds;
|
||||
QMap<quint32, MetaObjectTreeItem*> m_metaObjectTreeItemsPerObjectIds;
|
||||
};
|
||||
|
||||
class ObjectTreeItem : public TreeItem
|
||||
|
@ -45,5 +45,6 @@ void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
|
||||
m_widget->setManuallyChangedColor(m->manuallyChangedColor());
|
||||
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());
|
||||
m_widget->setOnlyHilightChangedValues(m->onlyHighlightChangedValues());
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="categorizeCheckbox">
|
||||
<property name="toolTip">
|
||||
<string>Select to sort objects in to categories.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Categorize Objects</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
|
@ -31,17 +31,20 @@ UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, QS
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
m_manuallyChangedColor(QColor(230, 230, 255)),
|
||||
m_recentlyUpdatedTimeout(500)
|
||||
m_recentlyUpdatedTimeout(500),
|
||||
m_onlyHilightChangedValues(false)
|
||||
{
|
||||
//if a saved configuration exists load it
|
||||
if(qSettings != 0) {
|
||||
QColor recent = qSettings->value("recentlyUpdatedColor").value<QColor>();
|
||||
QColor manual = qSettings->value("manuallyChangedColor").value<QColor>();
|
||||
int timeout = qSettings->value("recentlyUpdatedTimeout").toInt();
|
||||
bool hilight = qSettings->value("onlyHilightChangedValues").toBool();
|
||||
|
||||
m_recentlyUpdatedColor = recent;
|
||||
m_manuallyChangedColor = manual;
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
m_onlyHilightChangedValues = hilight;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +54,7 @@ IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
|
||||
m->m_recentlyUpdatedColor = m_recentlyUpdatedColor;
|
||||
m->m_manuallyChangedColor = m_manuallyChangedColor;
|
||||
m->m_recentlyUpdatedTimeout = m_recentlyUpdatedTimeout;
|
||||
m->m_onlyHilightChangedValues = m_onlyHilightChangedValues;
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -62,4 +66,5 @@ void UAVObjectBrowserConfiguration::saveConfig(QSettings* qSettings) const {
|
||||
qSettings->setValue("recentlyUpdatedColor", m_recentlyUpdatedColor);
|
||||
qSettings->setValue("manuallyChangedColor", m_manuallyChangedColor);
|
||||
qSettings->setValue("recentlyUpdatedTimeout", m_recentlyUpdatedTimeout);
|
||||
qSettings->setValue("onlyHilightChangedValues", m_onlyHilightChangedValues);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ Q_OBJECT
|
||||
Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
|
||||
Q_PROPERTY(QColor m_manuallyChangedColor READ manuallyChangedColor WRITE setManuallyChangedColor)
|
||||
Q_PROPERTY(int m_recentlyUpdatedTimeout READ recentlyUpdatedTimeout WRITE setRecentlyUpdatedTimeout)
|
||||
Q_PROPERTY(bool m_onlyHilightChangedValues READ onlyHighlightChangedValues WRITE setOnlyHighlightChangedValues)
|
||||
public:
|
||||
explicit UAVObjectBrowserConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
|
||||
|
||||
@ -48,6 +49,7 @@ public:
|
||||
QColor recentlyUpdatedColor() const { return m_recentlyUpdatedColor; }
|
||||
QColor manuallyChangedColor() const { return m_manuallyChangedColor; }
|
||||
int recentlyUpdatedTimeout() const { return m_recentlyUpdatedTimeout; }
|
||||
bool onlyHighlightChangedValues() const {return m_onlyHilightChangedValues;}
|
||||
|
||||
signals:
|
||||
|
||||
@ -55,11 +57,13 @@ public slots:
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; }
|
||||
void setOnlyHighlightChangedValues(bool hilight) { m_onlyHilightChangedValues = hilight; }
|
||||
|
||||
private:
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
int m_recentlyUpdatedTimeout;
|
||||
bool m_onlyHilightChangedValues;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTBROWSERCONFIGURATION_H
|
||||
|
@ -52,6 +52,7 @@ QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
|
||||
m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor());
|
||||
m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor());
|
||||
m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout());
|
||||
m_page->hilightBox->setChecked(m_config->onlyHighlightChangedValues());
|
||||
|
||||
return w;
|
||||
|
||||
@ -62,6 +63,7 @@ void UAVObjectBrowserOptionsPage::apply()
|
||||
m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color());
|
||||
m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color());
|
||||
m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value());
|
||||
m_config->setOnlyHighlightChangedValues(m_page->hilightBox->isChecked());
|
||||
}
|
||||
|
||||
void UAVObjectBrowserOptionsPage::finish()
|
||||
|
@ -48,7 +48,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<item row="5" column="3">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -115,6 +115,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="hilightBox">
|
||||
<property name="text">
|
||||
<string>Only hilight nodes when value actually changes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -54,6 +54,7 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
|
||||
showMetaData(m_browser->metaCheckBox->isChecked());
|
||||
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
|
||||
connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
|
||||
connect(m_browser->categorizeCheckbox, SIGNAL(toggled(bool)), this, SLOT(categorize(bool)));
|
||||
connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveObject()));
|
||||
connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(loadObject()));
|
||||
connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject()));
|
||||
@ -69,16 +70,32 @@ UAVObjectBrowserWidget::~UAVObjectBrowserWidget()
|
||||
|
||||
void UAVObjectBrowserWidget::showMetaData(bool show)
|
||||
{
|
||||
int topRowCount = m_model->rowCount(QModelIndex());
|
||||
for (int i = 0; i < topRowCount; ++i) {
|
||||
QModelIndex index = m_model->index(i, 0, QModelIndex());
|
||||
int subRowCount = m_model->rowCount(index);
|
||||
for (int j = 0; j < subRowCount; ++j) {
|
||||
m_browser->treeView->setRowHidden(0, index.child(j,0), !show);
|
||||
}
|
||||
QList<QModelIndex> metaIndexes = m_model->getMetaDataIndexes();
|
||||
foreach(QModelIndex index , metaIndexes)
|
||||
{
|
||||
m_browser->treeView->setRowHidden(index.row(), index.parent(), !show);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::categorize(bool categorize)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
Q_ASSERT(pm);
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(objManager);
|
||||
|
||||
UAVObjectTreeModel* tmpModel = m_model;
|
||||
m_model = new UAVObjectTreeModel(0, categorize);
|
||||
m_model->setRecentlyUpdatedColor(m_recentlyUpdatedColor);
|
||||
m_model->setManuallyChangedColor(m_manuallyChangedColor);
|
||||
m_model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
|
||||
m_model->setOnlyHilightChangedValues(m_onlyHilightChangedValues);
|
||||
m_browser->treeView->setModel(m_model);
|
||||
showMetaData(m_browser->metaCheckBox->isChecked());
|
||||
|
||||
delete tmpModel;
|
||||
}
|
||||
|
||||
void UAVObjectBrowserWidget::sendUpdate()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
|
@ -45,12 +45,15 @@ class UAVObjectBrowserWidget : public QWidget
|
||||
public:
|
||||
UAVObjectBrowserWidget(QWidget *parent = 0);
|
||||
~UAVObjectBrowserWidget();
|
||||
void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); }
|
||||
void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); }
|
||||
void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; m_model->setRecentlyUpdatedColor(color); }
|
||||
void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; m_model->setManuallyChangedColor(color); }
|
||||
void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; m_model->setRecentlyUpdatedTimeout(timeout); }
|
||||
void setOnlyHilightChangedValues(bool hilight) { m_onlyHilightChangedValues = hilight; m_model->setOnlyHilightChangedValues(hilight); }
|
||||
|
||||
|
||||
public slots:
|
||||
void showMetaData(bool show);
|
||||
void categorize(bool categorize);
|
||||
|
||||
private slots:
|
||||
void sendUpdate();
|
||||
@ -66,6 +69,11 @@ private:
|
||||
Ui_UAVObjectBrowser *m_browser;
|
||||
UAVObjectTreeModel *m_model;
|
||||
|
||||
int m_recentlyUpdatedTimeout;
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
bool m_onlyHilightChangedValues;
|
||||
|
||||
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
|
||||
void enableSendRequest(bool enable);
|
||||
ObjectTreeItem *findCurrentObjectTreeItem();
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize) :
|
||||
QAbstractItemModel(parent),
|
||||
m_recentlyUpdatedTimeout(500), // ms
|
||||
m_recentlyUpdatedColor(QColor(255, 230, 230)),
|
||||
@ -53,7 +53,7 @@ UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
connect(objManager, SIGNAL(newInstance(UAVObject*)), this, SLOT(newObject(UAVObject*)));
|
||||
|
||||
TreeItem::setHighlightTime(m_recentlyUpdatedTimeout);
|
||||
setupModelData(objManager);
|
||||
setupModelData(objManager, categorize);
|
||||
}
|
||||
|
||||
UAVObjectTreeModel::~UAVObjectTreeModel()
|
||||
@ -62,7 +62,7 @@ UAVObjectTreeModel::~UAVObjectTreeModel()
|
||||
delete m_rootItem;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager, bool categorize)
|
||||
{
|
||||
// root
|
||||
QList<QVariant> rootData;
|
||||
@ -82,7 +82,7 @@ void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
addDataObject(obj);
|
||||
addDataObject(obj, categorize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,33 +90,62 @@ void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager)
|
||||
void UAVObjectTreeModel::newObject(UAVObject *obj)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(obj);
|
||||
if (dobj)
|
||||
if (dobj) {
|
||||
addDataObject(dobj);
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
|
||||
{
|
||||
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
if (root->objIds().contains(obj->getObjID())) {
|
||||
int index = root->objIds().indexOf(obj->getObjID());
|
||||
addInstance(obj, root->child(index));
|
||||
} else {
|
||||
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName() + " (" + QString::number(obj->getNumBytes()) + " bytes)");
|
||||
data->setHighlightManager(m_highlightManager);
|
||||
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
int index = root->nameIndex(obj->getName());
|
||||
root->insert(index, data);
|
||||
root->insertObjId(index, obj->getObjID());
|
||||
UAVMetaObject *meta = obj->getMetaObject();
|
||||
addMetaObject(meta, data);
|
||||
addInstance(obj, data);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
void UAVObjectTreeModel::addDataObject(UAVDataObject *obj, bool categorize)
|
||||
{
|
||||
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
|
||||
TreeItem* parent = root;
|
||||
|
||||
if(categorize && obj->getCategory() != 0 && !obj->getCategory().isEmpty()) {
|
||||
QStringList categoryPath = obj->getCategory().split('/');
|
||||
parent = createCategoryItems(categoryPath, root);
|
||||
}
|
||||
|
||||
ObjectTreeItem* existing = root->findDataObjectTreeItemByObjectId(obj->getObjID());
|
||||
if (existing) {
|
||||
addInstance(obj, existing);
|
||||
} else {
|
||||
DataObjectTreeItem *dataTreeItem = new DataObjectTreeItem(obj->getName() + " (" + QString::number(obj->getNumBytes()) + " bytes)");
|
||||
dataTreeItem->setHighlightManager(m_highlightManager);
|
||||
connect(dataTreeItem, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
parent->insertChild(dataTreeItem);
|
||||
root->addObjectTreeItem(obj->getObjID(), dataTreeItem);
|
||||
UAVMetaObject *meta = obj->getMetaObject();
|
||||
MetaObjectTreeItem* metaTreeItem = addMetaObject(meta, dataTreeItem);
|
||||
root->addMetaObjectTreeItem(meta->getObjID(), metaTreeItem);
|
||||
addInstance(obj, dataTreeItem);
|
||||
}
|
||||
}
|
||||
|
||||
TreeItem* UAVObjectTreeModel::createCategoryItems(QStringList categoryPath, TreeItem* root)
|
||||
{
|
||||
TreeItem* parent = root;
|
||||
foreach(QString category, categoryPath) {
|
||||
TreeItem* existing = parent->findChildByName(category);
|
||||
if(!existing) {
|
||||
TreeItem* categoryItem = new TreeItem(category);
|
||||
connect(categoryItem, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
categoryItem->setHighlightManager(m_highlightManager);
|
||||
parent->insertChild(categoryItem);
|
||||
parent = categoryItem;
|
||||
}
|
||||
else {
|
||||
parent = existing;
|
||||
}
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
MetaObjectTreeItem* UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
{
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(highlightUpdatedObject(UAVObject*)));
|
||||
MetaObjectTreeItem *meta = new MetaObjectTreeItem(obj, tr("Meta Data"));
|
||||
|
||||
meta->setHighlightManager(m_highlightManager);
|
||||
connect(meta, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
|
||||
foreach (UAVObjectField *field, obj->getFields()) {
|
||||
@ -127,6 +156,7 @@ void UAVObjectTreeModel::addMetaObject(UAVMetaObject *obj, TreeItem *parent)
|
||||
}
|
||||
}
|
||||
parent->appendChild(meta);
|
||||
return meta;
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
@ -153,7 +183,6 @@ void UAVObjectTreeModel::addInstance(UAVObject *obj, TreeItem *parent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UAVObjectTreeModel::addArrayField(UAVObjectField *field, TreeItem *parent)
|
||||
{
|
||||
TreeItem *item = new ArrayFieldTreeItem(field->getName());
|
||||
@ -221,7 +250,7 @@ QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &pa
|
||||
else
|
||||
parentItem = static_cast<TreeItem*>(parent.internalPointer());
|
||||
|
||||
TreeItem *childItem = parentItem->child(row);
|
||||
TreeItem *childItem = parentItem->getChild(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
@ -281,6 +310,21 @@ int UAVObjectTreeModel::columnCount(const QModelIndex &parent) const
|
||||
return m_rootItem->columnCount();
|
||||
}
|
||||
|
||||
QList<QModelIndex> UAVObjectTreeModel::getMetaDataIndexes()
|
||||
{
|
||||
QList<QModelIndex> metaIndexes;
|
||||
foreach(MetaObjectTreeItem *metaItem , m_settingsTree->getMetaObjectItems())
|
||||
{
|
||||
metaIndexes.append(index(metaItem));
|
||||
}
|
||||
|
||||
foreach(MetaObjectTreeItem *metaItem , m_nonSettingsTree->getMetaObjectItems())
|
||||
{
|
||||
metaIndexes.append(index(metaItem));
|
||||
}
|
||||
return metaIndexes;
|
||||
}
|
||||
|
||||
QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@ -290,6 +334,7 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
return item->data(index.column());
|
||||
}
|
||||
|
||||
// if (role == Qt::DecorationRole)
|
||||
// return QIcon(":/core/images/openpilot_logo_128.png");
|
||||
|
||||
@ -301,14 +346,15 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
|
||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||
|
||||
if (index.column() == 0 && role == Qt::BackgroundRole) {
|
||||
ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem*>(item);
|
||||
if (objItem && objItem->highlighted())
|
||||
if (!dynamic_cast<TopTreeItem*>(item) && item->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
}
|
||||
|
||||
if (index.column() == TreeItem::dataColumn && role == Qt::BackgroundRole) {
|
||||
FieldTreeItem *fieldItem = dynamic_cast<FieldTreeItem*>(item);
|
||||
if (fieldItem && fieldItem->highlighted())
|
||||
return QVariant(m_recentlyUpdatedColor);
|
||||
|
||||
if (fieldItem && fieldItem->changed())
|
||||
return QVariant(m_manuallyChangedColor);
|
||||
}
|
||||
@ -364,58 +410,42 @@ void UAVObjectTreeModel::highlightUpdatedObject(UAVObject *obj)
|
||||
Q_ASSERT(obj);
|
||||
ObjectTreeItem *item = findObjectTreeItem(obj);
|
||||
Q_ASSERT(item);
|
||||
if(!m_onlyHilightChangedValues){
|
||||
item->setHighlight(true);
|
||||
}
|
||||
item->update();
|
||||
if(!m_onlyHilightChangedValues){
|
||||
QModelIndex itemIndex = index(item);
|
||||
Q_ASSERT(itemIndex != QModelIndex());
|
||||
emit dataChanged(itemIndex, itemIndex);
|
||||
}
|
||||
}
|
||||
|
||||
ObjectTreeItem *UAVObjectTreeModel::findObjectTreeItem(UAVObject *object)
|
||||
{
|
||||
UAVDataObject *dobj = qobject_cast<UAVDataObject*>(object);
|
||||
UAVMetaObject *mobj = qobject_cast<UAVMetaObject*>(object);
|
||||
Q_ASSERT(dobj || mobj);
|
||||
if (dobj) {
|
||||
return findDataObjectTreeItem(dobj);
|
||||
UAVDataObject *dataObject = qobject_cast<UAVDataObject*>(object);
|
||||
UAVMetaObject *metaObject = qobject_cast<UAVMetaObject*>(object);
|
||||
Q_ASSERT(dataObject || metaObject);
|
||||
if (dataObject) {
|
||||
return findDataObjectTreeItem(dataObject);
|
||||
} else {
|
||||
dobj = qobject_cast<UAVDataObject*>(mobj->getParentObject());
|
||||
Q_ASSERT(dobj);
|
||||
ObjectTreeItem *dItem = findDataObjectTreeItem(dobj);
|
||||
Q_ASSERT(dItem);
|
||||
Q_ASSERT(dItem->object());
|
||||
if (!dItem->object()->isSingleInstance())
|
||||
dItem = dynamic_cast<ObjectTreeItem*>(dItem->parent());
|
||||
foreach (TreeItem *child, dItem->treeChildren()) {
|
||||
MetaObjectTreeItem *mItem = dynamic_cast<MetaObjectTreeItem*>(child);
|
||||
if (mItem && mItem->object()) {
|
||||
Q_ASSERT(mItem->object() == mobj);
|
||||
return mItem;
|
||||
return findMetaObjectTreeItem(metaObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DataObjectTreeItem *UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *object)
|
||||
DataObjectTreeItem* UAVObjectTreeModel::findDataObjectTreeItem(UAVDataObject *obj)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
TopTreeItem *root = object->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
foreach (TreeItem *child, root->treeChildren()) {
|
||||
DataObjectTreeItem *dItem = dynamic_cast<DataObjectTreeItem*>(child);
|
||||
if (dItem && dItem->object() && dItem->object()->isSingleInstance()) {
|
||||
if(dItem->object() == object) {
|
||||
return dItem;
|
||||
}
|
||||
} else {
|
||||
foreach (TreeItem *c, dItem->treeChildren()) {
|
||||
DataObjectTreeItem *d = dynamic_cast<DataObjectTreeItem*>(c);
|
||||
if (d && d->object() == object)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
TopTreeItem *root = obj->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
return root->findDataObjectTreeItemByObjectId(obj->getObjID());
|
||||
}
|
||||
|
||||
MetaObjectTreeItem* UAVObjectTreeModel::findMetaObjectTreeItem(UAVMetaObject *obj)
|
||||
{
|
||||
UAVDataObject *dataObject = qobject_cast<UAVDataObject*>(obj->getParentObject());
|
||||
Q_ASSERT(dataObject);
|
||||
TopTreeItem *root = dataObject->isSettings() ? m_settingsTree : m_nonSettingsTree;
|
||||
return root->findMetaObjectTreeItemByObjectId(obj->getObjID());
|
||||
}
|
||||
|
||||
void UAVObjectTreeModel::updateHighlight(TreeItem *item)
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "treeitem.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
class TopTreeItem;
|
||||
@ -48,7 +49,7 @@ class UAVObjectTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVObjectTreeModel(QObject *parent = 0);
|
||||
explicit UAVObjectTreeModel(QObject *parent = 0, bool categorize=true);
|
||||
~UAVObjectTreeModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
@ -68,6 +69,9 @@ public:
|
||||
m_recentlyUpdatedTimeout = timeout;
|
||||
TreeItem::setHighlightTime(timeout);
|
||||
}
|
||||
void setOnlyHilightChangedValues(bool hilight) {m_onlyHilightChangedValues = hilight; }
|
||||
|
||||
QList<QModelIndex> getMetaDataIndexes();
|
||||
|
||||
signals:
|
||||
|
||||
@ -79,17 +83,20 @@ private slots:
|
||||
void updateHighlight(TreeItem*);
|
||||
|
||||
private:
|
||||
void setupModelData(UAVObjectManager *objManager, bool categorize = true);
|
||||
QModelIndex index(TreeItem *item);
|
||||
void addDataObject(UAVDataObject *obj);
|
||||
void addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
||||
void addDataObject(UAVDataObject *obj, bool categorize = true);
|
||||
MetaObjectTreeItem *addMetaObject(UAVMetaObject *obj, TreeItem *parent);
|
||||
void addArrayField(UAVObjectField *field, TreeItem *parent);
|
||||
|
||||
void addSingleField(int index, UAVObjectField *field, TreeItem *parent);
|
||||
void addInstance(UAVObject *obj, TreeItem *parent);
|
||||
|
||||
TreeItem *createCategoryItems(QStringList categoryPath, TreeItem *root);
|
||||
|
||||
QString updateMode(quint8 updateMode);
|
||||
void setupModelData(UAVObjectManager *objManager);
|
||||
ObjectTreeItem *findObjectTreeItem(UAVObject *obj);
|
||||
DataObjectTreeItem *findDataObjectTreeItem(UAVDataObject *obj);
|
||||
MetaObjectTreeItem *findMetaObjectTreeItem(UAVMetaObject *obj);
|
||||
|
||||
TreeItem *m_rootItem;
|
||||
TopTreeItem *m_settingsTree;
|
||||
@ -97,6 +104,7 @@ private:
|
||||
int m_recentlyUpdatedTimeout;
|
||||
QColor m_recentlyUpdatedColor;
|
||||
QColor m_manuallyChangedColor;
|
||||
bool m_onlyHilightChangedValues;
|
||||
|
||||
// Highlight manager to handle highlighting of tree items.
|
||||
HighLightManager *m_highlightManager;
|
||||
|
@ -31,7 +31,7 @@
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent):
|
||||
UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject *parent):
|
||||
UAVObject(objID, true, name)
|
||||
{
|
||||
this->parent = parent;
|
||||
|
@ -145,6 +145,22 @@ void UAVObject::setDescription(const QString& description)
|
||||
this->description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category of the object
|
||||
*/
|
||||
QString UAVObject::getCategory()
|
||||
{
|
||||
return category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the category of the object
|
||||
*/
|
||||
void UAVObject::setCategory(const QString& category)
|
||||
{
|
||||
this->category = category;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the total number of bytes of the object's data
|
||||
|
@ -103,6 +103,7 @@ public:
|
||||
quint32 getInstID();
|
||||
bool isSingleInstance();
|
||||
QString getName();
|
||||
QString getCategory();
|
||||
QString getDescription();
|
||||
quint32 getNumBytes();
|
||||
qint32 pack(quint8* dataOut);
|
||||
@ -163,6 +164,7 @@ protected:
|
||||
bool isSingleInst;
|
||||
QString name;
|
||||
QString description;
|
||||
QString category;
|
||||
quint32 numBytes;
|
||||
QMutex* mutex;
|
||||
quint8* data;
|
||||
@ -170,6 +172,7 @@ protected:
|
||||
|
||||
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes);
|
||||
void setDescription(const QString& description);
|
||||
void setCategory(const QString& category);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECT_H
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
const QString $(NAME)::NAME = QString("$(NAME)");
|
||||
const QString $(NAME)::DESCRIPTION = QString("$(DESCRIPTION)");
|
||||
const QString $(NAME)::CATEGORY = QString("$(CATEGORY)");
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -51,6 +52,9 @@ $(FIELDSINIT)
|
||||
// Set the object description
|
||||
setDescription(DESCRIPTION);
|
||||
|
||||
// Set the Category of this object type
|
||||
setCategory(CATEGORY);
|
||||
|
||||
connect(this, SIGNAL(objectUpdated(UAVObject*)),
|
||||
SLOT(emitNotifications()));
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ $(DATAFIELDINFO)
|
||||
static const quint32 OBJID = $(OBJIDHEX);
|
||||
static const QString NAME;
|
||||
static const QString DESCRIPTION;
|
||||
static const QString CATEGORY;
|
||||
static const bool ISSINGLEINST = $(ISSINGLEINST);
|
||||
static const bool ISSETTINGS = $(ISSETTINGS);
|
||||
static const quint32 NUMBYTES = sizeof(DataFields);
|
||||
|
@ -56,6 +56,8 @@ void replaceCommonTags(QString& out, ObjectInfo* info)
|
||||
out.replace(QString("$(NAMELC)"), info->namelc);
|
||||
// Replace $(DESCRIPTION) tag
|
||||
out.replace(QString("$(DESCRIPTION)"), info->description);
|
||||
// Replace $(CATEGORY) tag
|
||||
out.replace(QString("$(CATEGORY)"), info->category);
|
||||
// Replace $(NAMEUC) tag
|
||||
out.replace(QString("$(NAMEUC)"), info->name.toUpper());
|
||||
// Replace $(OBJID) tag
|
||||
|
@ -499,6 +499,13 @@ QString UAVObjectParser::processObjectAttributes(QDomNode& node, ObjectInfo* inf
|
||||
info->name = attr.nodeValue();
|
||||
info->namelc = attr.nodeValue().toLower();
|
||||
|
||||
// Get category attribute if present
|
||||
attr = attributes.namedItem("category");
|
||||
if ( !attr.isNull() )
|
||||
{
|
||||
info->category = attr.nodeValue();
|
||||
}
|
||||
|
||||
// Get singleinstance attribute
|
||||
attr = attributes.namedItem("singleinstance");
|
||||
if ( attr.isNull() )
|
||||
|
@ -96,6 +96,7 @@ typedef struct {
|
||||
int loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */
|
||||
QList<FieldInfo*> fields; /** The data fields for the object **/
|
||||
QString description; /** Description used for Doxygen **/
|
||||
QString category; /** Description used for Doxygen **/
|
||||
} ObjectInfo;
|
||||
|
||||
class UAVObjectParser
|
||||
@ -127,6 +128,7 @@ private:
|
||||
QString processObjectFields(QDomNode& childNode, ObjectInfo* info);
|
||||
QString processObjectAccess(QDomNode& childNode, ObjectInfo* info);
|
||||
QString processObjectDescription(QDomNode& childNode, QString * description);
|
||||
QString processObjectCategory(QDomNode& childNode, QString * category);
|
||||
QString processObjectMetadata(QDomNode& childNode, UpdateMode* mode, int* period, bool* acked);
|
||||
void calculateID(ObjectInfo* info);
|
||||
quint32 updateHash(quint32 value, quint32 hash);
|
||||
|
@ -1,5 +1,5 @@
|
||||
<xml>
|
||||
<object name="BaroAltitude" singleinstance="true" settings="false">
|
||||
<object name="BaroAltitude" singleinstance="true" settings="false" category="Sensors/Altitude">
|
||||
<description>The raw data from the barometric sensor with pressure, temperature and altitude estimate.</description>
|
||||
<field name="Altitude" units="m" type="float" elements="1"/>
|
||||
<field name="Temperature" units="C" type="float" elements="1"/>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<xml>
|
||||
<object name="Gyros" singleinstance="true" settings="false">
|
||||
<object name="Gyros" singleinstance="true" settings="false" category="Sensors">
|
||||
<description>The gyro data.</description>
|
||||
<field name="x" units="deg/s" type="float" elements="1"/>
|
||||
<field name="y" units="deg/s" type="float" elements="1"/>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<xml>
|
||||
<object name="Magnetometer" singleinstance="true" settings="false">
|
||||
<object name="Magnetometer" singleinstance="true" settings="false" category="Sensors">
|
||||
<description>The mag data.</description>
|
||||
<field name="x" units="mGa" type="float" elements="1"/>
|
||||
<field name="y" units="mGa" type="float" elements="1"/>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<xml>
|
||||
<object name="SonarAltitude" singleinstance="true" settings="false">
|
||||
<object name="SonarAltitude" singleinstance="true" settings="false" category="Sensors/Altitude">
|
||||
<description>The raw data from the ultrasound sonar sensor with altitude estimate.</description>
|
||||
<field name="Altitude" units="m" type="float" elements="1"/>
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user