1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

OP-706 Added support for visualizing unknown objects in UAVO browser.

Added settings for unknown object color to configuration and configuration GUI.
This commit is contained in:
m_thread 2014-10-15 23:32:42 +02:00
parent 666765f168
commit 33e9a6f956
12 changed files with 207 additions and 63 deletions

View File

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

View File

@ -206,6 +206,19 @@ public:
return 0;
}
void setKnown(bool known)
{
m_known = known;
foreach (TreeItem *child, m_children) {
child->setKnown(known);
}
updateHighlight(this);
}
inline bool isKnown()
{
return m_known;
}
signals:
void updateHighlight(TreeItem *);
@ -222,6 +235,8 @@ private:
QTime m_highlightExpires;
HighLightManager *m_highlightManager;
static int m_highlightTimeMs;
bool m_known;
public:
static const int dataColumn = 1;
};
@ -271,7 +286,8 @@ public:
TreeItem(data, parent), m_obj(0) {}
void setObject(UAVObject *obj)
{
m_obj = obj; setDescription(obj->getDescription());
m_obj = obj;
setDescription(obj->getDescription());
}
inline UAVObject *object()
{

View File

@ -45,6 +45,7 @@ void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration *config)
UAVObjectBrowserConfiguration *m = qobject_cast<UAVObjectBrowserConfiguration *>(config);
m_config = m;
m_widget->setUnknownObjectColor(m->unknownObjectColor());
m_widget->setRecentlyUpdatedColor(m->recentlyUpdatedColor());
m_widget->setManuallyChangedColor(m->manuallyChangedColor());
m_widget->setRecentlyUpdatedTimeout(m->recentlyUpdatedTimeout());

View File

@ -1,4 +1,5 @@
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

