From 6328b8a593ccb24ed68716c96adb9984250897da Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sat, 23 Apr 2016 18:32:32 +0200 Subject: [PATCH] LP-286 minor code cleanups remove unused class members reorganize some methods --- .../uavobjectbrowserwidget.cpp | 40 ++++++++++++------- .../uavobjectbrowser/uavobjectbrowserwidget.h | 11 +++-- .../uavobjectbrowser/uavobjecttreemodel.cpp | 26 ++++++------ .../uavobjectbrowser/uavobjecttreemodel.h | 1 + 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index fdc598ae0..9d13b2c40 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -44,43 +44,54 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent) { - m_browser = new Ui_UAVObjectBrowser(); - m_viewoptions = new Ui_viewoptions(); m_viewoptionsDialog = new QDialog(this); + + m_viewoptions = new Ui_viewoptions(); m_viewoptions->setupUi(m_viewoptionsDialog); - m_browser->setupUi(this); - m_model = new UAVObjectTreeModel(); + + m_model = new UAVObjectTreeModel(this); + m_modelProxy = new TreeSortFilterProxyModel(this); m_modelProxy->setSourceModel(m_model); m_modelProxy->setDynamicSortFilter(true); + + m_browser = new Ui_UAVObjectBrowser(); + m_browser->setupUi(this); m_browser->treeView->setModel(m_modelProxy); m_browser->treeView->setColumnWidth(0, 300); m_browser->treeView->setItemDelegate(new BrowserItemDelegate()); m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); m_browser->treeView->setSelectionBehavior(QAbstractItemView::SelectItems); + 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)), 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))); - connect(m_viewoptions->cbDescription, SIGNAL(toggled(bool)), this, SLOT(showDescription(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())); connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate())); + connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject())); 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->cbMetaData, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot())); - connect(m_viewoptions->cbCategorized, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot())); - connect(m_viewoptions->cbDescription, SIGNAL(toggled(bool)), this, SLOT(viewOptionsChangedSlot())); - connect(m_browser->splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(splitterMoved())); + + // search field and button connect(m_browser->searchLine, SIGNAL(textChanged(QString)), this, SLOT(searchLineChanged(QString))); connect(m_browser->searchClearButton, SIGNAL(clicked(bool)), this, SLOT(searchTextCleared())); + enableSendRequest(false); } @@ -106,9 +117,9 @@ void UAVObjectBrowserWidget::showMetaData(bool show) { QList metaIndexes = m_model->getMetaDataIndexes(); foreach(QModelIndex modelIndex, metaIndexes) { - QModelIndex proxyModelindex = m_modelProxy->mapFromSource(modelIndex); + QModelIndex proxyModelIndex = m_modelProxy->mapFromSource(modelIndex); - m_browser->treeView->setRowHidden(proxyModelindex.row(), proxyModelindex.parent(), !show); + m_browser->treeView->setRowHidden(proxyModelIndex.row(), proxyModelIndex.parent(), !show); } } @@ -140,6 +151,7 @@ void UAVObjectBrowserWidget::categorize(bool categorize) void UAVObjectBrowserWidget::useScientificNotation(bool scientific) { + // TODO we should have the model update itself instead of rebuilding it UAVObjectTreeModel *model = new UAVObjectTreeModel(0, m_viewoptions->cbCategorized->isChecked(), scientific); model->setManuallyChangedColor(m_manuallyChangedColor); diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h index 7c4c3eaf0..c0051ad67 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -29,12 +29,14 @@ #ifndef UAVOBJECTBROWSERWIDGET_H_ #define UAVOBJECTBROWSERWIDGET_H_ +#include "uavobjecttreemodel.h" + +#include "objectpersistence.h" + #include #include #include #include -#include "objectpersistence.h" -#include "uavobjecttreemodel.h" class QPushButton; class ObjectTreeItem; @@ -85,6 +87,7 @@ public: } void setViewOptions(bool categorized, bool scientific, bool metadata, bool description); void setSplitterState(QByteArray state); + public slots: void showMetaData(bool show); void showDescription(bool show); @@ -104,12 +107,12 @@ private slots: void searchTextCleared(); void splitterMoved(); QString createObjectDescription(UAVObject *object); + signals: void viewOptionsChanged(bool categorized, bool scientific, bool metadata, bool description); void splitterChanged(QByteArray state); + private: - QPushButton *m_requestUpdate; - QPushButton *m_sendUpdate; Ui_UAVObjectBrowser *m_browser; Ui_viewoptions *m_viewoptions; QDialog *m_viewoptionsDialog; diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp b/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp index a22fcf1c9..7c9f5b185 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp @@ -68,20 +68,23 @@ UAVObjectTreeModel::~UAVObjectTreeModel() void UAVObjectTreeModel::setupModelData(UAVObjectManager *objManager) { + m_settingsTree = new TopTreeItem(tr("Settings")); + m_settingsTree->setHighlightManager(m_highlightManager); + connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); + + m_nonSettingsTree = new TopTreeItem(tr("Data Objects")); + m_nonSettingsTree->setHighlightManager(m_highlightManager); + connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); + // root QList rootData; rootData << tr("Property") << tr("Value") << tr("Unit"); - m_rootItem = new TreeItem(rootData); - - m_settingsTree = new TopTreeItem(tr("Settings"), m_rootItem); - m_settingsTree->setHighlightManager(m_highlightManager); - m_rootItem->appendChild(m_settingsTree); - m_nonSettingsTree = new TopTreeItem(tr("Data Objects"), m_rootItem); - m_nonSettingsTree->setHighlightManager(m_highlightManager); - m_rootItem->appendChild(m_nonSettingsTree); + m_rootItem = new TreeItem(rootData); m_rootItem->setHighlightManager(m_highlightManager); - connect(m_settingsTree, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); - connect(m_nonSettingsTree, SIGNAL(updateHighlight(TreeItem *)), this, SLOT(updateHighlight(TreeItem *))); + + // tree item takes ownership of its children + m_rootItem->appendChild(m_settingsTree); + m_rootItem->appendChild(m_nonSettingsTree); QList< QList > objList = objManager->getDataObjects(); foreach(QList list, objList) { @@ -258,8 +261,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt parent->appendChild(item); } -QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent) -const +QModelIndex UAVObjectTreeModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h b/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h index 687310f40..6025679c3 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h @@ -128,4 +128,5 @@ private: // Highlight manager to handle highlighting of tree items. HighLightManager *m_highlightManager; }; + #endif // UAVOBJECTTREEMODEL_H