From dcc977c4b6f5d19a04610eed535ff7448cc842bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 19 Sep 2017 10:42:19 +0200 Subject: [PATCH] ParameterEditor: allow searching for multiple independent words --- src/QmlControls/ParameterEditor.qml | 2 +- src/QmlControls/ParameterEditorController.cc | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/QmlControls/ParameterEditor.qml b/src/QmlControls/ParameterEditor.qml index 25c00004a..2159e6435 100644 --- a/src/QmlControls/ParameterEditor.qml +++ b/src/QmlControls/ParameterEditor.qml @@ -32,7 +32,7 @@ QGCView { property Fact _editorDialogFact: Fact { } property int _rowHeight: ScreenTools.defaultFontPixelHeight * 2 property int _rowWidth: 10 // Dynamic adjusted at runtime - property bool _searchFilter: searchText.text != "" ///< true: showing results of search + property bool _searchFilter: searchText.text.trim() != "" ///< true: showing results of search property var _searchResults ///< List of parameter names from search results property bool _showRCToParam: !ScreenTools.isMobile && QGroundControl.multiVehicleManager.activeVehicle.px4Firmware diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 9520b9eb9..00ca6d27a 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -158,8 +158,9 @@ void ParameterEditorController::setRCToParam(const QString& paramName) void ParameterEditorController::_updateParameters(void) { QObjectList newParameterList; + QStringList searchItems = _searchText.split(' ', QString::SkipEmptyParts); - if (_searchText.isEmpty()) { + if (searchItems.isEmpty()) { const QMap >& groupMap = _vehicle->parameterManager()->getGroupMap(); foreach (const QString& parameter, groupMap[_currentComponentId][_currentGroup]) { newParameterList.append(_vehicle->parameterManager()->getParameter(_currentComponentId, parameter)); @@ -167,9 +168,17 @@ void ParameterEditorController::_updateParameters(void) } else { foreach(const QString ¶meter, _vehicle->parameterManager()->parameterNames(_vehicle->defaultComponentId())) { Fact* fact = _vehicle->parameterManager()->getParameter(_vehicle->defaultComponentId(), parameter); - if (fact->name().contains(_searchText, Qt::CaseInsensitive) || - fact->shortDescription().contains(_searchText, Qt::CaseInsensitive) || - fact->longDescription().contains(_searchText, Qt::CaseInsensitive)) { + 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) && + !fact->shortDescription().contains(searchItem, Qt::CaseInsensitive) && + !fact->longDescription().contains(searchItem, Qt::CaseInsensitive)) { + matched = false; + } + } + if (matched) { newParameterList.append(fact); } } -- 2.22.0