@ -29,6 +29,7 @@
UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, QSettings *qSettings, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_unknownObjectColor(QColor(Qt::gray)),
m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)),
m_onlyHilightChangedValues(false),
@ -44,6 +45,7 @@ UAVObjectBrowserConfiguration::UAVObjectBrowserConfiguration(QString classId, QS
int timeout = qSettings->value("recentlyUpdatedTimeout").toInt();
bool hilight = qSettings->value("onlyHilightChangedValues").toBool();
m_unknownObjectColor = qSettings->value("unknownObjectColor", QVariant(QColor(Qt::gray))).value<QColor>();
m_useCategorizedView = qSettings->value("CategorizedView").toBool();
m_useScientificView = qSettings->value("ScientificView").toBool();
m_showMetaData = qSettings->value("showMetaData").toBool();
@ -65,6 +67,7 @@ IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
m->m_useCategorizedView = m_useCategorizedView;
m->m_useScientificView = m_useScientificView;
m->m_showMetaData = m_showMetaData;
m->m_unknownObjectColor = m_unknownObjectColor;
return m;
}
@ -74,6 +77,7 @@ IUAVGadgetConfiguration *UAVObjectBrowserConfiguration::clone()
*/
void UAVObjectBrowserConfiguration::saveConfig(QSettings *qSettings) const
{
qSettings->setValue("unknownObjectColor", m_unknownObjectColor);
qSettings->setValue("recentlyUpdatedColor", m_recentlyUpdatedColor);
qSettings->setValue("manuallyChangedColor", m_manuallyChangedColor);
qSettings->setValue("recentlyUpdatedTimeout", m_recentlyUpdatedTimeout);

View File

@ -34,7 +34,9 @@
using namespace Core;
class UAVObjectBrowserConfiguration : public IUAVGadgetConfiguration {
Q_OBJECT Q_PROPERTY(QColor m_recentlyUpdatedColor READ recentlyUpdatedColor WRITE setRecentlyUpdatedColor)
Q_OBJECT
Q_PROPERTY(QColor m_unknownObjectColor READ unknownObjectColor WRITE setUnknownObjectColor)
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)
@ -47,6 +49,10 @@ public:
void saveConfig(QSettings *settings) const;
IUAVGadgetConfiguration *clone();
QColor unknownObjectColor() const
{
return m_unknownObjectColor;
}
QColor recentlyUpdatedColor() const
{
return m_recentlyUpdatedColor;
@ -79,6 +85,10 @@ public:
signals:
public slots:
void setUnknownObjectColor(QColor color)
{
m_unknownObjectColor = color;
}
void setRecentlyUpdatedColor(QColor color)
{
m_recentlyUpdatedColor = color;
@ -109,6 +119,7 @@ public slots:
}
private:
QColor m_unknownObjectColor;
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;
bool m_onlyHilightChangedValues;

View File

@ -50,6 +50,7 @@ QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
m_page->recentlyUpdatedButton->setColor(m_config->recentlyUpdatedColor());
m_page->manuallyChangedButton->setColor(m_config->manuallyChangedColor());
m_page->unknownButton->setColor(m_config->unknownObjectColor());
m_page->recentlyUpdatedTimeoutSpinBox->setValue(m_config->recentlyUpdatedTimeout());
m_page->hilightBox->setChecked(m_config->onlyHighlightChangedValues());
@ -58,6 +59,7 @@ QWidget *UAVObjectBrowserOptionsPage::createPage(QWidget *parent)
void UAVObjectBrowserOptionsPage::apply()
{
m_config->setUnknownObjectColor(m_page->unknownButton->color());
m_config->setRecentlyUpdatedColor(m_page->recentlyUpdatedButton->color());
m_config->setManuallyChangedColor(m_page->manuallyChangedButton->color());
m_config->setRecentlyUpdatedTimeout(m_page->recentlyUpdatedTimeoutSpinBox->value());

View File

@ -14,7 +14,16 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -33,12 +42,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>194</height>
<width>507</width>
<height>178</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
@ -48,6 +66,32 @@
</property>
</widget>
</item>
<item row="6" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="Utils::QtColorButton" name="recentlyUpdatedButton">
<property name="sizePolicy">
@ -67,10 +111,33 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Manually changed color:</string>
<string>Recently updated timeout (ms):</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="hilightBox">
<property name="text">
<string>Only highlight nodes when value actually changes</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="recentlyUpdatedTimeoutSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>100000000</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
@ -93,61 +160,38 @@
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Recently updated timeout (ms):</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="recentlyUpdatedTimeoutSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>100000000</number>
</property>
<property name="singleStep">
<number>100</number>
<string>Manually changed color:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="hilightBox">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Only highlight nodes when value actually changes</string>
<string>Unknown object color:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="3" column="1">
<widget class="Utils::QtColorButton" name="unknownButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<property name="minimumSize">
<size>
<width>20</width>
<height>40</height>
<width>64</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
@ -162,6 +206,14 @@
<header>utils/qtcolorbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>recentlyUpdatedButton</tabstop>
<tabstop>manuallyChangedButton</tabstop>
<tabstop>unknownButton</tabstop>
<tabstop>recentlyUpdatedTimeoutSpinBox</tabstop>
<tabstop>hilightBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -50,12 +50,14 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
m_model = new UAVObjectTreeModel();
m_browser->treeView->setModel(m_model);
m_browser->treeView->setColumnWidth(0, 300);
// m_browser->treeView->expandAll();
BrowserItemDelegate *m_delegate = new BrowserItemDelegate();
m_browser->treeView->setItemDelegate(m_delegate);
m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
showMetaData(m_viewoptions->cbMetaData->isChecked());
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection);
connect(m_viewoptions->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(categorize(bool)));
@ -69,6 +71,7 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
connect(m_viewoptions->cbScientific, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
enableSendRequest(false);
}
@ -101,6 +104,7 @@ void UAVObjectBrowserWidget::categorize(bool categorize)
m_model->setManuallyChangedColor(m_manuallyChangedColor);
m_model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
m_model->setOnlyHilightChangedValues(m_onlyHilightChangedValues);
m_model->setUnknowObjectColor(m_unknownObjectColor);
m_browser->treeView->setModel(m_model);
showMetaData(m_viewoptions->cbMetaData->isChecked());
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection);
@ -116,6 +120,7 @@ void UAVObjectBrowserWidget::useScientificNotation(bool scientific)
m_model->setRecentlyUpdatedColor(m_recentlyUpdatedColor);
m_model->setManuallyChangedColor(m_manuallyChangedColor);
m_model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
m_model->setUnknowObjectColor(m_unknownObjectColor);
m_browser->treeView->setModel(m_model);
showMetaData(m_viewoptions->cbMetaData->isChecked());
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection);

View File

