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

LP-313 fix uavobjectbrowser always showing metadata when filtering

This commit is contained in:
Philippe Renon 2016-08-30 00:43:32 +02:00
parent 52a9aa37c8
commit 4f3ae61da6
4 changed files with 47 additions and 79 deletions

View File

@ -50,7 +50,10 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
m_viewoptions = new Ui_viewoptions();
m_viewoptions->setupUi(m_viewoptionsDialog);
m_model = new UAVObjectTreeModel(this);
m_model = new UAVObjectTreeModel(this,
m_viewoptions->cbCategorized->isChecked(),
m_viewoptions->cbMetaData->isChecked(),
m_viewoptions->cbScientific->isChecked());
m_modelProxy = new TreeSortFilterProxyModel(this);
m_modelProxy->setSourceModel(m_model);
@ -67,7 +70,6 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
m_mustacheTemplate = loadFileIntoString(QString(":/uavobjectbrowser/resources/uavodescription.mustache"));
showMetaData(m_viewoptions->cbMetaData->isChecked());
showDescription(m_viewoptions->cbDescription->isChecked());
connect(m_browser->treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
@ -80,14 +82,11 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
connect(m_browser->tbView, SIGNAL(clicked()), this, SLOT(viewSlot()));
connect(m_browser->splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(splitterMoved()));
connect(m_viewoptions->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool)));
connect(m_viewoptions->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(categorize(bool)));
connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbDescription, SIGNAL(toggled(bool)), this, SLOT(showDescription(bool)));
connect(m_viewoptions->cbDescription, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbScientific, SIGNAL(toggled(bool)), this, SLOT(useScientificNotation(bool)));
connect(m_viewoptions->cbScientific, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot()));
connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(updateViewOptions()));
connect(m_viewoptions->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(updateViewOptions()));
connect(m_viewoptions->cbScientific, SIGNAL(toggled(bool)), this, SLOT(updateViewOptions()));
// search field and button
connect(m_browser->searchLine, SIGNAL(textChanged(QString)), this, SLOT(searchLineChanged(QString)));
@ -114,68 +113,13 @@ void UAVObjectBrowserWidget::setSplitterState(QByteArray state)
m_browser->splitter->restoreState(state);
}
void UAVObjectBrowserWidget::showMetaData(bool show)
{
// TODO update the model directly instead of hiding rows...
QList<QModelIndex> metaIndexes = m_model->getMetaDataIndexes();
foreach(QModelIndex modelIndex, metaIndexes) {
QModelIndex proxyModelIndex = m_modelProxy->mapFromSource(modelIndex);
m_browser->treeView->setRowHidden(proxyModelIndex.row(), proxyModelIndex.parent(), !show);
}
}
void UAVObjectBrowserWidget::showDescription(bool show)
{
m_browser->descriptionText->setVisible(show);
}
void UAVObjectBrowserWidget::categorize(bool categorize)
{
// TODO we should update the model instead of rebuilding it
// a side effect of rebuilding is that some state is lost (expand state, ...)
UAVObjectTreeModel *model = new UAVObjectTreeModel(0, categorize, m_viewoptions->cbScientific->isChecked());
model->setRecentlyUpdatedColor(m_recentlyUpdatedColor);
model->setManuallyChangedColor(m_manuallyChangedColor);
model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
model->setOnlyHilightChangedValues(m_onlyHilightChangedValues);
model->setUnknowObjectColor(m_unknownObjectColor);
UAVObjectTreeModel *tmpModel = m_model;
m_model = model;
m_modelProxy->setSourceModel(m_model);
delete tmpModel;
showMetaData(m_viewoptions->cbMetaData->isChecked());
// force an expand all if search text is not empty
if (!m_browser->searchLine->text().isEmpty()) {
searchLineChanged(m_browser->searchLine->text());
}
}
void UAVObjectBrowserWidget::useScientificNotation(bool scientific)
{
// TODO we should update the model instead of rebuilding it
// a side effect of rebuilding is that some state is lost (expand state, ...)
UAVObjectTreeModel *model = new UAVObjectTreeModel(0, m_viewoptions->cbCategorized->isChecked(), scientific);
model->setManuallyChangedColor(m_manuallyChangedColor);
model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
model->setUnknowObjectColor(m_unknownObjectColor);
UAVObjectTreeModel *tmpModel = m_model;
m_model = model;
m_modelProxy->setSourceModel(m_model);
delete tmpModel;
showMetaData(m_viewoptions->cbMetaData->isChecked());
// force an expand all if search text is not empty
if (!m_browser->searchLine->text().isEmpty()) {
searchLineChanged(m_browser->searchLine->text());
}
// persist options
emit viewOptionsChanged(m_viewoptions->cbCategorized->isChecked(), m_viewoptions->cbScientific->isChecked(),
m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbDescription->isChecked());
}
void UAVObjectBrowserWidget::sendUpdate()
@ -321,8 +265,30 @@ void UAVObjectBrowserWidget::viewSlot()
}
}
void UAVObjectBrowserWidget::viewOptionsChangedSlot()
void UAVObjectBrowserWidget::updateViewOptions()
{
// TODO we should update the model instead of rebuilding it
// a side effect of rebuilding is that some state is lost (expand state, ...)
UAVObjectTreeModel *model = new UAVObjectTreeModel(this,
m_viewoptions->cbCategorized->isChecked(),
m_viewoptions->cbMetaData->isChecked(),
m_viewoptions->cbScientific->isChecked());
model->setManuallyChangedColor(m_manuallyChangedColor);
model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout);
model->setUnknowObjectColor(m_unknownObjectColor);
UAVObjectTreeModel *tmpModel = m_model;
m_model = model;
m_modelProxy->setSourceModel(m_model);
delete tmpModel;
// force an expand all if search text is not empty
if (!m_browser->searchLine->text().isEmpty()) {
searchLineChanged(m_browser->searchLine->text());
}
// persist options
emit viewOptionsChanged(m_viewoptions->cbCategorized->isChecked(), m_viewoptions->cbScientific->isChecked(),
m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbDescription->isChecked());
}

