From 06b0fbebf3a626cb21e132331fd8ed706a538030 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Wed, 6 Mar 2019 13:00:12 -0500 Subject: [PATCH] Allow filtering parameters to only show those different from the default (changed) --- src/QmlControls/ParameterEditor.qml | 27 +++++++++++++------- src/QmlControls/ParameterEditorController.cc | 23 ++++++++++++----- src/QmlControls/ParameterEditorController.h | 8 +++++- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/QmlControls/ParameterEditor.qml b/src/QmlControls/ParameterEditor.qml index f9ea4fb42..5d3eda1b7 100644 --- a/src/QmlControls/ParameterEditor.qml +++ b/src/QmlControls/ParameterEditor.qml @@ -28,9 +28,9 @@ QGCView { property Fact _editorDialogFact: Fact { } property int _rowHeight: ScreenTools.defaultFontPixelHeight * 2 - property int _rowWidth: 10 // Dynamic adjusted at runtime + property int _rowWidth: 10 // Dynamic adjusted at runtime property bool _searchFilter: searchText.text.trim() != "" ///< true: showing results of search - property var _searchResults ///< List of parameter names from search results + property var _searchResults ///< List of parameter names from search results property bool _showRCToParam: !ScreenTools.isMobile && QGroundControl.multiVehicleManager.activeVehicle.px4Firmware property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property var _appSettings: QGroundControl.settingsManager.appSettings @@ -69,19 +69,18 @@ QGCView { } QGCLabel { - anchors.baseline: clearButton.baseline + anchors.verticalCenter: parent.verticalCenter text: qsTr("Search:") } QGCTextField { id: searchText - anchors.baseline: clearButton.baseline text: controller.searchText onDisplayTextChanged: controller.searchText = displayText + anchors.verticalCenter: parent.verticalCenter } QGCButton { - id: clearButton text: qsTr("Clear") onClicked: { if(ScreenTools.isMobile) { @@ -89,6 +88,16 @@ QGCView { } clearTimer.start() } + anchors.verticalCenter: parent.verticalCenter + } + + QGCCheckBox { + text: qsTr("Show modified only") + checked: controller.showModifiedOnly + anchors.verticalCenter: parent.verticalCenter + onClicked: { + controller.showModifiedOnly = !controller.showModifiedOnly + } } } // Row - Header @@ -152,7 +161,7 @@ QGCView { pixelAligned: true contentHeight: groupedViewCategoryColumn.height flickableDirection: Flickable.VerticalFlick - visible: !_searchFilter + visible: !_searchFilter && !controller.showModifiedOnly ColumnLayout { id: groupedViewCategoryColumn @@ -172,7 +181,7 @@ QGCView { SectionHeader { id: categoryHeader text: category - checked: controller.currentCategory == text + checked: controller.currentCategory === text exclusiveGroup: sectionGroup onCheckedChanged: { @@ -192,7 +201,7 @@ QGCView { width: ScreenTools.defaultFontPixelWidth * 25 text: groupName height: _rowHeight - checked: controller.currentGroup == text + checked: controller.currentGroup === text exclusiveGroup: buttonGroup readonly property string groupName: modelData @@ -214,7 +223,7 @@ QGCView { QGCListView { id: editorListView anchors.leftMargin: ScreenTools.defaultFontPixelWidth - anchors.left: _searchFilter ? parent.left : groupScroll.right + anchors.left: (_searchFilter || controller.showModifiedOnly) ? parent.left : groupScroll.right anchors.right: parent.right anchors.top: header.bottom anchors.bottom: parent.bottom diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 69d40dce9..0bb04c90a 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -26,6 +26,7 @@ ParameterEditorController::ParameterEditorController(void) , _parameters (new QmlObjectListModel(this)) , _parameterMgr (_vehicle->parameterManager()) , _componentCategoryPrefix (tr("Component ")) + , _showModifiedOnly (false) { const QMap >& categoryMap = _parameterMgr->getDefaultComponentCategoryMap(); _categories = categoryMap.keys(); @@ -50,6 +51,7 @@ ParameterEditorController::ParameterEditorController(void) connect(this, &ParameterEditorController::searchTextChanged, this, &ParameterEditorController::_updateParameters); connect(this, &ParameterEditorController::currentCategoryChanged, this, &ParameterEditorController::_updateParameters); connect(this, &ParameterEditorController::currentGroupChanged, this, &ParameterEditorController::_updateParameters); + connect(this, &ParameterEditorController::showModifiedOnlyChanged, this, &ParameterEditorController::_updateParameters); } ParameterEditorController::~ParameterEditorController() @@ -163,12 +165,18 @@ void ParameterEditorController::setRCToParam(const QString& paramName) #endif } +bool ParameterEditorController::_shouldShow(Fact* fact) +{ + bool show = _showModifiedOnly ? (fact->defaultValueAvailable() ? (fact->valueEqualsDefault() ? false : true) : false) : true; + return show; +} + void ParameterEditorController::_updateParameters(void) { QObjectList newParameterList; QStringList searchItems = _searchText.split(' ', QString::SkipEmptyParts); - if (searchItems.isEmpty()) { + if (searchItems.isEmpty() && !_showModifiedOnly) { if (_currentCategory.startsWith(_componentCategoryPrefix)) { int compId = _currentCategory.right(_currentCategory.length() - _componentCategoryPrefix.length()).toInt(); for (const QString& paramName: _parameterMgr->parameterNames(compId)) { @@ -184,14 +192,15 @@ void ParameterEditorController::_updateParameters(void) } else { for(const QString ¶meter: _parameterMgr->parameterNames(_vehicle->defaultComponentId())) { Fact* fact = _parameterMgr->getParameter(_vehicle->defaultComponentId(), parameter); - bool matched = true; - - // all of the search items must match in order for the parameter to be added to the list - for (const auto& searchItem : searchItems) { - if (!fact->name().contains(searchItem, Qt::CaseInsensitive) && + bool matched = _shouldShow(fact); + // All of the search items must match in order for the parameter to be added to the list + if(matched) { + for (const auto& searchItem : searchItems) { + if (!fact->name().contains(searchItem, Qt::CaseInsensitive) && !fact->shortDescription().contains(searchItem, Qt::CaseInsensitive) && !fact->longDescription().contains(searchItem, Qt::CaseInsensitive)) { - matched = false; + matched = false; + } } } if (matched) { diff --git a/src/QmlControls/ParameterEditorController.h b/src/QmlControls/ParameterEditorController.h index a7dba4309..fe5d5a2b2 100644 --- a/src/QmlControls/ParameterEditorController.h +++ b/src/QmlControls/ParameterEditorController.h @@ -36,7 +36,8 @@ public: Q_PROPERTY(QString currentGroup MEMBER _currentGroup NOTIFY currentGroupChanged) Q_PROPERTY(QmlObjectListModel* parameters MEMBER _parameters CONSTANT) Q_PROPERTY(QStringList categories MEMBER _categories CONSTANT) - + Q_PROPERTY(bool showModifiedOnly MEMBER _showModifiedOnly NOTIFY showModifiedOnlyChanged) + Q_INVOKABLE QStringList getGroupsForCategory(const QString& category); Q_INVOKABLE QStringList searchParameters(const QString& searchText, bool searchInName=true, bool searchInDescriptions=true); @@ -54,10 +55,14 @@ signals: void currentCategoryChanged(QString category); void currentGroupChanged(QString group); void showErrorMessage(const QString& errorMsg); + void showModifiedOnlyChanged(); private slots: void _updateParameters(void); +private: + bool _shouldShow(Fact *fact); + private: QStringList _categories; QString _searchText; @@ -66,6 +71,7 @@ private: QmlObjectListModel* _parameters; ParameterManager* _parameterMgr; QString _componentCategoryPrefix; + bool _showModifiedOnly; }; #endif -- 2.22.0