@ -44,21 +44,31 @@ class UAVObjectBrowserWidget : public QWidget {
public:
UAVObjectBrowserWidget(QWidget *parent = 0);
~UAVObjectBrowserWidget();
void setUnknownObjectColor(QColor color)
{
m_unknownObjectColor = color;
m_model->setUnknowObjectColor(color);
}
void setRecentlyUpdatedColor(QColor color)
{
m_recentlyUpdatedColor = color; m_model->setRecentlyUpdatedColor(color);
m_recentlyUpdatedColor = color;
m_model->setRecentlyUpdatedColor(color);
}
void setManuallyChangedColor(QColor color)
{
m_manuallyChangedColor = color; m_model->setManuallyChangedColor(color);
m_manuallyChangedColor = color;
m_model->setManuallyChangedColor(color);
}
void setRecentlyUpdatedTimeout(int timeout)
{
m_recentlyUpdatedTimeout = timeout; m_model->setRecentlyUpdatedTimeout(timeout);
m_recentlyUpdatedTimeout = timeout;
m_model->setRecentlyUpdatedTimeout(timeout);
}
void setOnlyHilightChangedValues(bool hilight)
{
m_onlyHilightChangedValues = hilight; m_model->setOnlyHilightChangedValues(hilight);
m_onlyHilightChangedValues = hilight;
m_model->setOnlyHilightChangedValues(hilight);
}
void setViewOptions(bool categorized, bool scientific, bool metadata);
public slots:
@ -75,8 +85,10 @@ private slots:
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void viewSlot();
void viewOptionsChangedSlot();
signals:
void viewOptionsChanged(bool categorized, bool scientific, bool metadata);
private:
QPushButton *m_requestUpdate;
QPushButton *m_sendUpdate;
@ -86,6 +98,7 @@ private:
UAVObjectTreeModel *m_model;
int m_recentlyUpdatedTimeout;
QColor m_unknownObjectColor;
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;
bool m_onlyHilightChangedValues;

View File

@ -42,11 +42,13 @@ 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))
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
Q_ASSERT(objManager);
// Create highlight manager, let it run every 300 ms.
m_highlightManager = new HighLightManager(300);
@ -54,6 +56,12 @@ 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);
}
@ -112,15 +120,17 @@ void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
if (existing) {
addInstance(obj, existing);
} else {
DataObjectTreeItem *dataTreeItem = new DataObjectTreeItem(obj->getName() + " (" + QString::number(obj->getNumBytes()) + " bytes)");
DataObjectTreeItem *dataTreeItem = new DataObjectTreeItem(obj->getName());
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);
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));
}
}
@ -352,20 +362,24 @@ QVariant UAVObjectTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
if (index.column() == TreeItem::dataColumn && role == Qt::EditRole) {
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
return item->data(index.column());
}
if (role == Qt::ToolTipRole) {
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
return item->description();
}
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
if (role == Qt::ForegroundRole) {
if (!dynamic_cast<TopTreeItem*>(item) && !item->isKnown()) {
return QVariant(m_unknownObjectColor);
}
}
if (index.column() == 0 && role == Qt::BackgroundRole) {
if (!dynamic_cast<TopTreeItem *>(item) && item->highlighted()) {
if(!dynamic_cast<TopTreeItem*>(item) && item->highlighted()) {
return QVariant(m_recentlyUpdatedColor);
}
}
@ -484,3 +498,18 @@ void UAVObjectTreeModel::updateHighlight(TreeItem *item)
Q_ASSERT(itemIndex != QModelIndex());
emit dataChanged(itemIndex, itemIndex.sibling(itemIndex.row(), TreeItem::dataColumn));
}
void UAVObjectTreeModel::knownObjectsChanged(UAVObject *object, bool known)
{
if (object->isSettingsObject()) {
TreeItem * item;
if (object->isMetaDataObject()) {
item = m_settingsTree->findMetaObjectTreeItemByObjectId(object->getObjID());
} else {
item = m_settingsTree->findDataObjectTreeItemByObjectId(object->getObjID());
}
if (item) {
item->setKnown(known);
}
}
}

View File

@ -29,6 +29,7 @@
#define UAVOBJECTTREEMODEL_H
#include "treeitem.h"
#include "uavtalk/telemetrymanager.h"
#include <QAbstractItemModel>
#include <QtCore/QMap>
#include <QtCore/QList>
@ -62,6 +63,10 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setUnknowObjectColor(QColor color)
{
m_unknownObjectColor = color;
}
void setRecentlyUpdatedColor(QColor color)
{
m_recentlyUpdatedColor = color;
@ -90,6 +95,7 @@ public slots:
private slots:
void highlightUpdatedObject(UAVObject *obj);
void updateHighlight(TreeItem *);
void knownObjectsChanged(UAVObject*object, bool known);
private:
void setupModelData(UAVObjectManager *objManager);
@ -115,10 +121,12 @@ private:
int m_recentlyUpdatedTimeout;
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;
QColor m_unknownObjectColor;
bool m_onlyHilightChangedValues;
// Highlight manager to handle highlighting of tree items.
HighLightManager *m_highlightManager;
TelemetryManager *m_telemetryManager;
};
#endif // UAVOBJECTTREEMODEL_H