View File

@ -90,10 +90,7 @@ public:
void setSplitterState(QByteArray state);
public slots:
void showMetaData(bool show);
void showDescription(bool show);
void categorize(bool categorize);
void useScientificNotation(bool scientific);
private slots:
void sendUpdate();
@ -103,7 +100,7 @@ private slots:
void eraseObject();
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void viewSlot();
void viewOptionsChangedSlot();
void updateViewOptions();
void searchLineChanged(QString searchText);
void searchTextCleared();
void splitterMoved();

View File

@ -37,10 +37,11 @@
#include <QtCore/QSignalMapper>
#include <QtCore/QDebug>
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize, bool useScientificNotation) :
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize, bool showMetadata, bool useScientificNotation) :
QAbstractItemModel(parent),
m_useScientificFloatNotation(useScientificNotation),
m_categorize(categorize),
m_showMetadata(showMetadata),
m_useScientificFloatNotation(useScientificNotation),
m_recentlyUpdatedTimeout(500), // ms
m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)),
@ -124,9 +125,11 @@ void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
connect(dataTreeItem, SIGNAL(updateIsKnown(TreeItem *)), this, SLOT(updateIsKnown(TreeItem *)));
parent->insertChild(dataTreeItem);
root->addObjectTreeItem(obj->getObjID(), dataTreeItem);
if (m_showMetadata) {
UAVMetaObject *meta = obj->getMetaObject();
MetaObjectTreeItem *metaTreeItem = addMetaObject(meta, dataTreeItem);
root->addMetaObjectTreeItem(meta->getObjID(), metaTreeItem);
}
addInstance(obj, dataTreeItem);
}
}

View File

@ -48,7 +48,8 @@ class QTimer;
class UAVObjectTreeModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit UAVObjectTreeModel(QObject *parent = 0, bool categorize = false, bool useScientificNotation = false);
explicit UAVObjectTreeModel(QObject *parent, bool categorize, bool showMetadata, bool useScientificNotation);
explicit UAVObjectTreeModel(bool categorize, bool showMetadata, bool useScientificNotation);
~UAVObjectTreeModel();
QVariant data(const QModelIndex &index, int role) const;
@ -116,8 +117,9 @@ private:
TreeItem *m_rootItem;
TopTreeItem *m_settingsTree;
TopTreeItem *m_nonSettingsTree;
bool m_useScientificFloatNotation;
bool m_categorize;
bool m_showMetadata;
bool m_useScientificFloatNotation;
int m_recentlyUpdatedTimeout;
QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor;